Skip to content

Commit 942e24d

Browse files
committed
factoring in the sub dirs
1 parent 9620206 commit 942e24d

File tree

4 files changed

+137
-116
lines changed

4 files changed

+137
-116
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Get-ATestDirectory {
2+
param(
3+
[Parameter(Mandatory)]
4+
[object]
5+
$RuleObject,
6+
[Parameter(Mandatory)]
7+
[ValidateSet('c', 'cpp')]
8+
[string]
9+
$Language
10+
)
11+
12+
$ruleDir = Get-TestDirectory -RuleObject $RuleObject -Language $Language
13+
14+
# return value MUST include the explicit test directory
15+
$dirs = @($ruleDir)
16+
17+
$dirs += (Get-Item "$($ruleDir).*" | ForEach-Object { $_.FullName })
18+
19+
$dirs
20+
}

scripts/PSCodingStandards/Get-RuleForPath.ps1

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,21 @@ function Get-RuleForPath {
5959
foreach($q in $allQueries){
6060

6161
# get test directory
62-
$testDirectory = (Get-TestDirectory -RuleObject $q -Language $Language)
63-
# resolve path to be compatible
64-
$testPath = Join-Path (Resolve-Path . -Relative) $testDirectory
62+
$testDirs = (Get-ATestDirectory -RuleObject $q -Language $Language)
63+
foreach($testDirectory in $testDirs){
64+
# resolve path to be compatible
65+
$testPath = Join-Path (Resolve-Path . -Relative) $testDirectory
6566

66-
# see if the TEST directory is a substring of the full path
67-
if($modifiedPath.StartsWith($testPath)){
68-
$matchingRules += $q
69-
continue
70-
}
67+
# see if the TEST directory is a substring of the full path
68+
if($modifiedPath.StartsWith($testPath)){
69+
$matchingRules += $q
70+
continue
71+
}
7172

72-
if($modifiedPathWithReplacement.StartsWith($testPath)){
73-
$matchingRules += $q
74-
continue
73+
if($modifiedPathWithReplacement.StartsWith($testPath)){
74+
$matchingRules += $q
75+
continue
76+
}
7577
}
7678
}
7779

scripts/matrix_testing/Config.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ $COMPILER_ARGS = @{
2222

2323
"c" = @{
2424
"gcc" = "-fsyntax-only";
25-
"clang" = "-fsyntax-only";
26-
25+
"clang" = "-fsyntax-only";
2726
};
2827

2928
}

scripts/matrix_testing/CreateMatrixTestReport.ps1

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
280280

281281
Import-Module -Name "$using:PSScriptRoot/../PSCodingStandards/CodingStandards"
282282

283-
#. "$using:PSScriptRoot/GetTestDirectory.ps1"
284283
. "$using:PSScriptRoot/NewDatabaseForRule.ps1"
285284
. "$using:PSScriptRoot/ExecuteQueryAndDecodeAsJson.ps1"
286285
. "$using:PSScriptRoot/Get-CompilerSpecificFiles.ps1"
@@ -293,6 +292,7 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
293292
$CurrentRuleName = $q.__memberof_rule
294293
$CurrentQueryName = $q.short_name
295294
$CurrentPackageName = $q.__memberof_package
295+
296296
# for the report
297297
$row = @{
298298
"SUITE" = $CurrentSuiteName;
@@ -305,115 +305,115 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
305305
"TEST_DIFFERENCE" = "";
306306
}
307307

308-
Write-Host "Resolving pack 'codeql/cpp-queries'...." -NoNewline
309-
$CODEQL_CPP_QUERIES_PATH = (codeql resolve qlpacks --format json | ConvertFrom-Json)."codeql/cpp-queries"
310-
if ( -Not (Test-Path -Path $CODEQL_CPP_QUERIES_PATH -PathType Container) ) {
311-
Write-Host "Could not resolve pack 'codeql/cpp-queries'. Please install the pack 'codeql/cpp-queries'."
312-
return $row
313-
}
314-
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
308+
# all the test directories -- there may be more than one for a given rule
309+
$testDirs = (Get-ATestDirectory -RuleObject $q -Language $using:Language)
315310

316-
Write-Host "====================[Rule=$CurrentRuleName,Suite=$CurrentSuiteName/Query=$CurrentQueryName]===================="
311+
foreach($testDirectory in $testDirs){
317312

318-
$testDirectory = (Get-TestDirectory -RuleObject $q -Language $using:Language)
313+
Write-Host "====================[Rule=$CurrentRuleName,Suite=$CurrentSuiteName/Query=$CurrentQueryName]===================="
319314

320-
try {
321-
###########################################################
322-
###########################################################
323-
# Push context
324-
###########################################################
325-
$fileSet = (Get-CompilerSpecificFiles -Configuration $using:Configuration -Language $using:Language -TestDirectory $testDirectory)
326-
327-
if($fileSet){
328-
$context = Push-CompilerSpecificFiles -Configuration $using:Configuration -Language $using:Language -FileSet $fileSet
329-
}
330-
331-
Write-Host "Compiling database in $testDirectory..." -NoNewline
332315

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

419419
# combine the outputs

0 commit comments

Comments
 (0)