diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cases/i24_mem_ta2.ll (renamed from tests/cases/i32_mem.ll) | 0 | ||||
-rw-r--r-- | tests/cases/i24_mem_ta2.txt (renamed from tests/cases/i32_mem.txt) | 0 | ||||
-rw-r--r-- | tests/openal_buffers.c | 187 | ||||
-rwxr-xr-x | tests/runner.py | 225 | ||||
-rw-r--r-- | tests/sdl_stb_image.c | 49 | ||||
-rw-r--r-- | tests/sdl_stb_image_data.c | 55 | ||||
-rw-r--r-- | tests/sounds/the_entertainer.wav | bin | 0 -> 264644 bytes |
7 files changed, 484 insertions, 32 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/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/runner.py b/tests/runner.py index 1948ab59..ed4f334c 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]' @@ -12868,6 +13015,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())) @@ -13134,6 +13291,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())) 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 |