From b13715b6984889a709ba29ea8a1961db469f8805 Mon Sep 17 00:00:00 2001
From: Fan Yang <52458914+fanyang-mono@users.noreply.github.com>
Date: Mon, 7 Jun 2021 14:14:16 -0400
Subject: [PATCH] Add runtime test logs to HELIX_WORKITEM_UPLOAD_ROOT (#53798)
---
src/tests/Common/CLRTest.Execute.Bash.targets | 2 +-
src/tests/Common/CLRTest.Execute.Batch.targets | 2 +-
.../Coreclr.TestWrapper/CoreclrTestWrapperLib.cs | 3 ++-
src/tests/run.proj | 31 ++++++++++++++++++++--
4 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/src/tests/Common/CLRTest.Execute.Bash.targets b/src/tests/Common/CLRTest.Execute.Bash.targets
index 9b71d71..e7a0f6c 100644
--- a/src/tests/Common/CLRTest.Execute.Bash.targets
+++ b/src/tests/Common/CLRTest.Execute.Bash.targets
@@ -363,7 +363,7 @@ else
HARNESS_RUNNER="xharness"
fi
-$__Command $HARNESS_RUNNER android test --instrumentation="net.dot.MonoRunner" --package-name="net.dot.$__Category" --app="$__TestBinaryBase/$__Category.apk" --output-directory=`$HELIX_WORKITEM_UPLOAD_ROOT` --arg=entrypoint:libname=$(MsBuildProjectName).dll --expected-exit-code=100 -v
+$__Command $HARNESS_RUNNER android test --instrumentation="net.dot.MonoRunner" --package-name="net.dot.$__Category" --app="$__TestBinaryBase/$__Category.apk" --output-directory="$__OutputDir" --arg=entrypoint:libname=$(MsBuildProjectName).dll --expected-exit-code=100 -v
CLRTestExitCode=$?
# Exist code of xharness is zero when tests finished successfully
diff --git a/src/tests/Common/CLRTest.Execute.Batch.targets b/src/tests/Common/CLRTest.Execute.Batch.targets
index 8653cb2..fa52664 100644
--- a/src/tests/Common/CLRTest.Execute.Batch.targets
+++ b/src/tests/Common/CLRTest.Execute.Batch.targets
@@ -329,7 +329,7 @@ IF NOT "%XHARNESS_CLI_PATH%"=="" (
set HARNESS_RUNNER=xharness
)
-%__Command% %HARNESS_RUNNER% android test --instrumentation="net.dot.MonoRunner" --package-name="net.dot.%__Category%" --app="%__TestBinaryBase%\%__Category%.apk" --output-directory="%HELIX_WORKITEM_UPLOAD_ROOT%" --arg=entrypoint:libname=$(MsBuildProjectName).dll --expected-exit-code=100 -v
+%__Command% %HARNESS_RUNNER% android test --instrumentation="net.dot.MonoRunner" --package-name="net.dot.%__Category%" --app="%__TestBinaryBase%\%__Category%.apk" --output-directory="%__OutputDir%" --arg=entrypoint:libname=$(MsBuildProjectName).dll --expected-exit-code=100 -v
set CLRTestExitCode=!ERRORLEVEL!
set CLRTestExpectedExitCode=0
]]>
diff --git a/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs b/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs
index 074eb1a..da13ad2 100644
--- a/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs
+++ b/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs
@@ -284,7 +284,7 @@ namespace CoreclrTestLib
return children;
}
- public int RunTest(string executable, string outputFile, string errorFile, string category, string testBinaryBase)
+ public int RunTest(string executable, string outputFile, string errorFile, string category, string testBinaryBase, string outputDir)
{
Debug.Assert(outputFile != errorFile);
@@ -321,6 +321,7 @@ namespace CoreclrTestLib
process.StartInfo.RedirectStandardError = true;
process.StartInfo.EnvironmentVariables.Add("__Category", category);
process.StartInfo.EnvironmentVariables.Add("__TestBinaryBase", testBinaryBase);
+ process.StartInfo.EnvironmentVariables.Add("__OutputDir", outputDir);
DateTime startTime = DateTime.Now;
process.Start();
diff --git a/src/tests/run.proj b/src/tests/run.proj
index 21e2573..11866fd 100644
--- a/src/tests/run.proj
+++ b/src/tests/run.proj
@@ -120,11 +120,25 @@ $(_XunitEpilog)
+
+
+
+
]]>
+
+
+
@@ -141,6 +155,12 @@ $(_XunitEpilog)
File="$(XunitWrapperSrcDir)\$(XunitWrapper).csproj"
Lines="$(XunitWrapperGenCsProj)"
Overwrite="true" />
+
+
+
@@ -184,6 +204,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
internal static string testBinaryBase%3B
internal static string coreRoot%3B
internal static string category%3B
+ internal static string helixUploadRoot%3B
static _Global()
{
@@ -191,6 +212,10 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
testBinaryBase = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)%3B
coreRoot = System.Environment.GetEnvironmentVariable(%22CORE_ROOT%22)%3B
category = "$([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").Replace("-","_"))"%3B
+ helixUploadRoot = System.Environment.GetEnvironmentVariable(%22HELIX_WORKITEM_UPLOAD_ROOT%22)%3B
+ if (!String.IsNullOrEmpty(helixUploadRoot)) {
+ reportBase = System.IO.Path.Combine(System.IO.Path.GetFullPath(helixUploadRoot), "Reports")%3B
+ }
if (String.IsNullOrEmpty(reportBase)) {
reportBase = System.IO.Path.Combine(testBinaryBase, "Reports")%3B
@@ -266,6 +291,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
string outputFile = null%3B
string errorFile = null%3B
string testExecutable = null%3B
+ string outputDir = null%3B
Exception infraEx = null%3B
try
@@ -276,6 +302,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
errorFile = System.IO.Path.GetFullPath(_Global.reportBase + testSubfolder + @"%(AllCMDs.FileName).error.txt")%3B
testExecutable = System.IO.Path.GetFullPath(_Global.testBinaryBase + @"$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",''))")%3B
$(TestExecutableReplacement)
+ outputDir = System.IO.Path.GetDirectoryName(outputFile)%3B
if (!_Global.runningInWindows) {
testExecutable = testExecutable.Replace(".cmd", ".sh")%3B
@@ -283,7 +310,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
System.IO.Directory.CreateDirectory(_Global.reportBase + testSubfolder)%3B
- ret = wrapper.RunTest(testExecutable, outputFile, errorFile, _Global.category, _Global.testBinaryBase)%3B
+ ret = wrapper.RunTest(testExecutable, outputFile, errorFile, _Global.category, _Global.testBinaryBase, outputDir)%3B
}
catch (Exception ex)
{
@@ -345,7 +372,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\","").
// Add Android app running log to testOutput
if (ret != CoreclrTestWrapperLib.EXIT_SUCCESS_CODE)
{
- string androidLogFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(testExecutable), "adb-logcat-net.dot." + _Global.category + ".log")%3B
+ string androidLogFile = System.IO.Path.Combine(outputDir, "adb-logcat-net.dot." + _Global.category + "-net.dot.MonoRunner.log")%3B
if(File.Exists(androidLogFile))
{
testOutput.AddRange(System.IO.File.ReadAllLines(androidLogFile))%3B
--
2.7.4