-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathbuildtest.py
More file actions
executable file
·133 lines (114 loc) · 3.47 KB
/
Copy pathbuildtest.py
File metadata and controls
executable file
·133 lines (114 loc) · 3.47 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
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
#!/usr/bin/python3
build_variants = [
#'WITH_ARGON2',
'WITH_ADNS',
'WITH_APPS',
'WITH_BROKER',
'WITH_CLIENTS',
'INC_BRIDGE_SUPPORT',
'WITH_CONTROL',
'WITH_CTRL_SHELL',
'WITH_DLT',
'WITH_HTTP_API',
'WITH_LIB_CPP',
'WITH_LTO',
'INC_MEMTRACK',
'WITH_OLD_KEEPALIVE',
'WITH_PERSISTENCE',
'WITH_PLUGINS',
'WITH_PLUGIN_ACL_FILE',
'WITH_PLUGIN_DYNAMIC_SECURITY',
'WITH_PLUGIN_EXAMPLES',
'WITH_PLUGIN_PASSWORD_FILE',
'WITH_PLUGIN_PERSIST_SQLITE',
'WITH_PLUGIN_SPARKPLUG_AWARE',
#'WITH_SHARED_LIBRARIES',
'WITH_SOCKS',
'WITH_SRV',
'WITH_STATIC_LIBRARIES',
'WITH_SYSTEMD',
'WITH_SYS_TREE',
'WITH_THREADING',
'WITH_TLS',
'WITH_TLS_PSK',
'WITH_UNIX_SOCKETS',
'WITH_WEBSOCKETS',
'WITH_WEBSOCKETS_BUILTIN',
'WITH_XTREPORT',
]
special_variants = [
'WITH_BUNDLED_DEPS',
'WITH_COVERAGE',
]
import os
import random
import shutil
import subprocess
import sys
import time
class Duration():
def __init__(self, label):
self.label = label
def __enter__(self):
self.start = time.time()
print(self.label, end="")
return self
def __exit__(self, exc_type, exc_value, traceback):
duration = time.time() - self.start
print(f" {duration:.2f}s")
def build_test(msg, run_tests, opts):
try:
shutil.rmtree("build")
except FileNotFoundError:
pass
print("%s: %s" % (msg, str(opts)))
# CMake
with Duration(" cmake"):
env = os.environ.copy()
env['CC'] = "ccache gcc"
env['CXX'] = "ccache g++"
args = ["cmake", "-DCMAKE_BUILD_TYPE=Debug", "-S", ".", "-B", "build", "-G", "Ninja"] + opts
proc = subprocess.run(args, stdout=subprocess.DEVNULL, env=env)
if proc.returncode != 0:
raise RuntimeError("CMAKE FAILED: %s" % (' '.join(args)))
# Build
with Duration(" build"):
args = ["cmake", "--build", "build", "--config", "Debug"]
proc = subprocess.run(args, stdout=subprocess.DEVNULL, env=env)
if proc.returncode != 0:
raise RuntimeError("BUILD FAILED: %s" % (' '.join(args)))
if run_tests:
# Test
with Duration(" test"):
args = ["ctest", "-j20", "--resource-spec-file", "../test/resource.json", "--test-dir", "build", "--output-on-failure", "--repeat", "until-pass:5"]
proc = subprocess.run(args, stdout=subprocess.DEVNULL, env=env)
if proc.returncode != 0:
raise RuntimeError("TEST FAILED: %s" % (' '.join(args)))
def report(res, opts):
with open("RESULTS", "at") as f:
f.write(f"{res} {opts}\n")
def simple_tests(run_tests):
failures = []
for bv in build_variants:
for enabled in ["ON", "OFF"]:
opts = f"-D{bv}={enabled}"
try:
build_test("SIMPLE BUILD", run_tests, [opts])
report("SUCCESS", opts)
except RuntimeError:
report("FAILURE", opts)
failures.append(opts)
print(failures)
def random_tests(count, run_tests):
for i in range(1, count):
opts = []
for bv in build_variants:
opts.append(f"-D{bv}={random.choice(['ON', 'OFF'])}")
build_test("RANDOM BUILD", run_tests, opts)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "--tests":
run_tests = True
else:
run_tests = False
simple_tests(run_tests)
#random_tests(2, run_tests)