Skip to content

Commit

Permalink
[wasm] wasi: Enable library tests on CI (#81052)
Browse files Browse the repository at this point in the history
  • Loading branch information
radical committed Feb 4, 2023
1 parent b494ef9 commit f8daacf
Show file tree
Hide file tree
Showing 67 changed files with 3,076 additions and 361 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
<PropertyGroup Label="CalculateArch">
<_hostArch>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant)</_hostArch>
<BuildArchitecture Condition="'$(BuildArchitecture)' == ''">$(_hostArch)</BuildArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(TargetOS)' == 'browser' or '$(RuntimeIdentifier)' == 'browser-wasm')">wasm</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(TargetOS)' == 'wasi' or '$(RuntimeIdentifier)' == 'wasi-wasm')">wasm</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'arm'">arm</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'armv6'">armv6</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'armel'">armel</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'arm64'">arm64</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'loongarch64'">loongarch64</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 's390x'">s390x</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(_hostArch)' == 'ppc64le'">ppc64le</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(TargetOS)' == 'browser' or '$(RuntimeIdentifier)' == 'browser-wasm')">wasm</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(TargetOS)' == 'wasi' or '$(RuntimeIdentifier)' == 'wasi-wasm')">wasm</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(TargetsMobile)' == 'true'">x64</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
<Platform Condition="'$(Platform)' == '' and '$(InferPlatformFromTargetArchitecture)' == 'true'">$(TargetArchitecture)</Platform>
Expand Down
12 changes: 12 additions & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@
IsNative="true" />
</ItemGroup>

<ItemGroup Label="Wasi" Condition="'$(TargetOS)' == 'wasi'">
<LibrariesRuntimeFiles Include="
$(LibrariesNativeArtifactsPath)src\*.c"
NativeSubDirectory="src"
IsNative="true" />

<LibrariesRuntimeFiles Include="
$(LibrariesNativeArtifactsPath)include\wasm\*.h;"
NativeSubDirectory="include\wasm"
IsNative="true" />
</ItemGroup>

<Error Condition="'@(LibrariesRuntimeFiles)' == ''" Text="The 'libs' subset must be built before building this project." />
</Target>

Expand Down
2 changes: 1 addition & 1 deletion eng/native/gen-buildsys.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if /i "%__Arch%" == "wasm" (
exit /B 1
)

set "WASI_SDK_PATH=%__repoRoot%src\mono\wasi\wasi-sdk"
set "WASI_SDK_PATH=%__repoRoot%\src\mono\wasi\wasi-sdk"
)
:: replace backslash with forward slash and append last slash
set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!"
Expand Down
3 changes: 1 addition & 2 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,13 @@ jobs:
df -h
displayName: Disk Usage before Build
- ${{ if eq(parameters.platform, 'browser_wasm_win') }}:
- ${{ if in(parameters.platform, 'browser_wasm_win', 'wasi_wasm_win') }}:
# Update machine certs
- task: PowerShell@2
displayName: Update machine certs
inputs:
filePath: $(Build.SourcesDirectory)/eng/pipelines/mono/update-machine-certs.ps1


# Build
- ${{ if eq(parameters.isSourceBuild, false) }}:
- ${{ if eq(parameters.isManualCodeQLBuild, true) }}:
Expand Down
20 changes: 20 additions & 0 deletions eng/pipelines/common/platform-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,26 @@ jobs:
buildConfig: ${{ parameters.buildConfig }}
${{ insert }}: ${{ parameters.jobParameters }}

# WASI WebAssembly windows

- ${{ if containsValue(parameters.platforms, 'wasi_wasm_win') }}:
- template: xplat-setup.yml
parameters:
jobTemplate: ${{ parameters.jobTemplate }}
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }}
variables: ${{ parameters.variables }}
osGroup: wasi
archType: wasm
targetRid: wasi-wasm
platform: wasi_wasm_win
shouldContinueOnError: ${{ parameters.shouldContinueOnError }}
jobParameters:
hostedOs: windows
runtimeFlavor: ${{ parameters.runtimeFlavor }}
stagedBuild: ${{ parameters.stagedBuild }}
buildConfig: ${{ parameters.buildConfig }}
${{ insert }}: ${{ parameters.jobParameters }}

# Browser WebAssembly

- ${{ if containsValue(parameters.platforms, 'browser_wasm') }}:
Expand Down
1 change: 0 additions & 1 deletion eng/pipelines/common/templates/wasm-library-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
parameters:
alwaysRun: false
buildAndRunWasi: false
extraBuildArgs: ''
extraHelixArgs: ''
isExtraPlatformsBuild: false
Expand Down
11 changes: 11 additions & 0 deletions eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parameters:
isRollingBuild: false
excludeLibTests: false
excludeNonLibTests: false
excludeOptional: true
debuggerTestsOnly: false

jobs:
Expand Down Expand Up @@ -230,3 +231,13 @@ jobs:
#parameters:
#runProfile: 'v8'
#onlySanityCheck: true

- ${{ if and(ne(parameters.isRollingBuild, true), ne(parameters.excludeOptional, true)) }}:
- template: /eng/pipelines/common/templates/wasm-library-tests.yml
parameters:
platforms:
- wasi_wasm
extraBuildArgs: /p:EnableAggressiveTrimming=true
alwaysRun: ${{ parameters.isWasmOnlyBuild }}
scenarios:
- normal
2 changes: 1 addition & 1 deletion eng/pipelines/libraries/helix-queues-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ jobs:
- (Ubuntu.1804.Amd64)Ubuntu.1804.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-helix-webassembly

# Browser WebAssembly windows
- ${{ if eq(parameters.platform, 'browser_wasm_win') }}:
- ${{ if in(parameters.platform, 'browser_wasm_win', 'wasi_wasm_win') }}:
- (Windows.Amd64.Server2022.Open)windows.amd64.server2022.open@mcr.microsoft.com/dotnet-buildtools/prereqs:windowsservercore-ltsc2022-helix-webassembly

${{ insert }}: ${{ parameters.jobParameters }}
29 changes: 29 additions & 0 deletions eng/pipelines/runtime-wasm-optional.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This is a wrapper yml for `extra-platforms/runtime-extra-platforms-wasm.yml`, which
# has all the wasm jobs. This file is essentially so we can have point
# the pipeline in azdo UI to this, and thus avoid any scheduled triggers

trigger: none

variables:
- template: /eng/pipelines/common/variables.yml

extends:
template: /eng/pipelines/common/templates/pipeline-with-resources.yml
parameters:
stages:
- stage: Build
jobs:

#
# Evaluate paths
#
- template: /eng/pipelines/common/evaluate-default-paths.yml

- template: /eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml
parameters:
isExtraPlatformsBuild: ${{ variables.isExtraPlatformsBuild }}
isWasmOnlyBuild: ${{ variables.isWasmOnlyBuild }}
isRollingBuild: ${{ variables.isRollingBuild }}
excludeLibTests: true
excludeNonLibTests: true
excludeOptional: false
12 changes: 9 additions & 3 deletions eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ extends:
parameters:
platforms:
- browser_wasm
buildAndRunWasi: true
alwaysRun: ${{ variables.isRollingBuild }}
scenarios:
- normal
Expand Down Expand Up @@ -456,12 +455,19 @@ extends:
extraBuildArgs: /p:MonoWasmBuildVariant=perftrace
alwaysRun: ${{ variables.isRollingBuild }}

# BUILD ONLY - WASI/Wasm
- template: /eng/pipelines/common/templates/wasi-build-only.yml
# WASI/WASM

- template: /eng/pipelines/common/templates/wasm-library-tests.yml
parameters:
platforms:
- wasi_wasm
- wasi_wasm_win
nameSuffix: '_Smoke'
extraBuildArgs: /p:EnableAggressiveTrimming=true /p:RunWasmSamples=true
shouldRunSmokeOnly: true
alwaysRun: ${{ variables.isRollingBuild }}
scenarios:
- normal

#
# iOS/tvOS devices - Full AOT + AggressiveTrimming to reduce size
Expand Down
69 changes: 69 additions & 0 deletions eng/testing/WasiRunnerTemplate.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@echo off
setlocal enabledelayedexpansion

:: SetCommands defined in eng\testing\tests.wasi.targets
[[SetCommands]]
[[SetCommandsEcho]]

set EXECUTION_DIR=%~dp0
if [%3] NEQ [] (
set SCENARIO=%3
)

if [%HELIX_WORKITEM_UPLOAD_ROOT%] == [] (
set "XHARNESS_OUT=%EXECUTION_DIR%xharness-output"
) else (
set "XHARNESS_OUT=%HELIX_WORKITEM_UPLOAD_ROOT%\xharness-output"
)

if [%XHARNESS_CLI_PATH%] NEQ [] (
:: When running in CI, we only have the .NET runtime available
:: We need to call the XHarness CLI DLL directly via dotnet exec
set HARNESS_RUNNER=dotnet.exe exec "%XHARNESS_CLI_PATH%"
) else (
set HARNESS_RUNNER=dotnet.exe xharness
)

if [%XHARNESS_COMMAND%] == [] (
set XHARNESS_COMMAND=test
)

if [%XHARNESS_ARGS%] == [] (
set "XHARNESS_ARGS=%ENGINE_ARGS%"
)

if [%PREPEND_PATH%] NEQ [] (
set "PATH=%PREPEND_PATH%:%PATH%"
)

if [%XUNIT_RANDOM_ORDER_SEED%] NEQ [] (
set "WasmXHarnessMonoArgs=%WasmXHarnessMonoArgs% --setenv=XUNIT_RANDOM_ORDER_SEED=%XUNIT_RANDOM_ORDER_SEED%"
)

echo EXECUTION_DIR=%EXECUTION_DIR%
echo SCENARIO=%SCENARIO%
echo XHARNESS_OUT=%XHARNESS_OUT%
echo XHARNESS_CLI_PATH=%XHARNESS_CLI_PATH%
echo HARNESS_RUNNER=%HARNESS_RUNNER%
echo XHARNESS_COMMAND=%XHARNESS_COMMAND%
echo XHARNESS_ARGS=%XHARNESS_ARGS%

:: ========================= BEGIN Test Execution =============================
echo ----- start %DATE% %TIME% =============== To repro directly: =====================================================
echo pushd %EXECUTION_DIR%
:: RunCommands defined in eng\testing\tests.wasi.targets
[[RunCommandsEcho]]
echo popd
echo ===========================================================================================================
pushd %EXECUTION_DIR%
@echo on
:: RunCommands defined in eng\testing\tests.wasi.targets
[[RunCommands]]
set EXIT_CODE=%ERRORLEVEL%
@echo off
popd
echo ----- end %DATE% %TIME% ----- exit code %EXIT_CODE% ----------------------------------------------------------

echo XHarness artifacts: %XHARNESS_OUT%

exit /b %EXIT_CODE%
68 changes: 68 additions & 0 deletions eng/testing/WasiRunnerTemplate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

# SetCommands defined in eng\testing\tests.wasi.targets
[[SetCommands]]
[[SetCommandsEcho]]

EXECUTION_DIR=$(dirname $0)
if [[ -n "$3" ]]; then
SCENARIO=$3
fi

if [[ -z "$HELIX_WORKITEM_UPLOAD_ROOT" ]]; then
XHARNESS_OUT="$EXECUTION_DIR/xharness-output"
else
XHARNESS_OUT="$HELIX_WORKITEM_UPLOAD_ROOT/xharness-output"
fi

if [[ -n "$XHARNESS_CLI_PATH" ]]; then
# When running in CI, we only have the .NET runtime available
# We need to call the XHarness CLI DLL directly via dotnet exec
HARNESS_RUNNER="dotnet exec $XHARNESS_CLI_PATH"
else
HARNESS_RUNNER="dotnet xharness"
fi

if [[ -z "$XHARNESS_COMMAND" ]]; then
XHARNESS_COMMAND="test"
fi

if [[ -z "$XHARNESS_ARGS" ]]; then
XHARNESS_ARGS="$ENGINE_ARGS"
fi

if [[ -n "$PREPEND_PATH" ]]; then
export PATH=$PREPEND_PATH:$PATH
fi

if [[ -n "$XUNIT_RANDOM_ORDER_SEED" ]]; then
WasmXHarnessMonoArgs="${WasmXHarnessMonoArgs} --setenv=XUNIT_RANDOM_ORDER_SEED=${XUNIT_RANDOM_ORDER_SEED}"
fi

echo EXECUTION_DIR=$EXECUTION_DIR
echo SCENARIO=$SCENARIO
echo XHARNESS_OUT=$XHARNESS_OUT
echo XHARNESS_CLI_PATH=$XHARNESS_CLI_PATH
echo HARNESS_RUNNER=$HARNESS_RUNNER
echo XHARNESS_COMMAND=$XHARNESS_COMMAND
echo XHARNESS_ARGS=$XHARNESS_ARGS

pushd $EXECUTION_DIR

# ========================= BEGIN Test Execution =============================
echo ----- start $(date) =============== To repro directly: =====================================================
echo pushd $EXECUTION_DIR
# RunCommands defined in eng\testing\tests.wasi.targets
[[RunCommandsEcho]]
echo popd
echo ===========================================================================================================
pushd $EXECUTION_DIR
# RunCommands defined in eng\testing\tests.wasi.targets
[[RunCommands]]
_exitCode=$?
popd
echo ----- end $(date) ----- exit code $_exitCode ----------------------------------------------------------

echo "XHarness artifacts: $XHARNESS_OUT"

exit $_exitCode

0 comments on commit f8daacf

Please sign in to comment.