From 9800f40e0e151138590544b7ab6ff50dfad965d3 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 21 Feb 2023 18:26:40 +0100 Subject: [PATCH 1/2] Attempt to get better logcat logging for failed tests I noticed that more often than not, we don't see the actual error in `logcat-failed.log` when the test fails on CI, but when it runs locally, we can see the issue logged properly. I'm not 100% what causes it on CI, but I suspect that we might be facing a problem with the logcat buffer wrapping around and overwriting the interesting data. This might be because of the fact that `logcat -c` runs only once per **class** containing tests and also because we log too quickly after the app quits. To remedy the former, run `logcat -c` before each test starts and to attempt a fix for the latter, pause for 1 second before dumping logcat buffer after the test fails. --- .../Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs index 4b4d6c88807..ba358dc8c3d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs @@ -48,7 +48,7 @@ public void AssertHasDevices (bool fail = true) public void DeviceSetup () { SetAdbLogcatBufferSize (64); - RunAdbCommand ("logcat -c"); + ClearAdbLogcat (); CreateGuestUser (GuestUserName); } @@ -69,6 +69,9 @@ public void CheckDevice () TestContext.Out.WriteLine ($"{nameof(CheckDevice)} is restarting the emulator."); RestartDevice (Path.Combine (Root, "Emulator.csproj")); } + + // We want to start with a clean logcat buffer for each test + ClearAdbLogcat (); } [TearDown] @@ -82,6 +85,9 @@ protected override void CleanupTest () string remote = "/data/local/tmp/screenshot.png"; string localUi = Path.Combine (outputDir, "ui.xml"); RunAdbCommand ($"shell screencap {remote}"); + + // Give the app a chance to finish logging + Thread.Sleep (1000); var output = RunAdbCommand ($"logcat -d"); File.WriteAllText (deviceLog, output); RunAdbCommand ($"pull {remote} \"{local}\""); From 2c5e04f184754e9f0089579c9f803f6df0a833b5 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 22 Feb 2023 09:36:06 +0100 Subject: [PATCH 2/2] Use WaitFor --- .../Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs index ba358dc8c3d..0f0b2cbe21f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs @@ -87,7 +87,7 @@ protected override void CleanupTest () RunAdbCommand ($"shell screencap {remote}"); // Give the app a chance to finish logging - Thread.Sleep (1000); + WaitFor (1000); var output = RunAdbCommand ($"logcat -d"); File.WriteAllText (deviceLog, output); RunAdbCommand ($"pull {remote} \"{local}\"");