forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-cbmc-version.py
executable file
·65 lines (51 loc) · 2.23 KB
/
check-cbmc-version.py
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
#!/usr/bin/env python3
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
import argparse
import re
import sys
import subprocess
from subprocess import PIPE
EXIT_CODE_SUCCESS = 0
EXIT_CODE_MISMATCH = 1
EXIT_CODE_FAIL = 2
def get_version(tool_str):
cmd = [tool_str, "--version"]
try:
version = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, check=True,
universal_newlines=True)
except (OSError, subprocess.SubprocessError) as error:
print(error)
print(f"Can't run command '{' '.join(cmd)}'")
sys.exit(EXIT_CODE_FAIL)
match = re.match("([0-9]+).([0-9]+).([0-9]+)", version.stdout)
if not match:
print(f"Can't parse " + tool_str + " version string: '{version.stdout.strip()}'")
sys.exit(EXIT_CODE_FAIL)
return match.groups()
def complete_version(*version):
numbers = [int(num) if num else 0 for num in version]
return (numbers + [0, 0, 0])[:3]
def main():
parser = argparse.ArgumentParser(
description='Check CBMC version matches major/minor/patch')
parser.add_argument('--major', required=True)
parser.add_argument('--minor', required=True)
parser.add_argument('--patch')
args = parser.parse_args()
current_cbmc_version = complete_version(*get_version("cbmc"))
current_synthesizer_version = complete_version(*get_version("goto-synthesizer"))
desired_version = complete_version(args.major, args.minor, args.patch)
if desired_version > current_cbmc_version:
version_string = '.'.join([str(num) for num in current_cbmc_version])
desired_version_string = '.'.join([str(num) for num in desired_version])
print(f'ERROR: CBMC version is {version_string}, expected at least {desired_version_string}')
sys.exit(EXIT_CODE_MISMATCH)
if current_cbmc_version != current_synthesizer_version:
version_string = '.'.join([str(num) for num in current_synthesizer_version])
cbmc_version_string = '.'.join([str(num) for num in current_cbmc_version])
print(
f'ERROR: goto-synthesizer version is {version_string}, non consistent with CBMC version {cbmc_version_string}')
sys.exit(EXIT_CODE_MISMATCH)
if __name__ == "__main__":
main()