Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

22 changes: 22 additions & 0 deletions tests/performance/perf_help.ps1
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions tests/performance/perf_pid_lookup.ps1
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions tests/performance/perf_self_lookup.ps1
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions tests/performance/perf_version.ps1
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since build.yml can run ps1 files now, the .bat file is kind of unnecessary since it was just a wrapper. now it will run both which will make workflows 30 seconds slower

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 97b4fd2 - removed the .bat wrapper since CI now runs .ps1 files directly.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
echo Running nested shell stress test...
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0stress_nested_shells.ps1" -MaxDepth 100
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0stress_nested_shells.ps1" -MaxDepth 50
if %ERRORLEVEL% neq 0 (
echo Stress test failed!
exit /b 1
Expand Down
19 changes: 12 additions & 7 deletions tests/performance/stress_nested_shells.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down