Skip to content

Commit 4a085d0

Browse files
committed
feat(tests): Add CFG Tests
1 parent 5d3412c commit 4a085d0

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dominates
2+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:1:103:1 | enter Infrastructure |
3+
postDominance
4+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:1:103:1 | enter Infrastructure |
5+
immediateDominator
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import bicep
2+
import codeql.bicep.controlflow.BasicBlocks
3+
import codeql.bicep.controlflow.ControlFlowGraph
4+
5+
query predicate dominates(BasicBlock bb1, BasicBlock bb2) { bb1.dominates(bb2) }
6+
7+
query predicate postDominance(BasicBlock bb1, BasicBlock bb2) { bb1.postDominates(bb2) }
8+
9+
query predicate immediateDominator(BasicBlock bb1, BasicBlock bb2) {
10+
bb1.getImmediateDominator() = bb2
11+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:1:103:1 | Infrastructure | |
2+
| sample.bicep:1:1:103:1 | Infrastructure | sample.bicep:1:1:103:1 | exit Infrastructure (normal) | |
3+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
4+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
5+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
6+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:25:1:37 | resourceGroup | |
7+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:25:1:37 | resourceGroup | |
8+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:25:1:37 | resourceGroup | |
9+
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:41:1:48 | location | |
10+
| sample.bicep:1:1:103:1 | exit Infrastructure (normal) | sample.bicep:1:1:103:1 | exit Infrastructure | |
11+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
12+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
13+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
14+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
15+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
16+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
17+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:41:1:48 | location | |
18+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
19+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
20+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
21+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
22+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
23+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
24+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
25+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
26+
| sample.bicep:1:25:1:37 | resourceGroup | sample.bicep:1:25:1:39 | CallExpression | |
27+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
28+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
29+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
30+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
31+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
32+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
33+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
34+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
35+
| sample.bicep:1:25:1:39 | CallExpression | sample.bicep:1:25:1:48 | MemberExpression | |
36+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
37+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
38+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
39+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
40+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
41+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
42+
| sample.bicep:1:41:1:48 | location | sample.bicep:1:25:1:48 | MemberExpression | |
43+
| sample.bicep:1:41:1:48 | location | sample.bicep:1:25:1:48 | MemberExpression | |
44+
| sample.bicep:1:41:1:48 | location | sample.bicep:1:25:1:48 | MemberExpression | |

ql/test/library-tests/cfg/Cfg.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import codeql.bicep.CFG
2+
import codeql.bicep.controlflow.internal.ControlFlowGraphImpl::TestOutput<CfgNode>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
param location string = resourceGroup().location
2+
param storageAccountName string = 'toylaunch${uniqueString(resourceGroup().id)}'
3+
param vmName string = 'myVM'
4+
param adminUsername string = 'azureuser'
5+
param adminPassword string = 'P@ssw0rd123!'
6+
param vnetName string = 'myVnet'
7+
param subnetName string = 'mySubnet'
8+
param publicIpName string = 'myPublicIP'
9+
param nicName string = 'myNIC'
10+
11+
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
12+
name: storageAccountName
13+
location: location
14+
sku: {
15+
name: 'Standard_LRS'
16+
}
17+
kind: 'StorageV2'
18+
properties: {
19+
accessTier: 'Hot'
20+
}
21+
}
22+
23+
resource vnet 'Microsoft.Network/virtualNetworks@2021-05-01' = {
24+
name: vnetName
25+
location: location
26+
properties: {
27+
addressSpace: {
28+
addressPrefixes: [
29+
'10.0.0.0/16'
30+
]
31+
}
32+
subnets: [
33+
{
34+
name: subnetName
35+
properties: {
36+
addressPrefix: '10.0.0.0/24'
37+
}
38+
}
39+
]
40+
}
41+
}
42+
43+
resource publicIp 'Microsoft.Network/publicIPAddresses@2021-05-01' = {
44+
name: publicIpName
45+
location: location
46+
properties: {
47+
publicIPAllocationMethod: 'Dynamic'
48+
}
49+
}
50+
51+
resource nic 'Microsoft.Network/networkInterfaces@2021-05-01' = {
52+
name: nicName
53+
location: location
54+
properties: {
55+
ipConfigurations: [
56+
{
57+
name: 'ipconfig1'
58+
properties: {
59+
subnet: {
60+
id: vnet.properties.subnets[0].id
61+
}
62+
privateIPAllocationMethod: 'Dynamic'
63+
publicIPAddress: {
64+
id: publicIp.id
65+
}
66+
}
67+
}
68+
]
69+
}
70+
}
71+
72+
resource vm 'Microsoft.Compute/virtualMachines@2021-07-01' = {
73+
name: vmName
74+
location: location
75+
properties: {
76+
hardwareProfile: {
77+
vmSize: 'Standard_DS1_v2'
78+
}
79+
osProfile: {
80+
computerName: vmName
81+
adminUsername: adminUsername
82+
adminPassword: adminPassword
83+
}
84+
storageProfile: {
85+
imageReference: {
86+
publisher: 'Canonical'
87+
offer: 'UbuntuServer'
88+
sku: '18.04-LTS'
89+
version: 'latest'
90+
}
91+
osDisk: {
92+
createOption: 'FromImage'
93+
}
94+
}
95+
networkProfile: {
96+
networkInterfaces: [
97+
{
98+
id: nic.id
99+
}
100+
]
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)