|
9 | 9 | examples run under node, which b2's emscripten toolset runs itself, and a testing.launcher is |
10 | 10 | refused there; a program that node runs reads the host's files and standard input (-sNODERAWFS=1), |
11 | 11 | and no other program gets the flag; every program is wasm32, whatever address model is asked for; a |
12 | | -failure reaches the report; a program of webcpp.link is linked and never run, and fails on a symbol |
13 | | -nothing defines; a test of webcpp.drive runs its program through a script of node's on each of its |
14 | | -targets, in an own lane, a driver or a program that hangs fails it within its bound and leaves no |
15 | | -process behind, and one that no own lane names is refused; and a native build needs no Emscripten. |
| 12 | +program links at the level of optimization it compiles at, -O3 in a release build, which b2's |
| 13 | +toolset leaves to em++'s default, -O0, and before its own linkflags; a failure reaches the report; |
| 14 | +a program of webcpp.link is linked and never run, and fails on a symbol nothing defines; a test of |
| 15 | +webcpp.drive runs its program through a script of node's on each of its targets, in an own lane, a |
| 16 | +driver or a program that hangs fails it within its bound and leaves no process behind, and one that |
| 17 | +no own lane names is refused; and a native build needs no Emscripten. |
16 | 18 | The suspension variant, jspi by default and asyncify on request, builds with the exceptions each |
17 | 19 | needs, asyncify in a directory of its own, and natively adds nothing. Every program node runs links |
18 | 20 | the test support (/webcpp//node-test), whose fixture library node_test_demo pins each case's exact |
@@ -191,6 +193,39 @@ def test_programs_are_wasm32(root): |
191 | 193 | assert not directories, directories |
192 | 194 |
|
193 | 195 |
|
| 196 | +# An option of em++'s that sets the level of optimization, a word of its own: -O0 to -O3, -Os, |
| 197 | +# -Oz and -Og. |
| 198 | +LEVEL = re.compile(r'(?<!\S)-O[0-3szg](?!\S)') |
| 199 | + |
| 200 | + |
| 201 | +def compile_line(result: subprocess.CompletedProcess, source: str) -> str: |
| 202 | + """The command line b2 (-d+2) compiled the source named source with.""" |
| 203 | + compiled = re.compile(rf'-c -o "[^"]*" "[^"]*/{re.escape(source)}"$') |
| 204 | + lines = [line for line in result.stdout.splitlines() if compiled.search(line)] |
| 205 | + assert len(lines) == 1, (source, lines, result.stdout[-4000:]) |
| 206 | + return lines[0] |
| 207 | + |
| 208 | + |
| 209 | +def test_a_link_is_optimized_as_its_compile(root): |
| 210 | + # b2 5.5.3's emscripten toolset compiles at the level <optimization> names and links with |
| 211 | + # none, which em++ takes for -O0: a release program, compiled with -O3, was linked without |
| 212 | + # optimization, so binaryen never optimized it, and Asyncify instrumented it unoptimized. The |
| 213 | + # Jamroot gives the link its compile's level, for every value of <optimization>, before a |
| 214 | + # program's own <linkflags>, so that a level they name comes last, which em++ keeps. |
| 215 | + for request, level, linked_levels in ( |
| 216 | + (('variant=debug',), '-O0', ['-O0']), (('variant=release',), '-O3', ['-O3']), |
| 217 | + (('variant=release', 'optimization=space'), '-Os', ['-Os']), |
| 218 | + (('optimization=minimal',), '-O1', ['-O1']), (('optimization=debug',), '-Og', ['-Og']), |
| 219 | + (('variant=release', 'linkflags=-Oz'), '-O3', ['-O3', '-Oz'])): |
| 220 | + result = harness.run_b2(root, '-a', '-n', '-d+2', *EMSCRIPTEN, *request, |
| 221 | + 'libs/browser_demo/test//pointer') |
| 222 | + harness.expect(result, True) |
| 223 | + compiled = compile_line(result, 'pointer_test.cpp') |
| 224 | + assert LEVEL.findall(compiled) == [level], (request, compiled) |
| 225 | + linked = link_line(root, result, 'pointer') |
| 226 | + assert LEVEL.findall(linked) == linked_levels, (request, linked) |
| 227 | + |
| 228 | + |
194 | 229 | def test_suspend_variants_build_apart(root): |
195 | 230 | # jspi, the default, compiles with WebAssembly exceptions and adds no directory; asyncify |
196 | 231 | # composes JavaScript exceptions, which Asyncify needs (an Asyncify program built with |
@@ -606,6 +641,7 @@ def run(root): |
606 | 641 | test_a_launcher_is_refused_on_emscripten, |
607 | 642 | test_input_file_is_read_from_the_host, |
608 | 643 | test_programs_are_wasm32, |
| 644 | + test_a_link_is_optimized_as_its_compile, |
609 | 645 | test_suspend_variants_build_apart, |
610 | 646 | test_a_native_build_ignores_the_variant, |
611 | 647 | test_a_test_ends_as_its_main_ends, |
|
0 commit comments