Menu

[4430e9]: / test_runner.py  Maximize  Restore  History

Download this file

47 lines (40 with data), 1.6 kB

 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
#!/usr/bin/python3
import argparse
import os
import subprocess
import sys
def build(build_dir, config):
os.chdir(build_dir)
cpu_count = os.cpu_count() or 1
ret = subprocess.run(['cmake', '-DCMAKE_BUILD_TYPE=' + config,
'..']).returncode
if ret:
return ret
ret = subprocess.run(['cmake', '--build', '.', '--config',
config, '-j', str(cpu_count)]).returncode
if ret:
# Try again, it could be due to cmake not supporting -j
return subprocess.run(['cmake', '--build', '.', '--config', config])
def run_tests(build_dir, config):
test_dir = os.path.join(build_dir, 'tests')
os.chdir(test_dir)
return subprocess.run(['ctest', '-C', config, '-V']).returncode
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Execute tests (and optionally builds)')
parser.add_argument('--build', dest='build', action='store_true',
help='Build target before testing')
parser.add_argument('--build_dir', dest='build_dir', action='store',
default='build', type=str, metavar='PATH',
help='CMake build directory')
parser.add_argument('--config', dest='config', action='store',
default='Debug', type=str,
help='CMake build config (Debug, Release, etc)')
args = parser.parse_args()
cwd = os.getcwd()
if args.build:
ret = build(args.build_dir, args.config)
if ret:
sys.exit(ret)
os.chdir(cwd)
sys.exit(run_tests(args.build_dir, args.config))
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.