-
Notifications
You must be signed in to change notification settings - Fork 13
/
ci_tests.py
executable file
·90 lines (67 loc) · 2.19 KB
/
ci_tests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
import logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
import glob
import io
import os
import pprint
import sys
import time
# Or write fallback os.walk code for glob ** usage
assert sys.version_info >= (3,5)
import sh
from sh import rm, mv, cp, ls, mkdir, tup, pwd
logging.getLogger("sh").setLevel(logging.WARNING)
BUILD_DIR = 'builds'
PRISTINE = os.path.join(BUILD_DIR, 'simulator')
# Start from scratch
rm('-r', '-f', BUILD_DIR)
mkdir(BUILD_DIR)
# No fuse in the CI environment means we need a unique directory for each
# variant. We first grab a copy of the simulator folder and wipe out all things
# tup to use as a template so that the same script will work locally and in CI
cp('-r', 'simulator', PRISTINE)
with sh.pushd(PRISTINE):
rm('-r', '-f', '.tup')
rm('-r', '-f', sh.glob('build-*'))
variants = {}
log.info(sh.cc('--version'))
for variant_file in os.listdir('simulator/configs'):
log.info("Building {}".format(variant_file))
variant = os.path.basename(variant_file)
build_variant_dir = os.path.join(BUILD_DIR, variant)
mkdir(build_variant_dir)
cp('-r', PRISTINE, build_variant_dir)
with sh.pushd(os.path.join(build_variant_dir, 'simulator')):
tup('init')
tup('generate', 'build.sh', '--config', os.path.join('configs', variant))
try:
errbuf = io.StringIO()
sh.sh('-x', 'build.sh', _err=errbuf)
except:
errbuf.seek(0)
for l in errbuf.readlines():
print(l, end='')
raise
sh.test('-x', 'simulator')
log.info("Built {}".format(variant_file))
any_fail = False
sim = sh.Command('./simulator')
for test in glob.iglob('tests/**/*.bin', recursive=True):
log.info("\t\ttest: %s", test)
try:
sim('-f', test)
log.info("\t\t\tPASSED")
except sh.ErrorReturnCode as e:
# XXX: This is a hack
if 'exceeds ram size' in e.stderr.decode('utf-8'):
log.info("\t\t\tSKIPPED -- Test too large for variant")
continue
log.info("\t\t\tFAILED -- Error code %s", e.exit_code)
log.info("\t\t\t\t%s", e)
any_fail = True
if any_fail:
raise NotImplementedError("Failed test cases")
log.info("All tests passed for {}".format(variant_file))
log.info("All built and all tests passed")