diff options
Diffstat (limited to 'tests')
28 files changed, 1355 insertions, 275 deletions
diff --git a/tests/browser_main.cpp b/tests/browser_main.cpp new file mode 100644 index 00000000..efdce1be --- /dev/null +++ b/tests/browser_main.cpp @@ -0,0 +1,42 @@ +#include <assert.h> +#include <stdio.h> +#include <dlfcn.h> +#include <emscripten.h> + +typedef void (*voidfunc)(); +typedef int (*intfunc)(); + +void *lib_handle; +voidfunc onefunc; +intfunc twofunc; + +void next(const char *x) { + lib_handle = dlopen("themodule.js", RTLD_NOW); + assert(lib_handle != NULL); + + onefunc = (voidfunc)dlsym(lib_handle, "one"); + twofunc = (intfunc)dlsym(lib_handle, "two"); + assert(onefunc && twofunc); + + assert(twofunc() == 0); + onefunc(); + assert(twofunc() == 1); + onefunc(); + onefunc(); + assert(twofunc() == 3); + onefunc(); + onefunc(); + onefunc(); + onefunc(); + assert(twofunc() == 7); + onefunc(); + int result = twofunc(); + REPORT_RESULT(); +} + +int main() { + emscripten_async_wget("module.js", "themodule.js", next, NULL); + + return 0; +} + diff --git a/tests/browser_module.cpp b/tests/browser_module.cpp new file mode 100644 index 00000000..85d724b5 --- /dev/null +++ b/tests/browser_module.cpp @@ -0,0 +1,15 @@ + +int state = 0; + +extern "C" { + +void one() { + state++; +} + +int two() { + return state; +} + +} + diff --git a/tests/cmake/target_html/CMakeLists.txt b/tests/cmake/target_html/CMakeLists.txt index 9f891e71..8b0528eb 100644 --- a/tests/cmake/target_html/CMakeLists.txt +++ b/tests/cmake/target_html/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -project(hello_world_gles.html) +project(hello_world_gles) file(GLOB sourceFiles ../../hello_world_gles.c) @@ -10,5 +10,7 @@ else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimi SET(linkFlags "-O2") endif() -add_executable(hello_world_gles.html ${sourceFiles}) -set_target_properties(hello_world_gles.html PROPERTIES LINK_FLAGS "${linkFlags}") +SET(CMAKE_EXECUTABLE_SUFFIX ".html") + +add_executable(hello_world_gles ${sourceFiles}) +set_target_properties(hello_world_gles PROPERTIES LINK_FLAGS "${linkFlags}") diff --git a/tests/cmake/target_js/CMakeLists.txt b/tests/cmake/target_js/CMakeLists.txt index 860b70a9..cee5fc42 100644 --- a/tests/cmake/target_js/CMakeLists.txt +++ b/tests/cmake/target_js/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) -project(hello_world.js) +project(hello_world) file(GLOB sourceFiles ../../hello_world.cpp) @@ -10,5 +10,23 @@ else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimi SET(linkFlags "-O2") endif() -add_executable(hello_world.js ${sourceFiles}) -set_target_properties(hello_world.js PROPERTIES LINK_FLAGS "${linkFlags}") +SET(CMAKE_EXECUTABLE_SUFFIX ".js") + +if (WIN32) + message(FATAL_ERROR "WIN32 should not be defined when cross-compiling!") +endif() + +if (APPLE) + message(FATAL_ERROR "APPLE should not be defined when cross-compiling!") +endif() + +if (NOT EMSCRIPTEN) + message(FATAL_ERROR "EMSCRIPTEN should be defined when cross-compiling!") +endif() + +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}") diff --git a/tests/dlmalloc_proxy.c b/tests/dlmalloc_proxy.c new file mode 100644 index 00000000..06137c42 --- /dev/null +++ b/tests/dlmalloc_proxy.c @@ -0,0 +1,85 @@ +// Emscripten tests + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <dlfcn.h> + +typedef void *(*mallocer)(int n); +typedef void (*freeer)(void *p); + +void *lib_handle; +int handles = 0; +mallocer mallocproxy = NULL; +freeer freeproxy = NULL; + +void get_lib() { + //printf("get lib\n"); + lib_handle = dlopen("liblib.so", RTLD_NOW); + assert(lib_handle != NULL); + handles++; + + mallocproxy = (mallocer)dlsym(lib_handle, "mallocproxy"); + assert(mallocproxy!= NULL); + freeproxy = (freeer)dlsym(lib_handle, "freeproxy"); + assert(freeproxy!= NULL); +} + +void unget_lib() { + //printf("unget lib\n"); + assert(lib_handle); + dlclose(lib_handle); + handles--; + if (handles == 0) lib_handle = NULL; +} + +int main() { + int n = 0, total = 0, l = 0; + void *allocs[50]; + allocs[10] = malloc(10); // pull in real malloc + for (int i = 0; i < 1000; i++) { + //printf("%d: total ever %d MB, current MB %d, total libs %d\n", i, total, n, l); + if (i % 5 == 0) { + if (handles < 10) { + get_lib(); + l++; + } + } + if (i % 7 == 0) { + if (handles > 0) unget_lib(); + } + if (i % 3 == 0) { + if (handles > 0) { + if (n < 10) { + if (i % 2 == 0) { + //printf("alloc\n"); + allocs[n++] = mallocproxy(1024*1024); + } else { + //printf("real alloc\n"); + allocs[n++] = malloc(1024*1024); + } + total++; + } else { + //printf("real free\n"); + free(allocs[--n]); // real free + } + } + } + if (i % 4 == 0) { + if (handles > 0 && n > 0) { + //printf("free\n"); + if (i % 2 == 0) { + //printf("free\n"); + freeproxy(allocs[--n]); + } else { + //printf("real free\n"); + free(allocs[--n]); + } + } + } + } + while (n > 0) free(allocs[--n]); // real free + while (handles > 0) unget_lib(); + printf("*%d,%d*\n", total, l); +} + diff --git a/tests/filesystem/src.js b/tests/filesystem/src.js index dbdd4bed..91337f5b 100644 --- a/tests/filesystem/src.js +++ b/tests/filesystem/src.js @@ -1,16 +1,18 @@ var dummy_device = FS.makedev(64, 0); FS.registerDevice(dummy_device, {}); -FS.createFolder('/', 'forbidden', false, false); -FS.createFolder('/forbidden', 'test', true, true); -FS.createPath('/', 'abc/123', true, true); -FS.createPath('/', 'abc/456', true, true); -FS.createPath('/', 'def/789', true, true); -FS.mkdev('/abc/deviceA', 0666, dummy_device); -FS.mkdev('/def/deviceB', 0666, dummy_device); -FS.createLink('/abc', 'localLink', '123', true, true); -FS.createLink('/abc', 'rootLink', '/', true, true); -FS.createLink('/abc', 'relativeLink', '../def', true, true); +FS.mkdir('/forbidden', 0000); +FS.mkdir('/forbidden/test'); +FS.mkdir('/abc'); +FS.mkdir('/abc/123'); +FS.mkdir('/abc/456'); +FS.mkdir('/def'); +FS.mkdir('/def/789'); +FS.mkdev('/abc/deviceA', dummy_device); +FS.mkdev('/def/deviceB', dummy_device); +FS.symlink('123', '/abc/localLink'); +FS.symlink('/', '/abc/rootLink'); +FS.symlink('../def', '/abc/relativeLink'); FS.ignorePermissions = false; function explore(path) { diff --git a/tests/gl_vertex_buffer.c b/tests/gl_vertex_buffer.c new file mode 100644 index 00000000..6b695462 --- /dev/null +++ b/tests/gl_vertex_buffer.c @@ -0,0 +1,195 @@ +/******************************************************************* + * * + * Using SDL With OpenGL * + * * + * Tutorial by Kyle Foley (sdw) * + * * + * http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL * + * * + *******************************************************************/ + +/* + THIS WORK, INCLUDING THE SOURCE CODE, DOCUMENTATION + AND RELATED MEDIA AND DATA, IS PLACED INTO THE PUBLIC DOMAIN. + + THE ORIGINAL AUTHOR IS KYLE FOLEY. + + THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY + OF ANY KIND, NOT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, + ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE + RESULTING FROM THE USE, MODIFICATION, OR + REDISTRIBUTION OF THIS SOFTWARE. + */ + +#if !EMSCRIPTEN +#define USE_GLEW 0 +#endif + +#if USE_GLEW +#include "GL/glew.h" +#endif + +#include <SDL/SDL.h> + +#if !USE_GLEW +#include "SDL/SDL_opengl.h" +#endif + +#include <stdio.h> +#include <string.h> +#include <assert.h> + +int main(int argc, char *argv[]) +{ + SDL_Surface *screen; + + // Slightly different SDL initialization + if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { + printf("Unable to initialize SDL: %s\n", SDL_GetError()); + return 1; + } + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* + + screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed* + if ( !screen ) { + printf("Unable to set video mode: %s\n", SDL_GetError()); + return 1; + } + + // Set the OpenGL state after creating the context with SDL_SetVideoMode + + glClearColor( 0, 0, 0, 0 ); + +#if !EMSCRIPTEN + glEnable( GL_TEXTURE_2D ); // Need this to display a texture XXX unnecessary in OpenGL ES 2.0/WebGL +#endif + + glViewport( 0, 0, 640, 480 ); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + // Clear the screen before drawing + glClear( GL_COLOR_BUFFER_BIT ); + + typedef struct Color { + GLubyte r; + GLubyte g; + GLubyte b; + GLubyte a; + } Color; + + typedef struct Vertex { + GLfloat x; + GLfloat y; + Color color; + } Vertex; + + Vertex vertices[18] = { + {-1.00, 0.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-1.00, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.75, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.75, 1.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + {-0.50, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.50, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.25, 0.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-0.25, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.00, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.00, 1.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 0.25, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.25, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.50, 0.0, {0xFF, 0x00, 0xFF, 0xFF}}, + { 0.50, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.75, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.75, 1.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 1.00, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 1.00, 1.0, {0xFF, 0xFF, 0x00, 0xFF}} + }; + + Vertex vertices2[18] = { + {-1.00, -1.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-1.00, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.75, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.75, 0.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + {-0.50, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.50, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.25, -1.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-0.25, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.00, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.00, 0.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 0.25, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.25, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.50, -1.0, {0xFF, 0x00, 0xFF, 0xFF}}, + { 0.50, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.75, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.75, 0.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 1.00, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 1.00, 0.0, {0xFF, 0xFF, 0x00, 0xFF}} + }; + + // make a vertex buffer for the second set of vertices + GLuint vbo = 0; + glGenBuffers(1, &vbo); + + + // bind to it + glBindBuffer(GL_ARRAY_BUFFER, vbo); + // send it to gl + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices2), vertices2, GL_STATIC_READ); // GL_STATIC_READ is not in WebGL! + + // unbind from it + glBindBuffer(GL_ARRAY_BUFFER, 0); + + + // DRAW + + // Clear the screen before drawing + glClear( GL_COLOR_BUFFER_BIT ); + + // This test ensures that we can use two separate arrays in memory for different + // attributes, and that they each can have different stride. + // The first test shows implicit striding (the zero indicates tightly packed) + // The second test shows explicit striding where the stride is passed in + // even though it also is tightly packed + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + // TEST 1 - clientside data + + glVertexPointer(2, GL_FLOAT, sizeof(Vertex), vertices); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &vertices[0].color); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 6); + glDrawArrays(GL_TRIANGLE_STRIP, 10, 3); + + + + // TEST 2 - bind to array buffer, gl*Pointer calls are offsets into the buffer, which was previously uploaded to + + glBindBuffer(GL_ARRAY_BUFFER, vbo); + + glVertexPointer(2, GL_FLOAT, sizeof(Vertex), 0); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (GLvoid*)((GLvoid*)&vertices2[0].color - (GLvoid*)&vertices2[0])); + +// gldrawarrays first with a low number of vertices, then with a high number + glDrawArrays(GL_TRIANGLE_STRIP, 0, 6); + glDrawArrays(GL_TRIANGLE_STRIP, 10, 3); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + SDL_GL_SwapBuffers(); + +#if !EMSCRIPTEN + // Wait for 3 seconds to give us a chance to see the image + SDL_Delay(3000); +#endif + + SDL_Quit(); + + return 0; +} diff --git a/tests/gl_vertex_buffer.png b/tests/gl_vertex_buffer.png Binary files differnew file mode 100644 index 00000000..3e1f2230 --- /dev/null +++ b/tests/gl_vertex_buffer.png diff --git a/tests/gl_vertex_buffer_pre.c b/tests/gl_vertex_buffer_pre.c new file mode 100644 index 00000000..84b76569 --- /dev/null +++ b/tests/gl_vertex_buffer_pre.c @@ -0,0 +1,177 @@ +/******************************************************************* + * * + * Using SDL With OpenGL * + * * + * Tutorial by Kyle Foley (sdw) * + * * + * http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL * + * * + *******************************************************************/ + +/* + THIS WORK, INCLUDING THE SOURCE CODE, DOCUMENTATION + AND RELATED MEDIA AND DATA, IS PLACED INTO THE PUBLIC DOMAIN. + + THE ORIGINAL AUTHOR IS KYLE FOLEY. + + THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY + OF ANY KIND, NOT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, + ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE + RESULTING FROM THE USE, MODIFICATION, OR + REDISTRIBUTION OF THIS SOFTWARE. + */ + +#if !EMSCRIPTEN +#define USE_GLEW 0 +#endif + +#if USE_GLEW +#include "GL/glew.h" +#endif + +#include <SDL/SDL.h> + +#if !USE_GLEW +#include "SDL/SDL_opengl.h" +#endif + +#include <stdio.h> +#include <string.h> +#include <assert.h> + +int main(int argc, char *argv[]) +{ + SDL_Surface *screen; + + // Slightly different SDL initialization + if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { + printf("Unable to initialize SDL: %s\n", SDL_GetError()); + return 1; + } + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* + + screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed* + if ( !screen ) { + printf("Unable to set video mode: %s\n", SDL_GetError()); + return 1; + } + + // Set the OpenGL state after creating the context with SDL_SetVideoMode + + glClearColor( 0, 0, 0, 0 ); + +#if !EMSCRIPTEN + glEnable( GL_TEXTURE_2D ); // Need this to display a texture XXX unnecessary in OpenGL ES 2.0/WebGL +#endif + + glViewport( 0, 0, 640, 480 ); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + // Clear the screen before drawing + glClear( GL_COLOR_BUFFER_BIT ); + + typedef struct Color { + GLubyte r; + GLubyte g; + GLubyte b; + GLubyte a; + } Color; + + typedef struct Vertex { + GLfloat x; + GLfloat y; + Color color; + } Vertex; + + Vertex vertices[18] = { + {-1.00, 0.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-1.00, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.75, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.75, 1.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + {-0.50, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.50, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.25, 0.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-0.25, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.00, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.00, 1.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 0.25, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.25, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.50, 0.0, {0xFF, 0x00, 0xFF, 0xFF}}, + { 0.50, 1.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.75, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.75, 1.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 1.00, 0.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 1.00, 1.0, {0xFF, 0xFF, 0x00, 0xFF}} + }; + + Vertex vertices2[18] = { + {-1.00, -1.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-1.00, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.75, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.75, 0.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + {-0.50, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.50, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.25, -1.0, {0xFF, 0x00, 0xFF, 0xFF}}, + {-0.25, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + {-0.00, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + {-0.00, 0.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 0.25, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.25, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.50, -1.0, {0xFF, 0x00, 0xFF, 0xFF}}, + { 0.50, 0.0, {0xFF, 0xFF, 0x00, 0xFF}}, + { 0.75, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 0.75, 0.0, {0xFF, 0xFF, 0xFF, 0xFF}}, + { 1.00, -1.0, {0xFF, 0x00, 0x00, 0xFF}}, + { 1.00, 0.0, {0xFF, 0xFF, 0x00, 0xFF}} + }; + + // make a vertex buffer for the second set of vertices + GLuint vbo = 0; + glGenBuffers(1, &vbo); + + + // bind to it + glBindBuffer(GL_ARRAY_BUFFER, vbo); + // send it to gl + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices2), vertices2, GL_STATIC_DRAW); + + // unbind from it + glBindBuffer(GL_ARRAY_BUFFER, 0); + + + // DRAW + + // Clear the screen before drawing + glClear( GL_COLOR_BUFFER_BIT ); + + // This test ensures that we can use two separate arrays in memory for different + // attributes, and that they each can have different stride. + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glVertexPointer(2, GL_FLOAT, sizeof(Vertex), vertices); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &vertices[0].color); + glDrawArrays(GL_TRIANGLE_STRIP, 10, 3); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 6); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + SDL_GL_SwapBuffers(); + +#if !EMSCRIPTEN + // Wait for 3 seconds to give us a chance to see the image + SDL_Delay(3000); +#endif + + SDL_Quit(); + + return 0; +} diff --git a/tests/gl_vertex_buffer_pre.png b/tests/gl_vertex_buffer_pre.png Binary files differnew file mode 100644 index 00000000..5677a868 --- /dev/null +++ b/tests/gl_vertex_buffer_pre.png diff --git a/tests/runner.py b/tests/runner.py index f0e61c4e..ddc97ea4 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -254,7 +254,7 @@ process(sys.argv[1]) os.chdir(cwd) out = open(stdout, 'r').read() err = open(stderr, 'r').read() - if engine == SPIDERMONKEY_ENGINE and Settings.ASM_JS: + if engine == SPIDERMONKEY_ENGINE and Settings.ASM_JS == 1: err = self.validate_asmjs(err) if output_nicerizer: ret = output_nicerizer(out, err) @@ -646,7 +646,7 @@ class BrowserCore(RunnerCore): }); ''' % basename) - def btest(self, filename, expected=None, reference=None, force_c=False, reference_slack=0, + def btest(self, filename, expected=None, reference=None, force_c=False, reference_slack=0, manual_reference=False, post_build=None, args=[], outfile='test.html', message='.'): # TODO: use in all other tests # if we are provided the source and not a path, use that filename_is_src = '\n' in filename @@ -663,9 +663,11 @@ class BrowserCore(RunnerCore): expected = [str(i) for i in range(0, reference_slack+1)] shutil.copyfile(filepath, temp_filepath) self.reftest(path_from_root('tests', reference)) - args = args + ['--pre-js', 'reftest.js', '-s', 'GL_TESTING=1'] + if not manual_reference: + args = args + ['--pre-js', 'reftest.js', '-s', 'GL_TESTING=1'] Popen([PYTHON, EMCC, temp_filepath, '-o', outfile] + args).communicate() assert os.path.exists(outfile) + if post_build: post_build() if type(expected) is str: expected = [expected] self.run_browser(outfile, message, ['/report_result?' + e for e in expected]) diff --git a/tests/sdl_canvas_proxy.c b/tests/sdl_canvas_proxy.c new file mode 100644 index 00000000..27ef3bb4 --- /dev/null +++ b/tests/sdl_canvas_proxy.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include <SDL/SDL.h> +#include <assert.h> +#include <emscripten.h> + +int main(int argc, char **argv) { + FILE *f = fopen("data.txt", "rb"); + assert(f); + assert(fgetc(f) == 'd'); + assert(fgetc(f) == 'a'); + assert(fgetc(f) == 't'); + assert(fgetc(f) == 'u'); + assert(fgetc(f) == 'm'); + fclose(f); + + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + SDL_LockSurface(screen); + unsigned int *pixels = (unsigned int *)screen->pixels; + for (int x = 0; x < screen->w; x++) { + for (int y = 0; y < screen->h; y++) { + pixels[x + y*screen->h] = x < 300 ? (y < 200 ? 0x3377AA88 : 0xAA3377CC) : (y < 200 ? 0x0066AA77 : 0xAA006699); + } + } + SDL_UnlockSurface(screen); + + SDL_Quit(); + + EM_ASM(window.close()); + return 0; +} + diff --git a/tests/sdl_canvas_proxy.png b/tests/sdl_canvas_proxy.png Binary files differnew file mode 100644 index 00000000..cc96acfd --- /dev/null +++ b/tests/sdl_canvas_proxy.png diff --git a/tests/sdl_key_proxy.c b/tests/sdl_key_proxy.c new file mode 100644 index 00000000..bc233f29 --- /dev/null +++ b/tests/sdl_key_proxy.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> +#include <emscripten.h> + +int result = 1; + +void one() { + SDL_Event event; + while (SDL_PollEvent(&event)) { + printf("got event %d\n", event.type); + switch(event.type) { + case SDL_KEYDOWN: + break; + case SDL_KEYUP: + // don't handle the modifier key events + if (event.key.keysym.sym == SDLK_LCTRL || + event.key.keysym.sym == SDLK_LSHIFT || + event.key.keysym.sym == SDLK_LALT) { + return; + } + if ((event.key.keysym.mod & KMOD_LCTRL) || (event.key.keysym.mod & KMOD_RCTRL)) { + result *= 2; + } + if ((event.key.keysym.mod & KMOD_LSHIFT) || (event.key.keysym.mod & KMOD_RSHIFT)) { + result *= 3; + } + if ((event.key.keysym.mod & KMOD_LALT) || (event.key.keysym.mod & KMOD_RALT)) { + result *= 5; + } + switch (event.key.keysym.sym) { + case SDLK_RIGHT: printf("right\n"); result *= 7; break; + case SDLK_LEFT: printf("left\n"); result *= 11; break; + case SDLK_DOWN: printf("down\n"); result *= 13; break; + case SDLK_UP: printf("up\n"); result *= 17; break; + case SDLK_a: printf("a\n"); result *= 19; break; + default: { + if (event.key.keysym.scancode == SDL_SCANCODE_B) { + printf("b scancode\n"); result *= 23; break; + } + printf("unknown key: sym %d scancode %d\n", event.key.keysym.sym, event.key.keysym.scancode); + REPORT_RESULT(); + emscripten_run_script("throw 'done'"); // comment this out to leave event handling active. Use the following to log DOM keys: + // addEventListener('keyup', function(event) { console.log(event.keyCode) }, true) + } + } + break; + default: /* Report an unhandled event */ + printf("I don't know what this event is!\n"); + } + } +} + +int main(int argc, char **argv) { + printf("main\n"); + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + if (argc == 1337) one(); // keep it alive + + return 0; +} + diff --git a/tests/test_browser.py b/tests/test_browser.py index a0c4dceb..e6fd6544 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -627,6 +627,28 @@ If manually bisecting: Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_canvas.c'), '-o', 'page.html', '-s', 'LEGACY_GL_EMULATION=1']).communicate() self.run_browser('page.html', '', '/report_result?1') + def test_sdl_canvas_proxy(self): + def post(): + html = open('test.html').read() + html = html.replace('</body>', ''' +<script> +function assert(x, y) { if (!x) throw 'assertion failed ' + y } + +%s + +var windowClose = window.close; +window.close = function() { + doReftest(); + setTimeout(windowClose, 1000); +}; +</script> +</body>''' % open('reftest.js').read()) + open('test.html', 'w').write(html) + + open('data.txt', 'w').write('datum') + + 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_key(self): open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' Module.postRun = function() { @@ -658,6 +680,52 @@ If manually bisecting: Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_key.c'), '-o', 'page.html', '--pre-js', 'pre.js', '-s', '''EXPORTED_FUNCTIONS=['_main', '_one']''']).communicate() self.run_browser('page.html', '', '/report_result?223092870') + def test_sdl_key_proxy(self): + open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' + var Module = {}; + Module.postRun = function() { + function doOne() { + Module._one(); + setTimeout(doOne, 1000/60); + } + setTimeout(doOne, 1000/60); + } + ''') + + def post(): + html = open('test.html').read() + html = html.replace('</body>', ''' +<script> +function keydown(c) { + var event = document.createEvent("KeyboardEvent"); + event.initKeyEvent("keydown", true, true, window, + 0, 0, 0, 0, + c, c);< |