Skip to content

Commit b266f10

Browse files
authored
Prefer command line over environment variables for test options (#15559)
At least for some of these options, the command line makes more sense. In general we should prefer the command line for all the normal reasons (e.g. less prone to typos, more local). For historical reasons (command line options just didn't work in the past) these evolved as environment variables.
1 parent 9e97b04 commit b266f10

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

tests/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ def setUp(self):
434434
print('Not clearing existing test directory')
435435
else:
436436
print('Clearing existing test directory')
437-
# Even when EMTEST_SAVE_DIR we still try to start with an empty directoy as many tests
438-
# expect this. EMTEST_SAVE_DIR=2 can be used to keep the old contents for the new test
437+
# Even when --save-dir is used we still try to start with an empty directory as many tests
438+
# expect this. --no-clean can be used to keep the old contents for the new test
439439
# run. This can be useful when iterating on a given test with extra files you want to keep
440440
# around in the output directory.
441441
delete_contents(self.working_dir)
@@ -740,7 +740,7 @@ def assertIdentical(self, values, y, msg=None,
740740
print("Expected to have '%s' == '%s'" % (limit_size(values[0]), limit_size(y)))
741741
fail_message = 'Unexpected difference:\n' + limit_size(diff)
742742
if not EMTEST_VERBOSE:
743-
fail_message += '\nFor full output run with EMTEST_VERBOSE=1.'
743+
fail_message += '\nFor full output run with --verbose.'
744744
if msg:
745745
fail_message += '\n' + msg
746746
self.fail(fail_message)
@@ -760,9 +760,9 @@ def assertFileContents(self, filename, contents):
760760

761761
if not os.path.exists(filename):
762762
self.fail('Test expectation file not found: ' + filename + '.\n' +
763-
'Run with EMTEST_REBASELINE to generate.')
763+
'Run with --rebaseline to generate.')
764764
expected_content = read_file(filename)
765-
message = "Run with EMTEST_REBASELINE=1 to automatically update expectations"
765+
message = "Run with --rebaseline to automatically update expectations"
766766
self.assertTextDataIdentical(expected_content, contents, message,
767767
filename, filename + '.new')
768768

tests/runner.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ def configure():
334334
assert 'PARALLEL_SUITE_EMCC_CORES' not in os.environ, 'use EMTEST_CORES rather than PARALLEL_SUITE_EMCC_CORES'
335335
parallel_testsuite.NUM_CORES = os.environ.get('EMTEST_CORES') or os.environ.get('EMCC_CORES')
336336

337+
# Some options make sense being set in the environment, others not-so-much.
338+
# TODO(sbc): eventually just make these command-line only.
339+
if os.getenv('EMTEST_SAVE_DIR'):
340+
print('Prefer --save-dir over setting $EMTEST_SAVE_DIR')
341+
if os.getenv('EMTEST_REBASELINE'):
342+
print('Prefer --rebaseline over setting $EMTEST_REBASELINE')
343+
if os.getenv('EMTEST_VERBOSE'):
344+
print('Prefer --verbose over setting $EMTEST_VERBOSE')
345+
337346

338347
def main(args):
339348
options = parse_args(args)

tests/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_zzz_html_source_map(self):
242242
If manually bisecting:
243243
Check that you see src.cpp among the page sources.
244244
Even better, add a breakpoint, e.g. on the printf, then reload, then step
245-
through and see the print (best to run with EMTEST_SAVE_DIR=1 for the reload).
245+
through and see the print (best to run with --save-dir for the reload).
246246
''')
247247

248248
def test_emscripten_log(self):

tests/test_other.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8941,7 +8941,7 @@ def get_file_gzipped_size(f):
89418941
# to rebaseline this test. However:
89428942
# a) such changes deserve extra scrutiny
89438943
# b) such changes should be few and far between
8944-
# c) rebaselining is trivial (just run with EMTEST_REBASELINE=1)
8944+
# c) rebaselining is trivial (just run with --rebaseline)
89458945
# Note that we do not compare the full wasm output since that is
89468946
# even more fragile and can change with LLVM updates.
89478947
if compare_js_output:
@@ -9014,9 +9014,11 @@ def get_file_gzipped_size(f):
90149014
open(results_file, 'w').write(json.dumps(obtained_results, indent=2) + '\n')
90159015
else:
90169016
if total_output_size > total_expected_size:
9017-
print('Oops, overall generated code size regressed by ' + str(total_output_size - total_expected_size) + ' bytes!')
9017+
print('Oops, overall generated code size regressed by {total_output_size - total_expected_size} bytes!')
9018+
print('If this is expected, rerun the test with --rebaseline to update the expected sizes')
90189019
if total_output_size < total_expected_size:
9019-
print('Hey amazing, overall generated code size was improved by ' + str(total_expected_size - total_output_size) + ' bytes! Rerun test with other.test_minimal_runtime_code_size with EMTEST_REBASELINE=1 to update the expected sizes!')
9020+
print(f'Hey amazing, overall generated code size was improved by {total_expected_size - total_output_size} bytes!')
9021+
print('If this is expected, rerun the test with --rebaseline to update the expected sizes')
90209022
self.assertEqual(total_output_size, total_expected_size)
90219023

90229024
# Tests the library_c_preprocessor.js functionality.
@@ -10569,7 +10571,7 @@ def test_split_main_module(self):
1056910571
def test_gen_struct_info(self):
1057010572
# This tests is fragile and will need updating any time any of the refereced
1057110573
# structs or defines change. However its easy to rebaseline with
10572-
# EMTEST_REBASELINE and it prevents regressions or unintended changes
10574+
# --rebaseline and it prevents regressions or unintended changes
1057310575
# to the output json.
1057410576
self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json'])
1057510577
self.assertFileContents(test_file('reference_struct_info.json'), read_file('out.json'))

tests/third_party/bullet/Demos/HelloWorld/frames.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<!--
66
7-
EMTEST_SAVE_DIR=1 ./tests/runner.py asm3.test_the_bullet
7+
./tests/runner.py asm3.test_the_bullet --save-dir
88
99
./emcc -O3 tests/bullet/Demos/HelloWorld/HelloWorldFrames.cpp tests/bullet/Demos/HelloWorld/BenchmarkDemo.cpp /tmp/emscripten_temp/building/bullet/src/BulletDynamics/libBulletDynamics.a /tmp/emscripten_temp/building/bullet/src/BulletCollision/libBulletCollision.a /tmp/emscripten_temp/building/bullet/src/LinearMath/libLinearMath.a -o tests/bullet/Demos/HelloWorld/frames.js -I./tests/bullet/src -s TOTAL_MEMORY=60000000 -s LINKABLE=1
1010

tools/scons/site_scons/site_tools/emscripten/emscripten.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def generate(env, emscripten_path=None, **kw):
2020
# environment variabls from the parent calling process,
2121
# so manually route all environment variables referenced
2222
# by Emscripten to the child.
23-
for var in ['EM_CACHE', 'EMCC_DEBUG', 'EMTEST_BROWSER',
23+
for var in ['EM_CACHE', 'EMCC_DEBUG',
2424
'EMMAKEN_JUST_CONFIGURE', 'EMCC_CFLAGS', 'EMCC_TEMP_DIR',
2525
'EMCC_AUTODEBUG', 'EM_COMPILER_WRAPPER',
2626
'EMMAKEN_COMPILER', 'EMMAKEN_CFLAGS',
@@ -29,8 +29,7 @@ def generate(env, emscripten_path=None, **kw):
2929
'EMCC_JSOPT_MAX_CHUNK_SIZE', 'EMCC_SAVE_OPT_TEMP', 'EMCC_CORES', 'EMCC_NO_OPT_SORT',
3030
'EMCC_BUILD_DIR', 'EMCC_DEBUG_SAVE', 'EMCC_SKIP_SANITY_CHECK',
3131
'EMMAKEN_NO_SDK', 'EM_PKG_CONFIG_PATH', 'EMCC_CLOSURE_ARGS', 'JAVA_HEAP_SIZE',
32-
'EMCC_FORCE_STDLIBS', 'EMCC_ONLY_FORCED_STDLIBS', 'EM_PORTS', 'IDL_CHECKS', 'IDL_VERBOSE',
33-
'EMTEST_SAVE_DIR']:
32+
'EMCC_FORCE_STDLIBS', 'EMCC_ONLY_FORCED_STDLIBS', 'EM_PORTS', 'IDL_CHECKS', 'IDL_VERBOSE']:
3433
if os.environ.get(var):
3534
env['ENV'][var] = os.environ.get(var)
3635
try:

0 commit comments

Comments
 (0)