def test_emcc_multiprocess_cache_access(self): restore_and_set_up() create_file( 'test.c', r''' #include <stdio.h> int main() { printf("hello, world!\n"); return 0; } ''') cache_dir_name = self.in_dir('test_cache') libname = Cache.get_lib_name('libc.a') with env_modify({'EM_CACHE': cache_dir_name}): tasks = [] num_times_libc_was_built = 0 for i in range(3): p = self.run_process( [EMCC, 'test.c', '-o', '%d.js' % i], stderr=STDOUT, stdout=PIPE) tasks += [p] for p in tasks: print('stdout:\n', p.stdout) if 'generating system library: ' + libname in p.stdout: num_times_libc_was_built += 1 # The cache directory must exist after the build self.assertExists(cache_dir_name) # The cache directory must contain a built libc self.assertExists(os.path.join(cache_dir_name, libname)) # Exactly one child process should have triggered libc build! self.assertEqual(num_times_libc_was_built, 1)
def test_emcc_cache_flag(self, use_response_files, relative): restore_and_set_up() if relative: cache_dir_name = 'emscripten_cache' else: cache_dir_name = self.in_dir('emscripten_cache') self.assertFalse(os.path.exists(cache_dir_name)) create_file( 'test.c', r''' #include <stdio.h> int main() { printf("hello, world!\n"); return 0; } ''') args = ['--cache', cache_dir_name] if use_response_files: rsp = response_file.create_response_file(args, shared.TEMP_DIR) args = ['@' + rsp] self.run_process([EMCC, 'test.c'] + args, stderr=PIPE) if use_response_files: os.remove(rsp) # The cache directory must exist after the build self.assertTrue(os.path.exists(cache_dir_name)) # The cache directory must contain a sysroot self.assertTrue(os.path.exists(os.path.join(cache_dir_name, 'sysroot')))
def test_em_config_env_var(self): # emcc should be configurable directly from EM_CONFIG without any config file restore_and_set_up() create_file( 'main.cpp', ''' #include <stdio.h> int main() { printf("hello from emcc with no config file\\n"); return 0; } ''') wipe() with env_modify({'EM_CONFIG': get_basic_config()}): self.run_process( [EMCC, 'main.cpp', '-Wno-deprecated', '-o', 'a.out.js']) self.assertContained('hello from emcc with no config file', self.run_js('a.out.js'))
def test_em_config_env_var(self): # emcc should be configurable directly from EM_CONFIG without any config file restore_and_set_up() create_file( 'main.cpp', ''' #include <stdio.h> int main() { printf("hello from emcc with no config file\\n"); return 0; } ''') wipe() with env_modify({'EM_CONFIG': get_basic_config()}): out = self.expect_fail( [EMCC, 'main.cpp', '-Wno-deprecated', '-o', 'a.out.js']) self.assertContained( 'error: Inline EM_CONFIG data no longer supported. Please use a config file.', out)
def test_sockets_echo_bigdata(self): sockets_include = '-I' + test_file('sockets') # generate a large string literal to use as our message message = '' for i in range(256 * 256 * 2): message += str(chr(ord('a') + (i % 26))) # re-write the client test with this literal (it's too big to pass via command line) input_filename = test_file('sockets', 'test_sockets_echo_client.c') input = open(input_filename).read() create_file( 'test_sockets_echo_bigdata.c', input.replace('#define MESSAGE "pingtothepong"', '#define MESSAGE "%s"' % message)) harnesses = [(CompiledServerHarness( os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=0'], 49172), 0), (CompiledServerHarness( os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=1'], 49173), 1)] if not WINDOWS: # TODO: Python pickling bug causes WebsockifyServerHarness to not work on Windows. harnesses += [(WebsockifyServerHarness( os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 49171), 0)] for harness, datagram in harnesses: with harness: self.btest('test_sockets_echo_bigdata.c', expected='0', args=[ sockets_include, '-DSOCKK=%d' % harness.listen_port, '-DTEST_DGRAM=%d' % datagram ])
def test_webrtc( self ): # XXX see src/settings.js, this is disabled pending investigation self.skipTest('WebRTC support is not up to date.') host_src = 'webrtc_host.c' peer_src = 'webrtc_peer.c' host_outfile = 'host.html' peer_outfile = 'peer.html' host_filepath = test_file('sockets', host_src) temp_host_filepath = os.path.join(self.get_dir(), os.path.basename(host_src)) with open(host_filepath) as f: host_src = f.read() with open(temp_host_filepath, 'w') as f: f.write(host_src) peer_filepath = test_file('sockets', peer_src) temp_peer_filepath = os.path.join(self.get_dir(), os.path.basename(peer_src)) with open(peer_filepath) as f: peer_src = f.read() with open(temp_peer_filepath, 'w') as f: f.write(peer_src) create_file( 'host_pre.js', ''' var Module = { webrtc: { broker: 'http://localhost:8182', session: undefined, onpeer: function(peer, route) { window.open('http://localhost:8888/peer.html?' + route); // iframe = document.createElement("IFRAME"); // iframe.setAttribute("src", "http://localhost:8888/peer.html?" + route); // iframe.style.display = "none"; // document.body.appendChild(iframe); peer.listen(); }, onconnect: function(peer) { }, ondisconnect: function(peer) { }, onerror: function(error) { console.error(error); } }, setStatus: function(text) { console.log('status: ' + text); } }; ''') create_file( 'peer_pre.js', ''' var Module = { webrtc: { broker: 'http://localhost:8182', session: window.location.toString().split('?')[1], onpeer: function(peer, route) { peer.connect(Module['webrtc']['session']); }, onconnect: function(peer) { }, ondisconnect: function(peer) { // Calling window.close() from this handler hangs my browser, so run it in the next turn setTimeout(window.close, 0); }, onerror: function(error) { console.error(error); }, }, setStatus: function(text) { console.log('status: ' + text); } }; ''') self.compile_btest( ['-Werror', temp_host_filepath, '-o', host_outfile] + [ '-s', 'GL_TESTING', '--pre-js', 'host_pre.js', '-s', 'SOCKET_WEBRTC', '-s', 'SOCKET_DEBUG' ]) self.compile_btest( ['-Werror', temp_peer_filepath, '-o', peer_outfile] + [ '-s', 'GL_TESTING', '--pre-js', 'peer_pre.js', '-s', 'SOCKET_WEBRTC', '-s', 'SOCKET_DEBUG' ]) # note: you may need to run this manually yourself, if npm is not in the path, or if you need a version that is not in the path self.run_process([NPM, 'install', test_file('sockets', 'p2p')]) broker = Popen( config.NODE_JS + [test_file('sockets', 'p2p', 'broker', 'p2p-broker.js')]) expected = '1' self.run_browser(host_outfile, '.', ['/report_result?' + e for e in expected]) broker.kill()