aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cases/fptosi.ll28
-rw-r--r--tests/cases/fptosi.txt6
-rw-r--r--tests/glgettexenv.c71
-rw-r--r--tests/test_browser.py45
-rw-r--r--tests/test_core.py5
-rw-r--r--tests/test_float_literals.cpp92
-rw-r--r--tests/test_float_literals.out22
-rw-r--r--tests/test_other.py2
8 files changed, 270 insertions, 1 deletions
diff --git a/tests/cases/fptosi.ll b/tests/cases/fptosi.ll
new file mode 100644
index 00000000..71bc6af8
--- /dev/null
+++ b/tests/cases/fptosi.ll
@@ -0,0 +1,28 @@
+; ModuleID = '/dev/shm/tmp/src.cpp.o'
+target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32"
+target triple = "le32-unknown-nacl"
+
+@.str = private unnamed_addr constant [8 x i8] c"*%.3f*\0A\00", align 1 ; [#uses=1 type=[8 x i8]*]
+@.str2 = private unnamed_addr constant [6 x i8] c"*%d*\0A\00", align 1 ; [#uses=1 type=[6 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %f = fadd float 1.000, 0.500
+ %d = fadd double 3.333, 0.444
+ %fd = fpext float %f to double
+ %call1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0), double %fd) ; [#uses=0 type=i32]
+ %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0), double %d) ; [#uses=0 type=i32]
+ %fs = fptosi float %f to i64
+ %fu = fptoui float %f to i64
+ %ds = fptosi double %d to i64
+ %du = fptoui double %d to i64
+ %call3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i64 %fs) ; [#uses=0 type=i32]
+ %call4 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i64 %fu) ; [#uses=0 type=i32]
+ %call5 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i64 %ds) ; [#uses=0 type=i32]
+ %call6 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i64 %du) ; [#uses=0 type=i32]
+ ret i32 1
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
diff --git a/tests/cases/fptosi.txt b/tests/cases/fptosi.txt
new file mode 100644
index 00000000..eea925c4
--- /dev/null
+++ b/tests/cases/fptosi.txt
@@ -0,0 +1,6 @@
+*1.500*
+*3.777*
+*1*
+*1*
+*3*
+*3*
diff --git a/tests/glgettexenv.c b/tests/glgettexenv.c
new file mode 100644
index 00000000..a051a690
--- /dev/null
+++ b/tests/glgettexenv.c
@@ -0,0 +1,71 @@
+/*
+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 1
+#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;
+ 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 );
+ screen = SDL_SetVideoMode( 640, 480, 24, SDL_OPENGL );
+ if ( !screen ) {
+ printf("Unable to set video mode: %s\n", SDL_GetError());
+ return 1;
+ }
+
+ GLint value = 0;
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
+ glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &value);
+ assert(value == GL_BLEND);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &value);
+ assert(value == GL_MODULATE);
+
+ GLfloat colora[4] = { 0.2f, 0.3f, 0.4f, 0.5f };
+ GLfloat colorb[4] = {};
+ glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, colora);
+ glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, colorb);
+ printf("%f %f %f %f\n", colorb[0], colorb[1], colorb[2], colorb[3]);
+ assert(colora[0] == colorb[0]);
+ assert(colora[1] == colorb[1]);
+ assert(colora[2] == colorb[2]);
+ assert(colora[3] == colorb[3]);
+ SDL_Quit();
+
+#ifdef REPORT_RESULT
+ int result = 1;
+ REPORT_RESULT();
+#endif
+ return 0;
+}
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 226eddee..f185c211 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -580,6 +580,45 @@ If manually bisecting:
shutil.rmtree(os.path.join(self.get_dir(), 'subdirr'))
self.run_browser('page.html', 'You should see two cool numbers', '/report_result?1')
+ def test_custom_file_package_url(self):
+ # a few files inside a directory
+ self.clear()
+ os.makedirs(os.path.join(self.get_dir(), 'subdirr'));
+ os.makedirs(os.path.join(self.get_dir(), 'cdn'));
+ open(os.path.join(self.get_dir(), 'subdirr', 'data1.txt'), 'w').write('''1214141516171819''')
+ # change the file package base dir to look in a "cdn". note that normally you would add this in your own custom html file etc., and not by
+ # modifying the existing shell in this manner
+ open(self.in_dir('shell.html'), 'w').write(open(path_from_root('src', 'shell.html')).read().replace('var Module = {', 'var Module = { filePackagePrefixURL: "cdn/", '))
+ open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(self.with_report_result(r'''
+ #include <stdio.h>
+ #include <string.h>
+ #include <emscripten.h>
+ int main() {
+ char buf[17];
+
+ FILE *f = fopen("subdirr/data1.txt", "r");
+ fread(buf, 1, 16, f);
+ buf[16] = 0;
+ fclose(f);
+ printf("|%s|\n", buf);
+ int result = !strcmp("1214141516171819", buf);
+
+ REPORT_RESULT();
+ return 0;
+ }
+ '''))
+
+ def test():
+ Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--shell-file', 'shell.html', '--preload-file', 'subdirr/data1.txt', '-o', 'test.html']).communicate()
+ shutil.move('test.data', os.path.join('cdn', 'test.data'))
+ self.run_browser('test.html', '', '/report_result?1')
+
+ test()
+
+ # TODO: CORS, test using a full url for filePackagePrefixURL
+ #open(self.in_dir('shell.html'), 'w').write(open(path_from_root('src', 'shell.html')).read().replace('var Module = {', 'var Module = { filePackagePrefixURL: "http:/localhost:8888/cdn/", '))
+ #test()
+
def test_compressed_file(self):
open(os.path.join(self.get_dir(), 'datafile.txt'), 'w').write('compress this please' + (2000*'.'))
open(os.path.join(self.get_dir(), 'datafile2.txt'), 'w').write('moar' + (100*'!'))
@@ -683,6 +722,9 @@ If manually bisecting:
def test_sdl_canvas(self):
self.btest('sdl_canvas.c', expected='1', args=['-s', 'LEGACY_GL_EMULATION=1'])
+ # some extra coverage
+ self.btest('sdl_canvas.c', expected='1', args=['-s', 'LEGACY_GL_EMULATION=1', '-s', '-O0', 'SAFE_HEAP=1'])
+ self.btest('sdl_canvas.c', expected='1', args=['-s', 'LEGACY_GL_EMULATION=1', '-s', '-O2', 'SAFE_HEAP=1'])
def test_sdl_canvas_proxy(self):
def post():
@@ -1543,6 +1585,9 @@ keydown(100);keyup(100); // trigger the end
def test_cube_explosion(self):
self.btest('cube_explosion.c', reference='cube_explosion.png', args=['-s', 'LEGACY_GL_EMULATION=1'])
+ def test_glgettexenv(self):
+ self.btest('glgettexenv.c', args=['-s', 'LEGACY_GL_EMULATION=1'], expected=['1'])
+
def test_sdl_canvas_blank(self):
self.btest('sdl_canvas_blank.c', reference='sdl_canvas_blank.png')
diff --git a/tests/test_core.py b/tests/test_core.py
index 311f33a0..99c69459 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -5954,7 +5954,7 @@ def process(filename):
def test_debug(self):
if '-g' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g')
if self.emcc_args is not None:
- if '-O1' in self.emcc_args or '-O2' in self.emcc_args: return self.skip('optimizations remove LLVM debug info')
+ if '-O1' in self.emcc_args or '-O2' in self.emcc_args or '-O3' in self.emcc_args: return self.skip('optimizations remove LLVM debug info')
src = '''
#include <stdio.h>
@@ -6267,6 +6267,9 @@ def process(filename):
self.do_run(src.replace('TYPE', 'unsigned int'), '*2147483645**2**-5**5*')
Settings.CORRECT_SIGNS = 0
+ def test_float_literals(self):
+ self.do_run_from_file(path_from_root('tests', 'test_float_literals.cpp'), path_from_root('tests', 'test_float_literals.out'))
+
def test_exit_status(self):
if self.emcc_args is None: return self.skip('need emcc')
src = r'''
diff --git a/tests/test_float_literals.cpp b/tests/test_float_literals.cpp
new file mode 100644
index 00000000..fdae2764
--- /dev/null
+++ b/tests/test_float_literals.cpp
@@ -0,0 +1,92 @@
+#include <limits>
+#include <math.h>
+#include <float.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(_MSC_VER) || defined(EMSCRIPTEN)
+#define FLOAT_NAN ((float)std::numeric_limits<float>::quiet_NaN())
+#define FLOAT_INF ((float)std::numeric_limits<float>::infinity())
+#else
+#define FLOAT_NAN ((float)NAN)
+#define FLOAT_INF ((float)INFINITY)
+#endif
+
+#if defined(_MSC_VER) || defined(EMSCRIPTEN)
+#define DOUBLE_NAN ((double)std::numeric_limits<double>::quiet_NaN())
+#define DOUBLE_INF ((double)std::numeric_limits<double>::infinity())
+#else
+#define DOUBLE_NAN ((double)NAN)
+#define DOUBLE_INF ((double)INFINITY)
+#endif
+
+#ifdef _MSC_VER
+#define NOINLINE
+#else
+#define NOINLINE __attribute__((noinline))
+#endif
+
+float NOINLINE ret_e() { return (float)2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274; }
+float NOINLINE ret_minuspi() { return (float)-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679; }
+float NOINLINE val() { return 10.f; }
+float NOINLINE val2() { return -10.f; }
+float NOINLINE zero() { return 0.f; }
+float NOINLINE zero2() { return -0.f; }
+
+double NOINLINE dret_e() { return (double)2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274; }
+double NOINLINE dret_minuspi() { return (double)-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679; }
+double NOINLINE dval() { return 10.0; }
+double NOINLINE dval2() { return -10.0; }
+double NOINLINE dzero() { return 0.0; }
+double NOINLINE dzero2() { return -0.0; }
+
+const float e = ret_e();
+const float negpi = ret_minuspi();
+const float inf = FLOAT_INF;
+const float negInf = -FLOAT_INF;
+const float floatNan = FLOAT_NAN;
+const float floatMax = FLT_MAX;
+const float floatMin = -FLT_MAX;
+const float posValue = val();
+const float negValue = val2();
+const float posZero = zero();
+const float negZero = zero2();
+
+const double de = dret_e();
+const double dnegpi = dret_minuspi();
+const double dinf = DOUBLE_INF;
+const double dnegInf = -DOUBLE_INF;
+const double doubleNan = DOUBLE_NAN;
+const double doubleMax = DBL_MAX;
+const double doubleMin = -DBL_MAX;
+const double dposValue = dval();
+const double dnegValue = dval2();
+const double dposZero = dzero();
+const double dnegZero = dzero2();
+
+int main()
+{
+ printf("e: %f\n", e);
+ printf("negpi: %f\n", negpi);
+ printf("inf: %f\n", inf);
+ printf("negInf: %f\n", negInf);
+ printf("floatNan: %f\n", floatNan);
+ printf("floatMax: %f\n", floatMax);
+ printf("floatMin: %f\n", floatMin);
+ printf("posValue: %f\n", posValue);
+ printf("negValue: %f\n", negValue);
+ printf("posZero: %f\n", posZero);
+ printf("negZero: %f\n", negZero);
+
+ printf("e: %f\n", de);
+ printf("negpi: %f\n", dnegpi);
+ printf("inf: %f\n", dinf);
+ printf("negInf: %f\n", dnegInf);
+ printf("doubleNan: %f\n", doubleNan);
+ printf("doubleMax: %f\n", doubleMax);
+ printf("doubleMin: %f\n", doubleMin);
+ printf("posValue: %f\n", dposValue);
+ printf("negValue: %f\n", dnegValue);
+ printf("posZero: %f\n", dposZero);
+ printf("negZero: %f\n", dnegZero);
+}
diff --git a/tests/test_float_literals.out b/tests/test_float_literals.out
new file mode 100644
index 00000000..ab52d6c4
--- /dev/null
+++ b/tests/test_float_literals.out
@@ -0,0 +1,22 @@
+e: 2.718282
+negpi: -3.141593
+inf: inf
+negInf: -inf
+floatNan: nan
+floatMax: 3.4028234663852886e+38
+floatMin: -3.4028234663852886e+38
+posValue: 10.000000
+negValue: -10.000000
+posZero: 0.000000
+negZero: -0.000000
+e: 2.718282
+negpi: -3.141593
+inf: inf
+negInf: -inf
+doubleNan: nan
+doubleMax: 1.7976931348623157e+308
+doubleMin: -1.7976931348623157e+308
+posValue: 10.000000
+negValue: -10.000000
+posZero: 0.000000
+negZero: -0.000000
diff --git a/tests/test_other.py b/tests/test_other.py
index 53128391..8895a911 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -1773,6 +1773,8 @@ f.close()
['asm', 'eliminate']),
(path_from_root('tools', 'test-js-optimizer-asm-regs.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-output.js')).read(),
['asm', 'registerize']),
+ (path_from_root('tools', 'test-js-optimizer-asm-regs-harder.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-harder-output.js')).read(),
+ ['asm', 'registerizeHarder']),
(path_from_root('tools', 'test-js-optimizer-asm-regs-min.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-min-output.js')).read(),
['asm', 'registerize', 'minifyLocals']),
(path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(),