Skip to content

Commit

Permalink
[wasm] Use latest stable version of chrome for testing (#77133)
Browse files Browse the repository at this point in the history
* Use the latest `stable` chrome version by default
* Install these by default on codespaces

## Details

- Added a new task `GetChromeVersions` to get the latest version
- This is applicable to library tests, debugger tests, and Wasm.Build.Tests
- The channel used for getting the "latest" version is `$(ChromeChannel)=stable`
- And they are installed in `artifacts/bin/chrome`, and `artifacts/bin/chromedriver`
- A newer version is fetched only `$(ChromeVersionCheckThresholdDays)=3` days after the last version check
- This is enabled by default on containers
- And the behavior can be disabled with `$(InstallChromeForTests)=false`.
  • Loading branch information
radical authored Oct 25, 2022
1 parent 5108757 commit 94c9d02
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 134 deletions.
8 changes: 7 additions & 1 deletion eng/pipelines/common/templates/wasm-library-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ jobs:
ne(dependencies.evaluate_paths.outputs.SetPathVars_any_other_than_wasm_wbt_dbg.containsChange, true))
- name: _wasmRunSmokeTestsOnlyArg
value: /p:RunSmokeTestsOnly=${{ eq(parameters.shouldRunSmokeOnly, true) }}
- name: chromeInstallArg
${{ if containsValue(parameters.scenarios, 'wasmtestonbrowser') }}:
value: /p:InstallChromeForTests=true
${{ else }}:
value: ''

jobParameters:
isExtraPlatforms: ${{ parameters.isExtraPlatformsBuild }}
testGroup: innerloop
nameSuffix: LibraryTests${{ parameters.nameSuffix }}
buildArgs: -s mono+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true /p:BrowserHost=$(_hostedOs) $(_wasmRunSmokeTestsOnlyArg) ${{ parameters.extraBuildArgs }}
buildArgs: -s mono+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true /p:BrowserHost=$(_hostedOs) $(_wasmRunSmokeTestsOnlyArg) $(chromeInstallArg) ${{ parameters.extraBuildArgs }}
timeoutInMinutes: 240
# if !alwaysRun, then:
# if this is runtime-wasm (isWasmOnlyBuild):
Expand Down
45 changes: 22 additions & 23 deletions eng/testing/ProvisioningVersions.props
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
<Project>
<!-- Version number to revision number mapping from http://omahaproxy.appspot.com/ and find the closest one in
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/
and https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win_x64/
Eg. latest stable version is 100.0.4896.88 with revision 972766.
but the closest one available in the snapshosts is 972765.
Please make sure to check both platforms as sometimes
the same snapshot might not be available in both of them.
<!--
Set ChromeChannel properties to get the latest versions
-->
<PropertyGroup>
<ChromeChannel>stable</ChromeChannel>

<ChromeOSIdentifier Condition="$([MSBuild]::IsOSPlatform('windows'))">win</ChromeOSIdentifier>
<ChromeOSIdentifier Condition="$([MSBuild]::IsOSPlatform('linux'))">linux</ChromeOSIdentifier>
<ChromeOSIdentifier Condition="$([MSBuild]::IsOSPlatform('mac'))">mac</ChromeOSIdentifier>

<InstallChromeForTests Condition="'$(InstallChromeForTests)' == '' and '$(ChromeOSIdentifier)' == ''">false</InstallChromeForTests>

<ChromeDir>$(ArtifactsBinDir)chrome\</ChromeDir>
<ChromeDriverDir>$(ArtifactsBinDir)chromedriver\</ChromeDriverDir>

<!-- Download all.json to get latest chrome versions, only if the last all.json
is more than 3 days old -->
<ChromeVersionCheckThresholdDays>3</ChromeVersionCheckThresholdDays>

<FirefoxDir>$(ArtifactsBinDir)firefox\</FirefoxDir>
<FirefoxStampFile>$([MSBuild]::NormalizePath($(FirefoxDir), '.install-firefox-$(FirefoxRevision).stamp'))</FirefoxStampFile>
</PropertyGroup>

<PropertyGroup Condition="'$(BrowserHost)' != 'windows'">
<ChromiumRevision>972765</ChromiumRevision>
<ChromiumUrl>https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/$(ChromiumRevision)/chrome-linux.zip</ChromiumUrl>
<ChromeDriverUrl>https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/$(ChromiumRevision)/chromedriver_linux64.zip</ChromeDriverUrl>
<ChromiumDirName>chrome-linux</ChromiumDirName>
<ChromeDriverDirName>chromedriver_linux64</ChromeDriverDirName>
<ChromiumBinaryName>chrome</ChromiumBinaryName>
<FirefoxRevision>97.0.1</FirefoxRevision>
<FirefoxUrl>https://ftp.mozilla.org/pub/firefox/releases/$(FirefoxRevision)/linux-x86_64/en-US/firefox-$(FirefoxRevision).tar.bz2</FirefoxUrl>
<FirefoxBinaryName>firefox</FirefoxBinaryName>
</PropertyGroup>

<PropertyGroup Condition="'$(BrowserHost)' == 'windows'">
<ChromiumRevision>972766</ChromiumRevision>
<ChromiumUrl>https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/$(ChromiumRevision)/chrome-win.zip</ChromiumUrl>
<ChromeDriverUrl>https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/$(ChromiumRevision)/chromedriver_win32.zip</ChromeDriverUrl>
<ChromiumDirName>chrome-win</ChromiumDirName>
<ChromeDriverDirName>chromedriver_win32</ChromeDriverDirName>
<ChromiumBinaryName>chrome.exe</ChromiumBinaryName>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions eng/testing/WasmRunnerTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ if [[ -z "$XHARNESS_ARGS" ]]; then
XHARNESS_ARGS="$JS_ENGINE $JS_ENGINE_ARGS $MAIN_JS"
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
Expand Down
97 changes: 0 additions & 97 deletions eng/testing/provisioning.targets

This file was deleted.

22 changes: 21 additions & 1 deletion eng/testing/tests.wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@
<WasmIgnoreNet6WorkloadInstallErrors Condition="'$(WasmIgnoreNet6WorkloadInstallErrors)' == ''">true</WasmIgnoreNet6WorkloadInstallErrors>
<WasmIgnoreNet6WorkloadInstallErrors Condition="'$(WasmIgnoreNet6WorkloadInstallErrors)' != 'true'">false</WasmIgnoreNet6WorkloadInstallErrors>
<InstallWorkloadUsingArtifactsDependsOn>_GetWorkloadsToInstall;$(InstallWorkloadUsingArtifactsDependsOn)</InstallWorkloadUsingArtifactsDependsOn>
<InstallChromeForTests Condition="'$(InstallChromeForTests)' == '' and
('$(ContinuousIntegrationBuild)' != 'true' or Exists('/.dockerenv')) and
'$(Scenario)' == 'WasmTestOnBrowser'">true</InstallChromeForTests>
</PropertyGroup>

<!-- On CI this is installed as part of pretest, but it should still be installed
for WBT, and debugger tests -->
<Import Project="$(MSBuildThisFileDirectory)wasm-provisioning.targets"
Condition="'$(InstallChromeForTests)' == 'true' and ('$(ContinuousIntegrationBuild)' != 'true' or '$(IsWasmProject)' != 'true')" />

<PropertyGroup Condition="'$(EnableAggressiveTrimming)' == 'true'">
<!-- suppress warnings as these are tests, and not expected to be trim-safe -->
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
Expand All @@ -46,6 +54,9 @@
<BuildAOTTestsOn Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(Scenario)' == 'BuildWasmApps'">helix</BuildAOTTestsOn>
<BuildAOTTestsOn Condition="'$(BuildAOTTestsOnHelix)' == 'true'">helix</BuildAOTTestsOn>
<BuildAOTTestsOn Condition="'$(BuildAOTTestsOn)' == ''">local</BuildAOTTestsOn>

<_WasmBrowserPathForTests Condition="'$(BROWSER_PATH_FOR_TESTS)' != ''">$(BROWSER_PATH_FOR_TESTS)</_WasmBrowserPathForTests>
<_WasmBrowserPathForTests Condition="'$(_WasmBrowserPathForTests)' == '' and '$(InstallChromeForTests)' == 'true'">$(ChromeBinaryPath)</_WasmBrowserPathForTests>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -94,6 +105,7 @@
<_XHarnessArgs >$(_XHarnessArgs) -s dotnet.js.symbols</_XHarnessArgs>
<_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbol-patterns wasm-symbol-patterns.txt</_XHarnessArgs>
<_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbolicator WasmSymbolicator.dll,Microsoft.WebAssembly.Internal.SymbolicatorWrapperForXHarness</_XHarnessArgs>
<_XHarnessArgs Condition="'$(_WasmBrowserPathForTests)' != ''" >$(_XHarnessArgs) &quot;--browser-path=$(_WasmBrowserPathForTests)&quot;</_XHarnessArgs>
<_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)</_XHarnessArgs>

<!-- There two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable -->
Expand Down Expand Up @@ -290,7 +302,8 @@
</ItemGroup>
</Target>

<Target Name="ProvideNodeNpmRestoreScripts" BeforeTargets="GenerateRunScript">

<Target Name="_WasmAddToRunScript" BeforeTargets="GenerateRunScript">
<!-- Combine optional alias on all NodeNpmModule and trim separator where alias is empty -->
<ItemGroup>
<_NodeNpmModuleString Include="%(NodeNpmModule.Identity):%(NodeNpmModule.Alias)" />
Expand All @@ -304,10 +317,17 @@
<ItemGroup Condition="'$(OS)' != 'Windows_NT'">
<SetScriptCommands Include="if [[ &quot;$SCENARIO&quot; == &quot;WasmTestOnNodeJS&quot; || &quot;$SCENARIO&quot; == &quot;wasmtestonnodejs&quot; ]]; then export WasmXHarnessMonoArgs=&quot;$WasmXHarnessMonoArgs --setenv=NPM_MODULES=$(NodeNpmModuleString)&quot;; fi" />
<RunScriptCommands Include="if [[ &quot;$SCENARIO&quot; == &quot;WasmTestOnNodeJS&quot; || &quot;$SCENARIO&quot; == &quot;wasmtestonnodejs&quot; ]]; then npm ci; fi" />

<SetScriptCommands Condition="'$(InstallChromeForTests)' == 'true' and '$(ChromeDriverBinaryPath)' != ''" Include="export PREPEND_PATH=$([System.IO.Path]::GetDirectoryName($(ChromeDriverBinaryPath)))" />
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<SetScriptCommands Include="if /I [%SCENARIO%]==[WasmTestOnNodeJS] ( set &quot;WasmXHarnessMonoArgs=%WasmXHarnessMonoArgs% --setenv=NPM_MODULES^=$(NodeNpmModuleString)&quot; )" />
<RunScriptCommands Include="if /I [%SCENARIO%]==[WasmTestOnNodeJS] ( call npm ci )" />

<SetScriptCommands Condition="'$(InstallChromeForTests)' == 'true' and '$(ChromeDriverBinaryPath)' != ''" Include="set PREPEND_PATH=$([System.IO.Path]::GetDirectoryName($(ChromeDriverBinaryPath)))" />
</ItemGroup>

<ItemGroup>
</ItemGroup>
</Target>

Expand Down
127 changes: 127 additions & 0 deletions eng/testing/wasm-provisioning.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)ProvisioningVersions.props" />

<PropertyGroup Condition="'$(ChromeOSIdentifier)' == 'linux'">
<ChromeDirName>chrome-linux</ChromeDirName>
<ChromeDriverDirName>chromedriver_linux64</ChromeDriverDirName>
<ChromeBinaryName>chrome</ChromeBinaryName>
<ChromeDriverBinaryName>chromedriver</ChromeDriverBinaryName>
<_ChromeOSPrefix>Linux_x64</_ChromeOSPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(ChromeOSIdentifier)' == 'win'">
<ChromeDirName>chrome-win</ChromeDirName>
<ChromeDriverDirName>chromedriver_win32</ChromeDriverDirName>
<ChromeBinaryName>chrome.exe</ChromeBinaryName>
<ChromeDriverBinaryName>chromedriver.exe</ChromeDriverBinaryName>
<_ChromeOSPrefix>Win_x64</_ChromeOSPrefix>
</PropertyGroup>

<PropertyGroup>
<_BrowserStampDir>$(ArtifactsBinDir)\</_BrowserStampDir>
<ChromeBinaryPath>$([MSBuild]::NormalizePath($(ChromeDir), $(ChromeDirName), $(ChromeBinaryName)))</ChromeBinaryPath>
<ChromeDriverBinaryPath>$([MSBuild]::NormalizePath($(ChromeDriverDir), $(ChromeDriverDirName), $(ChromeDriverBinaryName)))</ChromeDriverBinaryPath>
</PropertyGroup>

<Target Name="DownloadAndInstallChrome"
AfterTargets="GetChromeVersion"
Condition="(!Exists($(ChromeStampFile)) or !Exists($(ChromeBinaryPath))) and '$(InstallChromeForTests)' == 'true'">

<RemoveDir Directories="$(ChromeDir)" />

<Message Text="** Installing chrome version $(ChromeVersion), rev: $(ChromeRevision). To disable this set the msuild property InstallChromeForTests=false ."
Importance="High" />

<DownloadFile SourceUrl="$(ChromeUrl)" DestinationFolder="$(ArtifactsObjDir)" SkipUnchangedFiles="false">
<Output TaskParameter="DownloadedFile" PropertyName="_DownloadedFile" />
</DownloadFile>
<Unzip SourceFiles="$(_DownloadedFile)" DestinationFolder="$(ChromeDir)" />

<Error Text="Cannot find chrome at $(ChromeBinaryPath) in the downloaded copy"
Condition="!Exists($(ChromeBinaryPath))" />

<Exec Command="chmod +x $(ChromeBinaryPath)" Condition="!$([MSBuild]::IsOSPlatform('windows'))" />

<Touch Files="$(ChromeStampFile)" AlwaysCreate="true" />
</Target>

<Target Name="DownloadAndInstallChromeDriver"
AfterTargets="GetChromeVersion"
Condition="(!Exists($(ChromeDriverStampFile)) or !Exists($(ChromeDriverBinaryPath))) and '$(InstallChromeForTests)' == 'true'">

<RemoveDir Directories="$(ChromeDriverDir)" />

<Message Text="** Installing chromedriver version $(ChromeVersion), rev: $(ChromeRevision). To disable this set the msuild property InstallChromeForTests=false ."
Importance="High" />

<DownloadFile SourceUrl="$(ChromeDriverUrl)" DestinationFolder="$(ArtifactsObjDir)" SkipUnchangedFiles="false">
<Output TaskParameter="DownloadedFile" PropertyName="_DownloadedFile" />
</DownloadFile>
<Unzip SourceFiles="$(_DownloadedFile)" DestinationFolder="$(ChromeDriverDir)" />

<Error Text="Cannot find chromedriver at $(ChromeDriverBinaryPath) in the downloaded copy"
Condition="!Exists($(ChromeDriverBinaryPath))" />

<Exec Command="chmod +x $(ChromeDriverBinaryPath)" Condition="!$([MSBuild]::IsOSPlatform('windows'))" />

<Touch Files="$(ChromeDriverStampFile)" AlwaysCreate="true" />
</Target>

<Target Name="DownloadAndInstallFirefox"
AfterTargets="Build"
Condition="!Exists($(FirefoxStampFile)) and '$(InstallFirefoxForTests)' == 'true' and !$([MSBuild]::IsOSPlatform('windows'))">
<ItemGroup>
<_StampFile Include="$(_BrowserStampDir).install-firefox*.stamp" />
</ItemGroup>

<Delete Files="@(_StampFile)" />
<RemoveDir Directories="$(FirefoxDir)" />

<DownloadFile SourceUrl="$(FirefoxUrl)" DestinationFolder="$(FirefoxDir)" SkipUnchangedFiles="true">
<Output TaskParameter="DownloadedFile" PropertyName="_DownloadedFile" />
</DownloadFile>
<Exec Command="tar -xf $(_DownloadedFile) -C $(FirefoxDir)"/>
<Exec Command="rm -rf $(_DownloadedFile)"/>

<PropertyGroup>
<_FirefoxBinaryPath>$([MSBuild]::NormalizePath($(FirefoxDir), $(FirefoxBinaryName)))</_FirefoxBinaryPath>
</PropertyGroup>

<Error Text="Cannot find firefox at $(_FirefoxBinaryPath) in the downloaded copy"
Condition="!Exists($(_FirefoxBinaryPath))" />

<Exec Command="chmod +x $(_FirefoxBinaryPath)"/>

<Touch Files="$(FirefoxStampFile)" AlwaysCreate="true" />
</Target>

<UsingTask AssemblyFile="$(WasmBuildTasksAssemblyPath)"
TaskName="Microsoft.WebAssembly.Build.Tasks.GetChromeVersions" />

<Target Name="GetChromeVersion" AfterTargets="Build" Condition="'$(InstallChromeForTests)' == 'true'">
<GetChromeVersions
OSIdentifier="$(ChromeOSIdentifier)"
OSPrefix="$(_ChromeOSPrefix)"
Channel="$(ChromeChannel)"
IntermediateOutputPath="$(ArtifactsObjDir)">
<Output TaskParameter="ChromeVersion" PropertyName="ChromeVersion" />
<Output TaskParameter="V8Version" PropertyName="V8Version" />
<Output TaskParameter="BranchPosition" PropertyName="ChromeRevision" />
<Output TaskParameter="BaseSnapshotUrl" PropertyName="_ChromeBaseSnapshotUrl" />
</GetChromeVersions>

<PropertyGroup Condition="'$(ChromeOSIdentifier)' == 'linux'">
<ChromeUrl>$(_ChromeBaseSnapshotUrl)/chrome-linux.zip</ChromeUrl>
<ChromeDriverUrl>$(_ChromeBaseSnapshotUrl)/chromedriver_linux64.zip</ChromeDriverUrl>
</PropertyGroup>
<PropertyGroup Condition="'$(ChromeOSIdentifier)' == 'win'">
<ChromeUrl>$(_ChromeBaseSnapshotUrl)/chrome-win.zip</ChromeUrl>
<ChromeDriverUrl>$(_ChromeBaseSnapshotUrl)/chromedriver_win32.zip</ChromeDriverUrl>
</PropertyGroup>

<PropertyGroup>
<ChromeStampFile>$([MSBuild]::NormalizePath('$(ChromeDir)', '.install-$(ChromeVersion)-$(ChromeRevision).stamp'))</ChromeStampFile>
<ChromeDriverStampFile>$([MSBuild]::NormalizePath('$(ChromeDriverDir)', '.install-$(ChromeVersion)-$(ChromeRevision).stamp'))</ChromeDriverStampFile>
</PropertyGroup>
</Target>
</Project>
Loading

0 comments on commit 94c9d02

Please sign in to comment.