예제 #1
0
    def test_emcc_cache_flag(self):
        restore_and_set_up()

        cache_dir_name = self.in_dir('emscripten_cache')
        self.assertFalse(os.path.exists(cache_dir_name))
        create_test_file(
            'test.c', r'''
      #include <stdio.h>
      int main() {
        printf("hello, world!\n");
        return 0;
      }
      ''')
        run_process([PYTHON, EMCC, 'test.c', '--cache', cache_dir_name],
                    stderr=PIPE)
        # The cache directory must exist after the build
        self.assertTrue(os.path.exists(cache_dir_name))
        # The cache directory must contain a built libc'
        if self.is_wasm_backend():
            self.assertTrue(
                os.path.exists(os.path.join(cache_dir_name, 'wasm_o',
                                            'libc.a')))
        else:
            self.assertTrue(
                os.path.exists(os.path.join(cache_dir_name, 'asmjs',
                                            'libc.bc')))
예제 #2
0
    def test_emcc_multiprocess_cache_access(self):
        restore_and_set_up()

        create_test_file(
            'test.c', r'''
      #include <stdio.h>
      int main() {
        printf("hello, world!\n");
        return 0;
      }
      ''')
        cache_dir_name = self.in_dir('test_cache')
        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: libc' in p.stdout:
                    num_times_libc_was_built += 1

        # The cache directory must exist after the build
        self.assertTrue(os.path.exists(cache_dir_name))
        # The cache directory must contain a built libc
        self.assertTrue(
            os.path.exists(os.path.join(cache_dir_name, 'wasm', 'libc.a')))
        # Exactly one child process should have triggered libc build!
        self.assertEqual(num_times_libc_was_built, 1)
예제 #3
0
  def test_em_config_env_var(self):
    # emcc should be configurable directly from EM_CONFIG without any config file
    restore_and_set_up()
    create_test_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'))
예제 #4
0
    def test_sockets_echo_bigdata(self):
        sockets_include = '-I' + path_from_root('tests', '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 = path_from_root('tests', 'sockets',
                                        'test_sockets_echo_client.c')
        input = open(input_filename).read()
        create_test_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
                           ],
                           force_c=True)
예제 #5
0
  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 = path_from_root('tests', '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 = path_from_root('tests', '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_test_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_test_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=1', '--pre-js', 'host_pre.js', '-s', 'SOCKET_WEBRTC=1', '-s', 'SOCKET_DEBUG=1'])
    self.compile_btest(['-Werror', temp_peer_filepath, '-o', peer_outfile] + ['-s', 'GL_TESTING=1', '--pre-js', 'peer_pre.js', '-s', 'SOCKET_WEBRTC=1', '-s', 'SOCKET_DEBUG=1'])

    # 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', path_from_root('tests', 'sockets', 'p2p')])
    broker = Popen(config.NODE_JS + [path_from_root('tests', 'sockets', 'p2p', 'broker', 'p2p-broker.js')])

    expected = '1'
    self.run_browser(host_outfile, '.', ['/report_result?' + e for e in expected])

    broker.kill()