Skip to content

Commit 4ff421c

Browse files
committed
add verify_runtime.ps1 file to process with the column name
remove expected_runtimes.tsv
1 parent ee115db commit 4ff421c

File tree

2 files changed

+57
-65
lines changed

2 files changed

+57
-65
lines changed

test_scripts/test_data/expected_runtimes.tsv

Lines changed: 0 additions & 22 deletions
This file was deleted.

test_scripts/verify_runtime.ps1

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,77 @@
1-
param(
2-
[int] $ExpectedColumn = 8, # 1-based index of the threshold column
3-
[string]$input_file = "test_scripts/test_data/expected_runtimes.tsv"
1+
param (
2+
[string] $ExpectedColumnName = "windows-x86"
43
)
54

6-
$fail_count = 0
7-
$line_num = 0
5+
$WD = "test_scripts/test_data"
6+
$expectedFile = Join-Path $WD "expected_runtime.tsv"
7+
$reportedFile = "time_log.tsv"
8+
$selectedColumnsFile = Join-Path $WD "selected_columns.tsv"
9+
$reportedColumnFile = "$env:TEMP\reported_column.tsv"
10+
$finalFile = Join-Path $WD "combined_with_reported.tsv"
811

9-
Get-Content $input_file | ForEach-Object {
10-
$line = $_.Trim()
11-
$line_num++
12+
# Get the header and find the index of the expected column name
13+
$header = Get-Content $expectedFile -TotalCount 1
14+
$columns = $header -split "`t"
15+
$columnIndex = $columns.IndexOf($ExpectedColumnName)
1216

13-
if ($line_num -eq 1 -or $line -eq "") {
14-
return # skip header or empty line
15-
}
16-
17-
$columns = $line -split "`t"
18-
if ($columns.Count -lt 4) {
19-
Write-Host "Skipping malformed line: $line"
20-
return
21-
}
17+
if ($columnIndex -lt 0) {
18+
Write-Error "Column '$ExpectedColumnName' not found in $expectedFile"
19+
exit 1
20+
}
2221

23-
$iqtree_file = Join-Path "test_scripts/test_data" $columns[0]
24-
$field_name = $columns[1]
25-
$expected_value = [double]$columns[$ExpectedColumn]
26-
$threshold = [double]$columns[2]
22+
# Adjust to 0-based indexing for arrays
23+
$expectedLines = Get-Content $expectedFile | Select-Object -Skip 1
24+
$selectedColumns = foreach ($line in $expectedLines) {
25+
$parts = $line -split "`t"
26+
"$($parts[0])`t$($parts[1])`t$($parts[$columnIndex])"
27+
}
28+
$selectedColumns | Set-Content $selectedColumnsFile
2729

28-
if (-not (Test-Path $iqtree_file)) {
29-
Write-Host "File not found: ${iqtree_file}"
30-
return
31-
}
30+
# Read reported column from time_log.tsv (column 3 = RealTime, 4 = Memory)
31+
$reportedLines = Get-Content $reportedFile | Select-Object -Skip 1
32+
$reportedColumn = foreach ($line in $reportedLines) {
33+
$parts = $line -split "`t"
34+
$parts[1] # column 2 = runtime (0-based index)
35+
}
36+
$reportedColumn | Set-Content $reportedColumnFile
3237

33-
$actual_line = Select-String -Path $iqtree_file -Pattern ([regex]::Escape($field_name))
34-
if (-not $actual_line) {
35-
Write-Host "Field not found in ${iqtree_file}: ${field_name}"
36-
return
37-
}
38+
# Combine both files
39+
$combinedLines = @()
40+
for ($i = 0; $i -lt $selectedColumns.Count; $i++) {
41+
$combinedLines += "$($selectedColumns[$i])`t$($reportedColumn[$i])"
42+
}
43+
$combinedLines | Set-Content $finalFile
3844

39-
$match = [regex]::Match($actual_line.Line, '[-+]?\d+(\.\d+)?([eE][-+]?\d+)?')
45+
# Now compare
46+
$failCount = 0
47+
$finalLines = Get-Content $finalFile
4048

41-
if (-not $match.Success) {
42-
Write-Host "No numeric value found in line: $($actual_line.Line)"
43-
return
44-
}
49+
foreach ($line in $finalLines) {
50+
$parts = $line -split "`t"
51+
$command = $parts[0]
52+
$threshold = [double]$parts[1]
53+
$expected = [double]$parts[2]
54+
$reported = [double]$parts[3]
4555

46-
$actual_value = [double]$match.Value
47-
$highest_value = $expected_value + $threshold
56+
$allowed = $expected + $threshold
57+
$exceededBy = $reported - $expected
4858

49-
if ($actual_value -le $highest_value) {
50-
Write-Host "PASS: ${iqtree_file} -- Expected: ${expected_value}, Reported: ${actual_value}, Threshold: ${threshold}"
59+
if ($reported -gt $allowed) {
60+
Write-Host "$command exceeded the allowed usage."
61+
Write-Host "Expected: $expected S, Threshold: $threshold S, Reported: $reported S"
62+
$failCount++
5163
} else {
52-
Write-Host "FAIL: ${iqtree_file} -- Expected: ${expected_value}, Reported: ${actual_value}, Threshold: ${threshold}"
53-
$fail_count++
64+
Write-Host "$command passed the check."
65+
Write-Host "Expected: $expected S, Threshold: $threshold S, Reported: $reported S"
5466
}
5567
}
5668

5769
Write-Host ""
58-
if ($fail_count -eq 0) {
70+
71+
if ($failCount -eq 0) {
5972
Write-Host "✅ All runtime checks passed."
73+
exit 0
6074
} else {
61-
Write-Host "${fail_count} checks failed."
75+
Write-Host "$failCount checks failed."
6276
exit 1
6377
}

0 commit comments

Comments
 (0)