diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/checksummer.c | 71 | ||||
-rw-r--r-- | tests/cubegeom.c | 8 | ||||
-rwxr-xr-x | tests/runner.py | 333 | ||||
-rw-r--r-- | tests/sdl_image_prepare_data.c | 69 | ||||
-rw-r--r-- | tests/sdl_resize.c | 45 | ||||
-rw-r--r-- | tests/websockets_bi_bigdata.c | 137 | ||||
-rw-r--r-- | tests/websockets_bi_side_bigdata.c | 69 | ||||
-rw-r--r-- | tests/websockets_bigdata.h | 20 |
8 files changed, 719 insertions, 33 deletions
diff --git a/tests/checksummer.c b/tests/checksummer.c new file mode 100644 index 00000000..c3eb1eea --- /dev/null +++ b/tests/checksummer.c @@ -0,0 +1,71 @@ +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +const int MOD_ADLER = 65521; + +uint64_t adler32(unsigned char *data, int32_t len) /* where data is the location of the data in physical memory and + len is the length of the data in bytes */ +{ + uint64_t a = 1, b = 0; + int32_t index; + + /* Process each byte of the data in order */ + for (index = 0; index < len; ++index) + { + a = (a + data[index]) % MOD_ADLER; + b = (b + a) % MOD_ADLER; + } + + return (b << 16) | a; +} + +int main(int argc, char* argv[]) { + long bufsize; + + if (argc != 2) { + fputs("Need 1 argument\n", stderr); + return (EXIT_FAILURE); + } + + unsigned char *source = NULL; + FILE *fp = fopen(argv[1], "rb"); + if (fp != NULL) { + /* Go to the end of the file. */ + if (fseek(fp, 0L, SEEK_END) == 0) { + /* Get the size of the file. */ + bufsize = ftell(fp); + if (bufsize == -1) { fputs("Couldn't get size\n", stderr); return (EXIT_FAILURE); } + + /* Allocate our buffer to that size. */ + source = malloc(sizeof(char) * (bufsize + 1)); + if (source == NULL) { fputs("Couldn't allocate\n", stderr); return (EXIT_FAILURE); } + + /* Go back to the start of the file. */ + if (fseek(fp, 0L, SEEK_SET) == -1) { fputs("Couldn't seek\n", stderr); return (EXIT_FAILURE); } + + /* Read the entire file into memory. */ + size_t newLen = fread(source, sizeof(char), bufsize, fp); + if (newLen == 0) { + fputs("Error reading file\n", stderr); + //return (EXIT_FAILURE); + } else { + source[++newLen] = '\0'; /* Just to be safe. */ + } + } else { + fputs("Couldn't seek to end\n", stderr); + return (EXIT_FAILURE); + } + fclose(fp); + } else { + fputs("Couldn't open\n", stderr); + return (EXIT_FAILURE); + } + + printf("%d\n", (uint32_t) adler32(source, bufsize)); + + free(source); /* Don't forget to call free() later! */ + + return (EXIT_SUCCESS); + +} diff --git a/tests/cubegeom.c b/tests/cubegeom.c index ecefb24a..c137ad80 100644 --- a/tests/cubegeom.c +++ b/tests/cubegeom.c @@ -256,6 +256,14 @@ int main(int argc, char *argv[]) GLint lightmapLocation = glGetUniformLocation(program, "lightmap"); assert(lightmapLocation >= 0); + assert(lightmapLocation == glGetUniformLocation(program, "lightmap")); // must get identical ids + glLinkProgram(program); + glGetProgramiv(program, GL_LINK_STATUS, &ok); + assert(ok); + assert(lightmapLocation != glGetUniformLocation(program, "lightmap")); // must NOT get identical ids, we re-linked! + lightmapLocation = glGetUniformLocation(program, "lightmap"); + assert(lightmapLocation == glGetUniformLocation(program, "lightmap")); // must get identical ids + glUniform1i(lightmapLocation, 1); // sampler2D? Is it the texture unit? GLint diffusemapLocation = glGetUniformLocation(program, "diffusemap"); diff --git a/tests/runner.py b/tests/runner.py index a8af375c..41b9ee19 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -41,6 +41,12 @@ To run a specific set of tests, you can do things like Combinations work too, for example python tests/runner.py browser.test_sdl_image + +In the main test suite, you can run all variations (O0, O1, O2, etc.) of +an individual test with + + python tests/runner.py ALL.test_hello_world + ============================================================================== ''' @@ -394,6 +400,11 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv) and 'brows print "Running Emscripten tests..." + if len(sys.argv) == 2 and 'ALL.' in sys.argv[1]: + ignore, test = sys.argv[1].split('.') + print 'Running all test modes on test "%s"' % test + sys.argv = [sys.argv[0], 'default.'+test, 'o1.'+test, 'o2.'+test, 's_0_0.'+test, 's_0_1.'+test, 's_0_1_q1.'+test, 's_1_0.'+test, 's_1_1.'+test, 's_1_1_q1.'+test] + class T(RunnerCore): # Short name, to make it more fun to use manually on the commandline ## Does a complete test - builds, runs, checks output, etc. def do_run(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[]): @@ -1183,16 +1194,11 @@ c5,de,15,8a } ''' - Settings.EMULATE_UNALIGNED_ACCESSES = 0 - try: self.do_run(src, '*300:1*\n*515559*\n*42949672960*\n') except Exception, e: assert 'must be aligned' in str(e), e # expected to fail without emulation - # XXX TODO Settings.EMULATE_UNALIGNED_ACCESSES = 1 - #self.do_run(src, '*300:1*\n*515559*\n*42949672960*\n') # but succeeds with it - def test_unsigned(self): Settings.CORRECT_SIGNS = 1 # We test for exactly this sort of thing here Settings.CHECK_SIGNS = 0 @@ -4264,13 +4270,20 @@ at function.:blag printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); printf("%d,%u,%d\n", neg, neg2, neg3); + { + int a = 0; + sscanf("1", "%i", &a); + printf("%i\n", a); + } + return 0; } ''' self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n2.8208\n-3.0300\n|some|\n|something|\n|somethingmoar|\n' + '1\n1499\n' + '5\n87,0.481565,0.059481,0,1\n' + - '3\n-123,4294966531,-34\n') + '3\n-123,4294966531,-34\n' + + '1\n') def test_sscanf_2(self): # doubles @@ -7272,6 +7285,26 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'test.cpp'), '-fcatch-undefined-behavior']).communicate() self.assertContained('hello, world!', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_unaligned_memory(self): + open(os.path.join(self.get_dir(), 'test.cpp'), 'w').write(r''' + #include <stdio.h> + + typedef unsigned char Bit8u; + typedef unsigned short Bit16u; + typedef unsigned int Bit32u; + + int main() + { + Bit8u data[4] = {0x01,0x23,0x45,0x67}; + + printf("data: %x\n", *(Bit32u*)data); + printf("data[0,1] 16bit: %x\n", *(Bit16u*)data); + printf("data[1,2] 16bit: %x\n", *(Bit16u*)(data+1)); + } + ''') + Popen(['python', EMCC, os.path.join(self.get_dir(), 'test.cpp'), '-s', 'UNALIGNED_MEMORY=1']).communicate() + self.assertContained('data: 67452301\ndata[0,1] 16bit: 2301\ndata[1,2] 16bit: 4523', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_l_link(self): # Linking with -lLIBNAME and -L/DIRNAME should work @@ -7343,6 +7376,70 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), os.path.join(self.get_dir(), 'subdir', 'libfile.so'), '-L.']).communicate() self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_runtimelink_multi(self): + open('testa.h', 'w').write(r''' + #ifndef _TESTA_H_ + #define _TESTA_H_ + + class TestA { + public: + TestA(); + }; + + #endif + ''') + open('testb.h', 'w').write(r''' + #ifndef _TESTB_H_ + #define _TESTB_H_ + + class TestB { + public: + TestB(); + }; + + #endif + ''') + open('testa.cpp', 'w').write(r''' + #include <stdio.h> + #include <testa.h> + + TestA::TestA() { + printf("TestA\n"); + } + ''') + open('testb.cpp', 'w').write(r''' + #include <stdio.h> + #include <testb.h> + #include <testa.h> + /* + */ + TestB::TestB() { + printf("TestB\n"); + TestA* testa = new TestA(); + } + ''') + open('main.cpp', 'w').write(r''' + #include <stdio.h> + #include <testa.h> + #include <testb.h> + + /* + */ + int main(int argc, char** argv) { + printf("Main\n"); + TestA* testa = new TestA(); + TestB* testb = new TestB(); + } + ''') + + Popen(['python', EMCC, 'testa.cpp', '-o', 'liba.js', '-s', 'BUILD_AS_SHARED_LIB=2', '-s', 'LINKABLE=1', '-I.']).communicate() + Popen(['python', EMCC, 'testb.cpp', '-o', 'libb.js', '-s', 'BUILD_AS_SHARED_LIB=2', '-s', 'LINKABLE=1', '-I.']).communicate() + Popen(['python', EMCC, 'main.cpp', '-o', 'main.js', '-s', 'RUNTIME_LINKED_LIBS=["liba.js", "libb.js"]', '-I.']).communicate() + + Popen(['python', EMCC, 'main.cpp', 'testa.cpp', 'testb.cpp', '-o', 'full.js', '-I.']).communicate() + + self.assertContained('TestA\nTestB\nTestA\n', run_js('main.js', engine=SPIDERMONKEY_ENGINE)) + def test_js_libraries(self): open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(''' #include <stdio.h> @@ -8506,6 +8603,11 @@ elif 'browser' in str(sys.argv): shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) self.btest('sdl_image_prepare.c', reference='screenshot.jpg', args=['--preload-file', 'screenshot.not']) + def test_sdl_image_prepare_data(self): + # load an image file, get pixel data. Also O2 coverage for --preload-file + shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) + self.btest('sdl_image_prepare_data.c', reference='screenshot.jpg', args=['--preload-file', 'screenshot.not']) + def test_sdl_canvas(self): open(os.path.join(self.get_dir(), 'sdl_canvas.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_canvas.c')).read())) @@ -8678,6 +8780,114 @@ elif 'browser' in str(sys.argv): html_file.close() self.run_browser('main.html', 'You should see that the worker was called, and said "hello from worker!"', '/report_result?hello%20from%20worker!') + def test_chunked_synchronous_xhr(self): + main = 'chunked_sync_xhr.html' + worker_filename = "download_and_checksum_worker.js" + + html_file = open(main, 'w') + html_file.write(r""" + <!doctype html> + <html> + <head><meta charset="utf-8"><title>Chunked XHR</title></head> + <html> + <body> + Chunked XHR Web Worker Test + <script> + var worker = new Worker(""" + json.dumps(worker_filename) + r"""); + var buffer = []; + worker.onmessage = function(event) { + if (event.data.channel === "stdout") { + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'http://localhost:8888/report_result?' + event.data.line); + xhr.send(); + setTimeout(function() { window.close() }, 1000); + } else { + if (event.data.trace) event.data.trace.split("\n").map(function(v) { console.error(v); }); + if (event.data.line) { + console.error(event.data.line); + } else { + var v = event.data.char; + if (v == 10) { + var line = buffer.splice(0); + console.error(line = line.map(function(charCode){return String.fromCharCode(charCode);}).join('')); + } else { + buffer.push(v); + } + } + } + }; + </script> + </body> + </html> + """) + html_file.close() + + c_source_filename = "checksummer.c" + + prejs_filename = "worker_prejs.js" + prejs_file = open(prejs_filename, 'w') + prejs_file.write(r""" + if (typeof(Module) === "undefined") Module = {}; + Module["arguments"] = ["/bigfile"]; + Module["preInit"] = function() { + FS.createLazyFile('/', "bigfile", "http://localhost:11111/bogus_file_path", true, false); + }; + var doTrace = true; + Module["print"] = function(s) { self.postMessage({channel: "stdout", line: s}); }; + Module["stderr"] = function(s) { self.postMessage({channel: "stderr", char: s, trace: ((doTrace && s === 10) ? new Error().stack : null)}); doTrace = false; }; + """) + prejs_file.close() + # vs. os.path.join(self.get_dir(), filename) + # vs. path_from_root('tests', 'hello_world_gles.c') + Popen(['python', EMCC, path_from_root('tests', c_source_filename), '-g', '-s', 'SMALL_CHUNKS=1', '-o', worker_filename, + '--pre-js', prejs_filename]).communicate() + + chunkSize = 1024 + data = os.urandom(10*chunkSize+1) # 10 full chunks and one 1 byte chunk + expectedConns = 11 + import zlib + checksum = zlib.adler32(data) + + def chunked_server(support_byte_ranges): + class ChunkedServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): + @staticmethod + def sendheaders(s, extra=[], length=len(data)): + s.send_response(200) + s.send_header("Content-Length", str(length)) + s.send_header("Access-Control-Allow-Origin", "http://localhost:8888") + s.send_header("Access-Control-Expose-Headers", "Content-Length, Accept-Ranges") + s.send_header("Content-type", "application/octet-stream") + if support_byte_ranges: + s.send_header("Accept-Ranges", "bytes") + for i in extra: + s.send_header(i[0], i[1]) + s.end_headers() + + def do_HEAD(s): + ChunkedServerHandler.sendheaders(s) + + def do_GET(s): + if not support_byte_ranges: + ChunkedServerHandler.sendheaders(s) + s.wfile.write(data) + else: + (start, end) = s.headers.get("range").split("=")[1].split("-") + start = int(start) + end = int(end) + end = min(len(data)-1, end) + length = end-start+1 + ChunkedServerHandler.sendheaders(s,[],length) + s.wfile.write(data[start:end+1]) + s.wfile.close() + httpd = BaseHTTPServer.HTTPServer(('localhost', 11111), ChunkedServerHandler) + for i in range(expectedConns+1): + httpd.handle_request() + + server = multiprocessing.Process(target=chunked_server, args=(True,)) + server.start() + self.run_browser(main, 'Chunked binary synchronous XHR in Web Workers!', '/report_result?' + str(checksum)) + server.terminate() + def test_glgears(self): self.reftest(path_from_root('tests', 'gears.png')) Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html', @@ -8764,6 +8974,9 @@ elif 'browser' in str(sys.argv): def test_sdl_quit(self): self.btest('sdl_quit.c', '1') + def test_sdl_resize(self): + self.btest('sdl_resize.c', '1') + def test_gc(self): self.btest('browser_gc.cpp', '1') @@ -8782,52 +8995,52 @@ elif 'browser' in str(sys.argv): self.btest('gl_matrix_identity.c', expected=['-1882984448', '460451840']) def test_cubegeom_pre(self): - self.btest('cubegeom_pre.c', expected=['-1472804742', '-1626058463']) + self.btest('cubegeom_pre.c', expected=['-1472804742', '-1626058463', '-2046234971']) def test_cubegeom_pre2(self): - self.btest('cubegeom_pre2.c', expected=['-1472804742', '-1626058463'], args=['-s', 'GL_DEBUG=1']) # some coverage for GL_DEBUG not breaking the build + self.btest('cubegeom_pre2.c', expected=['-1472804742', '-1626058463', '-2046234971'], args=['-s', 'GL_DEBUG=1']) # some coverage for GL_DEBUG not breaking the build def test_cubegeom_pre3(self): - self.btest('cubegeom_pre3.c', expected=['-1472804742', '-1626058463']) + self.btest('cubegeom_pre3.c', expected=['-1472804742', '-1626058463', '-2046234971']) def test_cubegeom(self): - self.btest('cubegeom.c', expected=['188641320', '1522377227', '-1054007155']) + self.btest('cubegeom.c', expected=['188641320', '1522377227', '-1054007155', '-1111866053']) def test_cubegeom_color(self): - self.btest('cubegeom_color.c', expected=['588472350', '-687660609']) + self.btest('cubegeom_color.c', expected=['588472350', '-687660609', '-818120875']) def test_cubegeom_normal(self): - self.btest('cubegeom_normal.c', expected=['752917084', '-251570256']) + self.btest('cubegeom_normal.c', expected=['752917084', '-251570256', '-291655550']) def test_cubegeom_normal_dap(self): # draw is given a direct pointer to clientside memory, no element array buffer - self.btest('cubegeom_normal_dap.c', expected=['752917084', '-251570256']) + self.btest('cubegeom_normal_dap.c', expected=['752917084', '-251570256', '-291655550']) def test_cubegeom_normal_dap_far(self): # indices do nto start from 0 - self.btest('cubegeom_normal_dap_far.c', expected=['752917084', '-251570256']) + self.btest('cubegeom_normal_dap_far.c', expected=['752917084', '-251570256', '-291655550']) def test_cubegeom_normal_dap_far_range(self): # glDrawRangeElements - self.btest('cubegeom_normal_dap_far_range.c', expected=['752917084', '-251570256']) + self.btest('cubegeom_normal_dap_far_range.c', expected=['752917084', '-251570256', '-291655550']) def test_cubegeom_normal_dap_far_glda(self): # use glDrawArrays - self.btest('cubegeom_normal_dap_far_glda.c', expected=['-218745386', '-263951846']) + self.btest('cubegeom_normal_dap_far_glda.c', expected=['-218745386', '-263951846', '-375182658']) def test_cubegeom_normal_dap_far_glda_quad(self): # with quad - self.btest('cubegeom_normal_dap_far_glda_quad.c', expected=['1757386625', '-677777235']) + self.btest('cubegeom_normal_dap_far_glda_quad.c', expected=['1757386625', '-677777235', '-690699597']) def test_cubegeom_mt(self): - self.btest('cubegeom_mt.c', expected=['-457159152', '910983047']) # multitexture + self.btest('cubegeom_mt.c', expected=['-457159152', '910983047', '870576921']) # multitexture def test_cubegeom_color2(self): - self.btest('cubegeom_color2.c', expected=['1121999515', '-391668088']) + self.btest('cubegeom_color2.c', expected=['1121999515', '-391668088', '-522128354']) def test_cubegeom_texturematrix(self): - self.btest('cubegeom_texturematrix.c', expected=['1297500583', '-791216738']) + self.btest('cubegeom_texturematrix.c', expected=['1297500583', '-791216738', '-783804685']) def test_cubegeom_fog(self): - self.btest('cubegeom_fog.c', expected=['1617140399', '-898782526']) + self.btest('cubegeom_fog.c', expected=['1617140399', '-898782526', '-946179526']) def test_cube_explosion(self): - self.btest('cube_explosion.c', expected=['667220544', '-1543354600']) + self.btest('cube_explosion.c', expected=['667220544', '-1543354600', '-1485258415']) def test_sdl_canvas_palette(self): self.btest('sdl_canvas_palette.c', reference='sdl_canvas_palette.png') @@ -8944,6 +9157,7 @@ elif 'browser' in str(sys.argv): def websockify_func(q): print >> sys.stderr, 'running websockify on %d, forward to tcp %d' % (self.port+1, self.port) proc = Popen([path_from_root('third_party', 'websockify', 'other', 'websockify'), '-vvv', str(self.port+1), '127.0.0.1:' + str(self.port)]) + #proc = Popen([path_from_root('third_party', 'websockify', 'websockify.py'), '-vvv', str(self.port+1), '127.0.0.1:' + str(self.port)]) q.put(proc.pid) proc.communicate() @@ -9003,6 +9217,15 @@ elif 'browser' in str(sys.argv): finally: self.clean_pids() + def zzztest_zz_websockets_bi_bigdata(self): + try: + with self.WebsockHarness(3992, self.make_relay_server(3992, 3994)): + with self.WebsockHarness(3994, no_server=True): + Popen(['python', EMCC, path_from_root('tests', 'websockets_bi_side_bigdata.c'), '-o', 'side.html', '-DSOCKK=3995', '-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests')]).communicate() + self.btest('websockets_bi_bigdata.c', expected='0', args=['-s', 'SOCKET_DEBUG=0', '-I' + path_from_root('tests')]) + finally: + self.clean_pids() + def zzztest_zz_enet(self): try_delete(self.in_dir('enet')) shutil.copytree(path_from_root('tests', 'enet'), self.in_dir('enet')) @@ -9106,13 +9329,13 @@ elif 'benchmark' in str(sys.argv): print ' JavaScript: mean: %.3f (+-%.3f) secs median: %.3f range: %.3f-%.3f (noise: %3.3f%%) (%d runs)' % (mean, std, median, min(times), max(times), 100*std/mean, TEST_REPS) print ' Native : mean: %.3f (+-%.3f) secs median: %.3f range: %.3f-%.3f (noise: %3.3f%%) JS is %.2f X slower' % (mean_native, std_native, median_native, min(native_times), max(native_times), 100*std_native/mean_native, final) - def do_benchmark(self, src, args=[], expected_output='FAIL', emcc_args=[]): + def do_benchmark(self, name, src, args=[], expected_output='FAIL', emcc_args=[]): dirname = self.get_dir() - filename = os.path.join(dirname, 'src.cpp') + filename = os.path.join(dirname, name + '.cpp') f = open(filename, 'w') f.write(src) f.close() - final_filename = os.path.join(dirname, 'src.js') + final_filename = os.path.join(dirname, name + '.js') try_delete(final_filename) output = Popen(['python', EMCC, filename, '-O3', @@ -9175,7 +9398,7 @@ elif 'benchmark' in str(sys.argv): return 1; } ''' - self.do_benchmark(src, [], 'lastprime: 1297001.') + self.do_benchmark('primes', src, [], 'lastprime: 1297001.') def test_memops(self): src = ''' @@ -9198,7 +9421,7 @@ elif 'benchmark' in str(sys.argv): return 1; } ''' - self.do_benchmark(src, [], 'final: 720.') + self.do_benchmark('memops', src, [], 'final: 720.') def zzztest_files(self): src = r''' @@ -9284,11 +9507,11 @@ elif 'benchmark' in str(sys.argv): return 1; } ''' - self.do_benchmark(src, [], 'sum:9928\n', emcc_args=['-s', 'QUANTUM_SIZE=4', '-s', 'USE_TYPED_ARRAYS=2']) + self.do_benchmark('copy', src, [], 'sum:9928\n', emcc_args=['-s', 'QUANTUM_SIZE=4', '-s', 'USE_TYPED_ARRAYS=2']) def test_fannkuch(self): src = open(path_from_root('tests', 'fannkuch.cpp'), 'r').read() - self.do_benchmark(src, ['10'], 'Pfannkuchen(10) = 38.') + self.do_benchmark('fannkuch', src, ['10'], 'Pfannkuchen(10) = 38.') def test_corrections(self): src = r''' @@ -9311,11 +9534,11 @@ elif 'benchmark' in str(sys.argv): return 1; } ''' - self.do_benchmark(src, [], 'final: 826:14324.', emcc_args=['-s', 'CORRECT_SIGNS=1', '-s', 'CORRECT_OVERFLOWS=1', '-s', 'CORRECT_ROUNDINGS=1']) + self.do_benchmark('corrections', src, [], 'final: 826:14324.', emcc_args=['-s', 'CORRECT_SIGNS=1', '-s', 'CORRECT_OVERFLOWS=1', '-s', 'CORRECT_ROUNDINGS=1']) def fasta(self, double_rep): src = open(path_from_root('tests', 'fasta.cpp'), 'r').read().replace('double', double_rep) - self.do_benchmark(src, ['2100000'], '''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA\nTCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACT\nAAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAG\nGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCG\nCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAGGCCGGGCGCGGT\nGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCA\nGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAA\nTTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAG\nAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCA\nGCCTGGGCGA''') + self.do_benchmark('fasta', src, ['2100000'], '''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA\nTCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACT\nAAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAG\nGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCG\nCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAGGCCGGGCGCGGT\nGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCA\nGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAA\nTTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAG\nAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCA\nGCCTGGGCGA''') def test_fasta_float(self): self.fasta('float') @@ -9325,12 +9548,12 @@ elif 'benchmark' in str(sys.argv): def test_skinning(self): src = open(path_from_root('tests', 'skinning_test_no_simd.cpp'), 'r').read() - self.do_benchmark(src, ['10000', '1000'], 'blah=0.000000') + self.do_benchmark('skinning', src, ['10000', '1000'], 'blah=0.000000') def test_dlmalloc(self): # XXX This seems to have regressed slightly with emcc. Are -g and the signs lines passed properly? src = open(path_from_root('system', 'lib', 'dlmalloc.c'), 'r').read() + '\n\n\n' + open(path_from_root('tests', 'dlmalloc_test.c'), 'r').read() - self.do_benchmark(src, ['400', '400'], '*400,0*', emcc_args=['-g', '-s', 'CORRECT_SIGNS=2', '-s', 'CORRECT_SIGNS_LINES=[4820, 4195, 4250, 4203, 4209, 4239, 4231]']) + self.do_benchmark('dlmalloc', src, ['400', '400'], '*400,0*', emcc_args=['-g', '-s', 'CORRECT_SIGNS=2', '-s', 'CORRECT_SIGNS_LINES=[4820, 4195, 4250, 4203, 4209, 4239, 4231]']) elif 'sanity' in str(sys.argv): @@ -9502,6 +9725,50 @@ elif 'sanity' in str(sys.argv): finally: del os.environ['EM_IGNORE_SANITY'] + def test_node(self): + NODE_WARNING = 'warning: node version appears too old' + NODE_WARNING_2 = 'warning: cannot check node version' + + restore() + + # Clang should report the version number we expect, and emcc should not warn + assert check_node_version() + output = self.check_working(EMCC) + assert NODE_WARNING not in output, output + + # Fake a different node version + restore() + f = open(CONFIG_FILE, 'a') + f.write('NODE_JS = "' + path_from_root('tests', 'fake', 'nodejs') + '"') + f.close() + + if not os.path.exists(path_from_root('tests', 'fake')): + os.makedirs(path_from_root('tests', 'fake')) + + try: + os.environ['EM_IGNORE_SANITY'] = '1' + for version, succeed in [(('v0.6.6'), False), (('v0.6.7'), False), (('v0.6.8'), True), (('v0.6.9'), True), (('v0.7.1'), True), (('v0.7.9'), True), (('v0.8.7'), True), (('v0.8.9'), True), ('cheez', False)]: + f = open(path_from_root('tests', 'fake', 'nodejs'), 'w') + f.write('#!/bin/sh\n') + f.write('''if [ $1 = "--version" ]; then + echo "%s" +else + %s $@ +fi +''' % (version, NODE_JS)) + f.close() + os.chmod(path_from_root('tests', 'fake', 'nodejs'), stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) + if not succeed: + if version[0] == 'v': + self.check_working(EMCC, NODE_WARNING) + else: + self.check_working(EMCC, NODE_WARNING_2) + else: + output = self.check_working(EMCC) + assert NODE_WARNING not in output, output + finally: + del os.environ['EM_IGNORE_SANITY'] + def test_emcc(self): SANITY_MESSAGE = 'Emscripten: Running sanity checks' SANITY_FAIL_MESSAGE = 'sanity check failed to run' diff --git a/tests/sdl_image_prepare_data.c b/tests/sdl_image_prepare_data.c new file mode 100644 index 00000000..87e33399 --- /dev/null +++ b/tests/sdl_image_prepare_data.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_image.h> +#include <assert.h> +#include <emscripten.h> + +SDL_Surface* screen; + +int testImage(const char* fileName) { + printf("IMG_Load: %s\n", fileName); + SDL_Surface *image = IMG_Load(fileName); + if (!image) + { + printf("IMG_Load: %s\n", IMG_GetError()); + return 0; + } + assert(image->format->BitsPerPixel == 32); + assert(image->format->BytesPerPixel == 4); + assert(image->pitch == 4*image->w); + int result = image->w; + + SDL_BlitSurface (image, NULL, screen, NULL); + SDL_FreeSurface (image); + + return result; +} + +void ready(void *arg, const char *fileName) { + printf("ready! %s (%d)\n", fileName, (int)arg); + + static int first = 1; + static const char *seenName; + static void *seenArg; + if (first) { + first = 0; + seenName = fileName; + seenArg = arg; + } else { + printf("%s ? %s == %d\n", fileName, seenName, strcmp(fileName, seenName)); + assert(strcmp(fileName, seenName)); // different names + + assert(seenArg != arg); // different args + + testImage(seenName); + + free(seenName); // As the API docs say, we are responsible for freeing the 'fake' names we are given + + SDL_Flip(screen); + } +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE); + + printf("prepare..\n"); + + #define SIZE 203164 + FILE *f = open("screenshot.not", "rb"); + char *buffer = malloc(SIZE); + fread(buffer, SIZE, 1, f); + fclose(f); + + emscripten_async_prepare_data(buffer, SIZE, "jpg", (void*)25, ready, NULL); + emscripten_async_prepare_data(buffer, SIZE, "jpg", (void*)33, ready, NULL); // twice to see different filenames + + return 0; +} + diff --git a/tests/sdl_resize.c b/tests/sdl_resize.c new file mode 100644 index 00000000..dc3b374e --- /dev/null +++ b/tests/sdl_resize.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> +#include <assert.h> +#include <emscripten.h> + +int stage = 0; + +void loop() { + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_VIDEORESIZE: { + SDL_ResizeEvent *r = (SDL_ResizeEvent*)&event; + printf("resize event! %d:%d\n", r->w, r->h); + switch (stage) { + case 0: + assert(r->w == 100); + assert(r->h == 200); + emscripten_set_canvas_size(123, 246); + stage++; + break; + case 1: + assert(r->w == 123); + assert(r->h == 246); + int result = 1; + REPORT_RESULT(); + break; + } + } + } + } +} + +void main_2(); + +int main() { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + emscripten_set_canvas_size(100, 200); + + emscripten_set_main_loop(loop, 0, 0); +} + diff --git a/tests/websockets_bi_bigdata.c b/tests/websockets_bi_bigdata.c new file mode 100644 index 00000000..9e8635e3 --- /dev/null +++ b/tests/websockets_bi_bigdata.c @@ -0,0 +1,137 @@ +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/ioctl.h> +#if EMSCRIPTEN +#include <emscripten.h> +#endif + +#include "websockets_bigdata.h" + +#define EXPECTED_BYTES DATA_SIZE + +int SocketFD; + +unsigned int get_all_buf(int sock, char* output, unsigned int maxsize) +{ + int bytes; + if (ioctl(sock, FIONREAD, &bytes)) return 0; + if (bytes == 0) return 0; + + char buffer[EXPECTED_BYTES]; + int n; + unsigned int offset = 0; + while((errno = 0, (n = recv(sock, buffer, sizeof(buffer), 0))>0) || + errno == EINTR) { + if(n>0) + { + if (((unsigned int) n)+offset > maxsize) { fprintf(stderr, "too much data!"); exit(EXIT_FAILURE); } + memcpy(output+offset, buffer, n); + offset += n; + } + } + + if(n < 0) { + fprintf(stderr, "error in get_all_buf!"); + exit(EXIT_FAILURE); + } + return offset; +} + +int done = 0; + +void iter(void *arg) { + /* perform read write operations ... */ + static char out[EXPECTED_BYTES]; + static int pos = 0; + printf("so far %d, expecting up to %d\n", pos, EXPECTED_BYTES-pos); + int n = get_all_buf(SocketFD, out+pos, EXPECTED_BYTES-pos); + if (n) printf("read! %d\n", n); + pos += n; + if (pos >= EXPECTED_BYTES) { + shutdown(SocketFD, SHUT_RDWR); + + close(SocketFD); + + done = 1; + + emscripten_cancel_main_loop(); + +#if EMSCRIPTEN + char *comp = generateData(); + int result = strcmp(comp, out); + if (result != 0) { + for (int i = 0; i < DATA_SIZE; i++) { + printf("%d:%d\n", comp[i], out[i]); + } + } + REPORT_RESULT(); +#endif + } +} + +int main(void) +{ + printf("hello from main page\n"); + + struct sockaddr_in stSockAddr; + int Res; + SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (-1 == SocketFD) + { + perror("cannot create socket"); + exit(EXIT_FAILURE); + } + + memset(&stSockAddr, 0, sizeof(stSockAddr)); + + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons( +#if EMSCRIPTEN + 3993 +#else + 3992 +#endif + ); + Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr); + + if (0 > Res) { + perror("error: first parameter is not a valid address family"); + close(SocketFD); + exit(EXIT_FAILURE); + } else if (0 == Res) { + perror("char string (second parameter does not contain valid ipaddress)"); + close(SocketFD); + exit(EXIT_FAILURE); + } + + if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) { + perror("connect failed"); + close(SocketFD); + exit(EXIT_FAILURE); + + } + +#if EMSCRIPTEN + emscripten_run_script("console.log('adding iframe');" + "var iframe = document.createElement('iframe');" + "iframe.src = 'side.html';" + "iframe.width = '100%';" + "iframe.width = '40%';" + "document.body.appendChild(iframe);" + "console.log('added.');"); + emscripten_set_main_loop(iter, 1, 0); +#else + while (!done) iter(NULL); +#endif + + return EXIT_SUCCESS; +} + diff --git a/tests/websockets_bi_side_bigdata.c b/tests/websockets_bi_side_bigdata.c new file mode 100644 index 00000000..9b67fe4c --- /dev/null +++ b/tests/websockets_bi_side_bigdata.c @@ -0,0 +1,69 @@ +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/ioctl.h> +#if EMSCRIPTEN +#include <emscripten.h> +#endif + +#include "websockets_bigdata.h" + +#define EXPECTED_BYTES 5 + +void stall(void *arg) { +} + +int main(void) +{ + struct sockaddr_in stSockAddr; + int Res; + int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (-1 == SocketFD) + { + perror("cannot create socket"); + exit(EXIT_FAILURE); + } + + memset(&stSockAddr, 0, sizeof(stSockAddr)); + + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons(SOCKK); + Res = inet_pton(AF_INET, "127.0.0.1", &stSockAddr.sin_addr); + + if (0 > Res) { + perror("error: first parameter is not a valid address family"); + close(Sock |