diff options
-rwxr-xr-x | emcc | 12 | ||||
-rw-r--r-- | src/postamble.js | 8 | ||||
-rwxr-xr-x | tests/fuzz/csmith_driver.py | 2 | ||||
-rw-r--r-- | tests/mem_init.cpp | 24 | ||||
-rwxr-xr-x | tests/runner.py | 5 | ||||
-rw-r--r-- | tests/sdl_wm_togglefullscreen.c | 73 | ||||
-rw-r--r-- | tests/test_browser.py | 102 | ||||
-rw-r--r-- | tests/test_interactive.py | 91 |
8 files changed, 222 insertions, 95 deletions
@@ -470,7 +470,16 @@ Options that are modified or new in %s include: 1: Emit a separate memory initialization file in binary format. This is more efficient than storing it as text inside JavaScript, but does - mean you have another file to publish. + mean you have another file to publish. The + binary file will also be loaded asynchronously, + which means main() will not be called until + the file is downloaded and applied; you cannot + call any C functions until it arrives. (Call + yourself from main() to know when all async + stuff has happened and it is safe to call + library functions, as main() will only be + called at that time. You can also call + addOnPreMain from a preRun.) -Wno-warn-absolute-paths If not specified, the compiler will warn about any uses of absolute paths in -I and -L command line @@ -1369,6 +1378,7 @@ try: if file_ending.endswith(SOURCE_ENDINGS): temp_file = temp_files[i] logging.debug('optimizing %s', input_file) + #if DEBUG: shutil.copyfile(temp_file, os.path.join(TEMP_DIR, 'to_opt.bc') # useful when LLVM opt aborts shared.Building.llvm_opt(temp_file, llvm_opts) # If we were just asked to generate bitcode, stop there diff --git a/src/postamble.js b/src/postamble.js index 603b330c..b90049bc 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -48,10 +48,6 @@ Module['callMain'] = Module.callMain = function callMain(args) { args = args || []; - if (ENVIRONMENT_IS_WEB && preloadStartTime !== null) { - Module.printErr('preload time: ' + (Date.now() - preloadStartTime) + ' ms'); - } - ensureInitRuntime(); var argc = args.length+1; @@ -130,6 +126,10 @@ function run(args) { preMain(); + if (ENVIRONMENT_IS_WEB && preloadStartTime !== null) { + Module.printErr('pre-main prep time: ' + (Date.now() - preloadStartTime) + ' ms'); + } + if (Module['_main'] && shouldRunNow) { Module['callMain'](args); } diff --git a/tests/fuzz/csmith_driver.py b/tests/fuzz/csmith_driver.py index 238acb9a..76d646dd 100755 --- a/tests/fuzz/csmith_driver.py +++ b/tests/fuzz/csmith_driver.py @@ -121,7 +121,7 @@ while 1: print "EMSCRIPTEN BUG" notes['embug'] += 1 fails += 1 - shutil.copyfile(fullname, 'newfail%d%s' % (fails, suffix)) + shutil.copyfile(fullname, 'newfail%d%s%s' % (fails, opts.replace('-', '_'), suffix)) continue #if not ok: # try: # finally, try with safe heap. if that is triggered, this is nonportable code almost certainly diff --git a/tests/mem_init.cpp b/tests/mem_init.cpp new file mode 100644 index 00000000..e642bfc9 --- /dev/null +++ b/tests/mem_init.cpp @@ -0,0 +1,24 @@ +#include <stdio.h> +#include <emscripten.h> + +extern "C" { + +int noted = 0; + +void EMSCRIPTEN_KEEPALIVE note(int n) { + EM_ASM_({ Module.print([$0, $1]) }, n, noted); + noted = noted | n; + EM_ASM_({ Module.print(['noted is now', $0]) }, noted); + if (noted == 3) { + int result = noted; + REPORT_RESULT(); + } +} + +} + +int main() { + EM_ASM( myJSCallback() ); // calls a global JS func + return 0; +} + diff --git a/tests/runner.py b/tests/runner.py index c13a16eb..26912f25 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -779,14 +779,11 @@ A recommended order is: (the main test suite) other - tests separate from the main suite browser - runs pages in a web browser + interactive - runs interactive browser tests that need human verification, and could not be automated sockets - runs websocket networking tests benchmark - run before and after each set of changes before pushing to master, verify no regressions -There are also commands to run specific subsets of the test suite: - - browser.audio - runs audio tests in a web browser (requires human verification) - To run one of those parts, do something like python tests/runner.py sanity diff --git a/tests/sdl_wm_togglefullscreen.c b/tests/sdl_wm_togglefullscreen.c new file mode 100644 index 00000000..b8052988 --- /dev/null +++ b/tests/sdl_wm_togglefullscreen.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> +#include <assert.h> +#include <emscripten.h> + +int result = 1; + +SDL_Surface *screen = 0; + +int inFullscreen = 0; + +int wasFullscreen = 0; + +void mainloop() { + SDL_Event event; + int isInFullscreen = EM_ASM_INT_V(return !!(document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement)); + if (isInFullscreen && !wasFullscreen) { + printf("Successfully transitioned to fullscreen mode!\n"); + wasFullscreen = isInFullscreen; + } + + if (wasFullscreen && !isInFullscreen) { + printf("Exited fullscreen. Test succeeded.\n"); + result = 1; +#ifdef REPORT_RESULT + REPORT_RESULT(); +#endif + wasFullscreen = isInFullscreen; + emscripten_cancel_main_loop(); + return; + } + + int haveEvent = SDL_PollEvent(&event); + if (haveEvent) { + switch(event.type) { + case SDL_MOUSEBUTTONDOWN: { + SDL_WM_ToggleFullScreen(screen); + inFullscreen = 1 - inFullscreen; + if (inFullscreen == 0) { + result = wasFullscreen; + if (result) { + printf("Exited fullscreen. Test succeeded.\n"); + } else { + printf("Exited fullscreen. Test failed, fullscreen transition did not happen!\n"); + } +#ifdef REPORT_RESULT + REPORT_RESULT(); +#endif + emscripten_cancel_main_loop(); + return; + } else { + printf("Entering fullscreen...\n"); + } + break; + } + } + } +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + SDL_Rect rect = { 0, 0, 600, 450 }; + SDL_FillRect(screen, &rect, 0xff00ffff); + + printf("You should see a yellow canvas.\n"); + printf("Click on the canvas to enter full screen, and then click on the canvas again to finish the test.\n"); + printf("When in full screen, you should see the whole screen filled yellow, and after exiting, the yellow canvas should be restored in the window.\n"); + emscripten_set_main_loop(mainloop, 0, 0); + return 0; +} diff --git a/tests/test_browser.py b/tests/test_browser.py index dfb1ef69..d49244e2 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -51,23 +51,6 @@ def test_chunked_synchronous_xhr_server(support_byte_ranges, chunkSize, data, ch httpd.handle_request() class browser(BrowserCore): - @staticmethod - def audio(): - print - print 'Running the browser audio tests. Make sure to listen to hear the correct results!' - print - audio_test_cases = [ - 'test_sdl_audio', - 'test_sdl_audio_mix_channels', - 'test_sdl_audio_mix', - 'test_sdl_audio_quickload', - 'test_sdl_audio_beeps', - 'test_openal_playback', - 'test_openal_buffers', - 'test_freealut' - ] - return unittest.TestSuite(map(browser, audio_test_cases)) - @classmethod def setUpClass(self): super(browser, self).setUpClass() @@ -1130,47 +1113,6 @@ keydown(100);keyup(100); // trigger the end ''') self.btest('sdl_pumpevents.c', expected='7', args=['--pre-js', 'pre.js']) - def test_sdl_audio(self): - shutil.copyfile(path_from_root('tests', 'sounds', 'alarmvictory_1.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) - shutil.copyfile(path_from_root('tests', 'sounds', 'alarmcreatemiltaryfoot_1.wav'), os.path.join(self.get_dir(), 'sound2.wav')) - shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'noise.ogg')) - shutil.copyfile(path_from_root('tests', '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') - open(os.path.join(self.get_dir(), 'sdl_audio.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio.c')).read())) - - # use closure to check for a possible bug with closure minifying away newer Audio() attributes - Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), '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"]']).communicate() - self.run_browser('page.html', '', '/report_result?1') - - def test_sdl_audio_mix_channels(self): - shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) - open(os.path.join(self.get_dir(), 'sdl_audio_mix_channels.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix_channels.c')).read())) - - Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix_channels.c'), '--preload-file', 'sound.ogg', '-o', 'page.html']).communicate() - self.run_browser('page.html', '', '/report_result?1') - - def test_sdl_audio_mix(self): - shutil.copyfile(path_from_root('tests', 'sounds', 'pluck.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) - shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'music.ogg')) - shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'noise.ogg')) - open(os.path.join(self.get_dir(), 'sdl_audio_mix.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix.c')).read())) - - Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix.c'), '--preload-file', 'sound.ogg', '--preload-file', 'music.ogg', '--preload-file', 'noise.ogg', '-o', 'page.html']).communicate() - self.run_browser('page.html', '', '/report_result?1') - - def test_sdl_audio_quickload(self): - open(os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_quickload.c')).read())) - - Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play"]']).communicate() - self.run_browser('page.html', '', '/report_result?1') - - def test_sdl_audio_beeps(self): - open(os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_beep.cpp')).read())) - - # use closure to check for a possible bug with closure minifying away newer Audio() attributes - Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-o', 'page.html']).communicate() - self.run_browser('page.html', '', '/report_result?1') - def test_sdl_canvas_size(self): self.btest('sdl_canvas_size.c', reference='screenshot-gray-purple.png', reference_slack=1, args=['-O2', '--minify', '0', '--shell-file', path_from_root('tests', 'sdl_canvas_size.html'), '--preload-file', path_from_root('tests', 'screenshot.png') + '@/', '-s', 'LEGACY_GL_EMULATION=1'], @@ -1236,17 +1178,6 @@ keydown(100);keyup(100); // trigger the end args=['--preload-file', 'screenshot.png', '-s', 'LEGACY_GL_EMULATION=1'], message='You should see an image with fog.') - def test_openal_playback(self): - shutil.copyfile(path_from_root('tests', 'sounds', 'audio.wav'), os.path.join(self.get_dir(), 'audio.wav')) - open(os.path.join(self.get_dir(), 'openal_playback.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'openal_playback.cpp')).read())) - - Popen([PYTHON, EMCC, '-O2', os.path.join(self.get_dir(), 'openal_playback.cpp'), '--preload-file', 'audio.wav', '-o', 'page.html']).communicate() - self.run_browser('page.html', '', '/report_result?1') - - def test_openal_buffers(self): - shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.wav'), os.path.join(self.get_dir(), 'the_entertainer.wav')) - self.btest('openal_buffers.c', '0', args=['--preload-file', 'the_entertainer.wav'],) - def test_glfw(self): self.btest('glfw.c', '1', args=['-s', 'LEGACY_GL_EMULATION=1']) @@ -1262,19 +1193,6 @@ keydown(100);keyup(100); // trigger the end Popen([PYTHON, EMCC, '-O2', os.path.join(self.get_dir(), 'test_egl_width_height.c'), '-o', 'page.html']).communicate() self.run_browser('page.html', 'Should print "(300, 150)" -- the size of the canvas in pixels', '/report_result?1') - def get_freealut_library(self): - if WINDOWS and Building.which('cmake'): - return self.get_library('freealut', os.path.join('hello_world.bc'), configure=['cmake', '.'], configure_args=['-DBUILD_TESTS=ON']) - else: - return self.get_library('freealut', os.path.join('examples', '.libs', 'hello_world.bc'), make_args=['EXEEXT=.bc']) - - def test_freealut(self): - programs = self.get_freealut_library() - for program in programs: - assert os.path.exists(program) - Popen([PYTHON, EMCC, '-O2', program, '-o', 'page.html']).communicate() - self.run_browser('page.html', 'You should hear "Hello World!"') - def test_worker(self): # Test running in a web worker open('file.dat', 'w').write('data for worker') @@ -1752,6 +1670,23 @@ void *getBindBuffer() { for mem in [0, 1]: self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js', '--memory-init-file', str(mem)]) + def test_mem_init(self): + open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' + function myJSCallback() { // called from main() + Module._note(1); + } + Module.preRun = function() { + addOnPreMain(function() { + Module._note(2); + }); + }; + ''') + open(os.path.join(self.get_dir(), 'post.js'), 'w').write(''' + Module._note(4); // this happens too early! and is overwritten when the mem init arrives + ''') + + self.btest('mem_init.cpp', expected='3', args=['--pre-js', 'pre.js', '--post-js', 'post.js', '--memory-init-file', '1']) + def test_worker_api(self): Popen([PYTHON, EMCC, path_from_root('tests', 'worker_api_worker.cpp'), '-o', 'worker.js', '-s', 'BUILD_AS_WORKER=1', '-s', 'EXPORTED_FUNCTIONS=["_one"]']).communicate() self.btest('worker_api_main.cpp', expected='566') @@ -1853,9 +1788,6 @@ Module["preRun"].push(function () { def test_html5(self): self.btest(path_from_root('tests', 'test_html5.c'), expected='0') - def test_html5_fullscreen(self): - self.btest(path_from_root('tests', 'test_html5_fullscreen.c'), expected='0') - def test_codemods(self): for opt_level in [0, 2]: print 'opt level', opt_level diff --git a/tests/test_interactive.py b/tests/test_interactive.py new file mode 100644 index 00000000..715e7d6b --- /dev/null +++ b/tests/test_interactive.py @@ -0,0 +1,91 @@ +import BaseHTTPServer, multiprocessing, os, shutil, subprocess, unittest, zlib, webbrowser, time, shlex +from runner import BrowserCore, path_from_root, nonfastcomp +from tools.shared import * + +# User can specify an environment variable EMSCRIPTEN_BROWSER to force the browser test suite to +# run using another browser command line than the default system browser. +emscripten_browser = os.environ.get('EMSCRIPTEN_BROWSER') +if emscripten_browser: + cmd = shlex.split(emscripten_browser) + def run_in_other_browser(url): + Popen(cmd + [url]) + webbrowser.open_new = run_in_other_browser + +class interactive(BrowserCore): + @classmethod + def setUpClass(self): + super(interactive, self).setUpClass() + print + print 'Running the browser tests. Make sure the browser allows popups from localhost.' + print + + def test_html5_fullscreen(self): + self.btest(path_from_root('tests', 'test_html5_fullscreen.c'), expected='0') + + def test_sdl_wm_togglefullscreen(self): + self.btest('sdl_wm_togglefullscreen.c', expected='1', args=['-s', 'NO_EXIT_RUNTIME=1']) + + def test_sdl_audio(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'alarmvictory_1.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) + shutil.copyfile(path_from_root('tests', 'sounds', 'alarmcreatemiltaryfoot_1.wav'), os.path.join(self.get_dir(), 'sound2.wav')) + shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'noise.ogg')) + shutil.copyfile(path_from_root('tests', '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') + open(os.path.join(self.get_dir(), 'sdl_audio.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio.c')).read())) + + # use closure to check for a possible bug with closure minifying away newer Audio() attributes + Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), '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"]']).communicate() + self.run_browser('page.html', '', '/report_result?1') + + def test_sdl_audio_mix_channels(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) + open(os.path.join(self.get_dir(), 'sdl_audio_mix_channels.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix_channels.c')).read())) + + Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix_channels.c'), '--preload-file', 'sound.ogg', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?1') + + def test_sdl_audio_mix(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'pluck.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) + shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'music.ogg')) + shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'noise.ogg')) + open(os.path.join(self.get_dir(), 'sdl_audio_mix.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix.c')).read())) + + Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix.c'), '--preload-file', 'sound.ogg', '--preload-file', 'music.ogg', '--preload-file', 'noise.ogg', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?1') + + def test_sdl_audio_quickload(self): + open(os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_quickload.c')).read())) + + Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play"]']).communicate() + self.run_browser('page.html', '', '/report_result?1') + + def test_sdl_audio_beeps(self): + open(os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_beep.cpp')).read())) + + # use closure to check for a possible bug with closure minifying away newer Audio() attributes + Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?1') + + def test_openal_playback(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'audio.wav'), os.path.join(self.get_dir(), 'audio.wav')) + open(os.path.join(self.get_dir(), 'openal_playback.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'openal_playback.cpp')).read())) + + Popen([PYTHON, EMCC, '-O2', os.path.join(self.get_dir(), 'openal_playback.cpp'), '--preload-file', 'audio.wav', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?1') + + def test_openal_buffers(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.wav'), os.path.join(self.get_dir(), 'the_entertainer.wav')) + self.btest('openal_buffers.c', '0', args=['--preload-file', 'the_entertainer.wav'],) + + def get_freealut_library(self): + if WINDOWS and Building.which('cmake'): + return self.get_library('freealut', os.path.join('hello_world.bc'), configure=['cmake', '.'], configure_args=['-DBUILD_TESTS=ON']) + else: + return self.get_library('freealut', os.path.join('examples', '.libs', 'hello_world.bc'), make_args=['EXEEXT=.bc']) + + def test_freealut(self): + programs = self.get_freealut_library() + for program in programs: + assert os.path.exists(program) + Popen([PYTHON, EMCC, '-O2', program, '-o', 'page.html']).communicate() + self.run_browser('page.html', 'You should hear "Hello World!"') |