aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cases/fp80_ta2.ll21
-rw-r--r--tests/fs/test_idbfs_sync.c48
-rw-r--r--tests/fs/test_nodefs_rw.c49
-rw-r--r--tests/printf/output.txt11
-rw-r--r--tests/printf/output_i64_1.txt11
-rw-r--r--tests/printf/test.c11
-rwxr-xr-xtests/runner.py9
-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.py16
-rw-r--r--tests/test_core.py144
-rw-r--r--tests/test_other.py10
-rw-r--r--tests/test_sanity.py1
-rw-r--r--tests/unistd/access.c17
-rw-r--r--tests/unistd/access.out40
-rw-r--r--tests/unistd/io.c13
-rw-r--r--tests/unistd/links.c21
-rw-r--r--tests/unistd/links.out6
-rw-r--r--tests/unistd/misc.c24
-rw-r--r--tests/unistd/truncate.c23
-rw-r--r--tests/unistd/unlink.c12
22 files changed, 645 insertions, 134 deletions
diff --git a/tests/cases/fp80_ta2.ll b/tests/cases/fp80_ta2.ll
deleted file mode 100644
index 7fc0db4a..00000000
--- a/tests/cases/fp80_ta2.ll
+++ /dev/null
@@ -1,21 +0,0 @@
-; ModuleID = '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, world!\0A\00" ; [#uses=1]
-
-; [#uses=0]
-define i32 @main() {
-entry:
- %x = zext i32 0 to x86_fp80
- %1 = bitcast x86_fp80 %x to i80
- %2 = trunc i80 %1 to i32
- %retval = alloca i32, align 4 ; [#uses=1]
- store i32 0, i32* %retval
- %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0]
- ret i32 0
-}
-
-; [#uses=1]
-declare i32 @printf(i8*, ...)
-
diff --git a/tests/fs/test_idbfs_sync.c b/tests/fs/test_idbfs_sync.c
new file mode 100644
index 00000000..ff356416
--- /dev/null
+++ b/tests/fs/test_idbfs_sync.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <emscripten.h>
+
+#define EM_ASM_REEXPAND(x) EM_ASM(x)
+
+void success() {
+ int result = 1;
+ REPORT_RESULT();
+}
+
+int main() {
+ EM_ASM(
+ FS.mkdir('/working');
+ FS.mount(IDBFS, {}, '/working');
+ );
+
+#if FIRST
+ // store local files to backing IDB
+ EM_ASM_REEXPAND(
+ FS.writeFile('/working/waka.txt', 'az');
+ FS.writeFile('/working/moar.txt', SECRET);
+ FS.syncfs(function (err) {
+ assert(!err);
+
+ ccall('success', 'v', '', []);
+ });
+ );
+#else
+ // load files from backing IDB
+ EM_ASM_REEXPAND(
+ FS.syncfs(true, function (err) {
+ assert(!err);
+
+ var contents = FS.readFile('/working/waka.txt', { encoding: 'utf8' });
+ assert(contents === 'az');
+
+ var secret = FS.readFile('/working/moar.txt', { encoding: 'utf8' });
+ assert(secret === SECRET);
+
+ ccall('success', 'v', '', []);
+ });
+ );
+#endif
+
+ emscripten_exit_with_live_runtime();
+
+ return 0;
+}
diff --git a/tests/fs/test_nodefs_rw.c b/tests/fs/test_nodefs_rw.c
new file mode 100644
index 00000000..140da332
--- /dev/null
+++ b/tests/fs/test_nodefs_rw.c
@@ -0,0 +1,49 @@
+#include <assert.h>
+#include <stdio.h>
+#include <emscripten.h>
+
+int main() {
+ FILE *file;
+ int res;
+ char buffer[512];
+
+ // write something locally with node
+ EM_ASM(
+ var fs = require('fs');
+ fs.writeFileSync('foobar.txt', 'yeehaw');
+ );
+
+ // mount the current folder as a NODEFS instance
+ // inside of emscripten
+ EM_ASM(
+ FS.mkdir('/working');
+ FS.mount(NODEFS, { root: '.' }, '/working');
+ );
+
+ // read and validate the contents of the file
+ file = fopen("/working/foobar.txt", "r");
+ assert(file);
+ res = fread(buffer, sizeof(char), 6, file);
+ assert(res == 6);
+ fclose(file);
+
+ assert(!strcmp(buffer, "yeehaw"));
+
+ // write out something new
+ file = fopen("/working/foobar.txt", "w");
+ assert(file);
+ res = fwrite("cheez", sizeof(char), 5, file);
+ assert(res == 5);
+ fclose(file);
+
+ // validate the changes were persisted to the underlying fs
+ EM_ASM(
+ var fs = require('fs');
+ var contents = fs.readFileSync('foobar.txt', { encoding: 'utf8' });
+ assert(contents === 'cheez');
+ );
+
+ puts("success");
+
+ return 0;
+}
diff --git a/tests/printf/output.txt b/tests/printf/output.txt
index 19a6c1c2..0155f0da 100644
--- a/tests/printf/output.txt
+++ b/tests/printf/output.txt
@@ -3,10 +3,15 @@ n=7
Characters: a A
Decimals: 1977 650000 12 4
-Preceding with blanks: 1977
-Preceding with zeros: 0000001977
+Preceding with blanks: 1977 -1977
+Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
+Force sign or space: 1977 -1977 1977 -1977
+Sign overrides space: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
-floats: 3.14 +3e+00 3.141600E+00
+floats: 3.14 +3e+00 3.141600E+00 00003.14
+negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
+Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
diff --git a/tests/printf/output_i64_1.txt b/tests/printf/output_i64_1.txt
index 775f3f8d..e38fb78f 100644
--- a/tests/printf/output_i64_1.txt
+++ b/tests/printf/output_i64_1.txt
@@ -3,10 +3,15 @@ n=7
Characters: a A
Decimals: 1977 650000 12 4
-Preceding with blanks: 1977
-Preceding with zeros: 0000001977
+Preceding with blanks: 1977 -1977
+Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
+Force sign or space: 1977 -1977 1977 -1977
+Sign overrides space: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
-floats: 3.14 +3e+00 3.141600E+00
+floats: 3.14 +3e+00 3.141600E+00 00003.14
+negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
+Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
diff --git a/tests/printf/test.c b/tests/printf/test.c
index d05ba096..1c8ad9f7 100644
--- a/tests/printf/test.c
+++ b/tests/printf/test.c
@@ -8,10 +8,15 @@ int main() {
printf("\n");
printf("Characters: %c %c\n", 'a', 65);
printf("Decimals: %d %ld %lld %d\n", 1977, 650000L, 12LL, 4);
- printf("Preceding with blanks: %10d\n", 1977);
- printf("Preceding with zeros: %010d\n", 1977);
+ printf("Preceding with blanks: %10d %10d\n", 1977, -1977);
+ printf("Preceding with zeros: %010d %010d\n", 1977, -1977);
+ printf("Force sign: %+d %+d %+6d %+6d\n", 1977, -1977, 1977, -1977);
+ printf("Force sign or space: % d % d % 6d % 6d\n", 1977, -1977, 1977, -1977);
+ printf("Sign overrides space: % +d % +d % +6d % +6d\n", 1977, -1977, 1977, -1977);
printf("Some different radixes: %d %x %o %#x %#o\n", 100, 100, 100, 100, 100);
- printf("floats: %4.2f %+.0e %E\n", 3.1416, 3.1416, 3.1416);
+ printf("floats: %4.2f %+.0e %E %08.2f\n", 3.1416, 3.1416, 3.1416, 3.1416);
+ printf("negative floats: %4.2f %+.0e %E %08.2f\n", -3.1416, -3.1416, -3.1416, -3.1416);
+ printf("Force sign or space: % .2f % .2f % 6.2f % 6.2f\n", 3.1416, -3.1416, 3.1416, -3.1416);
printf("Width trick: %*d\n", 5, 10);
printf("%s %%\n", "A string");
printf("Null string: %7s\n", NULL);
diff --git a/tests/runner.py b/tests/runner.py
index ddc97ea4..867f7113 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -737,13 +737,15 @@ if __name__ == '__main__':
print '''
==============================================================================
Running the main part of the test suite. Don't forget to run the other parts!
+A recommended order is:
- other - tests separate from the main suite
sanity - tests for first run, etc., modifies ~/.emscripten
- benchmark - run before and after each set of changes before pushing to
- master, verify no regressions
+ (the main test suite)
+ other - tests separate from the main suite
browser - runs pages in a web browser
sockets - runs websocket networking tests
+ benchmark - run before and after each set of changes before pushing to
+ master, verify no regressions
There are also commands to run specific subsets of the test suite:
@@ -799,3 +801,4 @@ an individual test with
# Return the number of failures as the process exit code for automating success/failure reporting.
exit(numFailures)
+
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..799759a1 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -19,6 +19,7 @@ class browser(BrowserCore):
'test_sdl_audio_mix_channels',
'test_sdl_audio_mix',
'test_sdl_audio_quickload',
+ 'test_sdl_audio_beeps',
'test_openal_playback',
'test_openal_buffers',
'test_freealut'
@@ -649,6 +650,9 @@ window.close = function() {
self.btest('sdl_canvas_proxy.c', reference='sdl_canvas_proxy.png', args=['--proxy-to-worker', '--preload-file', 'data.txt'], manual_reference=True, post_build=post)
+ def test_sdl_canvas_alpha(self):
+ self.btest('sdl_canvas_alpha.c', reference='sdl_canvas_alpha.png', reference_slack=1)
+
def test_sdl_key(self):
open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('''
Module.postRun = function() {
@@ -876,6 +880,11 @@ keydown(100);keyup(100); // trigger the end
self.btest('file_db.cpp', secret, args=['--preload-file', 'moar.txt']) # even with a file there, we load over it
shutil.move('test.html', 'third.html')
+ def test_fs_idbfs_sync(self):
+ secret = str(time.time())
+ self.btest(path_from_root('tests', 'fs', 'test_idbfs_sync.c'), '1', force_c=True, args=['-DFIRST', '-DSECRET=\'' + secret + '\'', '-s', '''EXPORTED_FUNCTIONS=['_main', '_success']'''])
+ self.btest(path_from_root('tests', 'fs', 'test_idbfs_sync.c'), '1', force_c=True, args=['-DSECRET=\'' + secret + '\'', '-s', '''EXPORTED_FUNCTIONS=['_main', '_success']'''])
+
def test_sdl_pumpevents(self):
# key events should be detected using SDL_PumpEvents
open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('''
@@ -923,6 +932,13 @@ keydown(100);keyup(100); // trigger the end
Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play"]']).communicate()
self.run_browser('page.html', '', '/report_result?1')
+ def test_sdl_audio_beeps(self):
+ open(os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_beep.cpp')).read()))
+
+ # use closure to check for a possible bug with closure minifying away newer Audio() attributes
+ Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_beep.cpp'), '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-o', 'page.html']).communicate()
+ self.run_browser('page.html', '', '/report_result?1')
+
def test_sdl_gl_read(self):
# SDL, OpenGL, readPixels
open(os.path.join(self.get_dir(), 'sdl_gl_read.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_gl_read.c')).read()))
diff --git a/tests/test_core.py b/tests/test_core.py
index 991f43a9..c1bfce6f 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1372,6 +1372,50 @@ Succeeded!
'''
self.do_run(src, '*1,10,10.5,1,1.2340,0.00*\n0.50, 3.30, 3.30, 3.30\nsmall: 0.0000010000\n')
+ def test_zerodiv(self):
+ self.do_run(r'''
+ #include <stdio.h>
+ int main(int argc, const char* argv[])
+ {
+ float f1 = 1.0f;
+ float f2 = 0.0f;
+ float f_zero = 0.0f;
+
+ float f3 = 0.0f / f2;
+ float f4 = f2 / 0.0f;
+ float f5 = f2 / f2;
+ float f6 = f2 / f_zero;
+
+ printf("f3: %f\n", f3);
+ printf("f4: %f\n", f4);
+ printf("f5: %f\n", f5);
+ printf("f6: %f\n", f6);
+
+ return 0;
+ }
+ ''', '''f3: nan
+f4: nan
+f5: nan
+f6: nan
+''')
+
+ def test_zero_multiplication(self):
+ src = '''
+ #include <stdio.h>
+ int main(int argc, char * argv[]) {
+ int one = argc;
+
+ printf("%d ", 0 * one);
+ printf("%d ", 0 * -one);
+ printf("%d ", -one * 0);
+ printf("%g ", 0.0 * one);
+ printf("%g ", 0.0 * -one);
+ printf("%g", -one * 0.0);
+ return 0;
+ }
+ '''
+ self.do_run(src, '0 0 0 0 -0 -0')
+
def test_isnan(self):
src = r'''
#include <stdio.h>
@@ -1744,7 +1788,7 @@ Succeeded!
int xx, yy, zz;
char s[32];
- int cc = sscanf("abc_10.b1_xyz_543_defg", "abc_%d.%2x_xyz_%3d_%3s", &xx, &yy, &zz, s);
+ int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s);
printf("%d:%d,%d,%d,%s\\n", cc, xx, yy, zz, s);
printf("%d\\n", argc);
@@ -3797,25 +3841,26 @@ def process(filename):
self.do_run(src, '4\n200\ndone\n')
def test_inlinejs3(self):
- if Settings.ASM_JS: return self.skip('asm does not support random code, TODO: something that works in asm')
- src = r'''
- #include <stdio.h>
- #include <emscripten.h>
+ src = r'''
+ #include <stdio.h>
+ #include <emscripten.h>
- int main() {
- EM_ASM(Module.print('hello dere1'));
- EM_ASM(
- Module.print('hello dere2');
- );
+ int main() {
+ EM_ASM(Module.print('hello dere1'));
+ EM_ASM(
+ Module.print('hello dere2');
+ );
+ for (int i = 0; i < 3; i++) {
EM_ASM(
Module.print('hello dere3');
Module.print('hello dere' + 4);
);
- return 0;
}
- '''
+ return 0;
+ }
+ '''
- self.do_run(src, 'hello dere1\nhello dere2\nhello dere3\nhello dere4\n')
+ self.do_run(src, 'hello dere1\nhello dere2\nhello dere3\nhello dere4\nhello dere3\nhello dere4\nhello dere3\nhello dere4\n')
def test_memorygrowth(self):
if Settings.USE_TYPED_ARRAYS == 0: return self.skip('memory growth is only supported with typed arrays')
@@ -7222,6 +7267,7 @@ date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3
if self.emcc_args is not None and '-O2' in self.emcc_args:
self.emcc_args += ['--closure', '1'] # Use closure here, to test we don't break FS stuff
self.emcc_args = filter(lambda x: x != '-g', self.emcc_args) # ensure we test --closure 1 --memory-init-file 1 (-g would disable closure)
+ self.emcc_args += ["-s", "CHECK_HEAP_ALIGN=0"] # disable heap align check here, it mixes poorly with closure
Settings.CORRECT_SIGNS = 1 # Just so our output is what we expect. Can flip them both.
post = '''
@@ -7698,15 +7744,21 @@ def process(filename):
finally:
Settings.INCLUDE_FULL_LIBRARY = 0
+ def test_fs_nodefs_rw(self):
+ if self.emcc_args is None: return self.skip('requires emcc')
+ if not self.is_le32(): return self.skip('le32 needed for inline js')
+ src = open(path_from_root('tests', 'fs', 'test_nodefs_rw.c'), 'r').read()
+ self.do_run(src, 'success', force_c=True, js_engines=[NODE_JS])
+
def test_unistd_access(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
- src = open(path_from_root('tests', 'unistd', 'access.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'access.out'), 'r').read()
- self.do_run(src, expected)
+ for fs in ['MEMFS', 'NODEFS']:
+ src = open(path_from_root('tests', 'unistd', 'access.c'), 'r').read()
+ expected = open(path_from_root('tests', 'unistd', 'access.out'), 'r').read()
+ Building.COMPILER_TEST_OPTS += ['-D' + fs]
+ self.do_run(src, expected, js_engines=[NODE_JS])
def test_unistd_curdir(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
src = open(path_from_root('tests', 'unistd', 'curdir.c'), 'r').read()
expected = open(path_from_root('tests', 'unistd', 'curdir.out'), 'r').read()
@@ -7737,11 +7789,12 @@ def process(filename):
self.do_run(src, expected)
def test_unistd_truncate(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
- src = open(path_from_root('tests', 'unistd', 'truncate.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'truncate.out'), 'r').read()
- self.do_run(src, expected)
+ for fs in ['MEMFS', 'NODEFS']:
+ src = open(path_from_root('tests', 'unistd', 'truncate.c'), 'r').read()
+ expected = open(path_from_root('tests', 'unistd', 'truncate.out'), 'r').read()
+ Building.COMPILER_TEST_OPTS += ['-D' + fs]
+ self.do_run(src, expected, js_engines=[NODE_JS])
def test_unistd_swab(self):
src = open(path_from_root('tests', 'unistd', 'swab.c'), 'r').read()
@@ -7763,15 +7816,20 @@ def process(filename):
self.do_run(src, expected)
def test_unistd_unlink(self):
- src = open(path_from_root('tests', 'unistd', 'unlink.c'), 'r').read()
- self.do_run(src, 'success', force_c=True)
+ if self.emcc_args is None: return self.skip('requires emcc')
+ if not self.is_le32(): return self.skip('le32 needed for inline js')
+ for fs in ['MEMFS', 'NODEFS']:
+ src = open(path_from_root('tests', 'unistd', 'unlink.c'), 'r').read()
+ Building.COMPILER_TEST_OPTS += ['-D' + fs]
+ self.do_run(src, 'success', force_c=True, js_engines=[NODE_JS])
def test_unistd_links(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
- src = open(path_from_root('tests', 'unistd', 'links.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'links.out'), 'r').read()
- self.do_run(src, expected)
+ for fs in ['MEMFS', 'NODEFS']:
+ src = open(path_from_root('tests', 'unistd', 'links.c'), 'r').read()
+ expected = open(path_from_root('tests', 'unistd', 'links.out'), 'r').read()
+ Building.COMPILER_TEST_OPTS += ['-D' + fs]
+ self.do_run(src, expected, js_engines=[NODE_JS])
def test_unistd_sleep(self):
src = open(path_from_root('tests', 'unistd', 'sleep.c'), 'r').read()
@@ -7779,17 +7837,23 @@ def process(filename):
self.do_run(src, expected)
def test_unistd_io(self):
- if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code
if not self.is_le32(): return self.skip('le32 needed for inline js')
if self.run_name == 'o2': return self.skip('non-asm optimized builds can fail with inline js')
- src = open(path_from_root('tests', 'unistd', 'io.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'io.out'), 'r').read()
- self.do_run(src, expected)
+ if self.emcc_args is None: return self.skip('requires emcc')
+ for fs in ['MEMFS', 'NODEFS']:
+ src = open(path_from_root('tests', 'unistd', 'io.c'), 'r').read()
+ expected = open(path_from_root('tests', 'unistd', 'io.out'), 'r').read()
+ Building.COMPILER_TEST_OPTS += ['-D' + fs]
+ self.do_run(src, expected, js_engines=[NODE_JS])
def test_unistd_misc(self):
- src = open(path_from_root('tests', 'unistd', 'misc.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'misc.out'), 'r').read()
- self.do_run(src, expected)
+ if self.emcc_args is None: return self.skip('requires emcc')
+ if not self.is_le32(): return self.skip('le32 needed for inline js')
+ for fs in ['MEMFS', 'NODEFS']:
+ src = open(path_from_root('tests', 'unistd', 'misc.c'), 'r').read()
+ expected = open(path_from_root('tests', 'unistd', 'misc.out'), 'r').read()
+ Building.COMPILER_TEST_OPTS += ['-D' + fs]
+ self.do_run(src, expected, js_engines=[NODE_JS])
def test_uname(self):
src = r'''
@@ -8542,6 +8606,12 @@ void*:16
assert ' & 255]()' not in original, 'big function table does not exist'
assert ' & 255]()' in final, 'big function table exists'
+ assert 'asm1' in test_modes
+ if self.run_name == 'asm1':
+ assert not Settings.RELOOP
+ Settings.RELOOP = 1 # check for mixing of relooping with asm1
+ self.do_run(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
+
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this
@@ -10450,9 +10520,9 @@ o1 = make_run("o1", compiler=CLANG, emcc_args=["-O1", "-s", "ASM_JS=0", "-s", "S
o2 = make_run("o2", compiler=CLANG, emcc_args=["-O2", "-s", "ASM_JS=0", "-s", "JS_CHUNK_SIZE=1024"])
# asm.js
-asm1 = make_run("asm1", compiler=CLANG, emcc_args=["-O1", "-s", "CHECK_HEAP_ALIGN=1"])
+asm1 = make_run("asm1", compiler=CLANG, emcc_args=["-O1"])
asm2 = make_run("asm2", compiler=CLANG, emcc_args=["-O2"])
-asm2g = make_run("asm2g", compiler=CLANG, emcc_args=["-O2", "-g", "-s", "ASSERTIONS=1", "--memory-init-file", "1"])
+asm2g = make_run("asm2g", compiler=CLANG, emcc_args=["-O2", "-g", "-s", "ASSERTIONS=1", "--memory-init-file", "1", "-s", "CHECK_HEAP_ALIGN=1"])
asm2x86 = make_run("asm2x86", compiler=CLANG, emcc_args=["-O2", "-g", "-s", "CHECK_HEAP_ALIGN=1"], env={"EMCC_LLVM_TARGET": "i386-pc-linux-gnu"})
# Make custom runs with various options
diff --git a/tests/test_other.py b/tests/test_other.py
index 9f331439..afad1927 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -175,7 +175,7 @@ Options that are modified or new in %s include:
if opt_level >= 2 and '-g' in params:
assert re.search('HEAP8\[\$?\w+ ?\+ ?\(+\$?\w+ ?', generated) or re.search('HEAP8\[HEAP32\[', generated), 'eliminator should create compound expressions, and fewer one-time vars' # also in -O1, but easier to test in -O2
assert ('_puts(' in generated) == (opt_level >= 1), 'with opt >= 1, llvm opts are run and they should optimize printf to puts'
- if opt_level == 0 or '-g' in params: assert 'function _main() {' in generated, 'Should be unminified, including whitespace'
+ if opt_level == 0 or '-g' in params: assert 'function _main() {' in generated or 'function _main(){' in generated, 'Should be unminified'
elif opt_level >= 2: assert ('function _main(){' in generated or '"use asm";var a=' in generated), 'Should be whitespace-minified'
# emcc -s RELOOP=1 src.cpp ==> should pass -s to emscripten.py. --typed-arrays is a convenient alias for -s USE_TYPED_ARRAYS
@@ -807,10 +807,10 @@ f.close()
0: (1500, 5000)
}),
(['-O2'], {
- 100: (0, 1500),
- 250: (0, 1500),
- 500: (0, 1500),
- 1000: (0, 1500),
+ 100: (0, 1600),
+ 250: (0, 1600),
+ 500: (0, 1600),
+ 1000: (0, 1600),
2000: (0, 2000),
5000: (0, 5000),
0: (0, 5000)
diff --git a/tests/test_sanity.py b/tests/test_sanity.py
index 6fdf5ddd..aa3f1242 100644
--- a/tests/test_sanity.py
+++ b/tests/test_sanity.py
@@ -342,7 +342,6 @@ fi
assert INCLUDING_MESSAGE.replace('X', 'libc') not in output
assert BUILDING_MESSAGE.replace('X', 'libc') not in output
self.assertContained('hello, world!', run_js('a.out.js'))</