Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2d38ace

Browse filesBrowse files
committed
context switching
1 parent b3f6541 commit 2d38ace
Copy full SHA for 2d38ace

File tree

Expand file treeCollapse file tree

6 files changed

+211
-75
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+211
-75
lines changed

‎scripts/matrix_testing/CompileFixTool.ps1

Copy file name to clipboardExpand all lines: scripts/matrix_testing/CompileFixTool.ps1
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ param(
1616

1717
# The compiler to use. Valid values are 'clang' and 'arm-clang'.
1818
[Parameter(Mandatory)]
19-
[ValidateSet('clang', 'armclang', 'tiarmclang')]
19+
[ValidateSet('clang', 'armclang', 'tiarmclang', 'gcc')]
2020
[string]
2121
$Configuration
2222
)

‎scripts/matrix_testing/Config.ps1

Copy file name to clipboardExpand all lines: scripts/matrix_testing/Config.ps1
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
$COMPILER_MAPPINGS = @{
22
"cpp" = @{
33
"clang" = "clang++";
4+
"gcc" = "g++";
45
"armclang" = "armclang";
56
"tiarmclang" = "tiarmclang";
67
};
78

89
"c" = @{
910
"clang" = "clang";
11+
"gcc" = "gcc";
1012
};
1113
}
1214

1315
$COMPILER_ARGS = @{
1416
"cpp" = @{
1517
"clang" = "-std=c++14 -fsyntax-only";
18+
"gcc" = "-std=c++14 -fsyntax-only";
1619
"armclang" = "-std=c++14 -fsyntax-only --target=arm-arm-none-eabi";
1720
"tiarmclang" = "-std=c++14 -fsyntax-only --target=arm-arm-none-eabi";
1821
};
1922

2023
"c" = @{
24+
"gcc" = "-fsyntax-only";
2125
"clang" = "-fsyntax-only";
26+
2227
};
2328

2429
}

‎scripts/matrix_testing/CreateMatrixTestReport.ps1

Copy file name to clipboardExpand all lines: scripts/matrix_testing/CreateMatrixTestReport.ps1
+95-74Lines changed: 95 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ param(
142142

143143
# The compiler to use. Valid values are 'clang' and 'arm-clang'.
144144
[Parameter(Mandatory)]
145-
[ValidateSet('clang', 'armclang', 'tiarmclang')]
145+
[ValidateSet('clang', 'armclang', 'tiarmclang', 'gcc')]
146146
[string]
147147
$Configuration,
148148

@@ -283,6 +283,9 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
283283
#. "$using:PSScriptRoot/GetTestDirectory.ps1"
284284
. "$using:PSScriptRoot/NewDatabaseForRule.ps1"
285285
. "$using:PSScriptRoot/ExecuteQueryAndDecodeAsJson.ps1"
286+
. "$using:PSScriptRoot/Get-CompilerSpecificFiles.ps1"
287+
. "$using:PSScriptRoot/Pop-CompilerSpecificFiles.ps1"
288+
. "$using:PSScriptRoot/Push-CompilerSpecificFiles.ps1"
286289

287290
$q = $_
288291

@@ -314,82 +317,100 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
314317

315318
$testDirectory = (Get-TestDirectory -RuleObject $q -Language $using:Language)
316319

317-
Write-Host "Compiling database in $testDirectory..." -NoNewline
318-
319320
try {
320-
$db = New-Database-For-Rule -RuleName $CurrentRuleName -RuleTestDir $testDirectory -Configuration $using:Configuration -Language $using:Language
321-
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
322-
}
323-
catch {
324-
Write-Host -ForegroundColor ([ConsoleColor]4) "FAILED"
325-
$row["COMPILE_ERROR_OUTPUT"] = $_
326-
327-
return $row # although it is unlikely to succeed with the next rule skipping to the next rule
328-
# ensures all of the rules will be reported in the
329-
# output.
330-
}
331-
332-
$row["COMPILE_PASS"] = $true
333-
334-
Write-Host "Checking expected output..."
335-
336-
# Dragons below 🐉🐉🐉
337-
#
338-
# Note this technique uses so-called "wizard" settings to make it possible
339-
# to compare hand compiled databases using qltest. The relative paths and
340-
# other options are required to be set as below (especially the detail about
341-
# the relative path of the dataset and the test).
342-
343-
# the "dataset" should be the `db-cpp` directory inside the database
344-
# directory. HOWEVER. It should be the path relative to the test directory.
345-
346-
$rulePath = Resolve-Path $testDirectory
347-
$dbPath = Resolve-Path $db
348-
349-
Write-Host "Resolving database $dbPath relative to test directory $rulePath"
350-
$dataset = Resolve-Path (Join-Path $dbPath "db-cpp")
351-
352-
Push-Location $rulePath
353-
$datasetRelPath = Resolve-Path -Relative $dataset
354-
Pop-Location
355-
356-
Write-Host "Using relative path: $datasetRelPath"
357-
358-
# Actually do the qltest run.
359-
# codeql test run <qltest file> --dataset "relpath"
360-
361-
if ($q.shared_implementation_short_name) {
362-
$qlRefFile = Join-Path $rulePath "$($q.shared_implementation_short_name).ql"
363-
}
364-
else {
365-
$qlRefFile = Join-Path $rulePath "$CurrentQueryName.qlref"
366-
}
367-
368-
Write-Host "codeql test run $qlRefFile --dataset=`"$datasetRelPath`""
369-
370-
$stdOut = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
371-
$stdErr = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
372-
373-
374-
Write-Host "Standard Out Buffered to: $stdOut"
375-
Write-Host "Standard Error Buffered to: $stdErr"
376-
377-
$procDetails = Start-Process -FilePath "codeql" -PassThru -NoNewWindow -Wait -ArgumentList "test run $qlRefFile --dataset=`"$datasetRelPath`"" -RedirectStandardOutput $stdOut -RedirectStandardError $stdErr
378-
379-
if (-Not $procDetails.ExitCode -eq 0) {
380-
381-
Write-Host -ForegroundColor ([ConsoleColor]4) "FAILED"
382-
Get-Content $stdOut | Out-String | Write-Host
383-
384-
$row["TEST_DIFFERENCE"] = Get-Content $stdOut | Out-String
321+
###########################################################
322+
###########################################################
323+
# Push context
324+
###########################################################
325+
$context = Push-CompilerSpecificFiles -Configuration $using:Configuration -Language $using:Language -FileSet (Get-CompilerSpecificFiles -TestDirectory $testDirectory)
326+
327+
Write-Host "Compiling database in $testDirectory..." -NoNewline
328+
329+
try {
330+
$db = New-Database-For-Rule -RuleName $CurrentRuleName -RuleTestDir $testDirectory -Configuration $using:Configuration -Language $using:Language
331+
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
332+
}
333+
catch {
334+
Write-Host -ForegroundColor ([ConsoleColor]4) "FAILED"
335+
$row["COMPILE_ERROR_OUTPUT"] = $_
336+
337+
return $row # although it is unlikely to succeed with the next rule skipping to the next rule
338+
# ensures all of the rules will be reported in the
339+
# output.
340+
}
341+
342+
$row["COMPILE_PASS"] = $true
343+
344+
Write-Host "Checking expected output..."
345+
346+
# Dragons below 🐉🐉🐉
347+
#
348+
# Note this technique uses so-called "wizard" settings to make it possible
349+
# to compare hand compiled databases using qltest. The relative paths and
350+
# other options are required to be set as below (especially the detail about
351+
# the relative path of the dataset and the test).
352+
353+
# the "dataset" should be the `db-cpp` directory inside the database
354+
# directory. HOWEVER. It should be the path relative to the test directory.
355+
356+
$rulePath = Resolve-Path $testDirectory
357+
$dbPath = Resolve-Path $db
358+
359+
Write-Host "Resolving database $dbPath relative to test directory $rulePath"
360+
$dataset = Resolve-Path (Join-Path $dbPath "db-cpp")
361+
362+
Push-Location $rulePath
363+
$datasetRelPath = Resolve-Path -Relative $dataset
364+
Pop-Location
365+
366+
Write-Host "Using relative path: $datasetRelPath"
367+
368+
# Actually do the qltest run.
369+
# codeql test run <qltest file> --dataset "relpath"
370+
371+
if ($q.shared_implementation_short_name) {
372+
$qlRefFile = Join-Path $rulePath "$($q.shared_implementation_short_name).ql"
373+
}
374+
else {
375+
$qlRefFile = Join-Path $rulePath "$CurrentQueryName.qlref"
376+
}
377+
378+
Write-Host "codeql test run $qlRefFile --dataset=`"$datasetRelPath`""
379+
380+
$stdOut = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
381+
$stdErr = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
382+
383+
384+
Write-Host "Standard Out Buffered to: $stdOut"
385+
Write-Host "Standard Error Buffered to: $stdErr"
386+
387+
$procDetails = Start-Process -FilePath "codeql" -PassThru -NoNewWindow -Wait -ArgumentList "test run $qlRefFile --dataset=`"$datasetRelPath`"" -RedirectStandardOutput $stdOut -RedirectStandardError $stdErr
388+
389+
if (-Not $procDetails.ExitCode -eq 0) {
390+
391+
Write-Host -ForegroundColor ([ConsoleColor]4) "FAILED"
392+
Get-Content $stdOut | Out-String | Write-Host
393+
394+
$row["TEST_DIFFERENCE"] = Get-Content $stdOut | Out-String
395+
396+
}
397+
else {
398+
$row["TEST_PASS"] = $true
399+
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
400+
}
401+
402+
return $row
403+
}catch {
404+
Write-Host "Unknown error processing rule."
405+
return $row
406+
}finally {
385407

408+
###########################################################
409+
###########################################################
410+
# Context is restored here
411+
###########################################################
412+
Pop-CompilerSpecificFiles -Context $context
386413
}
387-
else {
388-
$row["TEST_PASS"] = $true
389-
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
390-
}
391-
392-
return $row
393414
}
394415

395416
# combine the outputs
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
. "$PSScriptRoot/Config.ps1"
2+
function Get-CompilerSpecificFiles {
3+
param([Parameter(Mandatory)]
4+
[string]
5+
$Configuration,
6+
[Parameter(Mandatory)]
7+
[ValidateSet('c', 'cpp')]
8+
[string]
9+
$TestDirectory
10+
)
11+
12+
#
13+
# Convention is as follows:
14+
#
15+
# For test files:
16+
#
17+
# file.c/cpp is used for ALL compilers
18+
# file.c.<configuration>/file.cpp.<configuration> is used for <configuration>
19+
#
20+
# file.expected is used for all compilers
21+
# file.expected.<configuration> is used for <configuration>
22+
$sourceFiles = Get-ChildItem -Filter "*.$Language.$Configuration"
23+
24+
$expectedFiles = Get-ChildItem -Filter "*.expected.$Configuration"
25+
26+
return $sourceFiles + $expectedFiles
27+
}
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
. "$PSScriptRoot/Config.ps1"
2+
function Pop-CompilerSpecificFiles {
3+
param([Parameter(Mandatory)]
4+
$Context
5+
)
6+
7+
foreach($c in $Context){
8+
9+
$origin = $context.origin
10+
$temp = $context.temp
11+
12+
if(-Not $temp -eq $null){
13+
Write-Host "Restoring $temp -> $origin"
14+
Move-Item -Force -Path $temp $origin
15+
}else {
16+
# otherwise we just need to delete the origin
17+
Write-Host "Removing unneeded context item $origin"
18+
Remove-Item -Force $origin
19+
}
20+
}
21+
22+
}
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
. "$PSScriptRoot/Config.ps1"
2+
function Push-CompilerSpecificFiles {
3+
param([Parameter(Mandatory)]
4+
[System.IO.FileSystemInfo[]]
5+
$FileSet,
6+
[string]
7+
$Configuration,
8+
[Parameter(Mandatory)]
9+
[ValidateSet('c', 'cpp')]
10+
$Language
11+
)
12+
13+
$context = @()
14+
15+
16+
# for each file, move it to a temporary location
17+
foreach($f in $FileSet){
18+
19+
#
20+
# Convention is as follows:
21+
#
22+
# For test files:
23+
#
24+
# file.c/cpp is used for ALL compilers
25+
# file.c.<configuration>/file.cpp.<configuration> is used for <configuration>
26+
#
27+
# file.expected is used for all compilers
28+
# file.expected.<configuration> is used for <configuration>
29+
30+
$tmp = New-TemporaryFile
31+
32+
#
33+
# Note -- it is not necessary for the file we are going to replace
34+
# to exist. If it DOES NOT exist, we simply delete the compiler specific
35+
# file afterwards.
36+
37+
# transform the compiler specific file to the generic one
38+
$originFile = Get-Item $f.FullName.Replace(".$Configuration", "")
39+
40+
# IF it exists, copy the originFile to a temp location and replace it
41+
# with the specific file.
42+
if($originFile.Exists){
43+
Write-Host "Moving generic file $originFile to $tmp..."
44+
Move-Item -Force -Path $originFile -Destination $tmp
45+
Write-Host "Copying $f to generic file $originFile"
46+
Copy-Item -Path $f -Destination $originFile
47+
48+
$context += @{"origin"=$originFile; "temp"=$tmp;}
49+
}else{
50+
Write-Host "Copying $f to generic file $originFile"
51+
Copy-Item -Path $f -Destination $originFile
52+
53+
# we set $temp to $null since we don't want to copy anything
54+
# back
55+
$context += @{"origin"=$originFile; "temp"=$null;}
56+
}
57+
}
58+
59+
return $context
60+
61+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.