| 1 | <# |
| 2 | .SYNOPSIS |
| 3 | Copies linux unit tests to a given WSL distribution and builds them. |
| 4 | .PARAMETER WslTestDirPath |
| 5 | The absolute path to the location of the \wsl-build\test\linux directory. |
| 6 | .PARAMETER DistroName |
| 7 | The name of the WSL distribution to copy and build the tests inside of. |
| 8 | Defaults to "test_distro" |
| 9 | #> |
| 10 | |
| 11 | param ( |
| 12 | [Parameter( ValueFromPipeline = $true, |
| 13 | ValueFromPipelineByPropertyName = $true, |
| 14 | Mandatory = $true, |
| 15 | ParameterSetName = "WslTestDirPath", |
| 16 | HelpMessage = "Path to \wsl-build\test\linux\ location")] |
| 17 | [Parameter( ParameterSetName = "CopyBuildTestAll ")] |
| 18 | [Alias('testpath')] |
| 19 | [string[]]$WslTestDirPath, |
| 20 | [Parameter( ValueFromPipeline = $true, |
| 21 | ValueFromPipelineByPropertyName = $true, |
| 22 | Mandatory = $false, |
| 23 | ParameterSetName = "DistroName", |
| 24 | HelpMessage = "Name of WSL distro to run tests in; defaults to test_distro")] |
| 25 | [Parameter( ParameterSetName = "CopyBuildTestAll ")] |
| 26 | [Alias('distro')] |
| 27 | [string[]]$DistroName = "test_distro" |
| 28 | ) |
| 29 | |
| 30 | $ErrorActionPreference = "Stop" |
| 31 | Set-StrictMode -Version Latest |
| 32 | |
| 33 | function Run { |
| 34 | [CmdletBinding()] |
| 35 | param([ScriptBlock]$cmd) |
| 36 | |
| 37 | Invoke-Command -ScriptBlock $cmd |
| 38 | if ($LastExitCode -ne 0) { |
| 39 | throw ("$cmd failed with exit code: " + $lastexitcode) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | $DistroPath = "$env:LocalAppData\lxss" |
| 44 | |
| 45 | $copyScriptCommand = $PSScriptRoot + "\copy_tests.ps1 -WslTestDirPath $WslTestDirPath -DistroName $DistroName" |
| 46 | |
| 47 | $cleanTestCommand = "rm -rf /data/test" |
| 48 | $buildTestCommand = "cd /data/test; ./build_tests.sh; less /data/test/log/build_output" |
| 49 | |
| 50 | # clean test directory on linux side |
| 51 | Write-Output "Cleaning unit tests at $DistroPath\rootfs\data\test" |
| 52 | Run { wsl.exe --distribution $DistroName --user root --exec bash -c "$cleanTestCommand" } |
| 53 | |
| 54 | # call the logic in copy_tests.ps1 |
| 55 | Invoke-Expression $copyScriptCommand |
| 56 | |
| 57 | # build the tests on the linux side |
| 58 | Write-Output "Building unit tests at $DistroPath\rootfs\data\test\" |
| 59 | Run { wsl.exe --distribution $DistroName --user root --exec bash -c "$buildTestCommand" } |