aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cases/atomicrmw_unaligned.emcc1
-rw-r--r--tests/cases/atomicrmw_unaligned.ll21
-rw-r--r--tests/cases/atomicrmw_unaligned.txt1
-rw-r--r--tests/printf/output.txt11
-rw-r--r--tests/printf/output_i64_1.txt11
-rw-r--r--tests/printf/test.c11
-rw-r--r--tests/sdl_audio_beep.cpp246
-rw-r--r--tests/sdl_canvas_alpha.c46
-rw-r--r--tests/sdl_canvas_alpha.pngbin0 -> 169826 bytes
-rw-r--r--tests/test_browser.py11
-rw-r--r--tests/test_core.py51
-rw-r--r--tests/test_other.py6
12 files changed, 404 insertions, 12 deletions
diff --git a/tests/cases/atomicrmw_unaligned.emcc b/tests/cases/atomicrmw_unaligned.emcc
new file mode 100644
index 00000000..9faeda24
--- /dev/null
+++ b/tests/cases/atomicrmw_unaligned.emcc
@@ -0,0 +1 @@
+["-s", "UNALIGNED_MEMORY=1"]
diff --git a/tests/cases/atomicrmw_unaligned.ll b/tests/cases/atomicrmw_unaligned.ll
new file mode 100644
index 00000000..fe479dce
--- /dev/null
+++ b/tests/cases/atomicrmw_unaligned.ll
@@ -0,0 +1,21 @@
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private unnamed_addr constant [15 x i8] c"hello, %d,%d!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %t = alloca i32, align 4 ; [#uses=2 type=i32**]
+ store i32 50, i32* %t, align 4
+ %0 = load i32* %t
+ %1 = atomicrmw add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12]
+ %2 = load i32* %t
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %0, i32 %2) ; [#uses=0 type=i32]
+ %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12]
+ ret i32 1
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
diff --git a/tests/cases/atomicrmw_unaligned.txt b/tests/cases/atomicrmw_unaligned.txt
new file mode 100644
index 00000000..45d16fb1
--- /dev/null
+++ b/tests/cases/atomicrmw_unaligned.txt
@@ -0,0 +1 @@
+hello, 50,53!
diff --git a/tests/printf/output.txt b/tests/printf/output.txt
index 19a6c1c2..0155f0da 100644
--- a/tests/printf/output.txt
+++ b/tests/printf/output.txt
@@ -3,10 +3,15 @@ n=7
Characters: a A
Decimals: 1977 650000 12 4
-Preceding with blanks: 1977
-Preceding with zeros: 0000001977
+Preceding with blanks: 1977 -1977
+Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
+Force sign or space: 1977 -1977 1977 -1977
+Sign overrides space: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
-floats: 3.14 +3e+00 3.141600E+00
+floats: 3.14 +3e+00 3.141600E+00 00003.14
+negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
+Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
diff --git a/tests/printf/output_i64_1.txt b/tests/printf/output_i64_1.txt
index 775f3f8d..e38fb78f 100644
--- a/tests/printf/output_i64_1.txt
+++ b/tests/printf/output_i64_1.txt
@@ -3,10 +3,15 @@ n=7
Characters: a A
Decimals: 1977 650000 12 4
-Preceding with blanks: 1977
-Preceding with zeros: 0000001977
+Preceding with blanks: 1977 -1977
+Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
+Force sign or space: 1977 -1977 1977 -1977
+Sign overrides space: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
-floats: 3.14 +3e+00 3.141600E+00
+floats: 3.14 +3e+00 3.141600E+00 00003.14
+negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
+Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
diff --git a/tests/printf/test.c b/tests/printf/test.c
index d05ba096..1c8ad9f7 100644
--- a/tests/printf/test.c
+++ b/tests/printf/test.c
@@ -8,10 +8,15 @@ int main() {
printf("\n");
printf("Characters: %c %c\n", 'a', 65);
printf("Decimals: %d %ld %lld %d\n", 1977, 650000L, 12LL, 4);
- printf("Preceding with blanks: %10d\n", 1977);
- printf("Preceding with zeros: %010d\n", 1977);
+ printf("Preceding with blanks: %10d %10d\n", 1977, -1977);
+ printf("Preceding with zeros: %010d %010d\n", 1977, -1977);
+ printf("Force sign: %+d %+d %+6d %+6d\n", 1977, -1977, 1977, -1977);
+ printf("Force sign or space: % d % d % 6d % 6d\n", 1977, -1977, 1977, -1977);
+ printf("Sign overrides space: % +d % +d % +6d % +6d\n", 1977, -1977, 1977, -1977);
printf("Some different radixes: %d %x %o %#x %#o\n", 100, 100, 100, 100, 100);
- printf("floats: %4.2f %+.0e %E\n", 3.1416, 3.1416, 3.1416);
+ printf("floats: %4.2f %+.0e %E %08.2f\n", 3.1416, 3.1416, 3.1416, 3.1416);
+ printf("negative floats: %4.2f %+.0e %E %08.2f\n", -3.1416, -3.1416, -3.1416, -3.1416);
+ printf("Force sign or space: % .2f % .2f % 6.2f % 6.2f\n", 3.1416, -3.1416, 3.1416, -3.1416);
printf("Width trick: %*d\n", 5, 10);
printf("%s %%\n", "A string");
printf("Null string: %7s\n", NULL);
diff --git a/tests/sdl_audio_beep.cpp b/tests/sdl_audio_beep.cpp
new file mode 100644
index 00000000..95a5a7e8
--- /dev/null
+++ b/tests/sdl_audio_beep.cpp
@@ -0,0 +1,246 @@
+#include <SDL/SDL.h>
+#include <SDL/SDL_audio.h>
+#include <queue>
+#include <cmath>
+#include <stdio.h>
+#include <assert.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846f
+#endif
+
+#ifdef EMSCRIPTEN
+#include "emscripten/emscripten.h"
+#endif
+
+#ifdef main
+#undef main
+#endif
+
+const int tone_duration = 1000;
+
+struct BeepObject {
+ double toneFrequency;
+ int samplesLeft;
+};
+
+class Beeper {
+private:
+ double phase;
+ int frequency;
+ int numChannels;
+ int mutedChannel;
+public:
+ Beeper(int frequency, int numChannels, int sdlAudioFormat);
+ ~Beeper();
+ void beep(double toneFrequency, int durationMSecs);
+ template<typename T>
+ void generateSamples(T *stream, int length);
+ void wait();
+
+ std::queue<BeepObject> beeps;
+ int sdlAudioFormat;
+};
+
+void audio_callback(void*, Uint8*, int);
+
+Beeper::Beeper(int frequency_, int numChannels_, int sdlAudioFormat_) {
+ phase = 0.0;
+ mutedChannel = 1;
+
+ SDL_AudioSpec desiredSpec;
+
+ desiredSpec.freq = frequency_;
+ desiredSpec.format = sdlAudioFormat_;
+ desiredSpec.channels = numChannels_;
+ desiredSpec.samples = 1024; // This is samples per channel.
+ desiredSpec.callback = audio_callback;
+ desiredSpec.userdata = this;
+
+ SDL_AudioSpec obtainedSpec;
+
+ // you might want to look for errors here
+ SDL_OpenAudio(&desiredSpec, &obtainedSpec);
+
+ // In this test, we require *exactly* the identical SDL result that we provide, since we test
+ // all various configurations individually.
+ if (obtainedSpec.freq != desiredSpec.freq || obtainedSpec.format != desiredSpec.format
+ || obtainedSpec.channels != desiredSpec.channels || obtainedSpec.samples != desiredSpec.samples) {
+ SDL_CloseAudio();
+ throw std::runtime_error("Failed to initialize desired SDL_OpenAudio!");
+ }
+
+ frequency = obtainedSpec.freq;
+ numChannels = obtainedSpec.channels;
+ sdlAudioFormat = obtainedSpec.format;
+
+ // Immediately start producing audio.
+ SDL_PauseAudio(0);
+}
+
+Beeper::~Beeper() {
+ SDL_CloseAudio();
+}
+
+template<typename T>
+void Beeper::generateSamples(T *stream, int length) {
+ const int AMPLITUDE = (sizeof(T) == 2) ? 28000 : 120;
+ const int offset = (sdlAudioFormat == AUDIO_U8) ? 120 : 0;
+
+ int i = 0;
+ length /= numChannels;
+ while (i < length) {
+ if (beeps.empty()) {
+ memset(stream + numChannels*i, 0, sizeof(T)*numChannels*(length-i));
+ return;
+ }
+ BeepObject& bo = beeps.front();
+
+ // In Stereo tests, mute one of the channels to be able to distinguish that Stereo output works.
+ if (bo.samplesLeft > tone_duration * frequency / 2 / 1000) {
+ mutedChannel = 1;
+ } else {
+ mutedChannel = 0;
+ }
+
+ int samplesToDo = std::min(i + bo.samplesLeft, length);
+ bo.samplesLeft -= samplesToDo - i;
+
+ while (i < samplesToDo) {
+ for(int j = 0; j < numChannels; ++j) {
+ stream[numChannels*i+j] = (T)(offset + (int)(AMPLITUDE * std::sin(phase * 2 * M_PI / frequency)));
+ if (numChannels > 1 && j == mutedChannel) {
+ stream[numChannels*i+j] = 0;
+ }
+ }
+ phase += bo.toneFrequency;
+ i++;
+ }
+
+ if (bo.samplesLeft == 0) {
+ beeps.pop();
+ }
+ }
+}
+
+void Beeper::beep(double toneFrequency, int durationMSecs) {
+ BeepObject bo;
+ bo.toneFrequency = toneFrequency;
+ bo.samplesLeft = durationMSecs * frequency / 1000;
+
+ SDL_LockAudio();
+ beeps.push(bo);
+ SDL_UnlockAudio();
+}
+
+Beeper *beep = 0;
+
+// Test all kinds of various possible formats. Not all are supported, but running this
+// test will report you which work.
+const int freqs[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000 };
+const int channels[] = { 1, 2 };
+const int sdlAudioFormats[] = { AUDIO_U8, AUDIO_S16LSB /*, AUDIO_S8, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16MSB */ };
+
+const char *SdlAudioFormatToString(int sdlAudioType) {
+ switch(sdlAudioType) {
+ case AUDIO_U8: return "AUDIO_U8";
+ case AUDIO_S8: return "AUDIO_S8";
+ case AUDIO_U16LSB: return "AUDIO_U16LSB";
+ case AUDIO_U16MSB: return "AUDIO_U16MSB";
+ case AUDIO_S16LSB: return "AUDIO_S16LSB";
+ case AUDIO_S16MSB: return "AUDIO_S16MSB";
+ default: return "(unknown)";
+ }
+}
+
+#define NUM_ELEMS(x) (sizeof(x)/sizeof((x)[0]))
+
+// Indices to the currently running test.
+int f = -1;
+int c = 0;
+int s = 0;
+
+void nextTest(void *unused = 0) {
+ ++f;
+ if (f >= NUM_ELEMS(freqs)) {
+ f = 0;
+ ++c;
+ if (c >= NUM_ELEMS(channels)) {
+ c = 0;
+ ++s;
+ if (s >= NUM_ELEMS(sdlAudioFormats)) {
+ printf("All tests done. Quit.\n");
+#ifdef EMSCRIPTEN
+ emscripten_cancel_main_loop();
+#ifdef REPORT_RESULT
+ int result = 1;
+ REPORT_RESULT();
+#endif
+#endif
+ return;
+ }
+ }
+ }
+
+ double Hz = 440;
+ try {
+ beep = new Beeper(freqs[f], channels[c], sdlAudioFormats[s]);
+ } catch(...) {
+ printf("FAILED to play beep for %d msecs at %d Hz tone with audio format %s, %d channels, and %d samples/sec.\n",
+ tone_duration, (int)Hz, SdlAudioFormatToString(sdlAudioFormats[s]), channels[c], freqs[f]);
+ nextTest();
+ return;
+ }
+
+ printf("Playing back a beep for %d msecs at %d Hz tone with audio format %s, %d channels, and %d samples/sec.\n",
+ tone_duration, (int)Hz, SdlAudioFormatToString(sdlAudioFormats[s]), channels[c], freqs[f]);
+ beep->beep(Hz, tone_duration);
+}
+
+void update() {
+ SDL_LockAudio();
+ int size = beep->beeps.size();
+ SDL_UnlockAudio();
+ if (size == 0 && beep) {
+ delete beep;
+ beep = 0;
+#ifdef EMSCRIPTEN
+ emscripten_async_call(nextTest, 0, 1500);
+#else
+ SDL_Delay(1500);
+ nextTest();
+#endif
+ }
+}
+
+void audio_callback(void *_beeper, Uint8 *_stream, int _length) {
+ Beeper* beeper = (Beeper*) _beeper;
+
+ if (beeper->sdlAudioFormat == AUDIO_U8) {
+ Uint8 *stream = (Uint8*) _stream;
+ beeper->generateSamples(stream, _length);
+ } else if (beeper->sdlAudioFormat == AUDIO_S16LSB) {
+ Sint16 *stream = (Sint16*) _stream;
+ int length = _length / 2;
+ beeper->generateSamples(stream, length);
+ } else {
+ assert(false && "Audio sample generation not implemented for current format!\n");
+ }
+}
+
+int main(int argc, char** argv) {
+ SDL_Init(SDL_INIT_AUDIO);
+
+ nextTest();
+
+#ifdef EMSCRIPTEN
+ emscripten_set_main_loop(update, 60, 0);
+#else
+ while(beep) {
+ SDL_Delay(20);
+ update();
+ }
+#endif
+
+ return 0;
+}
diff --git a/tests/sdl_canvas_alpha.c b/tests/sdl_canvas_alpha.c
new file mode 100644
index 00000000..1a41d115
--- /dev/null
+++ b/tests/sdl_canvas_alpha.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+#include <emscripten.h>
+
+
+int main(int argc, char **argv) {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
+
+ printf("Init: %d\n", TTF_Init());
+
+ TTF_Font *font = TTF_OpenFont("sans-serif", 40);
+ printf("Font: %p\n", font);
+
+ SDL_Color color = { 0xff, 0x99, 0x00, 0xff };
+ SDL_Surface *text = TTF_RenderText_Solid(font, "hello orange world", color);
+
+ // render
+ for (int i = 0; i < 255; i++) {
+ SDL_Rect dest = { i, i, 0, 0 };
+ SDL_SetAlpha(text, 0, (((float)i)/255)*(((float)i)/255)*255);
+ SDL_BlitSurface (text, NULL, screen, &dest);
+ }
+
+ SDL_Flip(screen);
+
+ SDL_LockSurface(screen);
+
+ int width, height, isFullscreen;
+ emscripten_get_canvas_size(&width, &height, &isFullscreen);
+
+ if (width != 600 && height != 450)
+ {
+ printf("error: wrong width/height\n");
+ abort();
+ }
+
+ SDL_Quit();
+
+ printf("done.\n");
+
+ return 0;
+}
+
diff --git a/tests/sdl_canvas_alpha.png b/tests/sdl_canvas_alpha.png
new file mode 100644
index 00000000..fb9d6165
--- /dev/null
+++ b/tests/sdl_canvas_alpha.png
Binary files differ
diff --git a/tests/test_browser.py b/tests/test_browser.py
index a3b9a1c3..8d000cd7 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -19,6 +19,7 @@ class browser(BrowserCore):
'test_sdl_audio_mix_channels',
'test_sdl_audio_mix',
'test_sdl_audio_quickload',
+ 'test_sdl_audio_beeps',
'test_openal_playback',
'test_openal_buffers',
'test_freealut'
@@ -649,6 +650,9 @@ window.close = function() {
self.btest('sdl_canvas_proxy.c', reference='sdl_canvas_proxy.png', args=['--proxy-to-worker', '--preload-file', 'data.txt'], manual_reference=True, post_build=post)
+ def test_sdl_canvas_alpha(self):
+ self.btest('sdl_canvas_alpha.c', reference='sdl_canvas_alpha.png')
+
def test_sdl_key(self):
open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('''
Module.postRun = function() {
@@ -923,6 +927,13 @@ keydown(100);keyup(100); // trigger the end
Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play"]']).communicate()
self.run_browser('page.html', '', '/report_result?1')
+ def test_sdl_audio_beeps(self):
+ open(os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_beep.cpp')).read()))
+
+ # use closure to check for a possible bug with closure minifying away newer Audio() attributes
+ Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-o', 'page.html']).communicate()
+ self.run_browser('page.html', '', '/report_result?1')
+
def test_sdl_gl_read(self):
# SDL, OpenGL, readPixels
open(os.path.join(self.get_dir(), 'sdl_gl_read.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_gl_read.c')).read()))
diff --git a/tests/test_core.py b/tests/test_core.py
index 4c17a942..d1d3bab0 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1372,6 +1372,50 @@ Succeeded!
'''
self.do_run(src, '*1,10,10.5,1,1.2340,0.00*\n0.50, 3.30, 3.30, 3.30\nsmall: 0.0000010000\n')
+ def test_zerodiv(self):
+ self.do_run(r'''
+ #include <stdio.h>
+ int main(int argc, const char* argv[])
+ {
+ float f1 = 1.0f;
+ float f2 = 0.0f;
+ float f_zero = 0.0f;
+
+ float f3 = 0.0f / f2;
+ float f4 = f2 / 0.0f;
+ float f5 = f2 / f2;
+ float f6 = f2 / f_zero;
+
+ printf("f3: %f\n", f3);
+ printf("f4: %f\n", f4);
+ printf("f5: %f\n", f5);
+ printf("f6: %f\n", f6);
+
+ return 0;
+ }
+ ''', '''f3: nan
+f4: nan
+f5: nan
+f6: nan
+''')
+
+ def test_zero_multiplication(self):
+ src = '''
+ #include <stdio.h>
+ int main(int argc, char * argv[]) {
+ int one = argc;
+
+ printf("%d ", 0 * one);
+ printf("%d ", 0 * -one);
+ printf("%d ", -one * 0);
+ printf("%g ", 0.0 * one);
+ printf("%g ", 0.0 * -one);
+ printf("%g", -one * 0.0);
+ return 0;
+ }
+ '''
+ self.do_run(src, '0 0 0 0 -0 -0')
+
def test_isnan(self):
src = r'''
#include <stdio.h>
@@ -8937,6 +8981,8 @@ def process(filename):
def test_cases(self):
if Building.LLVM_OPTS: return self.skip("Our code is not exactly 'normal' llvm assembly")
+ emcc_args = self.emcc_args
+
try:
os.environ['EMCC_LEAVE_INPUTS_RAW'] = '1'
Settings.CHECK_OVERFLOWS = 0
@@ -8950,6 +8996,10 @@ def process(filename):
if '_noasm' in shortname and Settings.ASM_JS:
print self.skip('case "%s" not relevant for asm.js' % shortname)
continue
+ self.emcc_args = emcc_args
+ if os.path.exists(shortname + '.emcc'):
+ if not self.emcc_args: continue
+ self.emcc_args = self.emcc_args + json.loads(open(shortname + '.emcc').read())
print >> sys.stderr, "Testing case '%s'..." % shortname
output_file = path_from_root('tests', 'cases', shortname + '.txt')
if Settings.QUANTUM_SIZE == 1:
@@ -8970,6 +9020,7 @@ def process(filename):
finally:
del os.environ['EMCC_LEAVE_INPUTS_RAW']
+ self.emcc_args = emcc_args
def test_fuzz(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
diff --git a/tests/test_other.py b/tests/test_other.py
index 56c13650..9f331439 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -1665,10 +1665,10 @@ f.close()
if multiprocessing.cpu_count() < 2: return self.skip('need multiple cores')
try:
os.environ['EMCC_DEBUG'] = '1'
- os.environ['EMCC_CORES'] = '2'
+ os.environ['EMCC_CORES'] = '2' # standardize over machines
for asm, linkable, chunks, js_chunks in [
- (0, 0, 3, 2), (0, 1, 3, 4),
- (1, 0, 3, 2), (1, 1, 3, 4)
+ (0, 0, 2, 2), (0, 1, 2, 4),
+ (1, 0, 2, 2), (1, 1, 2, 4)
]:
print asm, linkable, chunks, js_chunks
output, err = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp'), '-O1', '-s', 'LINKABLE=%d' % linkable, '-s', 'ASM_JS=%d' % asm] + (['-O2'] if asm else []), stdout=PIPE, stderr=PIPE).communicate()