diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63af9a6..d810f08 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,11 +71,26 @@ jobs: exit 1 } - # Run all test .bat files + # Run all test .bat and .ps1 files $env:force_ansi = 1 + + # Run .bat files Get-ChildItem -Path tests -Recurse -Filter *.bat | ForEach-Object { Write-Host "Running test: $($_.FullName)" & $_.FullName - + if ($LASTEXITCODE -ne 0) { + Write-Error "Test failed: $($_.FullName)" + exit 1 + } + } + + # Run .ps1 files + Get-ChildItem -Path tests -Recurse -Filter *.ps1 | ForEach-Object { + Write-Host "Running test: $($_.FullName)" + & $_.FullName + if ($LASTEXITCODE -ne 0) { + Write-Error "Test failed: $($_.FullName)" + exit 1 + } } diff --git a/tests/performance/perf_help.ps1 b/tests/performance/perf_help.ps1 new file mode 100644 index 0000000..6e6e560 --- /dev/null +++ b/tests/performance/perf_help.ps1 @@ -0,0 +1,22 @@ +# Performance test for help command +# Measures time taken to display help information + +Write-Host "Testing help command performance..." -ForegroundColor Yellow + +# Warm-up run +& win-witr --help | Out-Null + +# Measure performance +$result = Measure-Command { + & win-witr --help | Out-Null +} + +Write-Host "Performance: Help command took $($result.TotalMilliseconds)ms" -ForegroundColor Cyan + +# Verify it worked +if ($LASTEXITCODE -ne 0) { + Write-Error "Help command failed" + exit 1 +} + +exit 0 diff --git a/tests/performance/perf_pid_100runs.ps1 b/tests/performance/perf_pid_100runs.ps1 new file mode 100644 index 0000000..f103991 --- /dev/null +++ b/tests/performance/perf_pid_100runs.ps1 @@ -0,0 +1,22 @@ +# Performance test for process lookup - 100 iterations +# Measures time taken for each execution to look up a process by name + +Write-Host "Testing process lookup performance over 100 iterations..." -ForegroundColor Yellow + +# Verify win-witr works before starting measurements +& win-witr win-witr.exe | Out-Null +if ($LASTEXITCODE -ne 0) { + Write-Error "win-witr process lookup failed" + exit 1 +} + +# Run 100 iterations and measure each +Write-Host "Running 100 iterations of win-witr win-witr.exe..." -ForegroundColor Cyan +1..100 | ForEach-Object { + Measure-Command { + & win-witr win-witr.exe | Out-Null + } | Select-Object TotalMilliseconds +} + +Write-Host "Performance test completed successfully!" -ForegroundColor Green +exit 0 diff --git a/tests/performance/perf_pid_lookup.ps1 b/tests/performance/perf_pid_lookup.ps1 new file mode 100644 index 0000000..dc7cdae --- /dev/null +++ b/tests/performance/perf_pid_lookup.ps1 @@ -0,0 +1,33 @@ +# Performance test for PID lookup +# Measures time taken to look up a process by PID + +Write-Host "Testing PID lookup performance..." -ForegroundColor Yellow + +# Get current PowerShell PID +$currentPid = $PID + +# Warm-up run +& win-witr $currentPid | Out-Null + +# Measure performance - average of 5 runs +$measurements = @() +for ($i = 1; $i -le 5; $i++) { + $result = Measure-Command { + & win-witr $currentPid | Out-Null + } + $measurements += $result.TotalMilliseconds +} + +$average = ($measurements | Measure-Object -Average).Average +$min = ($measurements | Measure-Object -Minimum).Minimum +$max = ($measurements | Measure-Object -Maximum).Maximum + +Write-Host "Performance: PID lookup took avg=$([Math]::Round($average, 2))ms, min=$([Math]::Round($min, 2))ms, max=$([Math]::Round($max, 2))ms" -ForegroundColor Cyan + +# Verify it worked +if ($LASTEXITCODE -ne 0) { + Write-Error "PID lookup failed" + exit 1 +} + +exit 0 diff --git a/tests/performance/perf_self_lookup.ps1 b/tests/performance/perf_self_lookup.ps1 new file mode 100644 index 0000000..e36db6e --- /dev/null +++ b/tests/performance/perf_self_lookup.ps1 @@ -0,0 +1,30 @@ +# Performance test for process lookup +# Measures time taken to look up the win-witr process itself + +Write-Host "Testing process lookup performance..." -ForegroundColor Yellow + +# Warm-up run +& win-witr win-witr.exe | Out-Null + +# Measure performance - average of 5 runs +$measurements = @() +for ($i = 1; $i -le 5; $i++) { + $result = Measure-Command { + & win-witr win-witr.exe | Out-Null + } + $measurements += $result.TotalMilliseconds +} + +$average = ($measurements | Measure-Object -Average).Average +$min = ($measurements | Measure-Object -Minimum).Minimum +$max = ($measurements | Measure-Object -Maximum).Maximum + +Write-Host "Performance: Process lookup took avg=$([Math]::Round($average, 2))ms, min=$([Math]::Round($min, 2))ms, max=$([Math]::Round($max, 2))ms" -ForegroundColor Cyan + +# Verify it worked +if ($LASTEXITCODE -ne 0) { + Write-Error "Process lookup failed" + exit 1 +} + +exit 0 diff --git a/tests/performance/perf_version.ps1 b/tests/performance/perf_version.ps1 new file mode 100644 index 0000000..b2d2f6e --- /dev/null +++ b/tests/performance/perf_version.ps1 @@ -0,0 +1,22 @@ +# Performance test for version command +# Measures time taken to display version information + +Write-Host "Testing version command performance..." -ForegroundColor Yellow + +# Warm-up run +& win-witr --version | Out-Null + +# Measure performance +$result = Measure-Command { + & win-witr --version | Out-Null +} + +Write-Host "Performance: Version command took $($result.TotalMilliseconds)ms" -ForegroundColor Cyan + +# Verify it worked +if ($LASTEXITCODE -ne 0) { + Write-Error "Version command failed" + exit 1 +} + +exit 0 diff --git a/tests/performance/stess_nested_shells.bat b/tests/performance/stess_nested_shells.bat deleted file mode 100644 index 54bad0b..0000000 --- a/tests/performance/stess_nested_shells.bat +++ /dev/null @@ -1,9 +0,0 @@ -@echo off -echo Running nested shell stress test... -powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0stress_nested_shells.ps1" -MaxDepth 100 -if %ERRORLEVEL% neq 0 ( - echo Stress test failed! - exit /b 1 -) -echo Stress test passed! -exit /b 0 \ No newline at end of file diff --git a/tests/performance/stress_nested_shells.ps1 b/tests/performance/stress_nested_shells.ps1 index 3751598..b995412 100644 --- a/tests/performance/stress_nested_shells.ps1 +++ b/tests/performance/stress_nested_shells.ps1 @@ -3,23 +3,28 @@ param( [int]$CurrentDepth = 0, [string]$CurrentShell = "powershell" ) -cd D:\a\win-witr\win-witr -# Ensure win-witr.exe is in PATH or current directory +# Find the script directory and navigate to repository root +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$repoRoot = Split-Path -Parent (Split-Path -Parent $scriptDir) +Set-Location $repoRoot + +# Verify win-witr.exe is accessible +if (-not (Test-Path "win-witr.exe" -PathType Leaf) -and -not (Get-Command "win-witr" -ErrorAction SilentlyContinue)) { + Write-Error "win-witr.exe not found in current directory or PATH" + exit 1 +} if ($CurrentDepth -ge $MaxDepth) { # We've reached max depth - run the actual test Write-Host "Reached depth $CurrentDepth - Running stress test..." -ForegroundColor Green # Run the measurement - cd D:\a\win-witr\win-witr - .\win-witr win-witr.exe $result = Measure-Command { - - .\win-witr win-witr.exe + & win-witr win-witr.exe | Out-Null } - Write-Host "Time taken at depth ${CurrentDepth}: $($result.TotalMilliseconds)ms" -ForegroundColor Cyan + Write-Host "Performance: Nested shell lookup at depth $CurrentDepth took $($result.TotalMilliseconds)ms" -ForegroundColor Cyan # Verify it actually worked if ($LASTEXITCODE -ne 0) {