示例#1
0
    def test_binaryen_version(self):
        restore_and_set_up()
        with open(EM_CONFIG, '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 ')
示例#2
0
    def test_sdl_audio_mix(self, args):
        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'
        ] + args)
        self.run_browser('page.html', '', '/report_result?1')
示例#3
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',
            read_file(test_file('benchmark_ffis.cpp')),
            '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
            ])
示例#4
0
 def test_sockets_select_server_down(self):
     for harness in [
             WebsockifyServerHarness(test_file(
                 'sockets/test_sockets_select_server_down_server.c'), [],
                                     49190,
                                     do_server_check=False),
             CompiledServerHarness(
                 test_file(
                     'sockets/test_sockets_select_server_down_server.c'),
                 [], 49191)
     ]:
         with harness:
             self.btest_exit(test_file(
                 'sockets/test_sockets_select_server_down_client.c'),
                             args=['-DSOCKK=%d' % harness.listen_port])
示例#5
0
 def test_life(self):
     src = read_file(test_file('life.c'))
     self.do_benchmark('life',
                       src,
                       '''--------------------------------''',
                       shared_args=['-std=c99'],
                       force_c=True)
示例#6
0
  def test_js_engine_path(self):
    # Test that running JS commands works for node, d8, and jsc and is not path dependent
    restore_and_set_up()

    sample_script = test_file('print_args.js')

    # Fake some JS engines
    # Note that the path contains 'd8'.
    test_path = self.in_dir('fake', 'abcd8765')
    ensure_dir(test_path)

    jsengines = [('d8',     config.V8_ENGINE),
                 ('d8_g',   config.V8_ENGINE),
                 ('js',     config.SPIDERMONKEY_ENGINE),
                 ('node',   config.NODE_JS),
                 ('nodejs', config.NODE_JS)]
    for filename, engine in jsengines:
      try_delete(SANITY_FILE)
      if type(engine) is list:
        engine = engine[0]
      if not engine:
        print('WARNING: Not testing engine %s, not configured.' % (filename))
        continue

      print(filename, engine)

      test_engine_path = os.path.join(test_path, filename)
      with open(test_engine_path, 'w') as f:
        f.write('#!/bin/sh\n')
        f.write('exec %s $@\n' % (engine))
      make_executable(test_engine_path)

      out = self.run_js(sample_script, engine=test_engine_path, args=['--foo'])

      self.assertEqual('0: --foo', out.strip())
    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()
示例#8
0
    def test_sdl_audio_mix_channels(self, args):
        shutil.copyfile(test_file('sounds', 'noise.ogg'),
                        self.in_dir('sound.ogg'))

        self.btest_exit(
            'sdl_audio_mix_channels.c',
            args=['-O2', '--minify=0', '--preload-file', 'sound.ogg'] + args)
示例#9
0
    def test_zzz_lzma(self):
        src = read_file(test_file('benchmark/test_lzma_benchmark.c'))

        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)
示例#10
0
    def test_zzz_box2d(self):
        src = read_file(test_file('benchmark/test_box2d_benchmark.cpp'))

        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)
示例#11
0
 def test_sdl2_audio_beeps(self):
     # use closure to check for a possible bug with closure minifying away newer Audio() attributes
     self.btest_exit(test_file('sdl2_audio_beep.cpp'),
                     args=[
                         '-O2', '--closure=1', '--minify=0',
                         '-sDISABLE_EXCEPTION_CATCHING=0', '-sUSE_SDL=2'
                     ])
示例#12
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', '-sDISABLE_EXCEPTION_CATCHING=0', '-o', 'page.html'
     ])
     self.run_browser('page.html', '', '/report_result?1')
示例#13
0
 def second_use():
     # Using it again avoids retrieve and build
     output = self.do(
         [EMCC,
          test_file('hello_world_sdl.cpp'), '-sUSE_SDL=2'])
     self.assertNotContained(RETRIEVING_MESSAGE, output)
     self.assertNotContained(BUILDING_MESSAGE, output)
示例#14
0
 def first_use():
     output = self.do(
         [EMCC,
          test_file('hello_world_sdl.cpp'), '-sUSE_SDL=2'])
     self.assertContained(RETRIEVING_MESSAGE, output)
     self.assertContained(BUILDING_MESSAGE, output)
     self.assertExists(PORTS_DIR)
示例#15
0
    def test_nodejs_sockets_echo_subprotocol(self):
        # 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.
        with WebsockifyServerHarness(
                test_file('sockets/test_sockets_echo_server.c'), [], 59166):
            self.run_process([
                EMCC, '-Werror',
                test_file('sockets/test_sockets_echo_client.c'), '-o',
                'client.js', '-sSOCKET_DEBUG',
                '-sWEBSOCKET_SUBPROTOCOL="base64, binary"', '-DSOCKK=59166'
            ])

            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")
        create_file(
            'websocket_pre.js', '''
      var Module = {
        websocket: {
          url: 'ws://localhost:59168/testA/testB',
          subprotocol: 'text, base64, binary',
        }
      };
    ''')
        with WebsockifyServerHarness(
                test_file('sockets/test_sockets_echo_server.c'), [], 59168):
            self.run_process([
                EMCC, '-Werror',
                test_file('sockets/test_sockets_echo_client.c'), '-o',
                'client.js', '--pre-js=websocket_pre.js', '-sSOCKET_DEBUG',
                '-DSOCKK=12345'
            ])

            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)
示例#16
0
 def test_threadprofiler(self):
     args = [
         '-O2', '--threadprofiler', '-sUSE_PTHREADS', '-sASSERTIONS',
         '-DTEST_THREAD_PROFILING=1', '-sPTHREAD_POOL_SIZE=16',
         '-sINITIAL_MEMORY=64mb', '--shell-file',
         test_file('pthread', 'test_pthread_mandelbrot_shell.html')
     ]
     self.btest_exit('pthread/test_pthread_mandelbrot.cpp', args=args)
示例#17
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'
                    ])
示例#18
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'
         ],
     )
示例#19
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') + '@/'
         ],
     )
示例#20
0
 def test_openal_buffers(self):
     self.btest(
         'openal_buffers.c',
         '0',
         args=[
             '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/'
         ],
     )
示例#21
0
    def test_zzz_zlib(self):
        self.emcc_args.remove('-Werror')
        src = read_file(test_file('benchmark/test_zlib_benchmark.c'))

        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)
示例#22
0
 def test_sdl2_mixer_wav(self):
     shutil.copyfile(test_file('sounds', 'the_entertainer.wav'),
                     'sound.wav')
     self.btest_exit('sdl2_mixer_wav.c',
                     args=[
                         '-O2', '-sUSE_SDL=2', '-sUSE_SDL_MIXER=2',
                         '-sINITIAL_MEMORY=33554432', '--preload-file',
                         'sound.wav'
                     ])
示例#23
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'
                ])
示例#24
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',
                          read_file(test_file('benchmark_ffis.cpp')),
                          'Total time:',
                          output_parser=output_parser,
                          shared_args=['-DBUILD_FOR_SHELL', '-I' + TEST_ROOT])
示例#25
0
    def test_enet(self):
        # this is also a good test of raw usage of emconfigure and emmake
        shared.try_delete('enet')
        shutil.copytree(test_file('third_party', 'enet'), 'enet')
        with utils.chdir('enet'):
            self.run_process([
                path_from_root('emconfigure'), './configure',
                '--disable-shared'
            ])
            self.run_process([path_from_root('emmake'), 'make'])
            enet = [
                self.in_dir('enet', '.libs', 'libenet.a'),
                '-I' + self.in_dir('enet', 'include')
            ]

        with CompiledServerHarness(test_file('sockets/test_enet_server.c'),
                                   enet, 49210) as harness:
            self.btest_exit(test_file('sockets/test_enet_client.c'),
                            args=enet + ['-DSOCKK=%d' % harness.listen_port])
示例#26
0
 def test_openal_al_soft_source_spatialize(self):
     self.btest(
         'openal_playback.cpp',
         '1',
         args=[
             '-DTEST_AL_SOFT_SOURCE_SPATIALIZE=1',
             '-DTEST_LOOPED_PLAYBACK=1', '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/audio.wav'
         ],
     )
示例#27
0
 def test_openal_alc_soft_pause_device(self):
     self.btest(
         'openal_playback.cpp',
         '1',
         args=[
             '-DTEST_ALC_SOFT_PAUSE_DEVICE=1', '-DTEST_LOOPED_PLAYBACK=1',
             '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/audio.wav'
         ],
     )
示例#28
0
 def test_openal_al_soft_loop_points(self):
     self.btest(
         'openal_playback.cpp',
         '1',
         args=[
             '-DTEST_AL_SOFT_LOOP_POINTS=1', '-DTEST_LOOPED_PLAYBACK=1',
             '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/audio.wav'
         ],
     )
示例#29
0
 def test_openal_animated_looped_relative_playback(self):
     self.btest(
         'openal_playback.cpp',
         '1',
         args=[
             '-DTEST_ANIMATED_LOOPED_RELATIVE_PLAYBACK=1',
             '-DTEST_LOOPED_PLAYBACK=1', '--preload-file',
             test_file('sounds', 'the_entertainer.wav') + '@/audio.wav'
         ],
     )
示例#30
0
    def test_matrix_multiply(self):
        def output_parser(output):
            return float(
                re.search(r'Total elapsed: ([\d\.]+)', output).group(1))

        self.do_benchmark('matrix_multiply',
                          read_file(test_file('matrix_multiply.cpp')),
                          'Total elapsed:',
                          output_parser=output_parser,
                          shared_args=['-I' + TEST_ROOT])