aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-04-25 17:12:47 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-04-25 17:12:47 -0700
commita7dfddc6abee48cc9484fe8f08f45d053f08dae2 (patch)
tree21f88abdc7bffe6b4b5dcb07bbd10b2eb3820759 /tests
parent5940f5fc55f36e55466716514945cb6ac54c4634 (diff)
support disabling ALIASING_FUNCTION_POINTERS in fastcomp
Diffstat (limited to 'tests')
-rw-r--r--tests/test_other.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_other.py b/tests/test_other.py
index 4b5ed666..0721bb35 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2741,3 +2741,50 @@ int main() {
else:
assert 'abort()' in output, output
+ def test_aliased_func_pointers(self):
+ open('src.cpp', 'w').write(r'''
+#include <stdio.h>
+
+int impl1(int foo) { return foo; }
+float impla(float foo) { return foo; }
+int impl2(int foo) { return foo+1; }
+float implb(float foo) { return foo+1; }
+int impl3(int foo) { return foo+2; }
+float implc(float foo) { return foo+2; }
+
+int main(int argc, char **argv) {
+ volatile void *f = (void*)impl1;
+ if (argc == 50) f = (void*)impla;
+ if (argc == 51) f = (void*)impl2;
+ if (argc == 52) f = (void*)implb;
+ if (argc == 53) f = (void*)impl3;
+ if (argc == 54) f = (void*)implc;
+ return (int)f;
+}
+''')
+
+ print 'aliasing'
+
+ sizes_ii = {}
+ sizes_dd = {}
+
+ for alias in [None, 0, 1]:
+ cmd = [PYTHON, EMCC, 'src.cpp', '-O1']
+ if alias is not None:
+ cmd += ['-s', 'ALIASING_FUNCTION_POINTERS=' + str(alias)]
+ else:
+ alias = -1
+ print cmd
+ Popen(cmd).communicate()
+ src = open('a.out.js').read().split('\n')
+ for line in src:
+ if line.strip().startswith('var FUNCTION_TABLE_ii = '):
+ sizes_ii[alias] = line.count(',')
+ if line.strip().startswith('var FUNCTION_TABLE_dd = '):
+ sizes_dd[alias] = line.count(',')
+
+ for sizes in [sizes_ii, sizes_dd]:
+ assert sizes[-1] == 3 # default - let them alias
+ assert sizes[0] == 7 # no aliasing, all unique, fat tables
+ assert sizes[1] == 3 # aliased once more
+