Skip to content

Commit 2d9484a

Browse files
authored
Don't do duplicate builds during test runs (#1691)
The `run-tests.py` test execution harness validates the correctness of JerryScript by building various configurations of jerry and running various test suites and subsets against it. However, until now, it always built jerry for each (build configuration, test suite) pair. This commit improves `run-tests.py` by skipping duplicate builds, sharing the same-built binaries across multiple test suite runs. The patch also improves on the style of how `Option`s are specified and fixes the name of the `jerry_tests-debug-cpointer_32bit` option. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
1 parent 16d5d6f commit 2d9484a

File tree

1 file changed

+96
-79
lines changed

1 file changed

+96
-79
lines changed

tools/run-tests.py

Lines changed: 96 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -32,90 +32,94 @@ def __init__(self, name='', build_args=None, test_args=None):
3232
if test_args is None:
3333
test_args = []
3434

35-
self._build_args = build_args
36-
self._name = name
35+
self.build_args = build_args
36+
self.name = name
3737
self.test_args = test_args
3838

39-
def get_build_args(self, outdir):
40-
return self._build_args + ['--builddir=%s' % os.path.join(outdir, self._name)]
41-
42-
def get_bin_dir_path(self, outdir):
43-
return os.path.join(os.path.join(outdir, self._name), 'bin')
44-
45-
def get_binary_path(self, outdir):
46-
return os.path.join(self.get_bin_dir_path(outdir), 'jerry')
39+
def get_binary_path(bin_dir_path):
40+
return os.path.join(bin_dir_path, 'jerry')
4741

4842
# Test options for unittests
4943
JERRY_UNITTESTS_OPTIONS = [
50-
Options('unittests', ['--unittests', '--error-messages=on', '--snapshot-save=on', '--snapshot-exec=on']),
51-
Options('unittests-debug', ['--unittests',
52-
'--debug',
53-
'--error-messages=on',
54-
'--snapshot-save=on',
55-
'--snapshot-exec=on'])
44+
Options('unittests',
45+
['--unittests', '--error-messages=on', '--snapshot-save=on', '--snapshot-exec=on']),
46+
Options('unittests-debug',
47+
['--unittests', '--debug', '--error-messages=on', '--snapshot-save=on', '--snapshot-exec=on'])
5648
]
5749

5850
# Test options for jerry-tests
5951
JERRY_TESTS_OPTIONS = [
6052
Options('jerry_tests'),
61-
Options('jerry_tests-debug', ['--debug']),
62-
Options('jerry_tests-debug', ['--debug', '--cpointer-32bit=on', '--mem-heap=1024']),
63-
Options('jerry_tests-snapshot', ['--snapshot-save=on', '--snapshot-exec=on'], ['--snapshot']),
64-
Options('jerry_tests-debug-snapshot', ['--debug', '--snapshot-save=on', '--snapshot-exec=on'], ['--snapshot']),
65-
Options('jerry_tests-es2015-subset-debug', ['--debug', '--profile=es2015-subset'])
53+
Options('jerry_tests-debug',
54+
['--debug']),
55+
Options('jerry_tests-debug-cpointer_32bit',
56+
['--debug', '--cpointer-32bit=on', '--mem-heap=1024']),
57+
Options('jerry_tests-snapshot',
58+
['--snapshot-save=on', '--snapshot-exec=on'],
59+
['--snapshot']),
60+
Options('jerry_tests-debug-snapshot',
61+
['--debug', '--snapshot-save=on', '--snapshot-exec=on'],
62+
['--snapshot']),
63+
Options('jerry_tests-es2015-subset-debug',
64+
['--debug', '--profile=es2015-subset'])
6665
]
6766

6867
# Test options for jerry-test-suite
6968
JERRY_TEST_SUITE_OPTIONS = JERRY_TESTS_OPTIONS[:]
70-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-minimal', ['--profile=minimal']))
71-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-minimal-snapshot',
72-
['--profile=minimal',
73-
'--snapshot-save=on',
74-
'--snapshot-exec=on'],
75-
['--snapshot']))
76-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-minimal-debug', ['--debug', '--profile=minimal']))
77-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-minimal-debug-snapshot',
78-
['--debug',
79-
'--profile=minimal',
80-
'--snapshot-save=on',
81-
'--snapshot-exec=on'],
82-
['--snapshot']))
83-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-es2015-subset', ['--profile=es2015-subset']))
84-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-es2015-subset-snapshot',
85-
['--profile=es2015-subset',
86-
'--snapshot-save=on',
87-
'--snapshot-exec=on'],
88-
['--snapshot']))
89-
JERRY_TEST_SUITE_OPTIONS.append(Options('jerry_test_suite-es2015-subset-debug-snapshot',
90-
['--debug',
91-
'--profile=es2015-subset',
92-
'--snapshot-save=on',
93-
'--snapshot-exec=on'],
94-
['--snapshot']))
69+
JERRY_TEST_SUITE_OPTIONS.extend([
70+
Options('jerry_test_suite-minimal',
71+
['--profile=minimal']),
72+
Options('jerry_test_suite-minimal-snapshot',
73+
['--profile=minimal', '--snapshot-save=on', '--snapshot-exec=on'],
74+
['--snapshot']),
75+
Options('jerry_test_suite-minimal-debug',
76+
['--debug', '--profile=minimal']),
77+
Options('jerry_test_suite-minimal-debug-snapshot',
78+
['--debug', '--profile=minimal', '--snapshot-save=on', '--snapshot-exec=on'],
79+
['--snapshot']),
80+
Options('jerry_test_suite-es2015-subset',
81+
['--profile=es2015-subset']),
82+
Options('jerry_test_suite-es2015-subset-snapshot',
83+
['--profile=es2015-subset', '--snapshot-save=on', '--snapshot-exec=on'],
84+
['--snapshot']),
85+
Options('jerry_test_suite-es2015-subset-debug-snapshot',
86+
['--debug', '--profile=es2015-subset', '--snapshot-save=on', '--snapshot-exec=on'],
87+
['--snapshot'])
88+
])
9589

9690
# Test options for test262
97-
TEST262_TEST_SUITE_OPTIONS = [Options('test262_tests')]
91+
TEST262_TEST_SUITE_OPTIONS = [
92+
Options('test262_tests')
93+
]
9894

9995
# Test options for jerry-debugger
10096
DEBUGGER_TEST_OPTIONS = [
101-
Options('jerry_debugger_tests', ['--debug', '--jerry-debugger=on', '--jerry-libc=off'])
97+
Options('jerry_debugger_tests',
98+
['--debug', '--jerry-debugger=on', '--jerry-libc=off'])
10299
]
103100

104101
# Test options for buildoption-test
105102
JERRY_BUILDOPTIONS = [
106-
Options('buildoption_test-lto', ['--lto=on']),
107-
Options('buildoption_test-error_messages', ['--error-messages=on']),
108-
Options('buildoption_test-all_in_one', ['--all-in-one=on']),
109-
Options('buildoption_test-valgrind', ['--valgrind=on']),
110-
Options('buildoption_test-valgrind_freya', ['--valgrind-freya=on']),
111-
Options('buildoption_test-mem_stats', ['--mem-stats=on']),
112-
Options('buildoption_test-show_opcodes', ['--show-opcodes=on']),
113-
Options('buildoption_test-show_regexp_opcodes', ['--show-regexp-opcodes=on']),
114-
Options('buildoption_test-compiler_default_libc', ['--jerry-libc=off']),
115-
Options('buildoption_test-cpointer_32bit', ['--jerry-libc=off',
116-
'--compile-flag=-m32',
117-
'--cpointer-32bit=on',
118-
'--system-allocator=on']),
103+
Options('buildoption_test-lto',
104+
['--lto=on']),
105+
Options('buildoption_test-error_messages',
106+
['--error-messages=on']),
107+
Options('buildoption_test-all_in_one',
108+
['--all-in-one=on']),
109+
Options('buildoption_test-valgrind',
110+
['--valgrind=on']),
111+
Options('buildoption_test-valgrind_freya',
112+
['--valgrind-freya=on']),
113+
Options('buildoption_test-mem_stats',
114+
['--mem-stats=on']),
115+
Options('buildoption_test-show_opcodes',
116+
['--show-opcodes=on']),
117+
Options('buildoption_test-show_regexp_opcodes',
118+
['--show-regexp-opcodes=on']),
119+
Options('buildoption_test-compiler_default_libc',
120+
['--jerry-libc=off']),
121+
Options('buildoption_test-cpointer_32bit',
122+
['--jerry-libc=off', '--compile-flag=-m32', '--cpointer-32bit=on', '--system-allocator=on']),
119123
]
120124

121125
def get_arguments():
@@ -154,9 +158,14 @@ def get_arguments():
154158

155159
return script_args
156160

157-
def create_binary(buildoptions, options):
161+
BINARY_CACHE = {}
162+
163+
def create_binary(job, options):
158164
build_cmd = [settings.BUILD_SCRIPT]
159-
build_cmd.extend(buildoptions)
165+
build_cmd.extend(job.build_args)
166+
167+
build_dir_path = os.path.join(options.outdir, job.name)
168+
build_cmd.append('--builddir=%s' % build_dir_path)
160169

161170
if options.toolchain:
162171
build_cmd.append('--toolchain=%s' % options.toolchain)
@@ -166,12 +175,20 @@ def create_binary(buildoptions, options):
166175

167176
sys.stderr.write('Build command: %s\n' % ' '.join(build_cmd))
168177

178+
binary_key = tuple(job.build_args)
179+
if binary_key in BINARY_CACHE:
180+
ret, build_dir_path = BINARY_CACHE[binary_key]
181+
sys.stderr.write('(skipping: already built at %s with returncode %d)\n' % (build_dir_path, ret))
182+
return ret, os.path.join(build_dir_path, 'bin')
183+
169184
try:
170185
subprocess.check_output(build_cmd)
186+
ret = 0
171187
except subprocess.CalledProcessError as err:
172-
return err.returncode
188+
ret = err.returncode
173189

174-
return 0
190+
BINARY_CACHE[binary_key] = (ret, build_dir_path)
191+
return ret, os.path.join(build_dir_path, 'bin')
175192

176193
def run_check(runnable):
177194
sys.stderr.write('Test command: %s\n' % ' '.join(runnable))
@@ -186,7 +203,7 @@ def run_check(runnable):
186203
def run_jerry_debugger_tests(options):
187204
ret_build = ret_test = 0
188205
for job in DEBUGGER_TEST_OPTIONS:
189-
ret_build = create_binary(job.get_build_args(options.outdir), options)
206+
ret_build, bin_dir_path = create_binary(job, options)
190207
if ret_build:
191208
break
192209

@@ -196,7 +213,7 @@ def run_jerry_debugger_tests(options):
196213
test_case_path = os.path.join(settings.DEBUGGER_TESTS_DIR, test_case)
197214
test_cmd = [
198215
settings.DEBUGGER_TEST_RUNNER_SCRIPT,
199-
job.get_binary_path(options.outdir),
216+
get_binary_path(bin_dir_path),
200217
settings.DEBUGGER_CLIENT_SCRIPT,
201218
os.path.relpath(test_case_path, settings.PROJECT_DIR)
202219
]
@@ -211,18 +228,18 @@ def run_jerry_debugger_tests(options):
211228
def run_jerry_tests(options):
212229
ret_build = ret_test = 0
213230
for job in JERRY_TESTS_OPTIONS:
214-
ret_build = create_binary(job.get_build_args(options.outdir), options)
231+
ret_build, bin_dir_path = create_binary(job, options)
215232
if ret_build:
216233
break
217234

218235
test_cmd = [
219236
settings.TEST_RUNNER_SCRIPT,
220-
job.get_binary_path(options.outdir),
237+
get_binary_path(bin_dir_path),
221238
settings.JERRY_TESTS_DIR
222239
]
223240
skip_list = []
224241

225-
if '--profile=es2015-subset' not in job.get_build_args(options.outdir):
242+
if '--profile=es2015-subset' not in job.build_args:
226243
skip_list.append(r"es2015\/")
227244

228245
if options.skip_list:
@@ -241,15 +258,15 @@ def run_jerry_tests(options):
241258
def run_jerry_test_suite(options):
242259
ret_build = ret_test = 0
243260
for job in JERRY_TEST_SUITE_OPTIONS:
244-
ret_build = create_binary(job.get_build_args(options.outdir), options)
261+
ret_build, bin_dir_path = create_binary(job, options)
245262
if ret_build:
246263
break
247264

248-
test_cmd = [settings.TEST_RUNNER_SCRIPT, job.get_binary_path(options.outdir)]
265+
test_cmd = [settings.TEST_RUNNER_SCRIPT, get_binary_path(bin_dir_path)]
249266

250-
if '--profile=minimal' in job.get_build_args(options.outdir):
267+
if '--profile=minimal' in job.build_args:
251268
test_cmd.append(settings.JERRY_TEST_SUITE_MINIMAL_LIST)
252-
elif '--profile=es2015-subset' in job.get_build_args(options.outdir):
269+
elif '--profile=es2015-subset' in job.build_args:
253270
test_cmd.append(settings.JERRY_TEST_SUITE_DIR)
254271
else:
255272
test_cmd.append(settings.JERRY_TEST_SUITE_ES51_LIST)
@@ -267,13 +284,13 @@ def run_jerry_test_suite(options):
267284
def run_test262_test_suite(options):
268285
ret_build = ret_test = 0
269286
for job in TEST262_TEST_SUITE_OPTIONS:
270-
ret_build = create_binary(job.get_build_args(options.outdir), options)
287+
ret_build, bin_dir_path = create_binary(job, options)
271288
if ret_build:
272289
break
273290

274291
test_cmd = [
275292
settings.TEST262_RUNNER_SCRIPT,
276-
job.get_binary_path(options.outdir),
293+
get_binary_path(bin_dir_path),
277294
settings.TEST262_TEST_SUITE_DIR
278295
]
279296

@@ -287,20 +304,20 @@ def run_test262_test_suite(options):
287304
def run_unittests(options):
288305
ret_build = ret_test = 0
289306
for job in JERRY_UNITTESTS_OPTIONS:
290-
ret_build = create_binary(job.get_build_args(options.outdir), options)
307+
ret_build, bin_dir_path = create_binary(job, options)
291308
if ret_build:
292309
break
293310

294311
ret_test |= run_check([
295312
settings.UNITTEST_RUNNER_SCRIPT,
296-
job.get_bin_dir_path(options.outdir)
313+
bin_dir_path
297314
])
298315

299316
return ret_build | ret_test
300317

301318
def run_buildoption_test(options):
302319
for job in JERRY_BUILDOPTIONS:
303-
ret = create_binary(job.get_build_args(options.outdir), options)
320+
ret, _ = create_binary(job, options)
304321
if ret:
305322
break
306323

0 commit comments

Comments
 (0)