Skip to content

Commit aadda27

Browse files
Patrick LehmannPatrick Lehmann
authored andcommitted
First test runner implementation for Windows (PowerShell). #1
1 parent b661a05 commit aadda27

File tree

3 files changed

+443
-0
lines changed

3 files changed

+443
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828
!.publish
2929
!.git*
3030

31+
*.cf
32+
JSONTestSuite/config.pkg.vhdl

JSONTestSuite/JSONTestSuite.ps1

Lines changed: 391 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,391 @@
1+
# EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
2+
# vim: tabstop=2:shiftwidth=2:noexpandtab
3+
# kate: tab-width 2; replace-tabs off; indent-width 2;
4+
#
5+
# ==============================================================================
6+
# Authors: Patrick Lehmann
7+
#
8+
# PowerShell Script: Compile JSONTestSuite's JSON files with JSON-for-VHDL
9+
#
10+
# Description:
11+
# ------------------------------------
12+
# TODO
13+
#
14+
# License:
15+
# ==============================================================================
16+
# Copyright 2007-2016 Patrick Lehmann - Dresden, Germany
17+
#
18+
# Licensed under the Apache License, Version 2.0 (the "License");
19+
# you may not use this file except in compliance with the License.
20+
# You may obtain a copy of the License at
21+
#
22+
# http://www.apache.org/licenses/LICENSE-2.0
23+
#
24+
# Unless required by applicable law or agreed to in writing, software
25+
# distributed under the License is distributed on an "AS IS" BASIS,
26+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27+
# See the License for the specific language governing permissions and
28+
# limitations under the License.
29+
# ==============================================================================
30+
31+
# .SYNOPSIS
32+
# This CmdLet compiles the JSONTestSuite with GHDL and QuestaSim.
33+
#
34+
# .DESCRIPTION
35+
# To be written
36+
#
37+
[CmdletBinding()]
38+
param(
39+
# Show the embedded help page(s)
40+
[switch]$Help = $false,
41+
42+
# Run test suite with all simulators
43+
[switch]$All = $false,
44+
# Run test suite with GHDL
45+
[switch]$GHDL = $false,
46+
# # Run test suite with QuestaSim
47+
# [switch]$Questa = $false,
48+
# Clean up directory before analyzing.
49+
[switch]$Clean = $false,
50+
51+
# Set VHDL Standard to '93
52+
[switch]$VHDL93 = $false,
53+
# Set VHDL Standard to '08
54+
[switch]$VHDL2008 = $false,
55+
56+
# Skip warning messages. (Show errors only.)
57+
[switch]$SuppressWarnings = $false,
58+
# Halt on errors
59+
[switch]$HaltOnError = $false,
60+
61+
# Set GHDL executable
62+
[string]$GHDLBinaryDir = ""
63+
)
64+
65+
function Exit-Script
66+
{ <#
67+
.PARAMETER ExitCode
68+
ExitCode of this script run
69+
#>
70+
[CmdletBinding()]
71+
param([int]$ExitCode = 0)
72+
cd $WorkingDir
73+
exit $ExitCode
74+
}
75+
76+
# ---------------------------------------------
77+
# save working directory
78+
$WorkingDir = Get-Location
79+
80+
# Display help if no command was selected
81+
$Help = $Help -or (-not ($All -or $GHDL -or $Questa -or $Clean))
82+
83+
if ($Help)
84+
{ Get-Help $MYINVOCATION.InvocationName -Detailed
85+
Exit-Script
86+
}
87+
if ($All)
88+
{ $GHDL = $true
89+
$Questa = $true
90+
}
91+
92+
# Functions
93+
function Get-GHDLBinary
94+
{ <#
95+
.PARAMETER GHDL
96+
GHDL's binary directory
97+
#>
98+
[CmdletBinding()]
99+
param([string]$GHDL)
100+
101+
if ($GHDL -ne "")
102+
{ $GHDLBinary = $GHDL.TrimEnd("\") + "\ghdl.exe" }
103+
elseif (Test-Path env:GHDL)
104+
{ $GHDLBinary = $env:GHDL.TrimEnd("\") + "\ghdl.exe" }
105+
else
106+
{ $GHDLBinary = "ghdl.exe" }
107+
108+
if (-not (Test-Path $GHDLBinary -PathType Leaf))
109+
{ Write-Host "Use adv. options '-GHDLBinaryDir' to set the GHDL executable." -ForegroundColor Red
110+
Exit-Script -1
111+
}
112+
113+
return $GHDLBinary
114+
}
115+
116+
function Get-VHDLVariables
117+
{ <#
118+
.PARAMETER VHDL93
119+
Undocumented
120+
.PARAMETER VHDL2008
121+
Undocumented
122+
#>
123+
[CmdletBinding()]
124+
param(
125+
[bool]$VHDL93 = $false,
126+
[bool]$VHDL2008 = $true
127+
)
128+
129+
if ($VHDL93)
130+
{ $VHDLVersion = "v93"
131+
$VHDLStandard = "93c"
132+
$VHDLFlavor = "synopsys"
133+
}
134+
elseif ($VHDL2008)
135+
{ $VHDLVersion = "v08"
136+
$VHDLStandard = "08"
137+
$VHDLFlavor = "synopsys"
138+
}
139+
else
140+
{ $VHDLVersion = "v93"
141+
$VHDLStandard = "93c"
142+
$VHDLFlavor = "synopsys"
143+
}
144+
return $VHDLVersion,$VHDLStandard,$VHDLFlavor
145+
}
146+
147+
function Restore-NativeCommandStream
148+
{ <#
149+
.SYNOPSIS
150+
This CmdLet gathers multiple ErrorRecord objects and reconstructs outputs
151+
as a single line.
152+
153+
.DESCRIPTION
154+
This CmdLet collects multiple ErrorRecord objects and emits one String
155+
object per line.
156+
157+
.PARAMETER InputObject
158+
A object stream is required as an input.
159+
#>
160+
[CmdletBinding()]
161+
param([Parameter(ValueFromPipeline=$true)]$InputObject)
162+
163+
begin
164+
{ $LineRemainer = "" }
165+
166+
process
167+
{ if (-not $InputObject)
168+
{ Write-Host "Empty pipeline!" }
169+
elseif ($InputObject -is [System.Management.Automation.ErrorRecord])
170+
{ if ($InputObject.FullyQualifiedErrorId -eq "NativeCommandError")
171+
{ Write-Output $InputObject.ToString() }
172+
elseif ($InputObject.FullyQualifiedErrorId -eq "NativeCommandErrorMessage")
173+
{ $NewLine = $LineRemainer + $InputObject.ToString()
174+
while (($NewLinePos = $NewLine.IndexOf("`n")) -ne -1)
175+
{ Write-Output $NewLine.Substring(0, $NewLinePos)
176+
$NewLine = $NewLine.Substring($NewLinePos + 1)
177+
}
178+
$LineRemainer = $NewLine
179+
}
180+
}
181+
elseif ($InputObject -is [String])
182+
{ Write-Output $InputObject }
183+
else
184+
{ Write-Host "Unsupported object in pipeline stream" }
185+
}
186+
187+
end
188+
{ if ($LineRemainer -ne "")
189+
{ Write-Output $LineRemainer }
190+
}
191+
}
192+
193+
function Write-ColoredGHDLLine
194+
{ <#
195+
.SYNOPSIS
196+
This CmdLet colors GHDL output lines.
197+
198+
.DESCRIPTION
199+
This CmdLet colors GHDL output lines. Warnings are prefixed with 'WARNING: '
200+
in yellow and errors are prefixed with 'ERROR: ' in red.
201+
202+
.PARAMETER InputObject
203+
A object stream is required as an input.
204+
.PARAMETER SuppressWarnings
205+
Skip warning messages. (Show errors only.)
206+
.PARAMETER Indent
207+
Indentation string.
208+
#>
209+
[CmdletBinding()]
210+
param(
211+
[Parameter(ValueFromPipeline=$true)]
212+
$InputObject,
213+
214+
[Parameter(Position=1)]
215+
[switch]$SuppressWarnings = $false,
216+
[Parameter(Position=2)]
217+
[string]$Indent = ""
218+
)
219+
220+
begin
221+
{ $ErrorRecordFound = $false }
222+
223+
process
224+
{ if ($InputObject -is [String])
225+
{ if ($InputObject -match ":\d+:\d+:warning:\s")
226+
{ if (-not $SuppressWarnings)
227+
{ Write-Host "${Indent}WARNING: " -NoNewline -ForegroundColor Yellow
228+
Write-Host $InputObject
229+
}
230+
}
231+
elseif ($InputObject -match ":\d+:\d+:\s")
232+
{ $ErrorRecordFound = $true
233+
Write-Host "${Indent}ERROR: " -NoNewline -ForegroundColor Red
234+
Write-Host $InputObject
235+
}
236+
else
237+
{ Write-Host "${Indent}$InputObject" }
238+
}
239+
else
240+
{ Write-Host "Unsupported object in pipeline stream" }
241+
}
242+
243+
end
244+
{ $ErrorRecordFound }
245+
}
246+
247+
function Start-Analyze
248+
{ <#
249+
.PARAMETER GHDLBinary
250+
Undocumented
251+
.PARAMETER GHDLOptions
252+
Undocumented
253+
.PARAMETER Library
254+
Undocumented
255+
.PARAMETER SourceFiles
256+
Undocumented
257+
.PARAMETER HaltOnError
258+
Undocumented
259+
#>
260+
[CmdletBinding()]
261+
param(
262+
[Parameter(Mandatory=$true)][string]$GHDLBinary,
263+
[Parameter(Mandatory=$true)][string[]]$GHDLOptions,
264+
[Parameter(Mandatory=$true)][string]$Library,
265+
[Parameter(Mandatory=$true)][string]$VHDLVersion,
266+
[Parameter(Mandatory=$true)][string[]]$SourceFiles,
267+
[Parameter(Mandatory=$true)][bool]$HaltOnError
268+
)
269+
Write-Host "Compiling library '$Library' ..." -ForegroundColor Yellow
270+
$ErrorCount = 0
271+
foreach ($File in $SourceFiles)
272+
{ # Write-Host "Analyzing file '$File'" -ForegroundColor DarkCyan
273+
$InvokeExpr = "$GHDLBinary " + ($GHDLOptions -join " ") + " --work=$Library " + $File + " 2>&1"
274+
# Write-Host " $InvokeExpr" -ForegroundColor DarkGray
275+
$ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings
276+
if ($LastExitCode -ne 0)
277+
{ $ErrorCount += 1
278+
if ($HaltOnError)
279+
{ break }
280+
}
281+
}
282+
# return $ErrorCount
283+
}
284+
285+
function Start-Execution
286+
{ <#
287+
.PARAMETER GHDLBinary
288+
Undocumented
289+
.PARAMETER GHDLOptions
290+
Undocumented
291+
.PARAMETER Library
292+
Undocumented
293+
.PARAMETER TopLevel
294+
Undocumented
295+
.PARAMETER HaltOnError
296+
Undocumented
297+
#>
298+
[CmdletBinding()]
299+
param(
300+
[Parameter(Mandatory=$true)][string]$GHDLBinary,
301+
[Parameter(Mandatory=$true)][string[]]$GHDLOptions,
302+
[Parameter(Mandatory=$true)][string]$Library,
303+
[Parameter(Mandatory=$true)][string]$VHDLVersion,
304+
[Parameter(Mandatory=$true)][string]$TopLevel,
305+
[Parameter(Mandatory=$true)][bool]$HaltOnError
306+
)
307+
$ErrorCount = 0
308+
# Write-Host "Executing '$TopLevel'" -ForegroundColor DarkCyan
309+
$InvokeExpr = "$GHDLBinary " + ($GHDLOptions -join " ") + " --work=$Library " + $TopLevel + " 2>&1"
310+
# Write-Host " $InvokeExpr" -ForegroundColor DarkGray
311+
$ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings
312+
if ($LastExitCode -ne 0)
313+
{ $ErrorCount += 1
314+
if ($HaltOnError)
315+
{ break }
316+
}
317+
# return $ErrorCount
318+
}
319+
320+
# Setup directories
321+
322+
# Setup files
323+
$GHDLBinary = Get-GHDLBinary $GHDLBinaryDir
324+
$ConfigPackageFile = "config.pkg.vhdl"
325+
326+
# define global GHDL Options
327+
$VHDLVersion,$VHDLStandard,$VHDLFlavor = Get-VHDLVariables $VHDL93 $VHDL2008
328+
$GHDLAnalyzeOptions = @("-a", "-fexplicit", "-frelaxed-rules", "--mb-comments", "--warn-binding", "--ieee=$VHDLFlavor", "--no-vital-checks", "--std=$VHDLStandard")
329+
$GHDLRunOptions = @("-r", "-fexplicit", "-frelaxed-rules", "--mb-comments", "--warn-binding", "--ieee=$VHDLFlavor", "--no-vital-checks", "--std=$VHDLStandard")
330+
331+
# Cleanup directories
332+
# ==============================================================================
333+
if ($Clean)
334+
{ Write-Host "Cleaning up vendor directory ..." -ForegroundColor Yellow
335+
rm *.cf
336+
}
337+
338+
# Running JSONTestSuite with GHDL
339+
# ==============================================================================
340+
if ($GHDL)
341+
{ $Library = "json"
342+
$SourceFiles = (
343+
"..\vhdl\JSON.pkg.vhdl"
344+
)
345+
346+
$ErrorCount += 0
347+
Start-Analyze $GHDLBinary $GHDLAnalyzeOptions $Library $VHDLVersion $SourceFiles $HaltOnError
348+
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
349+
350+
351+
$SourceDirectory = ".\test_parsing"
352+
$FileNames = dir -Path ./test_parsing *.json | Sort-Object -Property Name
353+
$TestCase = 0
354+
foreach ($File in $FileNames)
355+
{ $TestName = $File.Name.TrimEnd(".json")
356+
$SourceFile = "$SourceDirectory\$File"
357+
358+
$ConfigPackageContent = "package config is`n`tconstant C_JSON_FILE : STRING := `"$SourceFile`";`nend package;"
359+
$ConfigPackageContent | Out-File $ConfigPackageFile -Encoding Ascii
360+
361+
$TestCase += 1
362+
$Library = "test_$TestCase"
363+
$SourceFiles = (
364+
$ConfigPackageFile,
365+
"TopLevel.vhdl"
366+
)
367+
368+
$ErrorCount += 0
369+
Start-Analyze $GHDLBinary $GHDLAnalyzeOptions $Library $VHDLVersion $SourceFiles $HaltOnError
370+
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
371+
372+
Start-Execution $GHDLBinary $GHDLRunOptions $Library $VHDLVersion "TopLevel" $HaltOnError
373+
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
374+
}
375+
376+
Write-Host "--------------------------------------------------------------------------------"
377+
Write-Host "Running JSONTestSuite with GHDL " -NoNewline
378+
if ($ErrorCount -gt 0)
379+
{ Write-Host "[FAILED]" -ForegroundColor Red
380+
Write-Host " $ErrorCount errors"
381+
}
382+
else
383+
{ Write-Host "[SUCCESSFUL]" -ForegroundColor Green }
384+
}
385+
386+
if ($Questa)
387+
{ Write-Host "[ERROR]: Not implemented." -ForegroundColor Red
388+
Exit-Script -1
389+
}
390+
391+
Exit-Script 0

0 commit comments

Comments
 (0)