-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Use custom mobile testing API #53871
Merged
fanyang-mono
merged 9 commits into
dotnet:main
from
fanyang-mono:xharness_custom_commands
Jun 10, 2021
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d5b8390
Use custom Android testing API
fanyang-mono ebd00eb
Fix for non-mobile cases
fanyang-mono 33a355a
Use Collection Fixtures for mobile only
fanyang-mono 69a8156
Update src/tests/Common/Coreclr.TestWrapper/MobileAppHandler.cs
fanyang-mono a6f69a4
Update src/tests/Common/Coreclr.TestWrapper/MobileAppHandler.cs
fanyang-mono f0ce338
Update src/tests/run.proj
fanyang-mono c1645d2
Fix the ios app extension
fanyang-mono a6ed79f
Add back Path and remove redundant namespace string
fanyang-mono dd8a199
Add missing class name Path
fanyang-mono File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/tests/Common/Coreclr.TestWrapper/MobileAppHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.IO; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace CoreclrTestLib | ||
{ | ||
public class MobileAppHandler | ||
{ | ||
public void InstallMobileApp(string platform, string category, string testBinaryBase, string reportBase) | ||
{ | ||
HandleMobileApp("install", platform, category, testBinaryBase, reportBase); | ||
} | ||
|
||
public void UninstallMobileApp(string platform, string category, string testBinaryBase, string reportBase) | ||
{ | ||
HandleMobileApp("uninstall", platform, category, testBinaryBase, reportBase); | ||
} | ||
|
||
private static void HandleMobileApp(string action, string platform, string category, string testBinaryBase, string reportBase) | ||
{ | ||
//install or uninstall mobile app | ||
string outputFile = Path.Combine(reportBase, action, $"{category}_{action}.output.txt"); | ||
string errorFile = Path.Combine(reportBase, action, $"{category}_{action}.error.txt"); | ||
string dotnetCmd_raw = System.Environment.GetEnvironmentVariable("__TestDotNetCmd"); | ||
string dotnetCmd; | ||
string xharnessCmd_raw = System.Environment.GetEnvironmentVariable("XHARNESS_CLI_PATH"); | ||
string xharnessCmd; | ||
string cmdStr; | ||
string appExtension; | ||
int timeout = 240000; // Set timeout to 4 mins, because the installation on Android arm64/32 devices could take up to 4 mins on CI | ||
|
||
if(String.IsNullOrEmpty(dotnetCmd_raw)) | ||
{ | ||
dotnetCmd = "dotnet"; | ||
} | ||
else | ||
{ | ||
dotnetCmd = dotnetCmd_raw; | ||
} | ||
|
||
if(String.IsNullOrEmpty(xharnessCmd_raw)) | ||
{ | ||
xharnessCmd = "xharness"; | ||
} | ||
else | ||
{ | ||
xharnessCmd = $"exec {xharnessCmd_raw}"; | ||
} | ||
|
||
if(platform == "android") | ||
{ | ||
appExtension = "apk"; | ||
} | ||
else | ||
{ | ||
appExtension = "ipa"; | ||
fanyang-mono marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
cmdStr = $"{dotnetCmd} {xharnessCmd} {platform} {action} --package-name=net.dot.{category} --app={testBinaryBase}/{category}.{appExtension} --output-directory={reportBase}/install"; | ||
|
||
Directory.CreateDirectory(Path.Combine(reportBase, action)); | ||
var outputStream = new FileStream(outputFile, FileMode.Create); | ||
var errorStream = new FileStream(errorFile, FileMode.Create); | ||
|
||
using (var outputWriter = new StreamWriter(outputStream)) | ||
using (var errorWriter = new StreamWriter(errorStream)) | ||
using (Process process = new Process()) | ||
{ | ||
if (OperatingSystem.IsWindows()) | ||
{ | ||
process.StartInfo.FileName = "cmd.exe"; | ||
} | ||
else | ||
{ | ||
process.StartInfo.FileName = "/bin/bash"; | ||
} | ||
|
||
process.StartInfo.Arguments = ConvertCmd2Arg(cmdStr); | ||
process.StartInfo.UseShellExecute = false; | ||
process.StartInfo.RedirectStandardOutput = true; | ||
process.StartInfo.RedirectStandardError = true; | ||
|
||
DateTime startTime = DateTime.Now; | ||
process.Start(); | ||
|
||
var cts = new CancellationTokenSource(); | ||
Task copyOutput = process.StandardOutput.BaseStream.CopyToAsync(outputStream, 4096, cts.Token); | ||
Task copyError = process.StandardError.BaseStream.CopyToAsync(errorStream, 4096, cts.Token); | ||
|
||
if (process.WaitForExit(timeout)) | ||
{ | ||
Task.WaitAll(copyOutput, copyError); | ||
} | ||
else | ||
{ | ||
//Time out | ||
DateTime endTime = DateTime.Now; | ||
|
||
try | ||
{ | ||
cts.Cancel(); | ||
} | ||
catch {} | ||
|
||
outputWriter.WriteLine("\ncmdLine:{0} Timed Out (timeout in milliseconds: {1}, start: {3}, end: {4})", | ||
cmdStr, timeout, startTime.ToString(), endTime.ToString()); | ||
errorWriter.WriteLine("\ncmdLine:{0} Timed Out (timeout in milliseconds: {1}, start: {3}, end: {4})", | ||
cmdStr, timeout, startTime.ToString(), endTime.ToString()); | ||
|
||
process.Kill(entireProcessTree: true); | ||
} | ||
|
||
outputWriter.Flush(); | ||
errorWriter.Flush(); | ||
} | ||
} | ||
|
||
private static string ConvertCmd2Arg(string cmd) | ||
{ | ||
cmd.Replace("\"", "\"\""); | ||
var result = $"-c \"{cmd}\""; | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greenEkatherine are these 4 minutes valid?