diff options
Diffstat (limited to 'tests')
53 files changed, 658 insertions, 390 deletions
diff --git a/tests/cases/i32_mem.ll b/tests/cases/i24_mem_ta2.ll index e50014ca..e50014ca 100644 --- a/tests/cases/i32_mem.ll +++ b/tests/cases/i24_mem_ta2.ll diff --git a/tests/cases/i32_mem.txt b/tests/cases/i24_mem_ta2.txt index 683e58e2..683e58e2 100644 --- a/tests/cases/i32_mem.txt +++ b/tests/cases/i24_mem_ta2.txt diff --git a/tests/cases/structphiparam.ll b/tests/cases/structphiparam.ll new file mode 100644 index 00000000..117bdf77 --- /dev/null +++ b/tests/cases/structphiparam.ll @@ -0,0 +1,36 @@ +; ModuleID = '/dev/shm/tmp/src.cpp.o' +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" +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]*] +@_dispatchTable = internal global i64 0 + +define i32 @doit(i32 %x, { i32, i32 } %y) { + %y0 = extractvalue { i32, i32 } %y, 0 + %y1 = extractvalue { i32, i32 } %y, 1 + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %y0, i32 %y1) ; [#uses=0 type=i32] [debug line = 5:13] + ret i32 0 +} + +define i32 @main(i32 %argc) { +entry: + %retval = alloca i32, align 4 ; [#uses=1 type=i32*] + %myi64 = alloca i64, align 4 + %comp = alloca { i32, i32 }, align 4 ; [#uses=1] + store i32 0, i32* %retval + %should = icmp ne i32 %argc, 1337 + br i1 %should, label %cond.end, label %cond.null + +cond.null: + br label %cond.end + +cond.end: ; preds = %cond.false, %cond.true + %cond = phi { i32, i32 } [ { i32 zext (i8 111 to i32), i32 6 }, %entry ], [ zeroinitializer, %cond.null ] ; [#uses=1] + store { i32, i32 } %cond, { i32, i32 }* %comp + %call = call i32 (i32, { i32, i32 })* @doit(i32 1, { i32, i32 } %cond) ; + ret i32 0 ; [debug line = 6:13] +} + +; [#uses=1] +declare i32 @printf(i8*, ...) + diff --git a/tests/cases/structphiparam.txt b/tests/cases/structphiparam.txt new file mode 100644 index 00000000..f5af49f1 --- /dev/null +++ b/tests/cases/structphiparam.txt @@ -0,0 +1 @@ +hello, 111 6! diff --git a/tests/cube_explosion.c b/tests/cube_explosion.c index 3f55b3c6..0c6eb674 100644 --- a/tests/cube_explosion.c +++ b/tests/cube_explosion.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -230,8 +216,6 @@ int main(int argc, char *argv[]) glDeleteTextures(1, &texture); assert(!glIsTexture(texture)); // but not anymore - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cube_explosion.png b/tests/cube_explosion.png Binary files differnew file mode 100644 index 00000000..58a16f2b --- /dev/null +++ b/tests/cube_explosion.png diff --git a/tests/cubegeom.c b/tests/cubegeom.c index 787b8373..949a1f9a 100644 --- a/tests/cubegeom.c +++ b/tests/cubegeom.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { int temp; // testing @@ -308,9 +294,7 @@ int main(int argc, char *argv[]) // END SDL_GL_SwapBuffers(); - - verify(); - + #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom.png b/tests/cubegeom.png Binary files differnew file mode 100644 index 00000000..1c6a7fd5 --- /dev/null +++ b/tests/cubegeom.png diff --git a/tests/cubegeom_color.png b/tests/cubegeom_color.png Binary files differnew file mode 100644 index 00000000..a1d15438 --- /dev/null +++ b/tests/cubegeom_color.png diff --git a/tests/cubegeom_color2.c b/tests/cubegeom_color2.c index 5294329d..76d71d00 100644 --- a/tests/cubegeom_color2.c +++ b/tests/cubegeom_color2.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -287,8 +273,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_color2.png b/tests/cubegeom_color2.png Binary files differnew file mode 100644 index 00000000..ee78eb63 --- /dev/null +++ b/tests/cubegeom_color2.png diff --git a/tests/cubegeom_fog.c b/tests/cubegeom_fog.c index 9c04a55d..cae6ca2d 100644 --- a/tests/cubegeom_fog.c +++ b/tests/cubegeom_fog.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -295,8 +281,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_fog.png b/tests/cubegeom_fog.png Binary files differnew file mode 100644 index 00000000..c88e5a14 --- /dev/null +++ b/tests/cubegeom_fog.png diff --git a/tests/cubegeom_glew.c b/tests/cubegeom_glew.c index 22ef5d74..a3d86a40 100644 --- a/tests/cubegeom_glew.c +++ b/tests/cubegeom_glew.c @@ -19,20 +19,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { int temp; // testing @@ -297,8 +283,7 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - + #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_mt.c b/tests/cubegeom_mt.c index 464de7cc..b4ad28a7 100644 --- a/tests/cubegeom_mt.c +++ b/tests/cubegeom_mt.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -288,8 +274,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_mt.png b/tests/cubegeom_mt.png Binary files differnew file mode 100644 index 00000000..47649cdc --- /dev/null +++ b/tests/cubegeom_mt.png diff --git a/tests/cubegeom_normal.c b/tests/cubegeom_normal.c index d128fef2..02655edf 100644 --- a/tests/cubegeom_normal.c +++ b/tests/cubegeom_normal.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -283,8 +269,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_normal.png b/tests/cubegeom_normal.png Binary files differnew file mode 100644 index 00000000..7e3b35d1 --- /dev/null +++ b/tests/cubegeom_normal.png diff --git a/tests/cubegeom_normal_dap.c b/tests/cubegeom_normal_dap.c index f811c586..752911a8 100644 --- a/tests/cubegeom_normal_dap.c +++ b/tests/cubegeom_normal_dap.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -279,8 +265,7 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - + #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_normal_dap_far.c b/tests/cubegeom_normal_dap_far.c index f954b3c7..35a068d9 100644 --- a/tests/cubegeom_normal_dap_far.c +++ b/tests/cubegeom_normal_dap_far.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -277,8 +263,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_normal_dap_far_glda.c b/tests/cubegeom_normal_dap_far_glda.c index a4b4975b..849245b8 100644 --- a/tests/cubegeom_normal_dap_far_glda.c +++ b/tests/cubegeom_normal_dap_far_glda.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -268,8 +254,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_normal_dap_far_glda.png b/tests/cubegeom_normal_dap_far_glda.png Binary files differnew file mode 100644 index 00000000..815efeb9 --- /dev/null +++ b/tests/cubegeom_normal_dap_far_glda.png diff --git a/tests/cubegeom_normal_dap_far_glda_quad.c b/tests/cubegeom_normal_dap_far_glda_quad.c index aa6383b8..93c157a4 100644 --- a/tests/cubegeom_normal_dap_far_glda_quad.c +++ b/tests/cubegeom_normal_dap_far_glda_quad.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -268,8 +254,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_normal_dap_far_glda_quad.png b/tests/cubegeom_normal_dap_far_glda_quad.png Binary files differnew file mode 100644 index 00000000..8683b0ed --- /dev/null +++ b/tests/cubegeom_normal_dap_far_glda_quad.png diff --git a/tests/cubegeom_normal_dap_far_range.c b/tests/cubegeom_normal_dap_far_range.c index eb54c22a..17691ce9 100644 --- a/tests/cubegeom_normal_dap_far_range.c +++ b/tests/cubegeom_normal_dap_far_range.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -277,8 +263,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_normal_dap_far_range.png b/tests/cubegeom_normal_dap_far_range.png Binary files differnew file mode 100644 index 00000000..7e3b35d1 --- /dev/null +++ b/tests/cubegeom_normal_dap_far_range.png diff --git a/tests/cubegeom_pre.c b/tests/cubegeom_pre.c index 8001a2b8..fb1a5e02 100644 --- a/tests/cubegeom_pre.c +++ b/tests/cubegeom_pre.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -295,8 +281,7 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - + #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_pre.png b/tests/cubegeom_pre.png Binary files differnew file mode 100644 index 00000000..0a8c95cb --- /dev/null +++ b/tests/cubegeom_pre.png diff --git a/tests/cubegeom_pre2.c b/tests/cubegeom_pre2.c index ae8dcf9f..51961bf7 100644 --- a/tests/cubegeom_pre2.c +++ b/tests/cubegeom_pre2.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -334,8 +320,6 @@ int main(int argc, char *argv[]) // END SDL_GL_SwapBuffers(); - - verify(); #if !EMSCRIPTEN SDL_Delay(1500); diff --git a/tests/cubegeom_pre2.png b/tests/cubegeom_pre2.png Binary files differnew file mode 100644 index 00000000..0a8c95cb --- /dev/null +++ b/tests/cubegeom_pre2.png diff --git a/tests/cubegeom_pre2_vao.c b/tests/cubegeom_pre2_vao.c index 98bedd54..cba262ff 100644 --- a/tests/cubegeom_pre2_vao.c +++ b/tests/cubegeom_pre2_vao.c @@ -33,20 +33,6 @@ PFNGLGENVERTEXARRAYSPROC glGenVertexArrays_ = NULL; PFNGLBINDVERTEXARRAYPROC glBindVertexArray_ = NULL; PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays_ = NULL; -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -367,8 +353,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_pre2_vao2.c b/tests/cubegeom_pre2_vao2.c index e3ab4d62..3784006c 100644 --- a/tests/cubegeom_pre2_vao2.c +++ b/tests/cubegeom_pre2_vao2.c @@ -33,20 +33,6 @@ PFNGLGENVERTEXARRAYSPROC glGenVertexArrays_ = NULL; PFNGLBINDVERTEXARRAYPROC glBindVertexArray_ = NULL; PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays_ = NULL; -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -368,8 +354,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_pre2_vao2.png b/tests/cubegeom_pre2_vao2.png Binary files differnew file mode 100644 index 00000000..1e18bcd9 --- /dev/null +++ b/tests/cubegeom_pre2_vao2.png diff --git a/tests/cubegeom_pre3.c b/tests/cubegeom_pre3.c index a1f811b6..4ba2a779 100644 --- a/tests/cubegeom_pre3.c +++ b/tests/cubegeom_pre3.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -335,8 +321,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_pre_vao.c b/tests/cubegeom_pre_vao.c index f1d35fb5..cae68cfc 100644 --- a/tests/cubegeom_pre_vao.c +++ b/tests/cubegeom_pre_vao.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -321,8 +307,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_pre_vao.png b/tests/cubegeom_pre_vao.png Binary files differnew file mode 100644 index 00000000..0a8c95cb --- /dev/null +++ b/tests/cubegeom_pre_vao.png diff --git a/tests/cubegeom_texturematrix.c b/tests/cubegeom_texturematrix.c index 229bf2a8..99a4469e 100644 --- a/tests/cubegeom_texturematrix.c +++ b/tests/cubegeom_texturematrix.c @@ -29,20 +29,6 @@ REDISTRIBUTION OF THIS SOFTWARE. #include <string.h> #include <assert.h> -void verify() { - int width = 640, height = 480; - unsigned char *data = (unsigned char*)malloc(width*height*4); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); - int sum = 0; - for (int x = 0; x < width*height*4; x++) { - if (x % 4 != 3) sum += x * data[x]; - } -#if EMSCRIPTEN - int result = sum; - REPORT_RESULT(); -#endif -} - int main(int argc, char *argv[]) { SDL_Surface *screen; @@ -300,8 +286,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapBuffers(); - verify(); - #if !EMSCRIPTEN SDL_Delay(1500); #endif diff --git a/tests/cubegeom_texturematrix.png b/tests/cubegeom_texturematrix.png Binary files differnew file mode 100644 index 00000000..9144b9e4 --- /dev/null +++ b/tests/cubegeom_texturematrix.png diff --git a/tests/dirent/test_readdir.c b/tests/dirent/test_readdir.c index 9f7b12e8..12f97b73 100644 --- a/tests/dirent/test_readdir.c +++ b/tests/dirent/test_readdir.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -129,4 +130,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/fcntl-open/src.c b/tests/fcntl-open/src.c index bd52dd3f..fc5d5c76 100644 --- a/tests/fcntl-open/src.c +++ b/tests/fcntl-open/src.c @@ -1,6 +1,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -91,4 +92,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/filesystem/output.txt b/tests/filesystem/output.txt index dd58133c..06e0a0bb 100644 --- a/tests/filesystem/output.txt +++ b/tests/filesystem/output.txt @@ -7,7 +7,7 @@ object.contents: ["123","456","deviceA","localLink","rootLink","relativeLink"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] / isRoot: true @@ -15,10 +15,10 @@ error: 0 path: / name: / - object.contents: ["forbidden","abc","def"] + object.contents: ["tmp","dev","forbidden","abc","def"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] . isRoot: false @@ -29,7 +29,7 @@ object.contents: ["123","456","deviceA","localLink","rootLink","relativeLink"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] .. isRoot: true @@ -37,10 +37,10 @@ error: 0 path: / name: / - object.contents: ["forbidden","abc","def"] + object.contents: ["tmp","dev","forbidden","abc","def"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] ../.. isRoot: true @@ -48,10 +48,10 @@ error: 0 path: / name: / - object.contents: ["forbidden","abc","def"] + object.contents: ["tmp","dev","forbidden","abc","def"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] /abc isRoot: false @@ -62,7 +62,7 @@ object.contents: ["123","456","deviceA","localLink","rootLink","relativeLink"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] /abc/123 isRoot: false @@ -114,10 +114,10 @@ error: 0 path: / name: / - object.contents: ["forbidden","abc","def"] + object.contents: ["tmp","dev","forbidden","abc","def"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] /abc/relativeLink isRoot: false @@ -128,7 +128,7 @@ object.contents: ["789","deviceB"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] /abc/relativeLink/deviceB isRoot: false @@ -150,7 +150,7 @@ object.contents: null parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] /abc/rootLink/abc/noexist isRoot: false @@ -172,7 +172,7 @@ object.contents: ["test"] parentExists: true parentPath: / - parentObject.contents: ["forbidden","abc","def"] + parentObject.contents: ["tmp","dev","forbidden","abc","def"] /forbidden/test isRoot: false diff --git a/tests/openal_buffers.c b/tests/openal_buffers.c new file mode 100644 index 00000000..6f51a685 --- /dev/null +++ b/tests/openal_buffers.c @@ -0,0 +1,187 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#ifdef EMSCRIPTEN +#include <emscripten.h> +#include <AL/al.h> +#include <AL/alc.h> +#else +#include "../system/include/AL/al.h" +#include "../system/include/AL/alc.h" +#endif + +#define NUM_BUFFERS 4 +#define BUFFER_SIZE 1470*10 + +ALCdevice* device = NULL; +ALCcontext* context = NULL; + +// Audio source state. +unsigned char* data = NULL; +unsigned int size = 0; +unsigned int offset = 0; +unsigned int channels = 0; +unsigned int frequency = 0; +unsigned int bits = 0; +ALenum format = 0; +ALuint source = 0; + +void iter(void *arg) { + ALuint buffer = 0; + ALint buffersProcessed = 0; + ALint buffersWereQueued = 0; + ALint buffersQueued = 0; + ALint state; + + alGetSourcei(source, AL_BUFFERS_PROCESSED, &buffersProcessed); + + while (offset < size && buffersProcessed--) { + // unqueue the old buffer and validate the queue length + alGetSourcei(source, AL_BUFFERS_QUEUED, &buffersWereQueued); + alSourceUnqueueBuffers(source, 1, &buffer); + + assert(alGetError() == AL_NO_ERROR); + int len = size - offset; + if (len > BUFFER_SIZE) { + len = BUFFER_SIZE; + } + + alGetSourcei(source, AL_BUFFERS_QUEUED, &buffersQueued); + assert(buffersQueued == buffersWereQueued - 1); + + // queue the new buffer and validate the queue length + buffersWereQueued = buffersQueued; + alBufferData(buffer, format, &data[offset], len, frequency); + + alSourceQueueBuffers(source, 1, &buffer); + assert(alGetError() == AL_NO_ERROR); + + alGetSourcei(source, AL_BUFFERS_QUEUED, &buffersQueued); + assert(buffersQueued == buffersWereQueued + 1); + + // make sure it's still playing + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_PLAYING); + + offset += len; + } + + // Exit once we've processed the entire clip. + if (offset >= size) { +#ifdef EMSCRIPTEN + int result = 0; + REPORT_RESULT(); +#endif + exit(0); + } +} + +int main(int argc, char* argv[]) { + // + // Setup the AL context. + // + device = alcOpenDevice(NULL); + context = alcCreateContext(device, NULL); + alcMakeContextCurrent(context); + + // + // Read in the audio sample. + // +#ifdef EMSCRIPTEN + FILE* fp = fopen("the_entertainer.wav", "rb"); +#else + FILE* fp = fopen("sounds/the_entertainer.wav", "rb"); +#endif + fseek(fp, 0, SEEK_END); + size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + data = (unsigned char*)malloc(size); + fread(data, size, 1, fp); + fclose(fp); + + offset = 12; // ignore the RIFF header + offset += 8; // ignore the fmt header + offset += 2; // ignore the format type + + channels = data[offset + 1] << 8; + channels |= data[offset]; + offset += 2; + printf("Channels: %u\n", channels); + + frequency = data[offset + 3] << 24; + frequency |= data[offset + 2] << 16; + frequency |= data[offset + 1] << 8; + frequency |= data[offset]; + offset += 4; + printf("Frequency: %u\n", frequency); + + offset += 6; // ignore block size and bps + + bits = data[offset + 1] << 8; + bits |= data[offset]; + offset += 2; + printf("Bits: %u\n", bits); + + format = 0; + if (bits == 8) { + if (channels == 1) { + format = AL_FORMAT_MONO8; + } else if (channels == 2) { + format = AL_FORMAT_STEREO8; + } + } else if (bits == 16) { + if (channels == 1) { + format = AL_FORMAT_MONO16; + } else if (channels == 2) { + format = AL_FORMAT_STEREO16; + } + } + offset += 8; // ignore the data chunk + + // + // Seed the buffers with some initial data. + // + ALuint buffers[NUM_BUFFERS]; + alGenBuffers(NUM_BUFFERS, buffers); + alGenSources(1, &source); + + ALint numBuffers = 0; + while (numBuffers < NUM_BUFFERS && offset < size) { + int len = size - offset; + if (len > BUFFER_SIZE) { + len = BUFFER_SIZE; + } + + alBufferData(buffers[numBuffers], format, &data[offset], len, frequency); + alSourceQueueBuffers(source, 1, &buffers[numBuffers]); + assert(alGetError() == AL_NO_ERROR); + + offset += len; + numBuffers++; + } + + // + // Start playing the source. + // + alSourcePlay(source); + + ALint state; + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_PLAYING); + + alGetSourcei(source, AL_BUFFERS_QUEUED, &numBuffers); + assert(numBuffers == NUM_BUFFERS); + + // + // Cycle and refill the buffers until we're done. + // +#if EMSCRIPTEN + emscripten_set_main_loop(iter, 0, 0); +#else + while (1) { + iter(NULL); + usleep(16); + } +#endif +} diff --git a/tests/qsort/benchmark.cpp b/tests/qsort/benchmark.cpp new file mode 100644 index 00000000..950ca437 --- /dev/null +++ b/tests/qsort/benchmark.cpp @@ -0,0 +1,43 @@ +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +typedef unsigned int uint32; + +int cmp_uint(const void *i1, const void *i2) { + if (*static_cast<const uint32*>(i1) > + *static_cast<const uint32*>(i2)) + return 1; + + if (*static_cast<const uint32*>(i1) < + *static_cast<const uint32*>(i2)) + return -1; + + return 0; +} + +int main() { + clock_t start = clock(); + const size_t TIMES = 10000; + for (size_t i = 0; i < TIMES; i++) { + const size_t num = 100; + uint32 rnd[num] = { \ + 407, 236, 765, 529, 24, 13, 577, 900, 242, 245, \ + 782, 972, 514, 100, 596, 470, 680, 65, 370, 788, \ + 44, 330, 579, 314, 914, 399, 100, 945, 992, 412, \ + 308, 102, 895, 529, 216, 422, 851, 778, 28, 804, \ + 325, 975, 961, 623, 922, 667, 141, 755, 416, 575, \ + 712, 503, 174, 675, 14, 647, 544, 881, 858, 621, \ + 26, 283, 460, 252, 146, 16, 571, 570, 14, 143, \ + 674, 985, 477, 386, 932, 490, 611, 127, 702, 619, \ + 104, 892, 58, 635, 663, 424, 714, 740, 229, 538, \ + 167, 181, 193, 193, 657, 778, 217, 573, 764, 745}; + + qsort(rnd, num, sizeof(uint32), cmp_uint); + } + clock_t end = clock(); + + float diff = (((float)end - (float)start) / CLOCKS_PER_SEC ) * 1000; + printf("cost %fms\n", diff); +} + diff --git a/tests/runner.py b/tests/runner.py index 1948ab59..84e8b69e 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -5025,6 +5025,36 @@ The current type of b is: 9 ''' self.do_run(src, 'time: ') # compilation check, mainly + def test_gmtime(self): + src = r''' + #include <stdio.h> + #include <stdlib.h> + #include <time.h> + #include <assert.h> + + int main(void) + { + time_t t=time(NULL); + struct tm *ptm=gmtime(&t); + struct tm tmCurrent=*ptm; + int hour=tmCurrent.tm_hour; + + t-=hour*3600; // back to midnight + int yday = -1; + for(hour=0;hour<24;hour++) + { + ptm=gmtime(&t); + // tm_yday must be constant all day... + printf("yday: %d, hour: %d\n", ptm->tm_yday, hour); + if (yday == -1) yday = ptm->tm_yday; + else assert(yday == ptm->tm_yday); + t+=3600; // add one hour + } + printf("ok!\n"); + return(0); + } + ''' + self.do_run(src, '''ok!''') def test_strptime_tm(self): src=r''' @@ -5313,7 +5343,7 @@ The current type of b is: 9 return 0; } ''' - self.do_run(src, 'fault on write to 0' if not Settings.ASM_JS else 'Assertion: 0') + self.do_run(src, 'fault on write to 0' if not Settings.ASM_JS else 'abort()') def test_trickystring(self): src = r''' @@ -9060,6 +9090,7 @@ def process(filename): src = r''' #include <stdio.h> + #include <stdlib.h> extern "C" { int get_int() { return 5; } @@ -9082,42 +9113,44 @@ def process(filename): if (argc == 15) print_string(argv[0]); if (argc == 16) pointer((int*)argv[0]); if (argc % 17 == 12) return multi(argc, float(argc)/2, argc+1, argv[0]); - return 0; + // return 0; + exit(0); } ''' post = ''' def process(filename): src = \'\'\' - var Module = { - 'postRun': function() { - Module.print('*'); - var ret; - ret = Module['ccall']('get_int', 'number'); Module.print([typeof ret, ret]); - ret = ccall('get_float', 'number'); Module.print([typeof ret, ret.toFixed(2)]); - ret = ccall('get_string', 'string'); Module.print([typeof ret, ret]); - ret = ccall('print_int', null, ['number'], [12]); Module.print(typeof ret); - ret = ccall('print_float', null, ['number'], [14.56]); Module.print(typeof ret); - ret = ccall('print_string', null, ['string'], ["cheez"]); Module.print(typeof ret); - ret = ccall('print_string', null, ['array'], [[97, 114, 114, 45, 97, 121, 0]]); Module.print(typeof ret); - ret = ccall('multi', 'number', ['number', 'number', 'number', 'string'], [2, 1.4, 3, 'more']); Module.print([typeof ret, ret]); - var p = ccall('malloc', 'pointer', ['number'], [4]); - setValue(p, 650, 'i32'); - ret = ccall('pointer', 'pointer', ['pointer'], [p]); Module.print([typeof ret, getValue(ret, 'i32')]); - Module.print('*'); - // part 2: cwrap - var multi = Module['cwrap']('multi', 'number', ['number', 'number', 'number', 'string']); - Module.print(multi(2, 1.4, 3, 'atr')); - Module.print(multi(8, 5.4, 4, 'bret')); - Module.print('*'); - // part 3: avoid stack explosion - for (var i = 0; i < TOTAL_STACK/60; i++) { - ccall('multi', 'number', ['number', 'number', 'number', 'string'], [0, 0, 0, '123456789012345678901234567890123456789012345678901234567890']); - } - Module.print('stack is ok.'); + var Module = { noInitialRun: true }; + \'\'\' + open(filename, 'r').read() + \'\'\' + Module.addOnExit(function () { + Module.print('*'); + var ret; + ret = Module['ccall']('get_int', 'number'); Module.print([typeof ret, ret]); + ret = ccall('get_float', 'number'); Module.print([typeof ret, ret.toFixed(2)]); + ret = ccall('get_string', 'string'); Module.print([typeof ret, ret]); + ret = ccall('print_int', null, ['number'], [12]); Module.print(typeof ret); + ret = ccall('print_float', null, ['number'], [14.56]); Module.print(typeof ret); + ret = ccall('print_string', null, ['string'], ["cheez"]); Module.print(typeof ret); + ret = ccall('print_string', null, ['array'], [[97, 114, 114, 45, 97, 121, 0]]); Module.print(typeof ret); + ret = ccall('multi', 'number', ['number', 'number', 'number', 'string'], [2, 1.4, 3, 'more']); Module.print([typeof ret, ret]); + var p = ccall('malloc', 'pointer', ['number'], [4]); + setValue(p, 650, 'i32'); + ret = ccall('pointer', 'pointer', ['pointer'], [p]); Module.print([typeof ret, getValue(ret, 'i32')]); + Module.print('*'); + // part 2: cwrap + var multi = Module['cwrap']('multi', 'number', ['number', 'number', 'number', 'string']); + Module.print(multi(2, 1.4, 3, 'atr')); + Module.print(multi(8, 5.4, 4, 'bret')); + Module.print('*'); + // part 3: avoid stack explosion + for (var i = 0; i < TOTAL_STACK/60; i++) { + ccall('multi', 'number', ['number', 'number', 'number', 'string'], [0, 0, 0, '123456789012345678901234567890123456789012345678901234567890']); } - }; - \'\'\' + open(filename, 'r').read() + Module.print('stack is ok.'); + }); + Module.callMain(); + \'\'\' open(filename, 'w').write(src) ''' @@ -9329,6 +9362,26 @@ def process(filename): ''' self.do_run(src, 'abs(-10): 10\nabs(-11): 11'); + def test_embind_2(self): + if self.emcc_args is None: return self.skip('requires emcc') + Building.COMPILER_TEST_OPTS += ['--bind', '--post-js', 'post.js'] + open('post.js', 'w').write(''' + Module.print('lerp ' + Module.lerp(1, 2, 0.66) + '.'); + ''') + src = r''' + #include <stdio.h> + #include <SDL/SDL.h> + #include <emscripten/bind.h> + using namespace emscripten; + float lerp(float a, float b, float t) { + return (1 - t) * a + t * b; + } + EMSCRIPTEN_BINDINGS(my_module) { + function("lerp", &lerp); + } + ''' + self.do_run(src, 'lerp 1.66'); + def test_scriptaclass(self): if self.emcc_args is None: return self.skip('requires emcc') @@ -10680,6 +10733,27 @@ f.close() os.chdir(path_from_root('tests')) # Move away from the directory we are about to remove. shutil.rmtree(tempdirname) + def test_nostdincxx(self): + try: + old = os.environ.get('EMCC_LLVM_TARGET') or '' + for compiler in [EMCC, EMXX]: + for target in ['i386-pc-linux-gnu', 'le32-unknown-nacl']: + print compiler, target + os.environ['EMCC_LLVM_TARGET'] = target + out, err = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-v'], stdout=PIPE, stderr=PIPE).communicate() + out2, err2 = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-v', '-nostdinc++'], stdout=PIPE, stderr=PIPE).communicate() + assert out == out2 + def focus(e): + assert 'search starts here:' in e, e + assert e.count('End of search list.') == 1, e + return e[e.index('search starts here:'):e.index('End of search list.')+20] + err = focus(err) + err2 = focus(err2) + assert err == err2, err + '\n\n\n\n' + err2 + finally: + if old: + os.environ['EMCC_LLVM_TARGET'] = old + def test_failure_error_code(self): for compiler in [EMCC, EMXX]: # Test that if one file is missing from the build, then emcc shouldn't succeed, and shouldn't try to produce an output file. @@ -11034,6 +11108,23 @@ f.close() std::string side() { return "and hello from side"; } ''', ['hello from main and hello from side\n']) + # followup to iostream test: a second linking + print 'second linking of a linking output' + open('moar.cpp', 'w').write(r''' + #include <iostream> + struct Moar { + Moar() { std::cout << "moar!" << std::endl; } + }; + Moar m; + ''') + Popen([PYTHON, EMCC, 'moar.cpp', '-o', 'moar.js', '-s', 'SIDE_MODULE=1', '-O2']).communicate() + Popen([PYTHON, EMLINK, 'together.js', 'moar.js', 'triple.js'], stdout=PIPE).communicate() + assert os.path.exists('triple.js') + for engine in JS_ENGINES: + out = run_js('triple.js', engine=engine, stderr=PIPE, full_output=True) + self.assertContained('moar!\nhello from main and hello from side\n', out) + if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) + # zlib compression library. tests function pointers in initializers and many other things test('zlib', '', open(path_from_root('tests', 'zlib', 'example.c'), 'r').read(), self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']), @@ -11246,6 +11337,29 @@ int main(int argc, char const *argv[]) # node's stdin support is broken self.assertContained('abc', Popen(listify(SPIDERMONKEY_ENGINE) + ['a.out.js'], stdin=open('in.txt'), stdout=PIPE, stderr=PIPE).communicate()[0]) + def test_ungetc_fscanf(self): + open('main.cpp', 'w').write(r''' + #include <stdio.h> + int main(int argc, char const *argv[]) + { + char str[4] = {0}; + FILE* f = fopen("my_test.input", "r"); + if (f == NULL) { + printf("cannot open file\n"); + return -1; + } + ungetc('x', f); + ungetc('y', f); + ungetc('z', f); + fscanf(f, "%3s", str); + printf("%s\n", str); + return 0; + } + ''') + open('my_test.input', 'w').write('abc') + Building.emcc('main.cpp', ['--embed-file', 'my_test.input'], output_filename='a.out.js') + self.assertContained('zyx', Popen(listify(JS_ENGINES[0]) + ['a.out.js'], stdout=PIPE, stderr=PIPE).communicate()[0]) + def test_abspaths(self): # Includes with absolute paths are generally dangerous, things like -I/usr/.. will get to system local headers, not our portable ones. @@ -11951,7 +12065,9 @@ int main(int argc, char const *argv[]) ([], True), # without --bind, we fail (['--bind'], False), (['--bind', '-O1'], False), - (['--bind', '-O2'], False) + (['--bind', '-O2'], False), + (['--bind', '-O1', '-s', 'ASM_JS=0'], False), + (['--bind', '-O2', '-s', 'ASM_JS=0'], False) ]: print args, fail self.clear() @@ -12070,6 +12186,36 @@ seeked= file. self.assertNotContained('emcc: warning: treating -s as linker option', output[1]) assert os.path.exists('conftest') + def test_file_packager(self): + try: + os.mkdir('subdir') + except: + pass + open('data1.txt', 'w').write('data1') + os.chdir('subdir') + open('data2.txt', 'w').write('data2') + # relative path to below the current dir is invalid + out, err = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', '../data1.txt'], stdout=PIPE, stderr=PIPE).communicate() + assert len(out) == 0 + assert 'below the current directory' in err + # relative path that ends up under us is cool + out, err = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', '../subdir/data2.txt'], stdout=PIPE, stderr=PIPE).communicate() + assert len(out) > 0 + assert 'below the current directory' not in err + # direct path leads to the same code being generated - relative path does not make us do anything different + out2, err2 = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'data2.txt'], stdout=PIPE, stderr=PIPE).communicate() + assert len(out2) > 0 + assert 'below the current directory' not in err2 + def clean(txt): + return filter(lambda line: 'PACKAGE_UUID' not in line, txt.split('\n')) + out = clean(out) + out2 = clean(out2) + assert out == out2 + # sanity check that we do generate different code for different inputs + out3, err3 = Popen([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'data2.txt', 'data2.txt@waka.txt'], stdout=PIPE, stderr=PIPE).communicate() + out3 = clean(out3) + assert out != out3 + def test_crunch(self): # crunch should not be run if a .crn exists that is more recent than the .dds shutil.copyfile(path_from_root('tests', 'ship.dds'), 'ship.dds') @@ -12131,6 +12277,7 @@ elif 'browser' in str(sys.argv): 'browser.test_sdl_audio_mix', 'browser.test_sdl_audio_quickload', 'browser.test_openal_playback', + 'browser.test_openal_buffers', 'browser.test_freealut' ] @@ -12196,7 +12343,7 @@ elif 'browser' in str(sys.argv): @classmethod def tearDownClass(cls): if not hasattr(browser, 'harness_server'): return - + browser.harness_server.terminate() delattr(browser, 'harness_server') print '[Browser harness server terminated]' @@ -12270,6 +12417,14 @@ elif 'browser' in str(sys.argv): var actualUrl = Module.canvas.toDataURL(); var actualImage = new Image(); actualImage.onload = function() { + /* + document.body.appendChild(img); // for comparisons + var div = document.createElement('div'); + div.innerHTML = '^=expected, v=actual'; + document.body.appendChild(div); + document.body.appendChild(actualImage); // to grab it for creating the test reference + */ + var actualCanvas = document.createElement('canvas'); actualCanvas.width = actualImage.width; actualCanvas.height = actualImage.height; @@ -12570,7 +12725,7 @@ Press any key to continue.''' open(absolute_src_path2, 'w').write('''load me right before running the code please''') def make_main(path): - print path + print 'make main at', path open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(self.with_report_result(r''' #include <stdio.h> #include <string.h> @@ -12608,14 +12763,14 @@ Press any key to continue.''' for test in test_cases: (srcpath, dstpath) = test + print 'Testing', srcpath, dstpath make_main(dstpath) - print srcpath Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', srcpath, '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1') # By absolute path - make_main(absolute_src_path) + make_main('somefile.txt') # absolute becomes relative Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--preload-file', absolute_src_path, '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should see |load me right before|.', '/report_result?1') @@ -12675,7 +12830,7 @@ Press any key to continue.''' # Should still work with -o subdir/.. - make_main(absolute_src_path) + make_main('somefile.txt') # absolute becomes relative try: os.mkdir(os.path.join(self.get_dir(), 'dirrey')) except: @@ -12868,6 +13023,16 @@ Press any key to continue.''' shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) self.btest('sdl_image_prepare_data.c', reference='screenshot.jpg', args=['--preload-file', 'screenshot.not']) + def test_sdl_stb_image(self): + # load an image file, get pixel data. + shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) + self.btest('sdl_stb_image.c', reference='screenshot.jpg', args=['-s', 'STB_IMAGE=1', '--preload-file', 'screenshot.not']) + + def test_sdl_stb_image_data(self): + # load an image file, get pixel data. + shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) + self.btest('sdl_stb_image_data.c', reference='screenshot.jpg', args=['-s', 'STB_IMAGE=1', '--preload-file', 'screenshot.not']) + def test_sdl_canvas(self): open(os.path.join(self.get_dir(), 'sdl_canvas.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_canvas.c')).read())) @@ -13080,20 +13245,20 @@ Press any key to continue.''' def test_sdl_ogl(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('sdl_ogl.c', reference='screenshot-gray-purple.png', + self.btest('sdl_ogl.c', reference='screenshot-gray-purple.png', reference_slack=1, args=['-O2', '--minify', '0', '--preload-file', 'screenshot.png'], message='You should see an image with gray at the top.') def test_sdl_ogl_defaultmatrixmode(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('sdl_ogl_defaultMatrixMode.c', reference='screenshot-gray-purple.png', + self.btest('sdl_ogl_defaultMatrixMode.c', reference='screenshot-gray-purple.png', reference_slack=1, args=['--minify', '0', '--preload-file', 'screenshot.png'], message='You should see an image with gray at the top.') def test_sdl_ogl_p(self): # Immediate mode with pointers shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('sdl_ogl_p.c', reference='screenshot-gray.png', + self.btest('sdl_ogl_p.c', reference='screenshot-gray.png', reference_slack=1, args=['--preload-file', 'screenshot.png'], message='You should see an image with gray at the top.') @@ -13123,7 +13288,7 @@ Press any key to continue.''' def test_sdl_fog_linear(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('sdl_fog_linear.c', reference='screenshot-fog-linear.png', + self.btest('sdl_fog_linear.c', reference='screenshot-fog-linear.png', reference_slack=1, args=['--preload-file', 'screenshot.png'], message='You should see an image with fog.') @@ -13134,6 +13299,10 @@ Press any key to continue.''' 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): open(os.path.join(self.get_dir(), 'glfw.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'glfw.c')).read())) @@ -13422,12 +13591,12 @@ Press any key to continue.''' def test_gl_ps(self): # pointers and a shader shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('gl_ps.c', reference='gl_ps.png', args=['--preload-file', 'screenshot.png']) + self.btest('gl_ps.c', reference='gl_ps.png', args=['--preload-file', 'screenshot.png'], reference_slack=1) def test_gl_ps_packed(self): # packed data that needs to be strided shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('gl_ps_packed.c', reference='gl_ps.png', args=['--preload-file', 'screenshot.png']) + self.btest('gl_ps_packed.c', reference='gl_ps.png', args=['--preload-file', 'screenshot.png'], reference_slack=1) def test_gl_ps_strides(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) @@ -13443,64 +13612,64 @@ Press any key to continue.''' self.btest('gl_matrix_identity.c', expected=['-1882984448', '460451840']) def test_cubegeom_pre(self): - self.btest('cubegeom_pre.c', expected=['-1472804742', '-1626058463', '-2046234971']) + self.btest('cubegeom_pre.c', reference='cubegeom_pre.png') def test_cubegeom_pre2(self): - self.btest('cubegeom_pre2.c', expected=['-1472804742', '-1626058463', '-2046234971'], args=['-s', 'GL_DEBUG=1']) # some coverage for GL_DEBUG not breaking the build + self.btest('cubegeom_pre2.c', reference='cubegeom_pre2.png', args=['-s', 'GL_DEBUG=1']) # some coverage for GL_DEBUG not breaking the build def test_cubegeom_pre3(self): - self.btest('cubegeom_pre3.c', expected=['-1472804742', '-1626058463', '-2046234971']) + self.btest('cubegeom_pre3.c', reference='cubegeom_pre2.png') def test_cubegeom(self): - self.btest('cubegeom.c', args=['-O2', '-g'], expected=['188641320', '1522377227', '-1054007155', '-1111866053']) + self.btest('cubegeom.c', args=['-O2', '-g'], reference='cubegeom.png') def test_cubegeom_glew(self): - self.btest('cubegeom_glew.c', args=['-O2', '--closure', '1'], expected=['188641320', '1522377227', '-1054007155', '-1111866053']) + self.btest('cubegeom_glew.c', args=['-O2', '--closure', '1'], reference='cubegeom.png') def test_cubegeom_color(self): - self.btest('cubegeom_color.c', expected=['588472350', '-687660609', '-818120875']) + self.btest('cubegeom_color.c', reference='cubegeom_color.png') def test_cubegeom_normal(self): - self.btest('cubegeom_normal.c', expected=['752917084', '-251570256', '-291655550']) + self.btest('cubegeom_normal.c', reference='cubegeom_normal.png') def test_cubegeom_normal_dap(self): # draw is given a direct pointer to clientside memory, no element array buffer - self.btest('cubegeom_normal_dap.c', expected=['752917084', '-251570256', '-291655550']) + self.btest('cubegeom_normal_dap.c', reference='cubegeom_normal.png') def test_cubegeom_normal_dap_far(self): # indices do nto start from 0 - self.btest('cubegeom_normal_dap_far.c', expected=['752917084', '-251570256', '-291655550']) + self.btest('cubegeom_normal_dap_far.c', reference='cubegeom_normal.png') def test_cubegeom_normal_dap_far_range(self): # glDrawRangeElements - self.btest('cubegeom_normal_dap_far_range.c', expected=['752917084', '-251570256', '-291655550']) + self.btest('cubegeom_normal_dap_far_range.c', reference='cubegeom_normal.png') def test_cubegeom_normal_dap_far_glda(self): # use glDrawArrays - self.btest('cubegeom_normal_dap_far_glda.c', expected=['-218745386', '-263951846', '-375182658']) + self.btest('cubegeom_normal_dap_far_glda.c', reference='cubegeom_normal_dap_far_glda.png') def test_cubegeom_normal_dap_far_glda_quad(self): # with quad - self.btest('cubegeom_normal_dap_far_glda_quad.c', expected=['1757386625', '-677777235', '-690699597']) + self.btest('cubegeom_normal_dap_far_glda_quad.c', reference='cubegeom_normal_dap_far_glda_quad.png') def test_cubegeom_mt(self): - self.btest('cubegeom_mt.c', expected=['-457159152', '910983047', '870576921']) # multitexture + self.btest('cubegeom_mt.c', reference='cubegeom_mt.png') # multitexture def test_cubegeom_color2(self): - self.btest('cubegeom_color2.c', expected=['1121999515', '-391668088', '-522128354']) + self.btest('cubegeom_color2.c', reference='cubegeom_color2.png') def test_cubegeom_texturematrix(self): - self.btest('cubegeom_texturematrix.c', expected=['1297500583', '-791216738', '-783804685']) + self.btest('cubegeom_texturematrix.c', reference='cubegeom_texturematrix.png') def test_cubegeom_fog(self): - self.btest('cubegeom_fog.c', expected=['1617140399', '-898782526', '-946179526']) + self.btest('cubegeom_fog.c', reference='cubegeom_fog.png') def test_cubegeom_pre_vao(self): - self.btest('cubegeom_pre_vao.c', expected=['-1472804742', '-1626058463', '-2046234971']) + self.btest('cubegeom_pre_vao.c', reference='cubegeom_pre_vao.png') def test_cubegeom_pre2_vao(self): - self.btest('cubegeom_pre2_vao.c', expected=['-1472804742', '-1626058463', '-2046234971']) + self.btest('cubegeom_pre2_vao.c', reference='cubegeom_pre_vao.png') def test_cubegeom_pre2_vao2(self): - self.btest('cubegeom_pre2_vao2.c', expected=['-790445118']) + self.btest('cubegeom_pre2_vao2.c', reference='cubegeom_pre2_vao2.png') def test_cube_explosion(self): - self.btest('cube_explosion.c', expected=['667220544', '-1543354600', '-1485258415']) + self.btest('cube_explosion.c', reference='cube_explosion.png') def test_sdl_canvas_blank(self): self.btest('sdl_canvas_blank.c', reference='sdl_canvas_blank.png') @@ -14766,12 +14935,31 @@ fi finally: del os.environ['EMCC_DEBUG'] + restore() + + def ensure_cache(): + self.do([EMCC, '-O2', path_from_root('tests', 'hello_world.c')]) + # Manual cache clearing + ensure_cache() assert os.path.exists(EMCC_CACHE) output = self.do([EMCC, '--clear-cache']) assert ERASING_MESSAGE in output assert not os.path.exists(EMCC_CACHE) + # Changing LLVM_ROOT, even without altering .emscripten, clears the cache + ensure_cache() + old = os.environ.get('LLVM') + try: + os.environ['LLVM'] = 'waka' + assert os.path.exists(EMCC_CACHE) + output = self.do([EMCC]) + assert ERASING_MESSAGE in output + assert not os.path.exists(EMCC_CACHE) + finally: + if old: os.environ['LLVM'] = old + else: del os.environ['LLVM'] + try_delete(CANONICAL_TEMP_DIR) def test_relooper(self): diff --git a/tests/sdl_stb_image.c b/tests/sdl_stb_image.c new file mode 100644 index 00000000..6d39cb8e --- /dev/null +++ b/tests/sdl_stb_image.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_image.h> +#include <assert.h> +#include <emscripten.h> + +SDL_Surface* screen; + +int testImage(const char* fileName) { + SDL_Surface *image = IMG_Load(fileName); + if (!image) + { + printf("IMG_Load: %s\n", IMG_GetError()); + return 0; + } + assert(image->format->BitsPerPixel == 32); + assert(image->format->BytesPerPixel == 4); + assert(image->pitch == 4*image->w); + int result = image->w; + + SDL_BlitSurface (image, NULL, screen, NULL); + SDL_FreeSurface (image); + + return result; +} + +void ready() { + printf("ready!\n"); + + testImage("screenshot.jpg"); // relative path + + SDL_Flip(screen); +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE); + + printf("rename..\n"); + + rename("screenshot.not", "screenshot.jpg"); + + printf("decode..\n"); + + ready(); + + return 0; +} + diff --git a/tests/sdl_stb_image_data.c b/tests/sdl_stb_image_data.c new file mode 100644 index 00000000..d702b4cc --- /dev/null +++ b/tests/sdl_stb_image_data.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <SDL/SDL.h> +#include <SDL/SDL_image.h> +#include <assert.h> +#include <emscripten.h> + +#define SIZE 203164 +SDL_Surface* screen; +char *buffer; + +int testImage() { + SDL_Surface *image = IMG_Load_RW(SDL_RWFromMem(buffer, SIZE), 1); + if (!image) + { + printf("IMG_Load: %s\n", IMG_GetError()); + return 0; + } + + printf("load succeeded\n"); + + assert(image->format->BitsPerPixel == 32); + assert(image->format->BytesPerPixel == 4); + assert(image->pitch == 4*image->w); + int result = image->w; + + SDL_BlitSurface (image, NULL, screen, NULL); + SDL_FreeSurface (image); + + return result; +} + +void ready() { + testImage(); + + SDL_Flip(screen); +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE); + + printf("prepare..\n"); + + FILE *f = fopen("screenshot.not", "rb"); + buffer = malloc(SIZE); + fread(buffer, SIZE, 1, f); + fclose(f); + + ready(); + + return 0; +} + diff --git a/tests/sounds/the_entertainer.wav b/tests/sounds/the_entertainer.wav Binary files differnew file mode 100644 index 00000000..6402e312 --- /dev/null +++ b/tests/sounds/the_entertainer.wav diff --git a/tests/stat/test_chmod.c b/tests/stat/test_chmod.c index 94e6c12b..bf0e2cbe 100644 --- a/tests/stat/test_chmod.c +++ b/tests/stat/test_chmod.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -150,4 +151,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/stat/test_mknod.c b/tests/stat/test_mknod.c index 4cff57d9..2b8f650d 100644 --- a/tests/stat/test_mknod.c +++ b/tests/stat/test_mknod.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -93,4 +94,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/stat/test_stat.c b/tests/stat/test_stat.c index 14e88370..2c2bf53d 100644 --- a/tests/stat/test_stat.c +++ b/tests/stat/test_stat.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -164,4 +165,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/stdio/test_fgetc_ungetc.c b/tests/stdio/test_fgetc_ungetc.c index c69a3d1a..0eea4007 100644 --- a/tests/stdio/test_fgetc_ungetc.c +++ b/tests/stdio/test_fgetc_ungetc.c @@ -1,5 +1,6 @@ #include <assert.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -47,7 +48,9 @@ void test() { ungetc('a', file); err = fgetc(file); assert(err == (int)'a'); - fread(buffer, sizeof(char), sizeof(buffer), file); + int r = fread(buffer, sizeof(char), sizeof(buffer), file); + assert(r == 3); + buffer[3] = 0; assert(!strcmp(buffer, "bcd")); // rewind and fseek should reset anything that's been @@ -84,4 +87,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/unistd/unlink.c b/tests/unistd/unlink.c index 87252da2..f0a8f4dd 100644 --- a/tests/unistd/unlink.c +++ b/tests/unistd/unlink.c @@ -1,6 +1,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -135,4 +136,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/utime/test_utime.c b/tests/utime/test_utime.c index 1793f4a5..59e3e98a 100644 --- a/tests/utime/test_utime.c +++ b/tests/utime/test_utime.c @@ -1,5 +1,6 @@ #include <assert.h> #include <errno.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -50,4 +51,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} |