diff options
Diffstat (limited to 'tests/test_core.py')
-rw-r--r-- | tests/test_core.py | 149 |
1 files changed, 129 insertions, 20 deletions
diff --git a/tests/test_core.py b/tests/test_core.py index dd3b7c44..f51c1691 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); @@ -5046,7 +5090,7 @@ The current type of b is: 9 src = r''' int main () { *(volatile char *)0 = 0; - return 0; + return *(volatile char *)0; } ''' self.do_run(src, 'fault on write to 0' if not Settings.ASM_JS else 'abort()') @@ -6908,6 +6952,29 @@ at function.:blag printf("%i\n", a); } + char buf1[100], buf2[100], buf3[100], buf4[100]; + + int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4); + printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); + + numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + return 0; } ''' @@ -6915,7 +6982,14 @@ at function.:blag '1\n1499\n' + '5\n87,0.481565,0.059481,0,1\n' + '3\n-123,4294966531,-34\n' + - '1\n') + '1\n' + + '4, level, 4, ref, 3\n' + + '2, def, 456\n' + + '2, 3-4, -ab\n' + + '2, Hello, World\n' + + '1, Hello\n' + + '1, Java\n' + + '2, [, ]') def test_sscanf_2(self): # doubles @@ -7171,6 +7245,18 @@ date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3 ''' self.do_run(src, '10 1.1 1.1 1.1'); + def test_sscanf_hex(self): + src = r''' + #include "stdio.h" + + int main(){ + unsigned int a, b; + sscanf("0x12AB 12AB", "%x %x", &a, &b); + printf("%d %d\n", a, b); + } + ''' + self.do_run(src, '4779 4779') + def test_langinfo(self): src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read() expected = open(path_from_root('tests', 'langinfo', 'output.txt'), 'r').read() @@ -7656,12 +7742,18 @@ def process(filename): finally: Settings.INCLUDE_FULL_LIBRARY = 0 + def test_fs_nodefs_rw(self): + src = open(path_from_root('tests', 'fs', 'test_nodefs_rw.c'), 'r').read() + self.do_run(src, 'success', force_c=True) + 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) def test_unistd_curdir(self): if Settings.ASM_JS: Settings.ASM_JS = 2 # skip validation, asm does not support random code @@ -7697,9 +7789,11 @@ def process(filename): 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) def test_unistd_swab(self): src = open(path_from_root('tests', 'unistd', 'swab.c'), 'r').read() @@ -7721,15 +7815,19 @@ 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) + 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) 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) def test_unistd_sleep(self): src = open(path_from_root('tests', 'unistd', 'sleep.c'), 'r').read() @@ -7740,14 +7838,18 @@ def process(filename): 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) + 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) 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) + 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) def test_uname(self): src = r''' @@ -8895,6 +8997,8 @@ def process(filename): def test_cases(self): if Building.LLVM_OPTS: return self.skip("Our code is not exactly 'normal' llvm assembly") + emcc_args = self.emcc_args + try: os.environ['EMCC_LEAVE_INPUTS_RAW'] = '1' Settings.CHECK_OVERFLOWS = 0 @@ -8908,6 +9012,10 @@ def process(filename): if '_noasm' in shortname and Settings.ASM_JS: print self.skip('case "%s" not relevant for asm.js' % shortname) continue + self.emcc_args = emcc_args + if os.path.exists(shortname + '.emcc'): + if not self.emcc_args: continue + self.emcc_args = self.emcc_args + json.loads(open(shortname + '.emcc').read()) print >> sys.stderr, "Testing case '%s'..." % shortname output_file = path_from_root('tests', 'cases', shortname + '.txt') if Settings.QUANTUM_SIZE == 1: @@ -8928,6 +9036,7 @@ def process(filename): finally: del os.environ['EMCC_LEAVE_INPUTS_RAW'] + self.emcc_args = emcc_args def test_fuzz(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2') |