diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-27 12:47:26 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-27 12:47:33 -0800 |
commit | b4605f200c14fefe6126d8e408edd00c15ac3280 (patch) | |
tree | ceda2fa7d2a8b26f28eda80a199883b0d97232cc /tests | |
parent | 0a42984265e281db88521c8f5adce1558ededa66 (diff) |
run -globalopt when NO_EXIT_RUNTIME, to get rid of global initializers entirely in some cases
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_other.py | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/tests/test_other.py b/tests/test_other.py index d12374dd..49b9dcd1 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2417,9 +2417,9 @@ int main(int argc, char **argv) { ''') for no_exit in [0, 1]: - for opts in [0, 1]: + for opts in [[], ['-O1'], ['-O2', '-g2']]: print no_exit, opts - Popen([PYTHON, EMCC, '-O' + str(opts), 'code.cpp', '-s', 'NO_EXIT_RUNTIME=' + str(no_exit)]).communicate() + Popen([PYTHON, EMCC] + opts + ['code.cpp', '-s', 'NO_EXIT_RUNTIME=' + str(no_exit)]).communicate() output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS) src = open('a.out.js').read() exit = 1-no_exit @@ -2446,3 +2446,64 @@ int main(int argc, char **argv) { finally: del os.environ['EMCC_DEBUG'] + def test_global_inits(self): + open('inc.h', 'w').write(r''' +#include <stdio.h> + +template<int x> +struct Waste { + int state; + Waste() : state(10) {} + void test(int a) { + printf("%d\n", a + state); + } + ~Waste() { + printf("going away %d\n", x); + } +}; + +Waste<3> *getMore(); + +''') + open('main.cpp', 'w').write(r''' +#include "inc.h" + +Waste<1> mw1; +Waste<2> mw2; + +int main(int argc, char **argv) { + printf("argc: %d\n", argc); + mw1.state += argc; + mw2.state += argc; + mw1.test(5); + mw2.test(6); + getMore()->test(0); + return 0; +} +''') + + open('side.cpp', 'w').write(r''' +#include "inc.h" + +Waste<3> sw3; + +Waste<3> *getMore() { + return &sw3; +} +''') + + for opts, has_global in [ + (['-O2', '-g'], True), + (['-O2', '-g', '-s', 'NO_EXIT_RUNTIME=1'], False), # no-exit-runtime removes the atexits, and then globalgce can work it's magic to remove the global initializer entirely + (['-Os', '-g'], True), + (['-Os', '-g', '-s', 'NO_EXIT_RUNTIME=1'], False), # no-exit-runtime removes the atexits, and then globalgce can work it's magic to remove the global initializer entirely + ]: + print opts, has_global + Popen([PYTHON, EMCC, 'main.cpp', '-c'] + opts).communicate() + Popen([PYTHON, EMCC, 'side.cpp', '-c'] + opts).communicate() + Popen([PYTHON, EMCC, 'main.o', 'side.o'] + opts).communicate() + output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS) + src = open('a.out.js').read() + self.assertContained('argc: 1\n16\n17\n10\n', run_js('a.out.js')) + assert ('_GLOBAL_' in src) == has_global + |