Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/TestResults.ps1 @ 17143

Last change on this file since 17143 was 16666, checked in by hmaislin, 6 years ago

#2929: Modified make / folder structure to build original app, added x86 dll

File size: 8.2 KB
Line 
1[cmdletbinding()]
2param(
3    [int] $WaitToStep = 200,
4    [parameter(Position=0)][string] $BenchName = "Pagie_1",
5    [int] $PeelCnt = 3,
6    [int] $EvalCnt = 3,
7    [ValidateSet("method1","method2", "method3")][string] $InitMethod = "method1",
8    [ValidateSet("method1","method2", "method3")][string] $GrowMethod = "method1",
9    [switch] $NoClear,
10    [switch] $UseExisting,
11    [switch] $i386,
12    [int]$MaxSecondsTimeout = 6000
13)
14
15$GenerateNew = -not $UseExisting.IsPresent
16
17$LogFolder = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "tmplog"
18
19$CLog = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_CGen.log"
20$GoLog = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_GoOut.log"
21
22$CLogError = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_CGen.err"
23$GoLogError = Join-Path -Path $LogFolder -ChildPath "$($BenchName)_GoOut.err"
24
25if($i386.IsPresent) {
26    $CExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\testmulti32.exe'
27    $GoExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\go-pge32.exe'
28} else {
29    $CExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\testmulti.exe'
30    $GoExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\go-pge.exe'
31}
32
33$BenchData = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\data\benchmark'
34$TestDataFile = Join-Path -Path $BenchData -ChildPath "$($BenchName).trn"
35$TrainDataFile = Join-Path -Path $BenchData -ChildPath "$($BenchName).tst"
36
37$ConfigData =  Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'src\go-pge\config\prob\bench'
38$ConfigDataFile = Join-Path -Path $ConfigData -ChildPath "$($BenchName).cfg"
39
40if(-not $(Test-Path -Path $TestDataFile -PathType Leaf) -or -not $(Test-Path -Path $TrainDataFile -PathType Leaf)) {
41    Write-Error "Train/test file does't exist for benchmark: $TestDataFile"
42    exit 4
43}
44if(-not $(Test-Path -Path $ConfigDataFile -PathType Leaf)) {
45    Write-Error "Configfile doesn't exist for benchmark: $ConfigDataFile"
46    exit 4
47}
48
49if($NoClear.IsPresent) {
50    $Clear = $false
51} else {
52    $Clear = $GenerateNew   
53}
54
55$env:GOGC="off"
56$env:GODEBUG="cgocheck=0"
57$env:CGO_ENABLED=1
58
59if(-not $(Test-Path $LogFolder -Type Container)) {
60   New-Item -Path $LogFolder -ItemType Directory -Force
61}
62
63if($GenerateNew -or -not $(Test-Path -Path $CLog)) {
64  if(Test-Path $CLog -Type Leaf) {
65    Remove-Item -Path $CLog
66    }
67   if(Test-Path $CLogError -Type Leaf) {
68      Remove-Item -Path $CLogError
69   }
70    $CGenProc = Start-Process -FilePath $CExecutable -ArgumentList "$BenchName -evals=$($EvalCnt) -peel=$($PeelCnt) -iter=$($WaitToStep) -init=$($InitMethod) -grow=$($GrowMethod)" -RedirectStandardOutput $CLog -RedirectStandardError $CLogError -WorkingDirectory $(Split-Path -Path $GoExecutable -Parent) -PassThru
71    $StepReached = $false
72    $LastLogLength = 0
73    $Timeout = $MaxSecondsTimeout
74    while(-not $StepReached) {
75        $CGenCont = Get-Content $CLog
76        if($CGenCont | Select-String -Pattern "\*+ StepW: $WaitToStep \*+") {
77            $StepReached = $true
78        }
79        if(-not $StepReached -and $LastLogLength -eq $CGenCont.Length) {
80            $Timeout--
81        } else {
82            $Timeout = $MaxSecondsTimeout
83        }
84        if($Timeout -le 0) {
85            $CGenProc | Stop-Process -ErrorAction SilentlyContinue -Force
86            Write-Error "C-data generation timed out!"
87            exit 2
88        }
89        $LastLogLength = $CGenCont.Length
90        Start-Sleep -Seconds 1
91    }
92    $CGenProc  | Stop-Process -ErrorAction SilentlyContinue
93}
94 
95if($GenerateNew -or -not $(Test-Path -Path $GoLog)) {
96   if(Test-Path $GoLogError -Type Leaf) {
97      Remove-Item -Path $GoLogError
98   }
99   if(Test-Path $GoLog -Type Leaf) {
100    Remove-Item -Path $GoLog
101  }
102    $GoGenProc = Start-Process -FilePath $GoExecutable -ArgumentList "-pcfg=prob/bench/$($BenchName).cfg -evals=$($EvalCnt) -peel=$($PeelCnt) -iter=$($WaitToStep) -init=$($InitMethod) -grow=$($GrowMethod)"  -RedirectStandardOutput $GoLog -RedirectStandardError $GoLogError -WorkingDirectory $(Split-Path -Path $GoExecutable -Parent) -PassThru
103    $StepReached = $false
104    $Timeout = $MaxSecondsTimeout
105    $LastLogLength = 0
106    while(-not $StepReached) {
107        $GoGenCont = Get-Content $GoLog
108        if($GoGenCont | Select-String -Pattern "PS\.step\(\)\s+$($WaitToStep)") {
109            $StepReached = $true
110        }
111        if($LastLogLength -eq $CGenCont.Length) {
112            $Timeout--
113        } else {
114            $Timeout = $MaxSecondsTimeout
115        }
116        if(-not $StepReached -and $Timeout -le 0) {
117            $GoGenProc | Stop-Process -ErrorAction SilentlyContinue -Force
118            Write-Error "Go-data generation timed out!"
119            exit 3
120        }
121        $LastLogLength = $CGenCont.Length
122        Start-Sleep -Seconds 1
123    }
124    $GoGenProc | Stop-Process -ErrorAction SilentlyContinue
125}
126
127# Read Result
128
129function Get-CSteps {
130    param([Object[]] $Content)
131    $ValueList = @{}
132    $CurrentStep = 0
133    foreach($Line in $Content) {
134        if($Line -match "\*+ StepW: (\d+) \*+") {
135            [int]$CurrentStep = $Matches[1]
136            $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList)
137        } elseif($Line -match "push\/pop \(\d+\,\d+\) (.+)") {
138            $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null
139        }
140    }
141    return $ValueList
142}
143
144function Get-GoSteps {
145    param([Object[]] $Content)
146    $ValueList = @{}
147    $CurrentStep = 0
148    foreach($Line in $Content) {
149        if($Line -match "PS\.step\(\)\s+(\d+)") {
150            [int]$CurrentStep = $Matches[1]
151            $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList)
152        } elseif($Line -match "pop\/push\(\d+\,\d+\)\: (.+)") {
153            $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null
154        }
155    }
156    return $ValueList
157}
158
159function Compare-Results {
160    param(
161        [string]$First,
162        [string]$Second
163    )
164    $FirstChars = $First.Trim().ToUpper().ToCharArray() | Sort-Object
165    $SecondChars = $Second.Trim().ToUpper().ToCharArray() | Sort-Object
166
167    [System.Collections.ArrayList]$LeftChars = $SecondChars.Clone()
168    $FirstCharNr = 0
169    foreach($FirstChar in $FirstChars) {
170        $SecondChar = $SecondChars[$FirstCharNr]
171        if($FirstChar -eq $SecondChar) {
172            $LeftChars.Remove($FirstChar)
173        } else {
174            return $false
175        }
176        $FirstCharNr++
177    }
178    return [bool]($LeftChars.Count -eq 0)
179}
180
181$CContent = Get-Content -Path $CLog
182$GoContent = Get-Content -Path $GoLog
183
184$ParseC = Get-CSteps -Content $CContent
185$ParseGo = Get-GoSteps -Content $GoContent
186
187for($StepNr = 1; $StepNr -le $WaitToStep; $StepNr++) {
188    $GoResult = $ParseGo[$StepNr]
189    [System.Collections.ArrayList]$CResult = $ParseC[$StepNr]
190    if($null -eq $GoResult -or $null -eq $CResult) {
191        $StepResult = $false
192    } else {
193        $StepResult = $CResult.Count -eq $GoResult.Count
194    }
195    if($StepResult) {   
196        foreach($GoRes in $GoResult) {            # Step Results
197            $State = $false
198            foreach($CRes in $CResult.Clone()) {  # Compare every Result with every Step Result
199                Write-Debug "$($GoRes) with $($CRes)"
200                if(Compare-Results -First $GoRes -Second $CRes) {
201                    $State = $true
202                    $CResult.Remove($CRes)
203                    break
204                }
205            }
206            if(-not $State) {
207                $StepResult = $false
208            }
209        }
210    }
211
212    if($StepResult) {
213        Write-Output "$StepNr OK"
214    } else {
215        Write-Warning "$StepNr failed!"
216    }
217}
218
219if($Clear) {
220    if(Test-Path $GoLog -Type Leaf) {
221        Remove-Item -Path $GoLog
222    }
223    if(Test-Path $CLog -Type Leaf) {
224        Remove-Item -Path $CLog
225    }
226    if(Test-Path $GoLogError -Type Leaf) {
227        Remove-Item -Path $GoLogError
228    }
229    if(Test-Path $CLogError -Type Leaf) {
230        Remove-Item -Path $CLogError
231    }
232}
Note: See TracBrowser for help on using the repository browser.