-
Notifications
You must be signed in to change notification settings - Fork 14
/
verify.py.in
executable file
·185 lines (150 loc) · 6.62 KB
/
verify.py.in
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
"""
Verify script for seahorn verification jobs
return code
0 - all ok
1 - expected string not found in stderr/stdout
2 - error reported to stderr
"""
import os
import os.path
import re
import sys
SEAHORN_ROOT = "@SEAHORN_ROOT@"
ASSERT_ERROR_PREFIX = r'^Error: assertion failed'
# the plan is to have two sets, vac error and info and put filepath:linenumbers) into both
VACUITY_CHECK_RE = r'^(?P<stream>Info|Error).*(?P<what>vacuity).*(?P<result>passed|failed).*sat\) (?P<debuginfo>.*)$'
def check_vacuity(line, passed_set, failed_set):
m = re.match(VACUITY_CHECK_RE, line)
if not m:
return
debugInfo = m.group('debuginfo')
if (m.group('stream') == 'Info'
and m.group('what') == 'vacuity'
and m.group('result') == 'passed'):
passed_set.add(debugInfo.strip())
elif (m.group('stream') == 'Error'
and m.group('what') == 'vacuity'
and m.group('result') == 'failed'):
failed_set.add(debugInfo.strip())
def main(argv):
import sea
def check_vacuity_inner(line, passed_set, failed_set):
return check_vacuity(line, passed_set, failed_set)
class VerifyCmd(sea.CliCmd):
def __init__(self):
super().__init__('verify', 'Verify', allow_extra=True)
def mk_arg_parser(self, argp):
import argparse
argp = super().mk_arg_parser(argp)
argp.add_argument('-v', '--verbose', action='store_true',
default=False)
argp.add_argument('--silent', action='store_true', default=False,
help='Do not produce any output')
argp.add_argument('--expect', type=str, default=None,
help='Expected string in the output')
argp.add_argument('--command', type=str, default='fpf',
help='sea command')
argp.add_argument('--cex', action='store_true', default=False,
help='Counterexample mode')
argp.add_argument('--vac', action='store_true', default=False,
help='Vacuity mode')
argp.add_argument('--pcond', action='store_true', default=False,
help='Path condition mode')
argp.add_argument('input_file', nargs=1)
argp.add_argument('--dry-run', dest='dry_run',
action='store_true', default=False,
help='Pass --dry-run to yama')
argp.add_argument('extra', nargs=argparse.REMAINDER)
return argp
def run(self, args=None, _extra=[]):
extra = _extra + args.extra
script_dir = os.path.abspath(sys.argv[0])
script_dir = os.path.dirname(script_dir)
input_file = os.path.abspath(args.input_file[0])
# try to guess input file from directory name
if os.path.isdir(input_file):
fname = os.path.basename(input_file)
_input_file = os.path.join(input_file, 'llvm-ir', fname + '.ir',
fname + '.ir.bc')
if os.path.isfile(_input_file):
input_file = _input_file
file_dir = input_file
file_dir = os.path.dirname(file_dir)
cmd = [os.path.join(SEAHORN_ROOT, 'bin', 'sea'),
'yama', '--yforce']
# base config
base_config = os.path.join(script_dir, 'seahorn', 'sea.yaml')
if args.cex:
base_config = os.path.join(script_dir, 'seahorn',
'sea.cex.yaml')
cmd.extend(['-y', base_config])
# vacuity config
if args.vac:
vac_config = os.path.join(script_dir, 'seahorn',
'sea.vac.yaml')
cmd.extend(['-y', vac_config])
# pcond config
if args.pcond:
pcond_config = os.path.join(script_dir, 'seahorn',
'sea.pcond.yaml')
cmd.extend(['-y', pcond_config])
# job specific config
job_config = os.path.abspath(os.path.join(file_dir, '..', '..',
'sea.yaml'))
cmd.extend(['-y', job_config])
if args.dry_run:
cmd.append('--dry-run')
cmd.append(args.command)
cmd.extend(extra)
cmd.append(input_file)
if args.verbose:
print(' '.join(cmd))
if args.expect is None:
os.execv(cmd[0], cmd)
import subprocess
process = subprocess.Popen(cmd, shell=False,
encoding='utf-8',
errors='ignore',
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
found_expected = False
found_error = False
vacuity_passed = set()
vacuity_failed = set()
for line in iter(process.stdout.readline, ''):
if not args.silent:
print(line, end='')
# checks after this line are mutually exclusive
if not found_expected and args.expect is not None and line.strip() == args.expect:
found_expected = True
elif re.match(ASSERT_ERROR_PREFIX, line):
found_error = True
else:
check_vacuity_inner(line, vacuity_passed, vacuity_failed)
process.stdout.close()
rcode = process.wait()
if args.vac and found_error:
return 2
elif args.vac and (vacuity_failed - vacuity_passed):
return 2
elif rcode == 0 and args.expect is not None:
return 0 if found_expected else 1
else:
return rcode
cmd = VerifyCmd()
# read extra flags from environment variable
if 'VERIFY_FLAGS' in os.environ:
env_flags = os.environ['VERIFY_FLAGS']
env_flags = env_flags.split()
argv = env_flags + argv
return cmd.main(argv)
if __name__ == '__main__':
root = os.path.abspath(SEAHORN_ROOT)
bin_dir = os.path.join(root, 'bin')
if os.path.isdir(bin_dir):
os.environ['PATH'] = bin_dir + os.pathsep + os.environ['PATH']
seapy_dir = os.path.join(root, 'lib', 'seapy')
if os.path.isdir(seapy_dir):
sys.path.insert(0, seapy_dir)
sys.exit(main(sys.argv[1:]))