diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cases/sillyfuncast.ll | 23 | ||||
-rw-r--r-- | tests/cases/sillyfuncast2.ll | 21 | ||||
-rw-r--r-- | tests/cases/zeroextarg.ll | 22 | ||||
-rw-r--r-- | tests/dirent/test_readdir.c | 132 | ||||
-rw-r--r-- | tests/embind/shell.html | 6 | ||||
-rw-r--r-- | tests/fcntl-misc/src.c | 2 | ||||
-rw-r--r-- | tests/fcntl-open/output.txt | 10 | ||||
-rw-r--r-- | tests/fcntl-open/src.c | 64 | ||||
-rwxr-xr-x | tests/fuzz/creduce_tester.py | 54 | ||||
-rwxr-xr-x | tests/fuzz/csmith_driver.py | 30 | ||||
-rw-r--r-- | tests/hello_world_gles_shell.html | 3 | ||||
-rwxr-xr-x | tests/runner.py | 1306 | ||||
-rw-r--r-- | tests/sdl_gfx_primitives.c | 46 | ||||
-rw-r--r-- | tests/sdl_gfx_primitives.png | bin | 0 -> 2357 bytes | |||
-rw-r--r-- | tests/sdl_rotozoom.c | 21 | ||||
-rw-r--r-- | tests/sdl_rotozoom.png | bin | 360054 -> 431921 bytes | |||
-rw-r--r-- | tests/unistd/isatty.c | 38 | ||||
-rw-r--r-- | tests/unistd/isatty.js | 5 | ||||
-rw-r--r-- | tests/unistd/isatty.out | 10 | ||||
-rw-r--r-- | tests/unistd/ttyname.c | 76 | ||||
-rw-r--r-- | tests/unistd/ttyname.js | 1 | ||||
-rw-r--r-- | tests/unistd/ttyname.out | 5 | ||||
-rw-r--r-- | tests/utime/test_utime.c | 53 |
23 files changed, 1292 insertions, 636 deletions
diff --git a/tests/cases/sillyfuncast.ll b/tests/cases/sillyfuncast.ll new file mode 100644 index 00000000..36c26720 --- /dev/null +++ b/tests/cases/sillyfuncast.ll @@ -0,0 +1,23 @@ +; 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, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +define void @doit() { + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + ret void +} + +define i32 @main() { +entry: + %retval = alloca i32, align 4 ; [#uses=1 type=i32*] + store i32 0, i32* %retval + %58 = tail call i32 bitcast (void ()* @doit to i32 ()*)() nounwind + ret i32 1 +} + +declare i32 @printf(i8*, ...) + + + diff --git a/tests/cases/sillyfuncast2.ll b/tests/cases/sillyfuncast2.ll new file mode 100644 index 00000000..f72ebe28 --- /dev/null +++ b/tests/cases/sillyfuncast2.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, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +define void @doit(i32 %one, i32 %two) { + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + ret void +} + +define i32 @main() { +entry: + %retval = alloca i32, align 4 ; [#uses=1 type=i32*] + store i32 0, i32* %retval + call i32 bitcast (void (i32, i32)* @doit to i32 (i32, i64)*)(i32 0, i64 0) nounwind + ret i32 1 +} + +declare i32 @printf(i8*, ...) + diff --git a/tests/cases/zeroextarg.ll b/tests/cases/zeroextarg.ll new file mode 100644 index 00000000..25efb7ec --- /dev/null +++ b/tests/cases/zeroextarg.ll @@ -0,0 +1,22 @@ +; 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, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +define void @glSampleCoverage(float %18, i8 zeroext %invert) { +entry: + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + ret void +} + +; [#uses=0] +define i32 @main() { +entry: + tail call void @glSampleCoverage(float 3.5, i8 zeroext 12) + ret i32 1 +} + +; [#uses=1] +declare i32 @printf(i8*, ...) + diff --git a/tests/dirent/test_readdir.c b/tests/dirent/test_readdir.c new file mode 100644 index 00000000..9f7b12e8 --- /dev/null +++ b/tests/dirent/test_readdir.c @@ -0,0 +1,132 @@ +#include <assert.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> + +static void create_file(const char *path, const char *buffer, int mode) { + int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode); + assert(fd >= 0); + + int err = write(fd, buffer, sizeof(char) * strlen(buffer)); + assert(err == (sizeof(char) * strlen(buffer))); + + close(fd); +} + +void setup() { + mkdir("nocanread", 0111); + mkdir("foobar", 0777); + create_file("foobar/file.txt", "ride into the danger zone", 0666); +} + +void cleanup() { + rmdir("nocanread"); + unlink("foobar/file.txt"); + rmdir("foobar"); +} + +void test() { + int err; + int loc; + DIR *dir; + struct dirent *ent; + struct dirent ent_r; + struct dirent *result; + + // check bad opendir input + dir = opendir("noexist"); + assert(!dir); + assert(errno == ENOENT); + dir = opendir("nocanread"); + assert(!dir); + assert(errno == EACCES); + dir = opendir("foobar/file.txt"); + assert(!dir); + assert(errno == ENOTDIR); + + // check bad readdir input + dir = opendir("foobar"); + closedir(dir); + ent = readdir(dir); + assert(!ent); + assert(errno == EBADF); + + // check bad readdir_r input + dir = opendir("foobar"); + closedir(dir); + err = readdir_r(dir, NULL, &result); + assert(err == EBADF); + + // + // do a normal read with readdir + // + dir = opendir("foobar"); + assert(dir); + ent = readdir(dir); + assert(!strcmp(ent->d_name, ".")); + assert(ent->d_type & DT_DIR); + ent = readdir(dir); + assert(!strcmp(ent->d_name, "..")); + assert(ent->d_type & DT_DIR); + ent = readdir(dir); + assert(!strcmp(ent->d_name, "file.txt")); + assert(ent->d_type & DT_REG); + ent = readdir(dir); + assert(!ent); + + // test rewinddir + rewinddir(dir); + ent = readdir(dir); + assert(!strcmp(ent->d_name, ".")); + + // test seek / tell + rewinddir(dir); + ent = readdir(dir); + assert(!strcmp(ent->d_name, ".")); + loc = telldir(dir); + ent = readdir(dir); + assert(!strcmp(ent->d_name, "..")); + ent = readdir(dir); + assert(!strcmp(ent->d_name, "file.txt")); + seekdir(dir, loc); + ent = readdir(dir); + assert(!strcmp(ent->d_name, "..")); + + // + // do a normal read with readdir_r + // + rewinddir(dir); + err = readdir_r(dir, &ent_r, &result); + assert(!err); + assert(&ent_r == result); + assert(!strcmp(ent_r.d_name, ".")); + err = readdir_r(dir, &ent_r, &result); + assert(!err); + assert(&ent_r == result); + assert(!strcmp(ent_r.d_name, "..")); + err = readdir_r(dir, &ent_r, &result); + assert(!err); + assert(&ent_r == result); + assert(!strcmp(ent_r.d_name, "file.txt")); + err = readdir_r(dir, &ent_r, &result); + assert(!err); + assert(!result); + + err = closedir(dir); + assert(!err); + + puts("success"); +} + +int main() { + atexit(cleanup); + signal(SIGABRT, cleanup); + setup(); + test(); + return EXIT_SUCCESS; +}
\ No newline at end of file diff --git a/tests/embind/shell.html b/tests/embind/shell.html index 6664ec78..c3655e03 100644 --- a/tests/embind/shell.html +++ b/tests/embind/shell.html @@ -85,10 +85,6 @@ }; Module.setStatus('Downloading...'); </script> - <script type='text/javascript'> - - {{{ SCRIPT_CODE }}} - - </script> + <script type='text/javascript'>{{{ SCRIPT_CODE }}}</script> </body> </html> diff --git a/tests/fcntl-misc/src.c b/tests/fcntl-misc/src.c index 73734969..7cdbbcd6 100644 --- a/tests/fcntl-misc/src.c +++ b/tests/fcntl-misc/src.c @@ -6,7 +6,7 @@ int main() { struct stat s; - int f = open("/test", O_RDONLY, 0777); + int f = open("/test", O_RDWR, 0777); printf("posix_fadvise: %d\n", posix_fadvise(f, 3, 2, POSIX_FADV_DONTNEED)); printf("errno: %d\n", errno); diff --git a/tests/fcntl-open/output.txt b/tests/fcntl-open/output.txt index 314ae880..07b106ac 100644 --- a/tests/fcntl-open/output.txt +++ b/tests/fcntl-open/output.txt @@ -19,8 +19,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,1 -success: 0 -errno: 21 +success: 1 +errno: 0 st_mode: 040000 NON-EXISTING 0,1 @@ -139,8 +139,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,9 -success: 0 -errno: 21 +success: 1 +errno: 0 st_mode: 040000 NON-EXISTING 0,9 @@ -720,4 +720,4 @@ st_mode: 0100000 CREAT success: 1 -errno: 0 +errno: 0
\ No newline at end of file diff --git a/tests/fcntl-open/src.c b/tests/fcntl-open/src.c index 52d2e7e4..bd52dd3f 100644 --- a/tests/fcntl-open/src.c +++ b/tests/fcntl-open/src.c @@ -1,13 +1,45 @@ -#include <stdio.h> +#include <assert.h> #include <errno.h> -#include <sys/stat.h> #include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <unistd.h> +#include <sys/stat.h> -int main() { +char nonexistent_name[] = "noexist-##"; + +void create_file(const char *path, const char *buffer, int mode) { + int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode); + assert(fd >= 0); + + int err = write(fd, buffer, sizeof(char) * strlen(buffer)); + assert(err == (sizeof(char) * strlen(buffer))); + + close(fd); +} + +void setup() { + create_file("test-file", "abcdef", 0777); + mkdir("test-folder", 0777); +} + +void cleanup() { + unlink("test-file"); + rmdir("test-folder"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 16; j++) { + nonexistent_name[8] = 'a' + i; + nonexistent_name[9] = 'a' + j; + unlink(nonexistent_name); + } + } + unlink("creat-me"); +} + +void test() { struct stat s; int modes[] = {O_RDONLY, O_WRONLY, O_RDWR}; - char nonexistent_name[] = "/noexist-##"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 16; j++) { @@ -18,25 +50,25 @@ int main() { if (j & 0x8) flags |= O_APPEND; printf("EXISTING FILE %d,%d\n", i, j); - printf("success: %d\n", open("/test-file", flags, 0777) != -1); + printf("success: %d\n", open("test-file", flags, 0777) != -1); printf("errno: %d\n", errno); - stat("/test-file", &s); + stat("test-file", &s); printf("st_mode: 0%o\n", s.st_mode & 037777777000); memset(&s, 0, sizeof s); printf("\n"); errno = 0; printf("EXISTING FOLDER %d,%d\n", i, j); - printf("success: %d\n", open("/test-folder", flags, 0777) != -1); + printf("success: %d\n", open("test-folder", flags, 0777) != -1); printf("errno: %d\n", errno); - stat("/test-folder", &s); + stat("test-folder", &s); printf("st_mode: 0%o\n", s.st_mode & 037777777000); memset(&s, 0, sizeof s); printf("\n"); errno = 0; - nonexistent_name[9] = 'a' + i; - nonexistent_name[10] = 'a' + j; + nonexistent_name[8] = 'a' + i; + nonexistent_name[9] = 'a' + j; printf("NON-EXISTING %d,%d\n", i, j); printf("success: %d\n", open(nonexistent_name, flags, 0777) != -1); printf("errno: %d\n", errno); @@ -49,8 +81,14 @@ int main() { } printf("CREAT\n"); - printf("success: %d\n", creat("/creat-me", 0777) != -1); + printf("success: %d\n", creat("creat-me", 0777) != -1); printf("errno: %d\n", errno); - - return 0; } + +int main() { + atexit(cleanup); + signal(SIGABRT, cleanup); + setup(); + test(); + return EXIT_SUCCESS; +}
\ No newline at end of file diff --git a/tests/fuzz/creduce_tester.py b/tests/fuzz/creduce_tester.py index c3460e9d..d5618c2e 100755 --- a/tests/fuzz/creduce_tester.py +++ b/tests/fuzz/creduce_tester.py @@ -1,53 +1,53 @@ #!/usr/bin/python ''' -Runs csmith, a C fuzzer, and looks for bugs +Usage: creduce ./creduce_tester.py newfail1.c ''' -import os, sys, difflib +import os, sys from subprocess import Popen, PIPE, STDOUT sys.path += [os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'tools')] -import shared +import shared, jsrun + +# creduce will only pass the filename of the C file as the first arg, so other +# configuration options will have to be hardcoded. +CSMITH_CFLAGS = ['-I', os.path.join(os.environ['CSMITH_PATH'], 'runtime')] +ENGINE = shared.JS_ENGINES[0] +EMCC_ARGS = ['-O2', '-s', 'ASM_JS=1', '-s', 'PRECISE_I64_MATH=1', '-s', + 'PRECISE_I32_MUL=1'] filename = sys.argv[1] +obj_filename = os.path.splitext(filename)[0] +js_filename = obj_filename + '.js' print 'testing file', filename -print '2) Compile natively' -shared.try_delete(filename) -shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename] + CSMITH_CFLAGS, stderr=PIPE) -assert os.path.exists(filename) -print '3) Run natively' try: - correct = shared.timeout_run(Popen([filename], stdout=PIPE, stderr=PIPE), 3) + print '2) Compile natively' + shared.check_execute([shared.CLANG_CC, '-O2', filename, '-o', obj_filename] + CSMITH_CFLAGS) + print '3) Run natively' + correct = jsrun.timeout_run(Popen([obj_filename], stdout=PIPE, stderr=PIPE), 3) except Exception, e: print 'Failed or infinite looping in native, skipping', e - notes['invalid'] += 1 - os.exit(0) # boring + sys.exit(1) # boring print '4) Compile JS-ly and compare' def try_js(args): - shared.try_delete(filename + '.js') - shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', '-s', 'PRECISE_I64_MATH=1', '-s', 'PRECISE_I32_MUL=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args, stderr=PIPE) - assert os.path.exists(filename + '.js') - js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1) - assert correct == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')]) + shared.check_execute([shared.EMCC] + EMCC_ARGS + CSMITH_CFLAGS + args + + [filename, '-o', js_filename]) + js = shared.run_js(js_filename, stderr=PIPE, engine=ENGINE) + assert correct == js # Try normally, then try unaligned because csmith does generate nonportable code that requires x86 alignment -ok = False -normal = True -for args, note in [([], None), (['-s', 'UNALIGNED_MEMORY=1'], 'unaligned')]: +# If you are sure that alignment is not the cause, disable it for a faster reduction +for args in [[]]: try: try_js(args) - ok = True - if note: - notes[note] += 1 break except Exception, e: - print e - normal = False -if not ok: sys.exit(1) - -sys.exit(0) # boring + pass +else: + sys.exit(0) +sys.exit(1) # boring diff --git a/tests/fuzz/csmith_driver.py b/tests/fuzz/csmith_driver.py index b60e67f7..c987a3be 100755 --- a/tests/fuzz/csmith_driver.py +++ b/tests/fuzz/csmith_driver.py @@ -1,11 +1,14 @@ #!/usr/bin/python ''' -Runs csmith, a C fuzzer, and looks for bugs +Runs csmith, a C fuzzer, and looks for bugs. + +CSMITH_PATH should be set to something like /usr/local/include/csmith ''' import os, sys, difflib, shutil -from subprocess import Popen, PIPE, STDOUT +from distutils.spawn import find_executable +from subprocess import check_call, Popen, PIPE, STDOUT, CalledProcessError sys.path += [os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'tools')] import shared @@ -15,8 +18,11 @@ engine2 = eval('shared.' + sys.argv[2]) if len(sys.argv) > 2 else None print 'testing js engines', engine1, engine2 -CSMITH = os.path.expanduser('~/Dev/csmith/src/csmith') -CSMITH_CFLAGS = ['-I' + os.path.expanduser('~/Dev/csmith/runtime/')] +CSMITH = os.environ.get('CSMITH') or find_executable('csmith') +assert CSMITH, 'Could not find CSmith on your PATH. Please set the environment variable CSMITH.' +CSMITH_PATH = os.environ.get('CSMITH_PATH') +assert CSMITH_PATH, 'Please set the environment variable CSMITH_PATH.' +CSMITH_CFLAGS = ['-I', os.path.join(CSMITH_PATH, 'runtime')] filename = os.path.join(shared.CANONICAL_TEMP_DIR, 'fuzzcode') @@ -31,7 +37,7 @@ fails = 0 while 1: print 'Tried %d, notes: %s' % (tried, notes) print '1) Generate C' - shared.execute([CSMITH, '--no-volatiles', '--no-math64', '--no-packed-struct'],# + + check_call([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) @@ -41,11 +47,11 @@ while 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 - shared.execute([shared.CLANG_CC, '-O2', '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', filename + '.c', '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS, stderr=PIPE) - shared.execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc'], stdout=PIPE, stderr=PIPE) + shared.check_execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename + '1'] + CSMITH_CFLAGS) # + shared.EMSDK_OPTS + shared.check_execute([shared.CLANG_CC, '-O2', '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', filename + '.c', '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS) + shared.check_execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc']) shutil.move(filename + '.bc.run', filename + '2') - shared.execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS, stderr=PIPE) + shared.check_execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS) print '3) Run natively' try: correct1 = shared.jsrun.timeout_run(Popen([filename + '1'], stdout=PIPE, stderr=PIPE), 3) @@ -65,7 +71,7 @@ while 1: def try_js(args): shared.try_delete(filename + '.js') print '(compile)' - shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args, stderr=PIPE) + shared.check_execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args) assert os.path.exists(filename + '.js') print '(run)' js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1, check_timeout=True) @@ -91,7 +97,7 @@ while 1: print "EMSCRIPTEN BUG" notes['embug'] += 1 fails += 1 - shutil.copyfile('fuzzcode.c', 'newfail%d.c' % fails) + shutil.copyfile(filename + '.c', 'newfail%d.c' % fails) continue #if not ok: # try: # finally, try with safe heap. if that is triggered, this is nonportable code almost certainly @@ -118,7 +124,7 @@ while 1: print "ODIN VALIDATION BUG" notes['embug'] += 1 fails += 1 - shutil.copyfile('fuzzcode.c', 'newfail%d.c' % fails) + shutil.copyfile(filename + '.c', 'newfail%d.c' % fails) continue js2 = js2.replace('\nwarning: Successfully compiled asm.js code\n', '') diff --git a/tests/hello_world_gles_shell.html b/tests/hello_world_gles_shell.html index 4abee90c..2459d755 100644 --- a/tests/hello_world_gles_shell.html +++ b/tests/hello_world_gles_shell.html @@ -48,9 +48,8 @@ } Module.postRun = doTest; - // The compiled code - {{{ SCRIPT_CODE }}} </script> + <script>{{{ SCRIPT_CODE }}}</script> </body> </html> diff --git a/tests/runner.py b/tests/runner.py index 2c459f6f..9e04c929 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -16,7 +16,7 @@ so you may prefer to use fewer cores here. ''' from subprocess import Popen, PIPE, STDOUT -import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib, webbrowser, hashlib, threading, platform, BaseHTTPServer, multiprocessing, functools, stat +import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, re, difflib, webbrowser, hashlib, threading, platform, BaseHTTPServer, multiprocessing, functools, stat if len(sys.argv) == 1: print ''' @@ -170,16 +170,13 @@ class RunnerCore(unittest.TestCase): post1 = post_build post2 = None - def run_post(post): - if not post: return - exec post in locals() - shutil.copyfile(filename + '.o.js', filename + '.o.js.prepost.js') - process(filename + '.o.js') - if self.emcc_args is None: Building.emscripten(filename, append_ext=True, extra_args=extra_emscripten_args) - run_post(post1) - run_post(post2) + if post1: + exec post1 in locals() + shutil.copyfile(filename + '.o.js', filename + '.o.js.prepost.js') + process(filename + '.o.js') + if post2: post2(filename + '.o.js') else: transform_args = [] if post1: @@ -196,7 +193,7 @@ process(sys.argv[1]) transform.close() transform_args = ['--js-transform', "%s %s" % (PYTHON, transform_filename)] Building.emcc(filename + '.o.ll', Settings.serialize() + self.emcc_args + transform_args + Building.COMPILER_TEST_OPTS, filename + '.o.js') - run_post(post2) + if post2: post2(filename + '.o.js') # Build JavaScript code from source code def build(self, src, dirname, filename, output_processor=None, main_file=None, additional_files=[], libraries=[], includes=[], build_ll_hook=None, extra_emscripten_args=[], post_build=None): @@ -233,11 +230,11 @@ process(sys.argv[1]) os.remove(f + '.o') except: pass - args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + \ + args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + Settings.serialize() + \ ['-I', dirname, '-I', os.path.join(dirname, 'include')] + \ map(lambda include: '-I' + include, includes) + \ ['-c', f, '-o', f + '.o'] - output = Popen(args, stdout=PIPE, stderr=self.stderr_redirect).communicate()[0] + output = Popen(args, stdout=PIPE, stderr=self.stderr_redirect if not DEBUG else None).communicate()[0] assert os.path.exists(f + '.o'), 'Source compilation error: ' + output # Link all files @@ -268,6 +265,12 @@ process(sys.argv[1]) else: assert 'memory initializer */' in open(filename + '.o.js').read() + def validate_asmjs(self, err): + if 'uccessfully compiled asm.js code' in err and 'asm.js link error' not in err: + print >> sys.stderr, "[was asm.js'ified]" + elif 'asm.js' in err: # if no asm.js error, then not an odin build + raise Exception("did NOT asm.js'ify") + def run_generated_code(self, engine, filename, args=[], check_timeout=True, output_nicerizer=None): stdout = os.path.join(self.get_dir(), 'stdout') # use files, as PIPE can get too full and hang us stderr = os.path.join(self.get_dir(), 'stderr') @@ -282,10 +285,7 @@ process(sys.argv[1]) out = open(stdout, 'r').read() err = open(stderr, 'r').read() if engine == SPIDERMONKEY_ENGINE and Settings.ASM_JS: - if 'uccessfully compiled asm.js code' in err and 'asm.js link error' not in err: - print >> sys.stderr, "[was asm.js'ified]" - elif 'asm.js' in err: # if no asm.js error, then not an odin build - raise Exception("did NOT asm.js'ify") + self.validate_asmjs(err) if output_nicerizer: ret = output_nicerizer(out, err) else: @@ -438,7 +438,7 @@ process(sys.argv[1]) sys.argv = map(lambda arg: arg if not arg.startswith('test_') else 'default.' + arg, sys.argv) -test_modes = ['default', 'o1', 'o2', 'asm1', 'asm2', 'asm2g', 'asm2x86', 's_0_0', 's_0_1', 's_1_0', 's_1_1'] +test_modes = ['default', 'o1', 'o2', 'asm1', 'asm2', 'asm2g', 'asm2x86', 's_0_0', 's_0_1'] test_index = 0 @@ -1981,6 +1981,18 @@ Succeeded! self.do_run(src, "1.0 2.0 -1.0 -2.0 2.0 3.0 -2.0 -3.0 " "1 2 -1 -2 2 2 -2 -2") + def test_llrint(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2') + src = r''' + #include <stdio.h> + #include <math.h> + int main() { + printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), llrint(1099511627776.667)); + return 0; + } + ''' + self.do_run(src, '0\n1\n1\n1099511627777\n') + def test_getgep(self): # Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP src = ''' @@ -2107,12 +2119,12 @@ Succeeded! } return int(&x); // both for the number, and forces x to not be nativized } - int main() + int main(int argc, char **argv) { // We should get the same value for the first and last - stack has unwound - int x1 = test(0); + int x1 = test(argc - 2); int x2 = test(100); - int x3 = test(0); + int x3 = test((argc - 2) / 4); printf("*%d,%d*\\n", x3-x1, x2 != x1); return 0; } @@ -4082,7 +4094,7 @@ def process(filename): #include <assert.h> #include "emscripten.h" - int main() + int main(int argc, char **argv) { char *buf1 = (char*)malloc(100); char *data1 = "hello"; @@ -4096,6 +4108,8 @@ def process(filename): int totalMemory = emscripten_run_script_int("TOTAL_MEMORY"); char *buf3 = (char*)malloc(totalMemory+1); + buf3[argc] = (int)buf2; + if (argc % 7 == 6) printf("%d\n", memcpy(buf3, buf1, argc)); char *buf4 = (char*)malloc(100); float *buf5 = (float*)malloc(100); //printf("totalMemory: %d bufs: %d,%d,%d,%d,%d\n", totalMemory, buf1, buf2, buf3, buf4, buf5); @@ -4233,6 +4247,8 @@ def process(filename): ''', args=['34962', '26214', '35040']) def test_indirectbr(self): + Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS) + src = ''' #include <stdio.h> int main(void) { @@ -4954,6 +4970,130 @@ The current type of b is: 9 ''' self.do_run(src, 'time: ') # compilation check, mainly + + def test_strptime_tm(self): + src=r''' + #include <time.h> + #include <stdio.h> + #include <string.h> + + int main() { + struct tm tm; + char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm); + + printf("%s: %s, %d/%d/%d %d:%d:%d", + (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", + tm.tm_wday == 0 ? "Sun" : (tm.tm_wday == 1 ? "Mon" : (tm.tm_wday == 2 ? "Tue" : (tm.tm_wday == 3 ? "Wed" : (tm.tm_wday == 4 ? "Thu" : (tm.tm_wday == 5 ? "Fri" : (tm.tm_wday == 6 ? "Sat" : "ERR")))))), + tm.tm_mon+1, + tm.tm_mday, + tm.tm_year+1900, + tm.tm_hour, + tm.tm_min, + tm.tm_sec + ); + } + ''' + self.do_run(src, 'OK: Wed, 1/5/2000 17:41:1') + + def test_strptime_days(self): + src = r''' + #include <time.h> + #include <stdio.h> + #include <string.h> + + static const struct { + const char *input; + const char *format; + } day_tests[] = { + { "2000-01-01", "%Y-%m-%d"}, + { "03/03/00", "%D"}, + { "9/9/99", "%x"}, + { "19990502123412", "%Y%m%d%H%M%S"}, + { "2001 20 Mon", "%Y %U %a"}, + { "2006 4 Fri", "%Y %U %a"}, + { "2001 21 Mon", "%Y %W %a"}, + { "2013 29 Wed", "%Y %W %a"}, + { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"}, + { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"}, + { "2001 17 Tue", "%Y %U %a"}, + { "2001 8 Thursday", "%Y %W %a"}, + }; + + int main() { + struct tm tm; + + for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) { + memset (&tm, '\0', sizeof (tm)); + char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm); + + printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday); + } + } + ''' + self.do_run(src, 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\ + 'OK: 3/3/2000 (5th DoW, 62th DoY)\n'\ + 'OK: 9/9/1999 (4th DoW, 251th DoY)\n'\ + 'OK: 5/2/1999 (0th DoW, 121th DoY)\n'\ + 'OK: 5/21/2001 (1th DoW, 140th DoY)\n'\ + 'OK: 1/27/2006 (5th DoW, 26th DoY)\n'\ + 'OK: 5/21/2001 (1th DoW, 140th DoY)\n'\ + 'OK: 7/24/2013 (3th DoW, 204th DoY)\n'\ + 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\ + 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\ + 'OK: 5/1/2001 (2th DoW, 120th DoY)\n'\ + 'OK: 2/22/2001 (4th DoW, 52th DoY)\n'\ + ) + + def test_strptime_reentrant(self): + src=r''' + #include <time.h> + #include <stdio.h> + #include <string.h> + #include <stdlib.h> + + int main () { + int result = 0; + struct tm tm; + + memset (&tm, 0xaa, sizeof (tm)); + + /* Test we don't crash on uninitialized struct tm. + Some fields might contain bogus values until everything + needed is initialized, but we shouldn't crash. */ + if (strptime ("2007", "%Y", &tm) == NULL + || strptime ("12", "%d", &tm) == NULL + || strptime ("Feb", "%b", &tm) == NULL + || strptime ("13", "%M", &tm) == NULL + || strptime ("21", "%S", &tm) == NULL + || strptime ("16", "%H", &tm) == NULL) { + printf("ERR: returned NULL"); + exit(EXIT_FAILURE); + } + + if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 + || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107 + || tm.tm_wday != 1 || tm.tm_yday != 42) { + printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); + exit(EXIT_FAILURE); + } + + if (strptime ("8", "%d", &tm) == NULL) { + printf("ERR: strptime failed"); + exit(EXIT_FAILURE); + } + + if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 + || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107 + || tm.tm_wday != 4 || tm.tm_yday != 38) { + printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); + exit(EXIT_FAILURE); + } + + printf("OK"); + } + ''' + self.do_run(src, 'OK') + def test_intentional_fault(self): # Some programs intentionally segfault themselves, we should compile that into a throw src = r''' @@ -5881,6 +6021,50 @@ def process(filename): self.do_run(src, '100\n200\n13\n42\n', post_build=add_pre_run_and_checks) + def test_dlfcn_self(s |