Skip to content

Commit eb97ecb

Browse files
committed
finished check
1 parent c9eb8d0 commit eb97ecb

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

scripts/PSCodingStandards/CodingStandards.psm1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ foreach($i in $Functions){
88

99
Export-ModuleMember -Function $Functions.BaseName
1010

11+
Write-Host "Importing Configuration.... "
12+
Export-ModuleMember -Variable AVAILABLE_SUITES
13+
Export-ModuleMember -Variable AVAILABLE_LANGUAGES
14+
1115
Write-Host "IMPORTING "

scripts/PSCodingStandards/Config.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$AVAILABLE_SUITES = @("CERT-C++", "AUTOSAR", "MISRA-C-2012", "CERT-C")
2+
$AVAILABLE_LANGUAGES = @("c", "cpp")

scripts/matrix_testing/Config.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ $COMPILER_ARGS = @{
2323

2424
}
2525

26-
$AVAILABLE_SUITES = @("CERT-C++", "AUTOSAR", "MISRA-C-2012", "CERT-C")
2726
$REQUIRED_CODEQL_VERSION = "2.6.3"
2827

2928

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env pwsh
2+
param(
3+
[ValidateSet('c', 'cpp')]
4+
[string]
5+
$Language = 'c',
6+
[Parameter(Mandatory = $false)]
7+
[string]
8+
$ReportDir = (Get-Location),
9+
[switch]
10+
$CIMode
11+
)
12+
13+
Import-Module -Force -Name "$PSScriptRoot/../PSCodingStandards/CodingStandards"
14+
15+
$allQueries = @()
16+
$queriesToCheck = @()
17+
18+
# load all the queries
19+
foreach ($s in $AVAILABLE_SUITES) {
20+
$allQueries += Get-RulesInSuite -Suite $s -Language $Language
21+
}
22+
23+
foreach ($q in $allQueries){
24+
if($q | Get-Member "shared_implementation_short_name"){
25+
$queriesToCheck += $q
26+
}
27+
}
28+
29+
if ($queriesToCheck.Count -eq 0) {
30+
throw "No queries loaded."
31+
}
32+
else {
33+
Write-Host "Loaded $($queriesToCheck.Count) queries with shared implementations."
34+
}
35+
36+
# What we want to verify is that IF a shared implementation is used, then we
37+
# have a valid test case WITHIN the language that is using it.
38+
39+
$REPORT = @()
40+
41+
foreach($q in $queriesToCheck){
42+
# Get test directory
43+
$testDirectory = Get-TestDirectory -RuleObject $q -Language $Language
44+
Write-Host "Verifying $Language language tests in $testDirectory..."
45+
46+
47+
$row = @{
48+
"SUITE" = $q.__memberof_suite;
49+
"PACKAGE" = $q.__memberof_package;
50+
"RULE" = $q.__memberof_rule;
51+
"QUERY" = $q.short_name;
52+
"SHARED_NAME" = $q.shared_implementation_short_name;
53+
"TEST_DIR_EXISTS" = $false;
54+
"SOURCE_CODE_EXISTS" = $false;
55+
"EXPECTED_EXISTS" = $false;
56+
"REFERENCE_EXISTS" = $false;
57+
}
58+
59+
# require a .c for language cpp
60+
# require a .expected
61+
# require a .ql
62+
63+
if(-not (Test-Path $testDirectory)){
64+
continue
65+
}
66+
67+
$dirName = (Get-Item $testDirectory).Basename
68+
$dirNameLower = $dirName.ToLower()
69+
70+
$row["TEST_DIR_EXISTS"] = $true
71+
72+
if((Test-Path (Join-Path $testDirectory "test.$Language"))){
73+
$row["SOURCE_CODE_EXISTS"] = $true
74+
}
75+
76+
if((Test-Path (Join-Path $testDirectory "$dirNameLower.expected"))){
77+
$row["EXPECTED_EXISTS"] = $true
78+
}
79+
80+
if((Test-Path (Join-Path $testDirectory "$dirNameLower.ql"))){
81+
$row["REFERENCE_EXISTS"] = $true
82+
}
83+
84+
85+
$REPORT += $row
86+
}
87+
88+
89+
90+
# output a CSV containing the elements that do not contain
91+
$fileTag = "$Language-$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss")"
92+
$reportOutputFile = Join-Path $ReportDir "TestReport-$fileTag.csv"
93+
$missingReportOutputFile = Join-Path $ReportDir "MissingTestReport-$fileTag.csv"
94+
95+
$failCount = 0
96+
foreach ($r in $REPORT) {
97+
if(($r["TEST_DIR_EXISTS"] -eq $false) -or ($r["SOURCE_CODE_EXISTS"] -eq $false) -or ($r["EXPECTED_EXISTS"] -eq $false) -or ($r["REFERENCE_EXISTS"] -eq $false)){
98+
$failCount += 1
99+
[PSCustomObject]$r | Export-CSV -Path $missingReportOutputFile -Append -NoTypeInformation
100+
101+
}
102+
[PSCustomObject]$r | Export-CSV -Path $reportOutputFile -Append -NoTypeInformation
103+
}
104+
105+
Write-Host "Write report to $reportOutputFile"
106+
107+
if(($CIMode) -and ($failCount -gt 0)){
108+
throw "Found $failCount/$($queriesToCheck.Count) invalid shared test uses"
109+
}else{
110+
Write-Host "Found $failCount/$($queriesToCheck.Count) invalid shared test uses"
111+
}

0 commit comments

Comments
 (0)