Skip to content

Commit d412dc3

Browse files
committed
[RunInstrumentationTests] Error on test failure
The instrumentatione exit code value of `-1` indicates success, and any other values returned here should be reported as errors. A non `-1` value indicates that crash or test failure occurred.
1 parent ce063f1 commit d412dc3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/RunInstrumentationTests.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class RunInstrumentationTests : Adb
1414
const string TestResultsPathResult = "INSTRUMENTATION_RESULT: nunit2-results-path=";
1515
internal const string AdbRestartText = "daemon not running; starting now at tcp:";
1616
internal const string AdbCrashErrorText = "The adb might have crashed and was restarted. ";
17+
const string ExitCodeName = "INSTRUMENTATION_CODE: ";
1718
const int StateRunInstrumentation = 0;
1819
const int StateGetLogcat = 1;
1920
const int StateClearLogcat = 2;
@@ -41,8 +42,8 @@ public class RunInstrumentationTests : Adb
4142
public string LogLevel { get; set; }
4243

4344
int currentState = -1;
45+
int exitCode = 99;
4446
string targetTestResultsPath;
45-
TextWriter logcatWriter;
4647

4748
bool adbRestarted;
4849

@@ -69,6 +70,14 @@ public override bool Execute ()
6970
return false;
7071
}
7172

73+
if (exitCode != -1) {
74+
FailedToRun = Component;
75+
Log.LogError (
76+
$"Instrumentation for component `{Component}` did not exit successfully. " +
77+
"Process crashed or test failures occurred!");
78+
return false;
79+
}
80+
7281
return !Log.HasLoggedErrors;
7382
}
7483

@@ -135,11 +144,15 @@ protected override void ProcessStdout (string line)
135144
if (currentState != StateRunInstrumentation || String.IsNullOrEmpty (line))
136145
return;
137146

138-
int i = line.IndexOf (TestResultsPathResult, StringComparison.OrdinalIgnoreCase);
139-
if (i < 0)
140-
return;
147+
int testResultIndex = line.IndexOf (TestResultsPathResult, StringComparison.OrdinalIgnoreCase);
148+
int exitCodeIndex = line.IndexOf (ExitCodeName, StringComparison.OrdinalIgnoreCase);
141149

142-
targetTestResultsPath = line.Substring (i + TestResultsPathResult.Length).Trim ();
150+
if (testResultIndex < 0 && exitCodeIndex < 0)
151+
return;
152+
else if (testResultIndex >= 0)
153+
targetTestResultsPath = line.Substring (testResultIndex + TestResultsPathResult.Length).Trim ();
154+
else if (exitCodeIndex >= 0)
155+
exitCode = int.Parse (line.Substring (exitCodeIndex + ExitCodeName.Length).Trim ());
143156
}
144157
}
145158
}

0 commit comments

Comments
 (0)