Skip to content

Commit b485425

Browse files
authored
[Xamarin.Android.Build.Tests] Improve logcat logging in failed tests (#7816)
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 `adb 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 `adb logcat -c` before each *test* starts. To attempt a fix for the latter, pause for 1 second before dumping logcat buffer after the test fails.
1 parent ebd7dff commit b485425

File tree

1 file changed

+7
-1
lines changed
  • src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities

1 file changed

+7
-1
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void AssertHasDevices (bool fail = true)
4848
public void DeviceSetup ()
4949
{
5050
SetAdbLogcatBufferSize (64);
51-
RunAdbCommand ("logcat -c");
51+
ClearAdbLogcat ();
5252
CreateGuestUser (GuestUserName);
5353
}
5454

@@ -69,6 +69,9 @@ public void CheckDevice ()
6969
TestContext.Out.WriteLine ($"{nameof(CheckDevice)} is restarting the emulator.");
7070
RestartDevice (Path.Combine (Root, "Emulator.csproj"));
7171
}
72+
73+
// We want to start with a clean logcat buffer for each test
74+
ClearAdbLogcat ();
7275
}
7376

7477
[TearDown]
@@ -82,6 +85,9 @@ protected override void CleanupTest ()
8285
string remote = "/data/local/tmp/screenshot.png";
8386
string localUi = Path.Combine (outputDir, "ui.xml");
8487
RunAdbCommand ($"shell screencap {remote}");
88+
89+
// Give the app a chance to finish logging
90+
WaitFor (1000);
8591
var output = RunAdbCommand ($"logcat -d");
8692
File.WriteAllText (deviceLog, output);
8793
RunAdbCommand ($"pull {remote} \"{local}\"");

0 commit comments

Comments
 (0)