diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cases/caall.ll | 2 | ||||
-rw-r--r-- | tests/cases/selectadd.ll | 29 | ||||
-rw-r--r-- | tests/cubegeom.c | 6 | ||||
-rw-r--r-- | tests/mmap_file.c | 27 | ||||
-rw-r--r-- | tests/test_browser.py | 11 | ||||
-rw-r--r-- | tests/test_core.py | 151 | ||||
-rw-r--r-- | tests/test_other.py | 98 | ||||
-rw-r--r-- | tests/test_sanity.py | 6 | ||||
-rw-r--r-- | tests/test_sockets.py | 26 |
9 files changed, 271 insertions, 85 deletions
diff --git a/tests/cases/caall.ll b/tests/cases/caall.ll index 313116e6..5b8f7f29 100644 --- a/tests/cases/caall.ll +++ b/tests/cases/caall.ll @@ -18,7 +18,7 @@ entry: define (i32*)** @_ZNSt3__13mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPFvP6ObjectENS_4lessIS6_EENS4_INS_4pairIKS6_SA_EEEEEixERSE_(i32 %x) { entry: %ret = inttoptr i32 0 to (i32*)** - ret %ret + ret (i32*)** %ret } ; [#uses=1] diff --git a/tests/cases/selectadd.ll b/tests/cases/selectadd.ll new file mode 100644 index 00000000..093032b8 --- /dev/null +++ b/tests/cases/selectadd.ll @@ -0,0 +1,29 @@ + +; ModuleID = 'tests/hello_world.bc' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" +target triple = "i386-pc-linux-gnu" + +@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +; [#uses=0] +define i32 @main() { +entry: + br label %zero + +zero: + %.3.ph.i757 = phi i8* [ getelementptr ([15 x i8]* @.str, i32 0, i32 add (i32 xor (i32 ptrtoint (i8* getelementptr ([15 x i8]* @.str, i32 0, i32 select (i1 icmp ugt (i32 sub (i32 0, i32 add (i32 ptrtoint ([15 x i8]* @.str to i32), i32 25)), i32 xor (i32 ptrtoint ([15 x i8]* @.str to i32), i32 -1)), i32 sub (i32 0, i32 add (i32 ptrtoint ([15 x i8]* @.str to i32), i32 25)), i32 xor (i32 ptrtoint ([15 x i8]* @.str to i32), i32 -1))) to i32), i32 -1), i32 25)), %entry ], [ getelementptr ([15 x i8]* @.str, i32 0, i32 ptrtoint (i8* getelementptr ([15 x i8]* @.str, i32 0, i32 add (i32 sub (i32 0, i32 ptrtoint ([15 x i8]* @.str to i32)), i32 25)) to i32)), %other ] + + %retval = alloca i32, align 4 ; [#uses=1 type=i32*] + store i32 0, i32* %retval + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + br label %other + +other: + br i1 0, label %zero, label %last + +last: + ret i32 1 +} + +declare i32 @printf(i8*, ...) + diff --git a/tests/cubegeom.c b/tests/cubegeom.c index fac0da2b..96d56339 100644 --- a/tests/cubegeom.c +++ b/tests/cubegeom.c @@ -194,8 +194,14 @@ int main(int argc, char *argv[]) // sauer vertex data is apparently 0-12: V3F, 12: N1B, 16-24: T2F, 24-28: T2S, 28-32: C4B glVertexPointer(3, GL_FLOAT, 32, (void*)0); // all these apply to the ARRAY_BUFFER that is bound glTexCoordPointer(2, GL_FLOAT, 32, (void*)16); + glClientActiveTexture(GL_TEXTURE1); // XXX seems to be ignored in native build glTexCoordPointer(2, GL_SHORT, 32, (void*)24); + glGetIntegerv(GL_TEXTURE_COORD_ARRAY_SIZE, &tempInt); assert(tempInt == 2); + glGetIntegerv(GL_TEXTURE_COORD_ARRAY_TYPE, &tempInt); assert(tempInt == GL_SHORT); + glGetIntegerv(GL_TEXTURE_COORD_ARRAY_STRIDE, &tempInt); assert(tempInt == 32); + glGetPointerv(GL_TEXTURE_COORD_ARRAY_POINTER, &tempPtr); assert(tempPtr == (void *)24); + glClientActiveTexture(GL_TEXTURE0); // likely not needed, it is a cleanup glNormalPointer(GL_BYTE, 32, (void*)12); glColorPointer(4, GL_UNSIGNED_BYTE, 32, (void*)28); diff --git a/tests/mmap_file.c b/tests/mmap_file.c new file mode 100644 index 00000000..6eed95e0 --- /dev/null +++ b/tests/mmap_file.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <sys/mman.h> +#include <emscripten.h> +#include <string.h> +#include <assert.h> + +int main() { + printf("*\n"); + FILE *f = fopen("data.dat", "r"); + char *m; + m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 0); + for (int i = 0; i < 20; i++) putchar(m[i]); + assert(!strncmp(m, "data from the file .", 20)); + munmap(m, 9000); + printf("\n"); + m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 5); + for (int i = 0; i < 20; i++) putchar(m[i]); + assert(!strncmp(m, "from the file ......", 20)); + munmap(m, 9000); + printf("\n*\n"); + +#ifdef REPORT_RESULT + int result = 1; + REPORT_RESULT(); +#endif + return 0; +} diff --git a/tests/test_browser.py b/tests/test_browser.py index 2ff9106b..d52f109f 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -338,7 +338,7 @@ If manually bisecting: ("somefile.txt@/directory/file.txt", "/directory/file.txt"), ("somefile.txt@/directory/file.txt", "directory/file.txt"), (absolute_src_path + "@/directory/file.txt", "directory/file.txt")] - + for test in test_cases: (srcpath, dstpath) = test print 'Testing', srcpath, dstpath @@ -346,6 +346,11 @@ If manually bisecting: Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', srcpath, '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1') + # Test that '--no-heap-copy' works. + make_main('somefile.txt') + Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', 'somefile.txt', '--no-heap-copy', '-o', 'page.html']).communicate() + self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1') + # By absolute path make_main('somefile.txt') # absolute becomes relative @@ -1566,3 +1571,7 @@ keydown(100);keyup(100); // trigger the end Popen([PYTHON, EMCC, path_from_root('tests', 'browser_module.cpp'), '-o', 'module.js', '-O2', '-s', 'SIDE_MODULE=1', '-s', 'DLOPEN_SUPPORT=1', '-s', 'EXPORTED_FUNCTIONS=["_one", "_two"]']).communicate() self.btest('browser_main.cpp', args=['-O2', '-s', 'MAIN_MODULE=1', '-s', 'DLOPEN_SUPPORT=1'], expected='8') + def test_mmap_file(self): + open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000)) + for extra_args in [[], ['--no-heap-copy']]: + self.btest(path_from_root('tests', 'mmap_file.c'), expected='1', args=['--preload-file', 'data.dat'] + extra_args) diff --git a/tests/test_core.py b/tests/test_core.py index 189da2bc..b2147d49 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -3814,7 +3814,6 @@ def process(filename): self.do_run(open(path_from_root('tests', 'emscripten_get_now.cpp')).read(), 'Timer resolution is good.') def test_inlinejs(self): - if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code if not self.is_le32(): return self.skip('le32 needed for inline js') src = r''' #include <stdio.h> @@ -3842,7 +3841,6 @@ def process(filename): self.do_run(src, 'Inline JS is very cool\n3.64\n') # TODO 1\n2\n3\n1\n2\n3\n') def test_inlinejs2(self): - if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code if not self.is_le32(): return self.skip('le32 needed for inline js') src = r''' #include <stdio.h> @@ -8594,30 +8592,13 @@ void*:16 def test_mmap_file(self): if self.emcc_args is None: return self.skip('requires emcc') - self.emcc_args += ['--embed-file', 'data.dat'] + for extra_args in [[], ['--no-heap-copy']]: + self.emcc_args += ['--embed-file', 'data.dat'] + extra_args - open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000)) + open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000)) - src = r''' - #include <stdio.h> - #include <sys/mman.h> - - int main() { - printf("*\n"); - FILE *f = fopen("data.dat", "r"); - char *m; - m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 0); - for (int i = 0; i < 20; i++) putchar(m[i]); - munmap(m, 9000); - printf("\n"); - m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 5); - for (int i = 0; i < 20; i++) putchar(m[i]); - munmap(m, 9000); - printf("\n*\n"); - return 0; - } - ''' - self.do_run(src, '*\ndata from the file .\nfrom the file ......\n*\n') + src = open(path_from_root('tests', 'mmap_file.c')).read() + self.do_run(src, '*\ndata from the file .\nfrom the file ......\n*\n') def test_cubescript(self): if self.emcc_args is None: return self.skip('requires emcc') @@ -8660,6 +8641,128 @@ void*:16 main = main[:main.find('\n}')] assert main.count('\n') == 7, 'must not emit too many postSets: %d' % main.count('\n') + def test_simd(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2') + if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate + src = r''' +#include <stdio.h> + +#include <emscripten/vector.h> + +static inline float32x4 __attribute__((always_inline)) +_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) +{ + return (float32x4){ __W, __X, __Y, __Z }; +} + +static __inline__ float32x4 __attribute__((__always_inline__)) +_mm_setzero_ps(void) +{ + return (float32x4){ 0.0, 0.0, 0.0, 0.0 }; +} + +int main(int argc, char **argv) { + float data[8]; + for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer + { + float32x4 *a = (float32x4*)&data[0]; + float32x4 *b = (float32x4*)&data[4]; + float32x4 c, d; + c = *a; + d = *b; + printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + c = c+d; + printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + d = c*d; + printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + c = _mm_setzero_ps(); + printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]); + } + { + uint32x4 *a = (uint32x4*)&data[0]; + uint32x4 *b = (uint32x4*)&data[4]; + uint32x4 c, d, e, f; + c = *a; + d = *b; + printf("4uints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]); + e = c+d; + f = c-d; + printf("5uints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); + e = c&d; + f = c|d; + e = ~c&d; + f = c^d; + printf("5uintops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); + } + { + float32x4 c, d, e, f; + c = _mm_set_ps(9.0, 4.0, 0, -9.0); + d = _mm_set_ps(10.0, 14.0, -12, -2.0); + printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well + } + + return 0; +} + ''' + + self.do_run(src, '''1floats! 6, 12, 20, 30 42, 56, 72, 90 +2floats! 48, 68, 92, 120 42, 56, 72, 90 +3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800 +zeros 0, 0, 0, 0 +4uints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736 +5uints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056 +5uintops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096 +6floats! -9, 0, 4, 9 -2, -12, 14, 10 +''') + + def test_simd2(self): + if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate + + self.do_run(r''' + #include <stdio.h> + + typedef float __m128 __attribute__ ((__vector_size__ (16))); + + static inline __m128 __attribute__((always_inline)) + _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) + { + return (__m128){ __W, __X, __Y, __Z }; + } + + static inline void __attribute__((always_inline)) + _mm_store_ps(float *__P, __m128 __A) + { + *(__m128 *)__P = __A; + } + + static inline __m128 __attribute__((always_inline)) + _mm_add_ps(__m128 __A, __m128 __B) + { + return __A + __B; + } + + using namespace std; + + int main(int argc, char ** argv) { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0); + __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0); + __m128 v3 = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v3); + + for (int i = 0; i < 4; i++) { + printf("%f\n", ar[i]); + } + + return 0; + } + ''', '''-8.000000 +2.500000 +7.000000 +16.000000 +''') + def test_gcc_unmangler(self): Settings.NAMED_GLOBALS = 1 # test coverage for this diff --git a/tests/test_other.py b/tests/test_other.py index 185e83d1..584f6714 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2010,69 +2010,51 @@ a(int [32], char [5]*) try_delete(path_from_root('tests', 'Module-exports', 'test.js')) try_delete(path_from_root('tests', 'Module-exports', 'test.js.map')) - def test_simd(self): - self.clear() - Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate() - self.assertContained('Unrolled Single Precision', run_js('a.out.js')) - - def test_simd2(self): - self.clear() + def test_fs_stream_proto(self): open('src.cpp', 'w').write(r''' #include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/stat.h> +#include <errno.h> +#include <string.h> -#include <emscripten/vector.h> - -static inline float32x4 __attribute__((always_inline)) -_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) +int main() { - return (float32x4){ __W, __X, __Y, __Z }; -} - -int main(int argc, char **argv) { - float data[8]; - for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); - { - float32x4 *a = (float32x4*)&data[0]; - float32x4 *b = (float32x4*)&data[4]; - float32x4 c, d; - c = *a; - d = *b; - printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - c = c+d; - printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - d = c*d; - printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - } - { - uint32x4 *a = (uint32x4*)&data[0]; - uint32x4 *b = (uint32x4*)&data[4]; - uint32x4 c, d, e, f; - c = *a; - d = *b; - printf("4uints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]); - e = c+d; - f = c-d; - printf("5uints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); - } - { - float32x4 c, d, e, f; - c = _mm_set_ps(9.0, 4.0, 0, -9.0); - d = _mm_set_ps(10.0, 14.0, -12, -2.0); - printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - } - - return 0; + int file_size = 0; + int h = open("src.cpp", O_RDONLY, 0666); + if (0 != h) + { + FILE* file = fdopen(h, "rb"); + if (0 != file) + { + fseek(file, 0, SEEK_END); + file_size = ftell(file); + fseek(file, 0, SEEK_SET); + } + else + { + printf("fdopen() failed: %s\n", strerror(errno)); + return 10; + } + close(h); + printf("File size: %d\n", file_size); + } + else + { + printf("open() failed: %s\n", strerror(errno)); + return 10; + } + return 0; } ''') + Popen([PYTHON, EMCC, 'src.cpp', '--embed-file', 'src.cpp']).communicate() + for engine in JS_ENGINES: + out = run_js('a.out.js', engine=engine, stderr=PIPE, full_output=True) + self.assertContained('File size: 722', out) - for opts in [[], ['-O1'], ['-O2']]: - print opts - Popen([PYTHON, EMCC, 'src.cpp'] + opts).communicate() - self.assertContained('''1floats! 6, 12, 20, 30 42, 56, 72, 90 -2floats! 48, 68, 92, 120 42, 56, 72, 90 -3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800 -4uints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736 -5uints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056 -6floats! -9, 0, 4, 9 -2, -12, 14, 10 -''', run_js('a.out.js')) + def test_simd(self): + self.clear() + Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate() + self.assertContained('Unrolled Single Precision', run_js('a.out.js')) diff --git a/tests/test_sanity.py b/tests/test_sanity.py index a0fff252..a405c3a3 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -217,7 +217,11 @@ class sanity(RunnerCore): try: os.environ['EM_IGNORE_SANITY'] = '1' - for version, succeed in [('v0.7.9', False), ('v0.8.0', True), ('v0.8.1', True), ('cheez', False)]: + for version, succeed in [('v0.7.9', False), + ('v0.8.0', True), + ('v0.8.1', True), + ('v0.10.21-pre', True), + ('cheez', False)]: f = open(path_from_root('tests', 'fake', 'nodejs'), 'w') f.write('#!/bin/sh\n') f.write('''if [ $1 = "--version" ]; then diff --git a/tests/test_sockets.py b/tests/test_sockets.py index d2bc46a2..e1caa150 100644 --- a/tests/test_sockets.py +++ b/tests/test_sockets.py @@ -400,3 +400,29 @@ class sockets(BrowserCore): expected = '1' self.run_browser(host_outfile, '.', ['/report_result?' + e for e in expected]) + def test_nodejs_sockets_echo(self): + # This test checks that sockets work when the client code is run in Node.js + # Run with ./runner.py sockets.test_nodejs_sockets_echo + if not NODE_JS in JS_ENGINES: + return self.skip('node is not present') + + sockets_include = '-I'+path_from_root('tests', 'sockets') + + # Websockify-proxied servers can't run dgram tests + harnesses = [ + # Websockify doesn't seem to like ws.WebSocket clients TODO check if this is a ws issue or Websockify issue + #(WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 49160), 0), + (CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=0'], 49161), 0), + (CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=1'], 49162), 1) + ] + + for harness, datagram in harnesses: + with harness: + Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', path_from_root('tests', 'sockets', 'client.js'), '-DSOCKK=%d' % harness.listen_port, '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate() + + self.assertContained('do_msg_read: read 14 bytes', run_js(path_from_root('tests', 'sockets', 'client.js'), engine=NODE_JS)) + + # Tidy up files that might have been created by this test. + try_delete(path_from_root('tests', 'sockets', 'client.js')) + try_delete(path_from_root('tests', 'sockets', 'client.js.map')) + |