[cmdletbinding()] param( [int] $WaitToStep = 200, [string] $BenchName = "Pagie_1", [int] $PeelCnt = 3, [int] $EvalCnt = 3, [ValidateSet("method1","method2", "method3")][string] $InitMethod = "method1", [ValidateSet("method1","method2", "method3")][string] $GrowMethod = "method1", [bool] $Clear ) $GenerateNew = $true $CLog = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "CGen_$($BenchName).log" $GoLog = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "GoOut_$($BenchName).log" $CLogError = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "CGen_$($BenchName).err" $GoLogError = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath "GoOut_$($BenchName).err" $CExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'testmulti.exe' $GoExecutable = Join-Path -Path $(Resolve-Path $PSScriptRoot) -ChildPath 'go-code\go-pge\go-pge.exe' if($GenerateNew) { if(Test-Path $GoLog -Type Leaf) { Remove-Item -Path $GoLog } if(Test-Path $CLog -Type Leaf) { Remove-Item -Path $CLog } if(Test-Path $GoLogError -Type Leaf) { Remove-Item -Path $GoLogError } if(Test-Path $CLogError -Type Leaf) { Remove-Item -Path $CLogError } $CGenProc = Start-Process -FilePath $CExecutable -ArgumentList "$BenchName -evals=$($EvalCnt) -peel=$($PeelCnt) -iter=$($WaitToStep) -init=$($InitMethod) -grow=$($GrowMethod)" -RedirectStandardOutput $CLog -RedirectStandardError $CLogError -WorkingDirectory $PSScriptRoot -PassThru $StepReached = $false while(-not $StepReached) { $CGenCont = Get-Content $CLog if($CGenCont | Select-String -Pattern "\*+ StepW: $WaitToStep \*+") { $StepReached = $true } Start-Sleep -Seconds 1 } $CGenProc | Stop-Process -ErrorAction SilentlyContinue $env:GOGC="off" $env:GODEBUG="cgocheck=0" $env:CGO_ENABLED=1 $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 $StepReached = $false while(-not $StepReached) { $GoGenCont = Get-Content $GoLog if($GoGenCont | Select-String -Pattern "PS\.step\(\)\s+$($WaitToStep)") { $StepReached = $true } Start-Sleep -Seconds 1 } $GoGenProc | Stop-Process -ErrorAction SilentlyContinue } # Read Result function Get-CSteps { param([Object[]] $Content) $ValueList = @{} $CurrentStep = 0 foreach($Line in $Content) { if($Line -match "\*+ StepW: (\d+) \*+") { [int]$CurrentStep = $Matches[1] $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList) } elseif($Line -match "push\/pop \(\d+\,\d+\) (.+)") { $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null } } return $ValueList } function Get-GoSteps { param([Object[]] $Content) $ValueList = @{} $CurrentStep = 0 foreach($Line in $Content) { if($Line -match "PS\.step\(\)\s+(\d+)") { [int]$CurrentStep = $Matches[1] $ValueList[$CurrentStep] = $(New-Object -TypeName System.Collections.ArrayList) } elseif($Line -match "pop\/push\(\d+\,\d+\)\: (.+)") { $ValueList[$CurrentStep].Add($Matches[1].Trim().Replace('(', '').Replace(')', '').Replace(' ', '')) | Out-Null } } return $ValueList } function Compare-Results { param( [string]$First, [string]$Second ) $FirstChars = $First.Trim().ToUpper().ToCharArray() | Sort-Object $SecondChars = $Second.Trim().ToUpper().ToCharArray() | Sort-Object [System.Collections.ArrayList]$LeftChars = $SecondChars.Clone() $FirstCharNr = 0 foreach($FirstChar in $FirstChars) { $SecondChar = $SecondChars[$FirstCharNr] if($FirstChar -eq $SecondChar) { $LeftChars.Remove($FirstChar) } else { return $false } $FirstCharNr++ } return [bool]($LeftChars.Count -eq 0) } $CContent = Get-Content -Path $CLog $GoContent = Get-Content -Path $GoLog $ParseC = Get-CSteps -Content $CContent $ParseGo = Get-GoSteps -Content $GoContent foreach($StepNr in $($ParseGo.Keys | Sort-Object | Where-Object { $_ -ne 0 -and $_ -le $WaitToStep})) { $GoResult = $ParseGo[$StepNr] [System.Collections.ArrayList]$CResult = $ParseC[$StepNr] if($null -eq $CResult -or $CResult.Count -lt 1) { Write-Warning "Missing CStep nr. $StepNr" continue } if($null -eq $GoResult -or $GoResult.Count -lt 1) { Write-Warning "Missing GoStep nr. $StepNr" continue } $StepResult = $true foreach($GoRes in $GoResult) { # Step Results $State = $false foreach($CRes in $CResult.Clone()) { # Compare every Result with every Step Result Write-Output "$($GoRes) with $($CRes)" if(Compare-Results -First $GoRes -Second $CRes) { $State = $true $CResult.Remove($CRes) break } } if(-not $State) { $StepResult = $false } } if($StepResult) { Write-Output "$StepNr OK" } else { Write-Warning "$StepNr failed!" } } if($Clear) { if(Test-Path $GoLog -Type Leaf) { Remove-Item -Path $GoLog } if(Test-Path $CLog -Type Leaf) { Remove-Item -Path $CLog } if(Test-Path $GoLogError -Type Leaf) { Remove-Item -Path $GoLogError } if(Test-Path $CLogError -Type Leaf) { Remove-Item -Path $CLogError } }