diff options
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 223 |
1 files changed, 193 insertions, 30 deletions
diff --git a/tests/runner.py b/tests/runner.py index 89305592..7188fd13 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -5080,10 +5080,54 @@ def process(filename): int main() { printf("*%x,%x,%x,%x,%x,%x*\n", htonl(0xa1b2c3d4), htonl(0xfe3572e0), htonl(0x07abcdf0), htons(0xabcd), ntohl(0x43211234), ntohs(0xbeaf)); + in_addr_t i = inet_addr("190.180.10.78"); + printf("%x\n", i); return 0; } ''' - self.do_run(src, '*d4c3b2a1,e07235fe,f0cdab07,cdab,34122143,afbe*') + self.do_run(src, '*d4c3b2a1,e07235fe,f0cdab07,cdab,34122143,afbe*\n4e0ab4be\n') + + def test_gethostbyname(self): + src = r''' + #include <netdb.h> + #include <stdio.h> + + void test(char *hostname) { + hostent *host = gethostbyname(hostname); + if (!host) { + printf("no such thing\n"); + return; + } + printf("%s : %d : %d\n", host->h_name, host->h_addrtype, host->h_length); + char **name = host->h_aliases; + while (*name) { + printf("- %s\n", *name); + name++; + } + name = host->h_addr_list; + while (name && *name) { + printf("* "); + for (int i = 0; i < host->h_length; i++) + printf("%d.", (*name)[i]); + printf("\n"); + name++; + } + } + + int main() { + test("www.cheezburger.com"); + test("fail.on.this.never.work"); // we will "work" on this - because we are just making aliases of names to ips + test("localhost"); + return 1; + } + ''' + self.do_run(src, '''www.cheezburger.com : 1 : 4 +* -84.29.1.0. +fail.on.this.never.work : 1 : 4 +* -84.29.2.0. +localhost : 1 : 4 +* -84.29.3.0. +''') def test_ctype(self): # The bit fiddling done by the macros using __ctype_b_loc requires this. @@ -7142,6 +7186,14 @@ f.close() # TODO: test normal project linking, static and dynamic: get_library should not need to be told what to link! # TODO: deprecate llvm optimizations, dlmalloc, etc. in emscripten.py. + def test_Os(self): + for opt in ['s', '0']: + output = Popen(['python', EMCC, path_from_root('tests', 'hello_world.c'), '-O' + opt], stdout=PIPE, stderr=PIPE).communicate() + assert len(output[0]) == 0, output[0] + assert ('emcc: warning: -Os is ignored (use -O0, -O1, -O2)' in output[1]) == (opt == 's'), 'warn on -Os when necessary' + assert os.path.exists('a.out.js'), '\n'.join(output) + self.assertContained('hello, world!', run_js('a.out.js')) + def test_catch_undef(self): open(os.path.join(self.get_dir(), 'test.cpp'), 'w').write(r''' #include <vector> @@ -7372,6 +7424,38 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'somefile.txt', '--embed-file', 'somefile.txt']).communicate() self.assertContained('|hello from a file wi|', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_embed_file_dup(self): + try_delete(os.path.join(self.get_dir(), 'tst')) + os.mkdir(os.path.join(self.get_dir(), 'tst')) + os.mkdir(os.path.join(self.get_dir(), 'tst', 'test1')) + os.mkdir(os.path.join(self.get_dir(), 'tst', 'test2')) + + open(os.path.join(self.get_dir(), 'tst', 'aa.txt'), 'w').write('''frist''') + open(os.path.join(self.get_dir(), 'tst', 'test1', 'aa.txt'), 'w').write('''sacond''') + open(os.path.join(self.get_dir(), 'tst', 'test2', 'aa.txt'), 'w').write('''thard''') + open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(r''' + #include <stdio.h> + #include <string.h> + void print_file(const char *name) { + FILE *f = fopen(name, "r"); + char buf[100]; + memset(buf, 0, 100); + fread(buf, 1, 20, f); + buf[20] = 0; + fclose(f); + printf("|%s|\n", buf); + } + int main() { + print_file("tst/aa.txt"); + print_file("tst/test1/aa.txt"); + print_file("tst/test2/aa.txt"); + return 0; + } + ''') + + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--embed-file', 'tst']).communicate() + self.assertContained('|frist|\n|sacond|\n|thard|\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_multidynamic_link(self): # Linking the same dynamic library in will error, normally, since we statically link it, causing dupe symbols # A workaround is to use --ignore-dynamic-linking, see emcc --help for details @@ -8266,6 +8350,11 @@ elif 'browser' in str(sys.argv): shutil.move(os.path.join(self.get_dir(), basename), basename + '.renamedsoitcannotbefound'); self.run_browser('page.html', '', '/report_result?' + str(width)) + def test_sdl_image_prepare(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.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())) @@ -8658,51 +8747,125 @@ elif 'browser' in str(sys.argv): ''') self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js']) - class WebsockHarness: - def __enter__(self): - self.pids = [] + pids_to_clean = [] + def clean_pids(self): + return + import signal + for pid in browser.pids_to_clean: + print '[killing %d]' % pid + try: + os.kill(pid, signal.SIGKILL) # With this commented, we leave no children, but we hang the test harness on exit XXX + print '[kill succeeded]' + except: + print '[kill fail]' + browser.pids_to_clean = [] - def server_func(q): - proc = Popen([path_from_root('tests', 'socket_server.sh')]) - q.put(proc.pid) - proc.communicate() + # Runs a websocket server at a specific port. port is the true tcp socket we forward to, port+1 is the websocket one + class WebsockHarness: + def __init__(self, port, server_func=None, no_server=False): + self.port = port + self.server_func = server_func + self.no_server = no_server - server_queue = multiprocessing.Queue() - self.server = multiprocessing.Process(target=server_func, args=(server_queue,)) - self.server.start() - self.pids.append(self.server.pid) - while True: - if not server_queue.empty(): - self.pids.append(server_queue.get()) - break - time.sleep(0.1) - print '[Socket server on processes %s]' % str(self.pids[-2:]) + def __enter__(self): + if not self.no_server: + def server_func(q): + proc = Popen([path_from_root('tests', 'socket_server.sh'), str(self.port)]) + q.put(proc.pid) + proc.communicate() + + server_func = self.server_func or server_func + + server_queue = multiprocessing.Queue() + self.server = multiprocessing.Process(target=server_func, args=(server_queue,)) + self.server.start() + browser.pids_to_clean.append(self.server.pid) + while True: + if not server_queue.empty(): + browser.pids_to_clean.append(server_queue.get()) + break + time.sleep(0.1) + print '[Socket server on processes %s]' % str(browser.pids_to_clean[-2:]) def websockify_func(q): - proc = Popen([path_from_root('third_party', 'websockify', 'other', 'websockify'), '-vvv', '8991', '127.0.0.1:8990']) + 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)]) q.put(proc.pid) proc.communicate() websockify_queue = multiprocessing.Queue() self.websockify = multiprocessing.Process(target=websockify_func, args=(websockify_queue,)) self.websockify.start() - self.pids.append(self.websockify.pid) + browser.pids_to_clean.append(self.websockify.pid) while True: if not websockify_queue.empty(): - self.pids.append(websockify_queue.get()) + browser.pids_to_clean.append(websockify_queue.get()) break time.sleep(0.1) - print '[Websockify on processes %s]' % str(self.pids[-2:]) + print '[Websockify on processes %s]' % str(browser.pids_to_clean[-2:]) def __exit__(self, *args, **kwargs): - import signal - for pid in self.pids: - #os.kill(pid, signal.SIGTERM) # With this commented, we leave no children, but we hang the test harness on exit XXX - print '[%d should be cleaned up automatically]' % pid - - def test_zz_websockets(self): # always run this test last - with self.WebsockHarness(): - self.btest('websockets.c', expected='571') + time.sleep(1) + + # always run these tests last + # make sure to use different ports in each one because it takes a while for the processes to be cleaned up + def test_zz_websockets(self): + try: + with self.WebsockHarness(8990): + self.btest('websockets.c', expected='571') + finally: + self.clean_pids() + + def make_relay_server(self, port1, port2): + def relay_server(q): + print >> sys.stderr, 'creating relay server on ports %d,%d' % (port1, port2) + proc = Popen(['python', path_from_root('tests', 'socket_relay.py'), str(port1), str(port2)]) + q.put(proc.pid) + proc.communicate() + return relay_server + + def test_zz_websockets_bi(self): + try: + with self.WebsockHarness(8992, self.make_relay_server(8992, 8994)): + with self.WebsockHarness(8994, no_server=True): + Popen(['python', EMCC, path_from_root('tests', 'websockets_bi_side.c'), '-o', 'side.html', '-DSOCKK=8995']).communicate() + self.btest('websockets_bi.c', expected='2499') + finally: + self.clean_pids() + + def test_zz_websockets_bi_listen(self): + try: + with self.WebsockHarness(6992, self.make_relay_server(6992, 6994)): + with self.WebsockHarness(6994, no_server=True): + Popen(['python', EMCC, path_from_root('tests', 'websockets_bi_side.c'), '-o', 'side.html', '-DSOCKK=6995']).communicate() + self.btest('websockets_bi_listener.c', expected='2499') + finally: + self.clean_pids() + + def test_zz_websockets_gethostbyname(self): + try: + with self.WebsockHarness(7000): + self.btest('websockets_gethostbyname.c', expected='571', args=['-O2']) + 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')) + pwd = os.getcwd() + os.chdir(self.in_dir('enet')) + Popen(['python', path_from_root('emconfigure'), './configure']).communicate() + Popen(['python', path_from_root('emmake'), 'make']).communicate() + enet = [self.in_dir('enet', '.libs', 'libenet.a'), '-I'+path_from_root('tests', 'enet', 'include')] + os.chdir(pwd) + Popen(['python', EMCC, path_from_root('tests', 'enet_server.c'), '-o', 'server.html', '-s', 'SOCKET_DEBUG=1'] + enet).communicate() + + try: + with self.WebsockHarness(1234, self.make_relay_server(1234, 1236)): + with self.WebsockHarness(1236, no_server=True): + self.btest('enet_client.c', expected='cheez', args=enet+['-s', 'SOCKET_DEBUG=1']) + finally: + self.clean_pids() elif 'benchmark' in str(sys.argv): # Benchmarks. Run them with argument |benchmark|. To run a specific test, do |