Skip to content
Merged
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 @@ -369,11 +369,18 @@ protected static bool MonitorAdbLogcat (Func<string, bool> action, string logcat
bool didActionSucceed = false;
ManualResetEventSlim stdout_done = new ManualResetEventSlim ();
using (var sw = File.CreateText (logcatFilePath)) {
// Process already-buffered logcat lines first so startup messages emitted before
// this monitor starts are still visible to tests.
if (TryMatchLogcatOutput (RunAdbCommand ("logcat -d"), sw, action)) {
sw.Flush ();
return true;
}

using (var proc = Process.Start (info)) {
proc.OutputDataReceived += (sender, e) => {
if (e.Data != null) {
Comment thread
jonathanpeppers marked this conversation as resolved.
sw.WriteLine (e.Data);
if (action (e.Data)) {
if (!didActionSucceed && action (e.Data)) {
didActionSucceed = true;
}
} else {
Expand All @@ -395,6 +402,23 @@ protected static bool MonitorAdbLogcat (Func<string, bool> action, string logcat
}
}

static bool TryMatchLogcatOutput (string output, TextWriter logcatOutput, Func<string, bool> action)
{
bool didActionSucceed = false;
using (var sr = new StringReader (output ?? "")) {
string line = sr.ReadLine ();
while (line != null) {
logcatOutput.WriteLine (line);
if (action (line)) {
didActionSucceed = true;
break;
}
line = sr.ReadLine ();
Comment thread
Copilot marked this conversation as resolved.
}
}
return didActionSucceed;
}

protected static bool WaitForDebuggerToStart (string logcatFilePath, int timeout = 120)
{
bool result = MonitorAdbLogcat ((line) => {
Expand Down
Loading