diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cases/entry3.ll | 36 | ||||
-rw-r--r-- | tests/cases/entry3.txt | 2 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 19 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 24 | ||||
-rwxr-xr-x | tests/runner.py | 134 | ||||
-rw-r--r-- | tests/unistd/unlink.c | 165 | ||||
-rw-r--r-- | tests/unistd/unlink.js | 7 | ||||
-rw-r--r-- | tests/unistd/unlink.out | 42 |
8 files changed, 316 insertions, 113 deletions
diff --git a/tests/cases/entry3.ll b/tests/cases/entry3.ll new file mode 100644 index 00000000..a20c6843 --- /dev/null +++ b/tests/cases/entry3.ll @@ -0,0 +1,36 @@ +; ModuleID = '/tmp/tmpKnA2D3/a.out.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 [11 x i8] c"getgid=%d\0A\00", align 1 +@.str1 = private unnamed_addr constant [6 x i8] c"f=%d\0A\00", align 1 + +define internal i32 @_Z1fii(i32, i32) noinline { +entry: + %3 = tail call i32 @getgid() + %4 = icmp eq i32 %3, 0 + br i1 %4, label %cond.b, label %cond.a + +cond.a: + %6 = tail call i32 @getgid() + br label %cond.end + +cond.b: + br label %cond.end + +cond.end: + %.0 = phi i32 [ 0, %cond.b ], [ 1, %1 ] + ret i32 %.0 +} + +declare i32 @getgid() + +define i32 @main() { + %1 = tail call i32 @getgid() + %2 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0), i32 %1) + %3 = tail call i32 @_Z1fii(i32 undef, i32 undef) + %4 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0), i32 %3) + ret i32 0 +} + +declare i32 @printf(i8* nocapture, ...) nounwind diff --git a/tests/cases/entry3.txt b/tests/cases/entry3.txt new file mode 100644 index 00000000..4060fb06 --- /dev/null +++ b/tests/cases/entry3.txt @@ -0,0 +1,2 @@ +getgid=0 +f=0 diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index e60e1ab3..da81a81e 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -898,10 +898,7 @@ module({ test("can clone handles", function() { var a = cm.emval_test_get_function_ptr(); - assert.equal(1, a.$$.count.value); var b = a.clone(); - assert.equal(2, a.$$.count.value); - assert.equal(2, b.$$.count.value); a.delete(); assert.throws(cm.BindingError, function() { @@ -1149,7 +1146,7 @@ module({ a.set(b); var c = a.get(); - assert.equal(b.$$.ptr, c.$$.ptr); + assert.true(b.isAliasOf(c)); b.delete(); c.delete(); a.delete(); @@ -1747,8 +1744,8 @@ module({ BaseFixture.extend("constants", function() { assert.equal(10, cm.INT_CONSTANT); assert.equal("some string", cm.STRING_CONSTANT); - assert.deepEqual([1, 2, 3, 4], cm.VALUE_TUPLE_CONSTANT); - assert.deepEqual({x:1,y:2,z:3,w:4}, cm.VALUE_STRUCT_CONSTANT); + assert.deepEqual([1, 2, 3, 4], cm.VALUE_ARRAY_CONSTANT); + assert.deepEqual({x:1,y:2,z:3,w:4}, cm.VALUE_OBJECT_CONSTANT); }); BaseFixture.extend("object handle comparison", function() { @@ -1881,6 +1878,16 @@ module({ // setTimeout(fn, 0); // }); }); + + BaseFixture.extend("references", function() { + test("JS object handles can be passed through to C++ by reference", function() { + var sh = new cm.StringHolder("Hello world"); + assert.equal("Hello world", sh.get()); + cm.clear_StringHolder(sh); + assert.equal("", sh.get()); + sh.delete(); + }); + }); }); /* global run_all_tests */ diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 3561b8a1..d6b27bce 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1445,7 +1445,7 @@ EMSCRIPTEN_BINDINGS(tests) { //function("emval_test_take_and_return_CustomStruct", &emval_test_take_and_return_CustomStruct); - value_tuple<TupleVector>("TupleVector") + value_array<TupleVector>("TupleVector") .element(&TupleVector::x) .element(&Vector::getY, &Vector::setY) .element(&readVectorZ, &writeVectorZ) @@ -1455,13 +1455,13 @@ EMSCRIPTEN_BINDINGS(tests) { function("emval_test_return_TupleVector", &emval_test_return_TupleVector); function("emval_test_take_and_return_TupleVector", &emval_test_take_and_return_TupleVector); - value_tuple<TupleVectorTuple>("TupleVectorTuple") + value_array<TupleVectorTuple>("TupleVectorTuple") .element(&TupleVectorTuple::v) ; function("emval_test_return_TupleVectorTuple", &emval_test_return_TupleVectorTuple); - value_struct<StructVector>("StructVector") + value_object<StructVector>("StructVector") .field("x", &StructVector::x) .field("y", &Vector::getY, &Vector::setY) .field("z", &readVectorZ, &writeVectorZ) @@ -1471,7 +1471,7 @@ EMSCRIPTEN_BINDINGS(tests) { function("emval_test_return_StructVector", &emval_test_return_StructVector); function("emval_test_take_and_return_StructVector", &emval_test_take_and_return_StructVector); - value_struct<TupleInStruct>("TupleInStruct") + value_object<TupleInStruct>("TupleInStruct") .field("field", &TupleInStruct::field) ; @@ -2077,12 +2077,12 @@ OrderedStruct getOrderedStruct() { } EMSCRIPTEN_BINDINGS(order) { - value_tuple<OrderedTuple>("OrderedTuple") + value_array<OrderedTuple>("OrderedTuple") .element(&OrderedTuple::first) .element(&OrderedTuple::second) ; - value_struct<OrderedStruct>("OrderedStruct") + value_object<OrderedStruct>("OrderedStruct") .field("first", &OrderedStruct::first) .field("second", &OrderedStruct::second) ; @@ -2215,10 +2215,10 @@ EMSCRIPTEN_BINDINGS(constants) { constant("STRING_CONSTANT", std::string("some string")); TupleVector tv(1, 2, 3, 4); - constant("VALUE_TUPLE_CONSTANT", tv); + constant("VALUE_ARRAY_CONSTANT", tv); StructVector sv(1, 2, 3, 4); - constant("VALUE_STRUCT_CONSTANT", sv); + constant("VALUE_OBJECT_CONSTANT", sv); } class DerivedWithOffset : public DummyDataToTestPointerAdjustment, public Base { @@ -2235,3 +2235,11 @@ EMSCRIPTEN_BINDINGS(with_adjustment) { function("return_Base_from_DerivedWithOffset", &return_Base_from_DerivedWithOffset); } + +void clear_StringHolder(StringHolder& sh) { + sh.set(""); +} + +EMSCRIPTEN_BINDINGS(references) { + function("clear_StringHolder", &clear_StringHolder); +} diff --git a/tests/runner.py b/tests/runner.py index f7f6f17c..69ee3e86 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -27,6 +27,7 @@ Running the main part of the test suite. Don't forget to run the other parts! benchmark - run before and after each set of changes before pushing to master, verify no regressions browser - runs pages in a web browser + browser audio - runs audio tests in a web browser (requires human verification) To run one of those parts, do something like @@ -4521,6 +4522,22 @@ The current address of a is: 0x12345678 The current type of b is: 9 ''') + def test_functionpointer_libfunc_varargs(self): + src = r''' + #include <stdio.h> + #include <fcntl.h> + typedef int (*fp_t)(int, int, ...); + int main(int argc, char **argv) { + fp_t fp = &fcntl; + if (argc == 1337) fp = (fp_t)&main; + (*fp)(0, 10); + (*fp)(0, 10, 5); + printf("waka\n"); + return 0; + } + ''' + self.do_run(src, '''waka''') + def test_structbyval(self): Settings.INLINING_LIMIT = 50 @@ -6785,6 +6802,25 @@ Pass: 0.000012 0.000012''') ''' self.do_run(src, '2, , black\n2, ., #001100\n2, X, #111100'); + def test_sscanf_6(self): + src = r''' + #include <stdio.h> + + int main() + { + char *date = "18.07.2013w"; + char c[10]; + int y, m, d, i; + i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, y, c[0], i); + i = sscanf(date, "%d.%d.%3c", &d, &m, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, y, c, i); + } + ''' + self.do_run(src, '''date: 18.07.2013w; day 18, month 7, year 2013, extra: w, 4 +date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3 +'''); + def test_sscanf_skip(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip("need ta2 for full i64") @@ -7377,18 +7413,8 @@ def process(filename): self.do_run(src, expected) def test_unistd_unlink(self): - add_pre_run = ''' -def process(filename): - import tools.shared as shared - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(shared.path_from_root('tests', 'unistd', 'unlink.js'), 'r').read() - ) - open(filename, 'w').write(src) -''' src = open(path_from_root('tests', 'unistd', 'unlink.c'), 'r').read() - expected = open(path_from_root('tests', 'unistd', 'unlink.out'), 'r').read() - self.do_run(src, expected, post_build=add_pre_run) + self.do_run(src, 'success', force_c=True) def test_unistd_links(self): add_pre_run = ''' @@ -10034,6 +10060,11 @@ finalizing 3 (global == 0) for k, v in self.env.iteritems(): del os.environ[k] + # clear global changes to Building + Building.COMPILER_TEST_OPTS = [] + Building.COMPILER = CLANG + Building.LLVM_OPTS = 0 + TT.tearDown = tearDown def setUp(self): @@ -10631,7 +10662,7 @@ f.close() Popen([PYTHON, EMLINK, 'main.js', 'side.js', 'together.js'], stdout=PIPE).communicate() assert os.path.exists('together.js') for engine in JS_ENGINES: - out = run_js('together.js', engine=SPIDERMONKEY_ENGINE, stderr=PIPE, full_output=True) + out = run_js('together.js', engine=engine, stderr=PIPE, full_output=True) self.assertContained(expected, out) if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) if first: @@ -10822,6 +10853,50 @@ f.close() args=['-I' + path_from_root('tests', 'bullet', 'src')]) + def test_outline(self): + def test(name, src, libs, expected, expected_ranges, args=[], suffix='cpp'): + print name + + def measure_funcs(filename): + i = 0 + start = -1 + curr = '?' + ret = {} + for line in open(filename): + i += 1 + if line.startswith('function '): + start = i + curr = line + elif line.startswith('}'): + size = i - start + if size > 100: ret[curr] = size + return ret + + for outlining_limit in [1000, 2000, 5000, 0]: + Popen([PYTHON, EMCC, src] + libs + ['-o', 'test.js', '-O2', '-g3', '-s', 'OUTLINING_LIMIT=%d' % outlining_limit] + args).communicate() + assert os.path.exists('test.js') + shutil.copyfile('test.js', '%d_test.js' % outlining_limit) + for engine in JS_ENGINES: + out = run_js('test.js', engine=engine, stderr=PIPE, full_output=True) + self.assertContained(expected, out) + if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) + low = expected_ranges[outlining_limit][0] + seen = max(measure_funcs('test.js').values()) + high = expected_ranges[outlining_limit][1] + print outlining_limit, ' ', low, '<=', seen, '<=', high + assert low <= seen <= high + + test('zlib', path_from_root('tests', 'zlib', 'example.c'), + self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']), + open(path_from_root('tests', 'zlib', 'ref.txt'), 'r').read(), + { + 1000: (380, 390), + 2000: (395, 410), + 5000: (800, 1100), + 0: (1500, 1800) + }, + args=['-I' + path_from_root('tests', 'zlib')], suffix='c') + def test_symlink(self): if os.name == 'nt': return self.skip('Windows FS does not need to be tested for symlinks support, since it does not have them.') @@ -11546,11 +11621,11 @@ f.close() def test_js_optimizer(self): for input, expected, passes in [ (path_from_root('tools', 'test-js-optimizer.js'), open(path_from_root('tools', 'test-js-optimizer-output.js')).read(), - ['hoistMultiples', 'loopOptimizer', 'removeAssignsToUndefined', 'simplifyExpressionsPre', 'simplifyExpressionsPost']), + ['hoistMultiples', 'loopOptimizer', 'removeAssignsToUndefined', 'simplifyExpressions']), (path_from_root('tools', 'test-js-optimizer-t2c.js'), open(path_from_root('tools', 'test-js-optimizer-t2c-output.js')).read(), - ['simplifyExpressionsPre', 'optimizeShiftsConservative']), + ['simplifyExpressions', 'optimizeShiftsConservative']), (path_from_root('tools', 'test-js-optimizer-t2.js'), open(path_from_root('tools', 'test-js-optimizer-t2-output.js')).read(), - ['simplifyExpressionsPre', 'optimizeShiftsAggressive']), + ['simplifyExpressions', 'optimizeShiftsAggressive']), # Make sure that optimizeShifts handles functions with shift statements. (path_from_root('tools', 'test-js-optimizer-t3.js'), open(path_from_root('tools', 'test-js-optimizer-t3-output.js')).read(), ['optimizeShiftsAggressive']), @@ -11567,13 +11642,15 @@ f.close() (path_from_root('tools', 'test-js-optimizer-asm-regs-min.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-min-output.js')).read(), ['asm', 'registerize']), (path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(), - ['asm', 'simplifyExpressionsPre']), + ['asm', 'simplifyExpressions']), (path_from_root('tools', 'test-js-optimizer-asm-last.js'), open(path_from_root('tools', 'test-js-optimizer-asm-last-output.js')).read(), ['asm', 'last']), (path_from_root('tools', 'test-js-optimizer-asm-relocate.js'), open(path_from_root('tools', 'test-js-optimizer-asm-relocate-output.js')).read(), ['asm', 'relocate']), - #(path_from_root('tools', 'test-js-optimizer-asm-outline.js'), open(path_from_root('tools', 'test-js-optimizer-asm-outline-output.js')).read(), - # ['asm', 'outline']), + (path_from_root('tools', 'test-js-optimizer-asm-outline1.js'), open(path_from_root('tools', 'test-js-optimizer-asm-outline1-output.js')).read(), + ['asm', 'outline']), + (path_from_root('tools', 'test-js-optimizer-asm-outline2.js'), open(path_from_root('tools', 'test-js-optimizer-asm-outline2-output.js')).read(), + ['asm', 'outline']), ]: print input output = Popen(listify(NODE_JS) + [path_from_root('tools', 'js-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).communicate()[0] @@ -11810,6 +11887,24 @@ elif 'browser' in str(sys.argv): print 'Running the browser tests. Make sure the browser allows popups from localhost.' print + if 'audio' in sys.argv: + print + print 'Running the browser audio tests. Make sure to listen to hear the correct results!' + print + + i = sys.argv.index('audio') + sys.argv = sys.argv[:i] + sys.argv[i+1:] + i = sys.argv.index('browser') + sys.argv = sys.argv[:i] + sys.argv[i+1:] + sys.argv += [ + 'browser.test_sdl_audio', + 'browser.test_sdl_audio_mix_channels', + 'browser.test_sdl_audio_mix', + 'browser.test_sdl_audio_quickload', + 'browser.test_openal_playback', + 'browser.test_freealut' + ] + # Run a server and a web page. When a test runs, we tell the server about it, # which tells the web page, which then opens a window with the test. Doing # it this way then allows the page to close() itself when done. @@ -12820,8 +12915,9 @@ Press any key to continue.''' self.run_browser('page.html', 'Should print "(300, 150)" -- the size of the canvas in pixels', '/report_result?1') def test_freealut(self): - programs = self.get_library('freealut', os.path.join('examples', 'hello_world.bc'), make_args=['EXEEXT=.bc']) + programs = self.get_library('freealut', os.path.join('examples', '.libs', 'hello_world.bc'), make_args=['EXEEXT=.bc']) for program in programs: + assert os.path.exists(program) Popen([PYTHON, EMCC, '-O2', program, '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should hear "Hello World!"') diff --git a/tests/unistd/unlink.c b/tests/unistd/unlink.c index 3f7d84b6..87252da2 100644 --- a/tests/unistd/unlink.c +++ b/tests/unistd/unlink.c @@ -1,35 +1,138 @@ -#include <stdio.h> +#include <assert.h> #include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <unistd.h> +#include <sys/stat.h> -int main() { - char* files[] = {"/device", "/file", "/file-forbidden", "/noexist"}; - char* folders[] = {"/empty", "/empty-forbidden", "/full"}; - int i; - - for (i = 0; i < sizeof files / sizeof files[0]; i++) { - printf("access(%s) before: %d\n", files[i], access(files[i], F_OK)); - rmdir(files[i]); - printf("errno: %d\n", errno); - errno = 0; - printf("access(%s) after rmdir: %d\n", files[i], access(files[i], F_OK)); - unlink(files[i]); - printf("errno: %d\n", errno); - errno = 0; - printf("access(%s) after unlink: %d\n\n", files[i], access(files[i], F_OK)); - } - - for (i = 0; i < sizeof folders / sizeof folders[0]; i++) { - printf("access(%s) before: %d\n", folders[i], access(folders[i], F_OK)); - unlink(folders[i]); - printf("errno: %d\n", errno); - errno = 0; - printf("access(%s) after unlink: %d\n", folders[i], access(folders[i], F_OK)); - rmdir(folders[i]); - printf("errno: %d\n", errno); - errno = 0; - printf("access(%s) after rmdir: %d\n\n", folders[i], access(folders[i], F_OK)); - } - - return 0; +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() { + create_file("file", "test", 0777); + create_file("file1", "test", 0777); + symlink("file1", "file1-link"); + mkdir("dir-empty", 0777); + symlink("dir-empty", "dir-empty-link"); + mkdir("dir-readonly", 0777); + create_file("dir-readonly/anotherfile", "test", 0777); + mkdir("dir-readonly/anotherdir", 0777); + chmod("dir-readonly", 0555); + mkdir("dir-full", 0777); + create_file("dir-full/anotherfile", "test", 0777); +} + +void cleanup() { + unlink("file"); + unlink("file1"); + unlink("file1-link"); + rmdir("dir-empty"); + unlink("dir-empty-link"); + chmod("dir-readonly", 0777); + unlink("dir-readonly/anotherfile"); + rmdir("dir-readonly/anotherdir"); + rmdir("dir-readonly"); + unlink("dir-full/anotherfile"); + rmdir("dir-full"); +} + +void test() { + int err; + char buffer[512]; + + // + // test unlink + // + err = unlink("noexist"); + assert(err == -1); + assert(errno == ENOENT); + + err = unlink("dir-readonly"); + assert(err == -1); +#ifdef __linux__ + assert(errno == EISDIR); +#else + assert(errno == EPERM); +#endif + + err = unlink("dir-readonly/anotherfile"); + assert(err == -1); + assert(errno == EACCES); + + // try unlinking the symlink first to make sure + // we don't follow the link + err = unlink("file1-link"); + assert(!err); + err = access("file1", F_OK); + assert(!err); + err = access("file1-link", F_OK); + assert(err == -1); + + err = unlink("file"); + assert(!err); + err = access("file", F_OK); + assert(err == -1); + + // + // test rmdir + // + err = rmdir("noexist"); + assert(err == -1); + assert(errno == ENOENT); + + err = rmdir("file1"); + assert(err == -1); + assert(errno == ENOTDIR); + + err = rmdir("dir-readonly/anotherdir"); + assert(err == -1); + assert(errno == EACCES); + + err = rmdir("dir-full"); + assert(err == -1); + assert(errno == ENOTEMPTY); + + // test removing the cwd / root. The result isn't specified by + // POSIX, but Linux seems to set EBUSY in both cases. +#ifndef __APPLE__ + getcwd(buffer, sizeof(buffer)); + err = rmdir(buffer); + assert(err == -1); + assert(errno == EBUSY); +#endif + err = rmdir("/"); + assert(err == -1); +#ifdef __APPLE__ + assert(errno == EISDIR); +#else + assert(errno == EBUSY); +#endif + + err = rmdir("dir-empty-link"); + assert(err == -1); + assert(errno == ENOTDIR); + + err = rmdir("dir-empty"); + assert(!err); + err = access("dir-empty", F_OK); + assert(err == -1); + + puts("success"); } + +int main() { + atexit(cleanup); + signal(SIGABRT, cleanup); + setup(); + test(); + return EXIT_SUCCESS; +}
\ No newline at end of file diff --git a/tests/unistd/unlink.js b/tests/unistd/unlink.js deleted file mode 100644 index c2366080..00000000 --- a/tests/unistd/unlink.js +++ /dev/null @@ -1,7 +0,0 @@ -FS.createDevice('/', 'device', function() {}, function() {}); -FS.createDataFile('/', 'file', 'test', true, true); -FS.createDataFile('/', 'file-forbidden', 'test', true, false); -FS.createFolder('/', 'empty', true, true); -FS.createFolder('/', 'empty-forbidden', true, false); -FS.createFolder('/', 'full', true, true); -FS.createFolder('/full', 'junk', true, true); diff --git a/tests/unistd/unlink.out b/tests/unistd/unlink.out deleted file mode 100644 index f7a894cb..00000000 --- a/tests/unistd/unlink.out +++ /dev/null @@ -1,42 +0,0 @@ -access(/device) before: 0 -errno: 20 -access(/device) after rmdir: 0 -errno: 0 -access(/device) after unlink: -1 - -access(/file) before: 0 -errno: 20 -access(/file) after rmdir: 0 -errno: 0 -access(/file) after unlink: -1 - -access(/file-forbidden) before: 0 -errno: 13 -access(/file-forbidden) after rmdir: 0 -errno: 13 -access(/file-forbidden) after unlink: 0 - -access(/noexist) before: -1 -errno: 2 -access(/noexist) after rmdir: -1 -errno: 2 -access(/noexist) after unlink: -1 - -access(/empty) before: 0 -errno: 21 -access(/empty) after unlink: 0 -errno: 0 -access(/empty) after rmdir: -1 - -access(/empty-forbidden) before: 0 -errno: 21 -access(/empty-forbidden) after unlink: 0 -errno: 13 -access(/empty-forbidden) after rmdir: 0 - -access(/full) before: 0 -errno: 21 -access(/full) after unlink: 0 -errno: 90 -access(/full) after rmdir: 0 - |