-
Notifications
You must be signed in to change notification settings - Fork 59
Add the WASI runtime test target #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bf34885
Added wasi files
mkhamoyan 9de2255
Added wasi files
mkhamoyan 9ba4a17
Removed not needed files
mkhamoyan 07d938f
fix
mkhamoyan 960dd73
Changed hardcoded path
mkhamoyan fd5d872
Removed not needed files and added dir
mkhamoyan eafbf96
Removed some files
mkhamoyan a708cb0
Removed log text
mkhamoyan aeff3df
Refactored
mkhamoyan 613849f
Remove WebServer for wasi
mkhamoyan 253afd0
Delete XHarnessCommandTests.cs
mkhamoyan 0cc4a66
Added back XharnessCommandTests
mkhamoyan 7d7fbf8
Renamed back some of the wasm files
mkhamoyan d2170be
Fix line endings
mkhamoyan ad41692
Delete WebServer file
mkhamoyan bc1f90d
WebServer files changed
mkhamoyan bf185c6
Removed some files
mkhamoyan 590c355
Add engineargs for wasi
mkhamoyan e2a275f
Removed symbolicator from wasi
mkhamoyan 5661f19
Removed not needed code
mkhamoyan 50c616e
Refactored and removed not needed parts
mkhamoyan fd29c39
Removed WasmFileArgument
mkhamoyan 2b41f7e
Refactored
mkhamoyan 56a294e
Merge branch 'dotnet:main' into xharness_wasi
mkhamoyan 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 hidden or 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
32 changes: 32 additions & 0 deletions
32
src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASI/Arguments/WasmEngineArgument.cs
This file contains hidden or 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,32 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasi; | ||
|
|
||
| internal class WasmEngineArgument : Argument<WasmEngine?> | ||
| { | ||
| public WasmEngineArgument() | ||
| : base("engine=|e=", "Specifies the Wasm engine to be used", null) | ||
| { | ||
| } | ||
|
|
||
| public override void Action(string argumentValue) => | ||
| Value = ParseArgument<WasmEngine>("engine", argumentValue); | ||
|
|
||
| // Set WasmTime as default engine | ||
| public override void Validate() => Value ??= WasmEngine.WasmTime; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Specifies a name of a wasm engine used to run WASI application. | ||
| /// </summary> | ||
| internal enum WasmEngine | ||
| { | ||
| /// <summary> | ||
| /// WasmTime | ||
| /// </summary> | ||
| WasmTime, | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASI/Arguments/WasmEngineArguments.cs
This file contains hidden or 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,13 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasi; | ||
|
|
||
| internal class WasmEngineArguments : RepeatableArgument | ||
| { | ||
| public WasmEngineArguments() | ||
| : base("engine-arg=", "Argument to pass to the wasm engine") | ||
| { | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...crosoft.DotNet.XHarness.CLI/CommandArguments/WASI/Arguments/WasmEngineLocationArgument.cs
This file contains hidden or 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,12 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasi; | ||
|
|
||
| internal class WasmEngineLocationArgument : StringArgument | ||
| { | ||
| public WasmEngineLocationArgument() : base("wasm-engine-path=", "Path to the wasm engine to be used. This must correspond to the engine specified with -e") | ||
| { | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/Microsoft.DotNet.XHarness.CLI/CommandArguments/WASI/WasiTestCommandArguments.cs
This file contains hidden or 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,28 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasi; | ||
|
|
||
| internal class WasiTestCommandArguments : XHarnessCommandArguments | ||
| { | ||
| public WasmEngineArgument Engine { get; } = new(); | ||
| public WasmEngineLocationArgument EnginePath { get; } = new(); | ||
| public WasmEngineArguments EngineArgs { get; } = new(); | ||
| public ExpectedExitCodeArgument ExpectedExitCode { get; } = new((int)Common.CLI.ExitCode.SUCCESS); | ||
| public OutputDirectoryArgument OutputDirectory { get; } = new(); | ||
| public TimeoutArgument Timeout { get; } = new(TimeSpan.FromMinutes(15)); | ||
|
|
||
| protected override IEnumerable<Argument> GetArguments() => new Argument[] | ||
| { | ||
| Engine, | ||
| EnginePath, | ||
| EngineArgs, | ||
| OutputDirectory, | ||
| Timeout, | ||
| ExpectedExitCode, | ||
| }; | ||
| } |
153 changes: 153 additions & 0 deletions
153
src/Microsoft.DotNet.XHarness.CLI/Commands/WASI/Engine/WasiTestCommand.cs
This file contains hidden or 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,153 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasi; | ||
| using Microsoft.DotNet.XHarness.CLI.Commands.Wasm; | ||
| using Microsoft.DotNet.XHarness.Common; | ||
| using Microsoft.DotNet.XHarness.Common.CLI; | ||
| using Microsoft.DotNet.XHarness.Common.Execution; | ||
| using Microsoft.DotNet.XHarness.Common.Logging; | ||
| using Microsoft.DotNet.XHarness.Common.Utilities; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.DotNet.XHarness.CLI.Commands.Wasi; | ||
| internal class WasiTestCommand : XHarnessCommand<WasiTestCommandArguments> | ||
| { | ||
| private const string CommandHelp = "Executes tests on WASI using a selected engine"; | ||
|
|
||
| protected override WasiTestCommandArguments Arguments { get; } = new(); | ||
| protected override string CommandUsage { get; } = "wasi test [OPTIONS] -- [ENGINE OPTIONS]"; | ||
| protected override string CommandDescription { get; } = CommandHelp; | ||
|
|
||
| public WasiTestCommand() : base(TargetPlatform.WASI, "test", true, new ServiceCollection(), CommandHelp) | ||
| { | ||
| } | ||
|
|
||
| protected override async Task<ExitCode> InvokeInternal(ILogger logger) | ||
| { | ||
| var processManager = ProcessManagerFactory.CreateProcessManager(); | ||
|
|
||
| string engineBinary = Arguments.Engine.Value switch | ||
| { | ||
| WasmEngine.WasmTime => "wasmtime", | ||
| _ => throw new ArgumentException("Engine not set") | ||
| }; | ||
|
|
||
| if (!string.IsNullOrEmpty(Arguments.EnginePath.Value)) | ||
| { | ||
| engineBinary = Arguments.EnginePath.Value; | ||
| if (Path.IsPathRooted(engineBinary) && !File.Exists(engineBinary)) | ||
| throw new ArgumentException($"Could not find js engine at the specified path - {engineBinary}"); | ||
| } | ||
| else | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| engineBinary = FileUtils.FindFileInPath(engineBinary + ".cmd"); | ||
| } | ||
| } | ||
|
|
||
| var cts = new CancellationTokenSource(); | ||
| try | ||
| { | ||
| logger.LogInformation($"Using wasm engine {Arguments.Engine.Value} from path {engineBinary}"); | ||
| await PrintVersionAsync(Arguments.Engine.Value.Value, engineBinary); | ||
|
|
||
| var engineArgs = new List<string>(); | ||
| engineArgs.AddRange(Arguments.EngineArgs.Value); | ||
| engineArgs.AddRange(PassThroughArguments); | ||
|
|
||
| var xmlResultsFilePath = Path.Combine(Arguments.OutputDirectory, "testResults.xml"); | ||
| File.Delete(xmlResultsFilePath); | ||
|
|
||
| var stdoutFilePath = Path.Combine(Arguments.OutputDirectory, "wasi-console.log"); | ||
| File.Delete(stdoutFilePath); | ||
|
|
||
| var logProcessor = new WasmTestMessagesProcessor(xmlResultsFilePath, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value for the last two parameters can be made |
||
| stdoutFilePath, | ||
| logger); | ||
| var logProcessorTask = Task.Run(() => logProcessor.RunAsync(cts.Token)); | ||
|
|
||
| var processTask = processManager.ExecuteCommandAsync( | ||
| engineBinary, | ||
| engineArgs, | ||
| log: new CallbackLog(m => logger.LogInformation(m.Trim())), | ||
| stdoutLog: new CallbackLog(msg => logProcessor.Invoke(msg)), | ||
| stderrLog: new CallbackLog(logProcessor.ProcessErrorMessage), | ||
| Arguments.Timeout); | ||
|
|
||
| var tasks = new Task[] | ||
| { | ||
| logProcessorTask, | ||
| processTask, | ||
| Task.Delay(Arguments.Timeout) | ||
| }; | ||
|
|
||
| var task = await Task.WhenAny(tasks).ConfigureAwait(false); | ||
| if (task == tasks[^1] || cts.IsCancellationRequested || task.IsCanceled) | ||
| { | ||
| logger.LogError($"Tests timed out after {((TimeSpan)Arguments.Timeout).TotalSeconds}secs"); | ||
| if (!cts.IsCancellationRequested) | ||
| cts.Cancel(); | ||
|
|
||
| return ExitCode.TIMED_OUT; | ||
| } | ||
|
|
||
| if (task.IsFaulted) | ||
| { | ||
| logger.LogError($"task faulted {task.Exception}"); | ||
| throw task.Exception!; | ||
| } | ||
|
|
||
| // if the log processor completed without errors, then the | ||
| // process should be done too, or about to be done! | ||
| var result = await processTask; | ||
| ExitCode logProcessorExitCode = await logProcessor.CompleteAndFlushAsync(); | ||
|
|
||
| if (result.ExitCode != Arguments.ExpectedExitCode) | ||
| { | ||
| logger.LogError($"Application has finished with exit code {result.ExitCode} but {Arguments.ExpectedExitCode} was expected"); | ||
| return ExitCode.GENERAL_FAILURE; | ||
| } | ||
| else | ||
| { | ||
| logger.LogInformation("Application has finished with exit code: " + result.ExitCode); | ||
| // return SUCCESS if logProcess also returned SUCCESS | ||
| return logProcessorExitCode; | ||
| } | ||
| } | ||
| catch (Win32Exception e) when (e.NativeErrorCode == 2) | ||
| { | ||
| logger.LogCritical($"The engine binary `{engineBinary}` was not found"); | ||
| return ExitCode.APP_LAUNCH_FAILURE; | ||
| } | ||
| finally | ||
| { | ||
| if (!cts.IsCancellationRequested) | ||
| { | ||
| cts.Cancel(); | ||
| } | ||
| } | ||
|
|
||
| Task PrintVersionAsync(WasmEngine engine, string engineBinary) | ||
| { | ||
| return processManager.ExecuteCommandAsync( | ||
| engineBinary, | ||
| new[] { "--version" }, | ||
| log: new CallbackLog(m => logger.LogDebug(m.Trim())), | ||
| stdoutLog: new CallbackLog(msg => logger.LogInformation(msg.Trim())), | ||
| stderrLog: new CallbackLog(msg => logger.LogError(msg.Trim())), | ||
| TimeSpan.FromSeconds(10)); | ||
| } | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
src/Microsoft.DotNet.XHarness.CLI/Commands/WASI/WasiCommandSet.cs
This file contains hidden or 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,18 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Mono.Options; | ||
|
|
||
| namespace Microsoft.DotNet.XHarness.CLI.Commands.Wasi; | ||
|
|
||
| // Main WASI command set that contains the platform specific commands. This allows the command line to | ||
| // support different options in different platforms. | ||
| // Whenever the behavior does match, the goal is to have the same arguments for all platforms | ||
| public class WasiCommandSet : CommandSet | ||
| { | ||
| public WasiCommandSet() : base("wasi") | ||
| { | ||
| Add(new WasiTestCommand()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,4 +9,5 @@ public enum TargetPlatform | |
| Android, | ||
| Apple, | ||
| WASM, | ||
| WASI, | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.