-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace.ps1
165 lines (133 loc) · 4.16 KB
/
trace.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<#
.SYNOPSIS
Runs proof in nuXmv.
.DESCRIPTION
The trace.ps1 script runs proofs with a list of assumtpions and options. It
attempts to prove each property given. If a property fails, its trace will be
pretty-printed as HTML table.
.PARAMETER In
Path to the .smv model. Model will be preprocessed with expander3.py.
Default: .\model\min-rv.smv
.PARAMETER OutDir
Path where results are placed. These include the preprocessed model and any
counter-example as HTML table. Default: .\dist
.PARAMETER CmdFile
Path to a file that holds commands for nuXmv. Will be preprocessed with
expander3.py. Various other options to this script will be used as variable.
Default: .\trace-bmc.template
.PARAMETER Dry
True to only preprocess the model and not perform any proofs. Default: False
.PARAMETER Cmd
Will replace $CMD in the command file. Default: check_ltlspec_klive
.PARAMETER Options
List of options to be enabled. Default: None.
.PARAMETER Assumptions
Array of assumptions for proofs. Default: All assumptions available.
.PARAMETER Props
List of properties to prove. Default: All properties but SYNTAX_CANARY.
.INPUTS
None.
.OUTPUTS
Miscellaneous logs and a summary how long the proofs took to run.
.EXAMPLE
PS> .\trace.ps1
.EXAMPLE
PS> .\trace.ps1 -cmd "check_ltlspec_bmc -k 10" -options CACHE_VULN
#>
param(
[string]$In = ".\model\min-rv.smv",
[string]$OutDir = ".\dist",
[string]$CmdFile = ".\trace-bmc.template",
[switch]$Dry = $false,
[switch]$TeX = $false,
[switch]$NoStart = $false,
[string]$Cmd = "check_ltlspec_klive",
[string[]]$Options = @(),
[string[]]$Assumptions = @(
"SP_SAFETY",
"SP_BANK",
"CLR_ON_RET",
"SAN_ON_CALL",
"NO_PUBLIC_READS",
"NO_PUBLIC_WRITES",
"CLR_ON_DECLASSIFICATION",
"CLR_CACHE_ON_DECLASSIFICATION",
"SAN_ON_CLASSIFICATION",
"SAN_CACHE_ON_CLASSIFICATION"
),
[string[]]$IgnoreAssumptions = @(),
[string[]]$Props = @(
"NO_LEAK",
"CSR_INTEGRITY",
"MEMORY_OP_INTEGRITY"
)
)
function unixTime() {
return [double]::Parse((Get-Date -UFormat %s))
}
# Create temporary files needed in this script
$preprocessedPath = Join-Path $OutDir (Split-Path $In -Leaf)
if (!(Test-Path $preprocessedPath)) {
New-Item $preprocessedPath
}
$preprocessed = Get-Item $preprocessedPath
# Preprocess the model
$localAssumptions = $Assumptions | Where-Object {
!$IgnoreAssumptions.Contains($PSItem)
}
$expr = ($localAssumptions + $Options `
| ForEach-Object { "$PSItem=True" }) -join ";"
expander.py -s --eval=$expr $header $In `
| Out-File -Encoding ascii $preprocessed
if ($Dry) {
exit
}
$replaced_cmd = New-TemporaryFile
# Track property time and success
$took_seconds = @{}
$outs = @{}
foreach ($prop in $Props) {
# Replace template-like variables in the command file
$trace = Join-Path $OutDir ($prop + ".xml")
if (Test-Path $trace) {
Remove-Item $trace
}
$expr = @(
"INPUT='$($preprocessed.FullName)'",
"PROPNAME='$prop'",
"OUTPUT='$trace'",
"CMD='$($Cmd)'"
) -join ";"
$expr = $expr.Replace("\", "/")
expander.py -s --eval=$expr $CmdFile | Out-File -encoding ascii $replaced_cmd
# Run nuXmv
$delta = unixTime
nuXmv.exe -source $replaced_cmd.FullName
$delta -= unixTime
$took_seconds[$prop] = [System.Math]::Abs($delta)
# Map the trace to an html table
if (Test-Path $trace) {
$out = Join-Path $OutDir ($prop + ".html")
$outs[$prop] = $out
# Execute https://github.com/felixlinker/smvtrcviz by script
smvtrcviz.ps1 -i $trace | Out-File $out
if ($TeX) {
$texName = $prop + ".tex" -replace "_","-"
smvtrcviz.ps1 -i $trace -m MINRV8 `
| Out-File -Encoding ascii (Join-Path $OutDir $texName)
}
}
}
$took_sum = 0
foreach ($prop in $Props) {
$s = $took_seconds[$prop]
$took_sum += $s
$proven = ![Bool]$outs[$prop]
Write-Host "$prop was proven to be $proven in $s s"
}
if (!$NoStart) {
$outs.Values | ForEach-Object { Start-Process $PSItem }
}
Write-Host "All proofs took $took_sum s"
# Clean up temporary files
Remove-Item $replaced_cmd