-
Notifications
You must be signed in to change notification settings - Fork 1
/
ct_run.py
executable file
·167 lines (144 loc) · 4.85 KB
/
ct_run.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
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
#!/usr/bin/env python3
"""Runs integration tests."""
import argparse
import os
import platform
import sys
import re
script_dir = os.path.dirname(os.path.realpath(__file__))
docker_dir = os.path.join(script_dir, 'bamboos', 'docker')
sys.path.insert(0, docker_dir)
from environment import docker, dockers_config
from environment.common import HOST_STORAGE_PATH
def parse_valgrind_log_error_count(log_file):
"""
Parses valgrind memcheck file and returns the identified error count.
"""
with open(log_file, 'r') as f:
regex = re.compile("ERROR SUMMARY:\s(\d+)\serrors")
for line in f:
match = re.search(regex, line)
if match:
return int(match.groups()[0])
raise SystemExit("Invalid Valgrind memcheck report file: "+log_file)
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Run Common Tests.')
parser.add_argument(
'--gdb',
action='store_true',
default=False,
help='run tests in GDB')
parser.add_argument(
'--valgrind',
action='store_true',
default=False,
help='run tests under Valgrind',
dest='valgrind')
parser.add_argument(
'--callgrind',
action='store_true',
default=False,
help='run tests under Valgrind callgrind tool',
dest='callgrind')
parser.add_argument(
'--image', '-i',
action='store',
default=None,
help='docker image to use as a test master',
dest='image')
parser.add_argument(
'--release',
action='store',
default='release',
help='release directory to run tests from',
dest='release')
parser.add_argument(
'--suite',
action='append',
default=[],
help='name of the test suite',
dest='suites')
parser.add_argument(
'--cpuset-cpus',
action='store',
default=None,
help='CPUs in which to allow execution (0-3, 0,1)',
dest='cpuset_cpus')
[args, pass_args] = parser.parse_known_args()
dockers_config.ensure_image(args, 'image', 'builder')
script_dir = os.path.dirname(os.path.realpath(__file__))
base_test_dir = os.path.join(os.path.realpath(args.release), 'test',
'integration')
test_dirs = map(lambda suite: os.path.join(base_test_dir, suite), args.suites)
if args.valgrind:
if len(test_dirs) != 1:
raise SystemExit('Valgrind test run requires specification of a single '
'test case suite, e.g. \'--suite ceph_helper_test\'')
if args.gdb:
raise SystemExit('GDB and Valgrind cannot be used simultanously for '
'tests')
if not test_dirs:
test_dirs = [base_test_dir]
command = '''
import os, subprocess, sys, stat
if {shed_privileges}:
os.environ['HOME'] = '/tmp'
docker_gid = os.stat('/var/run/docker.sock').st_gid
os.chmod('/etc/resolv.conf', 0o666)
os.setgroups([docker_gid])
os.setregid({gid}, {gid})
os.setreuid({uid}, {uid})
if {gdb}:
command = ['gdb', 'python3', '-silent', '-ex', """run -c "
import pytest
pytest.main({args} + ['{test_dirs}'])" """]
elif {valgrind}:
command = ['valgrind'] \\
+ ['--gen-suppressions=all'] \\
+ ['--suppressions=valgrind.supp'] \\
+ ['--track-origins=yes'] \\
+ ['--log-file=valgrind-{suite}.txt'] \\
+ ['--show-leak-kinds=definite'] \\
+ ['--leak-check=full'] \\
+ ['py.test'] + {args} + ['{test_dirs}']
elif {callgrind}:
command = ['valgrind'] \\
+ ['--tool=callgrind'] \\
+ ['py.test'] + {args} + ['{test_dirs}']
else:
command = ['python3'] + ['-m'] + ['pytest'] + {args} + ['{test_dirs}']
ret = subprocess.call(command)
sys.exit(ret)
'''
command = command.format(
args=pass_args,
uid=os.geteuid(),
gid=os.getegid(),
test_dirs="', '".join(test_dirs),
base_test_dir=base_test_dir,
shed_privileges=(platform.system() == 'Linux'),
gdb=args.gdb,
valgrind=args.valgrind,
callgrind=args.callgrind,
suite=(args.suites[0] if args.valgrind else "', '".join(test_dirs)))
docker.run(tty=True,
rm=True,
interactive=True,
workdir=base_test_dir,
reflect=[(script_dir, 'rw'),
('/var/run/docker.sock', 'rw'),
(HOST_STORAGE_PATH, 'rw')],
image=args.image,
envs={'BASE_TEST_DIR': base_test_dir, 'PYTHONWARNINGS': 'ignore:Unverified HTTPS request'},
run_params=['--privileged'] if (args.gdb or args.valgrind) else [],
cpuset_cpus=args.cpuset_cpus,
command=['python3', '-c', command])
# If exit code != 0 then bamboo always fails build.
# If it is 0 then result is based on test report.
ret = 0
# If Valgrind was enabled, parse the memcheck report
# and return error if any errors were identified
if args.valgrind:
ret = parse_valgrind_log_error_count("valgrind-"+args.suites[0]+".txt")
sys.exit(ret)