Skip to content

Commit

Permalink
Add running unit tests to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthysell committed Aug 16, 2024
1 parent d7b5b39 commit 3f04977
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .ado/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pool:
vmImage: 'windows-latest'

jobs:
- template: jobs.yml
- template: build-and-test.yml
166 changes: 166 additions & 0 deletions .ado/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Build and test

jobs:
- job: Build
timeoutInMinutes: 120
displayName: Build Hermes
strategy:
matrix:
DebugX64Uwp:
BuildConfiguration: Debug
BuildPlatform: x64
BuildAppPlatform: UWP
DebugX86Uwp:
BuildConfiguration: Debug
BuildPlatform: x86
BuildAppPlatform: UWP
DebugARM64Uwp:
BuildConfiguration: Debug
BuildPlatform: arm64
BuildAppPlatform: UWP
DebugX64Win32:
BuildConfiguration: Debug
BuildPlatform: x64
BuildAppPlatform: Desktop
DebugX86Win32:
BuildConfiguration: Debug
BuildPlatform: x86
BuildAppPlatform: Desktop
DebugARM64Win32:
BuildConfiguration: Debug
BuildPlatform: arm64
BuildAppPlatform: Desktop
DebugArm64ECWin32:
BuildConfiguration: Debug
BuildPlatform: arm64ec
BuildAppPlatform: Desktop
ReleaseX64Uwp:
BuildConfiguration: Release
BuildPlatform: x64
BuildAppPlatform: UWP
ReleaseX86Uwp:
BuildConfiguration: Release
BuildPlatform: x86
BuildAppPlatform: UWP
ReleaseARM64Uwp:
BuildConfiguration: Release
BuildPlatform: arm64
BuildAppPlatform: UWP
ReleaseX64Win32:
BuildConfiguration: Release
BuildPlatform: x64
BuildAppPlatform: Desktop
ReleaseX86Win32:
BuildConfiguration: Release
BuildPlatform: x86
BuildAppPlatform: Desktop
ReleaseARM64Win32:
BuildConfiguration: Release
BuildPlatform: arm64
BuildAppPlatform: Desktop
ReleaseArm64ECWin32:
BuildConfiguration: Release
BuildPlatform: arm64ec
BuildAppPlatform: Desktop
steps:
- powershell: |
$vsEnvArch = "$(BuildPlatform)".Replace("arm64ec", "arm64")
Write-Host "##vso[task.setvariable variable=vsEnvArch]$vsEnvArch"
displayName: Determine VS Environment Architecture
- task: BatchScript@1
inputs:
filename: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat'
arguments: >
-arch=$(vsEnvArch)
-app_platform=$(BuildAppPlatform)
-vcvars_spectre_libs=spectre
modifyEnvironment: true
displayName: Initialize Visual Studio Environment

- script: mkdir $(Build.ArtifactStagingDirectory)\build
displayName: Create build folder
workingDirectory: $(Build.ArtifactStagingDirectory)

- script: echo ##vso[task.setvariable variable=CmakeGenerateArgs]-DCMAKE_BUILD_TYPE=$(BuildConfiguration) -DHERMES_ENABLE_DEBUGGER=ON -DHERMES_ENABLE_INTL=ON -DHERMESVM_PLATFORM_LOGGING=ON
displayName: Set common CmakeGenerateArgs

- script: echo ##vso[task.setvariable variable=CmakeGenerateArgs]$(CmakeGenerateArgs) -DHERMES_MSVC_USE_PLATFORM_UNICODE_WINGLOB=OFF -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0.17763.0"
displayName: Set UWP CmakeGenerateArgs
condition: and(succeeded(), eq(variables['BuildAppPlatform'], 'UWP'))

- script: echo ##vso[task.setvariable variable=CmakeGenerateArgs]$(CmakeGenerateArgs) -DHERMES_MSVC_ARM64=ON
displayName: Set ARM64/ARM64EC CmakeGenerateArgs
condition: and(succeeded(), startsWith(variables['BuildPlatform'], 'arm64'))

- script: |
echo ##vso[task.setvariable variable=CFLAGS]-arm64EC
echo ##vso[task.setvariable variable=CXXFLAGS]-arm64EC
displayName: Set ARM64EC environment variables
condition: and(succeeded(), eq(variables['BuildPlatform'], 'arm64ec'))
- script: cmake -G Ninja $(CmakeGenerateArgs) $(Build.SourcesDirectory)
displayName: Configure Ninja with Cmake
workingDirectory: $(Build.ArtifactStagingDirectory)\build

- script: ninja hermes hermesc libshared HermesUnitTests
displayName: Build with Ninja
workingDirectory: $(Build.ArtifactStagingDirectory)\build

- script: dir /s /b *.exe *.dll *.pdb
displayName: List all output binaries in build folder
workingDirectory: $(Build.ArtifactStagingDirectory)\build
condition: succeededOrFailed()

- powershell: |
$vsExtensionPath="${env:ProgramFiles}\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\";
$GoogleTestAdapterPath=(Get-ChildItem $vsExtensionPath -Directory | Where-Object -FilterScript {Test-Path (Join-Path -Path $_.FullName -ChildPath "GoogleTestAdapter.Core.dll")}).FullName
# Test the path to the google test adapter
Test-Path -Path $GoogleTestAdapterPath
Write-Debug "Setting Google Test Adapter Path to '$GoogleTestAdapterPath' found in '$vsExtensionPath'"
Write-Host "##vso[task.setvariable variable=GoogleTestAdapterPath]$GoogleTestAdapterPath"
displayName: Set GoogleTestAdapterPath
condition: and(succeeded(), not(startsWith(variables['BuildPlatform'], 'arm'))) # Can't test arm on non-arm machines
- task: VSTest@2
displayName: Run Hermes Unit Tests
inputs:
testSelector: testAssemblies
testAssemblyVer2: |
**\*Tests.exe
pathtoCustomTestAdapters: $(GoogleTestAdapterPath)
searchFolder: $(Build.ArtifactStagingDirectory)\build\unittests
runTestsInIsolation: true
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
publishRunAttachments: true
collectDumpOn: onAbortOnly
vsTestVersion: latest
failOnMinTestsNotRun: true
condition: and(succeeded(), not(startsWith(variables['BuildPlatform'], 'arm'))) # Can't test arm on non-arm machines

- script: mkdir artifacts
displayName: Create artifacts folder
workingDirectory: $(Build.ArtifactStagingDirectory)
condition: succeededOrFailed()

- task: CopyFiles@2
displayName: Copy all binaries from build to the artifacts folder
inputs:
contents: |
'API\hermes_shared\hermes.(dll|pdb)'
'bin\hermes.(exe|pdb)'
'bin\hermesc.(exe|pdb)'
'unittests\**\*Tests.(exe|pdb)'
sourceFolder: $(Build.ArtifactStagingDirectory)\build
targetFolder: $(Build.ArtifactStagingDirectory)\artifacts
condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
displayName: "Publish artifacts"
inputs:
artifactName: HermesArtifacts.
pathtoPublish: $(Build.ArtifactStagingDirectory)\artifacts
condition: succeededOrFailed()
44 changes: 34 additions & 10 deletions .ado/scripts/cibuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ param(
# e.g. "0.0.2209.28001" for pre-release or "0.70.2.0" for release
[String]$FileVersion = "",

[switch]$RunTests,
[switch]$BuildTests,
[switch]$Incremental,
[switch]$UseVS,
[switch]$ConfigureOnly
Expand Down Expand Up @@ -248,7 +248,7 @@ function Invoke-Dll-Build($SourcesPath, $buildPath, $compilerAndToolsBuildPath,
$genArgs = @();
get-CommonArgs $Platform $Configuration $AppPlatform ([ref]$genArgs)

$targets = @('libshared');
$targets = @('all');

$genArgs += '-DHERMES_ENABLE_DEBUGGER=ON'
$genArgs += '-DHERMES_ENABLE_INTL=ON'
Expand Down Expand Up @@ -280,19 +280,36 @@ function Invoke-Dll-Build($SourcesPath, $buildPath, $compilerAndToolsBuildPath,

function Invoke-Test-Build($SourcesPath, $buildPath, $compilerAndToolsBuildPath, $Platform, $Configuration, $AppPlatform, $incrementalBuild) {
$genArgs = @();
get-CommonArgs([ref]$genArgs)
get-CommonArgs $Platform $Configuration $AppPlatform ([ref]$genArgs)

$targets = @('check-hermes');

$genArgs += '-DHERMES_ENABLE_DEBUGGER=On'
$genArgs += '-DHERMES_ENABLE_DEBUGGER=ON'
$genArgs += '-DHERMES_ENABLE_INTL=ON'

if ($AppPlatform -eq "uwp") {
# Link against default ICU libraries in Windows 10.
$genArgs += '-DHERMES_MSVC_USE_PLATFORM_UNICODE_WINGLOB=OFF'
} else {
# Use our custom WinGlob/NLS based implementation of unicode stubs, to avoid depending on the runtime ICU library.
$genArgs += '-DHERMES_MSVC_USE_PLATFORM_UNICODE_WINGLOB=ON'
}

if ($AppPlatform -eq "uwp") {
$genArgs += '-DCMAKE_SYSTEM_NAME=WindowsStore'
$genArgs += '-DCMAKE_SYSTEM_VERSION="10.0.17763"'
$genArgs += '-DCMAKE_SYSTEM_VERSION="10.0.17763.0"'
$genArgs += "-DIMPORT_HERMESC=$compilerAndToolsBuildPath\ImportHermesc.cmake"
} elseif ($Platform -eq "arm64" -or $Platform -eq "arm64ec") {
$genArgs += '-DHERMES_MSVC_ARM64=On'
$genArgs += "-DIMPORT_HERMESC=$compilerAndToolsBuildPath\ImportHermesc.cmake"
}

Invoke-BuildImpl $SourcesPath, $buildPath, $genArgs, @('check-hermes') $incrementalBuild $Platform $Configuration $AppPlatform
if ($Platform -eq "arm64ec") {
$Env:CFLAGS = "-arm64EC"
$Env:CXXFLAGS = "-arm64EC"
}

Invoke-BuildImpl $SourcesPath $buildPath $genArgs $targets $incrementalBuild $Platform $Configuration $AppPlatform
}

function Invoke-BuildAndCopy($SourcesPath, $WorkSpacePath, $OutputPath, $Platform, $Configuration, $AppPlatform) {
Expand All @@ -310,10 +327,6 @@ function Invoke-BuildAndCopy($SourcesPath, $WorkSpacePath, $OutputPath, $Platfor
$buildPath = Join-Path $WorkSpacePath "build\$Triplet"

Invoke-Dll-Build $SourcesPath $buildPath $compilerAndToolsBuildPath $Platform $Configuration $AppPlatform $Incremental.IsPresent

if ($RunTests.IsPresent) {
Invoke-Test-Build $SourcesPath $buildPath $compilerAndToolsBuildPath $Platform $Configuration $AppPlatform $Incremental.IsPresent
}

$finalOutputPath = "$OutputPath\lib\native\$AppPlatform\$Configuration\$Platform";
if (!(Test-Path -Path $finalOutputPath)) {
Expand Down Expand Up @@ -344,6 +357,17 @@ function Invoke-BuildAndCopy($SourcesPath, $WorkSpacePath, $OutputPath, $Platfor
Copy-Item "$buildPath\build.ninja" -Destination $flagsPath -force | Out-Null

Copy-Headers $SourcesPath $WorkSpacePath $OutputPath $Platform $Configuration $AppPlatform $RNDIR

if ($BuildTests.IsPresent) {
# Build should have already happened, no need to build tests separately
# Invoke-Test-Build $SourcesPath $buildPath $compilerAndToolsBuildPath $Platform $Configuration $AppPlatform $Incremental.IsPresent

$unittestsPath = "$OutputPath\unittests"
if (!(Test-Path -Path $unittestsPath)) {
New-Item -ItemType "directory" -Path $unittestsPath | Out-Null
}
Copy-Item "$buildPath\unittests\*" -Include *.exe -Recurse -Destination $unittestsPath -force | Out-Null
}
}

function Copy-Headers($SourcesPath, $WorkSpacePath, $OutputPath, $Platform, $Configuration, $AppPlatform, $RNDIR) {
Expand Down

0 comments on commit 3f04977

Please sign in to comment.