-
Notifications
You must be signed in to change notification settings - Fork 14
/
pyctest-runner.py
executable file
·341 lines (298 loc) · 11.1 KB
/
pyctest-runner.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PyCTest driver for Parallel Tasking Library (PTL)
"""
import os
import sys
import platform
import traceback
import warnings
import multiprocessing as mp
import pyctest.pyctest as pyct
import pyctest.pycmake as pycm
import pyctest.helpers as helpers
# --------------------------------------------------------------------------- #
def configure():
# Get pyctest argument parser that include PyCTest arguments
parser = helpers.ArgumentParser(
project_name="PTL",
source_dir=os.getcwd(),
binary_dir=os.path.join(os.getcwd(), "build-PTL"),
build_type="Release",
vcs_type="git",
)
parser.add_argument(
"--arch", help="PTL_USE_ARCH=ON", default=False, action="store_true"
)
parser.add_argument(
"--tbb", help="PTL_USE_TBB=ON", default=False, action="store_true"
)
parser.add_argument(
"--sanitizer",
help="PTL_USE_SANITIZER=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--sanitizer-type",
help="PTL_SANITIZER_TYPE=<type>",
default="leak",
type=str,
choices=("leak", "thread", "memory", "address"),
)
parser.add_argument(
"--static-analysis",
help="PTL_USE_CLANG_TIDY=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--coverage",
help="PTL_USE_COVERAGE=ON",
default=False,
action="store_true",
)
parser.add_argument(
"--num-tasks", help="Set the number of tasks", default=65536, type=int
)
parser.add_argument(
"--use-locks",
help="Enable mutex locking in task subqueues for extra safety",
default=None,
action="store_true",
)
parser.add_argument(
"--build-libs",
help="Set the number of tasks",
default=["shared", "static"],
type=str,
nargs="*",
choices=("shared", "static"),
)
args = parser.parse_args()
if os.path.exists(os.path.join(pyct.BINARY_DIRECTORY, "CMakeCache.txt")):
from pyctest import cmake_executable as cm
from pyctest import version_info as _pyctest_version
if (
_pyctest_version[0] == 0
and _pyctest_version[1] == 0
and _pyctest_version[2] < 11
):
cmd = pyct.command(
[cm, "--build", pyct.BINARY_DIRECTORY, "--target", "clean"]
)
cmd.SetWorkingDirectory(pyct.BINARY_DIRECTORY)
cmd.SetOutputQuiet(True)
cmd.SetErrorQuiet(True)
cmd.Execute()
else:
from pyctest.cmake import CMake
CMake("--build", pyct.BINARY_DIRECTORY, "--target", "clean")
helpers.RemovePath(os.path.join(pyct.BINARY_DIRECTORY, "CMakeCache.txt"))
pyct.set(
"CTEST_CUSTOM_COVERAGE_EXCLUDE",
";".join(
[
"/usr/.*",
".*external/.*",
".*examples/.*",
]
),
)
return args
# --------------------------------------------------------------------------- #
#
def run_pyctest():
# ----------------------------------------------------------------------- #
# run argparse, checkout source, copy over files
#
args = configure()
# ----------------------------------------------------------------------- #
# Compiler version
#
if os.environ.get("CXX") is None:
os.environ["CXX"] = os.path.realpath(helpers.FindExePath("c++"))
cmd = pyct.command([os.environ["CXX"], "-dumpversion"])
cmd.SetOutputStripTrailingWhitespace(True)
cmd.Execute()
compiler_version = cmd.Output()
# ----------------------------------------------------------------------- #
# Set the build name
#
pyct.BUILD_NAME = "[{}] [{} {} {}] [{} {}]".format(
pyct.GetGitBranch(pyct.SOURCE_DIRECTORY),
platform.uname()[0],
helpers.GetSystemVersionInfo(),
platform.uname()[4],
os.path.basename(os.environ["CXX"]),
compiler_version,
)
# ----------------------------------------------------------------------- #
# build specifications
#
build_opts = {
"PTL_USE_TBB": "OFF",
"PTL_USE_SANITIZER": "OFF",
"PTL_USE_CLANG_TIDY": "OFF",
"PTL_USE_COVERAGE": "OFF",
"PTL_USE_LOCKS": "ON" if args.use_locks else "OFF",
}
if args.tbb:
pyct.BUILD_NAME = "{} [tbb]".format(pyct.BUILD_NAME)
build_opts["PTL_USE_TBB"] = "ON"
if args.arch:
pyct.BUILD_NAME = "{} [arch]".format(pyct.BUILD_NAME)
build_opts["PTL_USE_ARCH"] = "ON"
if args.sanitizer:
pyct.BUILD_NAME = "{} [{}]".format(pyct.BUILD_NAME, args.sanitizer_type)
build_opts["PTL_USE_SANITIZER"] = "ON"
build_opts["PTL_SANITIZER_TYPE"] = args.sanitizer_type
if args.static_analysis:
build_opts["PTL_USE_CLANG_TIDY"] = "ON"
if args.coverage:
gcov_exe = helpers.FindExePath("gcov")
if gcov_exe is not None:
pyct.COVERAGE_COMMAND = "{}".format(gcov_exe)
build_opts["PTL_USE_COVERAGE"] = "ON"
warnings.warn("Forcing build type to 'Debug' when coverage is enabled")
pyct.BUILD_TYPE = "Debug"
build_opts["BUILD_SHARED_LIBS"] = "ON" if "shared" in args.build_libs else "OFF"
build_opts["BUILD_STATIC_LIBS"] = "ON" if "static" in args.build_libs else "OFF"
pyct.BUILD_NAME = "{} [{}]".format(pyct.BUILD_NAME, pyct.BUILD_TYPE)
# default options
cmake_args = "-DCMAKE_BUILD_TYPE={} -DPTL_BUILD_EXAMPLES=ON".format(pyct.BUILD_TYPE)
# customized from args
for key, val in build_opts.items():
cmake_args = "{} -D{}={}".format(cmake_args, key, val)
# ----------------------------------------------------------------------- #
# how to build the code
#
ctest_cmake_cmd = "${CTEST_CMAKE_COMMAND}"
pyct.CONFIGURE_COMMAND = "{} {} {} {}".format(
ctest_cmake_cmd, cmake_args, " ".join(pycm.ARGUMENTS), pyct.SOURCE_DIRECTORY
)
# ----------------------------------------------------------------------- #
# how to build the code
#
pyct.BUILD_COMMAND = "{} --build {} --target all".format(
ctest_cmake_cmd, pyct.BINARY_DIRECTORY
)
# ----------------------------------------------------------------------- #
# parallel build
#
if not args.static_analysis:
if platform.system() != "Windows":
pyct.BUILD_COMMAND = "{} -- -j{} VERBOSE=1".format(
pyct.BUILD_COMMAND, mp.cpu_count()
)
else:
pyct.BUILD_COMMAND = "{} -- /MP -A x64".format(pyct.BUILD_COMMAND)
# ----------------------------------------------------------------------- #
# how to update the code
#
git_exe = helpers.FindExePath("git")
pyct.UPDATE_COMMAND = "{}".format(git_exe)
pyct.set("CTEST_UPDATE_TYPE", "git")
pyct.set("CTEST_GIT_COMMAND", "{}".format(git_exe))
# ----------------------------------------------------------------------- #
# static analysis
#
clang_tidy_exe = helpers.FindExePath("clang-tidy")
if clang_tidy_exe:
pyct.set("CMAKE_CXX_CLANG_TIDY", "{};-checks=*".format(clang_tidy_exe))
# ----------------------------------------------------------------------- #
# find the CTEST_TOKEN_FILE
#
if args.pyctest_token_file is None and args.pyctest_token is None:
home = helpers.GetHomePath()
if home is not None:
token_path = os.path.join(home, os.path.join(".tokens", "nersc-cdash"))
if os.path.exists(token_path):
pyct.set("CTEST_TOKEN_FILE", token_path)
# ----------------------------------------------------------------------- #
# construct a command
#
def construct_command(cmd, args):
_cmd = []
_cmd.extend(cmd)
return _cmd
# ----------------------------------------------------------------------- #
# standard environment settings for tests, adds profile to notes
#
def test_env_settings(prof_fname, clobber=False, extra=""):
return "PTL_NUM_THREADS={};CPUPROFILE={};{}".format(
mp.cpu_count(), prof_fname, extra
)
# pyct.set("ENV{GCOV_PREFIX}", pyct.BINARY_DIRECTORY)
# pyct.set("ENV{GCOV_PREFIX_STRIP}", "4")
# ----------------------------------------------------------------------- #
# create tests
#
tasking_suffix = ""
if args.num_tasks != 65536:
tasking_suffix = "_{}".format(args.num_tasks)
test = pyct.test()
test.SetName("tasking{}".format(tasking_suffix))
test.SetProperty("WORKING_DIRECTORY", pyct.BINARY_DIRECTORY)
test.SetProperty(
"ENVIRONMENT",
test_env_settings(
"cpu-prof-tasking",
clobber=True,
extra="NUM_TASKS={}".format(args.num_tasks),
),
)
test.SetProperty("RUN_SERIAL", "ON")
test.SetCommand(construct_command(["./tasking"], args))
test = pyct.test()
test.SetName("recursive_tasking")
test.SetProperty("WORKING_DIRECTORY", pyct.BINARY_DIRECTORY)
test.SetProperty("ENVIRONMENT", test_env_settings("cpu-prof-recursive-tasking"))
test.SetProperty("RUN_SERIAL", "ON")
test.SetCommand(construct_command(["./recursive_tasking"], args))
test = pyct.test()
test.SetName("minimal")
test.SetProperty("WORKING_DIRECTORY", pyct.BINARY_DIRECTORY)
test.SetProperty("RUN_SERIAL", "ON")
test.SetCommand(construct_command(["./ptl-minimal"], args))
if args.tbb:
test = pyct.test()
test.SetName("tbb_minimal")
test.SetProperty("WORKING_DIRECTORY", pyct.BINARY_DIRECTORY)
test.SetProperty("RUN_SERIAL", "ON")
test.SetProperty("ENVIRONMENT", "PTL_USE_TBB=ON")
test.SetCommand(construct_command(["./ptl-minimal"], args))
test = pyct.test()
test.SetName("tbb_tasking{}".format(tasking_suffix))
test.SetProperty("WORKING_DIRECTORY", pyct.BINARY_DIRECTORY)
test.SetProperty(
"ENVIRONMENT",
test_env_settings(
"cpu-prof-tbb-tasking",
extra="NUM_TASKS={}".format(args.num_tasks),
),
)
test.SetProperty("RUN_SERIAL", "ON")
test.SetCommand(construct_command(["./tbb_tasking"], args))
test = pyct.test()
test.SetName("recursive_tbb_tasking")
test.SetProperty("WORKING_DIRECTORY", pyct.BINARY_DIRECTORY)
test.SetProperty(
"ENVIRONMENT", test_env_settings("cpu-prof-tbb-recursive-tasking")
)
test.SetProperty("RUN_SERIAL", "ON")
test.SetCommand(construct_command(["./recursive_tbb_tasking"], args))
pyct.generate_config(pyct.BINARY_DIRECTORY)
pyct.generate_test_file(pyct.BINARY_DIRECTORY)
pyct.run(pyct.ARGUMENTS, pyct.BINARY_DIRECTORY)
# --------------------------------------------------------------------------- #
if __name__ == "__main__":
try:
run_pyctest()
except Exception as e:
print("Error running pyctest - {}".format(e))
exc_type, exc_value, exc_trback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_trback, limit=10)
sys.exit(1)
sys.exit(0)