Skip to content

Commit 3e6af70

Browse files
committed
Allow the selection of non-default build directories
The default is still 'build' but this change allows users to specify a different directory, with the --build-dir option.
1 parent ea1d62b commit 3e6af70

File tree

1 file changed

+56
-36
lines changed

1 file changed

+56
-36
lines changed

run_conformance_tests.py

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ def handle_args(argv):
3838
type=str,
3939
required=True)
4040
parser.add_argument(
41-
'-c',
42-
'--build-system-call',
43-
help='The call to the used build system.',
41+
'--build-system-args',
42+
help='Additional args to pass to the build system through CMake',
4443
type=str,
4544
required=True)
45+
parser.add_argument(
46+
'--build-dir',
47+
help='The name of the build directory to use/create',
48+
type=str,
49+
default='build',
50+
required=False)
4651
parser.add_argument(
4752
'--build-only',
4853
help='Whether to perform only a build without any testing.',
@@ -104,11 +109,11 @@ def handle_args(argv):
104109
'together in a single script run.')
105110
exit(-1)
106111

107-
return (args.cmake_exe, args.build_system_name, args.build_system_call,
112+
return (args.cmake_exe, args.build_system_name, args.build_system_args,
108113
full_conformance, test_deprecated_features, args.exclude_categories,
109114
args.implementation_name, args.additional_cmake_args, args.device,
110115
args.additional_ctest_args, args.build_only, args.run_only,
111-
commit_hash, full_feature_set)
116+
commit_hash, full_feature_set, args.build_dir)
112117

113118

114119
def split_additional_args(additional_args):
@@ -130,7 +135,8 @@ def split_additional_args(additional_args):
130135
return shlex.split(additional_args, posix=use_posix_mode)
131136

132137

133-
def generate_cmake_call(cmake_exe, build_system_name, full_conformance,
138+
def generate_cmake_call(cmake_exe, build_dir, build_system_name,
139+
full_conformance,
134140
test_deprecated_features, exclude_categories,
135141
implementation_name, additional_cmake_args, device,
136142
full_feature_set):
@@ -140,7 +146,8 @@ def generate_cmake_call(cmake_exe, build_system_name, full_conformance,
140146
"""
141147
call = [
142148
cmake_exe,
143-
'..',
149+
'.',
150+
'-B' + build_dir,
144151
'-G' + build_system_name,
145152
'-DSYCL_CTS_ENABLE_FULL_CONFORMANCE=' + full_conformance,
146153
'-DSYCL_CTS_ENABLE_DEPRECATED_FEATURES_TESTS=' + test_deprecated_features,
@@ -154,17 +161,29 @@ def generate_cmake_call(cmake_exe, build_system_name, full_conformance,
154161
return call
155162

156163

157-
def generate_ctest_call(additional_ctest_args):
164+
def generate_ctest_call(build_dir, additional_ctest_args):
158165
"""
159166
Generates a CTest call based on the input in a form accepted by
160167
subprocess.call().
161168
"""
162169
return [
163-
'ctest', '.', '-T', 'Test', '--no-compress-output',
170+
'ctest', '.', '--test-dir', build_dir, '-T', 'Test', '--no-compress-output',
164171
'--test-output-size-passed', '0', '--test-output-size-failed', '0'
165172
] + split_additional_args(additional_ctest_args)
166173

167174

175+
def generate_build_call(cmake_exe, build_dir, build_system_args):
176+
"""
177+
Generates a CTest call based on the input in a form accepted by
178+
subprocess.call().
179+
"""
180+
build_call = [ cmake_exe, '--build', build_dir, '--parallel' ]
181+
build_system_args = split_additional_args(build_system_args)
182+
if build_system_args:
183+
build_call.extend(['--'] + build_system_args)
184+
return build_call
185+
186+
168187
def subprocess_call(parameter_list):
169188
"""
170189
Calls subprocess.call() with the parameter list.
@@ -174,7 +193,7 @@ def subprocess_call(parameter_list):
174193
return subprocess.call(parameter_list)
175194

176195

177-
def configure_and_run_tests(cmake_call, build_system_call, build_only,
196+
def configure_and_run_tests(cmake_call, build_call, build_only,
178197
run_only, ctest_call):
179198
"""
180199
Configures the tests with cmake to produce a ninja.build file.
@@ -185,18 +204,17 @@ def configure_and_run_tests(cmake_call, build_system_call, build_only,
185204
error_code = 0
186205

187206
if (not run_only):
188-
build_system_call = build_system_call.split()
189-
190207
subprocess_call(cmake_call)
191-
error_code = subprocess_call(build_system_call)
208+
209+
error_code = subprocess_call(build_call)
192210

193211
if (not build_only):
194212
error_code = subprocess_call(ctest_call)
195213

196214
return error_code
197215

198216

199-
def collect_info_filenames():
217+
def collect_info_filenames(build_dir):
200218
"""
201219
Collects all the .info test result files in the Testing directory.
202220
Exits the program if no result files are found.
@@ -205,8 +223,9 @@ def collect_info_filenames():
205223
info_filenames = []
206224

207225
# Get all the test results in Testing
208-
for filename in os.listdir('Testing'):
209-
filename_full = os.path.join('Testing', filename)
226+
testing_dir = os.path.join(build_dir, 'Testing')
227+
for filename in os.listdir(testing_dir):
228+
filename_full = os.path.join(testing_dir, filename)
210229
if filename.endswith('.info'):
211230
info_filenames.append(filename_full)
212231

@@ -236,15 +255,15 @@ def get_valid_json_info(info_filenames):
236255
return json.loads(reference_info)
237256

238257

239-
def get_xml_test_results():
258+
def get_xml_test_results(build_dir):
240259
"""
241260
Finds the xml file output by the test and returns the rool of the xml tree.
242261
"""
243262
test_tag = ""
244-
with open(os.path.join("Testing", "TAG"), 'r') as tag_file:
263+
with open(os.path.join(build_dir, "Testing", "TAG"), 'r') as tag_file:
245264
test_tag = tag_file.readline()[:-1]
246265

247-
test_xml_file = os.path.join("Testing", test_tag, "Test.xml")
266+
test_xml_file = os.path.join(build_dir, "Testing", test_tag, "Test.xml")
248267
test_xml_tree = ET.parse(test_xml_file)
249268
return test_xml_tree.getroot()
250269

@@ -283,7 +302,7 @@ def update_xml_attribs(info_json, implementation_name, test_xml_root,
283302
test_xml_root.attrib["FullConformanceMode"] = full_conformance
284303
test_xml_root.attrib["CMakeInput"] = ' '.join(cmake_call)
285304
test_xml_root.attrib["BuildSystemGenerator"] = build_system_name
286-
test_xml_root.attrib["BuildSystemCall"] = build_system_call
305+
test_xml_root.attrib["BuildSystemCall"] = ' '.join(build_system_call)
287306
test_xml_root.attrib["CTestCall"] = ' '.join(ctest_call)
288307
test_xml_root.attrib["TestDeprecatedFeatures"] = test_deprecated_features
289308
test_xml_root.attrib["FullFeatureSet"] = full_feature_set
@@ -294,57 +313,58 @@ def update_xml_attribs(info_json, implementation_name, test_xml_root,
294313
def main(argv=sys.argv[1:]):
295314

296315
# Parse and gather all the script args
297-
(cmake_exe, build_system_name, build_system_call, full_conformance,
316+
(cmake_exe, build_system_name, build_system_args, full_conformance,
298317
test_deprecated_features, exclude_categories, implementation_name,
299-
additional_cmake_args, device, additional_ctest_args,
300-
build_only, run_only, commit_hash, full_feature_set) = handle_args(argv)
318+
additional_cmake_args, device, additional_ctest_args, build_only, run_only,
319+
commit_hash, full_feature_set, build_dir) = handle_args(argv)
301320

302321
# Generate a cmake call in a form accepted by subprocess.call()
303-
cmake_call = generate_cmake_call(cmake_exe, build_system_name,
322+
cmake_call = generate_cmake_call(cmake_exe, build_dir, build_system_name,
304323
full_conformance, test_deprecated_features,
305324
exclude_categories, implementation_name,
306325
additional_cmake_args, device,
307326
full_feature_set)
308327

309328
# Generate a CTest call in a form accepted by subprocess.call()
310-
ctest_call = generate_ctest_call(additional_ctest_args)
329+
ctest_call = generate_ctest_call(build_dir, additional_ctest_args)
311330

312-
# Make a build directory if required and enter it
313-
if not os.path.isdir('build'):
314-
os.mkdir('build')
315-
os.chdir('build')
331+
build_call = generate_build_call(cmake_exe, build_dir, build_system_args)
316332

317333
# Configure the build system with cmake, run the build, and run the tests.
318-
error_code = configure_and_run_tests(cmake_call, build_system_call,
319-
build_only, run_only, ctest_call)
334+
error_code = configure_and_run_tests(cmake_call, build_call, build_only,
335+
run_only, ctest_call)
320336

321337
if build_only:
322338
return error_code
323339

324340
# Collect the test info files, validate them and get the contents as json.
325-
info_filenames = collect_info_filenames()
341+
info_filenames = collect_info_filenames(build_dir)
326342
info_json = get_valid_json_info(info_filenames)
327343

328344
# Get the xml results and update with the necessary information.
329-
result_xml_root = get_xml_test_results()
345+
result_xml_root = get_xml_test_results(build_dir)
330346
result_xml_root = update_xml_attribs(info_json, implementation_name,
331347
result_xml_root, full_conformance,
332348
cmake_call, build_system_name,
333-
build_system_call, ctest_call,
349+
build_call, ctest_call,
334350
test_deprecated_features,
335351
commit_hash,
336352
full_feature_set)
337353

338354
# Get the xml report stylesheet and add it to the results.
339-
stylesheet_xml_file = os.path.join("..", "tools", "stylesheet.xml")
355+
stylesheet_xml_file = os.path.join(
356+
os.path.abspath(os.path.dirname(__file__)), "tools", "stylesheet.xml"
357+
)
340358
stylesheet_xml_tree = ET.parse(stylesheet_xml_file)
341359
stylesheet_xml_root = stylesheet_xml_tree.getroot()
342360
result_xml_root.append(stylesheet_xml_root[0])
343361

344362
# Get the xml results as a string and append them to the report header.
345363
report = REPORT_HEADER + ET.tostring(result_xml_root).decode("utf-8")
346364

347-
with open("conformance_report.xml", 'w') as final_conformance_report:
365+
with open(
366+
os.path.join(build_dir, "conformance_report.xml"), "w"
367+
) as final_conformance_report:
348368
final_conformance_report.write(report)
349369

350370
return error_code

0 commit comments

Comments
 (0)