1 | param(
|
---|
2 | [switch] $GenerateNew = $true,
|
---|
3 | [int] $WaitToStep = 200
|
---|
4 | )
|
---|
5 |
|
---|
6 |
|
---|
7 | $CLog = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'CGen.log'
|
---|
8 | $GoLog = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'GoOut.log'
|
---|
9 |
|
---|
10 | $CExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'a.exe'
|
---|
11 | $GoExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'go-code\go-pge\go-pge.exe'
|
---|
12 |
|
---|
13 |
|
---|
14 | if($GenerateNew) {
|
---|
15 | $CGenProc = Start-Process -FilePath $CExecutable -RedirectStandardOutput $CLog -WorkingDirectory $PSScriptRoot -PassThru
|
---|
16 | $StepReached = $false
|
---|
17 | while(-not $StepReached) {
|
---|
18 | $CGenCont = Get-Content $CLog
|
---|
19 | if($CGenCont | Select-String -Pattern "\*+ StepW: $WaitToStep \*+") {
|
---|
20 | $StepReached = $true
|
---|
21 | }
|
---|
22 | Start-Sleep -Seconds 1
|
---|
23 | }
|
---|
24 |
|
---|
25 | $CGenProc | Stop-Process -ErrorAction SilentlyContinue
|
---|
26 |
|
---|
27 |
|
---|
28 | $GoGenProc = Start-Process -FilePath $GoExecutable -ArgumentList "-pcfg=prob/bench/Pagie_1.cfg -evals=3 -peel=3 -iter=$WaitToStep -init=method1 -grow=method1" -RedirectStandardOutput $GoLog -WorkingDirectory $(Join-Path -Path $PSScriptRoot -ChildPath 'go-code\go-pge') -PassThru
|
---|
29 | $StepReached = $false
|
---|
30 | while(-not $StepReached) {
|
---|
31 | $GoGenCont = Get-Content $GoLog
|
---|
32 | if($GoGenCont | Select-String -Pattern "PS\.step\(\)\s+$($WaitToStep)") {
|
---|
33 | $StepReached = $true
|
---|
34 | }
|
---|
35 | Start-Sleep -Seconds 1
|
---|
36 | }
|
---|
37 | $GoGenProc | Stop-Process -ErrorAction SilentlyContinue
|
---|
38 | }
|
---|
39 |
|
---|
40 | # Read Result
|
---|
41 |
|
---|
42 | function Get-CSteps {
|
---|
43 | param([Object[]] $Content)
|
---|
44 | $ValueList = @{}
|
---|
45 | $CurrentStep = 0
|
---|
46 | foreach($Line in $Content) {
|
---|
47 | if($Line -match "\*+ StepW: (\d+) \*+") {
|
---|
48 | [int]$CurrentStep = $Matches[1]
|
---|
49 | $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList)
|
---|
50 | } elseif($Line -match "push\/pop \(\d+\,\d+\) \((.+)\)") {
|
---|
51 | $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace(' ', '')) | Out-Null
|
---|
52 | }
|
---|
53 | }
|
---|
54 | return $ValueList
|
---|
55 | }
|
---|
56 |
|
---|
57 | function Get-GoSteps {
|
---|
58 | param([Object[]] $Content)
|
---|
59 | $ValueList = @{}
|
---|
60 | $CurrentStep = 0
|
---|
61 | foreach($Line in $Content) {
|
---|
62 | if($Line -match "PS\.step\(\)\s+(\d+)") {
|
---|
63 | [int]$CurrentStep = $Matches[1]
|
---|
64 | $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList)
|
---|
65 | } elseif($Line -match "pop\/push\(\d+\,\d+\)\: (.+)") {
|
---|
66 | $ValueList[$CurrentStep].Add($Matches[1].Trim().Trim('(').Trim(')').Replace(' ', '')) | Out-Null
|
---|
67 | }
|
---|
68 | }
|
---|
69 | return $ValueList
|
---|
70 | }
|
---|
71 |
|
---|
72 | function Compare-Results {
|
---|
73 | param(
|
---|
74 | [string]$First,
|
---|
75 | [string]$Second
|
---|
76 | )
|
---|
77 | $FirstChars = $First.Trim().ToUpper().ToCharArray() | Sort
|
---|
78 | $SecondChars = $Second.Trim().ToUpper().ToCharArray() | Sort
|
---|
79 |
|
---|
80 | [System.Collections.ArrayList]$LeftChars = $SecondChars.Clone()
|
---|
81 | $FirstCharNr = 0
|
---|
82 | foreach($FirstChar in $FirstChars) {
|
---|
83 | $SecondChar = $SecondChars[$FirstCharNr]
|
---|
84 | if($FirstChar -eq $SecondChar) {
|
---|
85 | $LeftChars.Remove($FirstChar)
|
---|
86 | } else {
|
---|
87 | return $false
|
---|
88 | }
|
---|
89 | $FirstCharNr++
|
---|
90 | }
|
---|
91 | return [bool]($LeftChars.Count -eq 0)
|
---|
92 | }
|
---|
93 |
|
---|
94 | $CContent = Get-Content -Path $CLog
|
---|
95 | $GoContent = Get-Content -Path $GoLog
|
---|
96 |
|
---|
97 | $ParseC = Get-CSteps -Content $CContent
|
---|
98 | $ParseGo = Get-GoSteps -Content $GoContent
|
---|
99 |
|
---|
100 | foreach($StepNr in $($ParseGo.Keys | Sort)) {
|
---|
101 | $GoResult = $ParseGo[$StepNr]
|
---|
102 | [System.Collections.ArrayList]$CResult = $ParseC[$StepNr + 1]
|
---|
103 |
|
---|
104 | if($CResult -eq $null -or $CResult.Count -lt 1) {
|
---|
105 | Write-Information "Missing CStep nr. $StepNr"
|
---|
106 | continue
|
---|
107 | }
|
---|
108 | if($GoResult -eq $null -or $GoResult.Count -lt 1) {
|
---|
109 | Write-Information "Missing GoStep nr. $StepNr"
|
---|
110 | continue
|
---|
111 | }
|
---|
112 |
|
---|
113 | $StepResult = $true
|
---|
114 | foreach($GoRes in $GoResult) { # Step Results
|
---|
115 | $State = $false
|
---|
116 | foreach($CRes in $CResult.Clone()) { # Compare every Result with every Step Result
|
---|
117 | Write-Debug "$($GoRes) with $($CRes)"
|
---|
118 | if(Compare-Results -First $GoRes -Second $CRes) {
|
---|
119 | $State = $true
|
---|
120 | $CResult.Remove($CRes)
|
---|
121 | break
|
---|
122 | }
|
---|
123 | }
|
---|
124 | if(-not $State) {
|
---|
125 | $StepResult = $false
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | if($StepResult) {
|
---|
130 | Write-Host "$StepNr OK"
|
---|
131 | } else {
|
---|
132 | Write-Warning "$StepNr failed!"
|
---|
133 | }
|
---|
134 | }
|
---|