Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ protected TimeSpan ProfileFor (Func<bool> func, TimeSpan? timeout = null)
return stopwatch.Elapsed;
}

protected static bool MonitorAdbLogcat (Func<string, bool> action, string logcatFilePath, int timeout = 15)
protected static bool MonitorAdbLogcat (Func<string, bool> action, string logcatFilePath, int timeout = 15, Action? onMonitoringStarted = null)
{
string ext = Environment.OSVersion.Platform != PlatformID.Unix ? ".exe" : "";
string adb = Path.Combine (AndroidSdkPath, "platform-tools", "adb" + ext);
Expand Down Expand Up @@ -388,15 +388,21 @@ protected static bool MonitorAdbLogcat (Func<string, bool> action, string logcat
}
};
proc.BeginOutputReadLine ();
TimeSpan time = TimeSpan.FromSeconds (timeout);
while (!stdout_done.IsSet && !didActionSucceed && time.TotalMilliseconds > 0) {
proc.WaitForExit (10);
time -= TimeSpan.FromMilliseconds (10);
try {
onMonitoringStarted?.Invoke ();
TimeSpan time = TimeSpan.FromSeconds (timeout);
while (!stdout_done.IsSet && !didActionSucceed && time.TotalMilliseconds > 0) {
proc.WaitForExit (10);
time -= TimeSpan.FromMilliseconds (10);
}
} finally {
if (!proc.HasExited) {
proc.Kill ();
}
proc.WaitForExit ();
stdout_done.Wait ();
sw.Flush ();
}
proc.Kill ();
proc.WaitForExit ();
stdout_done.Wait ();
sw.Flush ();
return didActionSucceed;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ public void MarshalMethodsAppRuns ([Values (AndroidRuntime.CoreCLR, AndroidRunti

using var apkBuilder = CreateApkBuilder ();
Assert.True (apkBuilder.Install (proj), "Project should have installed.");
RunProjectAndAssert (proj, apkBuilder);
ClearAdbLogcat ();

const string expectedLogcatOutput = "XXX:OnStart done";
Assert.IsTrue (
MonitorAdbLogcat (
InstallAndRunTests.CreateLineChecker (expectedLogcatOutput),
logcatFilePath: Path.Combine (Root, apkBuilder.ProjectDirectory, "startup-logcat.log"), timeout: 60
logcatFilePath: Path.Combine (Root, apkBuilder.ProjectDirectory, "startup-logcat.log"),
timeout: 60,
onMonitoringStarted: () => StartActivityAndAssert (proj)
),
$"Output did not contain {expectedLogcatOutput}!"
);
Expand Down
Loading