diff options
Diffstat (limited to 'tests')
30 files changed, 748 insertions, 98 deletions
diff --git a/tests/cases/atomicrmw_unaligned.emcc b/tests/cases/atomicrmw_unaligned.emcc new file mode 100644 index 00000000..9faeda24 --- /dev/null +++ b/tests/cases/atomicrmw_unaligned.emcc @@ -0,0 +1 @@ +["-s", "UNALIGNED_MEMORY=1"] diff --git a/tests/cases/atomicrmw_unaligned.ll b/tests/cases/atomicrmw_unaligned.ll new file mode 100644 index 00000000..fe479dce --- /dev/null +++ b/tests/cases/atomicrmw_unaligned.ll @@ -0,0 +1,21 @@ +; ModuleID = 'tests/hello_world.bc' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" +target triple = "i386-pc-linux-gnu" + +@.str = private unnamed_addr constant [15 x i8] c"hello, %d,%d!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +; [#uses=0] +define i32 @main() { +entry: + %t = alloca i32, align 4 ; [#uses=2 type=i32**] + store i32 50, i32* %t, align 4 + %0 = load i32* %t + %1 = atomicrmw add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12] + %2 = load i32* %t + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %0, i32 %2) ; [#uses=0 type=i32] + %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12] + ret i32 1 +} + +; [#uses=1] +declare i32 @printf(i8*, ...) diff --git a/tests/cases/atomicrmw_unaligned.txt b/tests/cases/atomicrmw_unaligned.txt new file mode 100644 index 00000000..45d16fb1 --- /dev/null +++ b/tests/cases/atomicrmw_unaligned.txt @@ -0,0 +1 @@ +hello, 50,53! diff --git a/tests/cmake/target_js/CMakeLists.txt b/tests/cmake/target_js/CMakeLists.txt index cee5fc42..244cc70a 100644 --- a/tests/cmake/target_js/CMakeLists.txt +++ b/tests/cmake/target_js/CMakeLists.txt @@ -1,11 +1,15 @@ cmake_minimum_required(VERSION 2.8) -project(hello_world) +project(test_cmake) -file(GLOB sourceFiles ../../hello_world.cpp) +file(GLOB sourceFiles main.cpp) + +file(GLOB preJsFiles pre*.js) +file(GLOB postJsFiles post*.js) +file(GLOB libraryJsFiles jslibrary*.js) if (CMAKE_BUILD_TYPE STREQUAL Debug) - SET(linkFlags "") + SET(linkFlags "-g4") else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimizations enabled. SET(linkFlags "-O2") endif() @@ -28,5 +32,17 @@ if (NOT CMAKE_C_SIZEOF_DATA_PTR) message(FATAL_ERROR "CMAKE_C_SIZEOF_DATA_PTR was not defined!") endif() -add_executable(hello_world ${sourceFiles}) -set_target_properties(hello_world PROPERTIES LINK_FLAGS "${linkFlags}") +add_executable(test_cmake ${sourceFiles}) + +# GOTCHA: If your project has custom link flags, these must be set *before* calling any of the em_link_xxx functions! +set_target_properties(test_cmake PROPERTIES LINK_FLAGS "${linkFlags}") + +message(STATUS "js libs '${libraryJsFiles}'") +# To link .js files using the --js-library flag, use the following helper function. +em_link_js_library(test_cmake ${libraryJsFiles}) + +# To link .js files using the --pre-js flag, use the following helper function. +em_link_pre_js(test_cmake ${preJsFiles}) + +# To link .js files using the --post-js flag, use the following helper function. +em_link_post_js(test_cmake ${postJsFiles}) diff --git a/tests/cmake/target_js/jslibrary.js b/tests/cmake/target_js/jslibrary.js new file mode 100644 index 00000000..63375d8f --- /dev/null +++ b/tests/cmake/target_js/jslibrary.js @@ -0,0 +1,7 @@ +var mylib = {}; + +mylib.lib_function = function() { + console.log('lib_function'); +} + +mergeInto(LibraryManager.library, mylib); diff --git a/tests/cmake/target_js/jslibrary2.js b/tests/cmake/target_js/jslibrary2.js new file mode 100644 index 00000000..5d322e2d --- /dev/null +++ b/tests/cmake/target_js/jslibrary2.js @@ -0,0 +1,7 @@ +var mylib = {}; + +mylib.lib_function2 = function() { + console.log('lib_function2'); +} + +mergeInto(LibraryManager.library, mylib); diff --git a/tests/cmake/target_js/main.cpp b/tests/cmake/target_js/main.cpp new file mode 100644 index 00000000..4b61dbf7 --- /dev/null +++ b/tests/cmake/target_js/main.cpp @@ -0,0 +1,10 @@ +extern "C" { + void lib_function(); + void lib_function2(); +} + +int main() +{ + lib_function(); + lib_function2(); +} diff --git a/tests/cmake/target_js/out.txt b/tests/cmake/target_js/out.txt new file mode 100644 index 00000000..76135df7 --- /dev/null +++ b/tests/cmake/target_js/out.txt @@ -0,0 +1,4 @@ +prejs executed +lib_function +lib_function2 +postjs executed
\ No newline at end of file diff --git a/tests/cmake/target_js/postjs.js b/tests/cmake/target_js/postjs.js new file mode 100644 index 00000000..5a1b44ce --- /dev/null +++ b/tests/cmake/target_js/postjs.js @@ -0,0 +1 @@ +console.log('postjs executed'); diff --git a/tests/cmake/target_js/prejs.js b/tests/cmake/target_js/prejs.js new file mode 100644 index 00000000..87beb770 --- /dev/null +++ b/tests/cmake/target_js/prejs.js @@ -0,0 +1 @@ +console.log('prejs executed'); diff --git a/tests/fs/test_idbfs_sync.c b/tests/fs/test_idbfs_sync.c new file mode 100644 index 00000000..ff356416 --- /dev/null +++ b/tests/fs/test_idbfs_sync.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <emscripten.h> + +#define EM_ASM_REEXPAND(x) EM_ASM(x) + +void success() { + int result = 1; + REPORT_RESULT(); +} + +int main() { + EM_ASM( + FS.mkdir('/working'); + FS.mount(IDBFS, {}, '/working'); + ); + +#if FIRST + // store local files to backing IDB + EM_ASM_REEXPAND( + FS.writeFile('/working/waka.txt', 'az'); + FS.writeFile('/working/moar.txt', SECRET); + FS.syncfs(function (err) { + assert(!err); + + ccall('success', 'v', '', []); + }); + ); +#else + // load files from backing IDB + EM_ASM_REEXPAND( + FS.syncfs(true, function (err) { + assert(!err); + + var contents = FS.readFile('/working/waka.txt', { encoding: 'utf8' }); + assert(contents === 'az'); + + var secret = FS.readFile('/working/moar.txt', { encoding: 'utf8' }); + assert(secret === SECRET); + + ccall('success', 'v', '', []); + }); + ); +#endif + + emscripten_exit_with_live_runtime(); + + return 0; +} diff --git a/tests/fs/test_nodefs_rw.c b/tests/fs/test_nodefs_rw.c new file mode 100644 index 00000000..140da332 --- /dev/null +++ b/tests/fs/test_nodefs_rw.c @@ -0,0 +1,49 @@ +#include <assert.h> +#include <stdio.h> +#include <emscripten.h> + +int main() { + FILE *file; + int res; + char buffer[512]; + + // write something locally with node + EM_ASM( + var fs = require('fs'); + fs.writeFileSync('foobar.txt', 'yeehaw'); + ); + + // mount the current folder as a NODEFS instance + // inside of emscripten + EM_ASM( + FS.mkdir('/working'); + FS.mount(NODEFS, { root: '.' }, '/working'); + ); + + // read and validate the contents of the file + file = fopen("/working/foobar.txt", "r"); + assert(file); + res = fread(buffer, sizeof(char), 6, file); + assert(res == 6); + fclose(file); + + assert(!strcmp(buffer, "yeehaw")); + + // write out something new + file = fopen("/working/foobar.txt", "w"); + assert(file); + res = fwrite("cheez", sizeof(char), 5, file); + assert(res == 5); + fclose(file); + + // validate the changes were persisted to the underlying fs + EM_ASM( + var fs = require('fs'); + var contents = fs.readFileSync('foobar.txt', { encoding: 'utf8' }); + assert(contents === 'cheez'); + ); + + puts("success"); + + return 0; +} diff --git a/tests/printf/output.txt b/tests/printf/output.txt index 19a6c1c2..0155f0da 100644 --- a/tests/printf/output.txt +++ b/tests/printf/output.txt @@ -3,10 +3,15 @@ n=7 Characters: a A Decimals: 1977 650000 12 4 -Preceding with blanks: 1977 -Preceding with zeros: 0000001977 +Preceding with blanks: 1977 -1977 +Preceding with zeros: 0000001977 -000001977 +Force sign: +1977 -1977 +1977 -1977 +Force sign or space: 1977 -1977 1977 -1977 +Sign overrides space: +1977 -1977 +1977 -1977 Some different radixes: 100 64 144 0x64 0144 -floats: 3.14 +3e+00 3.141600E+00 +floats: 3.14 +3e+00 3.141600E+00 00003.14 +negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14 +Force sign or space: 3.14 -3.14 3.14 -3.14 Width trick: 10 A string % Null string: (null) diff --git a/tests/printf/output_i64_1.txt b/tests/printf/output_i64_1.txt index 775f3f8d..e38fb78f 100644 --- a/tests/printf/output_i64_1.txt +++ b/tests/printf/output_i64_1.txt @@ -3,10 +3,15 @@ n=7 Characters: a A Decimals: 1977 650000 12 4 -Preceding with blanks: 1977 -Preceding with zeros: 0000001977 +Preceding with blanks: 1977 -1977 +Preceding with zeros: 0000001977 -000001977 +Force sign: +1977 -1977 +1977 -1977 +Force sign or space: 1977 -1977 1977 -1977 +Sign overrides space: +1977 -1977 +1977 -1977 Some different radixes: 100 64 144 0x64 0144 -floats: 3.14 +3e+00 3.141600E+00 +floats: 3.14 +3e+00 3.141600E+00 00003.14 +negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14 +Force sign or space: 3.14 -3.14 3.14 -3.14 Width trick: 10 A string % Null string: (null) diff --git a/tests/printf/test.c b/tests/printf/test.c index d05ba096..1c8ad9f7 100644 --- a/tests/printf/test.c +++ b/tests/printf/test.c @@ -8,10 +8,15 @@ int main() { printf("\n"); printf("Characters: %c %c\n", 'a', 65); printf("Decimals: %d %ld %lld %d\n", 1977, 650000L, 12LL, 4); - printf("Preceding with blanks: %10d\n", 1977); - printf("Preceding with zeros: %010d\n", 1977); + printf("Preceding with blanks: %10d %10d\n", 1977, -1977); + printf("Preceding with zeros: %010d %010d\n", 1977, -1977); + printf("Force sign: %+d %+d %+6d %+6d\n", 1977, -1977, 1977, -1977); + printf("Force sign or space: % d % d % 6d % 6d\n", 1977, -1977, 1977, -1977); + printf("Sign overrides space: % +d % +d % +6d % +6d\n", 1977, -1977, 1977, -1977); printf("Some different radixes: %d %x %o %#x %#o\n", 100, 100, 100, 100, 100); - printf("floats: %4.2f %+.0e %E\n", 3.1416, 3.1416, 3.1416); + printf("floats: %4.2f %+.0e %E %08.2f\n", 3.1416, 3.1416, 3.1416, 3.1416); + printf("negative floats: %4.2f %+.0e %E %08.2f\n", -3.1416, -3.1416, -3.1416, -3.1416); + printf("Force sign or space: % .2f % .2f % 6.2f % 6.2f\n", 3.1416, -3.1416, 3.1416, -3.1416); printf("Width trick: %*d\n", 5, 10); printf("%s %%\n", "A string"); printf("Null string: %7s\n", NULL); diff --git a/tests/sdl_audio_beep.cpp b/tests/sdl_audio_beep.cpp new file mode 100644 index 00000000..95a5a7e8 --- /dev/null +++ b/tests/sdl_audio_beep.cpp @@ -0,0 +1,246 @@ +#include <SDL/SDL.h> +#include <SDL/SDL_audio.h> +#include <queue> +#include <cmath> +#include <stdio.h> +#include <assert.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846f +#endif + +#ifdef EMSCRIPTEN +#include "emscripten/emscripten.h" +#endif + +#ifdef main +#undef main +#endif + +const int tone_duration = 1000; + +struct BeepObject { + double toneFrequency; + int samplesLeft; +}; + +class Beeper { +private: + double phase; + int frequency; + int numChannels; + int mutedChannel; +public: + Beeper(int frequency, int numChannels, int sdlAudioFormat); + ~Beeper(); + void beep(double toneFrequency, int durationMSecs); + template<typename T> + void generateSamples(T *stream, int length); + void wait(); + + std::queue<BeepObject> beeps; + int sdlAudioFormat; +}; + +void audio_callback(void*, Uint8*, int); + +Beeper::Beeper(int frequency_, int numChannels_, int sdlAudioFormat_) { + phase = 0.0; + mutedChannel = 1; + + SDL_AudioSpec desiredSpec; + + desiredSpec.freq = frequency_; + desiredSpec.format = sdlAudioFormat_; + desiredSpec.channels = numChannels_; + desiredSpec.samples = 1024; // This is samples per channel. + desiredSpec.callback = audio_callback; + desiredSpec.userdata = this; + + SDL_AudioSpec obtainedSpec; + + // you might want to look for errors here + SDL_OpenAudio(&desiredSpec, &obtainedSpec); + + // In this test, we require *exactly* the identical SDL result that we provide, since we test + // all various configurations individually. + if (obtainedSpec.freq != desiredSpec.freq || obtainedSpec.format != desiredSpec.format + || obtainedSpec.channels != desiredSpec.channels || obtainedSpec.samples != desiredSpec.samples) { + SDL_CloseAudio(); + throw std::runtime_error("Failed to initialize desired SDL_OpenAudio!"); + } + + frequency = obtainedSpec.freq; + numChannels = obtainedSpec.channels; + sdlAudioFormat = obtainedSpec.format; + + // Immediately start producing audio. + SDL_PauseAudio(0); +} + +Beeper::~Beeper() { + SDL_CloseAudio(); +} + +template<typename T> +void Beeper::generateSamples(T *stream, int length) { + const int AMPLITUDE = (sizeof(T) == 2) ? 28000 : 120; + const int offset = (sdlAudioFormat == AUDIO_U8) ? 120 : 0; + + int i = 0; + length /= numChannels; + while (i < length) { + if (beeps.empty()) { + memset(stream + numChannels*i, 0, sizeof(T)*numChannels*(length-i)); + return; + } + BeepObject& bo = beeps.front(); + + // In Stereo tests, mute one of the channels to be able to distinguish that Stereo output works. + if (bo.samplesLeft > tone_duration * frequency / 2 / 1000) { + mutedChannel = 1; + } else { + mutedChannel = 0; + } + + int samplesToDo = std::min(i + bo.samplesLeft, length); + bo.samplesLeft -= samplesToDo - i; + + while (i < samplesToDo) { + for(int j = 0; j < numChannels; ++j) { + stream[numChannels*i+j] = (T)(offset + (int)(AMPLITUDE * std::sin(phase * 2 * M_PI / frequency))); + if (numChannels > 1 && j == mutedChannel) { + stream[numChannels*i+j] = 0; + } + } + phase += bo.toneFrequency; + i++; + } + + if (bo.samplesLeft == 0) { + beeps.pop(); + } + } +} + +void Beeper::beep(double toneFrequency, int durationMSecs) { + BeepObject bo; + bo.toneFrequency = toneFrequency; + bo.samplesLeft = durationMSecs * frequency / 1000; + + SDL_LockAudio(); + beeps.push(bo); + SDL_UnlockAudio(); +} + +Beeper *beep = 0; + +// Test all kinds of various possible formats. Not all are supported, but running this +// test will report you which work. +const int freqs[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000 }; +const int channels[] = { 1, 2 }; +const int sdlAudioFormats[] = { AUDIO_U8, AUDIO_S16LSB /*, AUDIO_S8, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16MSB */ }; + +const char *SdlAudioFormatToString(int sdlAudioType) { + switch(sdlAudioType) { + case AUDIO_U8: return "AUDIO_U8"; + case AUDIO_S8: return "AUDIO_S8"; + case AUDIO_U16LSB: return "AUDIO_U16LSB"; + case AUDIO_U16MSB: return "AUDIO_U16MSB"; + case AUDIO_S16LSB: return "AUDIO_S16LSB"; + case AUDIO_S16MSB: return "AUDIO_S16MSB"; + default: return "(unknown)"; + } +} + +#define NUM_ELEMS(x) (sizeof(x)/sizeof((x)[0])) + +// Indices to the currently running test. +int f = -1; +int c = 0; +int s = 0; + +void nextTest(void *unused = 0) { + ++f; + if (f >= NUM_ELEMS(freqs)) { + f = 0; + ++c; + if (c >= NUM_ELEMS(channels)) { + c = 0; + ++s; + if (s >= NUM_ELEMS(sdlAudioFormats)) { + printf("All tests done. Quit.\n"); +#ifdef EMSCRIPTEN + emscripten_cancel_main_loop(); +#ifdef REPORT_RESULT + int result = 1; + REPORT_RESULT(); +#endif +#endif + return; + } + } + } + + double Hz = 440; + try { + beep = new Beeper(freqs[f], channels[c], sdlAudioFormats[s]); + } catch(...) { + printf("FAILED to play beep for %d msecs at %d Hz tone with audio format %s, %d channels, and %d samples/sec.\n", + tone_duration, (int)Hz, SdlAudioFormatToString(sdlAudioFormats[s]), channels[c], freqs[f]); + nextTest(); + return; + } + + printf("Playing back a beep for %d msecs at %d Hz tone with audio format %s, %d channels, and %d samples/sec.\n", + tone_duration, (int)Hz, SdlAudioFormatToString(sdlAudioFormats[s]), channels[c], freqs[f]); + beep->beep(Hz, tone_duration); +} + +void update() { + SDL_LockAudio(); + int size = beep->beeps.size(); + SDL_UnlockAudio(); + if (size == 0 && beep) { + delete beep; + beep = 0; +#ifdef EMSCRIPTEN + emscripten_async_call(nextTest, 0, 1500); +#else + SDL_Delay(1500); + nextTest(); +#endif + } +} + +void audio_callback(void *_beeper, Uint8 *_stream, int _length) { + Beeper* beeper = (Beeper*) _beeper; + + if (beeper->sdlAudioFormat == AUDIO_U8) { + Uint8 *stream = (Uint8*) _stream; + beeper->generateSamples(stream, _length); + } else if (beeper->sdlAudioFormat == AUDIO_S16LSB) { + Sint16 *stream = (Sint16*) _stream; + int length = _length / 2; + beeper->generateSamples(stream, length); + } else { + assert(false && "Audio sample generation not implemented for current format!\n"); + } +} + +int main(int argc, char** argv) { + SDL_Init(SDL_INIT_AUDIO); + + nextTest(); + +#ifdef EMSCRIPTEN + emscripten_set_main_loop(update, 60, 0); +#else + while(beep) { + SDL_Delay(20); + update(); + } +#endif + + return 0; +} diff --git a/tests/sdl_canvas_alpha.c b/tests/sdl_canvas_alpha.c new file mode 100644 index 00000000..1a41d115 --- /dev/null +++ b/tests/sdl_canvas_alpha.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdlib.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> +#include <emscripten.h> + + +int main(int argc, char **argv) { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + printf("Init: %d\n", TTF_Init()); + + TTF_Font *font = TTF_OpenFont("sans-serif", 40); + printf("Font: %p\n", font); + + SDL_Color color = { 0xff, 0x99, 0x00, 0xff }; + SDL_Surface *text = TTF_RenderText_Solid(font, "hello orange world", color); + + // render + for (int i = 0; i < 255; i++) { + SDL_Rect dest = { i, i, 0, 0 }; + SDL_SetAlpha(text, 0, (((float)i)/255)*(((float)i)/255)*255); + SDL_BlitSurface (text, NULL, screen, &dest); + } + + SDL_Flip(screen); + + SDL_LockSurface(screen); + + int width, height, isFullscreen; + emscripten_get_canvas_size(&width, &height, &isFullscreen); + + if (width != 600 && height != 450) + { + printf("error: wrong width/height\n"); + abort(); + } + + SDL_Quit(); + + printf("done.\n"); + + return 0; +} + diff --git a/tests/sdl_canvas_alpha.png b/tests/sdl_canvas_alpha.png Binary files differnew file mode 100644 index 00000000..fb9d6165 --- /dev/null +++ b/tests/sdl_canvas_alpha.png diff --git a/tests/test_browser.py b/tests/test_browser.py index 6a23b41c..799759a1 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -19,6 +19,7 @@ class browser(BrowserCore): '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' @@ -649,6 +650,9 @@ window.close = function() { self.btest('sdl_canvas_proxy.c', reference='sdl_canvas_proxy.png', args=['--proxy-to-worker', '--preload-file', 'data.txt'], manual_reference=True, post_build=post) + def test_sdl_canvas_alpha(self): + self.btest('sdl_canvas_alpha.c', reference='sdl_canvas_alpha.png', reference_slack=1) + def test_sdl_key(self): open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' Module.postRun = function() { @@ -876,6 +880,11 @@ keydown(100);keyup(100); // trigger the end self.btest('file_db.cpp', secret, args=['--preload-file', 'moar.txt']) # even with a file there, we load over it shutil.move('test.html', 'third.html') + def test_fs_idbfs_sync(self): + secret = str(time.time()) + self.btest(path_from_root('tests', 'fs', 'test_idbfs_sync.c'), '1', force_c=True, args=['-DFIRST', '-DSECRET=\'' + secret + '\'', '-s', '''EXPORTED_FUNCTIONS=['_main', '_success']''']) + self.btest(path_from_root('tests', 'fs', 'test_idbfs_sync.c'), '1', force_c=True, args=['-DSECRET=\'' + secret + '\'', '-s', '''EXPORTED_FUNCTIONS=['_main', '_success']''']) + def test_sdl_pumpevents(self): # key events should be detected using SDL_PumpEvents open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' @@ -923,6 +932,13 @@ keydown(100);keyup(100); // trigger the end 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_gl_read(self): # SDL, OpenGL, readPixels open(os.path.join(self.get_dir(), 'sdl_gl_read.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_gl_read.c')).read())) @@ -1477,7 +1493,9 @@ keydown(100);keyup(100); // trigger the end }, 2000); }; ''') - self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js']) + + 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_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() diff --git a/tests/test_core.py b/tests/test_core.py index dd3b7c44..f51c1691 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1372,6 +1372,50 @@ Succeeded! ''' self.do_run(src, '*1,10,10.5,1,1.2340,0.00*\n0.50, 3.30, 3.30, 3.30\nsmall: 0.0000010000\n') + def test_zerodiv(self): + self.do_run(r''' + #include <stdio.h> + int main(int argc, const char* argv[]) + { + float f1 = 1.0f; + float f2 = 0.0f; + float f_zero = 0.0f; + + float f3 = 0.0f / f2; + float f4 = f2 / 0.0f; + float f5 = f2 / f2; + float f6 = f2 / f_zero; + + printf("f3: %f\n", f3); + printf("f4: %f\n", f4); + printf("f5: %f\n", f5); + printf("f6: %f\n", f6); + + return 0; + } + ''', '''f3: nan +f4: nan +f5: nan +f6: nan +''') + + def test_zero_multiplication(self): + src = ''' + #include <stdio.h> + int main(int argc, char * argv[]) { + int one = argc; + + printf("%d ", 0 * one); + printf("%d ", 0 * -one); + printf("%d ", -one * 0); + printf("%g ", 0.0 * one); + printf("%g ", 0.0 * -one); + printf("%g", -one * 0.0); + return 0; + } + ''' + self.do_run(src, '0 0 0 0 -0 -0') + def test_isnan(self): src = r''' #include <stdio.h> @@ -1744,7 +1788,7 @@ Succeeded! int xx, yy, zz; char s[32]; - int cc = sscanf("abc_10.b1_xyz_543_defg", "abc_%d.%2x_xyz_%3d_%3s", &xx, &yy, &zz, s); + int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s); printf("%d:%d,%d,%d,%s\\n", cc, xx, yy, zz, s); printf("%d\\n", argc); @@ -5046,7 +5090,7 @@ The current type of b is: 9 src = r''' int main () { *(volatile char *)0 = 0; - return 0; + return *(volatile char *)0; } ''' self.do_run(src, 'fault on write to 0' if not Settings.ASM_JS else 'abort()') @@ -6908,6 +6952,29 @@ at function.:blag printf("%i\n", a); } + char buf1[100], buf2[100], buf3[100], buf4[100]; + + int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4); + printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); + + numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + return 0; } ''' @@ -6915,7 +6982,14 @@ at function.:blag '1\n1499\n' + '5\n87,0.481565,0.059481,0,1\n' + '3\n-123,4294966531,-34\n' + - '1\n') + '1\n' + + '4, level, 4, ref, 3\n' + + '2, def, 456\n' + + '2, 3-4, -ab\n' + + '2, Hello, World\n' + + '1, Hello\n' + + '1, Java\n' + + '2, [, ]') def test_sscanf_2(self): # doubles @@ -7171,6 +7245,18 @@ date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3 ''' self.do_run(src, '10 1.1 1.1 1.1'); + def test_sscanf_hex(self): + src = r''' + #include "stdio.h" + + int main(){ + unsigned int a, b; + sscanf("0x12AB 12AB", "%x %x", &a, &b); + printf("%d %d\n", a, b); |