Skip to content

Commit

Permalink
update runtime tests to work with WASIp2
Browse files Browse the repository at this point in the history
As of this writing, WASIp2 [does not support process exit
statuses](WebAssembly/wasi-cli#11) beyond 0 (success)
and 1 (failure).  To work around this, I've modified the relevant tests to
return 0 on success instead of 100.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
  • Loading branch information
dicej committed Jun 25, 2024
1 parent cc896fe commit 1d1c61f
Show file tree
Hide file tree
Showing 39 changed files with 347 additions and 44 deletions.
2 changes: 2 additions & 0 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ jobs:
displayName: Install wasi-sdk
- script: call $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasmtime.cmd $(Build.SourcesDirectory)\wasm-tools
displayName: Install wasmtime
- script: npm install -g @bytecodealliance/jco
displayName: Install jco

- ${{ if or(eq(parameters.platform, 'browser_wasm_win'), and(eq(parameters.platform, 'wasi_wasm_win'), not(eq(parameters.runtimeFlavor, 'coreclr')))) }}:
# Update machine certs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ set -ex
# [cargo](https://rustup.rs/)
# [curl](https://curl.se/download.html)

# TODO: Upstream the changes in this `wit-bindgen` fork and use a crates.io
# release instead:
# TODO: Use a crates.io release instead of the Git repo once a release
# containing this commit has been created:
cargo install --locked --no-default-features --features csharp-naot \
--git https://github.com/dicej/wit-bindgen --branch dotnet \
--git https://github.com/bytecodealliance/wit-bindgen --rev 266d638f7a9c4535ba5fa1f1bb2e8cc6b5d58667 \
wit-bindgen-cli
curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz
tar xzf v0.2.0.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ set -ex
# [cargo](https://rustup.rs/)
# [curl](https://curl.se/download.html)

# TODO: Upstream the changes in this `wit-bindgen` fork and use a crates.io
# release instead:
# TODO: Use a crates.io release instead of the Git repo once a release
# containing this commit has been created:
cargo install --locked --no-default-features --features csharp-naot \
--git https://github.com/dicej/wit-bindgen --branch dotnet \
--git https://github.com/bytecodealliance/wit-bindgen --rev 266d638f7a9c4535ba5fa1f1bb2e8cc6b5d58667 \
wit-bindgen-cli
curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz
tar xzf v0.2.0.tar.gz
Expand Down
10 changes: 6 additions & 4 deletions src/tests/Common/scripts/nativeaottest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

exename=$(basename $2 .dll)
wasm="$1/native/${exename}.wasm"
mjs="$1/native/${exename}.mjs"

if [ -e "$wasm" ]; then
shift 2
echo wasmtime run -S http "$wasm" "$@"
wasmtime run -S http "$wasm" "$@"
if [ -e "$mjs" ]; then
node "$mjs" "${@:3}"
elif [ -e "$wasm" ]; then
echo wasmtime run -S http "$wasm" "${@:3}"
wasmtime run -S http "$wasm" "${@:3}"
else
chmod +x $1/native/$exename
$_DebuggerFullPath $1/native/$exename "${@:3}"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/CustomMain/CustomMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ static void IncrementExitCode(int amount)
static int Main(string[] args)
{
Console.WriteLine("hello from managed main");
return s_exitCode;
return s_exitCode - 100;
}
}
1 change: 1 addition & 0 deletions src/tests/nativeaot/CustomMain/CustomMain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<!-- TODO-LLVM: Remove when https://github.com/WebAssembly/wasi-sdk/issues/367 is resolved -->
<EmccExtraArgs Condition="'$(TargetOS)' == 'wasi'">-Wl,--export-if-defined=__main_argc_argv</EmccExtraArgs>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<!-- Look for MULTIMODULE_BUILD #define for the more specific incompatible parts -->
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static int Main(string[] args)
if (passed && CoreFXTestLibrary.Internal.Runner.NumPassedTests > 0)
{
CoreFXTestLibrary.Logger.LogInformation("All tests PASSED.");
return 100;
return 0;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class BringUpTest
{
const int Pass = 100;
const int Pass = 0;
const int Fail = -1;

volatile int myField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ServerGarbageCollection>true</ServerGarbageCollection>
<!-- Test infra issue on apple devices: https://github.com/dotnet/runtime/issues/89917 -->
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>
<ItemGroup>
<Compile Include="Exceptions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<CLRTestPriority>0</CLRTestPriority>
<!-- Test infra issue on apple devices: https://github.com/dotnet/runtime/issues/89917 -->
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/tests/nativeaot/SmokeTests/FrameworkStrings/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
throw new Exception();
#endif

return 100;
return 0;

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
<!-- Test infra issue on apple devices: https://github.com/dotnet/runtime/issues/89917 -->
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static unsafe int Main(string[] args)
PrintLine("Hello from C#!");
int tempInt = 0;
int tempInt2 = 0;
StartTest("Address/derefernce test");
StartTest("Address/dereference test");
(*(&tempInt)) = 9;
EndTest(tempInt == 9);

Expand Down Expand Up @@ -437,7 +437,7 @@ private static unsafe int Main(string[] args)
}

PrintLine("Done");
return Success ? 100 : -1;
return Success ? 0 : 1;
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
1 change: 1 addition & 0 deletions src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- IL3049 warns about mismatched signatures; we are intentionally testing they are handled correctly
when the definition is statically linked -->
<NoWarn>$(NoWarn);IL3049;CS8500</NoWarn>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/SmokeTests/PInvoke/PInvoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public static int Main()
TestDifferentModopts();
TestFunctionPointers();

return 100;
return 0;
}

public static void ThrowIfNotEquals<T>(T expected, T actual, string message)
Expand Down
1 change: 1 addition & 0 deletions src/tests/nativeaot/SmokeTests/PInvoke/PInvoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
<!-- Test infra issue on apple devices: https://github.com/dotnet/runtime/issues/89917 -->
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>
<ItemGroup>
<Compile Include="PInvoke.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static int Main()
Console.WriteLine("Preinitialization is disabled in multimodule builds for now. Skipping test.");
#endif

return 100;
return 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
with system C++ runtime library (-lstdc++).
-->
<LinkStandardCPlusPlusLibrary>true</LinkStandardCPlusPlusLibrary>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static int Main()
TestBaseOnlyUsedFromCode.Run();
TestEntryPoint.Run();

return 100;
return 0;
}

class TestReflectionInvoke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<!-- Look for MULTIMODULE_BUILD #define for the more specific incompatible parts -->
<CLRTestTargetUnsupported Condition="'$(IlcMultiModule)' == 'true'">true</CLRTestTargetUnsupported>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>
<ItemGroup>
<Compile Include="Reflection.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>

<IlcTrimMetadata>false</IlcTrimMetadata>
<CLRTestExitCode>0</CLRTestExitCode>
</PropertyGroup>
<ItemGroup>
<Compile Include="Reflection.cs" />
Expand Down
167 changes: 167 additions & 0 deletions src/tests/nativeaot/SmokeTests/SharedLibrary/Library.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Generated by `wit-bindgen` 0.26.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
using System;
using System.Runtime.CompilerServices;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace LibraryWorld {

public interface ILibraryWorld {
static abstract int ReturnsPrimitiveInt();

static abstract bool ReturnsPrimitiveBool();

static abstract uint ReturnsPrimitiveChar();

static abstract void EnsureManagedClassLoaders();

static abstract int CheckSimpleExceptionHandling();

static abstract int CheckSimpleGcCollect();

}

public readonly struct None {}

[StructLayout(LayoutKind.Sequential)]
public readonly struct Result<Ok, Err>
{
public readonly byte Tag;
private readonly object value;

private Result(byte tag, object value)
{
Tag = tag;
this.value = value;
}

public static Result<Ok, Err> ok(Ok ok)
{
return new Result<Ok, Err>(OK, ok!);
}

public static Result<Ok, Err> err(Err err)
{
return new Result<Ok, Err>(ERR, err!);
}

public bool IsOk => Tag == OK;
public bool IsErr => Tag == ERR;

public Ok AsOk
{
get
{
if (Tag == OK)
return (Ok)value;
else
throw new ArgumentException("expected OK, got " + Tag);
}
}

public Err AsErr
{
get
{
if (Tag == ERR)
return (Err)value;
else
throw new ArgumentException("expected ERR, got " + Tag);
}
}

public const byte OK = 0;
public const byte ERR = 1;
}

namespace exports {
public static class LibraryWorld
{

[UnmanagedCallersOnly(EntryPoint = "returns-primitive-int")]
public static unsafe int wasmExportReturnsPrimitiveInt() {

int ret;
ret = LibraryWorldImpl.ReturnsPrimitiveInt();
return ret;

}

[UnmanagedCallersOnly(EntryPoint = "cabi_post_returns-primitive-int")]
public static void cabi_post_wasmExportReturnsPrimitiveInt(int returnValue) {
Console.WriteLine("TODO: cabi_post_returns-primitive-int");
}

[UnmanagedCallersOnly(EntryPoint = "returns-primitive-bool")]
public static unsafe int wasmExportReturnsPrimitiveBool() {

bool ret;
ret = LibraryWorldImpl.ReturnsPrimitiveBool();
return (ret ? 1 : 0);

}

[UnmanagedCallersOnly(EntryPoint = "cabi_post_returns-primitive-bool")]
public static void cabi_post_wasmExportReturnsPrimitiveBool(int returnValue) {
Console.WriteLine("TODO: cabi_post_returns-primitive-bool");
}

[UnmanagedCallersOnly(EntryPoint = "returns-primitive-char")]
public static unsafe int wasmExportReturnsPrimitiveChar() {

uint ret;
ret = LibraryWorldImpl.ReturnsPrimitiveChar();
return ((int)ret);

}

[UnmanagedCallersOnly(EntryPoint = "cabi_post_returns-primitive-char")]
public static void cabi_post_wasmExportReturnsPrimitiveChar(int returnValue) {
Console.WriteLine("TODO: cabi_post_returns-primitive-char");
}

[UnmanagedCallersOnly(EntryPoint = "ensure-managed-class-loaders")]
public static unsafe void wasmExportEnsureManagedClassLoaders() {

LibraryWorldImpl.EnsureManagedClassLoaders();

}

[UnmanagedCallersOnly(EntryPoint = "check-simple-exception-handling")]
public static unsafe int wasmExportCheckSimpleExceptionHandling() {

int ret;
ret = LibraryWorldImpl.CheckSimpleExceptionHandling();
return ret;

}

[UnmanagedCallersOnly(EntryPoint = "cabi_post_check-simple-exception-handling")]
public static void cabi_post_wasmExportCheckSimpleExceptionHandling(int returnValue) {
Console.WriteLine("TODO: cabi_post_check-simple-exception-handling");
}

[UnmanagedCallersOnly(EntryPoint = "check-simple-gc-collect")]
public static unsafe int wasmExportCheckSimpleGcCollect() {

int ret;
ret = LibraryWorldImpl.CheckSimpleGcCollect();
return ret;

}

[UnmanagedCallersOnly(EntryPoint = "cabi_post_check-simple-gc-collect")]
public static void cabi_post_wasmExportCheckSimpleGcCollect(int returnValue) {
Console.WriteLine("TODO: cabi_post_check-simple-gc-collect");
}

}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdlib.h>

/* Done in C so we can avoid initializing the dotnet runtime and hence WASI libc */
/* It would be preferable to do this in C# but the constraints of cabi_realloc and the demands */
/* of WASI libc prevent us doing so. */
/* See https://github.com/bytecodealliance/wit-bindgen/issues/777 */
/* and https://github.com/WebAssembly/wasi-libc/issues/452 */
/* The component model `start` function might be an alternative to this depending on whether it */
/* has the same constraints as `cabi_realloc` */
__attribute__((__weak__, __export_name__("cabi_realloc")))
void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) {
(void) old_size;
if (new_size == 0) return (void*) align;
void *ret = realloc(ptr, new_size);
if (!ret) abort();
return ret;
}
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 1d1c61f

Please sign in to comment.