-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathRegressionVerifier.ps1
More file actions
More file actions
Latest commit
424 lines (350 loc) · 9.18 KB
/
Copy pathRegressionVerifier.ps1
File metadata and controls
424 lines (350 loc) · 9.18 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$ReferenceBuild,
[Parameter(Mandatory = $true)]
[string]$CandidateBuild,
[Parameter(Mandatory = $false)]
[switch]$AllowKnownPrototypeDifferences
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Get-RequiredFile {
param(
[Parameter(Mandatory = $true)]
[string]$Directory,
[Parameter(Mandatory = $true)]
[string]$Name
)
$path = Join-Path $Directory $Name
if (
-not (
Test-Path `
-LiteralPath $path `
-PathType Leaf
)
) {
throw "Missing file: $path"
}
return $path
}
function Get-FileSha256 {
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
return (
Get-FileHash `
-LiteralPath $Path `
-Algorithm SHA256
).Hash.ToLowerInvariant()
}
function Compare-SortedFiles {
param(
[Parameter(Mandatory = $true)]
[string]$ReferencePath,
[Parameter(Mandatory = $true)]
[string]$CandidatePath,
[Parameter(Mandatory = $false)]
[int]$SampleLimit = 100
)
$referenceReader =
[System.IO.StreamReader]::new(
$ReferencePath,
[System.Text.UTF8Encoding]::new($false),
$true,
1048576
)
$candidateReader =
[System.IO.StreamReader]::new(
$CandidatePath,
[System.Text.UTF8Encoding]::new($false),
$true,
1048576
)
$referenceOnly = [long]0
$candidateOnly = [long]0
$referenceSamples =
[System.Collections.Generic.List[string]]::new()
$candidateSamples =
[System.Collections.Generic.List[string]]::new()
try {
$left = $referenceReader.ReadLine()
$right = $candidateReader.ReadLine()
while (
$null -ne $left -or
$null -ne $right
) {
if ($null -eq $right) {
$referenceOnly++
if (
$referenceSamples.Count -lt
$SampleLimit
) {
[void]$referenceSamples.Add(
[string]$left
)
}
$left =
$referenceReader.ReadLine()
continue
}
if ($null -eq $left) {
$candidateOnly++
if (
$candidateSamples.Count -lt
$SampleLimit
) {
[void]$candidateSamples.Add(
[string]$right
)
}
$right =
$candidateReader.ReadLine()
continue
}
$comparison =
[string]::CompareOrdinal(
$left,
$right
)
if ($comparison -eq 0) {
$left =
$referenceReader.ReadLine()
$right =
$candidateReader.ReadLine()
$difference =
Compare-SortedFiles `
-ReferencePath $referenceLabels `
-CandidatePath $candidateLabels
$knownDifferenceAccepted = $false
if ($AllowKnownPrototypeDifferences) {
$knownDifferenceAccepted =
$difference.ReferenceOnly -eq 1 -and
$difference.CandidateOnly -eq 0 -and
$difference.ReferenceOnlySamples.Count -eq 1 -and
$difference.ReferenceOnlySamples[0] -eq
"hluttaw"
}
$result = [pscustomobject]@{
ReferenceBuild = $ReferenceBuild
CandidateBuild = $CandidateBuild
ReferenceLabelHash =
$referenceLabelHash
CandidateLabelHash =
$candidateLabelHash
HashesIdentical =
$referenceLabelHash -eq
$candidateLabelHash
ReferenceOnlyLabels =
$difference.ReferenceOnly
CandidateOnlyLabels =
$difference.CandidateOnly
ReferenceOnlySamples =
$difference.ReferenceOnlySamples
CandidateOnlySamples =
$difference.CandidateOnlySamples
KnownPrototypeDifferenceAccepted =
$knownDifferenceAccepted
ExactMatch =
$difference.ReferenceOnly -eq 0 -and
$difference.CandidateOnly -eq 0
}
$result | Format-List
if (
-not $result.ExactMatch -and
-not $knownDifferenceAccepted
) {
throw (
"The candidate package differs from " +
"the reference package."
)
}
if ($result.ExactMatch) {
Write-Host (
"Regression verification passed: " +
"label files are identical."
) -ForegroundColor Green
}
else {
Write-Host (
"Regression verification passed with " +
"the explicitly allowed prototype difference."
) -ForegroundColor Yellow
}