|
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" |
4 | 3 | ) |
5 | 4 |
|
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" |
8 | 11 |
|
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) |
12 | 16 |
|
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 | +} |
22 | 21 |
|
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 |
27 | 29 |
|
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 |
32 | 37 |
|
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 |
38 | 44 |
|
39 | | - $match = [regex]::Match($actual_line.Line, '[-+]?\d+(\.\d+)?([eE][-+]?\d+)?') |
| 45 | +# Now compare |
| 46 | +$failCount = 0 |
| 47 | +$finalLines = Get-Content $finalFile |
40 | 48 |
|
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] |
45 | 55 |
|
46 | | - $actual_value = [double]$match.Value |
47 | | - $highest_value = $expected_value + $threshold |
| 56 | + $allowed = $expected + $threshold |
| 57 | + $exceededBy = $reported - $expected |
48 | 58 |
|
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++ |
51 | 63 | } 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" |
54 | 66 | } |
55 | 67 | } |
56 | 68 |
|
57 | 69 | Write-Host "" |
58 | | -if ($fail_count -eq 0) { |
| 70 | + |
| 71 | +if ($failCount -eq 0) { |
59 | 72 | Write-Host "✅ All runtime checks passed." |
| 73 | + exit 0 |
60 | 74 | } else { |
61 | | - Write-Host "❌ ${fail_count} checks failed." |
| 75 | + Write-Host "❌ $failCount checks failed." |
62 | 76 | exit 1 |
63 | 77 | } |
0 commit comments