diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cases/invokeundef.ll | 41 | ||||
-rw-r--r-- | tests/cases/longjmp_tiny_noasm_invoke.ll | 71 | ||||
-rw-r--r-- | tests/cases/longjmp_tiny_noasm_invoke.txt | 2 | ||||
-rwxr-xr-x | tests/fuzz/csmith_driver.py | 13 | ||||
-rw-r--r-- | tests/hello_libcxx_mod2.cpp | 10 | ||||
-rw-r--r-- | tests/hello_libcxx_mod2a.cpp | 11 | ||||
-rwxr-xr-x | tests/runner.py | 50 | ||||
-rw-r--r-- | tests/sdl_audio.c | 20 |
8 files changed, 207 insertions, 11 deletions
diff --git a/tests/cases/invokeundef.ll b/tests/cases/invokeundef.ll new file mode 100644 index 00000000..9dc1f93d --- /dev/null +++ b/tests/cases/invokeundef.ll @@ -0,0 +1,41 @@ +; ModuleID = '/dev/shm/tmp/src.cpp.o' +; Just test for compilation here +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-f128:128:128-n8:16:32" +target triple = "i386-pc-linux-gnu" + +%struct.CPU_Regs = type { [8 x %union.GenReg32] } +%union.GenReg32 = type { [1 x i32] } + +@cpu_regs = unnamed_addr global %struct.CPU_Regs zeroinitializer, align 32 ; [#uses=2] +@.str = private unnamed_addr constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1] + +; [#uses=0] +define i32 @main() { +entry: + %retval = alloca i32 ; [#uses=2] + %0 = alloca i32 ; [#uses=2] + %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] + %1 = load i32* bitcast (i32* getelementptr inbounds (%struct.CPU_Regs* @cpu_regs, i32 0, i32 0, i32 1, i32 0, i32 0) to i32*), align 2 ; [#uses=1] + store i16 %1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 + %2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + store i32 0, i32* %0, align 4 + %3 = load i32* %0, align 4 ; [#uses=1] + store i32 %3, i32* %retval, align 4 + br label %return + + invoke void undef(%struct.CPU_Regs* noalias @cpu_regs, i32 %99) + to label %invcont33 unwind label %lpad106 + +invcont33: + ret i32 %retval1 + +lpad106: + ret i32 %retval1 + +return: ; preds = %entry + %retval1 = load i32* %retval ; [#uses=1] + ret i32 %retval1 +} + +; [#uses=1] +declare i32 @puts(i8*) diff --git a/tests/cases/longjmp_tiny_noasm_invoke.ll b/tests/cases/longjmp_tiny_noasm_invoke.ll new file mode 100644 index 00000000..e1a72e00 --- /dev/null +++ b/tests/cases/longjmp_tiny_noasm_invoke.ll @@ -0,0 +1,71 @@ +; ModuleID = '/tmp/emscripten_temp/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-S128" +target triple = "i386-pc-linux-gnu" + +@_ZL3buf = internal global [20 x i16] zeroinitializer, align 2 +@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00", align 1 +@.str1 = private unnamed_addr constant [6 x i8] c"more\0A\00", align 1 + +define i32 @main() { + %retval = alloca i32, align 4 + store i32 0, i32* %retval + %call = invoke i32 @setjmp(i16* getelementptr inbounds ([20 x i16]* @_ZL3buf, i32 0, i32 0)) returns_twice, !dbg !20 + to label %allgood unwind label %awful + +allgood: + %tobool = icmp ne i32 %call, 0, !dbg !20 + br i1 %tobool, label %if.else, label %if.then, !dbg !20 + +if.then: ; preds = %entry + %call1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0)), !dbg !22 + call void @longjmp(i16* getelementptr inbounds ([20 x i16]* @_ZL3buf, i32 0, i32 0), i32 10), !dbg !24 + br label %if.end, !dbg !25 + +if.else: ; preds = %entry + %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0)), !dbg !26 + br label %if.end + +if.end: ; preds = %if.else, %if.then + ret i32 0, !dbg !28 + +awful: + ret i32 1 +} + +declare i32 @setjmp(i16*) returns_twice + +declare i32 @printf(i8*, ...) + +declare void @longjmp(i16*, i32) + +!llvm.dbg.cu = !{!0} + +!0 = metadata !{i32 786449, i32 0, i32 4, metadata !"/tmp/emscripten_temp/src.cpp", metadata !"/home/alon/Dev/emscripten", metadata !"clang version 3.1 (trunk 150936)", i1 true, i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !3, metadata !12} ; [ DW_TAG_compile_unit ] +!1 = metadata !{metadata !2} +!2 = metadata !{i32 0} +!3 = metadata !{metadata !4} +!4 = metadata !{metadata !5} +!5 = metadata !{i32 786478, i32 0, metadata !6, metadata !"main", metadata !"main", metadata !"", metadata !6, i32 7, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !10} ; [ DW_TAG_subprogram ] +!6 = metadata !{i32 786473, metadata !"/tmp/emscripten_temp/src.cpp", metadata !"/home/alon/Dev/emscripten", null} ; [ DW_TAG_file_type ] +!7 = metadata !{i32 786453, i32 0, metadata !"", i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] +!8 = metadata !{metadata !9} +!9 = metadata !{i32 786468, null, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] +!10 = metadata !{metadata !11} +!11 = metadata !{i32 786468} ; [ DW_TAG_base_type ] +!12 = metadata !{metadata !13} +!13 = metadata !{metadata !14} +!14 = metadata !{i32 786484, i32 0, null, metadata !"buf", metadata !"buf", metadata !"_ZL3buf", metadata !6, i32 5, metadata !15, i32 1, i32 1, [20 x i16]* @_ZL3buf} ; [ DW_TAG_variable ] +!15 = metadata !{i32 786454, null, metadata !"jmp_buf", metadata !6, i32 279, i64 0, i64 0, i64 0, i32 0, metadata !16} ; [ DW_TAG_typedef ] +!16 = metadata !{i32 786433, null, metadata !"", null, i32 0, i64 320, i64 16, i32 0, i32 0, metadata !17, metadata !18, i32 0, i32 0} ; [ DW_TAG_array_type ] +!17 = metadata !{i32 786468, null, metadata !"unsigned short", null, i32 0, i64 16, i64 16, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ] +!18 = metadata !{metadata !19} +!19 = metadata !{i32 786465, i64 0, i64 19} ; [ DW_TAG_subrange_type ] +!20 = metadata !{i32 8, i32 18, metadata !21, null} +!21 = metadata !{i32 786443, metadata !5, i32 7, i32 22, metadata !6, i32 0} ; [ DW_TAG_lexical_block ] +!22 = metadata !{i32 9, i32 15, metadata !23, null} +!23 = metadata !{i32 786443, metadata !21, i32 8, i32 31, metadata !6, i32 1} ; [ DW_TAG_lexical_block ] +!24 = metadata !{i32 10, i32 15, metadata !23, null} +!25 = metadata !{i32 11, i32 13, metadata !23, null} +!26 = metadata !{i32 12, i32 15, metadata !27, null} +!27 = metadata !{i32 786443, metadata !21, i32 11, i32 20, metadata !6, i32 2} ; [ DW_TAG_lexical_block ] +!28 = metadata !{i32 14, i32 13, metadata !21, null} diff --git a/tests/cases/longjmp_tiny_noasm_invoke.txt b/tests/cases/longjmp_tiny_noasm_invoke.txt new file mode 100644 index 00000000..8a0aa386 --- /dev/null +++ b/tests/cases/longjmp_tiny_noasm_invoke.txt @@ -0,0 +1,2 @@ +hello world +more diff --git a/tests/fuzz/csmith_driver.py b/tests/fuzz/csmith_driver.py index 3fa58db6..5bdef009 100755 --- a/tests/fuzz/csmith_driver.py +++ b/tests/fuzz/csmith_driver.py @@ -30,13 +30,15 @@ fails = 0 while 1: print 'Tried %d, notes: %s' % (tried, notes) - tried += 1 print '1) Generate C' shared.execute([CSMITH, '--no-volatiles', '--no-math64', '--no-packed-struct'],# + #['--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'], stdout=open(filename + '.c', 'w')) + #shutil.copyfile(filename + '.c', 'testcase%d.c' % tried) print '1) Generate C... %.2f K of C source' % (len(open(filename + '.c').read())/1024.) + tried += 1 + print '2) Compile natively' shared.try_delete(filename) shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename + '1'] + CSMITH_CFLAGS, stderr=PIPE) # + shared.EMSDK_OPTS @@ -46,11 +48,11 @@ while 1: shared.execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS, stderr=PIPE) print '3) Run natively' try: - correct1 = shared.timeout_run(Popen([filename + '1'], stdout=PIPE, stderr=PIPE), 5) + correct1 = shared.jsrun.timeout_run(Popen([filename + '1'], stdout=PIPE, stderr=PIPE), 3) if 'Segmentation fault' in correct1 or len(correct1) < 10: raise Exception('segfault') - correct2 = shared.timeout_run(Popen([filename + '2'], stdout=PIPE, stderr=PIPE), 5) + correct2 = shared.jsrun.timeout_run(Popen([filename + '2'], stdout=PIPE, stderr=PIPE), 3) if 'Segmentation fault' in correct2 or len(correct2) < 10: raise Exception('segfault') - correct3 = shared.timeout_run(Popen([filename + '3'], stdout=PIPE, stderr=PIPE), 5) + correct3 = shared.jsrun.timeout_run(Popen([filename + '3'], stdout=PIPE, stderr=PIPE), 3) if 'Segmentation fault' in correct3 or len(correct3) < 10: raise Exception('segfault') if correct1 != correct3: raise Exception('clang opts change result') except Exception, e: @@ -82,6 +84,9 @@ while 1: except Exception, e: print e normal = False + #open('testcase%d.js' % tried, 'w').write( + # open(filename + '.js').read().replace(' var ret = run();', ' var ret = run(["1"]);') + #) if not ok: print "EMSCRIPTEN BUG" notes['embug'] += 1 diff --git a/tests/hello_libcxx_mod2.cpp b/tests/hello_libcxx_mod2.cpp new file mode 100644 index 00000000..b18a523a --- /dev/null +++ b/tests/hello_libcxx_mod2.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include <emscripten.h> + +int main() +{ + std::cout << "hello, world!" << std::endl; + emscripten_jcache_printf("waka %d waka\n", 5); + return 0; +} + diff --git a/tests/hello_libcxx_mod2a.cpp b/tests/hello_libcxx_mod2a.cpp new file mode 100644 index 00000000..f48ad4fe --- /dev/null +++ b/tests/hello_libcxx_mod2a.cpp @@ -0,0 +1,11 @@ +#include <iostream> +#include <emscripten.h> + +int main() +{ + std::cout << "hello, world!" << std::endl; + emscripten_jcache_printf("waka %d waka\n", 5); + emscripten_jcache_printf("yet another printf %.2f %d\n", 5.5, 66); + return 0; +} + diff --git a/tests/runner.py b/tests/runner.py index 2515ef33..9ca052c7 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1054,6 +1054,19 @@ m_divisor is 1091269979 } ''', 'c = 4ca38a6bd2973f97') + def test_i64_llabs(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2') + Settings.PRECISE_I64_MATH = 2 + self.do_run(r''' + #include <stdio.h> + #include <stdlib.h> + + int main(int argc, char ** argv) { + printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489)); + return 0; + } + ''', '576460752303423489,576460752303423489') + def test_i64_zextneg(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2') @@ -3811,6 +3824,8 @@ The current type of b is: 9 ''') def test_structbyval(self): + Settings.INLINING_LIMIT = 50 + # part 1: make sure that normally, passing structs by value works src = r''' @@ -5086,7 +5101,7 @@ at function.:blag ''' self.do_run(src, '22 : me and myself 25 1.34\n21 waka 95\n') - def test_perror(self): + def test_perrar(self): src = r''' #include <sys/types.h> #include <sys/stat.h> @@ -8508,6 +8523,7 @@ Options that are modified or new in %s include: (['-o', 'something.js', '-O2'], 2, None, 0, 1), (['-o', 'something.js', '-O2', '--closure', '0'], 2, None, 0, 0), (['-o', 'something.js', '-O2', '-g'], 2, None, 0, 0), + (['-o', 'something.js', '-Os'], 2, None, 0, 1), (['-o', 'something.js', '-O3'], 3, None, 1, 1), (['-o', 'something.js', '-O3', '--closure', '0'], 3, None, 0, 0), # and, test compiling to bitcode first @@ -8559,6 +8575,7 @@ Options that are modified or new in %s include: (['-s', 'ASM_JS=1', '-O2', '-g'], lambda generated: 'var i1 = 0' not in generated, 'registerize is cancelled by -g'), (['-s', 'INLINING_LIMIT=0'], lambda generated: 'function _dump' in generated, 'no inlining without opts'), (['-O3', '-s', 'INLINING_LIMIT=0', '--closure', '0'], lambda generated: 'function _dump' not in generated, 'lto/inlining'), + (['-Os', '--llvm-lto', '1'], lambda generated: 'function _dump' in generated, '-Os disables inlining'), (['-s', 'USE_TYPED_ARRAYS=0'], lambda generated: 'new Int32Array' not in generated, 'disable typed arrays'), (['-s', 'USE_TYPED_ARRAYS=1'], lambda generated: 'IHEAPU = ' in generated, 'typed arrays 1 selected'), ([], lambda generated: 'Module["_dump"]' not in generated, 'dump is not exported by default'), @@ -9749,6 +9766,23 @@ seeked= file. if optimize_normally: del os.environ['EMCC_OPTIMIZE_NORMALLY'] del os.environ['EMCC_DEBUG'] + def test_jcache_printf(self): + open(self.in_dir('src.cpp'), 'w').write(r''' + #include <stdio.h> + #include <stdint.h> + #include <emscripten.h> + int main() { + emscripten_jcache_printf("hello world\n"); + emscripten_jcache_printf("hello %d world\n", 5); + emscripten_jcache_printf("hello %.3f world\n", 123.456789123); + emscripten_jcache_printf("hello %llx world\n", 0x1234567811223344ULL); + return 0; + } + ''') + Popen([PYTHON, EMCC, self.in_dir('src.cpp')]).communicate() + output = run_js('a.out.js') + self.assertIdentical('hello world\nhello 5 world\nhello 123.457 world\nhello 1234567811223300 world\n', output) + def test_conftest_s_flag_passing(self): open(os.path.join(self.get_dir(), 'conftest.c'), 'w').write(r''' int main() { @@ -11263,7 +11297,7 @@ elif 'benchmark' in str(sys.argv): try_delete(final_filename) output = Popen([PYTHON, EMCC, filename, #'-O3', '-O2', '-s', 'INLINING_LIMIT=0', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0',# '-s', 'EXPLICIT_ZEXT=1', - '-s', 'ASM_JS=1', '-s', 'USE_MATH_IMUL=1', + '-s', 'ASM_JS=1', '-s', 'USE_MATH_IMUL=1', '--llvm-lto', '1', '-s', 'TOTAL_MEMORY=128*1024*1024', '-s', 'FAST_MEMORY=10*1024*1024', '-o', final_filename] + shared_args + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate() assert os.path.exists(final_filename), 'Failed to compile file: ' + output[0] @@ -11924,6 +11958,8 @@ fi try_delete(CANONICAL_TEMP_DIR) def test_relooper(self): + RELOOPER = Cache.get_path('relooper.js') + restore() for phase in range(2): # 0: we wipe the relooper dir. 1: we have it, so should just update if phase == 0: Cache.erase() @@ -11992,9 +12028,17 @@ fi # finally, build a file close to the previous, to see that some chunks are found in the cache and some not (['--jcache'], 'hello_libcxx_mod1.cpp', False, True, True, True, True, True, []), # win on pre, mix on funcs, mix on jsfuncs (['--jcache'], 'hello_libcxx_mod1.cpp', False, True, False, True, False, True, []), + (None, None, None, None, None, None, None, None, None), # clear + (['--jcache'], 'hello_libcxx_mod2.cpp', True, False, True, False, True, False, []), # load into cache + (['--jcache'], 'hello_libcxx_mod2a.cpp', False, True, True, True, True, True, []) # add a printf, do not lose everything ]: - print >> sys.stderr, args, input_file, expect_pre_save, expect_pre_load, expect_funcs_save, expect_funcs_load, expect_jsfuncs_save, expect_jsfuncs_load, expected self.clear() + if args is None: + Cache.erase() + continue + + print >> sys.stderr, args, input_file, expect_pre_save, expect_pre_load, expect_funcs_save, expect_funcs_load, expect_jsfuncs_save, expect_jsfuncs_load, expected + out, err = Popen([PYTHON, EMCC, '-O2', path_from_root('tests', input_file)] + args, stdout=PIPE, stderr=PIPE).communicate() errtail = err.split('emcc invocation')[-1] self.assertContained('hello, world!', run_js('a.out.js'), errtail) diff --git a/tests/sdl_audio.c b/tests/sdl_audio.c index 938df3c4..ce3bf5a9 100644 --- a/tests/sdl_audio.c +++ b/tests/sdl_audio.c @@ -6,13 +6,14 @@ Mix_Chunk *sound, *sound2; -void play2(); +int play2(); -void play() { +int play() { int channel = Mix_PlayChannel(-1, sound, 1); assert(channel == 0); emscripten_run_script("setTimeout(Module['_play2'], 500)"); + return channel; } void done(int channel) { @@ -22,11 +23,12 @@ void done(int channel) { REPORT_RESULT(); } -void play2() { +int play2() { Mix_ChannelFinished(done); int channel2 = Mix_PlayChannel(-1, sound2, 1); assert(channel2 == 1); + return channel2; } int main(int argc, char **argv) { @@ -40,7 +42,17 @@ int main(int argc, char **argv) { sound2 = Mix_LoadWAV("sound2.wav"); assert(sound); - play(); + int channel = play(); + printf( "Pausing Channel %d", channel ); + Mix_Pause(channel); + int paused = Mix_Paused(channel); + printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" ); + assert(paused); + Mix_Resume(channel); + paused = Mix_Paused(channel); + printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" ); + assert(paused == 0); + if (argc == 12121) play2(); // keep it alive emscripten_run_script("element = document.createElement('input');" |