Example #1
0
    def test_zzz_coremark(self):
        src = open(test_file('third_party', 'coremark', 'core_main.c'),
                   'r').read()

        def lib_builder(name, native, env_init):
            return self.get_library('third_party/coremark',
                                    [os.path.join('coremark.a')],
                                    configure=None,
                                    native=native,
                                    cache_name_extra=name,
                                    env_init=env_init)

        def output_parser(output):
            iters_sec = re.search(r'Iterations/Sec   : ([\d\.]+)',
                                  output).group(1)
            return 100000.0 / float(iters_sec)

        self.do_benchmark(
            'coremark',
            src,
            'Correct operation validated.',
            shared_args=['-I' + test_file('third_party', 'coremark')],
            lib_builder=lib_builder,
            output_parser=output_parser,
            force_c=True)
Example #2
0
  def test_nodejs_sockets_echo(self):
    # This test checks that sockets work when the client code is run in Node.js
    if config.NODE_JS not in config.JS_ENGINES:
      self.skipTest('node is not present')

    sockets_include = '-I' + test_file('sockets')

    harnesses = [
      (CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=0'], 59162), 0),
      (CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=1'], 59164), 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], 59160), 0)]

    # Basic test of node client against both a Websockified and compiled echo server.
    for harness, datagram in harnesses:
      with harness:
        self.run_process([EMCC, '-Werror', test_file('sockets', 'test_sockets_echo_client.c'), '-o', 'client.js', '-DSOCKK=%d' % harness.listen_port, '-DTEST_DGRAM=%d' % datagram], stdout=PIPE, stderr=PIPE)

        out = self.run_js('client.js')
        self.assertContained('do_msg_read: read 14 bytes', out)

    if not WINDOWS: # TODO: Python pickling bug causes WebsockifyServerHarness to not work on Windows.
      # Test against a Websockified server with compile time configured WebSocket subprotocol. We use a Websockified
      # server because as long as the subprotocol list contains binary it will configure itself to accept binary
      # This test also checks that the connect url contains the correct subprotocols.
      print("\nTesting compile time WebSocket configuration.\n")
      for harness in [
        WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59166)
      ]:
        with harness:
          self.run_process([EMCC, '-Werror', test_file('sockets', 'test_sockets_echo_client.c'), '-o', 'client.js', '-s', 'SOCKET_DEBUG', '-s', 'WEBSOCKET_SUBPROTOCOL="base64, binary"', '-DSOCKK=59166'], stdout=PIPE, stderr=PIPE)

          out = self.run_js('client.js')
          self.assertContained('do_msg_read: read 14 bytes', out)
          self.assertContained(['connect: ws://127.0.0.1:59166, base64,binary', 'connect: ws://127.0.0.1:59166/, base64,binary'], out)

      # Test against a Websockified server with runtime WebSocket configuration. We specify both url and subprotocol.
      # In this test we have *deliberately* used the wrong port '-DSOCKK=12345' to configure the echo_client.c, so
      # the connection would fail without us specifying a valid WebSocket URL in the configuration.
      print("\nTesting runtime WebSocket configuration.\n")
      for harness in [
        WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59168)
      ]:
        with harness:
          open(os.path.join(self.get_dir(), 'websocket_pre.js'), 'w').write('''
          var Module = {
            websocket: {
              url: 'ws://localhost:59168/testA/testB',
              subprotocol: 'text, base64, binary',
            }
          };
          ''')

          self.run_process([EMCC, '-Werror', test_file('sockets', 'test_sockets_echo_client.c'), '-o', 'client.js', '--pre-js', 'websocket_pre.js', '-s', 'SOCKET_DEBUG', '-DSOCKK=12345'], stdout=PIPE, stderr=PIPE)

          out = self.run_js('client.js')
          self.assertContained('do_msg_read: read 14 bytes', out)
          self.assertContained('connect: ws://localhost:59168/testA/testB, text,base64,binary', out)
Example #3
0
  def test_sdl_audio_mix(self):
    shutil.copyfile(test_file('sounds', 'pluck.ogg'), os.path.join(self.get_dir(), 'sound.ogg'))
    shutil.copyfile(test_file('sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'music.ogg'))
    shutil.copyfile(test_file('sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'noise.ogg'))

    self.compile_btest(['-O2', '--minify=0', test_file('sdl_audio_mix.c'), '--preload-file', 'sound.ogg', '--preload-file', 'music.ogg', '--preload-file', 'noise.ogg', '-o', 'page.html'])
    self.run_browser('page.html', '', '/report_result?1')
Example #4
0
    def test_zzz_poppler(self):
        with open('pre.js', 'w') as f:
            f.write('''
        var benchmarkArgument = %s;
        var benchmarkArgumentToPageCount = {
          '0': 0,
          '1': 1,
          '2': 5,
          '3': 15,
          '4': 26,
          '5': 55,
        };
        if (benchmarkArgument === 0) {
          Module['arguments'] = ['-?'];
          Module['printErr'] = function(){};
        } else {
          // Add 'filename' after 'input.pdf' to write the output so it can be verified.
          Module['arguments'] = ['-scale-to', '1024', 'input.pdf',  '-f', '1', '-l', '' + benchmarkArgumentToPageCount[benchmarkArgument]];
          Module['postRun'] = function() {
            var files = [];
            for (var x in FS.root.contents) {
              if (x.startsWith('filename-')) {
                files.push(x);
              }
            }
            files.sort();
            var hash = 5381;
            var totalSize = 0;
            files.forEach(function(file) {
              var data = Array.from(MEMFS.getFileDataAsTypedArray(FS.root.contents[file]));
              for (var i = 0; i < data.length; i++) {
                hash = ((hash << 5) + hash) ^ (data[i] & 0xff);
              }
              totalSize += data.length;
            });
            out(files.length + ' files emitted, total output size: ' + totalSize + ', hashed printout: ' + hash);
          };
        }
      ''' % DEFAULT_ARG)

        def lib_builder(name, native, env_init):
            return self.get_poppler_library(env_init=env_init)

        # TODO: Fix poppler native build and remove skip_native=True
        self.do_benchmark(
            'poppler',
            '',
            'hashed printout',
            shared_args=[
                '-I' + test_file('poppler', 'include'),
                '-I' + test_file('freetype', 'include')
            ],
            emcc_args=[
                '-s', 'FILESYSTEM', '--pre-js', 'pre.js', '--embed-file',
                test_file('poppler', 'emscripten_html5.pdf') + '@input.pdf',
                '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0', '-s', 'MINIMAL_RUNTIME=0'
            ],  # not minimal because of files
            lib_builder=lib_builder,
            skip_native=True)
Example #5
0
  def test_sdl_audio(self):
    shutil.copyfile(test_file('sounds', 'alarmvictory_1.ogg'), os.path.join(self.get_dir(), 'sound.ogg'))
    shutil.copyfile(test_file('sounds', 'alarmcreatemiltaryfoot_1.wav'), os.path.join(self.get_dir(), 'sound2.wav'))
    shutil.copyfile(test_file('sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'noise.ogg'))
    shutil.copyfile(test_file('sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'the_entertainer.ogg'))
    open(os.path.join(self.get_dir(), 'bad.ogg'), 'w').write('I claim to be audio, but am lying')

    # use closure to check for a possible bug with closure minifying away newer Audio() attributes
    self.compile_btest(['-O2', '--closure=1', '--minify=0', test_file('sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--embed-file', 'the_entertainer.ogg', '--preload-file', 'noise.ogg', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]'])
    self.run_browser('page.html', '', '/report_result?1')
Example #6
0
 def test_html5_fullscreen(self):
     self.btest(
         test_file('test_html5_fullscreen.c'),
         expected='0',
         args=[
             '-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR', '-s',
             'EXPORTED_FUNCTIONS=["_requestFullscreen","_enterSoftFullscreen","_main"]',
             '--shell-file',
             test_file('test_html5_fullscreen.html')
         ])
Example #7
0
    def test_openal_playback(self):
        shutil.copyfile(test_file('sounds', 'audio.wav'),
                        os.path.join(self.get_dir(), 'audio.wav'))

        for args in [[], ['-s', 'USE_PTHREADS', '-s', 'PROXY_TO_PTHREAD']]:
            self.compile_btest([
                '-O2',
                test_file('openal_playback.cpp'), '--preload-file',
                'audio.wav', '-o', 'page.html'
            ] + args)
            self.run_browser('page.html', '', '/report_result?1')
Example #8
0
    def test_sdl_audio_panning(self):
        shutil.copyfile(test_file('sounds', 'the_entertainer.wav'),
                        os.path.join(self.get_dir(), 'the_entertainer.wav'))

        # use closure to check for a possible bug with closure minifying away newer Audio() attributes
        self.compile_btest([
            '-O2', '--closure=1', '--minify=0',
            test_file('sdl_audio_panning.c'), '--preload-file',
            'the_entertainer.wav', '-o', 'page.html', '-s',
            'EXPORTED_FUNCTIONS=["_main", "_play"]'
        ])
        self.run_browser('page.html', '', '/report_result?1')
Example #9
0
    def test_required_config_settings(self):
        # with no binaryen root, an error is shown
        restore_and_set_up()

        open(config_file, 'a').write('\nBINARYEN_ROOT = ""\n')
        self.check_working([EMCC, test_file('hello_world.c')],
                           'BINARYEN_ROOT is set to empty value in %s' %
                           config_file)

        open(config_file, 'a').write('\ndel BINARYEN_ROOT\n')
        self.check_working([EMCC, test_file('hello_world.c')],
                           'BINARYEN_ROOT is not defined in %s' % config_file)
Example #10
0
    def test_binaryen_version(self):
        restore_and_set_up()
        with open(config_file, 'a') as f:
            f.write('\nBINARYEN_ROOT = "' + self.in_dir('fake') + '"')

        make_fake_tool(self.in_dir('fake', 'bin', 'wasm-opt'), 'foo')
        self.check_working([
            EMCC, test_file('hello_world.c')
        ], 'error parsing binaryen version (wasm-opt version foo). Please check your binaryen installation'
                           )

        make_fake_tool(self.in_dir('fake', 'bin', 'wasm-opt'), '70')
        self.check_working([EMCC, test_file('hello_world.c')],
                           'unexpected binaryen version: 70 (expected ')
Example #11
0
    def test_zzz_sqlite(self):
        src = open(test_file(
            'third_party', 'sqlite', 'sqlite3.c'), 'r').read() + open(
                test_file('sqlite', 'speedtest1.c'), 'r').read()

        self.do_benchmark(
            'sqlite',
            src,
            'TOTAL...',
            native_args=['-ldl', '-pthread'],
            shared_args=['-I' + test_file('third_party', 'sqlite')],
            emcc_args=['-s', 'FILESYSTEM', '-s',
                       'MINIMAL_RUNTIME=0'],  # not minimal because of files
            force_c=True)
Example #12
0
    def test_foreign_functions(self):
        def output_parser(output):
            return float(re.search(r'Total time: ([\d\.]+)', output).group(1))

        self.do_benchmark(
            'foreign_functions',
            open(test_file('benchmark_ffis.cpp')).read(),
            'Total time:',
            output_parser=output_parser,
            emcc_args=['--js-library',
                       test_file('benchmark_ffis.js')],
            shared_args=[
                '-DBENCHMARK_FOREIGN_FUNCTION=1', '-DBUILD_FOR_SHELL',
                '-I' + TEST_ROOT
            ])
Example #13
0
 def test_life(self):
     src = open(test_file('life.c'), 'r').read()
     self.do_benchmark('life',
                       src,
                       '''--------------------------------''',
                       shared_args=['-std=c99'],
                       force_c=True)
Example #14
0
    def test_emcc_ports(self):
        restore_and_set_up()

        # listing ports
        out = self.do([EMCC, '--show-ports'])
        self.assertContained('Available ports:', out)
        self.assertContained('SDL2', out)
        self.assertContained('SDL2_image', out)
        self.assertContained('SDL2_net', out)

        # using ports
        RETRIEVING_MESSAGE = 'retrieving port'
        BUILDING_MESSAGE = 'generating port'

        PORTS_DIR = system_libs.Ports.get_dir()

        for i in [0, 1]:
            self.do([EMCC, '--clear-cache'])
            print(i)
            if i == 0:
                try_delete(PORTS_DIR)
            else:
                self.do([EMCC, '--clear-ports'])
            self.assertNotExists(PORTS_DIR)

            # Building a file that doesn't need ports should not trigger anything
            output = self.do([EMCC, test_file('hello_world_sdl.cpp')])
            self.assertNotContained(RETRIEVING_MESSAGE, output)
            self.assertNotContained(BUILDING_MESSAGE, output)
            self.assertNotExists(PORTS_DIR)

            def first_use():
                output = self.do([
                    EMCC,
                    test_file('hello_world_sdl.cpp'), '-s', 'USE_SDL=2'
                ])
                self.assertContained(RETRIEVING_MESSAGE, output)
                self.assertContained(BUILDING_MESSAGE, output)
                self.assertExists(PORTS_DIR)

            def second_use():
                # Using it again avoids retrieve and build
                output = self.do([
                    EMCC,
                    test_file('hello_world_sdl.cpp'), '-s', 'USE_SDL=2'
                ])
                self.assertNotContained(RETRIEVING_MESSAGE, output)
                self.assertNotContained(BUILDING_MESSAGE, output)

            # Building a file that need a port does trigger stuff
            first_use()
            second_use()

            # if the url doesn't match, we retrieve and rebuild
            with open(os.path.join(PORTS_DIR, 'sdl2', '.emscripten_url'),
                      'w') as f:
                f.write('foo')

            first_use()
            second_use()
Example #15
0
  def __enter__(self):
    # compile the server
    # NOTE empty filename support is a hack to support
    # the current test_enet
    if self.filename:
      proc = run_process([CLANG_CC, test_file(self.filename), '-o', 'server', '-DSOCKK=%d' % self.target_port] + clang_native.get_clang_native_args() + self.args, clang_native.get_clang_native_env(), stdout=PIPE, stderr=PIPE)
      print('Socket server build: out:', proc.stdout or '', '/ err:', proc.stderr or '')
      process = Popen([os.path.abspath('server')])
      self.processes.append(process)

    # start the websocket proxy
    print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr)
    wsp = websockify.WebSocketProxy(verbose=True, listen_port=self.listen_port, target_host="127.0.0.1", target_port=self.target_port, run_once=True)
    self.websockify = multiprocessing.Process(target=wsp.start_server)
    self.websockify.start()
    self.processes.append(self.websockify)
    # Make sure both the actual server and the websocket proxy are running
    for i in range(10):
      try:
        if self.do_server_check:
            server_sock = socket.create_connection(('localhost', self.target_port), timeout=1)
            server_sock.close()
        proxy_sock = socket.create_connection(('localhost', self.listen_port), timeout=1)
        proxy_sock.close()
        break
      except IOError:
        time.sleep(1)
    else:
      clean_processes(self.processes)
      raise Exception('[Websockify failed to start up in a timely manner]')

    print('[Websockify on process %s]' % str(self.processes[-2:]))
Example #16
0
    def test_zzz_lzma(self):
        src = open(test_file('benchmark', 'test_lzma_benchmark.c'), 'r').read()

        def lib_builder(name, native, env_init):
            return self.get_library(os.path.join('third_party', 'lzma'),
                                    [os.path.join('lzma.a')],
                                    configure=None,
                                    native=native,
                                    cache_name_extra=name,
                                    env_init=env_init)

        self.do_benchmark(
            'lzma',
            src,
            'ok.',
            shared_args=['-I' + test_file('third_party', 'lzma')],
            lib_builder=lib_builder)
Example #17
0
    def test_zzz_box2d(self):
        src = open(test_file('benchmark', 'test_box2d_benchmark.cpp')).read()

        def lib_builder(name, native, env_init):
            return self.get_library(os.path.join('third_party', 'box2d'),
                                    ['box2d.a'],
                                    configure=None,
                                    native=native,
                                    cache_name_extra=name,
                                    env_init=env_init)

        self.do_benchmark(
            'box2d',
            src,
            'frame averages',
            shared_args=['-I' + test_file('third_party', 'box2d')],
            lib_builder=lib_builder)
Example #18
0
 def test_sdl_audio_beeps(self):
     # use closure to check for a possible bug with closure minifying away newer Audio() attributes
     self.compile_btest([
         test_file('sdl_audio_beep.cpp'), '-O2', '--closure=1',
         '--minify=0', '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-o',
         'page.html'
     ])
     self.run_browser('page.html', '', '/report_result?1')
Example #19
0
 def test_websocket_send(self):
     with NodeJsWebSocketEchoServerProcess():
         self.btest(test_file('websocket', 'test_websocket_send.c'),
                    expected='101',
                    args=[
                        '-lwebsocket', '-s', 'NO_EXIT_RUNTIME', '-s',
                        'WEBSOCKET_DEBUG'
                    ])
Example #20
0
 def second_use():
     # Using it again avoids retrieve and build
     output = self.do([
         EMCC,
         test_file('hello_world_sdl.cpp'), '-s', 'USE_SDL=2'
     ])
     self.assertNotContained(RETRIEVING_MESSAGE, output)
     self.assertNotContained(BUILDING_MESSAGE, output)
Example #21
0
 def test_threadprofiler(self):
   args = ['-O2', '--threadprofiler',
           '-s', 'USE_PTHREADS',
           '-DTEST_THREAD_PROFILING=1',
           '-s', 'PTHREAD_POOL_SIZE=16',
           '-s', 'INITIAL_MEMORY=64mb',
           '--shell-file', test_file('pthread', 'test_pthread_mandelbrot_shell.html')]
   self.btest('pthread/test_pthread_mandelbrot.cpp', expected='0', args=args)
Example #22
0
 def first_use():
     output = self.do([
         EMCC,
         test_file('hello_world_sdl.cpp'), '-s', 'USE_SDL=2'
     ])
     self.assertContained(RETRIEVING_MESSAGE, output)
     self.assertContained(BUILDING_MESSAGE, output)
     self.assertExists(PORTS_DIR)
Example #23
0
 def test_openal_buffers(self):
     self.btest(
         'openal_buffers.c',
         '0',
         args=[
             '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/'
         ],
     )
Example #24
0
 def test_openal_looped_pitched_playback(self):
     self.btest(
         'openal_playback.cpp',
         '1',
         args=[
             '-DTEST_LOOPED_PLAYBACK=1', '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/audio.wav'
         ],
     )
Example #25
0
    def test_native_functions(self):
        def output_parser(output):
            return float(re.search(r'Total time: ([\d\.]+)', output).group(1))

        self.do_benchmark('native_functions',
                          open(test_file('benchmark_ffis.cpp')).read(),
                          'Total time:',
                          output_parser=output_parser,
                          shared_args=['-DBUILD_FOR_SHELL', '-I' + TEST_ROOT])
Example #26
0
 def test_sdl2_mixer_wav(self):
     shutil.copyfile(test_file('sounds', 'the_entertainer.wav'),
                     os.path.join(self.get_dir(), 'sound.wav'))
     self.btest('sdl2_mixer_wav.c',
                expected='1',
                args=[
                    '-O2', '-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2', '-s',
                    'INITIAL_MEMORY=33554432', '--preload-file', 'sound.wav'
                ])
Example #27
0
 def test_openal_buffers_animated_pitch(self):
     self.btest(
         'openal_buffers.c',
         '0',
         args=[
             '-DTEST_ANIMATED_PITCH=1', '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/'
         ],
     )
Example #28
0
  def test_sockets_select_server_closes_connection_rw(self):
    sockets_include = '-I' + test_file('sockets')

    for harness in [
      WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DCLOSE_CLIENT_AFTER_ECHO'], 49200),
      CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DCLOSE_CLIENT_AFTER_ECHO'], 49201)
    ]:
      with harness:
        self.btest(os.path.join('sockets', 'test_sockets_select_server_closes_connection_client_rw.c'), expected='266', args=[sockets_include, '-DSOCKK=%d' % harness.listen_port])
Example #29
0
    def test_zzz_zlib(self):
        self.emcc_args.remove('-Werror')
        src = open(test_file('benchmark', 'test_zlib_benchmark.c'), 'r').read()

        def lib_builder(name, native, env_init):
            return self.get_library(os.path.join('third_party', 'zlib'),
                                    os.path.join('libz.a'),
                                    make_args=['libz.a'],
                                    native=native,
                                    cache_name_extra=name,
                                    env_init=env_init)

        self.do_benchmark(
            'zlib',
            src,
            'ok.',
            force_c=True,
            shared_args=['-I' + test_file('third_party', 'zlib')],
            lib_builder=lib_builder)
Example #30
0
    def test_zzz_bullet(self):
        self.emcc_args.remove('-Werror')
        self.emcc_args += [
            '-Wno-c++11-narrowing', '-Wno-deprecated-register',
            '-Wno-writable-strings'
        ]
        src = open(
            test_file('third_party', 'bullet', 'Demos', 'Benchmarks',
                      'BenchmarkDemo.cpp'), 'r').read()
        src += open(
            test_file('third_party', 'bullet', 'Demos', 'Benchmarks',
                      'main.cpp'), 'r').read()

        def lib_builder(name, native, env_init):
            return self.get_library(
                os.path.join('third_party', 'bullet'),
                [
                    os.path.join('src', '.libs', 'libBulletDynamics.a'),
                    os.path.join('src', '.libs', 'libBulletCollision.a'),
                    os.path.join('src', '.libs', 'libLinearMath.a')
                ],
                # The --host parameter is needed for 2 reasons:
                # 1) bullet in it's configure.ac tries to do platform detection and will fail on unknown platforms
                # 2) configure will try to compile and run a test file to check if the C compiler is sane. As Cheerp
                #    will generate a wasm file (which cannot be run), configure will fail. Passing `--host` enables
                #    cross compile mode, which lets configure complete happily.
                configure_args=[
                    '--disable-demos', '--disable-dependency-tracking',
                    '--host=i686-unknown-linux'
                ],
                native=native,
                cache_name_extra=name,
                env_init=env_init)

        self.do_benchmark(
            'bullet',
            src,
            '\nok.\n',
            shared_args=[
                '-I' + test_file('third_party', 'bullet', 'src'), '-I' +
                test_file('third_party', 'bullet', 'Demos', 'Benchmarks')
            ],
            lib_builder=lib_builder)