diff --git a/ATTRIBUTIONS.md b/ATTRIBUTIONS.md index ef001c6e2..eff1434ab 100644 --- a/ATTRIBUTIONS.md +++ b/ATTRIBUTIONS.md @@ -12,6 +12,7 @@ These are the different project that we used as inspiration: - [greenwasm](https://github.com/Kimundi/greenwasm): for their [spectests framework](https://github.com/Kimundi/greenwasm/tree/master/greenwasm-spectest) - [wasmtime](/wasmtime): on their [mmap implementation](https://github.com/CraneStation/wasmtime/blob/3f24098edc81cd9bf0f877fb7fba018cad0f039e/lib/runtime/src/mmap.rs). - [stackoverflow](https://stackoverflow.com/a/45795699/1072990): to create an efficient HashMap with pair keys. +- [Emscripten](https://github.com/kripken/emscripten): for emtests test sources to ensure compatibility. We would love to hear from you if you think we can take inspiration from other projects that we haven't covered here. 😊 @@ -495,3 +496,108 @@ the License, but only in their entirety and only with respect to the Combined Software. ``` +### Emscripten +``` +Emscripten is available under 2 licenses, the MIT license and the +University of Illinois/NCSA Open Source License. + +Both are permissive open source licenses, with little if any +practical difference between them. + +The reason for offering both is that (1) the MIT license is +well-known, while (2) the University of Illinois/NCSA Open Source +License allows Emscripten's code to be integrated upstream into +LLVM, which uses that license, should the opportunity arise. + +The full text of both licenses follows. + +============================================================================== + +Copyright (c) 2010-2014 Emscripten authors, see AUTHORS file. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +============================================================================== + +Copyright (c) 2010-2014 Emscripten authors, see AUTHORS file. +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal with the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimers. + + Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimers + in the documentation and/or other materials provided with the + distribution. + + Neither the names of Mozilla, + nor the names of its contributors may be used to endorse + or promote products derived from this Software without specific prior + written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. + +============================================================================== + +This program uses portions of Node.js source code located in src/library_path.js, +in accordance with the terms of the MIT license. Node's license follows: + + """ + Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + """ + +The musl libc project is bundled in this repo, and it has the MIT license, see +system/lib/libc/musl/COPYRIGHT + +The third_party/ subdirectory contains code with other licenses. None of it is +used by default, but certain options use it (e.g., the optional closure compiler +flag will run closure compiler from third_party/). + +``` diff --git a/emtests/FS_exports.cpp b/emtests/FS_exports.cpp new file mode 100644 index 000000000..93f28fdc6 --- /dev/null +++ b/emtests/FS_exports.cpp @@ -0,0 +1,29 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +int main() { +#ifdef USE_FILES + if (fopen("nonexistend", "r")) { + puts("that was bad"); + return 1; + } +#endif +#ifdef DIRECT + EM_ASM({ + FS.createDataFile("/", "file.txt", [1, 2, 3]); + }); +#else + EM_ASM({ + Module["FS_createDataFile"]("/", "file.txt", [1, 2, 3]); + }); +#endif + EM_ASM({ + // use eval, so that the compiler can't see FS usage statically + eval('out("Data: " + JSON.stringify(MEMFS.getFileDataAsRegularArray(FS.root.contents["file.txt"])))'); + }); +} + diff --git a/emtests/FS_exports.txt b/emtests/FS_exports.txt new file mode 100644 index 000000000..04c28ed56 --- /dev/null +++ b/emtests/FS_exports.txt @@ -0,0 +1 @@ +Data: [1,2,3] diff --git a/emtests/FS_exports.wasm b/emtests/FS_exports.wasm new file mode 100644 index 000000000..f2a6b3e5a Binary files /dev/null and b/emtests/FS_exports.wasm differ diff --git a/emtests/FS_exports_2.txt b/emtests/FS_exports_2.txt new file mode 100644 index 000000000..04c28ed56 --- /dev/null +++ b/emtests/FS_exports_2.txt @@ -0,0 +1 @@ +Data: [1,2,3] diff --git a/emtests/FS_exports_assert.txt b/emtests/FS_exports_assert.txt new file mode 100644 index 000000000..063c2fdea --- /dev/null +++ b/emtests/FS_exports_assert.txt @@ -0,0 +1 @@ +You can force-include filesystem support with -s FORCE_FILESYSTEM=1 diff --git a/emtests/FS_exports_assert_2.txt b/emtests/FS_exports_assert_2.txt new file mode 100644 index 000000000..94eae0629 --- /dev/null +++ b/emtests/FS_exports_assert_2.txt @@ -0,0 +1 @@ +was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you diff --git a/emtests/closebitcasts.c b/emtests/closebitcasts.c new file mode 100644 index 000000000..1caeda2a1 --- /dev/null +++ b/emtests/closebitcasts.c @@ -0,0 +1,39 @@ +/* + * Copyright 2013 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main(int argc, char **argv) { + float x = argc%17, y = (argc+1)*(argc+2)*(argc+3)*(argc+4)*(argc*5); + y *= 1<<30; + y *= -13; + if (argc == 17) { x++; y--; } + int *xi = (int*)&x; + int *yi = (int*)&y; + int z = *xi - *yi; + while (z % 15) { + z++; + } + printf("!%d\n", z); + + double xd = x, yd = y; + yd = yd*yd; + yd = yd*yd; + int *xl = (int*)&xd; + int *xh = &((int*)&xd)[1]; + int *yl = (int*)&yd; + int *yh = &((int*)&yd)[1]; + int l = *xl - *yl; + int h = *xh - *yh; + while (l % 15) { + l++; + h += 3; + } + printf("%d,%d!\n", l, h); + return 0; +} + diff --git a/emtests/closebitcasts.txt b/emtests/closebitcasts.txt new file mode 100644 index 000000000..f97366cd2 --- /dev/null +++ b/emtests/closebitcasts.txt @@ -0,0 +1,2 @@ +!1787576325 +589815810,-179981561! diff --git a/emtests/closebitcasts.wasm b/emtests/closebitcasts.wasm new file mode 100644 index 000000000..452969dd8 Binary files /dev/null and b/emtests/closebitcasts.wasm differ diff --git a/emtests/dyncall.c b/emtests/dyncall.c new file mode 100644 index 000000000..2dedbe302 --- /dev/null +++ b/emtests/dyncall.c @@ -0,0 +1,29 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +void waka(int x, int y, int z) { + EM_ASM({ + out('received ' + [$0, $1, $2] + '.'); + }, x, y, z); +} + +int main() { + EM_ASM({ +#if EXPORTED + // test for additional things being exported + assert(Module['addFunction']); + assert(Module['lengthBytesUTF8']); + // the main test here + Module['dynCall']('viii', $0, [1, 4, 9]); +#else + dynCall('viii', $0, [1, 4, 9]); +#endif + }, &waka); +} + diff --git a/emtests/dyncall.txt b/emtests/dyncall.txt new file mode 100644 index 000000000..ed5226507 --- /dev/null +++ b/emtests/dyncall.txt @@ -0,0 +1 @@ +received 1,4,9. diff --git a/emtests/dyncall.wasm b/emtests/dyncall.wasm new file mode 100644 index 000000000..4e76b2fe6 Binary files /dev/null and b/emtests/dyncall.wasm differ diff --git a/emtests/dyncall_specific.c b/emtests/dyncall_specific.c new file mode 100644 index 000000000..cd9d91b7b --- /dev/null +++ b/emtests/dyncall_specific.c @@ -0,0 +1,33 @@ +/* + * Copyright 2018 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +void waka(int x, int y, int z) { + EM_ASM({ + out('received ' + [$0, $1, $2] + '.'); + }, x, y, z); +} + +int main() { + EM_ASM({ +#if DIRECT + dynCall_viii($0, 1, 4, 9); + return; +#endif +#if EXPORTED + Module['dynCall_viii']($0, 1, 4, 9); + return; +#endif +#if FROM_OUTSIDE + eval("Module['dynCall_viii'](" + $0 + ", 1, 4, 9)"); + return; +#endif + throw "no test mode"; + }, &waka); +} + diff --git a/emtests/dyncall_specific.txt b/emtests/dyncall_specific.txt new file mode 100644 index 000000000..ed5226507 --- /dev/null +++ b/emtests/dyncall_specific.txt @@ -0,0 +1 @@ +received 1,4,9. diff --git a/emtests/dyncall_specific.wasm b/emtests/dyncall_specific.wasm new file mode 100644 index 000000000..75f051601 Binary files /dev/null and b/emtests/dyncall_specific.wasm differ diff --git a/emtests/emscripten_get_compiler_setting.c b/emtests/emscripten_get_compiler_setting.c new file mode 100644 index 000000000..eee3a7dcd --- /dev/null +++ b/emtests/emscripten_get_compiler_setting.c @@ -0,0 +1,18 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + printf("QS: %d\n", emscripten_get_compiler_setting("QUANTUM_SIZE")); + assert((unsigned)emscripten_get_compiler_setting("OPT_LEVEL") <= 3); + assert((unsigned)emscripten_get_compiler_setting("DEBUG_LEVEL") <= 4); + printf("EV: %s\n", (char*)emscripten_get_compiler_setting("EMSCRIPTEN_VERSION")); +} + diff --git a/emtests/emscripten_get_compiler_setting.out b/emtests/emscripten_get_compiler_setting.out new file mode 100644 index 000000000..cd5200647 --- /dev/null +++ b/emtests/emscripten_get_compiler_setting.out @@ -0,0 +1,2 @@ +QS: 4 +EV: waka diff --git a/emtests/emscripten_get_compiler_setting.wasm b/emtests/emscripten_get_compiler_setting.wasm new file mode 100644 index 000000000..19545ff7c Binary files /dev/null and b/emtests/emscripten_get_compiler_setting.wasm differ diff --git a/emtests/fnmatch.c b/emtests/fnmatch.c new file mode 100644 index 000000000..4b3bf9385 --- /dev/null +++ b/emtests/fnmatch.c @@ -0,0 +1,86 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +// Begin test_fnmatch.cpp +#include +#include +#include +#include + +using namespace std; + +class TestCase { +public: + TestCase(const string& pattern, const string& testString, int flags, int expected) : + pattern(pattern), + testString(testString), + flags(flags), + expected(expected) + {} + string pattern; + string testString; + int flags; + int expected; +}; + +int main() +{ + vector testCases; + + testCases.push_back(TestCase("*","anything",0,0)); + testCases.push_back(TestCase("*.txt","readme.txt",0,0)); + testCases.push_back(TestCase("*.txt","readme.info",0,FNM_NOMATCH)); + testCases.push_back(TestCase("*.t?t","readme.txt",0,0)); + testCases.push_back(TestCase("*.t?t","readme.tot",0,0)); + testCases.push_back(TestCase("*.t?t","readme.txxt",0,FNM_NOMATCH)); + testCases.push_back(TestCase("[a-g]1","c1",0,0)); + testCases.push_back(TestCase("[a-g]1","i1",0,FNM_NOMATCH)); + testCases.push_back(TestCase("[!a-g]1","i1",0,0)); + testCases.push_back(TestCase("a\\*","anything",0,FNM_NOMATCH)); + testCases.push_back(TestCase("a\\*","a*",0,0)); + testCases.push_back(TestCase("a\\*","a*",FNM_NOESCAPE,FNM_NOMATCH)); + testCases.push_back(TestCase("a\\*","a\\*",FNM_NOESCAPE,0)); + testCases.push_back(TestCase("*readme","/etc/readme",0,0)); + testCases.push_back(TestCase("*readme","/etc/readme",FNM_PATHNAME,FNM_NOMATCH)); + testCases.push_back(TestCase("/*/readme","/etc/readme",FNM_PATHNAME,0)); + testCases.push_back(TestCase("*readme","/etc/.readme",0,0)); + testCases.push_back(TestCase("*readme",".readme",FNM_PERIOD,FNM_NOMATCH)); + testCases.push_back(TestCase("*.readme","/etc/.readme",FNM_PERIOD,0)); + testCases.push_back(TestCase("*.readme","/etc/.readme",FNM_PERIOD|FNM_PATHNAME,FNM_NOMATCH)); + testCases.push_back(TestCase("/*/.readme","/etc/.readme",FNM_PERIOD|FNM_PATHNAME,0)); + testCases.push_back(TestCase("ReAdME","readme",0,FNM_NOMATCH)); + + bool pass = true; + + for (vector::const_iterator it = testCases.begin(); it != testCases.end(); ++it) + { + int result = fnmatch(it->pattern.c_str(), it->testString.c_str(), it->flags); + if (result == it->expected) + cout << "Pass: "; + else + { + cout << "Fail: "; + pass = false; + } + + cout << "fnmatch(" << it->pattern << ", " << it->testString << ", " + << it->flags << ") returned " << result << ", expected " + << it->expected << endl; + } + + if (pass) + { + cout << "All tests passed." << endl; + return 0; + } + else + { + cout << "Some tests failed." << endl; + return 1; + } +} + diff --git a/emtests/fnmatch.out b/emtests/fnmatch.out new file mode 100644 index 000000000..303f7449b --- /dev/null +++ b/emtests/fnmatch.out @@ -0,0 +1,23 @@ +Pass: fnmatch(*, anything, 0) returned 0, expected 0 +Pass: fnmatch(*.txt, readme.txt, 0) returned 0, expected 0 +Pass: fnmatch(*.txt, readme.info, 0) returned 1, expected 1 +Pass: fnmatch(*.t?t, readme.txt, 0) returned 0, expected 0 +Pass: fnmatch(*.t?t, readme.tot, 0) returned 0, expected 0 +Pass: fnmatch(*.t?t, readme.txxt, 0) returned 1, expected 1 +Pass: fnmatch([a-g]1, c1, 0) returned 0, expected 0 +Pass: fnmatch([a-g]1, i1, 0) returned 1, expected 1 +Pass: fnmatch([!a-g]1, i1, 0) returned 0, expected 0 +Pass: fnmatch(a\*, anything, 0) returned 1, expected 1 +Pass: fnmatch(a\*, a*, 0) returned 0, expected 0 +Pass: fnmatch(a\*, a*, 2) returned 1, expected 1 +Pass: fnmatch(a\*, a\*, 2) returned 0, expected 0 +Pass: fnmatch(*readme, /etc/readme, 0) returned 0, expected 0 +Pass: fnmatch(*readme, /etc/readme, 1) returned 1, expected 1 +Pass: fnmatch(/*/readme, /etc/readme, 1) returned 0, expected 0 +Pass: fnmatch(*readme, /etc/.readme, 0) returned 0, expected 0 +Pass: fnmatch(*readme, .readme, 4) returned 1, expected 1 +Pass: fnmatch(*.readme, /etc/.readme, 4) returned 0, expected 0 +Pass: fnmatch(*.readme, /etc/.readme, 5) returned 1, expected 1 +Pass: fnmatch(/*/.readme, /etc/.readme, 5) returned 0, expected 0 +Pass: fnmatch(ReAdME, readme, 0) returned 1, expected 1 +All tests passed. diff --git a/emtests/getValue_setValue.cpp b/emtests/getValue_setValue.cpp new file mode 100644 index 000000000..af60382e0 --- /dev/null +++ b/emtests/getValue_setValue.cpp @@ -0,0 +1,21 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +int main() { +#ifdef DIRECT + EM_ASM({ + setValue(8, 1234, 'i32'); + out('|' + getValue(8, 'i32') + '|'); + }); +#else + EM_ASM({ + Module['setValue'](8, 1234, 'i32'); + out('|' + Module['getValue'](8, 'i32') + '|'); + }); +#endif +} + diff --git a/emtests/getValue_setValue.txt b/emtests/getValue_setValue.txt new file mode 100644 index 000000000..7cfd2285f --- /dev/null +++ b/emtests/getValue_setValue.txt @@ -0,0 +1 @@ +|1234| diff --git a/emtests/getValue_setValue.wasm b/emtests/getValue_setValue.wasm new file mode 100644 index 000000000..94767d564 Binary files /dev/null and b/emtests/getValue_setValue.wasm differ diff --git a/emtests/getValue_setValue_assert.txt b/emtests/getValue_setValue_assert.txt new file mode 100644 index 000000000..794dde0b1 --- /dev/null +++ b/emtests/getValue_setValue_assert.txt @@ -0,0 +1 @@ +'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ) diff --git a/emtests/ignores.txt b/emtests/ignores.txt new file mode 100644 index 000000000..e71e7b546 --- /dev/null +++ b/emtests/ignores.txt @@ -0,0 +1,72 @@ +test_ccall +test_demangle_stacks +emscripten_get_compiler_setting +fs_exports +getvalue_setvalue +legacy_exported_runtime_numbers +modularize_closure_pre +stackalloc +test_demangle_stacks_noassert +test_dlmalloc_partial_2 +test_em_asm +test_em_asm_2 +test_em_asm_parameter_pack +test_em_asm_signatures +test_em_asm_unicode +test_em_asm_unused_arguments +test_em_js +test_emscripten_api +test_exceptions_2 +test_exceptions_multi +test_exceptions_std +test_exceptions_white_list +test_fast_math +test_float_builtins +test_getopt +test_getopt_long +test_getloadavg +test_i16_emcc_intrinsic +test_i64 +test_i64_7z +test_i64_varargs +test_llvm_intrinsics +test_longjmp2 +test_longjmp3 +test_longjmp4 +test_longjmp +test_longjmp_exc +test_longjmp_funcptr +test_longjmp_repeat +test_longjmp_stacked +test_longjmp_throw +test_longjmp_unwind +test_lower_intrinsics +test_main_thread_async_em_asm +test_mainenv +test_mathfuncptr +test_memcpy_memcmp +test_mmap +test_perrar +test_poll +test_posixtime +test_siglongjmp +test_sscanf_hex +test_sscanf_whitespace +test_sscanf_other_whitespace +test_sscanf_skip +test_stack_varargs +test_stack_void +test_statvfs +test_strings +test_strptime_days +test_strtold +test_tracing +test_uname +test_utf +test_varargs_multi +test_varargs +test_zero_multiplication +test_strftime +test_wprintf +test_std_cout_new +test_strptime_reentrant \ No newline at end of file diff --git a/emtests/legacy_exported_runtime_numbers.cpp b/emtests/legacy_exported_runtime_numbers.cpp new file mode 100644 index 000000000..24bcced17 --- /dev/null +++ b/emtests/legacy_exported_runtime_numbers.cpp @@ -0,0 +1,19 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +int main() { +#ifdef DIRECT + EM_ASM({ + out('|' + ALLOC_DYNAMIC + '|'); + }); +#else + EM_ASM({ + out('|' + Module['ALLOC_DYNAMIC'] + '|'); + }); +#endif +} + diff --git a/emtests/legacy_exported_runtime_numbers.txt b/emtests/legacy_exported_runtime_numbers.txt new file mode 100644 index 000000000..a12955e26 --- /dev/null +++ b/emtests/legacy_exported_runtime_numbers.txt @@ -0,0 +1 @@ +|3| diff --git a/emtests/legacy_exported_runtime_numbers.wasm b/emtests/legacy_exported_runtime_numbers.wasm new file mode 100644 index 000000000..fc7597271 Binary files /dev/null and b/emtests/legacy_exported_runtime_numbers.wasm differ diff --git a/emtests/legacy_exported_runtime_numbers_assert.txt b/emtests/legacy_exported_runtime_numbers_assert.txt new file mode 100644 index 000000000..ba94bfa3b --- /dev/null +++ b/emtests/legacy_exported_runtime_numbers_assert.txt @@ -0,0 +1 @@ +'ALLOC_DYNAMIC' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ) diff --git a/emtests/modularize_closure_pre.c b/emtests/modularize_closure_pre.c new file mode 100644 index 000000000..7c4244905 --- /dev/null +++ b/emtests/modularize_closure_pre.c @@ -0,0 +1,15 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main() { + EM_ASM({ + out(Module['on_module']); + }); +} + diff --git a/emtests/modularize_closure_pre.out b/emtests/modularize_closure_pre.out new file mode 100644 index 000000000..483e04882 --- /dev/null +++ b/emtests/modularize_closure_pre.out @@ -0,0 +1 @@ +waka diff --git a/emtests/modularize_closure_pre.wasm b/emtests/modularize_closure_pre.wasm new file mode 100644 index 000000000..60bc839aa Binary files /dev/null and b/emtests/modularize_closure_pre.wasm differ diff --git a/emtests/stackAlloc.cpp b/emtests/stackAlloc.cpp new file mode 100644 index 000000000..d01738040 --- /dev/null +++ b/emtests/stackAlloc.cpp @@ -0,0 +1,35 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +int main() { + EM_ASM({ + var size = 128; + var before; + before = stackSave(); + var x = stackAlloc(size); + var y = stackAlloc(size); + var direction = y > x ? 1 : -1; + assert(x % 16 == 0, "allocation must have 16-byte alignment"); + assert(x == Math.min(before, before + direction*size), "allocation must return the start of the range allocated"); + var z = stackAlloc(size); + assert(x != y && y != z && x != z, "allocations must be unique"); + assert((y - x)*(z - y) > 0, "allocations must be in the same direction"); + // no overlaps + function notInRange(value, begin, end) { + function errormsg() { return value + " must not be in the range (" + begin + ", " + end + "]"; } + if (begin < end) assert(!(value >= begin && value < end), errormsg()); + else assert(!(value <= begin && value > end), errormsg()); + } + notInRange(x, y, y + direction*size); + notInRange(x, z, z + direction*size); + notInRange(y, x, x + direction*size); + notInRange(y, z, z + direction*size); + notInRange(z, x, x + direction*size); + notInRange(z, y, y + direction*size); + out('ok.'); + }); +} diff --git a/emtests/stackAlloc.txt b/emtests/stackAlloc.txt new file mode 100644 index 000000000..90b5016ef --- /dev/null +++ b/emtests/stackAlloc.txt @@ -0,0 +1 @@ +ok. diff --git a/emtests/stackAlloc.wasm b/emtests/stackAlloc.wasm new file mode 100644 index 000000000..9a7ac5ff4 Binary files /dev/null and b/emtests/stackAlloc.wasm differ diff --git a/emtests/stack_overflow.cpp b/emtests/stack_overflow.cpp new file mode 100644 index 000000000..1e0a6f259 --- /dev/null +++ b/emtests/stack_overflow.cpp @@ -0,0 +1,39 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +void recurse(unsigned int x); + +void act(volatile unsigned int *a) { + printf("act %d\n", *a); + unsigned int b = (int)(intptr_t)(alloca(*a)); + if (b < *a) *a--; + recurse(*a); +} + +void recurse(volatile unsigned int x) { + printf("recurse %d\n", x); + volatile unsigned int a = x; + volatile char buffer[1000*1000]; + buffer[x/2] = 0; + buffer[(x-1)/2] = 0; + EM_ASM({}); + if (x*x < x) { + act(&a); + if (a < x) x = a; + x--; + } + x += buffer[x/2]; + if (x > 0) recurse(x-1); +} + +int main() { + recurse(1000*1000); +} + diff --git a/emtests/stack_overflow.wasm b/emtests/stack_overflow.wasm new file mode 100644 index 000000000..32192ef0d Binary files /dev/null and b/emtests/stack_overflow.wasm differ diff --git a/emtests/test_addr_of_stacked.c b/emtests/test_addr_of_stacked.c new file mode 100644 index 000000000..583b209df --- /dev/null +++ b/emtests/test_addr_of_stacked.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +void alter(int *y) { *y += 5; } +int main() { + int x = 2; + alter(&x); + printf("*%d*\n", x); + return 0; +} diff --git a/emtests/test_addr_of_stacked.out b/emtests/test_addr_of_stacked.out new file mode 100644 index 000000000..2b8cf4a17 --- /dev/null +++ b/emtests/test_addr_of_stacked.out @@ -0,0 +1 @@ +*7* \ No newline at end of file diff --git a/emtests/test_addr_of_stacked.wasm b/emtests/test_addr_of_stacked.wasm new file mode 100644 index 000000000..9891f501c Binary files /dev/null and b/emtests/test_addr_of_stacked.wasm differ diff --git a/emtests/test_alloca.c b/emtests/test_alloca.c new file mode 100644 index 000000000..cd090be94 --- /dev/null +++ b/emtests/test_alloca.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main(int argc, char **argv) { + char *pc, *pc2; + assert(argc == 1); + pc = (char *)alloca(4+argc); + assert(((int)pc) % 4 == 0); + pc2 = (char *)alloca(4+argc); + assert(((int)pc2) % 4 == 0); + printf("z:%d*%d*%d*\n", (int)pc > 0, (int)pc, (int)pc2); + return 0; +} diff --git a/emtests/test_alloca.out b/emtests/test_alloca.out new file mode 100644 index 000000000..37de3d6bc --- /dev/null +++ b/emtests/test_alloca.out @@ -0,0 +1 @@ +z:1* \ No newline at end of file diff --git a/emtests/test_alloca.wasm b/emtests/test_alloca.wasm new file mode 100644 index 000000000..7f0b1d031 Binary files /dev/null and b/emtests/test_alloca.wasm differ diff --git a/emtests/test_alloca_stack.c b/emtests/test_alloca_stack.c new file mode 100644 index 000000000..738a1c255 --- /dev/null +++ b/emtests/test_alloca_stack.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +// We should not blow up the stack with numerous allocas +#include +#include + +int func(int i) { + char *pc = (char *)alloca(100); + *pc = i; + (*pc)++; + return (*pc) % 10; +} +int main() { + int total = 0; + for (int i = 0; i < 1024 * 1024; i++) total += func(i); + printf("ok:%d*\n", total); + return 0; +} diff --git a/emtests/test_alloca_stack.out b/emtests/test_alloca_stack.out new file mode 100644 index 000000000..d6a90d4e8 --- /dev/null +++ b/emtests/test_alloca_stack.out @@ -0,0 +1 @@ +ok:-32768* \ No newline at end of file diff --git a/emtests/test_alloca_stack.wasm b/emtests/test_alloca_stack.wasm new file mode 100644 index 000000000..806336573 Binary files /dev/null and b/emtests/test_alloca_stack.wasm differ diff --git a/emtests/test_array2.c b/emtests/test_array2.c new file mode 100644 index 000000000..18191971f --- /dev/null +++ b/emtests/test_array2.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +static const double grid[4][2] = {{-3 / 3., -1 / 3.}, + {+1 / 3., -3 / 3.}, + {-1 / 3., +3 / 3.}, + {+3 / 3., +1 / 3.}}; + +int main() { + for (int i = 0; i < 4; i++) + printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]); + printf("\n"); + return 0; +} diff --git a/emtests/test_array2.out b/emtests/test_array2.out new file mode 100644 index 000000000..a6ee88bbc --- /dev/null +++ b/emtests/test_array2.out @@ -0,0 +1 @@ +0:-1.00,-0.33 1:0.33,-1.00 2:-0.33,1.00 3:1.00,0.33 \ No newline at end of file diff --git a/emtests/test_array2.wasm b/emtests/test_array2.wasm new file mode 100644 index 000000000..43fd4fdfe Binary files /dev/null and b/emtests/test_array2.wasm differ diff --git a/emtests/test_array2b.c b/emtests/test_array2b.c new file mode 100644 index 000000000..fa054e9d4 --- /dev/null +++ b/emtests/test_array2b.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +static const struct { + unsigned char left; + unsigned char right; +} prioritah[] = {{6, 6}, {6, 6}, {7, 95}, {7, 7}}; + +int main() { + printf("*%d,%d\n", prioritah[1].left, prioritah[1].right); + printf("%d,%d*\n", prioritah[2].left, prioritah[2].right); + return 0; +} diff --git a/emtests/test_array2b.out b/emtests/test_array2b.out new file mode 100644 index 000000000..422896dcc --- /dev/null +++ b/emtests/test_array2b.out @@ -0,0 +1,2 @@ +*6,6 +7,95* \ No newline at end of file diff --git a/emtests/test_array2b.wasm b/emtests/test_array2b.wasm new file mode 100644 index 000000000..01d5a5aed Binary files /dev/null and b/emtests/test_array2b.wasm differ diff --git a/emtests/test_assert.c b/emtests/test_assert.c new file mode 100644 index 000000000..8545e0778 --- /dev/null +++ b/emtests/test_assert.c @@ -0,0 +1,14 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { + assert(1 == true); // pass + assert(1 == false); // fail + return 0; +} diff --git a/emtests/test_assert.out b/emtests/test_assert.out new file mode 100644 index 000000000..870c1784e --- /dev/null +++ b/emtests/test_assert.out @@ -0,0 +1 @@ +Assertion failed: 1 == false \ No newline at end of file diff --git a/emtests/test_atexit.c b/emtests/test_atexit.c new file mode 100644 index 000000000..bb83b3924 --- /dev/null +++ b/emtests/test_atexit.c @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +extern "C" { +extern int __cxa_thread_atexit(void (*dtor)(void *), void *obj, void *dso_symbol); +extern int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, void *dso_symbol); +} + +static void cleanA() { printf("A\n"); } +static void cleanB() { printf("B\n"); } +static void cleanCarg(void* x) { printf("C %d\n", (int)x); } + +int main() { + atexit(cleanA); + atexit(cleanB); + __cxa_thread_atexit(cleanCarg, (void*)100, NULL); + __cxa_thread_atexit_impl(cleanCarg, (void*)234, NULL); + return 0; +} diff --git a/emtests/test_atexit.out b/emtests/test_atexit.out new file mode 100644 index 000000000..c1e26b0e2 --- /dev/null +++ b/emtests/test_atexit.out @@ -0,0 +1,4 @@ +C 234 +C 100 +B +A diff --git a/emtests/test_atoX.c b/emtests/test_atoX.c new file mode 100644 index 000000000..9cf360a99 --- /dev/null +++ b/emtests/test_atoX.c @@ -0,0 +1,47 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + printf("%d*", atoi("")); + printf("%d*", atoi("a")); + printf("%d*", atoi(" b")); + printf("%d*", atoi(" c ")); + printf("%d*", atoi("6")); + printf("%d*", atoi(" 5")); + printf("%d*", atoi("4 ")); + printf("%d*", atoi("3 6")); + printf("%d*", atoi(" 3 7")); + printf("%d*", atoi("9 d")); + printf("%d\n", atoi(" 8 e")); + printf("%d*", (int)atol("")); + printf("%d*", (int)atol("a")); + printf("%d*", (int)atol(" b")); + printf("%d*", (int)atol(" c ")); + printf("%d*", (int)atol("6")); + printf("%d*", (int)atol(" 5")); + printf("%d*", (int)atol("4 ")); + printf("%d*", (int)atol("3 6")); + printf("%d*", (int)atol(" 3 7")); + printf("%d*", (int)atol("9 d")); + printf("%d\n", (int)atol(" 8 e")); + printf("%lld*", atoll("6294967296")); + printf("%lld*", atoll("")); + printf("%lld*", atoll("a")); + printf("%lld*", atoll(" b")); + printf("%lld*", atoll(" c ")); + printf("%lld*", atoll("6")); + printf("%lld*", atoll(" 5")); + printf("%lld*", atoll("4 ")); + printf("%lld*", atoll("3 6")); + printf("%lld*", atoll(" 3 7")); + printf("%lld*", atoll("9 d")); + printf("%lld\n", atoll(" 8 e")); + return 0; +} diff --git a/emtests/test_atoX.out b/emtests/test_atoX.out new file mode 100644 index 000000000..4b76d26d3 --- /dev/null +++ b/emtests/test_atoX.out @@ -0,0 +1,3 @@ +0*0*0*0*6*5*4*3*3*9*8 +0*0*0*0*6*5*4*3*3*9*8 +6294967296*0*0*0*0*6*5*4*3*3*9*8 diff --git a/emtests/test_atoX.wasm b/emtests/test_atoX.wasm new file mode 100644 index 000000000..00159075e Binary files /dev/null and b/emtests/test_atoX.wasm differ diff --git a/emtests/test_atomic.c b/emtests/test_atomic.c new file mode 100644 index 000000000..67a60b2cb --- /dev/null +++ b/emtests/test_atomic.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + int x = 10; + int y = __sync_add_and_fetch(&x, 5); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_fetch_and_add(&x, 5); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_lock_test_and_set(&x, 6); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_bool_compare_and_swap(&x, 9, 7); + printf("*%d,%d*\n", x, y); + y = __sync_bool_compare_and_swap(&x, 10, 7); + printf("*%d,%d*\n", x, y); + return 0; +} diff --git a/emtests/test_atomic.out b/emtests/test_atomic.out new file mode 100644 index 000000000..ed11bce08 --- /dev/null +++ b/emtests/test_atomic.out @@ -0,0 +1,5 @@ +*15,15* +*15,10* +*6,10* +*10,0* +*7,1* \ No newline at end of file diff --git a/emtests/test_atomic.wasm b/emtests/test_atomic.wasm new file mode 100644 index 000000000..949fc377e Binary files /dev/null and b/emtests/test_atomic.wasm differ diff --git a/emtests/test_atomic_cxx.cpp b/emtests/test_atomic_cxx.cpp new file mode 100644 index 000000000..b87896571 --- /dev/null +++ b/emtests/test_atomic_cxx.cpp @@ -0,0 +1,135 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +//------------------------------------------------------------------------------ +// test C++11 atomics +// compile native version with: +// clang -std=c++11 -Wno-format test_atomic_cxx.cpp +// compile emscripten version with: +// emcc -std=c++11 -Wno-format test_atomic_cxx.cpp +//------------------------------------------------------------------------------ +#include +#include + +template void test(TYPE mask0, TYPE mask1, TYPE mask2) { + typedef TYPE dog; + + const TYPE numMemoryOrders = 6; + std::memory_order memoryOrder[numMemoryOrders] = { + std::memory_order_relaxed, + std::memory_order_consume, + std::memory_order_acquire, + std::memory_order_release, + std::memory_order_acq_rel, + std::memory_order_seq_cst, + }; + + // test atomic + std::atomic atomicDog(5); + printf("atomic.is_lock_free(): %s\n", atomicDog.is_lock_free() ? "true" : "false"); + printf("atomic value: %lld\n", (long long)TYPE(atomicDog)); + + // test store/load + for (TYPE i = 0; i < numMemoryOrders; i++) { + atomicDog.store(i, memoryOrder[i]); + printf("store/load %lld: %lld\n", (long long)i, (long long)atomicDog.load(memoryOrder[i])); + } + + // test exchange + for (TYPE i = 0; i < numMemoryOrders; i++) { + TYPE old = atomicDog.exchange(i, memoryOrder[i]); + printf("exchange %lld: old=%lld new=%lld\n", (long long)i, (long long)old, (long long)TYPE(atomicDog)); + } + + // compare_exchange_weak + for (TYPE i = 0; i < numMemoryOrders; i++) { + bool success = atomicDog.compare_exchange_weak(i, i + 1, memoryOrder[i], memoryOrder[i]); + printf("compare_exchange_weak %lld: success = %s\n", (long long)i, success ? "true" : "false"); + } + + // compare_exchange_strong + for (TYPE i = 0; i < numMemoryOrders; i++) { + bool success = atomicDog.compare_exchange_strong(i, i + 1, memoryOrder[i], memoryOrder[i]); + printf("compare_exchange_strong %lld: success = %s\n", (long long)i, success ? "true" : "false"); + } + + // fetch_add + atomicDog = mask2; + for (TYPE i = 0; i < numMemoryOrders; i++) { + TYPE old = atomicDog.fetch_add(1, memoryOrder[i]); + printf("fetch_add %lld: old=%llx new=%llx\n", (long long)i, (long long)old, (long long)TYPE(atomicDog)); + } + + // fetch_sub + for (TYPE i = 0; i < numMemoryOrders; i++) { + TYPE old = atomicDog.fetch_sub(1, memoryOrder[i]); + printf("fetch_sub %lld: old=%llx new=%llx\n", (long long)i, (long long)old, (long long)TYPE(atomicDog)); + } + + // fetch_and + for (TYPE i = 0; i < numMemoryOrders; i++) { + atomicDog.store(mask0, memoryOrder[i]); + TYPE old = atomicDog.fetch_and((1<(0xFF, 0xF0, 0x0F); + printf("\n16 bits\n\n"); + test(0xFFFF, 0xF0F0, 0x0F0F); + printf("\n32 bits\n\n"); + test(0xFFFFFFFF, 0xF0F0F0F0, 0x0F0F0F0F); + printf("\n64 bits\n\n"); + test(0xFFFFFFFFFFFFFFFF, 0xF0F0F0F0F0F0F0F0, 0x0F0F0F0F0F0F0F0F); + + // test atomic_flag (should also have memory_orders, but probably doesn't matter + // to find the missing atomic functions) + std::atomic_flag af; + af.clear(); + bool b = af.test_and_set(); + printf("atomic_flag: %s\n", b ? "true" : "false"); + + printf("done.\n"); + return 0; +} + diff --git a/emtests/test_atomic_cxx.txt b/emtests/test_atomic_cxx.txt new file mode 100644 index 000000000..67b289950 --- /dev/null +++ b/emtests/test_atomic_cxx.txt @@ -0,0 +1,226 @@ + +8 bits + +atomic.is_lock_free(): true +atomic value: 5 +store/load 0: 0 +store/load 1: 1 +store/load 2: 2 +store/load 3: 3 +store/load 4: 4 +store/load 5: 5 +exchange 0: old=5 new=0 +exchange 1: old=0 new=1 +exchange 2: old=1 new=2 +exchange 3: old=2 new=3 +exchange 4: old=3 new=4 +exchange 5: old=4 new=5 +compare_exchange_weak 5: success = false +compare_exchange_strong 5: success = false +fetch_add 0: old=f new=10 +fetch_add 1: old=10 new=11 +fetch_add 2: old=11 new=12 +fetch_add 3: old=12 new=13 +fetch_add 4: old=13 new=14 +fetch_add 5: old=14 new=15 +fetch_sub 0: old=15 new=14 +fetch_sub 1: old=14 new=13 +fetch_sub 2: old=13 new=12 +fetch_sub 3: old=12 new=11 +fetch_sub 4: old=11 new=10 +fetch_sub 5: old=10 new=f +fetch_and 0: old=ff, new=1 +fetch_and 1: old=ff, new=2 +fetch_and 2: old=ff, new=4 +fetch_and 3: old=ff, new=8 +fetch_and 4: old=ff, new=10 +fetch_and 5: old=ff, new=20 +fetch_or 0: old=0, new=1 +fetch_or 1: old=1, new=3 +fetch_or 2: old=3, new=7 +fetch_or 3: old=7, new=f +fetch_or 4: old=f, new=1f +fetch_or 5: old=1f, new=3f +fetch_xor 0: old=0, new=1 +fetch_xor 1: old=1, new=3 +fetch_xor 2: old=3, new=7 +fetch_xor 3: old=7, new=f +fetch_xor 4: old=f, new=1f +fetch_xor 5: old=1f, new=3f +operator++: 1 +operator--: 0 +operator+=: 10 +operator-=: 5 +operator|=: ff +operator&=: f0 +operator^=: ff + +16 bits + +atomic.is_lock_free(): true +atomic value: 5 +store/load 0: 0 +store/load 1: 1 +store/load 2: 2 +store/load 3: 3 +store/load 4: 4 +store/load 5: 5 +exchange 0: old=5 new=0 +exchange 1: old=0 new=1 +exchange 2: old=1 new=2 +exchange 3: old=2 new=3 +exchange 4: old=3 new=4 +exchange 5: old=4 new=5 +compare_exchange_weak 5: success = false +compare_exchange_strong 5: success = false +fetch_add 0: old=f0f new=f10 +fetch_add 1: old=f10 new=f11 +fetch_add 2: old=f11 new=f12 +fetch_add 3: old=f12 new=f13 +fetch_add 4: old=f13 new=f14 +fetch_add 5: old=f14 new=f15 +fetch_sub 0: old=f15 new=f14 +fetch_sub 1: old=f14 new=f13 +fetch_sub 2: old=f13 new=f12 +fetch_sub 3: old=f12 new=f11 +fetch_sub 4: old=f11 new=f10 +fetch_sub 5: old=f10 new=f0f +fetch_and 0: old=ffff, new=1 +fetch_and 1: old=ffff, new=2 +fetch_and 2: old=ffff, new=4 +fetch_and 3: old=ffff, new=8 +fetch_and 4: old=ffff, new=10 +fetch_and 5: old=ffff, new=20 +fetch_or 0: old=0, new=1 +fetch_or 1: old=1, new=3 +fetch_or 2: old=3, new=7 +fetch_or 3: old=7, new=f +fetch_or 4: old=f, new=1f +fetch_or 5: old=1f, new=3f +fetch_xor 0: old=0, new=1 +fetch_xor 1: old=1, new=3 +fetch_xor 2: old=3, new=7 +fetch_xor 3: old=7, new=f +fetch_xor 4: old=f, new=1f +fetch_xor 5: old=1f, new=3f +operator++: 1 +operator--: 0 +operator+=: 10 +operator-=: 5 +operator|=: ffff +operator&=: f0f0 +operator^=: ffff + +32 bits + +atomic.is_lock_free(): true +atomic value: 5 +store/load 0: 0 +store/load 1: 1 +store/load 2: 2 +store/load 3: 3 +store/load 4: 4 +store/load 5: 5 +exchange 0: old=5 new=0 +exchange 1: old=0 new=1 +exchange 2: old=1 new=2 +exchange 3: old=2 new=3 +exchange 4: old=3 new=4 +exchange 5: old=4 new=5 +compare_exchange_weak 5: success = false +compare_exchange_strong 5: success = false +fetch_add 0: old=f0f0f0f new=f0f0f10 +fetch_add 1: old=f0f0f10 new=f0f0f11 +fetch_add 2: old=f0f0f11 new=f0f0f12 +fetch_add 3: old=f0f0f12 new=f0f0f13 +fetch_add 4: old=f0f0f13 new=f0f0f14 +fetch_add 5: old=f0f0f14 new=f0f0f15 +fetch_sub 0: old=f0f0f15 new=f0f0f14 +fetch_sub 1: old=f0f0f14 new=f0f0f13 +fetch_sub 2: old=f0f0f13 new=f0f0f12 +fetch_sub 3: old=f0f0f12 new=f0f0f11 +fetch_sub 4: old=f0f0f11 new=f0f0f10 +fetch_sub 5: old=f0f0f10 new=f0f0f0f +fetch_and 0: old=ffffffff, new=1 +fetch_and 1: old=ffffffff, new=2 +fetch_and 2: old=ffffffff, new=4 +fetch_and 3: old=ffffffff, new=8 +fetch_and 4: old=ffffffff, new=10 +fetch_and 5: old=ffffffff, new=20 +fetch_or 0: old=0, new=1 +fetch_or 1: old=1, new=3 +fetch_or 2: old=3, new=7 +fetch_or 3: old=7, new=f +fetch_or 4: old=f, new=1f +fetch_or 5: old=1f, new=3f +fetch_xor 0: old=0, new=1 +fetch_xor 1: old=1, new=3 +fetch_xor 2: old=3, new=7 +fetch_xor 3: old=7, new=f +fetch_xor 4: old=f, new=1f +fetch_xor 5: old=1f, new=3f +operator++: 1 +operator--: 0 +operator+=: 10 +operator-=: 5 +operator|=: ffffffff +operator&=: f0f0f0f0 +operator^=: ffffffff + +64 bits + +atomic.is_lock_free(): false +atomic value: 5 +store/load 0: 0 +store/load 1: 1 +store/load 2: 2 +store/load 3: 3 +store/load 4: 4 +store/load 5: 5 +exchange 0: old=5 new=0 +exchange 1: old=0 new=1 +exchange 2: old=1 new=2 +exchange 3: old=2 new=3 +exchange 4: old=3 new=4 +exchange 5: old=4 new=5 +compare_exchange_weak 5: success = false +compare_exchange_strong 5: success = false +fetch_add 0: old=f0f0f0f0f0f0f0f new=f0f0f0f0f0f0f10 +fetch_add 1: old=f0f0f0f0f0f0f10 new=f0f0f0f0f0f0f11 +fetch_add 2: old=f0f0f0f0f0f0f11 new=f0f0f0f0f0f0f12 +fetch_add 3: old=f0f0f0f0f0f0f12 new=f0f0f0f0f0f0f13 +fetch_add 4: old=f0f0f0f0f0f0f13 new=f0f0f0f0f0f0f14 +fetch_add 5: old=f0f0f0f0f0f0f14 new=f0f0f0f0f0f0f15 +fetch_sub 0: old=f0f0f0f0f0f0f15 new=f0f0f0f0f0f0f14 +fetch_sub 1: old=f0f0f0f0f0f0f14 new=f0f0f0f0f0f0f13 +fetch_sub 2: old=f0f0f0f0f0f0f13 new=f0f0f0f0f0f0f12 +fetch_sub 3: old=f0f0f0f0f0f0f12 new=f0f0f0f0f0f0f11 +fetch_sub 4: old=f0f0f0f0f0f0f11 new=f0f0f0f0f0f0f10 +fetch_sub 5: old=f0f0f0f0f0f0f10 new=f0f0f0f0f0f0f0f +fetch_and 0: old=ffffffffffffffff, new=1 +fetch_and 1: old=ffffffffffffffff, new=2 +fetch_and 2: old=ffffffffffffffff, new=4 +fetch_and 3: old=ffffffffffffffff, new=8 +fetch_and 4: old=ffffffffffffffff, new=10 +fetch_and 5: old=ffffffffffffffff, new=20 +fetch_or 0: old=0, new=1 +fetch_or 1: old=1, new=3 +fetch_or 2: old=3, new=7 +fetch_or 3: old=7, new=f +fetch_or 4: old=f, new=1f +fetch_or 5: old=1f, new=3f +fetch_xor 0: old=0, new=1 +fetch_xor 1: old=1, new=3 +fetch_xor 2: old=3, new=7 +fetch_xor 3: old=7, new=f +fetch_xor 4: old=f, new=1f +fetch_xor 5: old=1f, new=3f +operator++: 1 +operator--: 0 +operator+=: 10 +operator-=: 5 +operator|=: ffffffffffffffff +operator&=: f0f0f0f0f0f0f0f0 +operator^=: ffffffffffffffff +atomic_flag: false +done. diff --git a/emtests/test_atomic_cxx.wasm b/emtests/test_atomic_cxx.wasm new file mode 100644 index 000000000..c33d499c2 Binary files /dev/null and b/emtests/test_atomic_cxx.wasm differ diff --git a/emtests/test_bigarray.c b/emtests/test_bigarray.c new file mode 100644 index 000000000..aee3e5188 --- /dev/null +++ b/emtests/test_bigarray.c @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +// avoid "array initializer too large" errors +#include +#include + +#define SIZE (1024 * 100) +struct Struct { + char x; + int y; +}; +Struct buffy[SIZE]; + +int main() { + for (int i = 0; i < SIZE; i++) { + assert(buffy[i].x == 0 && buffy[i].y == 0); + } // we were zeroinitialized + for (int i = 0; i < SIZE; i++) { + buffy[i].x = i * i; + buffy[i].y = i * i * i; + } // we can save data + printf("*%d*\n", buffy[SIZE / 3].x); + return 0; +} diff --git a/emtests/test_bigarray.out b/emtests/test_bigarray.out new file mode 100644 index 000000000..33485c461 --- /dev/null +++ b/emtests/test_bigarray.out @@ -0,0 +1 @@ +*57* \ No newline at end of file diff --git a/emtests/test_bitfields.c b/emtests/test_bitfields.c new file mode 100644 index 000000000..4e62fd595 --- /dev/null +++ b/emtests/test_bitfields.c @@ -0,0 +1,27 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct bitty { + unsigned x : 1; + unsigned y : 1; + unsigned z : 1; +}; +int main() { + bitty b; + printf("*"); + for (int i = 0; i <= 1; i++) + for (int j = 0; j <= 1; j++) + for (int k = 0; k <= 1; k++) { + b.x = i; + b.y = j; + b.z = k; + printf("%d,%d,%d,", b.x, b.y, b.z); + } + printf("*\n"); + return 0; +} diff --git a/emtests/test_bitfields.out b/emtests/test_bitfields.out new file mode 100644 index 000000000..e121b181a --- /dev/null +++ b/emtests/test_bitfields.out @@ -0,0 +1 @@ +*0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,1,1,1,* \ No newline at end of file diff --git a/emtests/test_bsearch.c b/emtests/test_bsearch.c new file mode 100644 index 000000000..88b16fbb4 --- /dev/null +++ b/emtests/test_bsearch.c @@ -0,0 +1,52 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int cmp(const void* key, const void* member) { + return *(int*)key - *(int*)member; +} + +void printResult(int* needle, int* haystack, unsigned int len) { + void* result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp); + + if (result == NULL) { + printf("null\n"); + } else { + printf("%d\n", *(unsigned int*)result); + } +} + +int main() { + int a[] = {-2, -1, 0, 6, 7, 9}; + int b[] = {0, 1}; + + /* Find all keys that exist. */ + for (int i = 0; i < 6; i++) { + int val = a[i]; + + printResult(&val, a, 6); + } + + /* Keys that are covered by the range of the array but aren't in + * the array cannot be found. + */ + int v1 = 3; + int v2 = 8; + printResult(&v1, a, 6); + printResult(&v2, a, 6); + + /* Keys outside the range of the array cannot be found. */ + int v3 = -1; + int v4 = 2; + + printResult(&v3, b, 2); + printResult(&v4, b, 2); + + return 0; +} diff --git a/emtests/test_bsearch.out b/emtests/test_bsearch.out new file mode 100644 index 000000000..cc6a32050 --- /dev/null +++ b/emtests/test_bsearch.out @@ -0,0 +1,10 @@ +-2 +-1 +0 +6 +7 +9 +null +null +null +null \ No newline at end of file diff --git a/emtests/test_bsearch.wasm b/emtests/test_bsearch.wasm new file mode 100644 index 000000000..b55239263 Binary files /dev/null and b/emtests/test_bsearch.wasm differ diff --git a/emtests/test_bswap64.c b/emtests/test_bswap64.c new file mode 100644 index 000000000..37a5b1edf --- /dev/null +++ b/emtests/test_bswap64.c @@ -0,0 +1,55 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +#include +#include +#include + +typedef unsigned long long quint64; + +using namespace std; + +inline quint64 qbswap(quint64 source) { + return 0 | ((source & quint64(0x00000000000000ffLL)) << 56) | + ((source & quint64(0x000000000000ff00LL)) << 40) | + ((source & quint64(0x0000000000ff0000LL)) << 24) | + ((source & quint64(0x00000000ff000000LL)) << 8) | + ((source & quint64(0x000000ff00000000LL)) >> 8) | + ((source & quint64(0x0000ff0000000000LL)) >> 24) | + ((source & quint64(0x00ff000000000000LL)) >> 40) | + ((source & quint64(0xff00000000000000LL)) >> 56); +} + +int main() { + quint64 v = strtoull("4433ffeeddccbb00", NULL, 16); + printf("%lld\n", v); + + const string string64bitInt = "4433ffeeddccbb00"; + stringstream s(string64bitInt); + quint64 int64bitInt = 0; + printf("1\n"); + s >> hex >> int64bitInt; + printf("2\n"); + + stringstream out; + out << hex << qbswap(int64bitInt); + + cout << out.str() << endl; + cout << hex << int64bitInt << endl; + cout << string64bitInt << endl; + + if (out.str() != "bbccddeeff3344") { + cout << "Failed!" << endl; + } else { + cout << "Succeeded!" << endl; + } + + return 0; +} diff --git a/emtests/test_bswap64.out b/emtests/test_bswap64.out new file mode 100644 index 000000000..af129b5f1 --- /dev/null +++ b/emtests/test_bswap64.out @@ -0,0 +1,7 @@ +4914553019779824384 +1 +2 +bbccddeeff3344 +4433ffeeddccbb00 +4433ffeeddccbb00 +Succeeded! diff --git a/emtests/test_ccall.cpp b/emtests/test_ccall.cpp new file mode 100644 index 000000000..03f1d4cd7 --- /dev/null +++ b/emtests/test_ccall.cpp @@ -0,0 +1,54 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +extern "C" { +int get_int() { return 5; } +float get_float() { return 3.14; } +bool get_bool() { return true; } +const char *get_string() { return "hello world"; } +void print_int(int x) { printf("%d\n", x); } +void print_float(float x) { printf("%.2f\n", x); } +void print_string(char *x) { printf("%s\n", x); } +void print_bool(bool x) { + if (x) printf("true\n"); + else if (!x) printf("false\n"); +} +int multi(int x, float y, int z, char *str) { + if (x) puts(str); + return (x + y) * z; +} +int *pointer(int *in) { + printf("%d\n", *in); + static int ret = 21; + return &ret; +} + +// This test checks that ccall restores the stack correctly to whatever it was +// when ccall was entered. We save the stack pointer on the heap in stackChecker +// and verify that ccall restores it correctly. +struct test_struct { + int arg1, arg2, arg3; +}; +static int* stackChecker = 0; +__attribute__((noinline)) +int get_stack() { int i; return (int)&i; } +int uses_stack(test_struct* t1) { + if (stackChecker == 0) stackChecker = (int*)malloc(sizeof(int)); + *stackChecker = get_stack(); + EM_ASM(Module['ccall']('get_int', 'number')); + printf("stack is %s.\n", *stackChecker == get_stack() ? "ok" : "messed up"); + return 0; +} +void call_ccall_again() { + test_struct t1 = { 1, 2, 3 }; + uses_stack(&t1); +} +} + diff --git a/emtests/test_ccall.out b/emtests/test_ccall.out new file mode 100644 index 000000000..078566f0e --- /dev/null +++ b/emtests/test_ccall.out @@ -0,0 +1,30 @@ +* +number,5 +number,3.14 +boolean,true +string,hello world +12 +undefined +14.56 +undefined +true +undefined +cheez +undefined +arr-ay +undefined +arr-ay +undefined +more +number,10 +650 +number,21 +* +5 +atr +10 +bret +53 +* +stack is ok. +stack is ok. diff --git a/emtests/test_ccall.wasm b/emtests/test_ccall.wasm new file mode 100644 index 000000000..44ed2f4f4 Binary files /dev/null and b/emtests/test_ccall.wasm differ diff --git a/emtests/test_class.c b/emtests/test_class.c new file mode 100644 index 000000000..4daafe822 --- /dev/null +++ b/emtests/test_class.c @@ -0,0 +1,35 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct Random { + enum { + IM = 139968, + IA = 3877, + IC = 29573 + }; + Random() : last(42) {} + float get(float max = 1.0f) { + last = (last * IA + IC) % IM; + return max * last / IM; + } + + protected: + unsigned int last; +} rng1; +int main() { + Random rng2; + int count = 0; + for (int i = 0; i < 100; i++) { + float x1 = rng1.get(); + float x2 = rng2.get(); + printf("%f, %f\n", x1, x2); + if (x1 != x2) count += 1; + } + printf("*%d*\n", count); + return 0; +} diff --git a/emtests/test_class.out b/emtests/test_class.out new file mode 100644 index 000000000..a5e8240ea --- /dev/null +++ b/emtests/test_class.out @@ -0,0 +1 @@ +*0* \ No newline at end of file diff --git a/emtests/test_complex.c b/emtests/test_complex.c new file mode 100644 index 000000000..934324dbd --- /dev/null +++ b/emtests/test_complex.c @@ -0,0 +1,32 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char**argv) +{ + float complex z1 = 1.0 + 3.0 * I; + printf("value = real %.2f imag %.2f\n",creal(z1),cimag(z1)); + float abs_value = cabsf(z1); + printf("abs = %.2f\n",abs_value); + float complex z2 = conjf(z1); + printf("value = real %.2f imag %.2f\n",creal(z2),cimag(z2)); + float complex z3 = cexpf(z1); + printf("value = real %.2f imag %.2f\n",creal(z3),cimag(z3)); + float complex z4 = conj(z1); + printf("value = real %.2f imag %.2f\n",creal(z4),cimag(z4)); + float complex z5 = cargf(z1); + printf("value = real %.2f imag %.2f\n",creal(z5),cimag(z5)); + float complex z6 = 0.5 + 0.5 * I; + float complex z7 = 0.5 - 0.5 * I; + float complex z8 = z6 * z7; + printf("value = real %.2f imag %.2f\n",creal(z8),cimag(z8)); + float complex z9 = z6 / z7; + printf("value = real %.2f imag %.2f\n",creal(z9),cimag(z9)); + return 0; +} diff --git a/emtests/test_complex.out b/emtests/test_complex.out new file mode 100644 index 000000000..6f08f2010 --- /dev/null +++ b/emtests/test_complex.out @@ -0,0 +1,8 @@ +value = real 1.00 imag 3.00 +abs = 3.16 +value = real 1.00 imag -3.00 +value = real -2.69 imag 0.38 +value = real 1.00 imag -3.00 +value = real 1.25 imag 0.00 +value = real 0.50 imag 0.00 +value = real 0.00 imag 1.00 diff --git a/emtests/test_complex.wasm b/emtests/test_complex.wasm new file mode 100644 index 000000000..1a0b5d500 Binary files /dev/null and b/emtests/test_complex.wasm differ diff --git a/emtests/test_constglobalstructs.c b/emtests/test_constglobalstructs.c new file mode 100644 index 000000000..2badbc3f3 --- /dev/null +++ b/emtests/test_constglobalstructs.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct IUB { + int c; + double p; + unsigned int pi; +}; + +IUB iub[] = {{'a', 0.27, 5}, {'c', 0.15, 4}, {'g', 0.12, 3}, {'t', 0.27, 2}, }; + +const unsigned char faceedgesidx[6][4] = {{4, 5, 8, 10}, + {6, 7, 9, 11}, + {0, 2, 8, 9}, + {1, 3, 10, 11}, + {0, 1, 4, 6}, + {2, 3, 5, 7}, }; + +int main(int argc, const char *argv[]) { + printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p * 100), iub[2].pi, + faceedgesidx[3][2]); + return 0; +} diff --git a/emtests/test_constglobalstructs.out b/emtests/test_constglobalstructs.out new file mode 100644 index 000000000..1d530091a --- /dev/null +++ b/emtests/test_constglobalstructs.out @@ -0,0 +1 @@ +*97,15,3,10* \ No newline at end of file diff --git a/emtests/test_conststructs.c b/emtests/test_conststructs.c new file mode 100644 index 000000000..ce8e29d92 --- /dev/null +++ b/emtests/test_conststructs.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct IUB { + int c; + double p; + unsigned int pi; +}; + +int main(int argc, const char *argv[]) { + int before = 70; + IUB iub[] = {{'a', 0.3029549426680, 5}, + {'c', 0.15, 4}, + {'g', 0.12, 3}, + {'t', 0.27, 2}, }; + int after = 90; + printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p * 100), + iub[2].pi, int(iub[0].p * 10000), after); + return 0; +} diff --git a/emtests/test_conststructs.out b/emtests/test_conststructs.out new file mode 100644 index 000000000..af6000611 --- /dev/null +++ b/emtests/test_conststructs.out @@ -0,0 +1 @@ +*70,97,15,3,3029,90* \ No newline at end of file diff --git a/emtests/test_copyop.c b/emtests/test_copyop.c new file mode 100644 index 000000000..bbbae3420 --- /dev/null +++ b/emtests/test_copyop.c @@ -0,0 +1,41 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +struct vec { + double x, y, z; + vec() : x(0), y(0), z(0) {}; + vec(const double a, const double b, const double c) : x(a), y(b), z(c) {}; +}; + +struct basis { + vec a, b, c; + basis(const vec& v) { + a = v; // should not touch b! + printf("*%.2f,%.2f,%.2f*\n", b.x, b.y, b.z); + } +}; + +int main() { + basis B(vec(1, 0, 0)); + + // Part 2: similar problem with memset and memmove + int x = 1, y = 77, z = 2; + memset((void*)&x, 0, sizeof(int)); + memset((void*)&z, 0, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + memcpy((void*)&x, (void*)&z, sizeof(int)); + memcpy((void*)&z, (void*)&x, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + memmove((void*)&x, (void*)&z, sizeof(int)); + memmove((void*)&z, (void*)&x, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + return 0; +} diff --git a/emtests/test_copyop.out b/emtests/test_copyop.out new file mode 100644 index 000000000..17bde9e7a --- /dev/null +++ b/emtests/test_copyop.out @@ -0,0 +1,4 @@ +*0.00,0.00,0.00* +*0,77,0* +*0,77,0* +*0,77,0* \ No newline at end of file diff --git a/emtests/test_cxx03_do_run.c b/emtests/test_cxx03_do_run.c new file mode 100644 index 000000000..09ac4b759 --- /dev/null +++ b/emtests/test_cxx03_do_run.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +#if __cplusplus != 199711L +#error By default, if no -std is specified, emscripten should be compiling with -std=c++03! +#endif + +int main(int argc, const char *argv[]) { + printf("Hello world!\n"); + return 0; +} diff --git a/emtests/test_cxx03_do_run.out b/emtests/test_cxx03_do_run.out new file mode 100644 index 000000000..6769dd60b --- /dev/null +++ b/emtests/test_cxx03_do_run.out @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/emtests/test_demangle_stacks.cpp b/emtests/test_demangle_stacks.cpp new file mode 100644 index 000000000..b70a84d11 --- /dev/null +++ b/emtests/test_demangle_stacks.cpp @@ -0,0 +1,31 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +#include + +namespace NameSpace { +class Class { + public: + __attribute__((noinline)) + void Aborter(double x, char y, int *z) { + volatile int w = 1; + if (w) { + EM_ASM({ + out(stackTrace()); + }); + abort(); + } + } +}; +} + +int main(int argc, char **argv) { + NameSpace::Class c; + c.Aborter(1.234, 'a', NULL); + return 0; +} diff --git a/emtests/test_demangle_stacks.out b/emtests/test_demangle_stacks.out new file mode 100644 index 000000000..d1c61b458 --- /dev/null +++ b/emtests/test_demangle_stacks.out @@ -0,0 +1 @@ +NameSpace::Class::Aborter(double, char, int*) \ No newline at end of file diff --git a/emtests/test_demangle_stacks.wasm b/emtests/test_demangle_stacks.wasm new file mode 100644 index 000000000..1c9b6bfea Binary files /dev/null and b/emtests/test_demangle_stacks.wasm differ diff --git a/emtests/test_demangle_stacks_noassert.cpp b/emtests/test_demangle_stacks_noassert.cpp new file mode 100644 index 000000000..3918767ec --- /dev/null +++ b/emtests/test_demangle_stacks_noassert.cpp @@ -0,0 +1,26 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +namespace NameSpace { +class Class { + public: + __attribute__((noinline)) + void Aborter(double x, char y, int *z) { + volatile int w = 1; + if (w) { + abort(); + } + } +}; +} + +int main(int argc, char **argv) { + NameSpace::Class c; + c.Aborter(1.234, 'a', NULL); + return 0; +} diff --git a/emtests/test_demangle_stacks_noassert.out b/emtests/test_demangle_stacks_noassert.out new file mode 100644 index 000000000..43e50f062 --- /dev/null +++ b/emtests/test_demangle_stacks_noassert.out @@ -0,0 +1 @@ +Build with -s ASSERTIONS=1 for more info. diff --git a/emtests/test_demangle_stacks_noassert.wasm b/emtests/test_demangle_stacks_noassert.wasm new file mode 100644 index 000000000..c9b033125 Binary files /dev/null and b/emtests/test_demangle_stacks_noassert.wasm differ diff --git a/emtests/test_direct_string_constant_usage.c b/emtests/test_direct_string_constant_usage.c new file mode 100644 index 000000000..267b13f1a --- /dev/null +++ b/emtests/test_direct_string_constant_usage.c @@ -0,0 +1,16 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +template +void printText(const char (&text)[i]) { + std::cout << text; +} +int main() { + printText("some string constant"); + return 0; +} diff --git a/emtests/test_direct_string_constant_usage.out b/emtests/test_direct_string_constant_usage.out new file mode 100644 index 000000000..ddb4b681d --- /dev/null +++ b/emtests/test_direct_string_constant_usage.out @@ -0,0 +1 @@ +some string constant \ No newline at end of file diff --git a/emtests/test_dlfcn_self.c b/emtests/test_dlfcn_self.c new file mode 100644 index 000000000..c00cbea31 --- /dev/null +++ b/emtests/test_dlfcn_self.c @@ -0,0 +1,30 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int EMSCRIPTEN_KEEPALIVE global = 123; + +extern "C" EMSCRIPTEN_KEEPALIVE void foo(int x) { + printf("%d\n", x); +} + +extern "C" EMSCRIPTEN_KEEPALIVE void repeatable() { + void* self = dlopen(NULL, RTLD_LAZY); + int* global_ptr = (int*)dlsym(self, "global"); + void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo"); + foo_ptr(*global_ptr); + dlclose(self); +} + +int main() { + repeatable(); + repeatable(); + return 0; +} diff --git a/emtests/test_dlfcn_self.out b/emtests/test_dlfcn_self.out new file mode 100644 index 000000000..4ca9456b0 --- /dev/null +++ b/emtests/test_dlfcn_self.out @@ -0,0 +1,2 @@ +123 +123 \ No newline at end of file diff --git a/emtests/test_dlmalloc_partial_2.c b/emtests/test_dlmalloc_partial_2.c new file mode 100644 index 000000000..965ee217f --- /dev/null +++ b/emtests/test_dlmalloc_partial_2.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +void *malloc(size_t size) { return (void *)123; } +int main() { + void *x = malloc(10); + EM_ASM({ out("got 0x" + $0.toString(16)) }, x); + free(0); + EM_ASM({ out("freed a fake") }); + return 1; +} diff --git a/emtests/test_dlmalloc_partial_2.out b/emtests/test_dlmalloc_partial_2.out new file mode 100644 index 000000000..5512c7a8c --- /dev/null +++ b/emtests/test_dlmalloc_partial_2.out @@ -0,0 +1,2 @@ +got 0x7b +freed \ No newline at end of file diff --git a/emtests/test_dlmalloc_partial_2.wasm b/emtests/test_dlmalloc_partial_2.wasm new file mode 100644 index 000000000..acd345467 Binary files /dev/null and b/emtests/test_dlmalloc_partial_2.wasm differ diff --git a/emtests/test_double_i64_conversion.c b/emtests/test_double_i64_conversion.c new file mode 100644 index 000000000..19f4d87f2 --- /dev/null +++ b/emtests/test_double_i64_conversion.c @@ -0,0 +1,76 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +__attribute((noinline)) bool eq(double d, int64_t i) { + int64_t i2 = (int64_t)d; + if (i != i2) { + printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, + i2, i); + } + return i == i2; +} + +int main() { + assert(eq(0.0, 0)); + assert(eq(-0.0, 0)); + assert(eq(0.1, 0)); + assert(eq(-0.1, 0)); + assert(eq(0.6, 0)); + assert(eq(-0.6, 0)); + assert(eq(1.0, 1)); + assert(eq(-1.0, -1)); + assert(eq(1.1, 1)); + assert(eq(-1.1, -1)); + assert(eq(1.6, 1)); + assert(eq(-1.6, -1)); + assert(eq(4294967295.0, 4294967295LL)); + assert(eq(4294967295.5, 4294967295LL)); + assert(eq(4294967296.0, 4294967296LL)); + assert(eq(4294967296.5, 4294967296LL)); + assert(eq(14294967295.0, 14294967295LL)); + assert(eq(14294967295.5, 14294967295LL)); + assert(eq(14294967296.0, 14294967296LL)); + assert(eq(14294967296.5, 14294967296LL)); + assert(eq(-4294967295.0, -4294967295LL)); + assert(eq(-4294967295.5, -4294967295LL)); + assert(eq(-4294967296.0, -4294967296LL)); + assert(eq(-4294967296.5, -4294967296LL)); + assert(eq(-14294967295.0, -14294967295LL)); + assert(eq(-14294967295.5, -14294967295LL)); + assert(eq(-14294967296.0, -14294967296LL)); + assert(eq(-14294967296.5, -14294967296LL)); + + assert(eq(4294967295.3, 4294967295LL)); + assert(eq(4294967296.3, 4294967296LL)); + assert(eq(14294967295.3, 14294967295LL)); + assert(eq(14294967296.3, 14294967296LL)); + assert(eq(-4294967295.3, -4294967295LL)); + assert(eq(-4294967296.3, -4294967296LL)); + assert(eq(-14294967295.3, -14294967295LL)); + assert(eq(-14294967296.3, -14294967296LL)); + + assert(eq(4294967295.8, 4294967295LL)); + assert(eq(4294967296.8, 4294967296LL)); + assert(eq(14294967295.8, 14294967295LL)); + assert(eq(14294967296.8, 14294967296LL)); + assert(eq(-4294967295.8, -4294967295LL)); + assert(eq(-4294967296.8, -4294967296LL)); + assert(eq(-14294967295.8, -14294967295LL)); + assert(eq(-14294967296.8, -14294967296LL)); + + // The following number is the largest double such that all integers smaller + // than this can exactly be represented in a double. + assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */)); + assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */)); + + printf("OK!\n"); + return 0; +} diff --git a/emtests/test_double_i64_conversion.out b/emtests/test_double_i64_conversion.out new file mode 100644 index 000000000..d64066171 --- /dev/null +++ b/emtests/test_double_i64_conversion.out @@ -0,0 +1 @@ +OK! diff --git a/emtests/test_double_varargs.c b/emtests/test_double_varargs.c new file mode 100644 index 000000000..6a399e27d --- /dev/null +++ b/emtests/test_double_varargs.c @@ -0,0 +1,41 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +double func_int_double_1(int unused1, ...) +{ + int i; + double d; + va_list vl; + va_start(vl, unused1); + i = va_arg(vl, int); + d = va_arg(vl, double); + va_end(vl); + return i+d; +} + +double func_int_double_2(int unused1, int unused2, ...) +{ + int i; + double d; + va_list vl; + va_start(vl, unused2); + i = va_arg(vl, int); + d = va_arg(vl, double); + va_end(vl); + return i+d; +} + +int main() { + double ret = func_int_double_1(0, 5, 10.0); + printf("%f\n", ret); // Expects to print 15 + ret = func_int_double_2(0, 0, 5, 10.0); + printf("%f\n", ret); // Expects to print 15 +} + diff --git a/emtests/test_double_varargs.out b/emtests/test_double_varargs.out new file mode 100644 index 000000000..c907decea --- /dev/null +++ b/emtests/test_double_varargs.out @@ -0,0 +1,2 @@ +15.000000 +15.000000 diff --git a/emtests/test_double_varargs.wasm b/emtests/test_double_varargs.wasm new file mode 100644 index 000000000..5d511c2f9 Binary files /dev/null and b/emtests/test_double_varargs.wasm differ diff --git a/emtests/test_dynamic_cast.c b/emtests/test_dynamic_cast.c new file mode 100644 index 000000000..fc0d64cbc --- /dev/null +++ b/emtests/test_dynamic_cast.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +struct Support { + virtual void f() { printf("f()\n"); } +}; + +struct Derived : Support {}; + +int main() { + Support* p = new Derived; + dynamic_cast(p)->f(); +} diff --git a/emtests/test_dynamic_cast.out b/emtests/test_dynamic_cast.out new file mode 100644 index 000000000..a19096b57 --- /dev/null +++ b/emtests/test_dynamic_cast.out @@ -0,0 +1 @@ +f() diff --git a/emtests/test_dynamic_cast_2.c b/emtests/test_dynamic_cast_2.c new file mode 100644 index 000000000..95d18b82f --- /dev/null +++ b/emtests/test_dynamic_cast_2.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +class Class {}; + +int main() { + const Class* dp = dynamic_cast(&typeid(Class)); + // should return dp == NULL, + printf("pointer: %p\n", dp); +} diff --git a/emtests/test_dynamic_cast_2.out b/emtests/test_dynamic_cast_2.out new file mode 100644 index 000000000..c6e35541c --- /dev/null +++ b/emtests/test_dynamic_cast_2.out @@ -0,0 +1 @@ +pointer: 0 diff --git a/emtests/test_dynamic_cast_b.c b/emtests/test_dynamic_cast_b.c new file mode 100644 index 000000000..ee39d725f --- /dev/null +++ b/emtests/test_dynamic_cast_b.c @@ -0,0 +1,38 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +class CBase { + virtual void dummy() {} +}; +class CDerived : public CBase { + int a; +}; +class CDerivedest : public CDerived { + float b; +}; + +int main() { + CBase *pa = new CBase; + CBase *pb = new CDerived; + CBase *pc = new CDerivedest; + + printf("a1: %d\n", dynamic_cast(pa) != NULL); + printf("a2: %d\n", dynamic_cast(pa) != NULL); + printf("a3: %d\n", dynamic_cast(pa) != NULL); + + printf("b1: %d\n", dynamic_cast(pb) != NULL); + printf("b2: %d\n", dynamic_cast(pb) != NULL); + printf("b3: %d\n", dynamic_cast(pb) != NULL); + + printf("c1: %d\n", dynamic_cast(pc) != NULL); + printf("c2: %d\n", dynamic_cast(pc) != NULL); + printf("c3: %d\n", dynamic_cast(pc) != NULL); + + return 0; +} diff --git a/emtests/test_dynamic_cast_b.out b/emtests/test_dynamic_cast_b.out new file mode 100644 index 000000000..090390e8b --- /dev/null +++ b/emtests/test_dynamic_cast_b.out @@ -0,0 +1,9 @@ +a1: 0 +a2: 0 +a3: 1 +b1: 0 +b2: 1 +b3: 1 +c1: 1 +c2: 1 +c3: 1 diff --git a/emtests/test_em_asm.cpp b/emtests/test_em_asm.cpp new file mode 100644 index 000000000..645ff8e96 --- /dev/null +++ b/emtests/test_em_asm.cpp @@ -0,0 +1,53 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +int main() { + printf("BEGIN\n"); + EM_ASM({ out("no args works"); }); + + // The following two lines are deprecated, test them still. + printf(" EM_ASM_INT_V returned: %d\n", EM_ASM_INT_V({ out("no args returning int"); return 12; })); + printf(" EM_ASM_DOUBLE_V returned: %f\n", EM_ASM_DOUBLE_V({ out("no args returning double"); return 12.25; })); + + printf(" EM_ASM_INT returned: %d\n", EM_ASM_INT({ out("no args returning int"); return 12; })); + printf(" EM_ASM_DOUBLE returned: %f\n", EM_ASM_DOUBLE({ out("no args returning double"); return 12.25; })); + +#define TEST() \ + FUNC({ out(" takes ints: " + $0);}, 5); \ + FUNC({ out(" takes doubles: " + $0);}, 5.0675); \ + FUNC({ out(" takes strings: " + Pointer_stringify($0)); return 7.75; }, "string arg"); \ + FUNC({ out(" takes multiple ints: " + $0 + ", " + $1); return 6; }, 5, 7); \ + FUNC({ out(" mixed arg types: " + $0 + ", " + Pointer_stringify($1) + ", " + $2); return 8.125; }, 3, "hello", 4.75); \ + FUNC({ out(" ignores unused args"); return 5.5; }, 0); \ + FUNC({ out(" skips unused args: " + $1); return 6; }, 5, 7); \ + FUNC({ out(" " + $0 + " + " + $2); return $0 + $2; }, 5.5, 7.0, 14.375); + +#define FUNC_WITH(macro, format, ...) printf(" returned: " format "\n", macro(__VA_ARGS__)); +#define FUNC(...) FUNC_WITH(EM_ASM_, "%d", __VA_ARGS__) + printf("EM_ASM_ :\n"); + TEST() +#undef FUNC + +#define FUNC(...) FUNC_WITH(EM_ASM_INT, "%d", __VA_ARGS__) + printf("EM_ASM_INT :\n"); + TEST() +#undef FUNC + +#define FUNC(...) FUNC_WITH(EM_ASM_ARGS, "%d", __VA_ARGS__) + printf("EM_ASM_ARGS :\n"); + TEST() +#undef FUNC + +#define FUNC(...) FUNC_WITH(EM_ASM_DOUBLE, "%f", __VA_ARGS__) + printf("EM_ASM_DOUBLE :\n"); + TEST() +#undef FUNC + + printf("END\n"); + return 0; +} diff --git a/emtests/test_em_asm.out b/emtests/test_em_asm.out new file mode 100644 index 000000000..4f0323822 --- /dev/null +++ b/emtests/test_em_asm.out @@ -0,0 +1,79 @@ +BEGIN +no args works +no args returning int + EM_ASM_INT_V returned: 12 +no args returning double + EM_ASM_DOUBLE_V returned: 12.250000 +no args returning int + EM_ASM_INT returned: 12 +no args returning double + EM_ASM_DOUBLE returned: 12.250000 +EM_ASM_ : + takes ints: 5 + returned: 0 + takes doubles: 5.0675 + returned: 0 + takes strings: string arg + returned: 7 + takes multiple ints: 5, 7 + returned: 6 + mixed arg types: 3, hello, 4.75 + returned: 8 + ignores unused args + returned: 5 + skips unused args: 7 + returned: 6 + 5.5 + 14.375 + returned: 19 +EM_ASM_INT : + takes ints: 5 + returned: 0 + takes doubles: 5.0675 + returned: 0 + takes strings: string arg + returned: 7 + takes multiple ints: 5, 7 + returned: 6 + mixed arg types: 3, hello, 4.75 + returned: 8 + ignores unused args + returned: 5 + skips unused args: 7 + returned: 6 + 5.5 + 14.375 + returned: 19 +EM_ASM_ARGS : + takes ints: 5 + returned: 0 + takes doubles: 5.0675 + returned: 0 + takes strings: string arg + returned: 7 + takes multiple ints: 5, 7 + returned: 6 + mixed arg types: 3, hello, 4.75 + returned: 8 + ignores unused args + returned: 5 + skips unused args: 7 + returned: 6 + 5.5 + 14.375 + returned: 19 +EM_ASM_DOUBLE : + takes ints: 5 + returned: nan + takes doubles: 5.0675 + returned: nan + takes strings: string arg + returned: 7.750000 + takes multiple ints: 5, 7 + returned: 6.000000 + mixed arg types: 3, hello, 4.75 + returned: 8.125000 + ignores unused args + returned: 5.500000 + skips unused args: 7 + returned: 6.000000 + 5.5 + 14.375 + returned: 19.875000 +END \ No newline at end of file diff --git a/emtests/test_em_asm.wasm b/emtests/test_em_asm.wasm new file mode 100644 index 000000000..0b9f1b6f8 Binary files /dev/null and b/emtests/test_em_asm.wasm differ diff --git a/emtests/test_em_asm_2.cpp b/emtests/test_em_asm_2.cpp new file mode 100644 index 000000000..ca7b47d4c --- /dev/null +++ b/emtests/test_em_asm_2.cpp @@ -0,0 +1,152 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +int main() +{ + printf("EM_ASM: Simple expression without trailing semicolon\n"); + EM_ASM(console.log('1. expression without trailing semicolon')); + EM_ASM("console.log('2. expression without trailing semicolon')"); + EM_ASM({"console.log('3. expression without trailing semicolon')"}); + EM_ASM({console.log('4. expression without trailing semicolon')}); + EM_ASM("{console.log('5. expression without trailing semicolon')}"); + + printf("\nEM_ASM: Double quotes\n"); + EM_ASM(console.log("1. string in double quotes")); + EM_ASM("console.log(\"2. string in double quotes\")"); + EM_ASM({"console.log(\"3. string in double quotes\")"}); + EM_ASM({console.log("4. string in double quotes")}); + EM_ASM("{console.log(\"5. string in double quotes\")}"); + + printf("\nEM_ASM: Double quotes inside a string\n"); + EM_ASM(console.log('1. this is \"double\" \"quotes\"')); + EM_ASM(console.log('2. this is "double" "quotes" without escaping')); + EM_ASM("console.log('3. this is \"double\" \"quotes\"')"); + EM_ASM({"console.log('4. this is \"double\" \"quotes\"')"}); + EM_ASM({console.log('5. this is \"double\" \"quotes\"')}); + EM_ASM({console.log('6. this is "double" "quotes" without esacping')}); + EM_ASM("{console.log('7. this is \"double\" \"quotes\"')}"); + + printf("\nEM_ASM: Pass a string\n"); + EM_ASM(console.log('1. hello ' + UTF8ToString($0)), "world!"); + EM_ASM("console.log('2. hello ' + UTF8ToString($0))", "world!"); + EM_ASM({"console.log('3. hello ' + UTF8ToString($0))"}, "world!"); + EM_ASM({console.log('4. hello ' + UTF8ToString($0))}, "world!"); + EM_ASM("{console.log('5. hello ' + UTF8ToString($0))}", "world!"); + + printf("\nEM_ASM: Simple expression without trailing semicolon, wrap code block in extra parentheses\n"); + EM_ASM((console.log('1. expression without trailing semicolon, in parentheses'))); + EM_ASM(("console.log('2. expression without trailing semicolon, in parentheses')")); + EM_ASM(({"console.log('3. expression without trailing semicolon, in parentheses')"})); + EM_ASM(({console.log('4. expression without trailing semicolon, in parentheses')})); + EM_ASM(("{console.log('5. expression without trailing semicolon, in parentheses')}")); + + printf("\nEM_ASM: Two statements, separated with a semicolon\n"); + EM_ASM(console.log('1. two'); console.log('1. statements');); + EM_ASM("console.log('2. two'); console.log('2. statements 2');"); + EM_ASM({"console.log('3. two'); console.log('3. statements 3');"}); + EM_ASM({console.log('4. two'); console.log('4. statements 4');}); + EM_ASM("{console.log('5. two'); console.log('5. statements 5');}"); + + printf("\nEM_ASM: Pass an integer\n"); + EM_ASM(console.log('1. int ' + $0), 42); + EM_ASM("console.log('2. int ' + $0)", 43); + EM_ASM({"console.log('3. int ' + $0)"}, 44); + EM_ASM({console.log('4. int ' + $0)}, 45); + EM_ASM("{console.log('5. int ' + $0)}", 46); + + printf("\nEM_ASM: Evaluate an anonymous function\n"); + EM_ASM((function() {console.log('1. evaluating anonymous function ' + $0)})(), 42); + EM_ASM("(function() {console.log('2. evaluating anonymous function ' + $0)})()", 42); + EM_ASM({"(function() {console.log('3. evaluating anonymous function ' + $0)})()"}, 42); + EM_ASM({(function() {console.log('4. evaluating anonymous function ' + $0)})()}, 42); + EM_ASM("{(function() {console.log('5. evaluating anonymous function ' + $0)})()}", 42); + + printf("\nEM_ASM: Pass an integer and a double\n"); + EM_ASM(console.log('1. int and double ' + $0 + ' ' + $1), 42, 43.5); + EM_ASM("console.log('2. int and double ' + $0 + ' ' + $1)", 42, 43.5); + EM_ASM({"console.log('3. int and double ' + $0 + ' ' + $1)"}, 42, 43.5); + EM_ASM({console.log('4. int and double ' + $0 + ' ' + $1)}, 42, 43.5); + EM_ASM("{console.log('5. int and double ' + $0 + ' ' + $1)}", 42, 43.5); + + int i; + + printf("\nEM_ASM_INT: Pass an integer, return an integer back\n"); + i = EM_ASM_INT(console.log('1. got int ' + $0); return 3.5;, 42); printf("1. returned int %d\n", i); + i = EM_ASM_INT("console.log('2. got int ' + $0); return 4.5;", 42); printf("2. returned int %d\n", i); + i = EM_ASM_INT({"console.log('3. got int ' + $0); return 5.5;"}, 42); printf("3. returned int %d\n", i); + i = EM_ASM_INT({console.log('4. got int ' + $0); return 6.5;}, 42); printf("4. returned int %d\n", i); + i = EM_ASM_INT("{console.log('5. got int ' + $0); return 7.5;}", 42); printf("5. returned int %d\n", i); + + printf("\nEM_ASM_INT: Pass an integer, return an integer back, wrap code block in extra parentheses\n"); + i = EM_ASM_INT((console.log('1. got int, extra parentheses ' + $0); return 3.5;), 42); printf("1. returned int, extra parentheses %d\n", i); + i = EM_ASM_INT(("console.log('2. got int, extra parentheses ' + $0); return 4.5;"), 42); printf("2. returned int, extra parentheses %d\n", i); + i = EM_ASM_INT(({"console.log('3. got int, extra parentheses ' + $0); return 5.5;"}), 42); printf("3. returned int, extra parentheses %d\n", i); + i = EM_ASM_INT(({console.log('4. got int, extra parentheses ' + $0); return 6.5;}), 42); printf("4. returned int, extra parentheses %d\n", i); + i = EM_ASM_INT(("{console.log('5. got int, extra parentheses ' + $0); return 7.5;}"), 42); printf("5. returned int, extra parentheses %d\n", i); + + printf("\nEM_ASM_INT: More imaginable ways for user to wrap in extra parentheses\n"); + i = EM_ASM_INT({("console.log('1. got int, extra extra parentheses ' + $0); return 5.5;")}, 42); printf("1. returned int, extra extra parentheses %d\n", i); + i = EM_ASM_INT({(console.log('2. got int, extra extra parentheses ' + $0); return 6.5;)}, 42); printf("2. returned int, extra extra parentheses %d\n", i); + i = EM_ASM_INT(((((((((((console.log('3. got int, extra extra extra parentheses ' + $0); return 6.5;)))))))))), 42); printf("3. returned int, extra extra extra parentheses %d\n", i); + + printf("\nEM_ASM_INT: Return an integer back.\n"); + i = EM_ASM_INT(console.log('1. got int ' + $0); return 3.5;, 42); printf("1. returned int %d\n", i); + i = EM_ASM_INT("console.log('2. got int ' + $0); return 4.5;", 42); printf("2. returned int %d\n", i); + i = EM_ASM_INT({"console.log('3. got int ' + $0); return 5.5;"}, 42); printf("3. returned int %d\n", i); + i = EM_ASM_INT({console.log('4. got int ' + $0); return 6.5;}, 42); printf("4. returned int %d\n", i); + i = EM_ASM_INT("{console.log('5. got int ' + $0); return 7.5;}", 42); printf("5. returned int %d\n", i); + + printf("\nEM_ASM_INT: Return an integer in a single brief statement.\n"); + i = EM_ASM_INT(return TOTAL_MEMORY); printf("1. returned statement %d\n", i); + i = EM_ASM_INT("return TOTAL_MEMORY+1"); printf("2. returned statement %d\n", i); + i = EM_ASM_INT({"return TOTAL_MEMORY+2"}); printf("3. returned statement %d\n", i); + i = EM_ASM_INT({return TOTAL_MEMORY+3}); printf("4. returned statement %d\n", i); + i = EM_ASM_INT("return TOTAL_MEMORY+4"); printf("5. returned statement %d\n", i); + + // Note that expressions do not evaluate to return values, but the "return" keyword is needed. That is, the following line would return undefined and store i <- 0. + // i = EM_ASM_INT(TOTAL_MEMORY); printf("returned statement %d\n", i); + + double d; + + printf("\nEM_ASM_DOUBLE: Pass no parameters, return a double.\n"); + d = EM_ASM_DOUBLE(console.log('1. returning double'); return 3.5;); printf("1. got double %f\n", d); + d = EM_ASM_DOUBLE("console.log('2. returning double'); return 4.5;"); printf("2. got double %f\n", d); + d = EM_ASM_DOUBLE({"console.log('3. returning double'); return 5.5;"}); printf("3. got double %f\n", d); + d = EM_ASM_DOUBLE({console.log('4. returning double'); return 6.5;}); printf("4. got double %f\n", d); + d = EM_ASM_DOUBLE("{console.log('5. returning double'); return 7.5;}"); printf("5. got double %f\n", d); + + printf("\nEM_ASM_DOUBLE: Pass an integer, return a double.\n"); + d = EM_ASM_DOUBLE(console.log('1. got int ' + $0); return 3.5;, 42); printf("1. returned double %f\n", d); + d = EM_ASM_DOUBLE("console.log('2. got int ' + $0); return 4.5;", 42); printf("2. returned double %f\n", d); + d = EM_ASM_DOUBLE({"console.log('3. got int ' + $0); return 5.5;"}, 42); printf("3. returned double %f\n", d); + d = EM_ASM_DOUBLE({console.log('4. got int ' + $0); return 6.5;}, 42); printf("4. returned double %f\n", d); + d = EM_ASM_DOUBLE("{console.log('5. got int ' + $0); return 7.5;}", 42); printf("5. returned double %f\n", d); + + printf("\nEM_ASM_DOUBLE: Pass a double and an integer, return a double.\n"); + d = EM_ASM_DOUBLE(console.log('1. got double and int ' + $0 + ' ' + $1); return 3.5;, 5.5, 42); printf("1. returned double %f\n", d); + d = EM_ASM_DOUBLE("console.log('2. got double and int ' + $0 + ' ' + $1); return 4.5;", 5.5, 42); printf("2. returned double %f\n", d); + d = EM_ASM_DOUBLE({"console.log('3. got double and int ' + $0 + ' ' + $1); return 5.5;"}, 5.5, 42); printf("3. returned double %f\n", d); + d = EM_ASM_DOUBLE({console.log('4. got double and int ' + $0 + ' ' + $1); return 6.5;}, 5.5, 42); printf("4. returned double %f\n", d); + d = EM_ASM_DOUBLE("{console.log('5. got double and int ' + $0 + ' ' + $1); return 7.5;}", 5.5, 42); printf("5. returned double %f\n", d); + + printf("\nEM_ASM_INT: A comma character (,) inside the code block may need extra parentheses\n"); +// i = EM_ASM_INT(console.log('1. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b, 10); printf("1. returned %d\n", i); // This would not compile: use of undeclared identifier 'b' + i = EM_ASM_INT((console.log('1. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b), 10); printf("1. returned %d\n", i); // However by wrapping the code block inside parentheses, it will be ok + i = EM_ASM_INT("console.log('2. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b", 10); printf("2. returned %d\n", i); + i = EM_ASM_INT({"console.log('3. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b"}, 10); printf("3. returned %d\n", i); +// i = EM_ASM_INT({console.log('4. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b}, 10); printf("4. returned %d\n", i); // This would also not compile: use of undeclared identifier 'b' + i = EM_ASM_INT(({console.log('4. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b}), 10); printf("4. returned %d\n", i); // Again by wrapping the code block inside parentheses, it will work + i = EM_ASM_INT("{console.log('5. comma in em_asm'); var foo = { a: 5, b: $0 }; return foo.a + foo.b}", 10); printf("5. returned %d\n", i); + + printf("\nEM_ASM: Expression contains a tab character\n"); + EM_ASM(console.log('1. the following word is delimited by tab characters: H\tE\tL\tL\tO\tT\tA\tB\tS')); + EM_ASM("console.log('2. the following word is delimited by tab characters: H\tE\tL\tL\tO\tT\tA\tB\tS')"); + EM_ASM({"console.log('3. the following word is delimited by tab characters: H\tE\tL\tL\tO\tT\tA\tB\tS')"}); + EM_ASM({console.log('4. the following word is delimited by tab characters: H\tE\tL\tL\tO\tT\tA\tB\tS')}); + EM_ASM("{console.log('5. the following word is delimited by tab characters: H\tE\tL\tL\tO\tT\tA\tB\tS')}"); +} diff --git a/emtests/test_em_asm_2.out b/emtests/test_em_asm_2.out new file mode 100644 index 000000000..10ca9d7d5 --- /dev/null +++ b/emtests/test_em_asm_2.out @@ -0,0 +1,175 @@ +EM_ASM: Simple expression without trailing semicolon +1. expression without trailing semicolon +2. expression without trailing semicolon +3. expression without trailing semicolon +4. expression without trailing semicolon +5. expression without trailing semicolon + +EM_ASM: Double quotes +1. string in double quotes +2. string in double quotes +3. string in double quotes +4. string in double quotes +5. string in double quotes + +EM_ASM: Double quotes inside a string +1. this is "double" "quotes" +2. this is "double" "quotes" without escaping +3. this is "double" "quotes" +4. this is "double" "quotes" +5. this is "double" "quotes" +6. this is "double" "quotes" without esacping +7. this is "double" "quotes" + +EM_ASM: Pass a string +1. hello world! +2. hello world! +3. hello world! +4. hello world! +5. hello world! + +EM_ASM: Simple expression without trailing semicolon, wrap code block in extra parentheses +1. expression without trailing semicolon, in parentheses +2. expression without trailing semicolon, in parentheses +3. expression without trailing semicolon, in parentheses +4. expression without trailing semicolon, in parentheses +5. expression without trailing semicolon, in parentheses + +EM_ASM: Two statements, separated with a semicolon +1. two +1. statements +2. two +2. statements 2 +3. two +3. statements 3 +4. two +4. statements 4 +5. two +5. statements 5 + +EM_ASM: Pass an integer +1. int 42 +2. int 43 +3. int 44 +4. int 45 +5. int 46 + +EM_ASM: Evaluate an anonymous function +1. evaluating anonymous function 42 +2. evaluating anonymous function 42 +3. evaluating anonymous function 42 +4. evaluating anonymous function 42 +5. evaluating anonymous function 42 + +EM_ASM: Pass an integer and a double +1. int and double 42 43.5 +2. int and double 42 43.5 +3. int and double 42 43.5 +4. int and double 42 43.5 +5. int and double 42 43.5 + +EM_ASM_INT: Pass an integer, return an integer back +1. got int 42 +1. returned int 3 +2. got int 42 +2. returned int 4 +3. got int 42 +3. returned int 5 +4. got int 42 +4. returned int 6 +5. got int 42 +5. returned int 7 + +EM_ASM_INT: Pass an integer, return an integer back, wrap code block in extra parentheses +1. got int, extra parentheses 42 +1. returned int, extra parentheses 3 +2. got int, extra parentheses 42 +2. returned int, extra parentheses 4 +3. got int, extra parentheses 42 +3. returned int, extra parentheses 5 +4. got int, extra parentheses 42 +4. returned int, extra parentheses 6 +5. got int, extra parentheses 42 +5. returned int, extra parentheses 7 + +EM_ASM_INT: More imaginable ways for user to wrap in extra parentheses +1. got int, extra extra parentheses 42 +1. returned int, extra extra parentheses 5 +2. got int, extra extra parentheses 42 +2. returned int, extra extra parentheses 6 +3. got int, extra extra extra parentheses 42 +3. returned int, extra extra extra parentheses 6 + +EM_ASM_INT: Return an integer back. +1. got int 42 +1. returned int 3 +2. got int 42 +2. returned int 4 +3. got int 42 +3. returned int 5 +4. got int 42 +4. returned int 6 +5. got int 42 +5. returned int 7 + +EM_ASM_INT: Return an integer in a single brief statement. +1. returned statement 16777216 +2. returned statement 16777217 +3. returned statement 16777218 +4. returned statement 16777219 +5. returned statement 16777220 + +EM_ASM_DOUBLE: Pass no parameters, return a double. +1. returning double +1. got double 3.500000 +2. returning double +2. got double 4.500000 +3. returning double +3. got double 5.500000 +4. returning double +4. got double 6.500000 +5. returning double +5. got double 7.500000 + +EM_ASM_DOUBLE: Pass an integer, return a double. +1. got int 42 +1. returned double 3.500000 +2. got int 42 +2. returned double 4.500000 +3. got int 42 +3. returned double 5.500000 +4. got int 42 +4. returned double 6.500000 +5. got int 42 +5. returned double 7.500000 + +EM_ASM_DOUBLE: Pass a double and an integer, return a double. +1. got double and int 5.5 42 +1. returned double 3.500000 +2. got double and int 5.5 42 +2. returned double 4.500000 +3. got double and int 5.5 42 +3. returned double 5.500000 +4. got double and int 5.5 42 +4. returned double 6.500000 +5. got double and int 5.5 42 +5. returned double 7.500000 + +EM_ASM_INT: A comma character (,) inside the code block may need extra parentheses +1. comma in em_asm +1. returned 15 +2. comma in em_asm +2. returned 15 +3. comma in em_asm +3. returned 15 +4. comma in em_asm +4. returned 15 +5. comma in em_asm +5. returned 15 + +EM_ASM: Expression contains a tab character +1. the following word is delimited by tab characters: H E L L O T A B S +2. the following word is delimited by tab characters: H E L L O T A B S +3. the following word is delimited by tab characters: H E L L O T A B S +4. the following word is delimited by tab characters: H E L L O T A B S +5. the following word is delimited by tab characters: H E L L O T A B S diff --git a/emtests/test_em_asm_2.wasm b/emtests/test_em_asm_2.wasm new file mode 100644 index 000000000..3d1db657d Binary files /dev/null and b/emtests/test_em_asm_2.wasm differ diff --git a/emtests/test_em_asm_parameter_pack.cpp b/emtests/test_em_asm_parameter_pack.cpp new file mode 100644 index 000000000..941989fd7 --- /dev/null +++ b/emtests/test_em_asm_parameter_pack.cpp @@ -0,0 +1,22 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +template +int call(Args... args) { + return(EM_ASM_INT( + { + out(Array.prototype.join.call(arguments, ',')); + }, + args... + )); +} + +int main(int argc, char **argv) { + call(1); + call(1, 2); + call(1, 2, 3); + return 0; +} diff --git a/emtests/test_em_asm_parameter_pack.out b/emtests/test_em_asm_parameter_pack.out new file mode 100644 index 000000000..941a57bc6 --- /dev/null +++ b/emtests/test_em_asm_parameter_pack.out @@ -0,0 +1,3 @@ +1 +1,2 +1,2,3 diff --git a/emtests/test_em_asm_parameter_pack.wasm b/emtests/test_em_asm_parameter_pack.wasm new file mode 100644 index 000000000..f1c9ea3c2 Binary files /dev/null and b/emtests/test_em_asm_parameter_pack.wasm differ diff --git a/emtests/test_em_asm_signatures.cpp b/emtests/test_em_asm_signatures.cpp new file mode 100644 index 000000000..5e234861d --- /dev/null +++ b/emtests/test_em_asm_signatures.cpp @@ -0,0 +1,20 @@ +#include +#include + +int main() +{ + int ret = MAIN_THREAD_EM_ASM_INT(return 1); + ret += MAIN_THREAD_EM_ASM_INT(return $0, 1); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1, 1, 2); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1 + $2, 1, 2, 3); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1 + $2 + $3, 1, 2, 3, 4); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1 + $2 + $3 + $4, 1, 2, 3, 4, 5); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1 + $2 + $3 + $4 + $5, 1, 2, 3, 4, 5, 6); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1 + $2 + $3 + $4 + $5 + $6, 1, 2, 3, 4, 5, 6, 7); + ret += MAIN_THREAD_EM_ASM_INT(return $0 + $1 + $2 + $3 + $4 + $5 + $6 + $7, 1, 2, 3, 4, 5, 6, 7, 8); + printf("ret: %d\n", ret); +#ifdef REPORT_RESULT + REPORT_RESULT(ret); +#endif + return ret; +} diff --git a/emtests/test_em_asm_signatures.out b/emtests/test_em_asm_signatures.out new file mode 100644 index 000000000..311d66b4e --- /dev/null +++ b/emtests/test_em_asm_signatures.out @@ -0,0 +1 @@ +ret: 121 \ No newline at end of file diff --git a/emtests/test_em_asm_signatures.wasm b/emtests/test_em_asm_signatures.wasm new file mode 100644 index 000000000..ae7caf4ed Binary files /dev/null and b/emtests/test_em_asm_signatures.wasm differ diff --git a/emtests/test_em_asm_unicode.cpp b/emtests/test_em_asm_unicode.cpp new file mode 100644 index 000000000..f685f1f62 --- /dev/null +++ b/emtests/test_em_asm_unicode.cpp @@ -0,0 +1,10 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +int main() { + EM_ASM( out("hello world…") ); +} diff --git a/emtests/test_em_asm_unicode.out b/emtests/test_em_asm_unicode.out new file mode 100644 index 000000000..4ef53eab9 --- /dev/null +++ b/emtests/test_em_asm_unicode.out @@ -0,0 +1 @@ +hello world… \ No newline at end of file diff --git a/emtests/test_em_asm_unicode.wasm b/emtests/test_em_asm_unicode.wasm new file mode 100644 index 000000000..e3e7df3d9 Binary files /dev/null and b/emtests/test_em_asm_unicode.wasm differ diff --git a/emtests/test_em_asm_unused_arguments.cpp b/emtests/test_em_asm_unused_arguments.cpp new file mode 100644 index 000000000..13313cb64 --- /dev/null +++ b/emtests/test_em_asm_unused_arguments.cpp @@ -0,0 +1,15 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +int main(int argc, char **argv) { + int sum = EM_ASM_INT({ + return $0 + $2; + }, 0, 1, 2); + printf("0+2=%d\n", sum); + return 0; +} diff --git a/emtests/test_em_asm_unused_arguments.out b/emtests/test_em_asm_unused_arguments.out new file mode 100644 index 000000000..4b4125e48 --- /dev/null +++ b/emtests/test_em_asm_unused_arguments.out @@ -0,0 +1 @@ +0+2=2 diff --git a/emtests/test_em_asm_unused_arguments.wasm b/emtests/test_em_asm_unused_arguments.wasm new file mode 100644 index 000000000..593d3bec3 Binary files /dev/null and b/emtests/test_em_asm_unused_arguments.wasm differ diff --git a/emtests/test_em_js.cpp b/emtests/test_em_js.cpp new file mode 100644 index 000000000..8bbe9e38b --- /dev/null +++ b/emtests/test_em_js.cpp @@ -0,0 +1,95 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +EM_JS(void, noarg, (void), { out("no args works"); }); +EM_JS(int, noarg_int, (void), { + out("no args returning int"); + return 12; +}); +EM_JS(double, noarg_double, (void), { + out("no args returning double"); + return 12.25; +}); +EM_JS(void, intarg, (int x), { out(" takes ints: " + x);}); +EM_JS(void, doublearg, (double d), { out(" takes doubles: " + d);}); +EM_JS(double, stringarg, (char* str), { + out(" takes strings: " + Pointer_stringify(str)); + return 7.75; +}); +EM_JS(int, multi_intarg, (int x, int y), { + out(" takes multiple ints: " + x + ", " + y); + return 6; +}); +EM_JS(double, multi_mixedarg, (int x, const char* str, double d), { + out(" mixed arg types: " + x + ", " + Pointer_stringify(str) + ", " + d); + return 8.125; +}); +EM_JS(int, unused_args, (int unused), { + out(" ignores unused args"); + return 5.5; +}); +EM_JS(double, skip_args, (int x, int y), { + out(" skips unused args: " + y); + return 6; +}); +EM_JS(double, add_outer, (double x, double y, double z), { + out(" " + x + " + " + z); + return x + z; +}); +EM_JS(int, user_separator, (void), { + out(" can use <::> separator in user code"); + return 15; +}); +EM_JS(int, user_comma, (void), { + var x, y; + x = {}; + y = 3; + x[y] = [1, 2, 3]; + out(" can have commas in user code: " + x[y]); + return x[y][1]; +}); + +EM_JS(const char*, return_utf8_str, (void), { + var jsString = 'こんにちは'; + var lengthBytes = lengthBytesUTF8(jsString); + var stringOnWasmHeap = _malloc(lengthBytes); + stringToUTF8(jsString, stringOnWasmHeap, lengthBytes+1); + return stringOnWasmHeap; +}); + +EM_JS(const char*, return_str, (void), { + var jsString = 'hello from js'; + var lengthBytes = jsString.length+1; + var stringOnWasmHeap = _malloc(lengthBytes); + stringToUTF8(jsString, stringOnWasmHeap, lengthBytes+1); + return stringOnWasmHeap; +}); + +int main() { + printf("BEGIN\n"); + noarg(); + printf(" noarg_int returned: %d\n", noarg_int()); + printf(" noarg_double returned: %f\n", noarg_double()); + + intarg(5); + doublearg(5.0675); + printf(" stringarg returned: %f\n", stringarg("string arg")); + printf(" multi_intarg returned: %d\n", multi_intarg(5, 7)); + printf(" multi_mixedarg returned: %f\n", multi_mixedarg(3, "hello", 4.75)); + printf(" unused_args returned: %d\n", unused_args(0)); + printf(" skip_args returned: %f\n", skip_args(5, 7)); + printf(" add_outer returned: %f\n", add_outer(5.5, 7.0, 14.375)); + printf(" user_separator returned: %d\n", user_separator()); + printf(" user_comma returned: %d\n", user_comma()); + + printf(" return_str returned: %s\n", return_str()); + printf(" return_utf8_str returned: %s\n", return_utf8_str()); + + printf("END\n"); + return 0; +} diff --git a/emtests/test_em_js.out b/emtests/test_em_js.out new file mode 100644 index 000000000..9333a0dad --- /dev/null +++ b/emtests/test_em_js.out @@ -0,0 +1,27 @@ +BEGIN +no args works +no args returning int + noarg_int returned: 12 +no args returning double + noarg_double returned: 12.250000 + takes ints: 5 + takes doubles: 5.0675 + takes strings: string arg + stringarg returned: 7.750000 + takes multiple ints: 5, 7 + multi_intarg returned: 6 + mixed arg types: 3, hello, 4.75 + multi_mixedarg returned: 8.125000 + ignores unused args + unused_args returned: 5 + skips unused args: 7 + skip_args returned: 6.000000 + 5.5 + 14.375 + add_outer returned: 19.875000 + can use <::> separator in user code + user_separator returned: 15 + can have commas in user code: 1,2,3 + user_comma returned: 2 + return_str returned: hello from js + return_utf8_str returned: こんにちは +END diff --git a/emtests/test_em_js.wasm b/emtests/test_em_js.wasm new file mode 100644 index 000000000..c60ec74c1 Binary files /dev/null and b/emtests/test_em_js.wasm differ diff --git a/emtests/test_embind_5.cpp b/emtests/test_embind_5.cpp new file mode 100644 index 000000000..17d981783 --- /dev/null +++ b/emtests/test_embind_5.cpp @@ -0,0 +1,56 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +using namespace emscripten; + + +class MyFoo { +public: + MyFoo() { + EM_ASM({out("constructing my foo");}); + } + virtual void doit() { + EM_ASM({out("doing it");}); + } +}; + +class MyBar : public MyFoo { +public: + MyBar() { + EM_ASM({out("constructing my bar");}); + } + void doit() override { + EM_ASM({out("doing something else");}); + } +}; + + +EMSCRIPTEN_BINDINGS(my_module) { + class_("MyFoo") + .constructor<>() + .function("doit", &MyFoo::doit) + ; + class_>("MyBar") + .constructor<>() + ; +} + + +int main(int argc, char **argv) { + EM_ASM( + try { + var foo = new Module.MyFoo(); + foo.doit(); + var bar = new Module.MyBar(); + bar.doit(); + } catch(e) { + out(e); + } + ); + return 0; +} diff --git a/emtests/test_embind_5.out b/emtests/test_embind_5.out new file mode 100644 index 000000000..3d9881af0 --- /dev/null +++ b/emtests/test_embind_5.out @@ -0,0 +1,5 @@ +constructing my foo +doing it +constructing my foo +constructing my bar +doing something else diff --git a/emtests/test_emmalloc.cpp b/emtests/test_emmalloc.cpp new file mode 100644 index 000000000..bf1bebd91 --- /dev/null +++ b/emtests/test_emmalloc.cpp @@ -0,0 +1,304 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include + +#include + +#ifndef RANDOM_ITERS +#define RANDOM_ITERS 12345 +#endif + +extern void emmalloc_blank_slate_from_orbit(); + +// Test emmalloc internals, but through the external interface. We expect +// very specific outputs here based on the internals, this test would not +// pass in another malloc. + +void* check_where_we_would_malloc(size_t size) { + void* temp = malloc(size); + free(temp); + return temp; +} + +void check_where_we_would_malloc(size_t size, void* expected) { + void* temp = malloc(size); + assert(temp == expected); + free(temp); +} + +void stage(const char* name) { + EM_ASM({ + out('\n>> ' + Pointer_stringify($0) + '\n'); + }, name); +} + +const size_t ALLOCATION_UNIT = 8; + +void basics() { + stage("basics"); + stage("allocate 0"); + void* ptr = malloc(0); + assert(ptr == 0); + stage("allocate 100"); + void* first = malloc(100); + stage("free 100"); + free(first); + stage("allocate another 100"); + void* second = malloc(100); + stage("allocate 10"); + assert(second == first); + void* third = malloc(10); + assert(size_t(third) == size_t(first) + ((100 + ALLOCATION_UNIT - 1)&(-ALLOCATION_UNIT)) + ALLOCATION_UNIT); // allocation units are multiples of ALLOCATION_UNIT + stage("allocate 10 more"); + void* four = malloc(10); + assert(size_t(four) == size_t(third) + (2*ALLOCATION_UNIT) + ALLOCATION_UNIT); // payload (10 = 2 allocation units) and metadata + stage("free the first"); + free(second); + stage("several temp alloc/frees"); + // we reuse the first area, despite stuff later. + for (int i = 0; i < 4; i++) { + check_where_we_would_malloc(100, first); + } + stage("free all"); + free(third); + free(four); + stage("allocate various sizes to see they all start at the start"); + for (int i = 1; i < 1500; i++) { + check_where_we_would_malloc(i, first); + } +} + +void blank_slate() { + stage("blank_slate"); + emmalloc_blank_slate_from_orbit(); + void* ptr = malloc(0); + free(ptr); + for (int i = 0; i < 3; i++) { + void* two = malloc(0); + assert(two == ptr); + free(two); + } + for (int i = 0; i < 3; i++) { + emmalloc_blank_slate_from_orbit(); + void* two = malloc(0); + assert(two == ptr); + free(two); + } +} + +void previous_sbrk() { + stage("previous_sbrk"); + emmalloc_blank_slate_from_orbit(); + void* old = sbrk(0); + assert((size_t)old % ALLOCATION_UNIT == 0); + sbrk(3); // unalign things + void* other = malloc(10); + free(other); + assert(other != old); + assert((char*)other == (char*)old + 2 * ALLOCATION_UNIT); +} + +void min_alloc() { + stage("min_alloc"); + emmalloc_blank_slate_from_orbit(); + void* start = check_where_we_would_malloc(1); + for (int i = 1; i < 100; i++) { + void* temp = malloc(i); + void* expected = (char*)start + ALLOCATION_UNIT + ALLOCATION_UNIT * ((i + ALLOCATION_UNIT - 1) / ALLOCATION_UNIT); + check_where_we_would_malloc(1, expected); + free(temp); + } +} + +void space_at_end() { + stage("space_at_end"); + emmalloc_blank_slate_from_orbit(); + void* start = check_where_we_would_malloc(1); + for (int i = 1; i < 50; i++) { + for (int j = 1; j < 50; j++) { + void* temp = malloc(i); + free(temp); + check_where_we_would_malloc(j, start); + } + } +} + +void calloc() { + stage("calloc"); + emmalloc_blank_slate_from_orbit(); + char* ptr = (char*)malloc(10); + ptr[0] = 77; + free(ptr); + char* cptr = (char*)calloc(10, 1); + assert(cptr == ptr); + assert(ptr[0] == 0); +} + +void realloc() { + stage("realloc0"); + emmalloc_blank_slate_from_orbit(); + for (int i = 0; i < 2; i++) { + char* ptr = (char*)malloc(10); + stage("realloc0.1"); + char* raptr = (char*)realloc(ptr, 1); + assert(raptr == ptr); + stage("realloc0.2"); + char* raptr2 = (char*)realloc(raptr, 100); + assert(raptr2 == ptr); + char* last = (char*)malloc(1); + assert(last >= ptr + 100); + // slightly more still fits + stage("realloc0.3"); + char* raptr3 = (char*)realloc(raptr2, 11); + assert(raptr3 == ptr); + // finally, realloc a size we must reallocate for + stage("realloc0.4"); + char* raptr4 = (char*)realloc(raptr3, 1000); + assert(raptr4); + assert(raptr4 != ptr); + // leaving those in place, do another iteration + } + stage("realloc1"); + emmalloc_blank_slate_from_orbit(); + { + // realloc of NULL is like malloc + void* ptr = check_where_we_would_malloc(10); + assert(realloc(NULL, 10) == ptr); + } + stage("realloc2"); + emmalloc_blank_slate_from_orbit(); + { + // realloc to 0 is like free + void* ptr = malloc(10); + assert(realloc(ptr, 0) == NULL); + assert(check_where_we_would_malloc(10) == ptr); + } + stage("realloc3"); + emmalloc_blank_slate_from_orbit(); + { + // realloc copies + char* ptr = (char*)malloc(10); + *ptr = 123; + for (int i = 5; i <= 16; i++) { + char* temp = (char*)realloc(ptr, i); + assert(*temp == 123); + assert(temp == ptr); + } + stage("realloc3.5"); + malloc(1); + malloc(100); + { + char* temp = (char*)realloc(ptr, 17); + assert(*temp == 123); + assert(temp != ptr); + ptr = temp; + } + } +} + +void check_aligned(size_t align, size_t ptr) { + if (align < 4 || ((align & (align - 1)) != 0)) { + assert(ptr == 0); + } else { + assert(ptr); + assert(ptr % align == 0); + } +} + +void aligned() { + stage("aligned"); + for (int i = 0; i < 35; i++) { + for (int j = 0; j < 35; j++) { + emmalloc_blank_slate_from_orbit(); + size_t first = (size_t)memalign(i, 100); + size_t second = (size_t)memalign(j, 100); + printf("%d %d => %d %d\n", i, j, first, second); + check_aligned(i, first); + check_aligned(j, second); + } + } +} + +void randoms() { + stage("randoms"); + emmalloc_blank_slate_from_orbit(); + void* start = check_where_we_would_malloc(10); + const int N = 1000; + const int BINS = 128; + void* bins[BINS]; + char values[BINS]; + for (int i = 0; i < BINS; i++) { + bins[i] = NULL; + } + srandom(1337101); + for (int i = 0; i < RANDOM_ITERS; i++) { + unsigned int r = random(); + int alloc = r & 1; + r >>= 1; + int calloc_ = r & 1; + r >>= 1; + int bin = r & 127; + r >>= 7; + unsigned int size = r & 65535; + r >>= 16; + int useShifts = r & 1; + r >>= 1; + unsigned int shifts = r & 15; + r >>= 4; + if (size == 0) size = 1; + if (useShifts) { + size >>= shifts; // spread out values logarithmically + } + if (alloc || !bins[bin]) { + if (bins[bin]) { + char value = values[bin]; + assert(*(char*)(bins[bin]) == value /* one */); + bins[bin] = realloc(bins[bin], size); + if (bins[bin]) { + assert(*(char*)(bins[bin]) == value /* two */); + } + } else { + if (calloc_) { + bins[bin] = malloc(size); + } else { + bins[bin] = calloc(size, 1); + } + values[bin] = random(); + if (bins[bin]) { + *(char*)(bins[bin]) = values[bin]; + assert(*(char*)(bins[bin]) == values[bin] /* three */); + } + } + } else { + free(bins[bin]); + bins[bin] = NULL; + } + } + for (int i = 0; i < BINS; i++) { + if (bins[i]) free(bins[i]); + } + // it's all freed, should be a blank slate + assert(check_where_we_would_malloc(10) == start); +} + +int main() { + stage("beginning"); + + basics(); + blank_slate(); + previous_sbrk(); + min_alloc(); + space_at_end(); + calloc(); + realloc(); + aligned(); + randoms(); + + stage("the_end"); +} + diff --git a/emtests/test_emmalloc.txt b/emtests/test_emmalloc.txt new file mode 100644 index 000000000..9d55f9d7d --- /dev/null +++ b/emtests/test_emmalloc.txt @@ -0,0 +1 @@ +>> the_end diff --git a/emtests/test_emptyclass.c b/emtests/test_emptyclass.c new file mode 100644 index 000000000..09327f9a8 --- /dev/null +++ b/emtests/test_emptyclass.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +struct Randomized { + Randomized(int x) { printf("*zzcheezzz*\n"); } +}; + +int main(int argc, const char *argv[]) { + new Randomized(55); + + return 0; +} diff --git a/emtests/test_emptyclass.out b/emtests/test_emptyclass.out new file mode 100644 index 000000000..1be15e152 --- /dev/null +++ b/emtests/test_emptyclass.out @@ -0,0 +1 @@ +*zzcheezzz* \ No newline at end of file diff --git a/emtests/test_emscripten_api.cpp b/emtests/test_emscripten_api.cpp new file mode 100644 index 000000000..766db92ea --- /dev/null +++ b/emtests/test_emscripten_api.cpp @@ -0,0 +1,43 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include "emscripten.h" + +extern "C" { +void save_me_aimee() { printf("mann\n"); } +} + +int main() { + // EMSCRIPTEN_COMMENT("hello from the source"); + emscripten_run_script("out('hello world' + '!')"); + printf("*%d*\n", emscripten_run_script_int("5*20")); + printf("*%s*\n", emscripten_run_script_string("'five'+'six'")); + emscripten_run_script("Module['_save_me_aimee']()"); + // + double d = 0.1234567891231219886553; + int len = emscripten_print_double(d, NULL, -1); + char buffer[len+1]; + buffer[len] = CHAR_MAX; + emscripten_print_double(d, buffer, len+1); + assert(buffer[len] == 0); // null terminated + double e; + sscanf(buffer, "%lf", &e); + printf("%.30lf : %s : %.30lf (%d)\n", d, buffer, e, len); + + buffer[0] = 1; + buffer[1] = 2; + buffer[2] = 3; + int n = emscripten_print_double(d, buffer, 2); + assert(n == 1); + assert(buffer[0] == '0'); // touched + assert(buffer[1] == 0); // touched + assert(buffer[2] == 3); // untouched + puts("success\n"); + + return 0; +} diff --git a/emtests/test_emscripten_api.out b/emtests/test_emscripten_api.out new file mode 100644 index 000000000..c60188630 --- /dev/null +++ b/emtests/test_emscripten_api.out @@ -0,0 +1,6 @@ +hello world! +*100* +*fivesix* +mann +0.123456789123121982165720567082 : 0.12345678912312198 : 0.123456789123121982165720567082 (19) +success diff --git a/emtests/test_emscripten_api.wasm b/emtests/test_emscripten_api.wasm new file mode 100644 index 000000000..8903023cd Binary files /dev/null and b/emtests/test_emscripten_api.wasm differ diff --git a/emtests/test_emulate_function_pointer_casts.cpp b/emtests/test_emulate_function_pointer_casts.cpp new file mode 100644 index 000000000..d4dbadc07 --- /dev/null +++ b/emtests/test_emulate_function_pointer_casts.cpp @@ -0,0 +1,24 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +// We have to use a proxy function 'acos_test' here because the updated libc++ library provides a set of overloads to acos, +// this has the result that we can't take the function pointer to acos anymore due to failed overload resolution. +// This proxy function has no overloads so it's allowed to take the function pointer directly. +double acos_test(double x) { + return acos(x); +} + +typedef double (*ddd)(double x, double unused); +typedef int (*iii)(int x, int unused); + +int main() { + volatile ddd d = (ddd)acos_test; + volatile iii i = (iii)acos_test; + printf("|%.3f,%d|\n", d(0.3, 0.6), i(0, 0)); + return 0; +} diff --git a/emtests/test_emulate_function_pointer_casts.wasm b/emtests/test_emulate_function_pointer_casts.wasm new file mode 100644 index 000000000..b6acceceb Binary files /dev/null and b/emtests/test_emulate_function_pointer_casts.wasm differ diff --git a/emtests/test_erf.c b/emtests/test_erf.c new file mode 100644 index 000000000..51b2a04c3 --- /dev/null +++ b/emtests/test_erf.c @@ -0,0 +1,14 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { + printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\n", erf(1.0), erf(3.0), + erf(-1.0), erfc(1.0), erfc(3.0), erfc(-1.5)); + return 0; +} diff --git a/emtests/test_erf.out b/emtests/test_erf.out new file mode 100644 index 000000000..3b48202f9 --- /dev/null +++ b/emtests/test_erf.out @@ -0,0 +1 @@ +0.842701, 0.999978, -0.842701, 0.157299, 0.000022, 1.966105 \ No newline at end of file diff --git a/emtests/test_erf.wasm b/emtests/test_erf.wasm new file mode 100644 index 000000000..3cb58bd73 Binary files /dev/null and b/emtests/test_erf.wasm differ diff --git a/emtests/test_errar.c b/emtests/test_errar.c new file mode 100644 index 000000000..86543df7d --- /dev/null +++ b/emtests/test_errar.c @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + char* err; + char buffer[200]; + + err = strerror(EDOM); + strerror_r(EWOULDBLOCK, buffer, 200); + printf("<%s>\n", err); + printf("<%s>\n", buffer); + + printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0)); + errno = 123; + printf("<%d>\n", errno); + + return 0; +} diff --git a/emtests/test_errar.out b/emtests/test_errar.out new file mode 100644 index 000000000..7df247dd0 --- /dev/null +++ b/emtests/test_errar.out @@ -0,0 +1,4 @@ + + +<34> +<123> diff --git a/emtests/test_errar.wasm b/emtests/test_errar.wasm new file mode 100644 index 000000000..20c36d1d6 Binary files /dev/null and b/emtests/test_errar.wasm differ diff --git a/emtests/test_exceptions_2.cpp b/emtests/test_exceptions_2.cpp new file mode 100644 index 000000000..4091fceb1 --- /dev/null +++ b/emtests/test_exceptions_2.cpp @@ -0,0 +1,23 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +typedef void (*FuncPtr)(); + +void ThrowException() { throw std::runtime_error("catch me!"); } + +FuncPtr ptr = ThrowException; + +int main() { + try { + ptr(); + } + catch (...) { + printf("Exception caught successfully!\n"); + } + return 0; +} diff --git a/emtests/test_exceptions_2.out b/emtests/test_exceptions_2.out new file mode 100644 index 000000000..aa89c67dc --- /dev/null +++ b/emtests/test_exceptions_2.out @@ -0,0 +1 @@ +Exception caught successfully! \ No newline at end of file diff --git a/emtests/test_exceptions_2.wasm b/emtests/test_exceptions_2.wasm new file mode 100644 index 000000000..e9d65d0d5 Binary files /dev/null and b/emtests/test_exceptions_2.wasm differ diff --git a/emtests/test_exceptions_alias.c b/emtests/test_exceptions_alias.c new file mode 100644 index 000000000..cdb19dde0 --- /dev/null +++ b/emtests/test_exceptions_alias.c @@ -0,0 +1,22 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#define _POSIX_SOURCE +#include +#include +#include + +int main(void) { + try { + printf("*%i*\n", isdigit('0')); + printf("*%i*\n", isdigit_l('0', LC_GLOBAL_LOCALE)); + } + catch (...) { + printf("EXCEPTION!\n"); + } +} + diff --git a/emtests/test_exceptions_alias.out b/emtests/test_exceptions_alias.out new file mode 100644 index 000000000..2f67e501d --- /dev/null +++ b/emtests/test_exceptions_alias.out @@ -0,0 +1,2 @@ +*1* +*1* diff --git a/emtests/test_exceptions_convert.cpp b/emtests/test_exceptions_convert.cpp new file mode 100644 index 000000000..563057dad --- /dev/null +++ b/emtests/test_exceptions_convert.cpp @@ -0,0 +1,137 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +namespace +{ + struct TestEnum + { + enum type + { + Zero, + One + }; + }; + + // An input operator a-la-boost date_time. This input operator will catch + // anything and rethrow if the exception mask for the input stream is set to + // throw on failure. + std::istream& operator>>(std::istream& in, TestEnum::type& value) + { + try { + std::string raw; + if (not (in >> raw)) { return in; } + if (raw == "Zero") { value = TestEnum::Zero; return in; } + if (raw == "One") { value = TestEnum::One; return in; } + + // The boost input operator uses it's own facet for input which can + // throw, so we simulate something failing by just throwing an exception + // directly. + throw std::exception(); + } + catch (...) { + const std::ios_base::iostate exception_mask = in.exceptions(); + if (std::ios_base::failbit & exception_mask) { + try { in.setstate(std::ios_base::failbit); } + catch(std::ios_base::failure&) {} + throw; // rethrow original exception + } + else { + in.setstate(std::ios_base::failbit); + } + } + return in; + } +} + +int main() +{ + try { + // Show that the input operator works. + std::istringstream iss("One"); + TestEnum::type value = TestEnum::Zero; + + // We expect this to work. + iss >> value; + if (iss.fail()) { + std::cout + << "Failed to convert 'One' to TestEnum::type... fail" + << std::endl; + } + else { + std::cout + << "Successfully converted 'One' to TestEnum::type: " << value + << "... ok" << std::endl; + } + } + catch (...) { + std::cout + << "Unknown exception caught converting 'One' to TestEnum... fail" + << std::endl; + } + + try { + // Show that invalid input set the fail bit on the input stream and no + // exception is thrown, since we did not enable them on the stream. + std::istringstream iss("Two"); + TestEnum::type value = TestEnum::Zero; + + // We expect this to fail. + iss >> value; + if (iss.fail()) { + std::cout + << "Failed to convert 'Two' to TestEnum::type... ok" + << std::endl; + } + else { + std::cout + << "Successfully converted 'Two' to TestEnum::type: " << value + << "... fail" << std::endl; + } + } + catch (...) { + std::cout + << "Unknown exception caught converting 'Two' to TestEnum... fail" + << std::endl; + } + + try { + // Show that setting the input stream to throw on failure currently + // results in a JS exception being emitted. + std::istringstream iss("Three"); + TestEnum::type value = TestEnum::Zero; + + // Tell the stream to throw on failure. + iss.exceptions(std::ios_base::failbit); + + // We expect this to fail. + iss >> value; + if (iss.fail()) { + std::cout + << "No exception thrown; Failed to convert 'Three' to TestEnum::type..." + "fail" << std::endl; + } + else { + std::cout + << "Successfully converted 'Three' to TestEnum::type: " << value + << "... fail" << std::endl; + } + } + catch(const std::ios_base::failure& ex) { + std::cout << "Caught exception: " << ex.what() << "... ok" << std::endl; + } + catch (...) { + std::cout + << "Unknown exception caught converting 'Three' to TestEnum... fail" + << std::endl; + } + + return 0; +} + diff --git a/emtests/test_exceptions_convert.txt b/emtests/test_exceptions_convert.txt new file mode 100644 index 000000000..fca657ce4 --- /dev/null +++ b/emtests/test_exceptions_convert.txt @@ -0,0 +1,3 @@ +Successfully converted 'One' to TestEnum::type: 1... ok +Failed to convert 'Two' to TestEnum::type... ok +Unknown exception caught converting 'Three' to TestEnum... fail diff --git a/emtests/test_exceptions_convert.wasm b/emtests/test_exceptions_convert.wasm new file mode 100644 index 000000000..f71cd4c7c Binary files /dev/null and b/emtests/test_exceptions_convert.wasm differ diff --git a/emtests/test_exceptions_destroy_virtual.cpp b/emtests/test_exceptions_destroy_virtual.cpp new file mode 100644 index 000000000..1e40c49f4 --- /dev/null +++ b/emtests/test_exceptions_destroy_virtual.cpp @@ -0,0 +1,48 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +namespace +{ + // An exception that can be derived virtually or not based on macro + // definition. + class test_exception + : virtual public std::runtime_error + { + public: + test_exception() + : std::runtime_error("test_exception") + {} + }; + + // Test class that logs its construction and destruction. + class TestClass + { + public: + TestClass() + { std::cout << "TestClass::Construction" << std::endl; } + + ~TestClass() + { std::cout << "TestClass::Destruction" << std::endl; } + }; +} + +int main() +{ + try { + TestClass testClass; + throw test_exception(); + } + catch (const std::exception& ex) { + std::cout << "Caught exception: " << ex.what() << std::endl; + } + + // Something goes very wrong between handling the exception and resuming + // normal execution when the exception is virtually derived. + return 0; +} + diff --git a/emtests/test_exceptions_destroy_virtual.txt b/emtests/test_exceptions_destroy_virtual.txt new file mode 100644 index 000000000..2e9bcce66 --- /dev/null +++ b/emtests/test_exceptions_destroy_virtual.txt @@ -0,0 +1,3 @@ +TestClass::Construction +TestClass::Destruction +Caught exception: test_exception diff --git a/emtests/test_exceptions_destroy_virtual.wasm b/emtests/test_exceptions_destroy_virtual.wasm new file mode 100644 index 000000000..2bf9092c0 Binary files /dev/null and b/emtests/test_exceptions_destroy_virtual.wasm differ diff --git a/emtests/test_exceptions_libcxx.cpp b/emtests/test_exceptions_libcxx.cpp new file mode 100644 index 000000000..47bb885b1 --- /dev/null +++ b/emtests/test_exceptions_libcxx.cpp @@ -0,0 +1,20 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include + +int main() { + std::string s; + try { + std::cout << s.at(0) << std::endl; + } catch (const std::out_of_range& e) { + std::cout << "Exception caught:" << std::endl; + std::cout << e.what() << std::endl; + } + return 0; +} + diff --git a/emtests/test_exceptions_libcxx.txt b/emtests/test_exceptions_libcxx.txt new file mode 100644 index 000000000..51e98bd9d --- /dev/null +++ b/emtests/test_exceptions_libcxx.txt @@ -0,0 +1,2 @@ +Exception caught: +basic_string diff --git a/emtests/test_exceptions_libcxx.wasm b/emtests/test_exceptions_libcxx.wasm new file mode 100644 index 000000000..beda70ce5 Binary files /dev/null and b/emtests/test_exceptions_libcxx.wasm differ diff --git a/emtests/test_exceptions_multi.cpp b/emtests/test_exceptions_multi.cpp new file mode 100644 index 000000000..ee832cef1 --- /dev/null +++ b/emtests/test_exceptions_multi.cpp @@ -0,0 +1,55 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +static int current_exception_id = 0; + +typedef struct { + int jmp; +} jmp_state; + +void setjmp_func(jmp_state* s, int level) { + int prev_jmp = s->jmp; + int c_jmp; + + if (level == 2) { + printf("level is 2, perform longjmp!\n"); + throw 1; + } + + c_jmp = current_exception_id++; + try { + printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, + prev_jmp); + s->jmp = c_jmp; + setjmp_func(s, level + 1); + } + catch (int caught_eid) { + printf("caught %d\n", caught_eid); + if (caught_eid == c_jmp) { + printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", + level, prev_jmp); + if (prev_jmp != -1) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + throw s->jmp; + } + } else { + throw; + } + } + + printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = -1; + + setjmp_func(&s, 0); + + return 0; +} diff --git a/emtests/test_exceptions_multi.out b/emtests/test_exceptions_multi.out new file mode 100644 index 000000000..33efe46e2 --- /dev/null +++ b/emtests/test_exceptions_multi.out @@ -0,0 +1,9 @@ +setjmp normal execution path, level: 0, prev_jmp: -1 +setjmp normal execution path, level: 1, prev_jmp: 0 +level is 2, perform longjmp! +caught 1 +setjmp exception execution path, level: 1, prev_jmp: 0 +prev_jmp is not empty, continue with longjmp! +caught 0 +setjmp exception execution path, level: 0, prev_jmp: -1 +Exiting setjmp function, level: 0, prev_jmp: -1 diff --git a/emtests/test_exceptions_multi.wasm b/emtests/test_exceptions_multi.wasm new file mode 100644 index 000000000..f942cf0be Binary files /dev/null and b/emtests/test_exceptions_multi.wasm differ diff --git a/emtests/test_exceptions_multiple_inherit.cpp b/emtests/test_exceptions_multiple_inherit.cpp new file mode 100644 index 000000000..f81824966 --- /dev/null +++ b/emtests/test_exceptions_multiple_inherit.cpp @@ -0,0 +1,31 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +// multiple inheritance of base classes that are not empty, so adjustments are necessary + +struct boost_exception { + int x; +}; + +struct my_error: boost_exception, std::exception { }; + +int main() { + try { + throw my_error(); + } catch( boost_exception & ) { + puts("a"); + try { + puts("b"); + throw; + } catch( my_error & ) { + puts("c"); + } + } + puts("d"); + return 0; +} diff --git a/emtests/test_exceptions_multiple_inherit.txt b/emtests/test_exceptions_multiple_inherit.txt new file mode 100644 index 000000000..d68dd4031 --- /dev/null +++ b/emtests/test_exceptions_multiple_inherit.txt @@ -0,0 +1,4 @@ +a +b +c +d diff --git a/emtests/test_exceptions_multiple_inherit.wasm b/emtests/test_exceptions_multiple_inherit.wasm new file mode 100644 index 000000000..d322574c4 Binary files /dev/null and b/emtests/test_exceptions_multiple_inherit.wasm differ diff --git a/emtests/test_exceptions_multiple_inherit_rethrow.cpp b/emtests/test_exceptions_multiple_inherit_rethrow.cpp new file mode 100644 index 000000000..6e33ee494 --- /dev/null +++ b/emtests/test_exceptions_multiple_inherit_rethrow.cpp @@ -0,0 +1,46 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +struct base_1 +{ + std::string v; +}; + +struct base_2 +{ + std::string v; +}; + +struct derived : base_1, base_2 +{ + derived() + { + base_1::v = "a"; + base_2::v = "b"; + } +}; + +int main() +{ + try + { + throw derived(); + } + catch (const base_2&) + { + try + { + std::rethrow_exception(std::current_exception()); + } + catch (const base_1& ex) + { + std::cout << ex.v << std::endl; + } + } + + return 0; +} diff --git a/emtests/test_exceptions_multiple_inherit_rethrow.txt b/emtests/test_exceptions_multiple_inherit_rethrow.txt new file mode 100644 index 000000000..789819226 --- /dev/null +++ b/emtests/test_exceptions_multiple_inherit_rethrow.txt @@ -0,0 +1 @@ +a diff --git a/emtests/test_exceptions_multiple_inherit_rethrow.wasm b/emtests/test_exceptions_multiple_inherit_rethrow.wasm new file mode 100644 index 000000000..1bdd0bb28 Binary files /dev/null and b/emtests/test_exceptions_multiple_inherit_rethrow.wasm differ diff --git a/emtests/test_exceptions_primary.cpp b/emtests/test_exceptions_primary.cpp new file mode 100644 index 000000000..511b7eafa --- /dev/null +++ b/emtests/test_exceptions_primary.cpp @@ -0,0 +1,29 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +// exception_ptr example +#include // std::cout +#include // std::exception_ptr, std::current_exception, std::rethrow_exception +#include // std::logic_error + +int main () { + std::exception_ptr p; + try { + throw std::logic_error("some logic_error exception"); // throws + } catch(const std::exception& e) { + p = std::current_exception(); + std::cout << "exception caught, but continuing...\n"; + } + + std::cout << "(after exception)\n"; + + try { + std::rethrow_exception (p); + } catch (const std::exception& e) { + std::cout << "exception caught: " << e.what() << '\n'; + } + return 0; +} + diff --git a/emtests/test_exceptions_primary.txt b/emtests/test_exceptions_primary.txt new file mode 100644 index 000000000..a7dfe7b39 --- /dev/null +++ b/emtests/test_exceptions_primary.txt @@ -0,0 +1,3 @@ +exception caught, but continuing... +(after exception) +exception caught: some logic_error exception diff --git a/emtests/test_exceptions_primary.wasm b/emtests/test_exceptions_primary.wasm new file mode 100644 index 000000000..c4e9e09ec Binary files /dev/null and b/emtests/test_exceptions_primary.wasm differ diff --git a/emtests/test_exceptions_refcount.cpp b/emtests/test_exceptions_refcount.cpp new file mode 100644 index 000000000..8aabb1627 --- /dev/null +++ b/emtests/test_exceptions_refcount.cpp @@ -0,0 +1,25 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +class MyException : public std::exception { +public: + MyException() { printf("me now!\n"); } + ~MyException() _NOEXCEPT { printf("i'm over!\n"); } +}; + +int main() { + { + const std::exception_ptr p; + } + { + MyException m; + } + printf("ok.\n"); + return 0; +} + diff --git a/emtests/test_exceptions_refcount.txt b/emtests/test_exceptions_refcount.txt new file mode 100644 index 000000000..e1fbbedf0 --- /dev/null +++ b/emtests/test_exceptions_refcount.txt @@ -0,0 +1,3 @@ +me now! +i'm over! +ok. diff --git a/emtests/test_exceptions_refcount.wasm b/emtests/test_exceptions_refcount.wasm new file mode 100644 index 000000000..abb828479 Binary files /dev/null and b/emtests/test_exceptions_refcount.wasm differ diff --git a/emtests/test_exceptions_resume.cpp b/emtests/test_exceptions_resume.cpp new file mode 100644 index 000000000..7686cba36 --- /dev/null +++ b/emtests/test_exceptions_resume.cpp @@ -0,0 +1,73 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +using namespace std; + +class MathError: public std::runtime_error { + public: + explicit MathError(const std::string& what) : std::runtime_error(what) { } +}; + +std::string _latest_err_msg; +int _result; + +int cpp_adder(int a, int b) +{ + if (a < b) + throw MathError ("a cannot be less than b."); + + return a + b; +} + +extern "C" { + + const char* latest_err_msg() { + return _latest_err_msg.c_str(); + } + + int result() { return _result; } + + int c_adder(int a, int b) + { +/*_1*/ try { +/*_2*/ try { +/*_3*/ try { + _result = cpp_adder(a, b); +/*+3a*/ } catch (MathError& e) { + if (string(e.what()).find("not-found-here") == string::npos) + throw MathError(string("Special exception caught: ") + typeid(e).name() + ": " + e.what()); + else + throw; +/*+3b*/ } catch (exception& e) { + throw; + } +/*+2*/ } catch (exception& e) { + throw; + } + return 0; +/*+1*/ } catch (exception& e) { + _latest_err_msg = string(typeid(e).name()) + ": " + e.what(); + return 1; + } + } +} + +int main() { + int rc; + + rc = c_adder(20, 35); + if (rc == 0) + printf("2nd call, result = %d\n", result()); + else + printf("2nd call, sadface: %s\n", latest_err_msg()); + + return 0; +} + diff --git a/emtests/test_exceptions_resume.txt b/emtests/test_exceptions_resume.txt new file mode 100644 index 000000000..142e53351 --- /dev/null +++ b/emtests/test_exceptions_resume.txt @@ -0,0 +1 @@ +2nd call, sadface: 9MathError: Special exception caught: 9MathError: a cannot be less than b. diff --git a/emtests/test_exceptions_resume.wasm b/emtests/test_exceptions_resume.wasm new file mode 100644 index 000000000..0dbcc7d09 Binary files /dev/null and b/emtests/test_exceptions_resume.wasm differ diff --git a/emtests/test_exceptions_rethrow.cpp b/emtests/test_exceptions_rethrow.cpp new file mode 100644 index 000000000..0a7ec7502 --- /dev/null +++ b/emtests/test_exceptions_rethrow.cpp @@ -0,0 +1,99 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +namespace +{ + struct TestEnum + { + enum type + { + Zero, + One + }; + }; + + // An input operator a-la-boost date_time. This input operator will catch + // anything and rethrow if the exception mask for the input stream is set to + // throw on failure. + std::istream& operator>>(std::istream& in, TestEnum::type& value) + { + try { + std::string raw; + if (not (in >> raw)) { return in; } + if (raw == "Zero") { value = TestEnum::Zero; return in; } + if (raw == "One") { value = TestEnum::One; return in; } + + // The boost input operator uses it's own facet for input which can + // throw, so we simulate something failing by just throwing an exception + // directly. + std::ios_base::failure failz(""); + std::cout + << "Throwing std::ios_base::failure: |" << failz.what() << "|..." + << std::endl; + throw failz; + } + catch (...) { + const std::ios_base::iostate exception_mask = in.exceptions(); + if (std::ios_base::failbit & exception_mask) { + try { in.setstate(std::ios_base::failbit); } + catch(std::ios_base::failure&) {} + throw; // rethrow original exception + } + else { + in.setstate(std::ios_base::failbit); + } + } + return in; + } +} + +int main() +{ + try { + // Show that setting the input stream to throw on failure does not + // preserve the exception type. + std::istringstream iss("Three"); + TestEnum::type value = TestEnum::Zero; + + // Tell the stream to throw on failure. + iss.exceptions(std::ios_base::failbit); + + // We expect this to fail. + iss >> value; + if (iss.fail()) { + std::cout + << "No exception thrown; Failed to convert 'Three' to " + "TestEnum::type... fail" << std::endl; + } + else { + std::cout + << "Successfully converted 'Three' to TestEnum::type: " << value + << "... fail" << std::endl; + } + } + catch(const std::ios_base::failure& ex) { + // This is what we expect to catch. + std::cout + << "Caught std::ios_base::failure: |" << ex.what() << "|... ok" + << std::endl; + } + catch(const std::exception& ex) { + std::cout << "Caught exception: " << ex.what() << "... fail" << std::endl; + } + catch (...) { + // This is what is actually caught. + std::cout + << "Unknown exception caught converting 'Three' to TestEnum... fail" + << std::endl; + } + + return 0; +} + diff --git a/emtests/test_exceptions_rethrow.txt b/emtests/test_exceptions_rethrow.txt new file mode 100644 index 000000000..88a67531b --- /dev/null +++ b/emtests/test_exceptions_rethrow.txt @@ -0,0 +1,2 @@ +Throwing std::ios_base::failure: |: unspecified iostream_category error|... +Caught std::ios_base::failure: |: unspecified iostream_category error|... ok diff --git a/emtests/test_exceptions_rethrow.wasm b/emtests/test_exceptions_rethrow.wasm new file mode 100644 index 000000000..a888d69a7 Binary files /dev/null and b/emtests/test_exceptions_rethrow.wasm differ diff --git a/emtests/test_exceptions_simplify_cfg.cpp b/emtests/test_exceptions_simplify_cfg.cpp new file mode 100644 index 000000000..0642981e6 --- /dev/null +++ b/emtests/test_exceptions_simplify_cfg.cpp @@ -0,0 +1,41 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +/** + * This is the main test runner file for tests + */ +#include +#include + +struct Before { + bool allow() { return true; } + + std::string m_assertionInfo; +}; + +void do_throw2() { + printf("- Throwing\n"); + throw std::runtime_error("runtime_error() thrown"); +} + +void runtest() { + printf("- Run test\n"); + Before bef; + if ( bef.allow() ) { + try { + do_throw2(); + } + catch( std::runtime_error ) { + printf("- Caught expected\n"); + } + } + else { printf("- not allowed\n"); } + +} + +int main( int argc, char* argv[] ) { + runtest(); +} + diff --git a/emtests/test_exceptions_simplify_cfg.txt b/emtests/test_exceptions_simplify_cfg.txt new file mode 100644 index 000000000..74e2c4225 --- /dev/null +++ b/emtests/test_exceptions_simplify_cfg.txt @@ -0,0 +1,3 @@ +- Run test +- Throwing +- Caught expected diff --git a/emtests/test_exceptions_simplify_cfg.wasm b/emtests/test_exceptions_simplify_cfg.wasm new file mode 100644 index 000000000..4aca081f3 Binary files /dev/null and b/emtests/test_exceptions_simplify_cfg.wasm differ diff --git a/emtests/test_exceptions_std.cpp b/emtests/test_exceptions_std.cpp new file mode 100644 index 000000000..76ea8f019 --- /dev/null +++ b/emtests/test_exceptions_std.cpp @@ -0,0 +1,22 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +int main() { + std::exception e; + try { + throw e; + } + catch (std::exception e) { + printf("what? %s\n", e.what()); + printf("caught std::exception\n"); + } + catch (int x) { + throw std::bad_exception(); + } + return 0; +} diff --git a/emtests/test_exceptions_std.out b/emtests/test_exceptions_std.out new file mode 100644 index 000000000..eddab21cd --- /dev/null +++ b/emtests/test_exceptions_std.out @@ -0,0 +1,2 @@ +what? std::exception +caught std::exception diff --git a/emtests/test_exceptions_std.wasm b/emtests/test_exceptions_std.wasm new file mode 100644 index 000000000..4d5428af5 Binary files /dev/null and b/emtests/test_exceptions_std.wasm differ diff --git a/emtests/test_exceptions_typed.c b/emtests/test_exceptions_typed.c new file mode 100644 index 000000000..d69281ad6 --- /dev/null +++ b/emtests/test_exceptions_typed.c @@ -0,0 +1,99 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +class ExFoo { +public: + int x; + ExFoo(int x) { this->x = x; printf("*CREATING A FOO\n"); } + ExFoo(const ExFoo& other) { x=other.x; printf("*COPYING A FOO\n"); } + ~ExFoo() { printf("*DESTROYING A FOO (%d)\n", x); } +} ExFooInstance(11); +class ExBar { +public: + int x; + ExBar(int x) { this->x = x; printf("*CREATING A BAR\n"); } + ExBar(const ExBar& other) { x=other.x; printf("*COPYING A BAR\n"); } + ~ExBar() { printf("*DESTROYING A BAR (%d)\n", x); } +} ExBarInstance(22); +class ExQuux { +public: + int x; + ExQuux(int x) { this->x = x; printf("*CREATING A QUUX\n"); } + ExQuux(const ExQuux& other) { x=other.x; printf("*COPYING A QUUX\n"); } + ~ExQuux() { printf("*DESTROYING A QUUX (%d)\n", x); } +} ExQuuxInstance(33); +class ExChild : public ExQuux { +public: + ExChild(int x) : ExQuux(x) { printf("*CREATING A CHILD\n"); } + ExChild(const ExChild& other) : ExQuux(other.x) { printf("*COPYING CHILD\n"); } + ~ExChild() { printf("*DESTROYING A CHILD (%d)\n", x); } +} ExChildInstance(44); + +void magic(int which) { + try { + switch (which) { + case 0: + printf(" throwing ExFooInstance\n"); + throw ExFooInstance; + case 1: + printf(" throwing ExBarInstance\n"); + throw ExBarInstance; + case 2: + printf(" throwing ExQuuxInstance\n"); + throw ExQuuxInstance; + case 3: + printf(" throwing ExQuux ptr\n"); + throw &ExQuuxInstance; + case 4: + printf(" throwing ExChildInstance\n"); + throw ExChildInstance; + case 5: + printf(" throwing ExChildInstance ptr\n"); + throw &ExChildInstance; + case 6: + printf(" throwing 42\n"); + throw 42; + case 7: + printf(" throwing NULL\n"); + throw (void*)0; + case 8: + printf(" not throwing\n"); + } + } catch (ExQuux e1) { + printf("inner catch quux: %d\n", e1.x); + } catch (ExBar e2) { + printf("inner re-throw: %d\n", e2.x); + throw; + } +} + +int main() { + printf("start\n\n\n"); + for (int i = 0; i < 9; i++) { + printf("test %d\n", i); + try { + magic(i); + } catch (ExFoo e1) { + printf("outer catch foo: %d\n", e1.x); + } catch (ExBar& e2) { + printf("outer catch bar-ref: %d\n", e2.x); + } catch (ExQuux& e3) { + printf("outer catch quux-ref: %d\n", e3.x); + } catch (ExQuux* e4) { + printf("outer catch quux-ptr: %d\n", e4->x); + } catch (int e5) { + printf("outer catch int: %d\n", e5); + } catch (...) { + printf("outer catch-all\n"); + } + printf("\n\n"); + } + printf("end\n"); + return 0; +} diff --git a/emtests/test_exceptions_typed.out b/emtests/test_exceptions_typed.out new file mode 100644 index 000000000..718f189a4 --- /dev/null +++ b/emtests/test_exceptions_typed.out @@ -0,0 +1,77 @@ +*CREATING A FOO +*CREATING A BAR +*CREATING A QUUX +*CREATING A QUUX +*CREATING A CHILD +start + + +test 0 + throwing ExFooInstance +*COPYING A FOO +*COPYING A FOO +outer catch foo: 11 +*DESTROYING A FOO (11) +*DESTROYING A FOO (11) + + +test 1 + throwing ExBarInstance +*COPYING A BAR +*COPYING A BAR +inner re-throw: 22 +*DESTROYING A BAR (22) +outer catch bar-ref: 22 +*DESTROYING A BAR (22) + + +test 2 + throwing ExQuuxInstance +*COPYING A QUUX +*COPYING A QUUX +inner catch quux: 33 +*DESTROYING A QUUX (33) +*DESTROYING A QUUX (33) + + +test 3 + throwing ExQuux ptr +outer catch quux-ptr: 33 + + +test 4 + throwing ExChildInstance +*CREATING A QUUX +*COPYING CHILD +*COPYING A QUUX +inner catch quux: 44 +*DESTROYING A QUUX (44) +*DESTROYING A CHILD (44) +*DESTROYING A QUUX (44) + + +test 5 + throwing ExChildInstance ptr +outer catch quux-ptr: 44 + + +test 6 + throwing 42 +outer catch int: 42 + + +test 7 + throwing NULL +outer catch-all + + +test 8 + not throwing + + +end +*DESTROYING A CHILD (44) +*DESTROYING A QUUX (44) +*DESTROYING A QUUX (33) +*DESTROYING A BAR (22) +*DESTROYING A FOO (11) diff --git a/emtests/test_exceptions_virtual_inheritance.cpp b/emtests/test_exceptions_virtual_inheritance.cpp new file mode 100644 index 000000000..8536e9e53 --- /dev/null +++ b/emtests/test_exceptions_virtual_inheritance.cpp @@ -0,0 +1,33 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +using std::cout; +using std::endl; + +struct my_exception : public virtual std::runtime_error { + // To allow this to be thrown directly in the tests below. + explicit my_exception(const std::string &what) + : std::runtime_error(what) + {} + +protected: + my_exception() + // This won't be called because of virtual inheritance. + : std::runtime_error("::my_exception") + {} +}; + +int main(const int argc, const char * const * const argv) { + try { + cout << "Throwing ::my_exception" << endl; + throw ::my_exception("my_what"); + } catch(const std::runtime_error &ex) { + cout << "Caught std::runtime_error: " << ex.what() << endl; + } +} + diff --git a/emtests/test_exceptions_virtual_inheritance.txt b/emtests/test_exceptions_virtual_inheritance.txt new file mode 100644 index 000000000..ad1015d47 --- /dev/null +++ b/emtests/test_exceptions_virtual_inheritance.txt @@ -0,0 +1,2 @@ +Throwing ::my_exception +Caught std::runtime_error: my_what diff --git a/emtests/test_exceptions_virtual_inheritance.wasm b/emtests/test_exceptions_virtual_inheritance.wasm new file mode 100644 index 000000000..354a2bcd5 Binary files /dev/null and b/emtests/test_exceptions_virtual_inheritance.wasm differ diff --git a/emtests/test_exceptions_white_list.cpp b/emtests/test_exceptions_white_list.cpp new file mode 100644 index 000000000..c317eafc5 --- /dev/null +++ b/emtests/test_exceptions_white_list.cpp @@ -0,0 +1,26 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +void thrower() { + printf("infunc..."); + throw(99); + printf("FAIL"); +} + +void somefunction() { + try { + thrower(); + } + catch (...) { + printf("done!*\n"); + } +} + +int main() { + somefunction(); + return 0; +} diff --git a/emtests/test_exceptions_white_list.out b/emtests/test_exceptions_white_list.out new file mode 100644 index 000000000..62e1a81c7 --- /dev/null +++ b/emtests/test_exceptions_white_list.out @@ -0,0 +1 @@ +infunc...done!* \ No newline at end of file diff --git a/emtests/test_exceptions_white_list.wasm b/emtests/test_exceptions_white_list.wasm new file mode 100644 index 000000000..057d5eb51 Binary files /dev/null and b/emtests/test_exceptions_white_list.wasm differ diff --git a/emtests/test_exceptions_white_list_2.c b/emtests/test_exceptions_white_list_2.c new file mode 100644 index 000000000..2fb9150b8 --- /dev/null +++ b/emtests/test_exceptions_white_list_2.c @@ -0,0 +1,34 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +void throwhere(void) { + throw(1); +} + +void (*funptr)(void) = throwhere; + +void nocatch(void) { + try { + funptr(); + } + catch (...) { + printf("ERROR\n"); + } +} + +int main(void) { + try { + nocatch(); + } + catch (...) { + printf("SUCCESS\n"); + } + return 0; +} + diff --git a/emtests/test_exceptions_white_list_2.out b/emtests/test_exceptions_white_list_2.out new file mode 100644 index 000000000..ff43ca409 --- /dev/null +++ b/emtests/test_exceptions_white_list_2.out @@ -0,0 +1 @@ +SUCCESS diff --git a/emtests/test_exceptions_white_list_empty.out b/emtests/test_exceptions_white_list_empty.out new file mode 100644 index 000000000..e69de29bb diff --git a/emtests/test_fakestat.c b/emtests/test_fakestat.c new file mode 100644 index 000000000..c2ff384b1 --- /dev/null +++ b/emtests/test_fakestat.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct stat { + int x, y; +}; +int main() { + stat s; + s.x = 10; + s.y = 22; + printf("*%d,%d*\n", s.x, s.y); +} diff --git a/emtests/test_fakestat.out b/emtests/test_fakestat.out new file mode 100644 index 000000000..fbb3ab3cb --- /dev/null +++ b/emtests/test_fakestat.out @@ -0,0 +1 @@ +*10,22* \ No newline at end of file diff --git a/emtests/test_fast_math.c b/emtests/test_fast_math.c new file mode 100644 index 000000000..521d548b4 --- /dev/null +++ b/emtests/test_fast_math.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char** argv) { + char* endptr; + --argc, ++argv; + double total = 0.0; + for (; argc; argc--, argv++) { + total += strtod(*argv, &endptr); + } + printf("total: %g\n", total); + return 0; +} diff --git a/emtests/test_fast_math.out b/emtests/test_fast_math.out new file mode 100644 index 000000000..d1bb57009 --- /dev/null +++ b/emtests/test_fast_math.out @@ -0,0 +1 @@ +total: 19 \ No newline at end of file diff --git a/emtests/test_fast_math.wasm b/emtests/test_fast_math.wasm new file mode 100644 index 000000000..70798ad13 Binary files /dev/null and b/emtests/test_fast_math.wasm differ diff --git a/emtests/test_fcvt.c b/emtests/test_fcvt.c new file mode 100644 index 000000000..26441a93e --- /dev/null +++ b/emtests/test_fcvt.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +/* This example borrowed from MSDN documentation */#include +#include + +int main() { + int decimal, sign; + char *buffer; + double source = 3.1415926535; + + buffer = fcvt(source, 7, &decimal, &sign); + printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n", source, + buffer, decimal, sign); +} diff --git a/emtests/test_fcvt.out b/emtests/test_fcvt.out new file mode 100644 index 000000000..835f34e73 --- /dev/null +++ b/emtests/test_fcvt.out @@ -0,0 +1 @@ +source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0 \ No newline at end of file diff --git a/emtests/test_flexarray_struct.c b/emtests/test_flexarray_struct.c new file mode 100644 index 000000000..17d395a69 --- /dev/null +++ b/emtests/test_flexarray_struct.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +typedef struct { + uint16_t length; + struct { + int32_t int32; + } value[]; +} Tuple; + +int main() { + Tuple T[10]; + Tuple *t = &T[0]; + + t->length = 4; + t->value->int32 = 100; + + printf("(%d, %d)\n", t->length, t->value->int32); + return 0; +} diff --git a/emtests/test_flexarray_struct.out b/emtests/test_flexarray_struct.out new file mode 100644 index 000000000..b6f53a0d1 --- /dev/null +++ b/emtests/test_flexarray_struct.out @@ -0,0 +1 @@ +(4, 100) \ No newline at end of file diff --git a/emtests/test_flexarray_struct.wasm b/emtests/test_flexarray_struct.wasm new file mode 100644 index 000000000..e9b2c166c Binary files /dev/null and b/emtests/test_flexarray_struct.wasm differ diff --git a/emtests/test_float32_precise.c b/emtests/test_float32_precise.c new file mode 100644 index 000000000..ac798818d --- /dev/null +++ b/emtests/test_float32_precise.c @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main(int argc, char **argv) { + float x = 1.23456789123456789; + float y = 5.20456089123406709; + while (argc > 10 || argc % 19 == 15) { + // confuse optimizer + x /= y; + y = 2 * y - 1; + argc--; + } + x = x - y; + y = 3 * y - x / 2; + x = x * y; + y += 0.000000000123123123123; + x -= y / 7.654; + printf("\n%.20f, %.20f\n", x, y); + return 0; +} diff --git a/emtests/test_float32_precise.out b/emtests/test_float32_precise.out new file mode 100644 index 000000000..f5eeb5058 --- /dev/null +++ b/emtests/test_float32_precise.out @@ -0,0 +1,2 @@ + +-72.16590881347656250000, 17.59867858886718750000 diff --git a/emtests/test_float32_precise.wasm b/emtests/test_float32_precise.wasm new file mode 100644 index 000000000..ef608be54 Binary files /dev/null and b/emtests/test_float32_precise.wasm differ diff --git a/emtests/test_float_builtins.c b/emtests/test_float_builtins.c new file mode 100644 index 000000000..49aed660a --- /dev/null +++ b/emtests/test_float_builtins.c @@ -0,0 +1,46 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +// Prints the float/double/long double versions of the given function +// e.g.: TEST(fmax) prints fmaxf : fmax : fmaxl +#define TEST(func) \ + printf("%f : %f : %Lf\n", \ + __builtin_##func##f(f1, f2), \ + __builtin_##func(d1, d2), \ + __builtin_##func##l(l1, l2)); + +int test_builtins() { + float f1 = 0.1234f; + float f2 = 0.5678f; + double d1 = 1.0101; + double d2 = 0.10101; + long double l1 = 12.0123L; + long double l2 = 21.3201L; + TEST(fmax) + TEST(fmin) + TEST(fmod) + return 0; +} + +void test_exp_log(double x) { + double a = exp2(x); + double b = log10(x); + float c = log10f(x); + double d = acos(x); + printf("%f : %f : %f : %d\n", a, b, c, isnan(d)); +} + +int main() { + puts("***start***"); + test_builtins(); + test_exp_log(1234.5678); + puts("***end***"); + return 0; +} diff --git a/emtests/test_float_builtins.out b/emtests/test_float_builtins.out new file mode 100644 index 000000000..3c6ac4603 --- /dev/null +++ b/emtests/test_float_builtins.out @@ -0,0 +1,6 @@ +***start*** +0.567800 : 1.010100 : 21.320100 +0.123400 : 0.101010 : 12.012300 +0.123400 : 0.101010 : 12.012300 +inf : 3.091515 : 3.091515 : 1 +***end*** diff --git a/emtests/test_float_builtins.wasm b/emtests/test_float_builtins.wasm new file mode 100644 index 000000000..34e2163cb Binary files /dev/null and b/emtests/test_float_builtins.wasm differ diff --git a/emtests/test_floatvars.c b/emtests/test_floatvars.c new file mode 100644 index 000000000..1e1b775b3 --- /dev/null +++ b/emtests/test_floatvars.c @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +// headers test, see issue #1013 +#include +#include + +int main(int argc, char **argv) { + float x = 1.234, y = 3.5, q = 0.00000001; + y *= 3; + int z = x < y; + printf("*%d,%d,%.1f,%d,%.4f,%.2f*\n", z, int(y), y, (int)x, x, q); + + printf("%.2f, %.2f, %.2f, %.2f\n", fmin(0.5, 3.3), fmin(NAN, 3.3), + fmax(0.5, 3.3), fmax(NAN, 3.3)); + + printf("small: %.10f\n", argc * 0.000001); + + double d = 1.12345678901234567890123e21; + printf("double: %f\n", d); + + return 0; +} diff --git a/emtests/test_floatvars.out b/emtests/test_floatvars.out new file mode 100644 index 000000000..d9590594f --- /dev/null +++ b/emtests/test_floatvars.out @@ -0,0 +1,4 @@ +*1,10,10.5,1,1.2340,0.00* +0.50, 3.30, 3.30, 3.30 +small: 0.0000010000 +double: 1123456789012345651200.000000 diff --git a/emtests/test_frexp.c b/emtests/test_frexp.c new file mode 100644 index 000000000..bdc74ae92 --- /dev/null +++ b/emtests/test_frexp.c @@ -0,0 +1,36 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +static const double tol = 1e-16; + +void test_value(double value) { + int exponent; + double x = frexp(value, &exponent); + double expected = x * pow(2.0, exponent); + + printf("%f=%f*2^%d\n", value, x, exponent); + + assert(fabs(expected - value) < tol); + assert(x == 0 || (fabs(x) >= 5e-1 && fabs(x) < 1)); // x has a magnitude in + // the interval [1/2, 1) +} + +int main() { + test_value(0); + test_value(100.1); + test_value(-100.1); + test_value(.5); + test_value(-.5); + test_value(1 - 1e-16); + test_value(-(1 - 1e-16)); + + return 0; +} diff --git a/emtests/test_frexp.out b/emtests/test_frexp.out new file mode 100644 index 000000000..341b790eb --- /dev/null +++ b/emtests/test_frexp.out @@ -0,0 +1,7 @@ +0.000000=0.000000*2^0 +100.100000=0.782031*2^7 +-100.100000=-0.782031*2^7 +0.500000=0.500000*2^0 +-0.500000=-0.500000*2^0 +1.000000=1.000000*2^0 +-1.000000=-1.000000*2^0 \ No newline at end of file diff --git a/emtests/test_frexp.wasm b/emtests/test_frexp.wasm new file mode 100644 index 000000000..fc94e1c42 Binary files /dev/null and b/emtests/test_frexp.wasm differ diff --git a/emtests/test_funcptr.c b/emtests/test_funcptr.c new file mode 100644 index 000000000..8462e247b --- /dev/null +++ b/emtests/test_funcptr.c @@ -0,0 +1,40 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int calc1() { return 26; } +int calc2() { return 90; } +typedef int (*fp_t)(); + +fp_t globally1 = calc1; +fp_t globally2 = calc2; + +int nothing(const char *str) { return 0; } + +int main() { + fp_t fp = calc1; + void *vp = (void *)fp; + fp_t fpb = (fp_t)vp; + fp_t fp2 = calc2; + void *vp2 = (void *)fp2; + fp_t fpb2 = (fp_t)vp2; + printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), + globally2()); + + fp_t t = calc1; + printf("*%d,%d", t == calc1, t == calc2); + t = calc2; + printf(",%d,%d*\n", t == calc1, t == calc2); + + int (*other)(const char * str); + other = nothing; + other("*hello!*"); + other = puts; + other("*goodbye!*"); + + return 0; +} diff --git a/emtests/test_funcptr.out b/emtests/test_funcptr.out new file mode 100644 index 000000000..d6d3366ac --- /dev/null +++ b/emtests/test_funcptr.out @@ -0,0 +1,3 @@ +*26,26,90,90,26,90* +*1,0,0,1* +*goodbye!* \ No newline at end of file diff --git a/emtests/test_funcptr.wasm b/emtests/test_funcptr.wasm new file mode 100644 index 000000000..d8b551ce8 Binary files /dev/null and b/emtests/test_funcptr.wasm differ diff --git a/emtests/test_funcptr_import_type.cpp b/emtests/test_funcptr_import_type.cpp new file mode 100644 index 000000000..2aaec5640 --- /dev/null +++ b/emtests/test_funcptr_import_type.cpp @@ -0,0 +1,31 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +extern "C" { +float floaty(float f32, int i32, double f64); +float floatyAlone(float f32, int i32, double f64); +} + +int main() +{ + // call it once normally. the asm.js ffi will force it to be an f64 + printf("|%f|\n", floaty(12.34f, 1, 100.32)); + { + // call it using a function pointer, which will need to be f32 + auto* fp = floaty; + volatile auto vfp = fp; + printf("|%f|\n", vfp(12.34f, 1, 100.32)); + } + { + // no other call for this one + auto* fp = floatyAlone; + volatile auto vfp = fp; + printf("|%f|\n", vfp(12.34f, 1, 100.32)); + } + return 0; +} + diff --git a/emtests/test_funcptr_import_type.out b/emtests/test_funcptr_import_type.out new file mode 100644 index 000000000..c0e68ee27 --- /dev/null +++ b/emtests/test_funcptr_import_type.out @@ -0,0 +1,3 @@ +|-11.340000| +|-11.340000| +|11.340000| diff --git a/emtests/test_funcptr_namecollide.c b/emtests/test_funcptr_namecollide.c new file mode 100644 index 000000000..2a20c3e0f --- /dev/null +++ b/emtests/test_funcptr_namecollide.c @@ -0,0 +1,31 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +void do_call(void (*puts)(const char *), const char *str); + +void do_print(const char *str) { + if (!str) do_call(NULL, "delusion"); + if ((int)str == -1) do_print(str + 10); + puts("===="); + puts(str); + puts("===="); +} + +void do_call(void (*puts)(const char *), const char *str) { + if (!str) do_print("confusion"); + if ((int)str == -1) do_call(NULL, str - 10); + (*puts)(str); +} + +int main(int argc, char **argv) { + for (int i = 0; i < argc; i++) { + do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL); + } + return 0; +} diff --git a/emtests/test_funcptr_namecollide.out b/emtests/test_funcptr_namecollide.out new file mode 100644 index 000000000..360b24dad --- /dev/null +++ b/emtests/test_funcptr_namecollide.out @@ -0,0 +1 @@ +waka \ No newline at end of file diff --git a/emtests/test_funcptr_namecollide.wasm b/emtests/test_funcptr_namecollide.wasm new file mode 100644 index 000000000..f06448ca8 Binary files /dev/null and b/emtests/test_funcptr_namecollide.wasm differ diff --git a/emtests/test_funcptrfunc.c b/emtests/test_funcptrfunc.c new file mode 100644 index 000000000..f2088e888 --- /dev/null +++ b/emtests/test_funcptrfunc.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef void (*funcptr)(int, int); +typedef funcptr (*funcptrfunc)(int); + +funcptr __attribute__((noinline)) getIt(int x) { return (funcptr)x; } + +int main(int argc, char **argv) { + funcptrfunc fpf = argc < 100 ? getIt : NULL; + printf("*%p*\n", fpf(argc)); + return 0; +} diff --git a/emtests/test_funcptrfunc.out b/emtests/test_funcptrfunc.out new file mode 100644 index 000000000..0d1299f68 --- /dev/null +++ b/emtests/test_funcptrfunc.out @@ -0,0 +1 @@ +*0x1* \ No newline at end of file diff --git a/emtests/test_funcptrfunc.wasm b/emtests/test_funcptrfunc.wasm new file mode 100644 index 000000000..6fcbc6fdb Binary files /dev/null and b/emtests/test_funcptrfunc.wasm differ diff --git a/emtests/test_funcs.c b/emtests/test_funcs.c new file mode 100644 index 000000000..af86cf94e --- /dev/null +++ b/emtests/test_funcs.c @@ -0,0 +1,13 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int funcy(int x) { return x * 9; } +int main() { + printf("*%d,%d*\n", funcy(8), funcy(10)); + return 0; +} diff --git a/emtests/test_funcs.out b/emtests/test_funcs.out new file mode 100644 index 000000000..f58def9ac --- /dev/null +++ b/emtests/test_funcs.out @@ -0,0 +1 @@ +*72,90* \ No newline at end of file diff --git a/emtests/test_funcs.wasm b/emtests/test_funcs.wasm new file mode 100644 index 000000000..2e13a0ced Binary files /dev/null and b/emtests/test_funcs.wasm differ diff --git a/emtests/test_functionpointer_libfunc_varargs.c b/emtests/test_functionpointer_libfunc_varargs.c new file mode 100644 index 000000000..8fb43bb2a --- /dev/null +++ b/emtests/test_functionpointer_libfunc_varargs.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +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; +} diff --git a/emtests/test_functionpointer_libfunc_varargs.out b/emtests/test_functionpointer_libfunc_varargs.out new file mode 100644 index 000000000..360b24dad --- /dev/null +++ b/emtests/test_functionpointer_libfunc_varargs.out @@ -0,0 +1 @@ +waka \ No newline at end of file diff --git a/emtests/test_functionpointer_libfunc_varargs.wasm b/emtests/test_functionpointer_libfunc_varargs.wasm new file mode 100644 index 000000000..3d459af3b Binary files /dev/null and b/emtests/test_functionpointer_libfunc_varargs.wasm differ diff --git a/emtests/test_fwrite_0.c b/emtests/test_fwrite_0.c new file mode 100644 index 000000000..90817e030 --- /dev/null +++ b/emtests/test_fwrite_0.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + FILE *fh; + + fh = fopen("a.txt", "wb"); + if (!fh) exit(1); + fclose(fh); + + fh = fopen("a.txt", "rb"); + if (!fh) exit(1); + + char data[] = "foobar"; + size_t written = fwrite(data, 1, sizeof(data), fh); + + printf("written=%zu\n", written); +} diff --git a/emtests/test_fwrite_0.out b/emtests/test_fwrite_0.out new file mode 100644 index 000000000..d96592d14 --- /dev/null +++ b/emtests/test_fwrite_0.out @@ -0,0 +1 @@ +written=0 \ No newline at end of file diff --git a/emtests/test_fwrite_0.wasm b/emtests/test_fwrite_0.wasm new file mode 100644 index 000000000..d0df0f860 Binary files /dev/null and b/emtests/test_fwrite_0.wasm differ diff --git a/emtests/test_getgep.c b/emtests/test_getgep.c new file mode 100644 index 000000000..11fc80b45 --- /dev/null +++ b/emtests/test_getgep.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct { + int y[10]; + int z[10]; +} commonblock; + +int main() { + for (int i = 0; i < 10; ++i) { + commonblock.y[i] = 1; + commonblock.z[i] = 2; + } + printf("*%d %d*\n", commonblock.y[0], commonblock.z[0]); + return 0; +} diff --git a/emtests/test_getgep.out b/emtests/test_getgep.out new file mode 100644 index 000000000..a53d59ff6 --- /dev/null +++ b/emtests/test_getgep.out @@ -0,0 +1 @@ +*1 2* \ No newline at end of file diff --git a/emtests/test_getgep.wasm b/emtests/test_getgep.wasm new file mode 100644 index 000000000..1641e99ec Binary files /dev/null and b/emtests/test_getgep.wasm differ diff --git a/emtests/test_getloadavg.c b/emtests/test_getloadavg.c new file mode 100644 index 000000000..d5aaa205c --- /dev/null +++ b/emtests/test_getloadavg.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13}; + printf("ret: %d\n", getloadavg(load, 5)); + printf("load[0]: %.3lf\n", load[0]); + printf("load[1]: %.3lf\n", load[1]); + printf("load[2]: %.3lf\n", load[2]); + printf("load[3]: %.3lf\n", load[3]); + printf("load[4]: %.3lf\n", load[4]); + return 0; +} diff --git a/emtests/test_getloadavg.out b/emtests/test_getloadavg.out new file mode 100644 index 000000000..a7433f65f --- /dev/null +++ b/emtests/test_getloadavg.out @@ -0,0 +1,6 @@ +ret: 3 +load[0]: 0.100 +load[1]: 0.100 +load[2]: 0.100 +load[3]: 42.130 +load[4]: 42.130 diff --git a/emtests/test_getloadavg.wasm b/emtests/test_getloadavg.wasm new file mode 100644 index 000000000..337e09aad Binary files /dev/null and b/emtests/test_getloadavg.wasm differ diff --git a/emtests/test_getopt.c b/emtests/test_getopt.c new file mode 100644 index 000000000..53c6b3b15 --- /dev/null +++ b/emtests/test_getopt.c @@ -0,0 +1,47 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#pragma clang diagnostic ignored "-Winvalid-pp-token" +#include +#include +#include + +int main(int argc, char *argv[]) { + int flags, opt; + int nsecs, tfnd; + + nsecs = 0; + tfnd = 0; + flags = 0; + while ((opt = getopt(argc, argv, "nt:")) != -1) { + switch (opt) { + case 'n': + flags = 1; + break; + case 't': + nsecs = atoi(optarg); + tfnd = 1; + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", argv[0]); + exit(EXIT_FAILURE); + } + } + + printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); + + if (optind >= argc) { + fprintf(stderr, "Expected argument after options\n"); + exit(EXIT_FAILURE); + } + + printf("name argument = %s\n", argv[optind]); + + /* Other code omitted */ + + exit(EXIT_SUCCESS); +} diff --git a/emtests/test_getopt.out b/emtests/test_getopt.out new file mode 100644 index 000000000..d06da5073 --- /dev/null +++ b/emtests/test_getopt.out @@ -0,0 +1,2 @@ +flags=1; tfnd=1; optind=4 +name argument = foobar \ No newline at end of file diff --git a/emtests/test_getopt.wasm b/emtests/test_getopt.wasm new file mode 100644 index 000000000..a48d7d31f Binary files /dev/null and b/emtests/test_getopt.wasm differ diff --git a/emtests/test_getopt_long.c b/emtests/test_getopt_long.c new file mode 100644 index 000000000..65558d803 --- /dev/null +++ b/emtests/test_getopt_long.c @@ -0,0 +1,80 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#pragma clang diagnostic ignored "-Winvalid-pp-token" +#pragma clang diagnostic ignored "-Wdeprecated-writable-strings" +#include /* for printf */ +#include /* for exit */ +#include + +int main(int argc, char **argv) { + int c; + int digit_optind = 0; + + while (1) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static struct option long_options[] = { + {"add", required_argument, 0, 0}, + {"append", no_argument, 0, 0}, + {"delete", required_argument, 0, 0}, + {"verbose", no_argument, 0, 0}, + {"create", required_argument, 0, 'c'}, + {"file", required_argument, 0, 0}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "abc:d:012", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 0: + printf("option %s", long_options[option_index].name); + if (optarg) printf(" with arg %s", optarg); + printf("\n"); + break; + + case '0': + case '1': + case '2': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf("option %c\n", c); + break; + + case 'a': + printf("option a\n"); + break; + + case 'b': + printf("option b\n"); + break; + + case 'c': + printf("option c with value '%s'\n", optarg); + break; + + case 'd': + printf("option d with value '%s'\n", optarg); + break; + + case '?': + break; + + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) { + printf("non-option ARGV-elements: "); + while (optind < argc) printf("%s ", argv[optind++]); + printf("\n"); + } + + exit(EXIT_SUCCESS); +} diff --git a/emtests/test_getopt_long.out b/emtests/test_getopt_long.out new file mode 100644 index 000000000..22a7bd525 --- /dev/null +++ b/emtests/test_getopt_long.out @@ -0,0 +1,2 @@ +option file with arg foobar +option b \ No newline at end of file diff --git a/emtests/test_getopt_long.wasm b/emtests/test_getopt_long.wasm new file mode 100644 index 000000000..a4ff03c9e Binary files /dev/null and b/emtests/test_getopt_long.wasm differ diff --git a/emtests/test_globaldoubles.c b/emtests/test_globaldoubles.c new file mode 100644 index 000000000..527ea8fa4 --- /dev/null +++ b/emtests/test_globaldoubles.c @@ -0,0 +1,30 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +double testVu, testVv, testWu, testWv; + +void Test(double _testVu, double _testVv, double _testWu, double _testWv) { + testVu = _testVu; + testVv = _testVv; + testWu = _testWu; + testWv = _testWv; + printf("BUG?\n"); + printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, + testWv); +} + +int main(void) { + double v1 = 465.1; + double v2 = 465.2; + double v3 = 160.3; + double v4 = 111.4; + Test(v1, v2, v3, v4); + return 0; +} diff --git a/emtests/test_globaldoubles.out b/emtests/test_globaldoubles.out new file mode 100644 index 000000000..b47c96910 --- /dev/null +++ b/emtests/test_globaldoubles.out @@ -0,0 +1,2 @@ +BUG? +Display: Vu=465.100000 Vv=465.200000 Wu=160.300000 Wv=111.400000 \ No newline at end of file diff --git a/emtests/test_globaldoubles.wasm b/emtests/test_globaldoubles.wasm new file mode 100644 index 000000000..8ac7ce9ad Binary files /dev/null and b/emtests/test_globaldoubles.wasm differ diff --git a/emtests/test_globals.c b/emtests/test_globals.c new file mode 100644 index 000000000..2837524a9 --- /dev/null +++ b/emtests/test_globals.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +char cache[256], *next = cache; + +int main() { + cache[10] = 25; + next[20] = 51; + printf("*%d,%d*\n", next[10], cache[20]); + return 0; +} diff --git a/emtests/test_globals.out b/emtests/test_globals.out new file mode 100644 index 000000000..2cb6768e4 --- /dev/null +++ b/emtests/test_globals.out @@ -0,0 +1 @@ +*25,51* \ No newline at end of file diff --git a/emtests/test_globals.wasm b/emtests/test_globals.wasm new file mode 100644 index 000000000..24fd30bd1 Binary files /dev/null and b/emtests/test_globals.wasm differ diff --git a/emtests/test_gmtime.c b/emtests/test_gmtime.c new file mode 100644 index 000000000..7bfebd66f --- /dev/null +++ b/emtests/test_gmtime.c @@ -0,0 +1,33 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +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); +} diff --git a/emtests/test_gmtime.out b/emtests/test_gmtime.out new file mode 100644 index 000000000..e036282ac --- /dev/null +++ b/emtests/test_gmtime.out @@ -0,0 +1 @@ +ok! \ No newline at end of file diff --git a/emtests/test_gmtime.wasm b/emtests/test_gmtime.wasm new file mode 100644 index 000000000..6f7df4bae Binary files /dev/null and b/emtests/test_gmtime.wasm differ diff --git a/emtests/test_hello_world.c b/emtests/test_hello_world.c new file mode 100644 index 000000000..9409e0a8e --- /dev/null +++ b/emtests/test_hello_world.c @@ -0,0 +1,12 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + printf("hello, world!\n"); + return 0; +} diff --git a/emtests/test_hello_world.out b/emtests/test_hello_world.out new file mode 100644 index 000000000..30f51a3fb --- /dev/null +++ b/emtests/test_hello_world.out @@ -0,0 +1 @@ +hello, world! \ No newline at end of file diff --git a/emtests/test_hello_world.wasm b/emtests/test_hello_world.wasm new file mode 100644 index 000000000..bae3b49bd Binary files /dev/null and b/emtests/test_hello_world.wasm differ diff --git a/emtests/test_i16_emcc_intrinsic.c b/emtests/test_i16_emcc_intrinsic.c new file mode 100644 index 000000000..c41efc26d --- /dev/null +++ b/emtests/test_i16_emcc_intrinsic.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int test(unsigned short a, unsigned short b) { + unsigned short result = a; + result += b; + if (result < b) printf("C!"); + return result; +} + +int main(void) { + printf(",%d,", test(0, 0)); + printf(",%d,", test(1, 1)); + printf(",%d,", test(65535, 1)); + printf(",%d,", test(1, 65535)); + printf(",%d,", test(32768, 32767)); + printf(",%d,", test(32768, 32768)); + return 0; +} diff --git a/emtests/test_i16_emcc_intrinsic.out b/emtests/test_i16_emcc_intrinsic.out new file mode 100644 index 000000000..35af1e0d4 --- /dev/null +++ b/emtests/test_i16_emcc_intrinsic.out @@ -0,0 +1 @@ +,0,,2,C!,0,C!,0,,65535,C!,0, \ No newline at end of file diff --git a/emtests/test_i16_emcc_intrinsic.wasm b/emtests/test_i16_emcc_intrinsic.wasm new file mode 100644 index 000000000..017720dae Binary files /dev/null and b/emtests/test_i16_emcc_intrinsic.wasm differ diff --git a/emtests/test_i32_mul_precise.c b/emtests/test_i32_mul_precise.c new file mode 100644 index 000000000..35ee6d080 --- /dev/null +++ b/emtests/test_i32_mul_precise.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main(int argc, char **argv) { + unsigned long d1 = 0x847c9b5d; + unsigned long q = 0x549530e1; + if (argc > 1000) { + q += argc; + d1 -= argc; + } // confuse optimizer + printf("%lu\n", d1 * q); + return 0; +} diff --git a/emtests/test_i32_mul_precise.out b/emtests/test_i32_mul_precise.out new file mode 100644 index 000000000..d46a50554 --- /dev/null +++ b/emtests/test_i32_mul_precise.out @@ -0,0 +1 @@ +3217489085 \ No newline at end of file diff --git a/emtests/test_i32_mul_precise.wasm b/emtests/test_i32_mul_precise.wasm new file mode 100644 index 000000000..bb6b62593 Binary files /dev/null and b/emtests/test_i32_mul_precise.wasm differ diff --git a/emtests/test_i64.c b/emtests/test_i64.c new file mode 100644 index 000000000..e44254a87 --- /dev/null +++ b/emtests/test_i64.c @@ -0,0 +1,36 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() +{ + long long a = 0x2b00505c10; + long long b = a >> 29; + long long c = a >> 32; + long long d = a >> 34; + printf("*%lld,%lld,%lld,%lld*\n", a, b, c, d); + unsigned long long ua = 0x2b00505c10; + unsigned long long ub = ua >> 29; + unsigned long long uc = ua >> 32; + unsigned long long ud = ua >> 34; + printf("*%lld,%lld,%lld,%lld*\n", ua, ub, uc, ud); + + long long x = 0x0000def123450789ULL; // any bigger than this, and we + long long y = 0x00020ef123456089ULL; // start to run into the double precision limit! + printf("*%lld,%lld,%lld,%lld,%lld*\n", x, y, x | y, x & y, x ^ y); + + printf("*"); + long long z = 13; + int n = 0; + while (z > 1) { + printf("%.2f,", (float)z); // these must be integers! + z = z >> 1; + n++; + } + printf("*%d*\n", n); + return 0; +} diff --git a/emtests/test_i64.out b/emtests/test_i64.out new file mode 100644 index 000000000..1f5d4f860 --- /dev/null +++ b/emtests/test_i64.out @@ -0,0 +1,4 @@ +*184688860176,344,43,10* +*184688860176,344,43,10* +*245127260211081,579378795077769,808077213656969,16428841631881,791648372025088* +*13.00,6.00,3.00,*3* diff --git a/emtests/test_i64.wasm b/emtests/test_i64.wasm new file mode 100644 index 000000000..e3b45cc8b Binary files /dev/null and b/emtests/test_i64.wasm differ diff --git a/emtests/test_i64_2.c b/emtests/test_i64_2.c new file mode 100644 index 000000000..888955574 --- /dev/null +++ b/emtests/test_i64_2.c @@ -0,0 +1,121 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int64_t returner1() { return 0x0000def123450789ULL; } +int64_t returner2(int test) { + while (test > 10) test /= 2; // confuse the compiler so it doesn't eliminate this function + return test > 5 ? 0x0000def123450123ULL : 0ULL; +} + +void modifier1(int64_t t) { + t |= 12; + printf("m1: %lld\n", t); +} +void modifier2(int64_t &t) { + t |= 12; +} + +int truthy() { + int x = time(0); + while (x > 10) { + x |= 7; + x /= 2; + } + return x < 3; +} + +struct IUB { + int c; + long long d; +}; + +IUB iub[] = { + { 55, 17179869201 }, + { 122, 25769803837 }, +}; + +int main(int argc, char **argv) +{ + int64_t x1 = 0x1234def123450789ULL; + int64_t x2 = 0x1234def123450788ULL; + int64_t x3 = 0x1234def123450789ULL; + printf("*%lld\n%d,%d,%d,%d,%d\n%d,%d,%d,%d,%d*\n", x1, x1==x2, x1x2, x1>=x2, // note: some rounding in the printing! + x1==x3, x1x3, x1>=x3); + printf("*%lld*\n", returner1()); + printf("*%lld*\n", returner2(30)); + + uint64_t maxx = -1ULL; + printf("*%llu*\n*%llu*\n", maxx, maxx >> 5); + + // Make sure params are not modified if they shouldn't be + int64_t t = 123; + modifier1(t); + printf("*%lld*\n", t); + modifier2(t); + printf("*%lld*\n", t); + + // global structs with i64s + printf("*%d,%lld*\n*%d,%lld*\n", iub[0].c, iub[0].d, iub[1].c, iub[1].d); + + // Bitshifts + { + int64_t a = -1; + int64_t b = a >> 29; + int64_t c = a >> 32; + int64_t d = a >> 34; + printf("*%lld,%lld,%lld,%lld*\n", a, b, c, d); + uint64_t ua = -1; + int64_t ub = ua >> 29; + int64_t uc = ua >> 32; + int64_t ud = ua >> 34; + printf("*%lld,%lld,%lld,%lld*\n", ua, ub, uc, ud); + } + + // Nonconstant bitshifts + { + int64_t a = -1; + int64_t b = a >> (29 - argc + 1); + int64_t c = a >> (32 - argc + 1); + int64_t d = a >> (34 - argc + 1); + printf("*%lld,%lld,%lld,%lld*\n", a, b, c, d); + uint64_t ua = -1; + int64_t ub = ua >> (29 - argc + 1); + int64_t uc = ua >> (32 - argc + 1); + int64_t ud = ua >> (34 - argc + 1); + printf("*%lld,%lld,%lld,%lld*\n", ua, ub, uc, ud); + } + + // Math mixtures with doubles + { + uint64_t a = 5; + double b = 6.8; + uint64_t c = a * b; + if (truthy()) printf("*%d,%d,%d*\n", (int)&a, (int)&b, (int)&c); // printing addresses prevents optimizations + printf("*prod:%llu*\n", c); + } + + // Basic (rounded, for now) math. Just check compilation. + int64_t a = 0x1234def123450789ULL; + a--; if (truthy()) a--; // confuse optimizer + int64_t b = 0x1234000000450789ULL; + b++; if (truthy()) b--; // confuse optimizer + printf("*%lld,%lld,%lld,%lld*\n", (a+b)/5000, (a-b)/5000, (a*3)/5000, (a/5)/5000); + + a -= 17; if (truthy()) a += 5; // confuse optimizer + b -= 17; if (truthy()) b += 121; // confuse optimizer + printf("*%llx,%llx,%llx,%llx*\n", b - a, b - a/2, b/2 - a, b - 20); + + if (truthy()) a += 5/b; // confuse optimizer + if (truthy()) b += 121*(3+a/b); // confuse optimizer + printf("*%llx,%llx,%llx,%llx*\n", a - b, a - b/2, a/2 - b, a - 20); + + return 0; +} diff --git a/emtests/test_i64_2.out b/emtests/test_i64_2.out new file mode 100644 index 000000000..154bfa578 --- /dev/null +++ b/emtests/test_i64_2.out @@ -0,0 +1,20 @@ +*1311918518731868041 +0,0,0,1,1 +1,0,1,0,1* +*245127260211081* +*245127260209443* +*18446744073709551615* +*576460752303423487* +m1: 127 +*123* +*127* +*55,17179869201* +*122,25769803837* +*-1,-1,-1,-1* +*-1,34359738367,4294967295,1073741823* +*-1,-1,-1,-1* +*-1,34359738367,4294967295,1073741823* +*prod:34* +*524718382041609,49025451137,787151111239120,52476740749274* +*ffff210edd000002,91990876ea283be,f6e5210edcdd7c45,1234000000450765* +*def122fffffe,91adef1232283bb,f6e66f78915d7c42,1234def123450763* diff --git a/emtests/test_i64_3.c b/emtests/test_i64_3.c new file mode 100644 index 000000000..3b4ef6615 --- /dev/null +++ b/emtests/test_i64_3.c @@ -0,0 +1,31 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() +{ + long long i,j,k; + + i = 0; + j = -1, + k = 1; + + printf( "*\n" ); + printf( "%s\n", i > j ? "Ok": "Fail" ); + printf( "%s\n", k > i ? "Ok": "Fail" ); + printf( "%s\n", k > j ? "Ok": "Fail" ); + printf( "%s\n", i < j ? "Fail": "Ok" ); + printf( "%s\n", k < i ? "Fail": "Ok" ); + printf( "%s\n", k < j ? "Fail": "Ok" ); + printf( "%s\n", (i-j) >= k ? "Ok": "Fail" ); + printf( "%s\n", (i-j) <= k ? "Ok": "Fail" ); + printf( "%s\n", i > std::numeric_limits::min() ? "Ok": "Fail" ); + printf( "%s\n", i < std::numeric_limits::max() ? "Ok": "Fail" ); + printf( "*\n" ); +} diff --git a/emtests/test_i64_3.out b/emtests/test_i64_3.out new file mode 100644 index 000000000..c5941b24c --- /dev/null +++ b/emtests/test_i64_3.out @@ -0,0 +1,12 @@ +* +Ok +Ok +Ok +Ok +Ok +Ok +Ok +Ok +Ok +Ok +* diff --git a/emtests/test_i64_4.c b/emtests/test_i64_4.c new file mode 100644 index 000000000..1da2fd163 --- /dev/null +++ b/emtests/test_i64_4.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() +{ + // i32 vs i64 + int32_t small = -1; + int64_t large = -1; + printf("*%d*\n", small == large); + small++; + printf("*%d*\n", small == large); + uint32_t usmall = -1; + uint64_t ularge = -1; + printf("*%d*\n", usmall == ularge); + return 0; +} diff --git a/emtests/test_i64_4.out b/emtests/test_i64_4.out new file mode 100644 index 000000000..709089bf6 --- /dev/null +++ b/emtests/test_i64_4.out @@ -0,0 +1,3 @@ +*1* +*0* +*0* diff --git a/emtests/test_i64_4.wasm b/emtests/test_i64_4.wasm new file mode 100644 index 000000000..084a00192 Binary files /dev/null and b/emtests/test_i64_4.wasm differ diff --git a/emtests/test_i64_7z.c b/emtests/test_i64_7z.c new file mode 100644 index 000000000..b4568e603 --- /dev/null +++ b/emtests/test_i64_7z.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +uint64_t a, b; +int main(int argc, char *argv[]) { + a = argc; + b = argv[1][0]; + printf("%d,%d\n", (int)a, (int)b); + if (a > a + b || a > a + b + 1) { + printf("one %lld, %lld", a, b); + return 0; + } + printf("zero %lld, %lld", a, b); + return 0; +} diff --git a/emtests/test_i64_7z.out b/emtests/test_i64_7z.out new file mode 100644 index 000000000..3e9d35a4e --- /dev/null +++ b/emtests/test_i64_7z.out @@ -0,0 +1 @@ +zero 2, 104 \ No newline at end of file diff --git a/emtests/test_i64_7z.wasm b/emtests/test_i64_7z.wasm new file mode 100644 index 000000000..7d5ed21fc Binary files /dev/null and b/emtests/test_i64_7z.wasm differ diff --git a/emtests/test_i64_b.c b/emtests/test_i64_b.c new file mode 100644 index 000000000..d64cc780e --- /dev/null +++ b/emtests/test_i64_b.c @@ -0,0 +1,27 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +typedef long long int64; + +#define PRMJ_USEC_PER_SEC 1000000L + +int main(int argc, char* argv[]) { + int64 sec = 1329409675 + argc; + int64 usec = 2329509675ll; + int64 mul = int64(sec) * PRMJ_USEC_PER_SEC; + int64 add = mul + int64(usec); + int add_low = add; + int add_high = add >> 32; + printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high); + int64 x = sec + (usec << 25); + x >>= argc * 3; + printf("*%llu*\n", x); + return 0; +} diff --git a/emtests/test_i64_b.out b/emtests/test_i64_b.out new file mode 100644 index 000000000..70d0a95cb --- /dev/null +++ b/emtests/test_i64_b.out @@ -0,0 +1,2 @@ +*1329409676000000,1329412005509675,3663280683,309527* +*9770671914067409* diff --git a/emtests/test_i64_cmp.c b/emtests/test_i64_cmp.c new file mode 100644 index 000000000..efa984c39 --- /dev/null +++ b/emtests/test_i64_cmp.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef long long int64; + +bool compare(int64 val) { return val == -12; } + +bool compare2(int64 val) { return val < -12; } + +int main(int argc, char* argv[]) { + printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc - 1 - 12), + compare(1000 + argc), compare2(argc - 1 - 10), compare2(argc - 1 - 14), + compare2(argc + 1000)); + return 0; +} diff --git a/emtests/test_i64_cmp.out b/emtests/test_i64_cmp.out new file mode 100644 index 000000000..6474e7f59 --- /dev/null +++ b/emtests/test_i64_cmp.out @@ -0,0 +1 @@ +*1,1,0,0,1,0* diff --git a/emtests/test_i64_cmp2.c b/emtests/test_i64_cmp2.c new file mode 100644 index 000000000..7a05ddc9b --- /dev/null +++ b/emtests/test_i64_cmp2.c @@ -0,0 +1,35 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +typedef int32_t INT32; +typedef int64_t INT64; +typedef uint8_t UINT8; + +void interface_clock_changed() { + UINT8 m_divshift; + INT32 m_divisor; + + // INT64 attos = m_attoseconds_per_cycle; + INT64 attos = 279365114840; + m_divshift = 0; + while (attos >= (1UL << 31)) { + m_divshift++; + printf("m_divshift is %i, on %lld >?= %lu\n", m_divshift, attos, 1UL << 31); + attos >>= 1; + } + m_divisor = attos; + + printf("m_divisor is %i\n", m_divisor); +} + +int main() { + interface_clock_changed(); + return 0; +} diff --git a/emtests/test_i64_cmp2.out b/emtests/test_i64_cmp2.out new file mode 100644 index 000000000..893bb8267 --- /dev/null +++ b/emtests/test_i64_cmp2.out @@ -0,0 +1,9 @@ +m_divshift is 1, on 279365114840 >?= 2147483648 +m_divshift is 2, on 139682557420 >?= 2147483648 +m_divshift is 3, on 69841278710 >?= 2147483648 +m_divshift is 4, on 34920639355 >?= 2147483648 +m_divshift is 5, on 17460319677 >?= 2147483648 +m_divshift is 6, on 8730159838 >?= 2147483648 +m_divshift is 7, on 4365079919 >?= 2147483648 +m_divshift is 8, on 2182539959 >?= 2147483648 +m_divisor is 1091269979 diff --git a/emtests/test_i64_cmp2.wasm b/emtests/test_i64_cmp2.wasm new file mode 100644 index 000000000..e2a1edbd3 Binary files /dev/null and b/emtests/test_i64_cmp2.wasm differ diff --git a/emtests/test_i64_double.c b/emtests/test_i64_double.c new file mode 100644 index 000000000..e0841ec57 --- /dev/null +++ b/emtests/test_i64_double.c @@ -0,0 +1,41 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef long long int64; +#define JSDOUBLE_HI32_SIGNBIT 0x80000000 + +bool JSDOUBLE_IS_NEGZERO(double d) { + union { + struct { + unsigned int lo, hi; + } s; + double d; + } x; + if (d != 0) return false; + x.d = d; + return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0; +} + +bool JSINT64_IS_NEGZERO(int64 l) { + union { + int64 i; + double d; + } x; + if (l != 0) return false; + x.i = l; + return x.d == -0; +} + +int main(int argc, char* argv[]) { + printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), + JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1)); + printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), + JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1)); + return 0; +} diff --git a/emtests/test_i64_double.out b/emtests/test_i64_double.out new file mode 100644 index 000000000..cfb987037 --- /dev/null +++ b/emtests/test_i64_double.out @@ -0,0 +1,2 @@ +*0,0,0,0* +*1,1,0,0* diff --git a/emtests/test_i64_i16.c b/emtests/test_i64_i16.c new file mode 100644 index 000000000..bcb20ae0c --- /dev/null +++ b/emtests/test_i64_i16.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main(int argc, char** argv) { + int y = -133; + int64_t x = ((int64_t)((short)(y))) * (100 + argc); + if (x > 0) + printf(">0\n"); + else + printf("<=0\n"); +} diff --git a/emtests/test_i64_i16.out b/emtests/test_i64_i16.out new file mode 100644 index 000000000..01adb4295 --- /dev/null +++ b/emtests/test_i64_i16.out @@ -0,0 +1 @@ +<=0 \ No newline at end of file diff --git a/emtests/test_i64_i16.wasm b/emtests/test_i64_i16.wasm new file mode 100644 index 000000000..20a3a08b1 Binary files /dev/null and b/emtests/test_i64_i16.wasm differ diff --git a/emtests/test_i64_llabs.c b/emtests/test_i64_llabs.c new file mode 100644 index 000000000..df6230067 --- /dev/null +++ b/emtests/test_i64_llabs.c @@ -0,0 +1,14 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char** argv) { + printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489)); + return 0; +} diff --git a/emtests/test_i64_llabs.out b/emtests/test_i64_llabs.out new file mode 100644 index 000000000..e1ec50623 --- /dev/null +++ b/emtests/test_i64_llabs.out @@ -0,0 +1 @@ +576460752303423489,576460752303423489 \ No newline at end of file diff --git a/emtests/test_i64_llabs.wasm b/emtests/test_i64_llabs.wasm new file mode 100644 index 000000000..54a545c5e Binary files /dev/null and b/emtests/test_i64_llabs.wasm differ diff --git a/emtests/test_i64_precise.c b/emtests/test_i64_precise.c new file mode 100644 index 000000000..4e58eb06f --- /dev/null +++ b/emtests/test_i64_precise.c @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + uint64_t x = 0, y = 0; + for (int i = 0; i < 64; i++) { + x += 1ULL << i; + y += x; + x /= 3; + y *= 5; + printf("unsigned %d: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n", i, x, y, x+y, x-y, x*y, y ? x/y : 0, x ? y/x : 0, y ? x%y : 0, x ? y%x : 0); + } + int64_t x2 = 0, y2 = 0; + for (int i = 0; i < 64; i++) { + x2 += 1LL << i; + y2 += x2; + x2 /= 3 * (i % 7 ? -1 : 1); + y2 *= 5 * (i % 2 ? -1 : 1); + printf("signed %d: %lld,%lld,%lld,%lld,%lld,%lld,%lld,%lld,%lld\n", i, x2, y2, x2+y2, x2-y2, x2*y2, y2 ? x2/y2 : 0, x2 ? y2/x2 : 0, y2 ? x2%y2 : 0, x2 ? y2%x2 : 0); + } + return 0; +} diff --git a/emtests/test_i64_precise.out b/emtests/test_i64_precise.out new file mode 100644 index 000000000..69f1f3067 --- /dev/null +++ b/emtests/test_i64_precise.out @@ -0,0 +1,128 @@ +unsigned 0: 0,5,5,18446744073709551611,0,0,0,0,0 +unsigned 1: 0,35,35,18446744073709551581,0,0,0,0,0 +unsigned 2: 1,195,196,18446744073709551422,195,0,195,1,0 +unsigned 3: 3,1020,1023,18446744073709550599,3060,0,340,3,0 +unsigned 4: 6,5195,5201,18446744073709546427,31170,0,865,6,5 +unsigned 5: 12,26165,26177,18446744073709525463,313980,0,2180,12,5 +unsigned 6: 25,131205,131230,18446744073709420436,3280125,0,5248,25,5 +unsigned 7: 51,656790,656841,18446744073708894877,33496290,0,12878,51,12 +unsigned 8: 102,3285485,3285587,18446744073706266233,335119470,0,32210,102,65 +unsigned 9: 204,16430495,16430699,18446744073693121325,3351820980,0,80541,204,131 +unsigned 10: 409,82158615,82159024,18446744073627393410,33602873535,0,200876,409,331 +unsigned 11: 819,410805360,410806179,18446744073298747075,336449589840,0,501593,819,693 +unsigned 12: 1638,2054051375,2054053013,18446744071655501879,3364536152250,0,1253999,1638,1013 +unsigned 13: 3276,10270306025,10270309301,18446744063439248867,33645522537900,0,3135014,3276,161 +unsigned 14: 6553,51351628425,51351634978,18446744022357929744,336507221069025,0,7836354,6553,663 +unsigned 15: 13107,256758338730,256758351837,18446743816951225993,3365331545734110,0,19589405,13107,7395 +unsigned 16: 26214,1283792086865,1283792113079,18446742789917490965,33653325765079110,0,48973528,26214,23873 +unsigned 17: 52428,6418961220755,6418961273183,18446737654748383289,336533298881743140,0,122433837,52428,14519 +unsigned 18: 104857,32094807676635,32094807781492,18446711978901979838,3365365248548916195,0,306081689,104857,13162 +unsigned 19: 209715,160474041528900,160474041738615,18446583599668232431,15207069545523711884,0,765200589,209715,6765 +unsigned 20: 419430,802370213935955,802370214355385,18445941703496035091,4496745504385676562,0,1913001487,419430,243545 +unsigned 21: 838860,4011851082262685,4011851083101545,18442732222628127791,8073977451737544988,0,4782503733,838860,798305 +unsigned 22: 1677721,20059255436479245,20059255438156966,18426684818274750092,6972899699173253061,0,11956252223,1677721,655462 +unsigned 23: 3355443,100296277232727870,100296277236083313,18346447796480179189,14489229932752165722,0,29890621665,3355443,1255275 +unsigned 24: 6710886,501481386264302645,501481386271013531,17945262687451959857,15765766351451925278,0,74726554178,6710886,2920937 +unsigned 25: 13421772,2507406931522839815,2507406931536261587,15939337142200133573,10086413084431357332,0,186816385461,13421772,1182923 +unsigned 26: 26843545,12537034658016852255,12537034658043695800,5909709415719542906,2731509698427185799,0,467040946269,26843545,2368650 +unsigned 27: 53687091,7344941069760912792,7344941069814599883,11101803004002325915,16256528535618547016,0,136810189059,53687091,23175423 +unsigned 28: 107374182,18277961276705625079,18277961276812999261,168782797111300719,15164270991448465002,0,170226780183,107374182,62189773 +unsigned 29: 214748364,17602830091911144401,17602830092125892765,843913982013155579,4760510224565868172,0,81969565513,214748364,203573669 +unsigned 30: 429496729,14227174171159966481,14227174171589463210,4219569902979081864,9259055794720517673,0,33125221242,429496729,319649063 +unsigned 31: 858993459,15795638647556079442,15795638648415072901,2651105427012465633,8773778578690814806,0,18388543570,858993459,389570812 +unsigned 32: 1717986918,5191216968711994521,5191216970429981439,13255527106715544013,2882763035818302198,0,3021685971,1717986918,229867143 +unsigned 33: 3435973836,7509340821390028539,7509340824826002375,10937403255755496913,3002188606886016004,0,2185505821,3435973836,2008329183 +unsigned 34: 6871947673,653216062610254563,653216069482202236,17793528017971244726,1160311421120597163,0,95055447,6871947673,4792629732 +unsigned 35: 13743895347,3266080519209703020,3266080532953598367,15180663568243743943,7490496812310051716,0,237638634,13743895347,3109667022 +unsigned 36: 27487790694,16330403008365375515,16330403035853166209,2116341092831966795,8496689265331596482,0,594096600,27487790694,15548335115 +unsigned 37: 54975581388,7865039571622391941,7865039626597973329,10581704557062741063,3801217959335798268,0,143064236,54975581388,21692352373 +unsigned 38: 109951162777,2431711359960298133,2431711469911460910,16015032823700416260,10929097356750440461,0,22116285,109951162777,107902774688 +unsigned 39: 219902325555,12158560098336373990,12158560318238699545,6288184195275503181,3390366976150811602,0,55290729,219902325555,209605094395 +unsigned 40: 439804651110,5452574867622981757,5452575307427632867,12994169645891220969,4388876164940275662,0,12397719,439804651110,388268163667 +unsigned 41: 879609302220,8816143458544890479,8816144338154192699,9630601494773963357,18063307631679153268,0,10022794,879609302220,621910087799 +unsigned 42: 1759218604441,7187255533584415783,7187257292803020224,11259490299343740274,10731539484643328591,0,4085481,1759218604441,1350294194662 +unsigned 43: 3518437208883,17489586370770660544,17489589889207869427,957161221376099955,6745745258281429568,0,4970839,3518437208883,1473803897707 +unsigned 44: 7036874417766,13661061112131362751,13661068149005780517,4785689998452606631,1049124659338985498,0,1941353,7036874417766,3850578085353 +unsigned 45: 14073748835532,12965284445760691897,12965298519509527429,5481473701697695251,3112351931422336876,0,921238,14073748835532,12216012863281 +unsigned 46: 28147497671065,9486612220139870617,9486640367637541682,8960160001067352064,11094552886493166961,0,337032,28147497671065,4785065491537 +unsigned 47: 56294995342131,10540417378210381818,10540473673205723949,7906382990494511929,3425601976498736334,0,187235,56294995342131,23925326484033 +unsigned 48: 112589990684262,15810287593493069793,15810400183483754055,2636569070207166085,4740441117117290918,0,140423,112589990684262,63331636946967 +unsigned 49: 225179981368524,5267839372347670371,5268064552329038895,13179129881343249769,3129072874530825956,0,23393,225179981368524,204068193788439 +unsigned 50: 450359962737049,7899208187469855979,7899658547432593028,10547986246202432686,9662536335886195571,0,17539,450359962737049,344801024753568 +unsigned 51: 900719925474099,2616063588812288148,2616964308737762247,15831581204822737567,18056837904917260668,0,2904,900719925474099,372925235504652 +unsigned 52: 1801439850948198,13107339541825663715,13109140981676611913,5341205971734836099,3467025862604273778,0,7276,1801439850948198,63186326575067 +unsigned 53: 3602879701896396,10250508683528109677,10254111563230006073,8199838269883338335,8794376607022815964,0,2845,3602879701896396,315931632863057 +unsigned 54: 7205759403792793,14467141661278337053,14474347420682129846,3986808171835007356,17354123729136361045,0,2007,7205759403792793,5182537866201502 +unsigned 55: 14411518807585587,17211648867376814222,17226060386184399809,1249506725140322981,17050849970911342154,0,1194,14411518807585587,4295411119623344 +unsigned 56: 28823037615171174,12703613606273432261,12732436643888603435,5771953505051290529,11664739411905079422,0,440,28823037615171174,21477055598115701 +unsigned 57: 57646075230342348,9042526938693641687,9100173013923984035,9461863210246252277,16227931067794422612,0,156,57646075230342348,49739202760235399 +unsigned 58: 115292150460684697,10048528802959375663,10163820953420060360,8513507421210860650,10457660234102286359,0,87,115292150460684697,18111712879807024 +unsigned 59: 230584300921369395,16807920381198316008,17038504682119685403,1869407993432605003,16929834404840843576,0,72,230584300921369395,205850714859719568 +unsigned 60: 461168601842738790,17170154638794455431,17631323240637194221,1737758036757834975,7428164801607120330,0,37,461168601842738790,106916370613120201 +unsigned 61: 922337203685477580,7452110880706682785,8374448084392160365,11916970396688346411,17096741387571593292,0,8,922337203685477580,73413251222862145 +unsigned 62: 1844674407370955161,9590438292969086497,11435112700340041658,10700980188111420280,7158457875815234233,0,5,1844674407370955161,367066256114310692 +unsigned 63: 3689348814741910323,11058703317426329250,14748052132168239573,11077389571025132689,16235003410224285766,0,2,3689348814741910323,3680005687942508604 +signed 0: 0,5,5,-5,0,0,0,0,0 +signed 1: 0,-35,-35,35,0,0,0,0,0 +signed 2: -1,-155,-156,154,155,0,155,-1,0 +signed 3: -2,740,738,-742,-1480,0,-370,-2,0 +signed 4: -4,3770,3766,-3774,-15080,0,-942,-4,2 +signed 5: -9,-18990,-18999,18981,170910,0,2110,-9,0 +signed 6: -18,-94675,-94693,94657,1704150,0,5259,-18,-13 +signed 7: 36,472825,472861,-472789,17021700,0,13134,36,1 +signed 8: -97,2365585,2365488,-2365682,-229461745,0,-24387,-97,46 +signed 9: -138,-11830000,-11830138,11829862,1632540000,0,85724,-138,-88 +signed 10: -295,-59145570,-59145865,59145275,17447943150,0,200493,-295,-135 +signed 11: -584,295719085,295718501,-295719669,-172699945640,0,-506368,-584,173 +signed 12: -1170,1478612985,1478611815,-1478614155,-1729977192450,0,-1263771,-1170,915 +signed 13: -2340,-7393100035,-7393102375,7393097695,17299854081900,0,3159444,-2340,-1075 +signed 14: 4681,-36965429955,-36965425274,36965434636,-173035177619355,0,-7896908,4681,-3607 +signed 15: -12483,184826962530,184826950047,-184826975013,-2307194973261990,0,-14806293,-12483,7011 +signed 16: -17684,924135077915,924135060231,-924135095599,-16342404717848860,0,-52258260,-17684,8075 +signed 17: -37796,-4620675956515,-4620675994311,4620675918719,174643068452440940,0,122253041,-37796,-18879 +signed 18: -74782,-23103378660835,-23103378735617,23103378586053,1727716863014562970,0,308943043,-74782,-19209 +signed 19: -149835,115516891056645,115516890906810,-115516891206480,1138270702237148041,0,-770960663,-149835,116040 +signed 20: -299580,577584459776930,577584459477350,-577584460076510,-7012055796586724856,0,-1927980705,-299580,173030 +signed 21: 599190,-2887922307872510,-2887922307273320,2887922308471700,3579775274568585004,0,-4819710455,599190,-341060 +signed 22: -1597831,-14439611515395080,-14439611516992911,14439611513797249,-4817928955413000136,0,9037007991,-1597831,-127559 +signed 23: -2263592,72198057543021515,72198057540757923,-72198057545285107,-7239720930239415736,0,-31895349313,-2263592,909219 +signed 24: -4837874,360990287787675695,360990287782837821,-360990287792513569,1520893864324420754,0,-74617546423,-4837874,4050993 +signed 25: -9572186,-1804951439081961265,-1804951439091533451,1804951439072389079,-284040605827480006,0,188562094288,-9572186,-7687697 +signed 26: -19178892,-9024757195122122935,-9024757195141301827,9024757195102944043,3158545232664844052,0,470556755579,-19178892,-2084467 +signed 27: -38346278,8230297827616317263,8230297827577970985,-8230297827654663541,-2447170876606408634,0,-214630943519,-38346278,34444981 +signed 28: 76696392,4258000991812928973,4258000991889625365,-4258000991736232581,-4010249384068861784,0,55517617984,76696392,5815245 +signed 29: -204522434,-2843260888422929769,-2843260888627452203,2843260888218407335,-3330061828535700334,0,13901951159,-204522434,-35128763 +signed 30: -289739796,4230439635940999721,4230439635651259925,-4230439636230739517,-8819265314490703668,0,-14600823547,-289739796,1223309 +signed 31: -619247950,-2705454115284166249,-2705454115903414199,2705454114664918299,4237355741738226942,0,4368935117,-619247950,-398906099 +signed 32: -1225239782,4919473515667317101,4919473514442077319,-4919473516892556883,8469738706080185362,0,-4015110828,-1225239782,62757605 +signed 33: -2454898270,-6150623541450507939,-6150623543905406209,6150623538995609669,-6720592984569904678,0,2505449458,-2454898270,-1433870279 +signed 34: -4908323638,6140370513791418107,6140370508883094469,-6140370518699741745,-2321546656369961458,0,-1251011743,-4908323638,4208937073 +signed 35: 9817138243,6191635431204939047,6191635441022077290,-6191635421387800804,1329921992230270261,0,630696571,9817138243,4311874294 +signed 36: -26178871659,-5935310598711333102,-5935310624890204761,5935310572532461443,-1523401759741279878,0,226721406,-26178871659,-8689300548 +signed 37: -37086693937,-7216935710162846787,-7216935747249540724,7216935673076152850,4375670093386346195,0,194596361,-37086693937,-28501883530 +signed 38: -79263737669,808810785560934332,808810706297196663,-808810864824672001,1308775974572414548,0,-10204045,-79263737669,39518263227 +signed 39: -156830692073,-4044056280265052755,-4044056437095744828,4044056123434360682,3200853909245289355,0,25786127,-156830692073,-136972781484 +signed 40: -314226978567,-1773532614211033644,-1773532928438012211,1773532299984055077,149458714710412084,0,5644113,-314226978567,-39530307573 +signed 41: -628265425661,8867653647073783295,8867653018808357634,-8867654275339208956,1335113139221865725,0,-14114502,-628265425661,40050747473 +signed 42: 1256593695147,7444798936855240458,7444800193448935605,-7444797680261545311,194995390784062894,0,5924587,1256593695147,266305361169 +signed 43: -3350895572451,-330556800290685833,-330560151186258284,330553449395113382,-3084978225808244869,0,98647,-3350895572451,-1004755112036 +signed 44: -4747096823988,-1652712795001069340,-1652717542097893328,1652708047904245352,888305014260137904,0,348152,-4747096823988,-1541535999164 +signed 45: -10145758421614,8263411788629022480,8263401642870600866,-8263421934387444094,1433933448381331232,0,-814469,-10145758421614,6072735489514 +signed 46: -20074328585350,4423871910654789418,4423851836326204068,-4423891984983374768,1087756533121529860,0,-220374,-20074328585350,11822986868518 +signed 47: -40221053256659,-3673218795363245364,-3673259016416502023,3673178574309988705,-3788250272949359140,0,91325,-40221053256659,-31106698862189 +signed 48: -80417974484665,81856366510594781,81775948536110116,-81936784485079446,3556652555309224011,0,-1017,-80417974484665,71286459690476 +signed 49: 160843992978882,-411694492447657140,-411533648454678258,411855336440636022,8646015829301599128,0,-2559,160843992978882,-94714414698102 +signed 50: -428914633273835,-2052038742739178170,-2052467657372452005,2051609828105904335,4194688249318378174,0,4784,-428914633273835,-111137157151530 +signed 51: -607628393470471,-8195664785915717831,-8196272414309188302,8195057157522247360,245300141642486641,0,13487,-607628393470471,-580643179475454 +signed 52: -1298657077966675,-4065355925989985798,-4066654583067952473,4064057268912019123,1136007313742779890,0,3130,-1298657077966675,-559271954293048 +signed 53: -2569514058924772,1841492845356505789,1838923331297581017,-1844062359415430561,6068344375485822380,0,-716,-2569514058924772,1720779166369037 +signed 54: -5148294816852404,-9162055424674236611,-9167203719491089015,9156907129857384207,-6087205165210098660,0,1779,-5148294816852404,-3238945493809895 +signed 55: -10293500734037188,8762386464941522003,8752092964207484815,-8772679965675559191,8399093139116719220,0,-851,-10293500734037188,2617340275875015 +signed 56: 20588031101296916,7227264643807960523,7247852674909257439,-7206676612706663607,-3352533841896882468,0,351,20588031101296916,865727252743007 +signed 57: -54901073059050929,-66351167506463323,-121252240565514252,11450094447412394,1896642381847523307,0,1,-54901073059050929,-11450094447412394 +signed 58: -77776434364220271,834890677930987460,757114243566767189,-912667112295207731,-3500275542106939900,0,-10,-77776434364220271,57126334288784750 +signed 59: -166228105979734405,-6667874979350953385,-6834103085330687790,6501646873371218980,-4513011972483376691,0,40,-166228105979734405,-18750740161577185 +signed 60: -328897799542370857,8487580243799899162,8158682444257528305,-8816478043342270019,-905439778191045674,0,-25,-328897799542370857,265135255240627737 +signed 61: -658981736557107698,3017604953772543563,2358623217215435865,-3676586690329651261,-378165734266082790,0,-4,-658981736557107698,381678007544112771 +signed 62: -1317568093956760068,-2041941969204984387,-3359510063161744455,724373875248224319,-7186442770938425588,0,1,-1317568093956760068,-724373875248224319 +signed 63: 2635267980966005246,7574178278953946467,-8237297813789599903,-4938910297987941221,1110862422097806138,0,2,2635267980966005246,2303642317021935975 diff --git a/emtests/test_i64_precise.wasm b/emtests/test_i64_precise.wasm new file mode 100644 index 000000000..4a8ada32e Binary files /dev/null and b/emtests/test_i64_precise.wasm differ diff --git a/emtests/test_i64_precise_needed.c b/emtests/test_i64_precise_needed.c new file mode 100644 index 000000000..1fca4c8d9 --- /dev/null +++ b/emtests/test_i64_precise_needed.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main( int argc, char ** argv ) +{ + unsigned long a = 0x60DD1695U; + unsigned long b = 0xCA8C4E7BU; + unsigned long long c = (unsigned long long)a * b; + printf( "c = %016llx\n", c ); + + return 0; +} diff --git a/emtests/test_i64_precise_needed.out b/emtests/test_i64_precise_needed.out new file mode 100644 index 000000000..7f8562f97 --- /dev/null +++ b/emtests/test_i64_precise_needed.out @@ -0,0 +1 @@ +c = 4ca38a6bd2973f97 diff --git a/emtests/test_i64_precise_needed.wasm b/emtests/test_i64_precise_needed.wasm new file mode 100644 index 000000000..064653b4d Binary files /dev/null and b/emtests/test_i64_precise_needed.wasm differ diff --git a/emtests/test_i64_precise_unneeded.c b/emtests/test_i64_precise_unneeded.c new file mode 100644 index 000000000..15ddd5f65 --- /dev/null +++ b/emtests/test_i64_precise_unneeded.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char **argv) { + uint64_t x = 2125299906845564, y = 1225891506842664; + if (argc == 12) { + x = x >> 1; + y = y >> 1; + } + x = x & 12ULL; + y = y | 12ULL; + x = x ^ y; + x <<= 2; + y >>= 3; + printf("*%llu, %llu*\n", x, y); +} diff --git a/emtests/test_i64_precise_unneeded.out b/emtests/test_i64_precise_unneeded.out new file mode 100644 index 000000000..c5684f68e --- /dev/null +++ b/emtests/test_i64_precise_unneeded.out @@ -0,0 +1 @@ +*4903566027370624, 153236438355333* diff --git a/emtests/test_i64_precise_unneeded.wasm b/emtests/test_i64_precise_unneeded.wasm new file mode 100644 index 000000000..063636eec Binary files /dev/null and b/emtests/test_i64_precise_unneeded.wasm differ diff --git a/emtests/test_i64_qdouble.c b/emtests/test_i64_qdouble.c new file mode 100644 index 000000000..04b4e578e --- /dev/null +++ b/emtests/test_i64_qdouble.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +typedef long long qint64; /* 64 bit signed */ +typedef double qreal; + +int main(int argc, char **argv) { + qreal c = 111; + qint64 d = -111 + (argc - 1); + c += d; + if (c < -1 || c > 1) { + printf("Failed!\n"); + } else { + printf("Succeeded!\n"); + } +}; diff --git a/emtests/test_i64_qdouble.out b/emtests/test_i64_qdouble.out new file mode 100644 index 000000000..0b9e5e9e1 --- /dev/null +++ b/emtests/test_i64_qdouble.out @@ -0,0 +1 @@ +Succeeded! \ No newline at end of file diff --git a/emtests/test_i64_qdouble.wasm b/emtests/test_i64_qdouble.wasm new file mode 100644 index 000000000..4c89e3030 Binary files /dev/null and b/emtests/test_i64_qdouble.wasm differ diff --git a/emtests/test_i64_umul.c b/emtests/test_i64_umul.c new file mode 100644 index 000000000..1ec58bdb4 --- /dev/null +++ b/emtests/test_i64_umul.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +typedef uint32_t UINT32; +typedef uint64_t UINT64; + +int main() { + volatile UINT32 testu32a = 2375724032U; + UINT32 bigu32 = 0xffffffffU; + volatile UINT64 testu64a = 14746250828952703000U; + + while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) { + printf("testu64a is %llu\n", testu64a); + testu64a /= 2; + } + + return 0; +} diff --git a/emtests/test_i64_umul.out b/emtests/test_i64_umul.out new file mode 100644 index 000000000..eb85c3abb --- /dev/null +++ b/emtests/test_i64_umul.out @@ -0,0 +1 @@ +testu64a is 14746250828952703000 diff --git a/emtests/test_i64_umul.wasm b/emtests/test_i64_umul.wasm new file mode 100644 index 000000000..4a44d15aa Binary files /dev/null and b/emtests/test_i64_umul.wasm differ diff --git a/emtests/test_i64_varargs.c b/emtests/test_i64_varargs.c new file mode 100644 index 000000000..042ff8b2b --- /dev/null +++ b/emtests/test_i64_varargs.c @@ -0,0 +1,37 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, + ...) { + if (sig_start < 10123) printf("%s\n", msg + len); + va_list v; + va_start(v, sig_start); + if (sig_start > 1413) + printf("%d\n", va_arg(v, int)); + else + printf("nada\n"); + va_end(v); + return len * sig_start * (msg[0] + 1); +} + +int main(int argc, char **argv) { + argv[0] = (char*)"..."; + for (int i = 0; i < argc; i++) { + int64_t x; + if (i % 123123 == 0) + x = ccv_cache_generate_signature(argv[i], i + 2, (int64_t)argc * argc, + 54.111); + else + x = ccv_cache_generate_signature(argv[i], i + 2, (int64_t)argc * argc, + 13); + printf("%lld\n", x); + } +}; diff --git a/emtests/test_i64_varargs.out b/emtests/test_i64_varargs.out new file mode 100644 index 000000000..01832abc5 --- /dev/null +++ b/emtests/test_i64_varargs.out @@ -0,0 +1,12 @@ +. +nada +1504 +a +nada +5760 +fl +nada +6592 +sdfasdfasdf +nada +7840 diff --git a/emtests/test_i64_varargs.wasm b/emtests/test_i64_varargs.wasm new file mode 100644 index 000000000..f5fa93ed4 Binary files /dev/null and b/emtests/test_i64_varargs.wasm differ diff --git a/emtests/test_i64_zextneg.c b/emtests/test_i64_zextneg.c new file mode 100644 index 000000000..7a86c443a --- /dev/null +++ b/emtests/test_i64_zextneg.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char *argv[]) { + uint8_t byte = 0x80; + uint16_t two = byte; + uint32_t four = byte; + uint64_t eight = byte; + + printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight); + + return 0; +} diff --git a/emtests/test_i64_zextneg.out b/emtests/test_i64_zextneg.out new file mode 100644 index 000000000..e2d9fd342 --- /dev/null +++ b/emtests/test_i64_zextneg.out @@ -0,0 +1 @@ +value: 128,128,128,128. \ No newline at end of file diff --git a/emtests/test_i64_zextneg.wasm b/emtests/test_i64_zextneg.wasm new file mode 100644 index 000000000..115dfbaff Binary files /dev/null and b/emtests/test_i64_zextneg.wasm differ diff --git a/emtests/test_if.c b/emtests/test_if.c new file mode 100644 index 000000000..79bd56931 --- /dev/null +++ b/emtests/test_if.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + int x = 5; + if (x > 3) { + printf("*yes*\n"); + } + return 0; +} diff --git a/emtests/test_if.out b/emtests/test_if.out new file mode 100644 index 000000000..f74b06396 --- /dev/null +++ b/emtests/test_if.out @@ -0,0 +1 @@ +*yes* \ No newline at end of file diff --git a/emtests/test_if.wasm b/emtests/test_if.wasm new file mode 100644 index 000000000..60d91fcd3 Binary files /dev/null and b/emtests/test_if.wasm differ diff --git a/emtests/test_if_else.c b/emtests/test_if_else.c new file mode 100644 index 000000000..543acf2bd --- /dev/null +++ b/emtests/test_if_else.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + int x = 5; + if (x > 10) { + printf("*yes*\n"); + } else { + printf("*no*\n"); + } + return 0; +} diff --git a/emtests/test_if_else.out b/emtests/test_if_else.out new file mode 100644 index 000000000..208ac5ecc --- /dev/null +++ b/emtests/test_if_else.out @@ -0,0 +1 @@ +*no* \ No newline at end of file diff --git a/emtests/test_if_else.wasm b/emtests/test_if_else.wasm new file mode 100644 index 000000000..f4de5d144 Binary files /dev/null and b/emtests/test_if_else.wasm differ diff --git a/emtests/test_indirectbr.c b/emtests/test_indirectbr.c new file mode 100644 index 000000000..521b878e1 --- /dev/null +++ b/emtests/test_indirectbr.c @@ -0,0 +1,27 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main(void) { + const void *addrs[2] = {&&FOO, &&BAR}; + + // confuse the optimizer so it doesn't hardcode the jump and avoid generating + // an |indirectbr| instruction + int which = 0; + for (int x = 0; x < 1000; x++) which = (which + x * x) % 7; + which = (which % 2) + 1; + + goto *addrs[which]; + +FOO: + printf("bad\n"); + return 0; +BAR: + printf("good\n"); + const void *addr = &&FOO; + goto *addr; +} diff --git a/emtests/test_indirectbr.out b/emtests/test_indirectbr.out new file mode 100644 index 000000000..5364b418c --- /dev/null +++ b/emtests/test_indirectbr.out @@ -0,0 +1,2 @@ +good +bad \ No newline at end of file diff --git a/emtests/test_indirectbr.wasm b/emtests/test_indirectbr.wasm new file mode 100644 index 000000000..ffd1236b7 Binary files /dev/null and b/emtests/test_indirectbr.wasm differ diff --git a/emtests/test_indirectbr_many.c b/emtests/test_indirectbr_many.c new file mode 100644 index 000000000..9ad3b4e4f --- /dev/null +++ b/emtests/test_indirectbr_many.c @@ -0,0 +1,51 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +/* Store, "declare" (but jump over) the current B_* label */ +#define IND_BLOCK(X) \ +do { \ + addrs[i] = &&B_##X; \ + i++; \ + goto JMP_##X; \ + B_##X: \ + printf(#X "\n"); \ + return 0; \ + JMP_##X: \ + ; \ +} while (0) + +/* Add an indirection block to enable token pasting */ +#define SINGLE(X) IND_BLOCK(X); + +#define P2 SINGLE(__COUNTER__) SINGLE(__COUNTER__) +#define P4 P2 P2 +#define P8 P4 P4 +#define P16 P8 P8 +#define P32 P16 P16 +#define P64 P32 P32 +#define P128 P64 P64 +#define P256 P128 P128 +#define P512 P256 P256 +#define P1024 P512 P512 + +int main(int argc, char *argv[]) +{ + const void *addrs[1024 + 512]; + int i = 0; + + /* + * Repeat as many times as you want, but remember to update + * the labels address array's size accordingly. + */ + P1024; + P512; + + /* jump back at the correct label */ + goto *addrs[(argc * argc) + 1000]; +} diff --git a/emtests/test_indirectbr_many.out b/emtests/test_indirectbr_many.out new file mode 100644 index 000000000..dd1172404 --- /dev/null +++ b/emtests/test_indirectbr_many.out @@ -0,0 +1 @@ +1001 diff --git a/emtests/test_indirectbr_many.wasm b/emtests/test_indirectbr_many.wasm new file mode 100644 index 000000000..baa1e21e1 Binary files /dev/null and b/emtests/test_indirectbr_many.wasm differ diff --git a/emtests/test_inherit.c b/emtests/test_inherit.c new file mode 100644 index 000000000..51115546c --- /dev/null +++ b/emtests/test_inherit.c @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct Parent { + int x1, x2; +}; +struct Child : Parent { + int y; +}; +int main() { + Parent a; + a.x1 = 50; + a.x2 = 87; + Child b; + b.x1 = 78; + b.x2 = 550; + b.y = 101; + Child* c = (Child*)&a; + c->x1++; + c = &b; + c->y--; + printf("*%d,%d,%d,%d,%d,%d,%d*\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2); + return 0; +} diff --git a/emtests/test_inherit.out b/emtests/test_inherit.out new file mode 100644 index 000000000..34570bd7a --- /dev/null +++ b/emtests/test_inherit.out @@ -0,0 +1 @@ +*51,87,78,550,100,78,550* \ No newline at end of file diff --git a/emtests/test_inlinejs.c b/emtests/test_inlinejs.c new file mode 100644 index 000000000..be22a2bd9 --- /dev/null +++ b/emtests/test_inlinejs.c @@ -0,0 +1,34 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +double get() { + double ret = 0; + __asm __volatile__("Math.abs(-12/3.3)" : "=r"(ret)); // write to a variable + asm("#comment1"); + asm volatile("#comment2"); + asm volatile( + "#comment3\n" + "#comment4\n"); + return ret; +} + +int main() { + asm("out('Inline JS is very cool')"); + printf("%.2f\n", get()); + + // Test that passing multiple input and output variables works. + int src1 = 1, src2 = 2, src3 = 3; + int dst1 = 0, dst2 = 0, dst3 = 0; + // TODO asm("out(%3); out(%4); out(%5); %0 = %3; %1 + // = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): + // "r"(src1),"r"(src2),"r"(src3)); + // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3); + + return 0; +} diff --git a/emtests/test_inlinejs.out b/emtests/test_inlinejs.out new file mode 100644 index 000000000..1838ef2e9 --- /dev/null +++ b/emtests/test_inlinejs.out @@ -0,0 +1,2 @@ +Inline JS is very cool +3.64 diff --git a/emtests/test_inlinejs2.c b/emtests/test_inlinejs2.c new file mode 100644 index 000000000..b3b201bc9 --- /dev/null +++ b/emtests/test_inlinejs2.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int mix(int x, int y) { + int ret; + asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write + return ret; +} + +void mult() { + asm("var $_$1 = Math.abs(-100); $_$1 *= 2; out($_$1)"); // multiline + asm __volatile__("out('done')"); +} + +int main(int argc, char **argv) { + printf("%d\n", mix(argc, argc / 2)); + mult(); + return 0; +} diff --git a/emtests/test_inlinejs2.out b/emtests/test_inlinejs2.out new file mode 100644 index 000000000..68dd9b641 --- /dev/null +++ b/emtests/test_inlinejs2.out @@ -0,0 +1,3 @@ +4 +200 +done diff --git a/emtests/test_inlinejs3.c b/emtests/test_inlinejs3.c new file mode 100644 index 000000000..ad548f6ab --- /dev/null +++ b/emtests/test_inlinejs3.c @@ -0,0 +1,41 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +void loop_iter() { + EM_ASM(out('loop iter!')); +} + +int main(int argc, char **argv) { + EM_ASM(out('hello dere1')); + EM_ASM("out('hello dere2');"); + emscripten_debugger(); // does nothing in shells; check for validation error though + for (int i = 0; i < 3; i++) { + EM_ASM(out('hello dere3'); out('hello dere' + 4);); + } + EM_ASM_({ out('hello input ' + $0) }, 123); + EM_ASM_ARGS({ out('hello input ' + $0) }, 456); + int sum = 0; + for (int i = 0; i < argc * 3; i++) { + sum += EM_ASM_INT({ + out('i: ' + [ $0, ($1).toFixed(2) ]); + return $0 * 2; + }, + i, double(i) / 12); + } + EM_ASM_INT({ globalVar = $0 }, sum); // no outputs, just input + sum = 0; + sum = EM_ASM_INT(return globalVar); // no inputs, just output + printf("sum: %d\n", sum); + printf("|%.2f|\n", EM_ASM_DOUBLE({ + return $0; // return double properly + }, 1.2)); + for (int i = 0; i < argc*2; i++) loop_iter(); + return 0; +} diff --git a/emtests/test_inlinejs3.out b/emtests/test_inlinejs3.out new file mode 100644 index 000000000..e65cddda3 --- /dev/null +++ b/emtests/test_inlinejs3.out @@ -0,0 +1,17 @@ +hello dere1 +hello dere2 +hello dere3 +hello dere4 +hello dere3 +hello dere4 +hello dere3 +hello dere4 +hello input 123 +hello input 456 +i: 0,0.00 +i: 1,0.08 +i: 2,0.17 +sum: 6 +|1.20| +loop iter! +loop iter! diff --git a/emtests/test_intentional_fault.c b/emtests/test_intentional_fault.c new file mode 100644 index 000000000..ab84416e4 --- /dev/null +++ b/emtests/test_intentional_fault.c @@ -0,0 +1,12 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main () { + *(volatile char *)0 = 0; + return *(volatile char *)0; +} diff --git a/emtests/test_intentional_fault.wasm b/emtests/test_intentional_fault.wasm new file mode 100644 index 000000000..661ceb762 Binary files /dev/null and b/emtests/test_intentional_fault.wasm differ diff --git a/emtests/test_intvars.c b/emtests/test_intvars.c new file mode 100644 index 000000000..715eff1be --- /dev/null +++ b/emtests/test_intvars.c @@ -0,0 +1,56 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int global = 20; +int *far; +int main() { + int x = 5; + int y = x + 17; + int z = (y - 1) / 2; // Should stay an integer after division! + y += 1; + int w = x * 3 + 4; + int k = w < 15 ? 99 : 101; + far = &k; + *far += global; + int i = k > 100; // Should be an int, not a bool! + int j = i << 6; + j >>= 1; + j = j ^ 5; + int h = 1; + h |= 0; + int p = h; + p &= 0; + printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p); + + long hash = -1; + size_t perturb; + int ii = 0; + for (perturb = hash;; perturb >>= 5) { + printf("%d:%d", ii, perturb); + ii++; + if (ii == 9) break; + printf(","); + } + printf("*\n"); + printf("*%.1d,%.2d*\n", 56, 9); + + // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit + // shifts in JS + { + struct Fixed { + static int Mult(int a, int b) { + return ((long long)a * (long long)b) >> 16; + } + }; + printf("fixed:%d\n", Fixed::Mult(150000, 140000)); + } + + printf("*%ld*%p\n", (long)21, + &hash); // The %p should not enter an infinite loop! + return 0; +} diff --git a/emtests/test_intvars.out b/emtests/test_intvars.out new file mode 100644 index 000000000..9d1cada75 --- /dev/null +++ b/emtests/test_intvars.out @@ -0,0 +1,5 @@ +*5,23,10,19,121,1,37,1,0* +0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0* +*56,09* +fixed:320434 +*21* \ No newline at end of file diff --git a/emtests/test_isdigit_l.c b/emtests/test_isdigit_l.c new file mode 100644 index 000000000..df9be72c3 --- /dev/null +++ b/emtests/test_isdigit_l.c @@ -0,0 +1,12 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + using namespace std; + use_facet >(cout.getloc()).put(cout, cout, '0', 3.14159265); +} diff --git a/emtests/test_isdigit_l.out b/emtests/test_isdigit_l.out new file mode 100644 index 000000000..2c0cac55e --- /dev/null +++ b/emtests/test_isdigit_l.out @@ -0,0 +1 @@ +3.14159 \ No newline at end of file diff --git a/emtests/test_isnan.c b/emtests/test_isnan.c new file mode 100644 index 000000000..3716c5a38 --- /dev/null +++ b/emtests/test_isnan.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int IsNaN(double x) { + int rc; /* The value return */ + volatile double y = x; + volatile double z = y; + rc = (y != z); + return rc; +} + +int main() { + double tests[] = {1.0, 3.333, 1.0 / 0.0, 0.0 / 0.0, -1.0 / 0.0, + -0, 0, -123123123, 12.0E200}; + for (int i = 0; i < sizeof(tests) / sizeof(double); i++) + printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i])); +} diff --git a/emtests/test_isnan.out b/emtests/test_isnan.out new file mode 100644 index 000000000..f517e69a6 --- /dev/null +++ b/emtests/test_isnan.out @@ -0,0 +1,9 @@ +0 - 1.000000 - 0 +1 - 3.333000 - 0 +2 - inf - 0 +3 - nan - 1 +4 - -inf - 0 +5 - 0.000000 - 0 +6 - 0.000000 - 0 +7 - -123123123.000000 - 0 +8 - 1199999999999999963679746655012433991369403930546028351778901011404162181226648906410356060856475022416330148991686588898185628812419341815672620492566878534452283092801479781734181759674005546258661376.000000 - 0 diff --git a/emtests/test_isnan.wasm b/emtests/test_isnan.wasm new file mode 100644 index 000000000..54db1e33b Binary files /dev/null and b/emtests/test_isnan.wasm differ diff --git a/emtests/test_istream.c b/emtests/test_istream.c new file mode 100644 index 000000000..74870f477 --- /dev/null +++ b/emtests/test_istream.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + std::string mystring("1 2 3"); + std::istringstream is(mystring); + int one, two, three; + + is >> one >> two >> three; + + printf("%i %i %i", one, two, three); +} diff --git a/emtests/test_istream.out b/emtests/test_istream.out new file mode 100644 index 000000000..703ca85bc --- /dev/null +++ b/emtests/test_istream.out @@ -0,0 +1 @@ +1 2 3 \ No newline at end of file diff --git a/emtests/test_iswdigit.c b/emtests/test_iswdigit.c new file mode 100644 index 000000000..df1f12a1e --- /dev/null +++ b/emtests/test_iswdigit.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + using namespace std; + printf("%d ", isdigit('0')); + printf("%d ", iswdigit(L'0')); + return 0; +} diff --git a/emtests/test_iswdigit.out b/emtests/test_iswdigit.out new file mode 100644 index 000000000..92880af71 --- /dev/null +++ b/emtests/test_iswdigit.out @@ -0,0 +1 @@ +1 1 \ No newline at end of file diff --git a/emtests/test_libcextra.c b/emtests/test_libcextra.c new file mode 100644 index 000000000..2220993d3 --- /dev/null +++ b/emtests/test_libcextra.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const wchar_t* wstr = L"Hello"; + + printf("wcslen: %d\n", wcslen(wstr)); + + return 0; +} diff --git a/emtests/test_libcextra.out b/emtests/test_libcextra.out new file mode 100644 index 000000000..d0191c327 --- /dev/null +++ b/emtests/test_libcextra.out @@ -0,0 +1 @@ +wcslen: 5 \ No newline at end of file diff --git a/emtests/test_libcextra.wasm b/emtests/test_libcextra.wasm new file mode 100644 index 000000000..fa88805e2 Binary files /dev/null and b/emtests/test_libcextra.wasm differ diff --git a/emtests/test_libgen.c b/emtests/test_libgen.c new file mode 100644 index 000000000..4fe55ba8d --- /dev/null +++ b/emtests/test_libgen.c @@ -0,0 +1,46 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + char p1[16] = "/usr/lib", p1x[16] = "/usr/lib"; + printf("%s -> ", p1); + printf("%s : %s\n", dirname(p1x), basename(p1)); + + char p2[16] = "/usr", p2x[16] = "/usr"; + printf("%s -> ", p2); + printf("%s : %s\n", dirname(p2x), basename(p2)); + + char p3[16] = "/usr/", p3x[16] = "/usr/"; + printf("%s -> ", p3); + printf("%s : %s\n", dirname(p3x), basename(p3)); + + char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///"; + printf("%s -> ", p4); + printf("%s : %s\n", dirname(p4x), basename(p4)); + + char p5[16] = "/", p5x[16] = "/"; + printf("%s -> ", p5); + printf("%s : %s\n", dirname(p5x), basename(p5)); + + char p6[16] = "///", p6x[16] = "///"; + printf("%s -> ", p6); + printf("%s : %s\n", dirname(p6x), basename(p6)); + + char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/.."; + printf("%s -> ", p7); + printf("%s : %s\n", dirname(p7x), basename(p7)); + + char p8[16] = "", p8x[16] = ""; + printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8)); + + printf("(null) -> %s : %s\n", dirname(0), basename(0)); + + return 0; +} diff --git a/emtests/test_libgen.out b/emtests/test_libgen.out new file mode 100644 index 000000000..b29893a87 --- /dev/null +++ b/emtests/test_libgen.out @@ -0,0 +1,9 @@ +/usr/lib -> /usr : lib +/usr -> / : usr +/usr/ -> / : usr +/usr/lib/// -> /usr : lib +/ -> / : / +/// -> / : / +/usr/../lib/.. -> /usr/../lib : .. +(empty) -> . : . +(null) -> . : . diff --git a/emtests/test_libgen.wasm b/emtests/test_libgen.wasm new file mode 100644 index 000000000..d4ae39405 Binary files /dev/null and b/emtests/test_libgen.wasm differ diff --git a/emtests/test_linked_list.c b/emtests/test_linked_list.c new file mode 100644 index 000000000..bcd5fc1ab --- /dev/null +++ b/emtests/test_linked_list.c @@ -0,0 +1,46 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct worker_args { + int value; + struct worker_args* next; +}; +int main() { + worker_args a; + worker_args b; + a.value = 60; + a.next = &b; + b.value = 900; + b.next = NULL; + worker_args* c = &a; + int total = 0; + while (c) { + total += c->value; + c = c->next; + } + + // Chunk of em + worker_args chunk[10]; + for (int i = 0; i < 9; i++) { + chunk[i].value = i * 10; + chunk[i].next = &chunk[i + 1]; + } + chunk[9].value = 90; + chunk[9].next = &chunk[0]; + + c = chunk; + do { + total += c->value; + c = c->next; + } while (c != chunk); + + printf("*%d,%p*\n", total, b.next); + // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) + + return 0; +} diff --git a/emtests/test_linked_list.out b/emtests/test_linked_list.out new file mode 100644 index 000000000..f3b615b1d --- /dev/null +++ b/emtests/test_linked_list.out @@ -0,0 +1 @@ +*1410,0* \ No newline at end of file diff --git a/emtests/test_literal_negative_zero.c b/emtests/test_literal_negative_zero.c new file mode 100644 index 000000000..056a3135e --- /dev/null +++ b/emtests/test_literal_negative_zero.c @@ -0,0 +1,34 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +static float XXXf = -0.0f; +static double XXXd = -0.0; + +struct x { + float f; + double d; +}; + +static struct x xx[] = { + -0x0p+0, + -0x0p+0, +}; + +int main(int argc, char ** argv) { + float YYYf = -0.0f; + float YYYd = -0.0; + + printf("%.2f\n", XXXf); + printf("%.2f\n", XXXd); + printf("%.2f\n", YYYf); + printf("%.2f\n", YYYd); + printf("%.2f\n", xx->f); + printf("%.2f\n", xx->d); +} diff --git a/emtests/test_literal_negative_zero.out b/emtests/test_literal_negative_zero.out new file mode 100644 index 000000000..d1b863b85 --- /dev/null +++ b/emtests/test_literal_negative_zero.out @@ -0,0 +1,6 @@ +-0.00 +-0.00 +-0.00 +-0.00 +-0.00 +-0.00 diff --git a/emtests/test_literal_negative_zero.wasm b/emtests/test_literal_negative_zero.wasm new file mode 100644 index 000000000..fd1de6b7a Binary files /dev/null and b/emtests/test_literal_negative_zero.wasm differ diff --git a/emtests/test_llrint.c b/emtests/test_llrint.c new file mode 100644 index 000000000..1d5018e49 --- /dev/null +++ b/emtests/test_llrint.c @@ -0,0 +1,14 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +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; +} diff --git a/emtests/test_llrint.out b/emtests/test_llrint.out new file mode 100644 index 000000000..80e9c9084 --- /dev/null +++ b/emtests/test_llrint.out @@ -0,0 +1,4 @@ +0 +1 +1 +1099511627777 diff --git a/emtests/test_llrint.wasm b/emtests/test_llrint.wasm new file mode 100644 index 000000000..019dbd283 Binary files /dev/null and b/emtests/test_llrint.wasm differ diff --git a/emtests/test_llvm_fabs.c b/emtests/test_llvm_fabs.c new file mode 100644 index 000000000..d5ebef76e --- /dev/null +++ b/emtests/test_llvm_fabs.c @@ -0,0 +1,37 @@ +/* + * Copyright 2015 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +float __attribute__((noinline)) negative10() +{ + return (emscripten_random() < -1) ? 0.f : -10.5f; +} + +float __attribute__((noinline)) positive42() +{ + return (emscripten_random() < -1) ? 0.f : 42.25f; +} + +double __attribute__((noinline)) negative_dbl_max() +{ + return (emscripten_random() < -1) ? 0.f : -DBL_MAX; +} + +int main() +{ + printf("%f\n", __builtin_fabsf(negative10())); + printf("%f\n", __builtin_fabsf(positive42())); + printf("%f\n", __builtin_fabsf((float)negative_dbl_max())); + + printf("%f\n", __builtin_fabs(negative10())); + printf("%f\n", __builtin_fabs(positive42())); + printf("%f\n", __builtin_fabs(negative_dbl_max())); +} diff --git a/emtests/test_llvm_fabs.out b/emtests/test_llvm_fabs.out new file mode 100644 index 000000000..3547f19cd --- /dev/null +++ b/emtests/test_llvm_fabs.out @@ -0,0 +1,6 @@ +10.500000 +42.250000 +inf +10.500000 +42.250000 +179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 diff --git a/emtests/test_llvm_fabs.wasm b/emtests/test_llvm_fabs.wasm new file mode 100644 index 000000000..ef1cb7fed Binary files /dev/null and b/emtests/test_llvm_fabs.wasm differ diff --git a/emtests/test_llvm_intrinsics.cpp b/emtests/test_llvm_intrinsics.cpp new file mode 100644 index 000000000..1349643ed --- /dev/null +++ b/emtests/test_llvm_intrinsics.cpp @@ -0,0 +1,198 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +extern "C" { +extern unsigned short llvm_bswap_i16(unsigned short x); +extern unsigned int llvm_bswap_i32(unsigned int x); +extern int32_t llvm_ctlz_i8(int8_t x, int izZeroUndef); +extern int32_t llvm_ctlz_i16(int16_t x, int izZeroUndef); +extern int32_t llvm_ctlz_i32(int32_t x, int izZeroUndef); +extern int64_t llvm_ctlz_i64(int64_t x, int izZeroUndef); +extern int32_t llvm_cttz_i32(int32_t x, int izZeroUndef); +extern int64_t llvm_cttz_i64(int64_t x, int izZeroUndef); +extern int32_t llvm_ctpop_i32(int32_t x); +extern int64_t llvm_ctpop_i64(int64_t x); +extern int llvm_expect_i32(int x, int y); +extern float llvm_powi_f32(float x, int32_t y); +extern double llvm_powi_f64(double x, int32_t y); +extern float llvm_trunc_f32(float x); +extern double llvm_trunc_f64(double x); +extern float llvm_ceil_f32(float x); +extern double llvm_ceil_f64(double x); +extern float llvm_floor_f32(float x); +extern double llvm_floor_f64(double x); +extern float llvm_cos_f32(float x); +extern double llvm_cos_f64(double x); +extern float llvm_sin_f32(float x); +extern double llvm_sin_f64(double x); +extern float llvm_exp2_f32(float x); +extern double llvm_exp2_f64(double x); +extern float llvm_log2_f32(float x); +extern double llvm_log2_f64(double x); +extern float llvm_log10_f32(float x); +extern double llvm_log10_f64(double x); + +extern float llvm_copysign_f32(float x, float y); +extern double llvm_copysign_f64(double x, double y); + +extern float llvm_round_f32(float x); +extern double llvm_round_f64(double x); +extern float llvm_minnum_f32(float x, float y); +extern double llvm_minnum_f64(double x, double y); +extern float llvm_maxnum_f32(float x, float y); +extern double llvm_maxnum_f64(double x, double y); +extern float llvm_nearbyint_f32(float x); +extern double llvm_nearbyint_f64(double x); +} + +int main(void) { + unsigned short x = 0xc8ef; + printf("%x,%x\n", x & 0xff, x >> 8); + x = llvm_bswap_i16(x); + printf("%x,%x\n", x & 0xff, x >> 8); + + unsigned int y = 0xc5de158a; + printf("%x,%x,%x,%x\n", y & 0xff, (y >> 8) & 0xff, (y >> 16) & 0xff, + (y >> 24) & 0xff); + y = llvm_bswap_i32(y); + printf("%x,%x,%x,%x\n", y & 0xff, (y >> 8) & 0xff, (y >> 16) & 0xff, + (y >> 24) & 0xff); + + printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40, 0), + llvm_ctlz_i32(1 << 10, 0)); + printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40, 0), + llvm_cttz_i32(1 << 10, 0)); + printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), + llvm_ctpop_i32(0x3101)); + + printf("llvm_cttz_i32:\n"); + printf("(0, 0)=%d\n", llvm_cttz_i32(0, 0)); + printf("(1, 0)=%d\n", llvm_cttz_i32(1, 0)); + printf("(2, 0)=%d\n", llvm_cttz_i32(2, 0)); + printf("(0x0000FFFF, 0)=%d\n", llvm_cttz_i32(0x0000FFFF, 0)); + printf("(0x7FFF0000, 0)=%d\n", llvm_cttz_i32(0x7FFF0000, 0)); + printf("(0xFFFF0000, 0)=%d\n", llvm_cttz_i32(0xFFFF0000, 0)); + printf("(0x7FFFFFFF, 0)=%d\n", llvm_cttz_i32(0x7FFFFFFF, 0)); + printf("(0xFFFFFFFE, 0)=%d\n", llvm_cttz_i32(0xFFFFFFFE, 0)); + printf("(0xFFFFFFFF, 0)=%d\n", llvm_cttz_i32(0xFFFFFFFF, 0)); + printf("small ctlz: %d,%d\n", (int)llvm_ctlz_i8(2, 0), llvm_ctlz_i16(2, 0)); + + printf("llvm_ctpop_i32:\n"); + printf("%d\n", (int)llvm_ctpop_i32(-594093059)); // 22 + printf("%d\n", (int)llvm_ctpop_i32(0xdeadbeef)); // 24 + printf("%d\n", (int)llvm_ctpop_i32(0x00000000)); // 0 + printf("%d\n", (int)llvm_ctpop_i32(0xffffffff)); // 32 + printf("%d\n", (int)llvm_ctpop_i32(0x55555555)); // 16 + printf("%d\n", (int)llvm_ctpop_i32(0xa55a5aa5)); // 16 + printf("%d\n", (int)llvm_ctpop_i32(0xaaaaaaaa)); // 16 + printf("%d\n", (int)llvm_ctpop_i32(0x80000000)); // 1 + printf("%d\n", (int)llvm_ctpop_i32(0x00000001)); // 1 + printf("llvm_expect_i32:\n"); + printf("%d\n", llvm_expect_i32(x % 27, 3)); + + int64_t a = 1; + a = __builtin_bswap64(a); + printf("%lld\n", a); + + printf("%d\n", (int)llvm_powi_f32(5.0f, 3)); + printf("%d\n", (int)llvm_powi_f64(3.0, 5)); + printf("%d\n", (int)llvm_trunc_f32(18.0987f)); + printf("%d\n", (int)llvm_trunc_f64(-12.42)); + printf("%d\n", (int)llvm_floor_f32(27.665f)); + printf("%d\n", (int)llvm_floor_f64(-8.95)); + printf("%.1f\n", llvm_cos_f32(0.0f * 3.14/180)); + printf("%.1f\n", llvm_cos_f64(180.0 * 3.14/180)); + printf("%.1f\n", llvm_sin_f32(90.0f * 3.14/180)); + printf("%.1f\n", llvm_sin_f64(270.0 * 3.14/180)); + + printf("exp2_f32 %.1f\n", llvm_exp2_f32(3)); + printf("exp2_f64 %.1f\n", llvm_exp2_f64(4.5)); + printf("log2_f32 %.1f\n", llvm_log2_f32(16)); + printf("log2_f64 %.1f\n", llvm_log2_f64(20)); + printf("log10_f32 %.1f\n", llvm_log10_f32(1000)); + printf("log10_f64 %.1f\n", llvm_log10_f64(2000)); + + printf("llvm_ceil_f32 %.1f\n", llvm_ceil_f32(1.4f)); + printf("llvm_ceil_f32 %.1f\n", llvm_ceil_f32(1.5f)); + printf("llvm_ceil_f32 %.1f\n", llvm_ceil_f32(1.6f)); + printf("llvm_ceil_f32 %.1f\n", llvm_ceil_f32(-1.4f)); + printf("llvm_ceil_f32 %.1f\n", llvm_ceil_f32(-1.5f)); + printf("llvm_ceil_f32 %.1f\n", llvm_ceil_f32(-1.6f)); + + printf("llvm_ceil_f64 %.1f\n", llvm_ceil_f64(1.4)); + printf("llvm_ceil_f64 %.1f\n", llvm_ceil_f64(1.5)); + printf("llvm_ceil_f64 %.1f\n", llvm_ceil_f64(1.6)); + printf("llvm_ceil_f64 %.1f\n", llvm_ceil_f64(-1.4)); + printf("llvm_ceil_f64 %.1f\n", llvm_ceil_f64(-1.5)); + printf("llvm_ceil_f64 %.1f\n", llvm_ceil_f64(-1.6)); + + printf("llvm_floor_f32 %.1f\n", llvm_floor_f32(1.4f)); + printf("llvm_floor_f32 %.1f\n", llvm_floor_f32(1.5f)); + printf("llvm_floor_f32 %.1f\n", llvm_floor_f32(1.6f)); + printf("llvm_floor_f32 %.1f\n", llvm_floor_f32(-1.4f)); + printf("llvm_floor_f32 %.1f\n", llvm_floor_f32(-1.5f)); + printf("llvm_floor_f32 %.1f\n", llvm_floor_f32(-1.6f)); + + printf("llvm_floor_f64 %.1f\n", llvm_floor_f64(1.4)); + printf("llvm_floor_f64 %.1f\n", llvm_floor_f64(1.5)); + printf("llvm_floor_f64 %.1f\n", llvm_floor_f64(1.6)); + printf("llvm_floor_f64 %.1f\n", llvm_floor_f64(-1.4)); + printf("llvm_floor_f64 %.1f\n", llvm_floor_f64(-1.5)); + printf("llvm_floor_f64 %.1f\n", llvm_floor_f64(-1.6)); + + printf("llvm_round_f64 %.1f\n", llvm_round_f64(20.49)); + printf("llvm_round_f64 %.1f\n", llvm_round_f64(20.5)); + printf("llvm_round_f64 %.1f\n", llvm_round_f64(42)); + printf("llvm_round_f64 %.1f\n", llvm_round_f64(-20.49)); + printf("llvm_round_f64 %.1f\n", llvm_round_f64(-20.5)); + printf("llvm_round_f64 %.1f\n", llvm_round_f64(-20.51)); + + printf("llvm_round_f32 %.1f\n", llvm_round_f32(20.49)); + printf("llvm_round_f32 %.1f\n", llvm_round_f32(20.5)); + printf("llvm_round_f32 %.1f\n", llvm_round_f32(42)); + printf("llvm_round_f32 %.1f\n", llvm_round_f32(-20.49)); + printf("llvm_round_f32 %.1f\n", llvm_round_f32(-20.5)); + printf("llvm_round_f32 %.1f\n", llvm_round_f32(-20.51)); + + printf("llvm_nearbyint_f64 %.1f\n", llvm_nearbyint_f64(20.50)); + printf("llvm_nearbyint_f64 %.1f\n", llvm_nearbyint_f64(20.51)); + printf("llvm_nearbyint_f64 %.1f\n", llvm_nearbyint_f64(42)); + printf("llvm_nearbyint_f64 %.1f\n", llvm_nearbyint_f64(-20.49)); + printf("llvm_nearbyint_f64 %.1f\n", llvm_nearbyint_f64(-20.5)); + printf("llvm_nearbyint_f64 %.1f\n", llvm_nearbyint_f64(-20.51)); + + printf("llvm_nearbyint_f32 %.1f\n", llvm_nearbyint_f32(20.50)); + printf("llvm_nearbyint_f32 %.1f\n", llvm_nearbyint_f32(20.51)); + printf("llvm_nearbyint_f32 %.1f\n", llvm_nearbyint_f32(42)); + printf("llvm_nearbyint_f32 %.1f\n", llvm_nearbyint_f32(-20.49)); + printf("llvm_nearbyint_f32 %.1f\n", llvm_nearbyint_f32(-20.5)); + printf("llvm_nearbyint_f32 %.1f\n", llvm_nearbyint_f32(-20.51)); + + printf("llvm_minnum_f32 %.1f\n", llvm_minnum_f32(5.7, 10.2)); + printf("llvm_minnum_f32 %.1f\n", llvm_minnum_f32(8.5, 2.3)); + printf("llvm_minnum_f64 %.1f\n", llvm_minnum_f64(5.7, 10.2)); + printf("llvm_minnum_f64 %.1f\n", llvm_minnum_f64(8.5, 2.3)); + + printf("llvm_maxnum_f32 %.1f\n", llvm_maxnum_f32(5.7, 10.2)); + printf("llvm_maxnum_f32 %.1f\n", llvm_maxnum_f32(8.5, 2.3)); + printf("llvm_maxnum_f64 %.1f\n", llvm_maxnum_f64(5.7, 10.2)); + printf("llvm_maxnum_f64 %.1f\n", llvm_maxnum_f64(8.5, 2.3)); + + printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(-1.2, 3.4)); + printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(5.6, -7.8)); + printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(-1.3, -2.4)); + printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(5.7, 6.8)); + printf("llvm_copysign_f64 %.1f\n", llvm_copysign_f64(-1.2, 3.4)); + printf("llvm_copysign_f64 %.1f\n", llvm_copysign_f64(5.6, -7.8)); + printf("llvm_copysign_f64 %.1f\n", llvm_copysign_f64(-1.3, -2.4)); + printf("llvm_copysign_f64 %.1f\n", llvm_copysign_f64(5.7, 6.8)); + + printf("ok.\n"); + + return 0; +} diff --git a/emtests/test_llvm_intrinsics.out b/emtests/test_llvm_intrinsics.out new file mode 100644 index 000000000..316cd68db --- /dev/null +++ b/emtests/test_llvm_intrinsics.out @@ -0,0 +1,112 @@ +ef,c8 +c8,ef +8a,15,de,c5 +c5,de,15,8a +23,21 +40,10 +5,4 +llvm_cttz_i32: +(0, 0)=32 +(1, 0)=0 +(2, 0)=1 +(0x0000FFFF, 0)=0 +(0x7FFF0000, 0)=16 +(0xFFFF0000, 0)=16 +(0x7FFFFFFF, 0)=0 +(0xFFFFFFFE, 0)=1 +(0xFFFFFFFF, 0)=0 +small ctlz: 6,14 +llvm_ctpop_i32: +22 +24 +0 +32 +16 +16 +16 +1 +1 +llvm_expect_i32: +13 +72057594037927936 +125 +243 +18 +-12 +27 +-9 +1.0 +-1.0 +1.0 +-1.0 +exp2_f32 8.0 +exp2_f64 22.6 +log2_f32 4.0 +log2_f64 4.3 +log10_f32 3.0 +log10_f64 3.3 +llvm_ceil_f32 2.0 +llvm_ceil_f32 2.0 +llvm_ceil_f32 2.0 +llvm_ceil_f32 -1.0 +llvm_ceil_f32 -1.0 +llvm_ceil_f32 -1.0 +llvm_ceil_f64 2.0 +llvm_ceil_f64 2.0 +llvm_ceil_f64 2.0 +llvm_ceil_f64 -1.0 +llvm_ceil_f64 -1.0 +llvm_ceil_f64 -1.0 +llvm_floor_f32 1.0 +llvm_floor_f32 1.0 +llvm_floor_f32 1.0 +llvm_floor_f32 -2.0 +llvm_floor_f32 -2.0 +llvm_floor_f32 -2.0 +llvm_floor_f64 1.0 +llvm_floor_f64 1.0 +llvm_floor_f64 1.0 +llvm_floor_f64 -2.0 +llvm_floor_f64 -2.0 +llvm_floor_f64 -2.0 +llvm_round_f64 20.0 +llvm_round_f64 21.0 +llvm_round_f64 42.0 +llvm_round_f64 -20.0 +llvm_round_f64 -21.0 +llvm_round_f64 -21.0 +llvm_round_f32 20.0 +llvm_round_f32 21.0 +llvm_round_f32 42.0 +llvm_round_f32 -20.0 +llvm_round_f32 -21.0 +llvm_round_f32 -21.0 +llvm_nearbyint_f64 20.0 +llvm_nearbyint_f64 21.0 +llvm_nearbyint_f64 42.0 +llvm_nearbyint_f64 -20.0 +llvm_nearbyint_f64 -20.0 +llvm_nearbyint_f64 -21.0 +llvm_nearbyint_f32 20.0 +llvm_nearbyint_f32 21.0 +llvm_nearbyint_f32 42.0 +llvm_nearbyint_f32 -20.0 +llvm_nearbyint_f32 -20.0 +llvm_nearbyint_f32 -21.0 +llvm_minnum_f32 5.7 +llvm_minnum_f32 2.3 +llvm_minnum_f64 5.7 +llvm_minnum_f64 2.3 +llvm_maxnum_f32 10.2 +llvm_maxnum_f32 8.5 +llvm_maxnum_f64 10.2 +llvm_maxnum_f64 8.5 +llvm_copysign_f32 1.2 +llvm_copysign_f32 -5.6 +llvm_copysign_f32 -1.3 +llvm_copysign_f32 5.7 +llvm_copysign_f64 1.2 +llvm_copysign_f64 -5.6 +llvm_copysign_f64 -1.3 +llvm_copysign_f64 5.7 +ok. diff --git a/emtests/test_llvm_intrinsics.wasm b/emtests/test_llvm_intrinsics.wasm new file mode 100644 index 000000000..6f170c1ae Binary files /dev/null and b/emtests/test_llvm_intrinsics.wasm differ diff --git a/emtests/test_llvm_used.c b/emtests/test_llvm_used.c new file mode 100644 index 000000000..a25241fb8 --- /dev/null +++ b/emtests/test_llvm_used.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +extern "C" { + __attribute__((annotate("hello attribute world"))) + EMSCRIPTEN_KEEPALIVE void foobar(int x) { + printf("Worked! %d\n", x); + } +} + +int main() { + emscripten_run_script("Module['_foobar'](10)"); + return 0; +} diff --git a/emtests/test_llvm_used.out b/emtests/test_llvm_used.out new file mode 100644 index 000000000..87ef26127 --- /dev/null +++ b/emtests/test_llvm_used.out @@ -0,0 +1 @@ +Worked! 10 diff --git a/emtests/test_llvmswitch.c b/emtests/test_llvmswitch.c new file mode 100644 index 000000000..93170c07d --- /dev/null +++ b/emtests/test_llvmswitch.c @@ -0,0 +1,30 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int switcher(int p) { + switch (p) { + case 'a': + case 'b': + case 'c': + return p - 1; + case -15: + return p + 1; + } + return p; +} + +int main(int argc, const char *argv[]) { + unsigned int x = 0xfffffff1; + x >>= (argc - 1); // force it to be unsigned for purpose of checking our + // switch comparison in signed/unsigned + printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'), + switcher(x), switcher(-15), switcher('e')); + return 0; +} diff --git a/emtests/test_llvmswitch.out b/emtests/test_llvmswitch.out new file mode 100644 index 000000000..4647c7e12 --- /dev/null +++ b/emtests/test_llvmswitch.out @@ -0,0 +1 @@ +*96,97,98,-14,-14,101* \ No newline at end of file diff --git a/emtests/test_llvmswitch.wasm b/emtests/test_llvmswitch.wasm new file mode 100644 index 000000000..076ad61a0 Binary files /dev/null and b/emtests/test_llvmswitch.wasm differ diff --git a/emtests/test_longjmp.c b/emtests/test_longjmp.c new file mode 100644 index 000000000..2abb84f98 --- /dev/null +++ b/emtests/test_longjmp.c @@ -0,0 +1,40 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +static jmp_buf buf; + +void second(void) { + printf("second\n"); + longjmp(buf, -1); +} + +void first(void) { + printf("first\n"); // prints + longjmp(buf, 1); // jumps back to where setjmp was called - making setjmp now + // return 1 +} + +int main() { + volatile int x = 0; + int jmpval = setjmp(buf); + if (!jmpval) { + x++; // should be properly restored once longjmp jumps back + first(); // when executed, setjmp returns 1 + printf("skipped\n"); // does not print + } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 + printf("result: %d %d\n", x, jmpval); // prints + x++; + second(); // when executed, setjmp returns -1 + } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 + printf("result: %d %d\n", x, jmpval); // prints + } + + return 0; +} diff --git a/emtests/test_longjmp.out b/emtests/test_longjmp.out new file mode 100644 index 000000000..4a412fef0 --- /dev/null +++ b/emtests/test_longjmp.out @@ -0,0 +1,4 @@ +first +result: 1 1 +second +result: 2 -1 \ No newline at end of file diff --git a/emtests/test_longjmp.wasm b/emtests/test_longjmp.wasm new file mode 100644 index 000000000..c38a00932 Binary files /dev/null and b/emtests/test_longjmp.wasm differ diff --git a/emtests/test_longjmp2.c b/emtests/test_longjmp2.c new file mode 100644 index 000000000..c9351dd3a --- /dev/null +++ b/emtests/test_longjmp2.c @@ -0,0 +1,42 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void stack_manipulate_func(jmp_state* s, int level) { + jmp_buf buf; + + printf("Entering stack_manipulate_func, level: %d\n", level); + + if (level == 0) { + s->jmp = &buf; + if (setjmp(*(s->jmp)) == 0) { + printf("Setjmp normal execution path, level: %d\n", level); + stack_manipulate_func(s, level + 1); + } else { + printf("Setjmp error execution path, level: %d\n", level); + } + } else { + printf("Perform longjmp at level %d\n", level); + longjmp(*(s->jmp), 1); + } + + printf("Exiting stack_manipulate_func, level: %d\n", level); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + stack_manipulate_func(&s, 0); + + return 0; +} diff --git a/emtests/test_longjmp2.out b/emtests/test_longjmp2.out new file mode 100644 index 000000000..829562159 --- /dev/null +++ b/emtests/test_longjmp2.out @@ -0,0 +1,6 @@ +Entering stack_manipulate_func, level: 0 +Setjmp normal execution path, level: 0 +Entering stack_manipulate_func, level: 1 +Perform longjmp at level 1 +Setjmp error execution path, level: 0 +Exiting stack_manipulate_func, level: 0 diff --git a/emtests/test_longjmp2.wasm b/emtests/test_longjmp2.wasm new file mode 100644 index 000000000..e2a0448f3 Binary files /dev/null and b/emtests/test_longjmp2.wasm differ diff --git a/emtests/test_longjmp3.c b/emtests/test_longjmp3.c new file mode 100644 index 000000000..843e4fb00 --- /dev/null +++ b/emtests/test_longjmp3.c @@ -0,0 +1,47 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void setjmp_func(jmp_state* s, int level) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + + if (level == 2) { + printf("level is 2, perform longjmp!\n"); + longjmp(*(s->jmp), 1); + } + + if (setjmp(c_jmp) == 0) { + printf("setjmp normal execution path, level: %d\n", level); + s->jmp = &c_jmp; + setjmp_func(s, level + 1); + } else { + printf("setjmp exception execution path, level: %d\n", level); + if (prev_jmp) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + longjmp(*(s->jmp), 1); + } + } + + printf("Exiting setjmp function, level: %d\n", level); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + + setjmp_func(&s, 0); + + return 0; +} diff --git a/emtests/test_longjmp3.out b/emtests/test_longjmp3.out new file mode 100644 index 000000000..c0d39cfbd --- /dev/null +++ b/emtests/test_longjmp3.out @@ -0,0 +1,7 @@ +setjmp normal execution path, level: 0 +setjmp normal execution path, level: 1 +level is 2, perform longjmp! +setjmp exception execution path, level: 1 +prev_jmp is not empty, continue with longjmp! +setjmp exception execution path, level: 0 +Exiting setjmp function, level: 0 diff --git a/emtests/test_longjmp3.wasm b/emtests/test_longjmp3.wasm new file mode 100644 index 000000000..af07d89df Binary files /dev/null and b/emtests/test_longjmp3.wasm differ diff --git a/emtests/test_longjmp4.c b/emtests/test_longjmp4.c new file mode 100644 index 000000000..88b150b93 --- /dev/null +++ b/emtests/test_longjmp4.c @@ -0,0 +1,47 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void second_func(jmp_state* s); + +void first_func(jmp_state* s) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + volatile int once = 0; + + if (setjmp(c_jmp) == 0) { + printf("Normal execution path of first function!\n"); + + s->jmp = &c_jmp; + second_func(s); + } else { + printf("Exception execution path of first function! %d\n", once); + + if (!once) { + printf("Calling longjmp the second time!\n"); + once = 1; + longjmp(*(s->jmp), 1); + } + } +} + +void second_func(jmp_state* s) { longjmp(*(s->jmp), 1); } + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + + first_func(&s); + + return 0; +} diff --git a/emtests/test_longjmp4.out b/emtests/test_longjmp4.out new file mode 100644 index 000000000..53fdd41bf --- /dev/null +++ b/emtests/test_longjmp4.out @@ -0,0 +1,4 @@ +Normal execution path of first function! +Exception execution path of first function! 0 +Calling longjmp the second time! +Exception execution path of first function! 1 diff --git a/emtests/test_longjmp4.wasm b/emtests/test_longjmp4.wasm new file mode 100644 index 000000000..12fbeeea7 Binary files /dev/null and b/emtests/test_longjmp4.wasm differ diff --git a/emtests/test_longjmp_exc.c b/emtests/test_longjmp_exc.c new file mode 100644 index 000000000..ea71f7b2f --- /dev/null +++ b/emtests/test_longjmp_exc.c @@ -0,0 +1,35 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +jmp_buf abortframe; + +void dostuff(int a) { + printf("pre\n"); + if (a != 42) + emscripten_run_script( + "waka_waka()"); // this should fail, and never reach "never" + printf("never\n"); + + if (a == 100) { + longjmp(abortframe, -1); + } + + if (setjmp(abortframe)) { + printf("got 100"); + } +} + +int main(int argc, char **argv) { + dostuff(argc); + exit(1); + return 1; +} diff --git a/emtests/test_longjmp_exc.out b/emtests/test_longjmp_exc.out new file mode 100644 index 000000000..b12dbd822 --- /dev/null +++ b/emtests/test_longjmp_exc.out @@ -0,0 +1 @@ +waka_waka \ No newline at end of file diff --git a/emtests/test_longjmp_exc.wasm b/emtests/test_longjmp_exc.wasm new file mode 100644 index 000000000..a1072597a Binary files /dev/null and b/emtests/test_longjmp_exc.wasm differ diff --git a/emtests/test_longjmp_funcptr.c b/emtests/test_longjmp_funcptr.c new file mode 100644 index 000000000..c2f0ff4c2 --- /dev/null +++ b/emtests/test_longjmp_funcptr.c @@ -0,0 +1,38 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +static jmp_buf buf; + +void (*fp)() = NULL; + +void second(void) { + printf("second\n"); // prints + longjmp(buf, 1); // jumps back to where setjmp was called - making setjmp now + // return 1 +} + +void first(void) { + fp(); + printf("first\n"); // does not print +} + +int main(int argc, char **argv) { + fp = argc == 200 ? NULL : second; + + volatile int x = 0; + if (!setjmp(buf)) { + x++; + first(); // when executed, setjmp returns 0 + } else { // when longjmp jumps back, setjmp returns 1 + printf("main: %d\n", x); // prints + } + + return 0; +} diff --git a/emtests/test_longjmp_funcptr.out b/emtests/test_longjmp_funcptr.out new file mode 100644 index 000000000..0e823e76b --- /dev/null +++ b/emtests/test_longjmp_funcptr.out @@ -0,0 +1,2 @@ +second +main: 1 diff --git a/emtests/test_longjmp_funcptr.wasm b/emtests/test_longjmp_funcptr.wasm new file mode 100644 index 000000000..2d642c2eb Binary files /dev/null and b/emtests/test_longjmp_funcptr.wasm differ diff --git a/emtests/test_longjmp_repeat.c b/emtests/test_longjmp_repeat.c new file mode 100644 index 000000000..43c0ac331 --- /dev/null +++ b/emtests/test_longjmp_repeat.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +static jmp_buf buf; + +int main() { + volatile int x = 0; + printf("setjmp:%d\n", setjmp(buf)); + x++; + printf("x:%d\n", x); + if (x < 4) longjmp(buf, x * 2); + return 0; +} diff --git a/emtests/test_longjmp_repeat.out b/emtests/test_longjmp_repeat.out new file mode 100644 index 000000000..8f4183b95 --- /dev/null +++ b/emtests/test_longjmp_repeat.out @@ -0,0 +1,8 @@ +setjmp:0 +x:1 +setjmp:2 +x:2 +setjmp:4 +x:3 +setjmp:6 +x:4 diff --git a/emtests/test_longjmp_repeat.wasm b/emtests/test_longjmp_repeat.wasm new file mode 100644 index 000000000..2eb523b83 Binary files /dev/null and b/emtests/test_longjmp_repeat.wasm differ diff --git a/emtests/test_longjmp_stacked.c b/emtests/test_longjmp_stacked.c new file mode 100644 index 000000000..cae85cb01 --- /dev/null +++ b/emtests/test_longjmp_stacked.c @@ -0,0 +1,49 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +int bottom, top; + +int run(int y) { + // confuse stack + char *s = (char *)alloca(100); + memset(s, 1, 100); + s[y] = y; + s[y / 2] = y * 2; + volatile int x = s[y]; + top = (int)alloca(4); + if (x <= 2) return x; + jmp_buf buf; + printf("setjmp of %d\n", x); + if (setjmp(buf) == 0) { + printf("going\n"); + x += run(x / 2); + longjmp(buf, 1); + } + printf("back\n"); + return x / 2; +} + +int main(int argc, char **argv) { + int sum = 0; + for (int i = 0; i < argc * 2; i++) { + bottom = (int)alloca(4); + sum += run(10); + // scorch the earth + if (bottom < top) { + memset((void *)bottom, 1, top - bottom); + } else { + memset((void *)top, 1, bottom - top); + } + } + printf("%d\n", sum); + return sum; +} diff --git a/emtests/test_longjmp_stacked.out b/emtests/test_longjmp_stacked.out new file mode 100644 index 000000000..d16a8e7da --- /dev/null +++ b/emtests/test_longjmp_stacked.out @@ -0,0 +1,13 @@ +setjmp of 10 +going +setjmp of 5 +going +back +back +setjmp of 10 +going +setjmp of 5 +going +back +back +12 diff --git a/emtests/test_longjmp_stacked.wasm b/emtests/test_longjmp_stacked.wasm new file mode 100644 index 000000000..280a974d5 Binary files /dev/null and b/emtests/test_longjmp_stacked.wasm differ diff --git a/emtests/test_longjmp_throw.cpp b/emtests/test_longjmp_throw.cpp new file mode 100644 index 000000000..dd4c23d85 --- /dev/null +++ b/emtests/test_longjmp_throw.cpp @@ -0,0 +1,43 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +static jmp_buf buf; +volatile int x = 0; + +void second(void) { + printf("second\n"); + if (x == 17) throw 5; + else longjmp(buf, -1); +} + +void first(void) { + printf("first\n"); + longjmp(buf, 1); +} + +int main() { + int jmpval = setjmp(buf); + if (!jmpval) { + x++; + first(); + printf("skipped\n"); + } else if (jmpval == 1) { + printf("result: %d %d\n", x, jmpval); + x++; + try { + second(); + } catch(int a) { + x--; + second(); + } + } else if (jmpval == -1) { + printf("result: %d %d\n", x, jmpval); + } + + return 0; +} diff --git a/emtests/test_longjmp_throw.out b/emtests/test_longjmp_throw.out new file mode 100644 index 000000000..e9cc75258 --- /dev/null +++ b/emtests/test_longjmp_throw.out @@ -0,0 +1,4 @@ +first +result: 1 1 +second +result: 2 -1 diff --git a/emtests/test_longjmp_throw.wasm b/emtests/test_longjmp_throw.wasm new file mode 100644 index 000000000..e006d275b Binary files /dev/null and b/emtests/test_longjmp_throw.wasm differ diff --git a/emtests/test_longjmp_unwind.c b/emtests/test_longjmp_unwind.c new file mode 100644 index 000000000..030abba37 --- /dev/null +++ b/emtests/test_longjmp_unwind.c @@ -0,0 +1,65 @@ +/* + * Copyright 2018 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +#define abs(x) ((x) < 0 ? (-x) : (x)) + +// A minor stack change is ignorable (e.g., printf) +#define MINOR 100 +// A major stack change must not happen +#define MAJOR 1000 + +jmp_buf jb; + +__attribute__((noinline)) int get_stack() +{ + int dummy; + int ptr = (int)&dummy; + return ptr; +} + +__attribute__((noinline)) void bar() +{ + printf("before longjmp: %d\n", get_stack()); + longjmp(jb, 1); +} + +volatile void* temp; + +__attribute__((noinline)) void foo() +{ + temp = alloca(MAJOR); + printf("major allocation at: %d\n", (int)temp); +#ifdef __asmjs__ + // asmjs stack grows up, but wasm backend stack grows down, so the delta + // between get_stack() and temp isn't related to the size of the alloca for + // wasm backend + assert(abs(get_stack() - (int)temp) >= MAJOR); +#endif + bar(); +} + +int main() +{ + int before = get_stack(); + printf("before setjmp: %d\n", before); + + if (!setjmp(jb)) { + foo(); + return 0; + } else { + int after = get_stack(); + printf("before setjmp: %d\n", after); + assert(abs(after - before) < MINOR); // stack has been unwound (but may have minor printf changes + printf("ok.\n"); + return 1; + } +} diff --git a/emtests/test_longjmp_unwind.out b/emtests/test_longjmp_unwind.out new file mode 100644 index 000000000..90b5016ef --- /dev/null +++ b/emtests/test_longjmp_unwind.out @@ -0,0 +1 @@ +ok. diff --git a/emtests/test_longjmp_unwind.wasm b/emtests/test_longjmp_unwind.wasm new file mode 100644 index 000000000..0fa0b29ef Binary files /dev/null and b/emtests/test_longjmp_unwind.wasm differ diff --git a/emtests/test_loop.c b/emtests/test_loop.c new file mode 100644 index 000000000..bc9e150ad --- /dev/null +++ b/emtests/test_loop.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + int x = 5; + for (int i = 0; i < 6; i++) { + x += x * i; + if (x > 1000) { + if (x % 7 == 0) printf("cheez\n"); + x /= 2; + break; + } + } + printf("*%d*\n", x); + return 0; +} diff --git a/emtests/test_loop.out b/emtests/test_loop.out new file mode 100644 index 000000000..428e01b6e --- /dev/null +++ b/emtests/test_loop.out @@ -0,0 +1 @@ +*1800* \ No newline at end of file diff --git a/emtests/test_loop.wasm b/emtests/test_loop.wasm new file mode 100644 index 000000000..1a72f176d Binary files /dev/null and b/emtests/test_loop.wasm differ diff --git a/emtests/test_lower_intrinsics.c b/emtests/test_lower_intrinsics.c new file mode 100644 index 000000000..b1966216f --- /dev/null +++ b/emtests/test_lower_intrinsics.c @@ -0,0 +1,35 @@ +/* + * Copyright 2018 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + volatile float f = 1.0f; + volatile double d = 2.0; + + #define TEST1(name) { \ + volatile float tf = name##f(f); \ + volatile double td = name(d); \ + } + TEST1(cos); + TEST1(exp); + TEST1(log); + TEST1(sin); + TEST1(sqrt); + + #define TEST2(name) { \ + volatile float tf = name##f(f, f); \ + volatile double td = name(d, d); \ + } + TEST2(pow); + + EM_ASM({ + out('ok.'); + }); +} + diff --git a/emtests/test_lower_intrinsics.out b/emtests/test_lower_intrinsics.out new file mode 100644 index 000000000..90b5016ef --- /dev/null +++ b/emtests/test_lower_intrinsics.out @@ -0,0 +1 @@ +ok. diff --git a/emtests/test_lower_intrinsics.wasm b/emtests/test_lower_intrinsics.wasm new file mode 100644 index 000000000..a987337b5 Binary files /dev/null and b/emtests/test_lower_intrinsics.wasm differ diff --git a/emtests/test_main_module_static_align.cpp b/emtests/test_main_module_static_align.cpp new file mode 100644 index 000000000..310848e48 --- /dev/null +++ b/emtests/test_main_module_static_align.cpp @@ -0,0 +1,18 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +__attribute__((aligned(16))) volatile char aligned; + +int main() { + emscripten_log(EM_LOG_WARN, "16-byte aligned char: %d.", int(&aligned)); + EM_ASM({ + // whether the char was properly aligned affects tempDoublePtr, which is after the static aligns + out('tempDoublePtr: ' + tempDoublePtr + '.'); + out('tempDoublePtr alignment: ' + (tempDoublePtr % 16) + '.'); + }); +} + diff --git a/emtests/test_main_module_static_align.txt b/emtests/test_main_module_static_align.txt new file mode 100644 index 000000000..755a70dd6 --- /dev/null +++ b/emtests/test_main_module_static_align.txt @@ -0,0 +1 @@ +tempDoublePtr alignment: 0. diff --git a/emtests/test_main_module_static_align.wasm b/emtests/test_main_module_static_align.wasm new file mode 100644 index 000000000..3a408b30e Binary files /dev/null and b/emtests/test_main_module_static_align.wasm differ diff --git a/emtests/test_main_thread_async_em_asm.cpp b/emtests/test_main_thread_async_em_asm.cpp new file mode 100644 index 000000000..0c805bc64 --- /dev/null +++ b/emtests/test_main_thread_async_em_asm.cpp @@ -0,0 +1,16 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include + +int main() +{ + // Test that on main browser thread, MAIN_THREAD_ASYNC_EM_ASM() will get + // synchronously executed. + printf("Before MAIN_THREAD_ASYNC_EM_ASM\n"); + MAIN_THREAD_ASYNC_EM_ASM(out('Inside MAIN_THREAD_ASYNC_EM_ASM: ' + $0 + ' ' + $1), 42, 3.5); + printf("After MAIN_THREAD_ASYNC_EM_ASM\n"); +} diff --git a/emtests/test_main_thread_async_em_asm.out b/emtests/test_main_thread_async_em_asm.out new file mode 100644 index 000000000..47ebc8fad --- /dev/null +++ b/emtests/test_main_thread_async_em_asm.out @@ -0,0 +1,3 @@ +Before MAIN_THREAD_ASYNC_EM_ASM +Inside MAIN_THREAD_ASYNC_EM_ASM: 42 3.5 +After MAIN_THREAD_ASYNC_EM_ASM diff --git a/emtests/test_main_thread_async_em_asm.wasm b/emtests/test_main_thread_async_em_asm.wasm new file mode 100644 index 000000000..02d6a801a Binary files /dev/null and b/emtests/test_main_thread_async_em_asm.wasm differ diff --git a/emtests/test_mainenv.c b/emtests/test_mainenv.c new file mode 100644 index 000000000..ceb30fe84 --- /dev/null +++ b/emtests/test_mainenv.c @@ -0,0 +1,12 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main(int argc, char **argv, char **envp) { + printf("*%p*\n", envp); + return 0; +} diff --git a/emtests/test_mainenv.out b/emtests/test_mainenv.out new file mode 100644 index 000000000..5fc422ed9 --- /dev/null +++ b/emtests/test_mainenv.out @@ -0,0 +1 @@ +*0* diff --git a/emtests/test_mainenv.wasm b/emtests/test_mainenv.wasm new file mode 100644 index 000000000..ef8783709 Binary files /dev/null and b/emtests/test_mainenv.wasm differ diff --git a/emtests/test_math.c b/emtests/test_math.c new file mode 100644 index 000000000..4b136b038 --- /dev/null +++ b/emtests/test_math.c @@ -0,0 +1,80 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +using namespace std; + +int main(int argc, char **argv) { + printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1 / 0.0) > 1e300); // could end up as + // infinity, or just + // a very very big + // number + printf(",%d", isfinite(NAN) != 0); + printf(",%d", isfinite(INFINITY) != 0); + printf(",%d", isfinite(-INFINITY) != 0); + printf(",%d", isfinite(12.3) != 0); + printf(",%d", isinf(NAN) != 0); + printf(",%d", isinf(INFINITY) != 0); + printf(",%d", isinf(-INFINITY) != 0); + printf(",%d", isinf(12.3) != 0); + + div_t div_result = div(23, 10); + printf(",%d", div_result.quot); + printf(",%d", div_result.rem); + + div_result = div(-5, 3); // see div manpage :) + printf(",%d", div_result.quot); // -1 + printf(",%d", div_result.rem); // -2 + + div_result = div(5, -3); + printf(",%d", div_result.quot); + printf(",%d", div_result.rem); + + div_result = div(-5, -3); + printf(",%d", div_result.quot); + printf(",%d", div_result.rem); + + + + { + double x,y; + x = modf(3.2, &y); + printf(",%1.1lf", x); + printf(",%1.1lf", y); + x = modf(-3.2, &y); + printf(",%1.1lf", x); + printf(",%1.1lf", y); + } + + { + float x,y; + x = modff(3.2, &y); + printf(",%1.1f", x); + printf(",%1.1f", y); + x = modff(-3.2, &y); + printf(",%1.1f", x); + printf(",%1.1f", y); + } + + double sine = -1.0, cosine = -1.0; + sincos(0.0, &sine, &cosine); + printf(",%1.1lf", sine); + printf(",%1.1lf", cosine); + float fsine = -1.0f, fcosine = -1.0f; + sincosf(0.0, &fsine, &fcosine); + printf(",%1.1f", fsine); + printf(",%1.1f", fcosine); + fsine = sinf(1.1 + argc - 1); + fcosine = cosf(1.1 + argc - 1); + printf(",%1.1f", fsine); + printf(",%1.1f", fcosine); + printf("*\n"); + return 0; +} diff --git a/emtests/test_math.out b/emtests/test_math.out new file mode 100644 index 000000000..3475a0216 --- /dev/null +++ b/emtests/test_math.out @@ -0,0 +1 @@ +*3.14,-3.14,1,0,0,0,1,0,1,1,0,2,3,-1,-2,-1,2,1,-2,0.2,3.0,-0.2,-3.0,0.2,3.0,-0.2,-3.0,0.0,1.0,0.0,1.0,0.9,0.5* \ No newline at end of file diff --git a/emtests/test_mathfuncptr.c b/emtests/test_mathfuncptr.c new file mode 100644 index 000000000..8fba500ff --- /dev/null +++ b/emtests/test_mathfuncptr.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char **argv) { + float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf; + float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf; + float (*fn3)(float) = argc != 14 ? &erff : &fabsf; + printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), + fn3(10)); + return 0; +} diff --git a/emtests/test_mathfuncptr.out b/emtests/test_mathfuncptr.out new file mode 100644 index 000000000..166cc3da4 --- /dev/null +++ b/emtests/test_mathfuncptr.out @@ -0,0 +1 @@ +fn2(-5) = 5, fn(10) = 3.16, erf(10) = 1.00 \ No newline at end of file diff --git a/emtests/test_mathfuncptr.wasm b/emtests/test_mathfuncptr.wasm new file mode 100644 index 000000000..7691f159d Binary files /dev/null and b/emtests/test_mathfuncptr.wasm differ diff --git a/emtests/test_memcpy2.c b/emtests/test_memcpy2.c new file mode 100644 index 000000000..bfcf1959d --- /dev/null +++ b/emtests/test_memcpy2.c @@ -0,0 +1,27 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +int main() { + char buffer[256]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 35; k++) { + for (int t = 0; t < 256; t++) buffer[t] = t; + char *dest = buffer + i + 128; + char *src = buffer + j; + // printf("%d, %d, %d\n", i, j, k); + assert(memcpy(dest, src, k) == dest); + assert(memcmp(dest, src, k) == 0); + } + } + } + printf("ok.\n"); + return 1; +} diff --git a/emtests/test_memcpy2.out b/emtests/test_memcpy2.out new file mode 100644 index 000000000..59f3f9845 --- /dev/null +++ b/emtests/test_memcpy2.out @@ -0,0 +1 @@ +ok. \ No newline at end of file diff --git a/emtests/test_memcpy2.wasm b/emtests/test_memcpy2.wasm new file mode 100644 index 000000000..23fd1f404 Binary files /dev/null and b/emtests/test_memcpy2.wasm differ diff --git a/emtests/test_memcpy3.c b/emtests/test_memcpy3.c new file mode 100644 index 000000000..7da6c2e11 --- /dev/null +++ b/emtests/test_memcpy3.c @@ -0,0 +1,58 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +#define TOTAL 10240 + +#define TEST(size, type) { \ + for (int i = 0; i < TOTAL; i++) { \ + buffer[i] = i*seed; \ + } \ + memcpy(buffer, buffer+size+1, size*sizeof(type)); \ + int v = 0; \ + for (int i = 0; i < TOTAL; i++) { \ + v += buffer[i]; \ + } \ + printf("final %d:%d\n", size, v); \ +} + +int main() { + #define RUN(type) \ + { \ + type buffer[TOTAL]; \ + volatile int seed = 123; \ + TEST(1, type); \ + TEST(2, type); \ + TEST(3, type); \ + TEST(4, type); \ + TEST(5, type); \ + TEST(6, type); \ + TEST(7, type); \ + TEST(8, type); \ + TEST(9, type); \ + TEST(10, type); \ + TEST(16, type); \ + TEST(32, type); \ + TEST(64, type); \ + TEST(128, type); \ + TEST(256, type); \ + TEST(512, type); \ + TEST(1024, type); \ + for (int x = 10; x < 100; x += 10) { TEST(x, type) }; \ + } + printf("8\n"); + RUN(unsigned char); + printf("16\n"); + RUN(unsigned short); + printf("32\n"); + RUN(unsigned); + return 1; +} + diff --git a/emtests/test_memcpy3.out b/emtests/test_memcpy3.out new file mode 100644 index 000000000..6f39e709e --- /dev/null +++ b/emtests/test_memcpy3.out @@ -0,0 +1,81 @@ +8 +final 1:1305846 +final 2:1305826 +final 3:1305796 +final 4:1305756 +final 5:1305706 +final 6:1305646 +final 7:1305576 +final 8:1305496 +final 9:1305406 +final 10:1305306 +final 16:1305264 +final 32:1305696 +final 64:1305024 +final 128:1305728 +final 256:1305600 +final 512:1305600 +final 1024:1305600 +final 10:1305306 +final 20:1305548 +final 30:1305814 +final 40:1305336 +final 50:1305906 +final 60:1305476 +final 70:1305582 +final 80:1305712 +final 90:1304842 +16 +final 1:332555510 +final 2:332556002 +final 3:332556740 +final 4:332557724 +final 5:332558954 +final 6:332560430 +final 7:332562152 +final 8:332564120 +final 9:332566334 +final 10:332568794 +final 16:332588720 +final 32:332685152 +final 64:333066944 +final 128:334586240 +final 256:340647680 +final 512:332618240 +final 1024:332812288 +final 10:332568794 +final 20:332606924 +final 30:332669654 +final 40:332756984 +final 50:332868914 +final 60:333005444 +final 70:333166574 +final 80:333352304 +final 90:333562634 +32 +final 1:-2141821706 +final 2:-2141821214 +final 3:-2141820476 +final 4:-2141819492 +final 5:-2141818262 +final 6:-2141816786 +final 7:-2141815064 +final 8:-2141813096 +final 9:-2141810882 +final 10:-2141808422 +final 16:-2141788496 +final 32:-2141692064 +final 64:-2141310272 +final 128:-2139790976 +final 256:-2133729536 +final 512:-2109515264 +final 1024:-2012721152 +final 10:-2141808422 +final 20:-2141770292 +final 30:-2141707562 +final 40:-2141620232 +final 50:-2141508302 +final 60:-2141371772 +final 70:-2141210642 +final 80:-2141024912 +final 90:-2140814582 diff --git a/emtests/test_memcpy3.wasm b/emtests/test_memcpy3.wasm new file mode 100644 index 000000000..d30196686 Binary files /dev/null and b/emtests/test_memcpy3.wasm differ diff --git a/emtests/test_memcpy_memcmp.c b/emtests/test_memcpy_memcmp.c new file mode 100644 index 000000000..b13a2b8fc --- /dev/null +++ b/emtests/test_memcpy_memcmp.c @@ -0,0 +1,50 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +#define MAXX 48 +void reset(unsigned char *buffer) { + for (int i = 0; i < MAXX; i++) buffer[i] = i + 1; +} +void dump(unsigned char *buffer) { + for (int i = 0; i < MAXX - 1; i++) printf("%2d,", buffer[i]); + printf("%d\n", buffer[MAXX - 1]); +} +int main() { + unsigned char buffer[MAXX]; + for (int i = MAXX / 4; i < MAXX - MAXX / 4; i++) { + for (int j = MAXX / 4; j < MAXX - MAXX / 4; j++) { + for (int k = 1; k < MAXX / 4; k++) { + if (i == j) continue; + if (i < j && i + k > j) continue; + if (j < i && j + k > i) continue; + printf("[%d,%d,%d] ", i, j, k); + reset(buffer); + memcpy(buffer + i, buffer + j, k); + dump(buffer); + assert(memcmp(buffer + i, buffer + j, k) == 0); + buffer[i + k / 2]++; + if (buffer[i + k / 2] != 0) { + assert(memcmp(buffer + i, buffer + j, k) > 0); + } else { + assert(memcmp(buffer + i, buffer + j, k) < 0); + } + buffer[i + k / 2]--; + buffer[j + k / 2]++; + if (buffer[j + k / 2] != 0) { + assert(memcmp(buffer + i, buffer + j, k) < 0); + } else { + assert(memcmp(buffer + i, buffer + j, k) > 0); + } + } + } + } + return 0; +} diff --git a/emtests/test_memcpy_memcmp.out b/emtests/test_memcpy_memcmp.out new file mode 100644 index 000000000..934209810 --- /dev/null +++ b/emtests/test_memcpy_memcmp.out @@ -0,0 +1 @@ +6c9cdfe937383b79e52ca7a2cce83a21d9f5422c \ No newline at end of file diff --git a/emtests/test_memcpy_memcmp.wasm b/emtests/test_memcpy_memcmp.wasm new file mode 100644 index 000000000..222b6d764 Binary files /dev/null and b/emtests/test_memcpy_memcmp.wasm differ diff --git a/emtests/test_memmove.c b/emtests/test_memmove.c new file mode 100644 index 000000000..760b9a440 --- /dev/null +++ b/emtests/test_memmove.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { + char str[] = "memmove can be very useful....!"; + memmove(str + 20, str + 15, 11); + puts(str); + return 0; +} diff --git a/emtests/test_memmove.out b/emtests/test_memmove.out new file mode 100644 index 000000000..e2a1ac2f8 --- /dev/null +++ b/emtests/test_memmove.out @@ -0,0 +1 @@ +memmove can be very very useful \ No newline at end of file diff --git a/emtests/test_memmove.wasm b/emtests/test_memmove.wasm new file mode 100644 index 000000000..a5ba50b75 Binary files /dev/null and b/emtests/test_memmove.wasm differ diff --git a/emtests/test_memmove2.c b/emtests/test_memmove2.c new file mode 100644 index 000000000..73eccf1f0 --- /dev/null +++ b/emtests/test_memmove2.c @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +int main() { + int sum = 0; + char buffer[256]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 35; k++) { + for (int t = 0; t < 256; t++) buffer[t] = t; + char *dest = buffer + i; + char *src = buffer + j; + if (dest == src) continue; + // printf("%d, %d, %d\n", i, j, k); + assert(memmove(dest, src, k) == dest); + for (int t = 0; t < 256; t++) sum += buffer[t]; + } + } + } + printf("final: %d.\n", sum); + return 1; +} diff --git a/emtests/test_memmove2.out b/emtests/test_memmove2.out new file mode 100644 index 000000000..0e06b2e7e --- /dev/null +++ b/emtests/test_memmove2.out @@ -0,0 +1 @@ +final: -403200. \ No newline at end of file diff --git a/emtests/test_memmove2.wasm b/emtests/test_memmove2.wasm new file mode 100644 index 000000000..8ddb8bab7 Binary files /dev/null and b/emtests/test_memmove2.wasm differ diff --git a/emtests/test_memmove3.c b/emtests/test_memmove3.c new file mode 100644 index 000000000..e9fc7c165 --- /dev/null +++ b/emtests/test_memmove3.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { + char str[] = "memmove can be vvery useful....!"; + memmove(str + 15, str + 16, 17); + puts(str); + return 0; +} diff --git a/emtests/test_memmove3.out b/emtests/test_memmove3.out new file mode 100644 index 000000000..1adadcc22 --- /dev/null +++ b/emtests/test_memmove3.out @@ -0,0 +1 @@ +memmove can be very useful....! \ No newline at end of file diff --git a/emtests/test_memmove3.wasm b/emtests/test_memmove3.wasm new file mode 100644 index 000000000..4b620ec4c Binary files /dev/null and b/emtests/test_memmove3.wasm differ diff --git a/emtests/test_memorygrowth.c b/emtests/test_memorygrowth.c new file mode 100644 index 000000000..fc90ef540 --- /dev/null +++ b/emtests/test_memorygrowth.c @@ -0,0 +1,42 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#include "emscripten.h" + +int main(int argc, char **argv) +{ + char *buf1 = (char*)malloc(100); + char *data1 = (char*)"hello"; + memcpy(buf1, data1, strlen(data1)+1); + + float *buf2 = (float*)malloc(100); + float pie = 4.955; + memcpy(buf2, &pie, sizeof(float)); + + printf("*pre: %s,%.3f*\n", buf1, buf2[0]); + + 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", (int)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); + assert((int)buf4 > (int)totalMemory && (int)buf5 > (int)totalMemory); + + printf("*%s,%.3f*\n", buf1, buf2[0]); // the old heap data should still be there + + memcpy(buf4, buf1, strlen(data1)+1); + memcpy(buf5, buf2, sizeof(float)); + printf("*%s,%.3f*\n", buf4, buf5[0]); // and the new heap space should work too + + return 0; +} diff --git a/emtests/test_memorygrowth.wasm b/emtests/test_memorygrowth.wasm new file mode 100644 index 000000000..03a5ad50c Binary files /dev/null and b/emtests/test_memorygrowth.wasm differ diff --git a/emtests/test_memorygrowth_2.c b/emtests/test_memorygrowth_2.c new file mode 100644 index 000000000..c0d8c6899 --- /dev/null +++ b/emtests/test_memorygrowth_2.c @@ -0,0 +1,46 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#include "emscripten.h" + +int main(int argc, char **argv) +{ + char *buf1 = (char*)malloc(100); + char *data1 = "hello"; + memcpy(buf1, data1, strlen(data1)+1); + + float *buf2 = (float*)malloc(100); + float pie = 4.955; + memcpy(buf2, &pie, sizeof(float)); + + printf("*pre: %s,%.3f*\n", buf1, buf2[0]); + + int totalMemory = emscripten_run_script_int("TOTAL_MEMORY"); + int chunk = 1024*1024; + char *buf3; + for (int i = 0; i < (totalMemory/chunk)+1; i++) { + buf3 = (char*)malloc(chunk); + 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); + assert((int)buf4 > (int)totalMemory && (int)buf5 > (int)totalMemory); + + printf("*%s,%.3f*\n", buf1, buf2[0]); // the old heap data should still be there + + memcpy(buf4, buf1, strlen(data1)+1); + memcpy(buf5, buf2, sizeof(float)); + printf("*%s,%.3f*\n", buf4, buf5[0]); // and the new heap space should work too + + return 0; +} diff --git a/emtests/test_memorygrowth_2.wasm b/emtests/test_memorygrowth_2.wasm new file mode 100644 index 000000000..aa3c9f758 Binary files /dev/null and b/emtests/test_memorygrowth_2.wasm differ diff --git a/emtests/test_memorygrowth_3.c b/emtests/test_memorygrowth_3.c new file mode 100644 index 000000000..d541cc2db --- /dev/null +++ b/emtests/test_memorygrowth_3.c @@ -0,0 +1,54 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include "emscripten.h" + +int get_TOTAL_MEMORY() { + return EM_ASM_INT({ return TOTAL_MEMORY }); +} + +typedef void* voidStar; + +int main(int argc, char **argv) +{ + int totalMemory = get_TOTAL_MEMORY(); + int chunk = 1024*1024; + volatile voidStar alloc; +#ifdef FAIL_REALLOC_BUFFER + EM_ASM({ + Module.seenOurReallocBuffer = false; + Module['reallocBuffer'] = function() { + Module.seenOurReallocBuffer = true; + return null; + }; + }); +#endif + for (int i = 0; i < (totalMemory/chunk)+2; i++) { + // make sure state remains the same if malloc fails + void* sbrk_before = sbrk(0); + alloc = malloc(chunk); + printf("%d : %d\n", i, !!alloc); + if (alloc == NULL) { + assert(sbrk(0) == sbrk_before); + assert(totalMemory == get_TOTAL_MEMORY()); + break; + } + } + assert(alloc == NULL); +#ifdef FAIL_REALLOC_BUFFER + EM_ASM({ + assert(Module.seenOurReallocBuffer, 'our override should have been called'); + }); +#endif + puts("ok."); + return 0; +} diff --git a/emtests/test_memorygrowth_3.txt b/emtests/test_memorygrowth_3.txt new file mode 100644 index 000000000..90b5016ef --- /dev/null +++ b/emtests/test_memorygrowth_3.txt @@ -0,0 +1 @@ +ok. diff --git a/emtests/test_memorygrowth_3.wasm b/emtests/test_memorygrowth_3.wasm new file mode 100644 index 000000000..167d32d9d Binary files /dev/null and b/emtests/test_memorygrowth_3.wasm differ diff --git a/emtests/test_memorygrowth_wasm_mem_max.c b/emtests/test_memorygrowth_wasm_mem_max.c new file mode 100644 index 000000000..8cc520c27 --- /dev/null +++ b/emtests/test_memorygrowth_wasm_mem_max.c @@ -0,0 +1,29 @@ +/* + * Copyright 2018 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + const int MB = 1024 * 1024; + // TOTAL_MEMORY starts at 64MB, and max is 100. allocate enough + // to prove we can grow. 70 is enough to prove we can grow, + // higher can prove we stop at the right point. + for (int i = 0; 1; i++) { + printf("%d\n", i); + volatile int sink = (int)malloc(MB); + if (!sink) { + printf("failed at %d\n", i); + assert(i > 70); + break; + } + assert(i <= 100); // the wasm mem max limit, we must not get there + } + printf("grew memory ok.\n"); +} + diff --git a/emtests/test_memorygrowth_wasm_mem_max.txt b/emtests/test_memorygrowth_wasm_mem_max.txt new file mode 100644 index 000000000..726d4b028 --- /dev/null +++ b/emtests/test_memorygrowth_wasm_mem_max.txt @@ -0,0 +1 @@ +grew memory ok. diff --git a/emtests/test_memorygrowth_wasm_mem_max.wasm b/emtests/test_memorygrowth_wasm_mem_max.wasm new file mode 100644 index 000000000..b70b836ee Binary files /dev/null and b/emtests/test_memorygrowth_wasm_mem_max.wasm differ diff --git a/emtests/test_memset.c b/emtests/test_memset.c new file mode 100644 index 000000000..5b6a8b256 --- /dev/null +++ b/emtests/test_memset.c @@ -0,0 +1,58 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +#define TOTAL 10240 + +#define TEST(size, type) { \ + for (int i = 0; i < TOTAL; i++) { \ + buffer[i] = i*seed; \ + } \ + memset(buffer+size%17, 0xA5, size); \ + int v = 0; \ + for (int i = 0; i < TOTAL; i++) { \ + v += buffer[i]; \ + } \ + printf("final %d:%d\n", size, v); \ +} + +int main() { + #define RUN(type) \ + { \ + type buffer[TOTAL]; \ + volatile int seed = 123; \ + TEST(1, type); \ + TEST(2, type); \ + TEST(3, type); \ + TEST(4, type); \ + TEST(5, type); \ + TEST(6, type); \ + TEST(7, type); \ + TEST(8, type); \ + TEST(9, type); \ + TEST(10, type); \ + TEST(16, type); \ + TEST(32, type); \ + TEST(64, type); \ + TEST(128, type); \ + TEST(256, type); \ + TEST(512, type); \ + TEST(1024, type); \ + for (int x = 10; x < 100; x += 10) { TEST(x, type) }; \ + } + printf("8\n"); + RUN(unsigned char); + printf("16\n"); + RUN(unsigned short); + printf("32\n"); + RUN(unsigned); + return 1; +} + diff --git a/emtests/test_memset.out b/emtests/test_memset.out new file mode 100644 index 000000000..7517e6ba6 --- /dev/null +++ b/emtests/test_memset.out @@ -0,0 +1,81 @@ +8 +final 1:1305642 +final 2:1305571 +final 3:1305643 +final 4:1305602 +final 5:1305704 +final 6:1305693 +final 7:1305825 +final 8:1305844 +final 9:1306006 +final 10:1306055 +final 16:1306280 +final 32:1307056 +final 64:1308384 +final 128:1310400 +final 256:1315200 +final 512:1324800 +final 1024:1344000 +final 10:1306055 +final 20:1306310 +final 30:1306867 +final 40:1307060 +final 50:1307463 +final 60:1307850 +final 70:1308037 +final 80:1308424 +final 90:1308805 +16 +final 1:332555306 +final 2:332597423 +final 3:332597229 +final 4:332638967 +final 5:332638793 +final 6:332679896 +final 7:332679486 +final 8:332720210 +final 9:332719820 +final 10:332759909 +final 16:332875316 +final 32:333189464 +final 64:333800048 +final 128:334950368 +final 256:336967616 +final 512:339333248 +final 1024:337924352 +final 10:332759909 +final 20:332970089 +final 30:333154439 +final 40:333365234 +final 50:333529289 +final 60:333740699 +final 70:333957644 +final 80:334096484 +final 90:334314044 +32 +final 1:-2141821910 +final 2:-2141779793 +final 3:-2130966476 +final 4:637274041 +final 5:637273857 +final 6:637315339 +final 7:648128533 +final 8:-878598369 +final 9:-878598523 +final 10:-878557932 +final 16:384620786 +final 32:-1383904756 +final 64:-625991496 +final 128:889823216 +final 256:-373561888 +final 512:1394178624 +final 1024:633133696 +final 10:-878557932 +final 20:-1131244490 +final 30:132010428 +final 40:-120673793 +final 50:1142572023 +final 60:889890139 +final 70:-2141802805 +final 80:1900447306 +final 90:-1131244285 diff --git a/emtests/test_memset.wasm b/emtests/test_memset.wasm new file mode 100644 index 000000000..75fdbcf60 Binary files /dev/null and b/emtests/test_memset.wasm differ diff --git a/emtests/test_mmap.c b/emtests/test_mmap.c new file mode 100644 index 000000000..26f337bb0 --- /dev/null +++ b/emtests/test_mmap.c @@ -0,0 +1,48 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + // Alignment check for mmap below should be consistent with the reported page size + // For now, just require it to be 16384 + assert(getpagesize() == 16384); + assert(sysconf(_SC_PAGESIZE) == 16384); + + for (int i = 0; i < 10; i++) { + int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + assert(map != MAP_FAILED); + assert(((int)map) % 16384 == 0); // aligned + assert(munmap(map, 5000) == 0); + } + + const int NUM_BYTES = 8 * 1024 * 1024; + const int NUM_INTS = NUM_BYTES / sizeof(int); + + int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + assert(map != MAP_FAILED); + + int i; + + for (i = 0; i < NUM_INTS; i++) { + map[i] = i; + } + + for (i = 0; i < NUM_INTS; i++) { + assert(map[i] == i); + } + + assert(munmap(map, NUM_BYTES) == 0); + + printf("hello,world"); + return 0; +} diff --git a/emtests/test_mmap.out b/emtests/test_mmap.out new file mode 100644 index 000000000..f2fff68f3 --- /dev/null +++ b/emtests/test_mmap.out @@ -0,0 +1 @@ +hello,world \ No newline at end of file diff --git a/emtests/test_mmap.wasm b/emtests/test_mmap.wasm new file mode 100644 index 000000000..7a268605b Binary files /dev/null and b/emtests/test_mmap.wasm differ diff --git a/emtests/test_mod_globalstruct.c b/emtests/test_mod_globalstruct.c new file mode 100644 index 000000000..5566761ff --- /dev/null +++ b/emtests/test_mod_globalstruct.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +struct malloc_params { + size_t magic, page_size; +}; + +malloc_params mparams; + +#define SIZE_T_ONE ((size_t)1) +#define page_align(S) \ + (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) + +int main() { + mparams.page_size = 4096; + printf("*%d,%d,%d,%d*\n", mparams.page_size, page_align(1000), + page_align(6000), page_align(66474)); + return 0; +} diff --git a/emtests/test_mod_globalstruct.out b/emtests/test_mod_globalstruct.out new file mode 100644 index 000000000..3be9bc197 --- /dev/null +++ b/emtests/test_mod_globalstruct.out @@ -0,0 +1 @@ +*4096,4096,8192,69632* \ No newline at end of file diff --git a/emtests/test_negative_zero.c b/emtests/test_negative_zero.c new file mode 100644 index 000000000..870fa1c10 --- /dev/null +++ b/emtests/test_negative_zero.c @@ -0,0 +1,57 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +// test copysign of 0 +int __attribute__((noinline)) +copysign_bug (double x) +{ + if (x != 0.0 && (x * 0.5 == x)) { + printf("1\n"); + return 1; + } + printf("f: %f\n", x); + if (__builtin_copysign(1.0, x) < 0.0) { + printf("2\n"); + return 2; + } else { + printf("3\n"); + return 3; + } +} + +int main() { +#define TEST(x, y) printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y)); + TEST(5.0f, 5.0f); + TEST(5.0f, -5.0f); + TEST(-5.0f, 5.0f); + TEST(-5.0f, -5.0f); + TEST(5.0f, 4.0f); + TEST(5.0f, -4.0f); + TEST(-5.0f, 4.0f); + TEST(-5.0f, -4.0f); + TEST(0.0f, 5.0f); + TEST(0.0f, -5.0f); + TEST(-0.0f, 5.0f); + TEST(-0.0f, -5.0f); + TEST(5.0f, 0.0f); + TEST(5.0f, -0.0f); + TEST(-5.0f, 0.0f); + TEST(-5.0f, -0.0f); + TEST(0.0f, 0.0f); + TEST(0.0f, -0.0f); + TEST(-0.0f, 0.0f); + TEST(-0.0f, -0.0f); + + double x = -0.0; + if (copysign_bug (x) != 2) + __builtin_abort (); + + return 0; +} diff --git a/emtests/test_negative_zero.out b/emtests/test_negative_zero.out new file mode 100644 index 000000000..71ac79b28 --- /dev/null +++ b/emtests/test_negative_zero.out @@ -0,0 +1,22 @@ +5.00, 5.00 ==> 5.00 +5.00, -5.00 ==> -5.00 +-5.00, 5.00 ==> 5.00 +-5.00, -5.00 ==> -5.00 +5.00, 4.00 ==> 5.00 +5.00, -4.00 ==> -5.00 +-5.00, 4.00 ==> 5.00 +-5.00, -4.00 ==> -5.00 +0.00, 5.00 ==> 0.00 +0.00, -5.00 ==> -0.00 +-0.00, 5.00 ==> 0.00 +-0.00, -5.00 ==> -0.00 +5.00, 0.00 ==> 5.00 +5.00, -0.00 ==> -5.00 +-5.00, 0.00 ==> 5.00 +-5.00, -0.00 ==> -5.00 +0.00, 0.00 ==> 0.00 +0.00, -0.00 ==> -0.00 +-0.00, 0.00 ==> 0.00 +-0.00, -0.00 ==> -0.00 +f: -0.000000 +2 diff --git a/emtests/test_negative_zero.wasm b/emtests/test_negative_zero.wasm new file mode 100644 index 000000000..d5dd33fe9 Binary files /dev/null and b/emtests/test_negative_zero.wasm differ diff --git a/emtests/test_nested_struct_varargs.c b/emtests/test_nested_struct_varargs.c new file mode 100644 index 000000000..b4eaf1b50 --- /dev/null +++ b/emtests/test_nested_struct_varargs.c @@ -0,0 +1,52 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +struct A { + int x; +}; + +struct B { + double x; +}; + +struct C { + char c[9]; + struct A a; + struct B b; +}; + +void foo(int unused, ...) +{ + va_list vl; + va_start(vl, unused); + struct C c = va_arg(vl, struct C); + va_end(vl); + + printf("%d\n", c.a.x); + printf("%f\n", c.b.x); + printf("%s\n", c.c); +} + +int main() { + struct A a = { + .x = 42, + }; + struct B b = { + .x = 42.314, + }; + struct C c = { + .a = a, + .b = b, + .c = "nicetest", + }; + foo(0, c); + return 0; +} + diff --git a/emtests/test_nested_struct_varargs.out b/emtests/test_nested_struct_varargs.out new file mode 100644 index 000000000..10dd54227 --- /dev/null +++ b/emtests/test_nested_struct_varargs.out @@ -0,0 +1,3 @@ +42 +42.314000 +nicetest diff --git a/emtests/test_nested_struct_varargs.wasm b/emtests/test_nested_struct_varargs.wasm new file mode 100644 index 000000000..8e1b4465f Binary files /dev/null and b/emtests/test_nested_struct_varargs.wasm differ diff --git a/emtests/test_nl_types.c b/emtests/test_nl_types.c new file mode 100644 index 000000000..e30120afd --- /dev/null +++ b/emtests/test_nl_types.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main(int argc, char ** argv) { + nl_catd c = catopen("none", 0); + printf("Hello, %s.\n", catgets(c, 0, 0, "world")); + return catclose(c); +} diff --git a/emtests/test_nl_types.out b/emtests/test_nl_types.out new file mode 100644 index 000000000..f75ba05f3 --- /dev/null +++ b/emtests/test_nl_types.out @@ -0,0 +1 @@ +Hello, world. diff --git a/emtests/test_nl_types.wasm b/emtests/test_nl_types.wasm new file mode 100644 index 000000000..68ddf74b4 Binary files /dev/null and b/emtests/test_nl_types.wasm differ diff --git a/emtests/test_perrar.c b/emtests/test_perrar.c new file mode 100644 index 000000000..9500ce170 --- /dev/null +++ b/emtests/test_perrar.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +int main(int argc, char** argv) { + int retval = open("NonExistingFile", O_RDONLY); + if (retval == -1) perror("Cannot open NonExistingFile"); + return 0; +} diff --git a/emtests/test_perrar.out b/emtests/test_perrar.out new file mode 100644 index 000000000..0de5f4489 --- /dev/null +++ b/emtests/test_perrar.out @@ -0,0 +1 @@ +Cannot open NonExistingFile: No such file or directory diff --git a/emtests/test_perrar.wasm b/emtests/test_perrar.wasm new file mode 100644 index 000000000..a41ebac0d Binary files /dev/null and b/emtests/test_perrar.wasm differ diff --git a/emtests/test_phiundef.c b/emtests/test_phiundef.c new file mode 100644 index 000000000..cc7aacbaf --- /dev/null +++ b/emtests/test_phiundef.c @@ -0,0 +1,37 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +static int state; + +struct my_struct { + union { + struct { + unsigned char a; + unsigned char b; + } c; + unsigned int d; + } e; + unsigned int f; +}; + +int main(int argc, char **argv) { + struct my_struct r; + + state = 0; + + for (int i = 0; i < argc + 10; i++) { + if (state % 2 == 0) + r.e.c.a = 3; + else + printf("%d\n", r.e.c.a); + state++; + } + return 0; +} diff --git a/emtests/test_phiundef.out b/emtests/test_phiundef.out new file mode 100644 index 000000000..3b04a0398 --- /dev/null +++ b/emtests/test_phiundef.out @@ -0,0 +1,5 @@ +3 +3 +3 +3 +3 diff --git a/emtests/test_phiundef.wasm b/emtests/test_phiundef.wasm new file mode 100644 index 000000000..e857c4599 Binary files /dev/null and b/emtests/test_phiundef.wasm differ diff --git a/emtests/test_poll.c b/emtests/test_poll.c new file mode 100644 index 000000000..89fc4b46d --- /dev/null +++ b/emtests/test_poll.c @@ -0,0 +1,35 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +int main() { + struct pollfd multi[5]; + multi[0].fd = open("/file", O_RDONLY, 0777); + multi[1].fd = open("/device", O_RDONLY, 0777); + multi[2].fd = 123; + multi[3].fd = open("/file", O_RDONLY, 0777); + multi[4].fd = open("/file", O_RDONLY, 0777); + multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[3].events = 0x00; + multi[4].events = POLLOUT | POLLNVAL | POLLERR; + + printf("ret: %d\n", poll(multi, 5, 123)); + printf("errno: %d\n", errno); + printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT)); + printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT)); + printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL); + printf("multi[3].revents: %d\n", multi[3].revents == 0); + printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT); + + return 0; +} diff --git a/emtests/test_poll.out b/emtests/test_poll.out new file mode 100644 index 000000000..8ffd32649 --- /dev/null +++ b/emtests/test_poll.out @@ -0,0 +1,7 @@ +ret: 4 +errno: 0 +multi[0].revents: 1 +multi[1].revents: 1 +multi[2].revents: 1 +multi[3].revents: 1 +multi[4].revents: 1 diff --git a/emtests/test_poll.wasm b/emtests/test_poll.wasm new file mode 100644 index 000000000..ddf56301a Binary files /dev/null and b/emtests/test_poll.wasm differ diff --git a/emtests/test_polymorph.c b/emtests/test_polymorph.c new file mode 100644 index 000000000..59774e1a3 --- /dev/null +++ b/emtests/test_polymorph.c @@ -0,0 +1,48 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct Pure { + virtual int implme() = 0; +}; +struct Parent : Pure { + virtual int getit() { + return 11; + }; + int implme() { return 32; } +}; +struct Child : Parent { + int getit() { return 74; } + int implme() { return 1012; } +}; + +struct Other { + int one() { return 11; } + int two() { return 22; } + virtual int three() { return 33; } + virtual int four() { return 44; } +}; + +int main() { + Parent *x = new Parent(); + Parent *y = new Child(); + printf("*%d,%d,%d,%d*\n", x->getit(), y->getit(), x->implme(), y->implme()); + + Other *o = new Other; + + int (Other::*Ls)() = &Other::one; + printf("*%d*\n", (o->*(Ls))()); + Ls = &Other::two; + printf("*%d*\n", (o->*(Ls))()); + + Ls = &Other::three; + printf("*%d*\n", (o->*(Ls))()); + Ls = &Other::four; + printf("*%d*\n", (o->*(Ls))()); + + return 0; +} diff --git a/emtests/test_polymorph.out b/emtests/test_polymorph.out new file mode 100644 index 000000000..5163ea8e8 --- /dev/null +++ b/emtests/test_polymorph.out @@ -0,0 +1,5 @@ +*11,74,32,1012* +*11* +*22* +*33* +*44* diff --git a/emtests/test_posixtime.c b/emtests/test_posixtime.c new file mode 100644 index 000000000..406e30665 --- /dev/null +++ b/emtests/test_posixtime.c @@ -0,0 +1,54 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + clockid_t clocks[] = { CLOCK_REALTIME, CLOCK_MONOTONIC }; + for (int i = 0; i < (int)(sizeof(clocks)/sizeof(*clocks)); ++i) { + printf("%sTests for clockid_t=%d\n-----------------\n", + i == 0 ? "" : "\n", clocks[i]); + struct timespec ts; + int rv = clock_getres(clocks[i], &ts); + if (rv) + printf("clock_getres failed\n"); + else if (ts.tv_sec || ts.tv_nsec > 50000000) + printf("clock_getres resolution not enough (%ld.%09ld)\n", + (long)ts.tv_sec, ts.tv_nsec); + else + printf("clock_getres resolution OK\n"); + rv = clock_gettime(clocks[i], &ts); + printf(rv ? "clock_gettime failed\n" : "clock_gettime OK\n"); + errno = 0; + if (clock_settime(clocks[i], &ts) == 0) + printf("clock_settime should have failed\n"); + else if (errno == EPERM && clocks[i] == CLOCK_REALTIME) + printf("clock_settime failed with EPERM (OK)\n"); + else if (errno == EINVAL && clocks[i] == CLOCK_MONOTONIC) + printf("clock_settime failed with EINVAL (OK)\n"); + else + printf("clock_settime failed with wrong error code\n"); + } + clockid_t bogus = 42; + struct timespec ts; + printf("\nTests for clockid_t=%d\n-----------------\n", bogus); + if (clock_gettime(bogus, &ts) == 0 || errno != EINVAL) + printf("clock_gettime should have failed\n"); + else + printf("clock_gettime failed with EINVAL (OK)\n"); + if (clock_getres(bogus, &ts) == 0 || errno != EINVAL) + printf("clock_getres should have failed\n"); + else + printf("clock_getres failed with EINVAL (OK)\n"); + if (clock_settime(bogus, &ts) == 0 || errno != EINVAL) + printf("clock_settime should have failed\n"); + else + printf("clock_settime failed with EINVAL (OK)\n"); + return 0; +} diff --git a/emtests/test_posixtime.out b/emtests/test_posixtime.out new file mode 100644 index 000000000..84417e293 --- /dev/null +++ b/emtests/test_posixtime.out @@ -0,0 +1,17 @@ +Tests for clockid_t=0 +----------------- +clock_getres resolution OK +clock_gettime OK +clock_settime failed with EPERM (OK) + +Tests for clockid_t=1 +----------------- +clock_getres resolution OK +clock_gettime OK +clock_settime failed with EINVAL (OK) + +Tests for clockid_t=42 +----------------- +clock_gettime failed with EINVAL (OK) +clock_getres failed with EINVAL (OK) +clock_settime failed with EINVAL (OK) diff --git a/emtests/test_posixtime.wasm b/emtests/test_posixtime.wasm new file mode 100644 index 000000000..10f21d0a9 Binary files /dev/null and b/emtests/test_posixtime.wasm differ diff --git a/emtests/test_posixtime_no_monotonic.out b/emtests/test_posixtime_no_monotonic.out new file mode 100644 index 000000000..52a47a143 --- /dev/null +++ b/emtests/test_posixtime_no_monotonic.out @@ -0,0 +1,17 @@ +Tests for clockid_t=0 +----------------- +clock_getres resolution OK +clock_gettime OK +clock_settime failed with EPERM (OK) + +Tests for clockid_t=1 +----------------- +clock_getres failed +clock_gettime failed +clock_settime failed with EINVAL (OK) + +Tests for clockid_t=42 +----------------- +clock_gettime failed with EINVAL (OK) +clock_getres failed with EINVAL (OK) +clock_settime failed with EINVAL (OK) diff --git a/emtests/test_printf_2.c b/emtests/test_printf_2.c new file mode 100644 index 000000000..43e53ec15 --- /dev/null +++ b/emtests/test_printf_2.c @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main() { + char c = '1'; + short s = 2; + int i = 3; + long long l = 4; + float f = 5.5; + double d = 6.6; + + printf("%c,%hd,%d,%lld,%.1f,%.1f\n", c, s, i, l, f, d); + printf("%#x,%#x\n", 1, 0); + + return 0; +} diff --git a/emtests/test_printf_2.out b/emtests/test_printf_2.out new file mode 100644 index 000000000..002cd93a5 --- /dev/null +++ b/emtests/test_printf_2.out @@ -0,0 +1,2 @@ +1,2,3,4,5.5,6.6 +0x1,0 diff --git a/emtests/test_printf_2.wasm b/emtests/test_printf_2.wasm new file mode 100644 index 000000000..f92646368 Binary files /dev/null and b/emtests/test_printf_2.wasm differ diff --git a/emtests/test_printf_more.c b/emtests/test_printf_more.c new file mode 100644 index 000000000..96cd3202a --- /dev/null +++ b/emtests/test_printf_more.c @@ -0,0 +1,24 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345); + char buf[size]; + snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345); + printf("%d : %s\n", size, buf); + char *buff = NULL; + asprintf(&buff, "%d waka %d\n", 21, 95); + puts(buff); + // test buffering, write more than a musl buffer at once + #define X 1026 + char c[X]; + for(int i=0;i 1025 this line doesn't print if we don't handle buffering properly + return 0; +} diff --git a/emtests/test_printf_more.out b/emtests/test_printf_more.out new file mode 100644 index 000000000..3472cfdad --- /dev/null +++ b/emtests/test_printf_more.out @@ -0,0 +1,4 @@ +22 : me and myself 25 1.34 +21 waka 95 + +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA diff --git a/emtests/test_printf_more.wasm b/emtests/test_printf_more.wasm new file mode 100644 index 000000000..d49d932de Binary files /dev/null and b/emtests/test_printf_more.wasm differ diff --git a/emtests/test_ptrtoint.out b/emtests/test_ptrtoint.out new file mode 100644 index 000000000..770e08e07 --- /dev/null +++ b/emtests/test_ptrtoint.out @@ -0,0 +1 @@ +*5* \ No newline at end of file diff --git a/emtests/test_random_device.cpp b/emtests/test_random_device.cpp new file mode 100644 index 000000000..9ab6d3c7f --- /dev/null +++ b/emtests/test_random_device.cpp @@ -0,0 +1,21 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include + +auto main() + -> int +try +{ + std::random_device rd; + std::cout << "random was read" << "\n"; +} +catch( const std::exception& e ) +{ + std::cerr << e.what(); +} + diff --git a/emtests/test_random_device.txt b/emtests/test_random_device.txt new file mode 100644 index 000000000..4b386ac68 --- /dev/null +++ b/emtests/test_random_device.txt @@ -0,0 +1 @@ +random was read diff --git a/emtests/test_regex.c b/emtests/test_regex.c new file mode 100644 index 000000000..8c91d187c --- /dev/null +++ b/emtests/test_regex.c @@ -0,0 +1,43 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +// This is from// http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm +#include +#include +#include + +int main(void) { + regex_t preg; + const char *string = "a very simple simple simple string"; + const char *pattern = "\\(sim[a-z]le\\) \\1"; + int rc; + size_t nmatch = 2; + regmatch_t pmatch[2]; + + if (0 != (rc = regcomp(&preg, pattern, 0))) { + printf("regcomp() failed, returning nonzero (%d)\n", rc); + exit(EXIT_FAILURE); + } + + if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { + printf("Failed to match '%s' with '%s',returning %d.\n", string, pattern, + rc); + } else { + printf( + "With the whole expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], + pmatch[0].rm_so, pmatch[0].rm_eo - 1); + printf( + "With the sub-expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], + pmatch[1].rm_so, pmatch[1].rm_eo - 1); + } + regfree(&preg); + return 0; +} diff --git a/emtests/test_regex.out b/emtests/test_regex.out new file mode 100644 index 000000000..f238d2e33 --- /dev/null +++ b/emtests/test_regex.out @@ -0,0 +1,2 @@ +With the whole expression, a matched substring "simple simple" is found at position 7 to 19. +With the sub-expression, a matched substring "simple" is found at position 7 to 12. \ No newline at end of file diff --git a/emtests/test_regex.wasm b/emtests/test_regex.wasm new file mode 100644 index 000000000..e99a9da9c Binary files /dev/null and b/emtests/test_regex.wasm differ diff --git a/emtests/test_reinterpreted_ptrs.c b/emtests/test_reinterpreted_ptrs.c new file mode 100644 index 000000000..7ed09084f --- /dev/null +++ b/emtests/test_reinterpreted_ptrs.c @@ -0,0 +1,47 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +class Foo { + private: + float bar; + + public: + int baz; + + Foo() : bar(0), baz(4711) {}; + + int getBar() const; +}; + +int Foo::getBar() const { + return this->bar; +}; + +const Foo *magic1 = reinterpret_cast(0xDEAD111F); +const Foo *magic2 = reinterpret_cast(0xDEAD888F); + +static void runTest() { + + const Foo *a = new Foo(); + const Foo *b = a; + + if (a->getBar() == 0) { + if (a->baz == 4712) + b = magic1; + else + b = magic2; + } + + printf("%s\n", + (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); +}; + +extern "C" { +int main(int argc, char **argv) { runTest(); } +} diff --git a/emtests/test_reinterpreted_ptrs.out b/emtests/test_reinterpreted_ptrs.out new file mode 100644 index 000000000..360335022 --- /dev/null +++ b/emtests/test_reinterpreted_ptrs.out @@ -0,0 +1 @@ +magic2 \ No newline at end of file diff --git a/emtests/test_relocatable_void_function.c b/emtests/test_relocatable_void_function.c new file mode 100644 index 000000000..7ffe3043e --- /dev/null +++ b/emtests/test_relocatable_void_function.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +void hi_world() { + puts("hi world"); +} + +int main() { + hi_world(); + return 0; +} diff --git a/emtests/test_relocatable_void_function.out b/emtests/test_relocatable_void_function.out new file mode 100644 index 000000000..3d2efad00 --- /dev/null +++ b/emtests/test_relocatable_void_function.out @@ -0,0 +1 @@ +hi world \ No newline at end of file diff --git a/emtests/test_relocatable_void_function.wasm b/emtests/test_relocatable_void_function.wasm new file mode 100644 index 000000000..ee4050825 Binary files /dev/null and b/emtests/test_relocatable_void_function.wasm differ diff --git a/emtests/test_rounding.c b/emtests/test_rounding.c new file mode 100644 index 000000000..8c52d47a3 --- /dev/null +++ b/emtests/test_rounding.c @@ -0,0 +1,81 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +const char *mode(int mode) +{ + switch(mode) + { + case FE_DOWNWARD: return "FE_DOWNWARD"; + case FE_TONEAREST: return "FE_TONEAREST"; + case FE_TOWARDZERO: return "FE_TOWARDZERO"; + case FE_UPWARD: return "FE_UPWARD"; + default: return "Unknown"; + } +} + +#define NUMELEMS(x) (sizeof((x)) / sizeof((x)[0])) + +int main() { + printf("Initial rounding mode is %s\n", mode(fegetround())); + + // The functions round() and roundf() are specced to always round *away* from zero (negative numbers down, positive numbers up) + // fesetround() mode dictates what to do when rounding halfway numbers (-0.5, 0.5, 1.5, 2.5, ...) in functions rint(), rintf(), lrint(), lrintf(), llrint() and llrintf(): + // FE_DOWNWARD always rounds down to the smaller integer. + // FE_TONEAREST performs banker's rounding (always round towards the even number) + // FE_TOWARDZERO rounds negative numbers up, and positive numbers down + // FE_UPWARD always rounds up to the next higher integer. +// const int modes[] = { FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD }; // TODO: Currently only supported mode is FE_TONEAREST. + const int modes[] = { FE_TONEAREST }; + const double interestingDoubles[] = { -4.5, -3.6, -3.5, -3.4, -2.6, -2.5, -2.4, -1.5, -0.5, 0, 0.5, 1.4, 1.5, 1.6, 2.5, 3.5, 4.5 }; + const float interestingFloats[] = { -4.5f, -3.6f, -3.5f, -3.4f, -2.6f, -2.5f, -2.4f, -1.5f, -0.5f, 0, 0.5f, 1.4f, 1.5f, 1.6f, 2.5f, 3.5f, 4.5f }; + + for(int i = 0; i < NUMELEMS(modes); ++i) + { + int ret = fesetround(modes[i]); + int modeAfter = fegetround(); + printf("fesetround(%s) returned %d, fegetround() afterwards returns %s. Test results:\n", mode(modes[i]), ret, mode(modeAfter)); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: round(%.1f)=%.1f\n", mode(modeAfter), interestingDoubles[j], round(interestingDoubles[j])); + + for(int j = 0; j < NUMELEMS(interestingFloats); ++j) + printf("%s: roundf(%.1f)=%.1f\n", mode(modeAfter), interestingFloats[j], roundf(interestingFloats[j])); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: rint(%.1f)=%.1f\n", mode(modeAfter), interestingDoubles[j], rint(interestingDoubles[j])); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: rintf(%.1f)=%.1f\n", mode(modeAfter), interestingFloats[j], rint(interestingFloats[j])); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: lrint(%.1f)=%ld\n", mode(modeAfter), interestingDoubles[j], lrint(interestingDoubles[j])); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: lrintf(%.1f)=%ld\n", mode(modeAfter), interestingFloats[j], lrintf(interestingFloats[j])); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: llrint(%.1f)=%lld\n", mode(modeAfter), interestingDoubles[j], llrint(interestingDoubles[j])); + + for(int j = 0; j < NUMELEMS(interestingDoubles); ++j) + printf("%s: llrintf(%.1f)=%lld\n", mode(modeAfter), interestingFloats[j], llrintf(interestingFloats[j])); + } + + double param, fractpart, intpart; + + param = 3.14159265; + fractpart = modf (param , &intpart); + printf ("%f = %f + %f\n", param, intpart, fractpart); + + param = -3.14159265; + fractpart = modf (param , &intpart); + printf ("%f = %f + %f\n", param, intpart, fractpart); + return 0; +} diff --git a/emtests/test_rounding.out b/emtests/test_rounding.out new file mode 100644 index 000000000..700e7721c --- /dev/null +++ b/emtests/test_rounding.out @@ -0,0 +1,140 @@ +Initial rounding mode is FE_TONEAREST +fesetround(FE_TONEAREST) returned 0, fegetround() afterwards returns FE_TONEAREST. Test results: +FE_TONEAREST: round(-4.5)=-5.0 +FE_TONEAREST: round(-3.6)=-4.0 +FE_TONEAREST: round(-3.5)=-4.0 +FE_TONEAREST: round(-3.4)=-3.0 +FE_TONEAREST: round(-2.6)=-3.0 +FE_TONEAREST: round(-2.5)=-3.0 +FE_TONEAREST: round(-2.4)=-2.0 +FE_TONEAREST: round(-1.5)=-2.0 +FE_TONEAREST: round(-0.5)=-1.0 +FE_TONEAREST: round(0.0)=0.0 +FE_TONEAREST: round(0.5)=1.0 +FE_TONEAREST: round(1.4)=1.0 +FE_TONEAREST: round(1.5)=2.0 +FE_TONEAREST: round(1.6)=2.0 +FE_TONEAREST: round(2.5)=3.0 +FE_TONEAREST: round(3.5)=4.0 +FE_TONEAREST: round(4.5)=5.0 +FE_TONEAREST: roundf(-4.5)=-5.0 +FE_TONEAREST: roundf(-3.6)=-4.0 +FE_TONEAREST: roundf(-3.5)=-4.0 +FE_TONEAREST: roundf(-3.4)=-3.0 +FE_TONEAREST: roundf(-2.6)=-3.0 +FE_TONEAREST: roundf(-2.5)=-3.0 +FE_TONEAREST: roundf(-2.4)=-2.0 +FE_TONEAREST: roundf(-1.5)=-2.0 +FE_TONEAREST: roundf(-0.5)=-1.0 +FE_TONEAREST: roundf(0.0)=0.0 +FE_TONEAREST: roundf(0.5)=1.0 +FE_TONEAREST: roundf(1.4)=1.0 +FE_TONEAREST: roundf(1.5)=2.0 +FE_TONEAREST: roundf(1.6)=2.0 +FE_TONEAREST: roundf(2.5)=3.0 +FE_TONEAREST: roundf(3.5)=4.0 +FE_TONEAREST: roundf(4.5)=5.0 +FE_TONEAREST: rint(-4.5)=-4.0 +FE_TONEAREST: rint(-3.6)=-4.0 +FE_TONEAREST: rint(-3.5)=-4.0 +FE_TONEAREST: rint(-3.4)=-3.0 +FE_TONEAREST: rint(-2.6)=-3.0 +FE_TONEAREST: rint(-2.5)=-2.0 +FE_TONEAREST: rint(-2.4)=-2.0 +FE_TONEAREST: rint(-1.5)=-2.0 +FE_TONEAREST: rint(-0.5)=-0.0 +FE_TONEAREST: rint(0.0)=0.0 +FE_TONEAREST: rint(0.5)=0.0 +FE_TONEAREST: rint(1.4)=1.0 +FE_TONEAREST: rint(1.5)=2.0 +FE_TONEAREST: rint(1.6)=2.0 +FE_TONEAREST: rint(2.5)=2.0 +FE_TONEAREST: rint(3.5)=4.0 +FE_TONEAREST: rint(4.5)=4.0 +FE_TONEAREST: rintf(-4.5)=-4.0 +FE_TONEAREST: rintf(-3.6)=-4.0 +FE_TONEAREST: rintf(-3.5)=-4.0 +FE_TONEAREST: rintf(-3.4)=-3.0 +FE_TONEAREST: rintf(-2.6)=-3.0 +FE_TONEAREST: rintf(-2.5)=-2.0 +FE_TONEAREST: rintf(-2.4)=-2.0 +FE_TONEAREST: rintf(-1.5)=-2.0 +FE_TONEAREST: rintf(-0.5)=-0.0 +FE_TONEAREST: rintf(0.0)=0.0 +FE_TONEAREST: rintf(0.5)=0.0 +FE_TONEAREST: rintf(1.4)=1.0 +FE_TONEAREST: rintf(1.5)=2.0 +FE_TONEAREST: rintf(1.6)=2.0 +FE_TONEAREST: rintf(2.5)=2.0 +FE_TONEAREST: rintf(3.5)=4.0 +FE_TONEAREST: rintf(4.5)=4.0 +FE_TONEAREST: lrint(-4.5)=-4 +FE_TONEAREST: lrint(-3.6)=-4 +FE_TONEAREST: lrint(-3.5)=-4 +FE_TONEAREST: lrint(-3.4)=-3 +FE_TONEAREST: lrint(-2.6)=-3 +FE_TONEAREST: lrint(-2.5)=-2 +FE_TONEAREST: lrint(-2.4)=-2 +FE_TONEAREST: lrint(-1.5)=-2 +FE_TONEAREST: lrint(-0.5)=0 +FE_TONEAREST: lrint(0.0)=0 +FE_TONEAREST: lrint(0.5)=0 +FE_TONEAREST: lrint(1.4)=1 +FE_TONEAREST: lrint(1.5)=2 +FE_TONEAREST: lrint(1.6)=2 +FE_TONEAREST: lrint(2.5)=2 +FE_TONEAREST: lrint(3.5)=4 +FE_TONEAREST: lrint(4.5)=4 +FE_TONEAREST: lrintf(-4.5)=-4 +FE_TONEAREST: lrintf(-3.6)=-4 +FE_TONEAREST: lrintf(-3.5)=-4 +FE_TONEAREST: lrintf(-3.4)=-3 +FE_TONEAREST: lrintf(-2.6)=-3 +FE_TONEAREST: lrintf(-2.5)=-2 +FE_TONEAREST: lrintf(-2.4)=-2 +FE_TONEAREST: lrintf(-1.5)=-2 +FE_TONEAREST: lrintf(-0.5)=0 +FE_TONEAREST: lrintf(0.0)=0 +FE_TONEAREST: lrintf(0.5)=0 +FE_TONEAREST: lrintf(1.4)=1 +FE_TONEAREST: lrintf(1.5)=2 +FE_TONEAREST: lrintf(1.6)=2 +FE_TONEAREST: lrintf(2.5)=2 +FE_TONEAREST: lrintf(3.5)=4 +FE_TONEAREST: lrintf(4.5)=4 +FE_TONEAREST: llrint(-4.5)=-4 +FE_TONEAREST: llrint(-3.6)=-4 +FE_TONEAREST: llrint(-3.5)=-4 +FE_TONEAREST: llrint(-3.4)=-3 +FE_TONEAREST: llrint(-2.6)=-3 +FE_TONEAREST: llrint(-2.5)=-2 +FE_TONEAREST: llrint(-2.4)=-2 +FE_TONEAREST: llrint(-1.5)=-2 +FE_TONEAREST: llrint(-0.5)=0 +FE_TONEAREST: llrint(0.0)=0 +FE_TONEAREST: llrint(0.5)=0 +FE_TONEAREST: llrint(1.4)=1 +FE_TONEAREST: llrint(1.5)=2 +FE_TONEAREST: llrint(1.6)=2 +FE_TONEAREST: llrint(2.5)=2 +FE_TONEAREST: llrint(3.5)=4 +FE_TONEAREST: llrint(4.5)=4 +FE_TONEAREST: llrintf(-4.5)=-4 +FE_TONEAREST: llrintf(-3.6)=-4 +FE_TONEAREST: llrintf(-3.5)=-4 +FE_TONEAREST: llrintf(-3.4)=-3 +FE_TONEAREST: llrintf(-2.6)=-3 +FE_TONEAREST: llrintf(-2.5)=-2 +FE_TONEAREST: llrintf(-2.4)=-2 +FE_TONEAREST: llrintf(-1.5)=-2 +FE_TONEAREST: llrintf(-0.5)=0 +FE_TONEAREST: llrintf(0.0)=0 +FE_TONEAREST: llrintf(0.5)=0 +FE_TONEAREST: llrintf(1.4)=1 +FE_TONEAREST: llrintf(1.5)=2 +FE_TONEAREST: llrintf(1.6)=2 +FE_TONEAREST: llrintf(2.5)=2 +FE_TONEAREST: llrintf(3.5)=4 +FE_TONEAREST: llrintf(4.5)=4 +3.141593 = 3.000000 + 0.141593 +-3.141593 = -3.000000 + -0.141593 diff --git a/emtests/test_rounding.wasm b/emtests/test_rounding.wasm new file mode 100644 index 000000000..cea8b61df Binary files /dev/null and b/emtests/test_rounding.wasm differ diff --git a/emtests/test_runtime_stacksave.c b/emtests/test_runtime_stacksave.c new file mode 100644 index 000000000..f366ce520 --- /dev/null +++ b/emtests/test_runtime_stacksave.c @@ -0,0 +1,18 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + int x = EM_ASM_INT({ return stackSave(); }); + int y = EM_ASM_INT({ return stackSave(); }); + EM_ASM_INT({ out($0); }, &x); + EM_ASM_INT({ out($0); }, &y); + assert(x == y); + EM_ASM({ out('success'); }); +} diff --git a/emtests/test_runtime_stacksave.wasm b/emtests/test_runtime_stacksave.wasm new file mode 100644 index 000000000..58cda40c4 Binary files /dev/null and b/emtests/test_runtime_stacksave.wasm differ diff --git a/emtests/test_set_align.c b/emtests/test_set_align.c new file mode 100644 index 000000000..e985d4596 --- /dev/null +++ b/emtests/test_set_align.c @@ -0,0 +1,56 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +volatile char data[16]; + +__attribute__((noinline)) void *get_aligned(int align) +{ + char *ptr = (char*)(((int)(data + 7)) & ~7); // Make 8-byte aligned + ptr += align; // Now 'align' aligned + return (void*)ptr; +} + +int main() +{ + emscripten_align4_double *d4 = (emscripten_align4_double*)get_aligned(4); + *d4 = 17.0; + printf("addr: %d, value: %f\n", ((int)d4) % 8, *d4); + + emscripten_align2_double *d2 = (emscripten_align2_double*)get_aligned(2); + *d2 = 18.0; + printf("addr: %d, value: %f\n", ((int)d2) % 8, *d2); + + emscripten_align1_double *d1 = (emscripten_align1_double*)get_aligned(1); + *d1 = 19.0; + printf("addr: %d, value: %f\n", ((int)d1) % 8, *d1); + + emscripten_align2_float *f2 = (emscripten_align2_float*)get_aligned(2); + *f2 = 20.0; + printf("addr: %d, value: %f\n", ((int)f2) % 4, *f2); + + emscripten_align1_float *f1 = (emscripten_align1_float*)get_aligned(1); + *f1 = 21.0; + printf("addr: %d, value: %f\n", ((int)f1) % 4, *f1); + + emscripten_align2_int *i2 = (emscripten_align2_int*)get_aligned(2); + *i2 = 22; + printf("addr: %d, value: %d\n", ((int)i2) % 4, *i2); + + emscripten_align1_int *i1 = (emscripten_align1_int*)get_aligned(1); + *i1 = 23; + printf("addr: %d, value: %d\n", ((int)i1) % 4, *i1); + + emscripten_align1_short *s1 = (emscripten_align1_short*)get_aligned(1); + *s1 = 24; + printf("addr: %d, value: %d\n", ((int)s1) % 4, (int)*s1); + + return 0; +} + diff --git a/emtests/test_set_align.out b/emtests/test_set_align.out new file mode 100644 index 000000000..55e377b02 --- /dev/null +++ b/emtests/test_set_align.out @@ -0,0 +1,8 @@ +addr: 4, value: 17.000000 +addr: 2, value: 18.000000 +addr: 1, value: 19.000000 +addr: 2, value: 20.000000 +addr: 1, value: 21.000000 +addr: 2, value: 22 +addr: 1, value: 23 +addr: 1, value: 24 diff --git a/emtests/test_set_align.wasm b/emtests/test_set_align.wasm new file mode 100644 index 000000000..49110c510 Binary files /dev/null and b/emtests/test_set_align.wasm differ diff --git a/emtests/test_siglongjmp.c b/emtests/test_siglongjmp.c new file mode 100644 index 000000000..bd6132a98 --- /dev/null +++ b/emtests/test_siglongjmp.c @@ -0,0 +1,28 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +// TODO: Once signals are supported, improve this test to verify preservation of signals state + +int main() { + sigjmp_buf env; + volatile int flag = 0; + if (sigsetjmp(env, 1) == 0) { + // Cannot print anything here, because siglongjmp will + // print a warning in between but only with ASSERTIONS enabled + flag = 1; + siglongjmp(env, 1); + } else { + if (flag) { + puts("Success"); + } + } + return 0; +} + diff --git a/emtests/test_siglongjmp.out b/emtests/test_siglongjmp.out new file mode 100644 index 000000000..35821117c --- /dev/null +++ b/emtests/test_siglongjmp.out @@ -0,0 +1 @@ +Success diff --git a/emtests/test_siglongjmp.wasm b/emtests/test_siglongjmp.wasm new file mode 100644 index 000000000..e02454c04 Binary files /dev/null and b/emtests/test_siglongjmp.wasm differ diff --git a/emtests/test_simd.c b/emtests/test_simd.c new file mode 100644 index 000000000..a8971cee0 --- /dev/null +++ b/emtests/test_simd.c @@ -0,0 +1,73 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +#include + +static inline float32x4 __attribute__((always_inline)) + _mm_set_ps(const float __Z, const float __Y, const float __X, + const float __W) { + return (float32x4) {__W, __X, __Y, __Z}; +} + +static __inline__ float32x4 __attribute__((__always_inline__)) + _mm_setzero_ps(void) { + return (float32x4) {0.0, 0.0, 0.0, 0.0}; +} + +int main(int argc, char **argv) { + float data[8]; + for (int i = 0; i < 32; i++) + data[i] = (1 + i + argc) * (2 + i + argc * argc); // confuse optimizer + { + float32x4 *a = (float32x4 *)&data[0]; + float32x4 *b = (float32x4 *)&data[4]; + float32x4 c, d; + c = *a; + d = *b; + printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + c = c + d; + printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + d = c * d; + printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + c = _mm_setzero_ps(); + printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], + (int)c[3]); + } + { + int32x4 *a = (int32x4 *)&data[0]; + int32x4 *b = (int32x4 *)&data[4]; + int32x4 c, d, e, f; + c = *a; + d = *b; + printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], + d[0], d[1], d[2], d[3]); + e = c + d; + f = c - d; + printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], + f[0], f[1], f[2], f[3]); + e = c & d; + f = c | d; + e = ~c & d; + f = c ^ d; + printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], + f[0], f[1], f[2], f[3]); + } + { + float32x4 c, d, e, f; + c = _mm_set_ps(9.0, 4.0, 0, -9.0); + d = _mm_set_ps(10.0, 14.0, -12, -2.0); + printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + } + + return 0; +} diff --git a/emtests/test_simd.out b/emtests/test_simd.out new file mode 100644 index 000000000..08ca37386 --- /dev/null +++ b/emtests/test_simd.out @@ -0,0 +1,8 @@ +1floats! 6, 12, 20, 30 42, 56, 72, 90 +2floats! 48, 68, 92, 120 42, 56, 72, 90 +3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800 +zeros 0, 0, 0, 0 +4ints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736 +5ints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056 +5intops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096 +6floats! -9, 0, 4, 9 -2, -12, 14, 10 diff --git a/emtests/test_simd10.c b/emtests/test_simd10.c new file mode 100644 index 000000000..9f1b3a0c9 --- /dev/null +++ b/emtests/test_simd10.c @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +std::string tostr(__m128 m) +{ + unsigned int u[4]; + _mm_store_ps((float*)u, m); + char str[256]; + sprintf(str, "[%X,%X,%X,%X]", u[3], u[2], u[1], u[0]); + return str; +} + +int main() +{ + unsigned int u[4] = { 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU }; + __m128 m1 = _mm_load_ps((float*)&u); + printf("%s\n", tostr(m1).c_str()); +} diff --git a/emtests/test_simd10.out b/emtests/test_simd10.out new file mode 100644 index 000000000..2869fe0da --- /dev/null +++ b/emtests/test_simd10.out @@ -0,0 +1 @@ +[FFFFFFFF,FFFFFFFF,FFFFFFFF,FFFFFFFF] \ No newline at end of file diff --git a/emtests/test_simd11.c b/emtests/test_simd11.c new file mode 100644 index 000000000..4b9683fc4 --- /dev/null +++ b/emtests/test_simd11.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +bool always_true() { return time(NULL) != 0; } // This function always returns true, but the compiler should not know this. + +int main() +{ + int a = _mm_movemask_ps(_mm_set_epi32(-1, -1, -1, -1)); + printf("%d\n", a); +} diff --git a/emtests/test_simd11.out b/emtests/test_simd11.out new file mode 100644 index 000000000..3f10ffe7a --- /dev/null +++ b/emtests/test_simd11.out @@ -0,0 +1 @@ +15 \ No newline at end of file diff --git a/emtests/test_simd12.c b/emtests/test_simd12.c new file mode 100644 index 000000000..b397209b0 --- /dev/null +++ b/emtests/test_simd12.c @@ -0,0 +1,107 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +volatile __m128 zero; +volatile __m128 one; +volatile __m128 nan_; + +int main() { + zero = _mm_set1_ps(0); + one = _mm_set1_ps(1); + nan_ = _mm_set1_ps(__builtin_nan("")); + + assert(_mm_comieq_ss(zero, zero) == 1); + assert(_mm_comieq_ss(zero, one) == 0); + assert(_mm_comieq_ss(one, zero) == 0); + assert(_mm_comieq_ss(zero, nan_) == 1); + assert(_mm_comieq_ss(nan_, zero) == 1); + assert(_mm_comieq_ss(nan_, nan_) == 1); + + assert(_mm_comige_ss(zero, zero) == 1); + assert(_mm_comige_ss(zero, one) == 0); + assert(_mm_comige_ss(one, zero) == 1); + assert(_mm_comige_ss(zero, nan_) == 0); + assert(_mm_comige_ss(nan_, zero) == 0); + assert(_mm_comige_ss(nan_, nan_) == 0); + + assert(_mm_comigt_ss(zero, zero) == 0); + assert(_mm_comigt_ss(zero, one) == 0); + assert(_mm_comigt_ss(one, zero) == 1); + assert(_mm_comigt_ss(zero, nan_) == 0); + assert(_mm_comigt_ss(nan_, zero) == 0); + assert(_mm_comigt_ss(nan_, nan_) == 0); + + assert(_mm_comile_ss(zero, zero) == 1); + assert(_mm_comile_ss(zero, one) == 1); + assert(_mm_comile_ss(one, zero) == 0); + assert(_mm_comile_ss(zero, nan_) == 1); + assert(_mm_comile_ss(nan_, zero) == 1); + assert(_mm_comile_ss(nan_, nan_) == 1); + + assert(_mm_comilt_ss(zero, zero) == 0); + assert(_mm_comilt_ss(zero, one) == 1); + assert(_mm_comilt_ss(one, zero) == 0); + assert(_mm_comilt_ss(zero, nan_) == 1); + assert(_mm_comilt_ss(nan_, zero) == 1); + assert(_mm_comilt_ss(nan_, nan_) == 1); + + assert(_mm_comineq_ss(zero, zero) == 0); + assert(_mm_comineq_ss(zero, one) == 1); + assert(_mm_comineq_ss(one, zero) == 1); + assert(_mm_comineq_ss(zero, nan_) == 0); + assert(_mm_comineq_ss(nan_, zero) == 0); + assert(_mm_comineq_ss(nan_, nan_) == 0); + + assert(_mm_ucomieq_ss(zero, zero) == 1); + assert(_mm_ucomieq_ss(zero, one) == 0); + assert(_mm_ucomieq_ss(one, zero) == 0); + assert(_mm_ucomieq_ss(zero, nan_) == 1); + assert(_mm_ucomieq_ss(nan_, zero) == 1); + assert(_mm_ucomieq_ss(nan_, nan_) == 1); + + assert(_mm_ucomige_ss(zero, zero) == 1); + assert(_mm_ucomige_ss(zero, one) == 0); + assert(_mm_ucomige_ss(one, zero) == 1); + assert(_mm_ucomige_ss(zero, nan_) == 0); + assert(_mm_ucomige_ss(nan_, zero) == 0); + assert(_mm_ucomige_ss(nan_, nan_) == 0); + + assert(_mm_ucomigt_ss(zero, zero) == 0); + assert(_mm_ucomigt_ss(zero, one) == 0); + assert(_mm_ucomigt_ss(one, zero) == 1); + assert(_mm_ucomigt_ss(zero, nan_) == 0); + assert(_mm_ucomigt_ss(nan_, zero) == 0); + assert(_mm_ucomigt_ss(nan_, nan_) == 0); + + assert(_mm_ucomile_ss(zero, zero) == 1); + assert(_mm_ucomile_ss(zero, one) == 1); + assert(_mm_ucomile_ss(one, zero) == 0); + assert(_mm_ucomile_ss(zero, nan_) == 1); + assert(_mm_ucomile_ss(nan_, zero) == 1); + assert(_mm_ucomile_ss(nan_, nan_) == 1); + + assert(_mm_ucomilt_ss(zero, zero) == 0); + assert(_mm_ucomilt_ss(zero, one) == 1); + assert(_mm_ucomilt_ss(one, zero) == 0); + assert(_mm_ucomilt_ss(zero, nan_) == 1); + assert(_mm_ucomilt_ss(nan_, zero) == 1); + assert(_mm_ucomilt_ss(nan_, nan_) == 1); + + assert(_mm_ucomineq_ss(zero, zero) == 0); + assert(_mm_ucomineq_ss(zero, one) == 1); + assert(_mm_ucomineq_ss(one, zero) == 1); + assert(_mm_ucomineq_ss(zero, nan_) == 0); + assert(_mm_ucomineq_ss(nan_, zero) == 0); + assert(_mm_ucomineq_ss(nan_, nan_) == 0); + + printf("DONE!\n"); +} diff --git a/emtests/test_simd12.out b/emtests/test_simd12.out new file mode 100644 index 000000000..84ce3dcb4 --- /dev/null +++ b/emtests/test_simd12.out @@ -0,0 +1 @@ +DONE! \ No newline at end of file diff --git a/emtests/test_simd13.c b/emtests/test_simd13.c new file mode 100644 index 000000000..f2bb1bf46 --- /dev/null +++ b/emtests/test_simd13.c @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +class float4 +{ +public: + float4(){} + float4(__m128 in) { m128 = in; } + operator __m128() { return m128; } + operator const __m128() const { return m128; } + __m128 m128; +}; + +int main() +{ + float4 v = _mm_set_ps(3, 2, 1, 0); + float4 w = _mm_shuffle_ps(v, v, _MM_SHUFFLE(3,3,3,3)); + printf("%d\n", (int)_mm_cvtss_f32(w)); +} diff --git a/emtests/test_simd13.out b/emtests/test_simd13.out new file mode 100644 index 000000000..00750edc0 --- /dev/null +++ b/emtests/test_simd13.out @@ -0,0 +1 @@ +3 diff --git a/emtests/test_simd14.c b/emtests/test_simd14.c new file mode 100644 index 000000000..5b0af307f --- /dev/null +++ b/emtests/test_simd14.c @@ -0,0 +1,23 @@ +/* + * Copyright 2015 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +void __attribute__((noinline)) foo(__m128 vec, __m128 &outLength) +{ + outLength = vec; +} + +int main() +{ + puts("before"); + __m128 x; + foo(_mm_set1_ps(1.f), x); + printf("%.2f", x[0]); +} + diff --git a/emtests/test_simd14.out b/emtests/test_simd14.out new file mode 100644 index 000000000..3ae59d3c8 --- /dev/null +++ b/emtests/test_simd14.out @@ -0,0 +1,2 @@ +before +1.00 diff --git a/emtests/test_simd15.c b/emtests/test_simd15.c new file mode 100644 index 000000000..e8ec2b99f --- /dev/null +++ b/emtests/test_simd15.c @@ -0,0 +1,50 @@ +/* + * Copyright 2015 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +__m128i set_64x2(int64_t a, int64_t b) { union { int64_t x[2]; __m128i m; } u; u.x[0] = a; u.x[1] = b; return u.m; } +int64_t get_64x2_lo(__m128i m) { union { int64_t x[2]; __m128i m; } u; u.m = m; return u.x[0]; } +int64_t get_64x2_hi(__m128i m) { union { int64_t x[2]; __m128i m; } u; u.m = m; return u.x[1]; } + +void test1() +{ + __m128i a = set_64x2(1, 2); + __m128i b = set_64x2(3, 4); + __m128i c = _mm_add_epi64(a, b); + printf("%lld %lld\n", get_64x2_lo(c), get_64x2_hi(c)); +} + +typedef int m128i __attribute__((__vector_size__(16))); + +m128i __attribute__((noinline)) add_epi16(m128i a, m128i b) +{ + union { + signed short x[8]; + m128i m; + } src, src2, dst; + src.m = a; + src2.m = b; + dst.x[0] = src.x[0] + src2.x[0]; + return dst.m; +} + +void test2() +{ + m128i a = (m128i){ 1, 2, 3, 4 }; + m128i b = add_epi16(a, a); + printf("%d\n", b[0]); +} + + +int main() { + test1(); + test2(); +} + diff --git a/emtests/test_simd15.out b/emtests/test_simd15.out new file mode 100644 index 000000000..e92780248 --- /dev/null +++ b/emtests/test_simd15.out @@ -0,0 +1,2 @@ +4 6 +2 diff --git a/emtests/test_simd16.c b/emtests/test_simd16.c new file mode 100644 index 000000000..6ffde21de --- /dev/null +++ b/emtests/test_simd16.c @@ -0,0 +1,34 @@ +/* + * Copyright 2015 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +class vec +{ +public: + __m128 v; + + void mul(float s) + { + __m128 vs = _mm_load_ss(&s); + // __m128 vs = _mm_set_ss(s); // _mm_set_ss(s) instead of _mm_load_ss(&s) avoids the problem somehow..? + v = _mm_mul_ps(v, vs); + } +}; + +int main() +{ + vec v; + v.v = _mm_set_ps(8,8,8,8); + v.mul(0.5f); + + float f[4]; + _mm_storeu_ps(f, v.v); + printf("%f %f %f %f\n", f[0], f[1], f[2], f[3]); +} + diff --git a/emtests/test_simd16.out b/emtests/test_simd16.out new file mode 100644 index 000000000..6917aef1c --- /dev/null +++ b/emtests/test_simd16.out @@ -0,0 +1 @@ +4.000000 0.000000 0.000000 0.000000 diff --git a/emtests/test_simd2.c b/emtests/test_simd2.c new file mode 100644 index 000000000..d8690573f --- /dev/null +++ b/emtests/test_simd2.c @@ -0,0 +1,40 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef float __m128 __attribute__((__vector_size__(16))); + +static inline __m128 __attribute__((always_inline)) + _mm_set_ps(const float __Z, const float __Y, const float __X, + const float __W) { + return (__m128) {__W, __X, __Y, __Z}; +} + +static inline void __attribute__((always_inline)) + _mm_store_ps(float *__P, __m128 __A) { + *(__m128 *)__P = __A; +} + +static inline __m128 __attribute__((always_inline)) + _mm_add_ps(__m128 __A, __m128 __B) { + return __A + __B; +} + +int main(int argc, char **argv) { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0); + __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0); + __m128 v3 = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v3); + + for (int i = 0; i < 4; i++) { + printf("%f\n", ar[i]); + } + + return 0; +} diff --git a/emtests/test_simd2.out b/emtests/test_simd2.out new file mode 100644 index 000000000..4b01ec862 --- /dev/null +++ b/emtests/test_simd2.out @@ -0,0 +1,4 @@ +-8.000000 +2.500000 +7.000000 +16.000000 diff --git a/emtests/test_simd3.c b/emtests/test_simd3.c new file mode 100644 index 000000000..8cf65ff77 --- /dev/null +++ b/emtests/test_simd3.c @@ -0,0 +1,496 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include + +using namespace std; + +void testSetPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0); + _mm_store_ps(ar, v); + assert(ar[0] == 4.0); + assert(ar[1] == 3.0); + assert(ar[2] == 2.0); + assert(ar[3] == 1.0); +} + +void testSet1Ps() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_set1_ps(5.5); + _mm_store_ps(ar, v); + assert(ar[0] == 5.5); + assert(ar[1] == 5.5); + assert(ar[2] == 5.5); + assert(ar[3] == 5.5); +} + +void testSetZeroPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_setzero_ps(); + _mm_store_ps(ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testSetEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_set_epi32(5, 7, 126, 381); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 381); + assert(ar[1] == 126); + assert(ar[2] == 7); + assert(ar[3] == 5); + v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x12345678); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xaaaaaaaa); + assert(ar[3] == 0x55555555); +} + +void testSet1Epi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_set1_epi32(-5); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == -5); + assert(ar[1] == -5); + assert(ar[2] == -5); + assert(ar[3] == -5); +} + +void testSetZeroSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_setzero_si128(); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testBitCasts() { + int32_t __attribute__((__aligned__(16))) ar1[4]; + float __attribute__((__aligned__(16))) ar2[4]; + __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000); + __m128 v2 = _mm_castsi128_ps(v1); + _mm_store_ps(ar2, v2); + assert(ar2[0] == 4.0); + assert(ar2[1] == 3.0); + assert(ar2[2] == 2.0); + assert(ar2[3] == 1.0); + v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0); + v1 = _mm_castps_si128(v2); + _mm_store_si128((__m128i *)ar1, v1); + assert(ar1[0] == 0x41000000); + assert(ar1[1] == 0x40e00000); + assert(ar1[2] == 0x40c00000); + assert(ar1[3] == 0x40a00000); + float w = 0; + float z = -278.3; + float y = 5.2; + float x = -987654321; + v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x)); + _mm_store_ps(ar2, _mm_castsi128_ps(v1)); + assert(ar2[0] == x); + assert(ar2[1] == y); + assert(ar2[2] == z); + assert(ar2[3] == w); + /* + std::bitset bits1x(*reinterpret_cast(&(ar2[0]))); + std::bitset bits1y(*reinterpret_cast(&(ar2[1]))); + std::bitset bits1z(*reinterpret_cast(&(ar2[2]))); + std::bitset bits1w(*reinterpret_cast(&(ar2[3]))); + std::bitset bits2x(*reinterpret_cast(&x)); + std::bitset bits2y(*reinterpret_cast(&y)); + std::bitset bits2z(*reinterpret_cast(&z)); + std::bitset bits2w(*reinterpret_cast(&w)); + assert(bits1x == bits2x); + assert(bits1y == bits2y); + assert(bits1z == bits2z); + assert(bits1w == bits2w); + */ + v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa)); + _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2)); + assert(ar1[0] == 0xaaaaaaaa); + assert(ar1[1] == 0x5555cccc); + assert(ar1[2] == 0); + assert(ar1[3] == 0xffffffff); +} + +void testConversions() { + int32_t __attribute__((__aligned__(16))) ar1[4]; + float __attribute__((__aligned__(16))) ar2[4]; + __m128i v1 = _mm_set_epi32(0, -3, -517, 256); + __m128 v2 = _mm_cvtepi32_ps(v1); + _mm_store_ps(ar2, v2); + assert(ar2[0] == 256.0); + assert(ar2[1] == -517.0); + assert(ar2[2] == -3.0); + assert(ar2[3] == 0); + v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0); + v1 = _mm_cvtps_epi32(v2); + _mm_store_si128((__m128i *)ar1, v1); + assert(ar1[0] == -8); + assert(ar1[1] == 7); + assert(ar1[2] == 6); + assert(ar1[3] == 5); +} + +void testMoveMaskPs() { + __m128 v = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + int mask = _mm_movemask_ps(v); + assert(mask == 13); +} + +void testAddPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 41.0); + assert(ar[1] == 32.0); + assert(ar[2] == 23.0); + assert(ar[3] == 14.0); +} + +void testSubPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_sub_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == -39.0); + assert(ar[1] == -28.0); + assert(ar[2] == -17.0); + assert(ar[3] == -6.0); +} + +void testMulPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_mul_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 40.0); + assert(ar[1] == 60.0); + assert(ar[2] == 60.0); + assert(ar[3] == 40.0); +} + +void testDivPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0); + __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5); + __m128 v = _mm_div_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 2.0); + assert(ar[1] == 8.0); + assert(ar[2] == 3.0); + assert(ar[3] == 2.0); +} + +void testMinPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); + __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0); + __m128 v = _mm_min_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 0.0); + assert(ar[1] == 30.0); + assert(ar[2] == 1.0); + assert(ar[3] == -20.0); +} + +void testMaxPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); + __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0); + __m128 v = _mm_max_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 1.0); + assert(ar[1] == 55.0); + assert(ar[2] == 10.0); + assert(ar[3] == 2.5); +} + +void testSqrtPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0); + __m128 v = _mm_sqrt_ps(v1); + _mm_store_ps(ar, v); + assert(ar[0] == 1.0); + assert(ar[1] == 2.0); + assert(ar[2] == 3.0); + assert(ar[3] == 4.0); +} + +void testCmpLtPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmplt_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0xffffffff); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0xffffffff); + assert(_mm_movemask_ps(v) == 9); +} + +void testCmpLePs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmple_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0xffffffff); + assert(ar[1] == 0); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); + assert(_mm_movemask_ps(v) == 13); +} + +void testCmpEqPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpeq_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 4); +} + +void testCmpGePs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpge_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 6); +} + +void testCmpGtPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpgt_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 2); +} + +void testAndPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(425, -501, -32, 68); + __m128 v2 = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + __m128 v = _mm_and_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 68); + assert(ar[1] == 0); + assert(ar[2] == -501); + assert(ar[3] == 425); + int32_t __attribute__((__aligned__(16))) ar2[4]; + v1 = _mm_castsi128_ps( + _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); + v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + v = _mm_and_ps(v1, v2); + _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); + assert(ar2[0] == 0); + assert(ar2[1] == 0); + assert(ar2[2] == 0); + assert(ar2[3] == 0); +} + +void testAndNotPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(425, -501, -32, 68); + __m128 v2 = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + __m128 v = _mm_andnot_ps(v2, v1); + _mm_store_ps(ar, v); + assert(ar[0] == 0); + assert(ar[1] == -32); + assert(ar[2] == 0); + assert(ar[3] == 0); + int32_t __attribute__((__aligned__(16))) ar2[4]; + v1 = _mm_castsi128_ps( + _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); + v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + v = _mm_andnot_ps(v1, v2); + _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); + assert(ar2[0] == 0x55555555); + assert(ar2[1] == 0x55555555); + assert(ar2[2] == 0x55555555); + assert(ar2[3] == 0x55555555); +} + +void testOrPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = + _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); + __m128 v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + __m128 v = _mm_or_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testXorPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = + _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); + __m128 v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + __m128 v = _mm_xor_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xaaaaaaaa); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testAndSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_and_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testAndNotSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_andnot_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0x55555555); + assert(ar[2] == 0x55555555); + assert(ar[3] == 0x55555555); +} + +void testOrSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_or_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testXorSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_xor_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xaaaaaaaa); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testAddEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(4, 3, 2, 1); + __m128i v2 = _mm_set_epi32(10, 20, 30, 40); + __m128i v = _mm_add_epi32(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 41); + assert(ar[1] == 32); + assert(ar[2] == 23); + assert(ar[3] == 14); +} + +void testSubEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(4, 3, 2, 1); + __m128i v2 = _mm_set_epi32(10, 20, 30, 40); + __m128i v = _mm_sub_epi32(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == -39); + assert(ar[1] == -28); + assert(ar[2] == -17); + assert(ar[3] == -6); +} + +int main(int argc, char **argv) { + testSetPs(); + testSet1Ps(); + testSetZeroPs(); + testSetEpi32(); + testSet1Epi32(); + testSetZeroSi128(); + testBitCasts(); + testConversions(); + testMoveMaskPs(); + testAddPs(); + testSubPs(); + testMulPs(); + testDivPs(); + testMaxPs(); + testMinPs(); + testSqrtPs(); + testCmpLtPs(); + testCmpLePs(); + testCmpEqPs(); + testCmpGePs(); + testCmpGtPs(); + testAndPs(); + testAndNotPs(); + testOrPs(); + testXorPs(); + testAndSi128(); + testAndNotSi128(); + testOrSi128(); + testXorSi128(); + testAddEpi32(); + testSubEpi32(); + printf("DONE"); + return 0; +} diff --git a/emtests/test_simd3.out b/emtests/test_simd3.out new file mode 100644 index 000000000..096264973 --- /dev/null +++ b/emtests/test_simd3.out @@ -0,0 +1 @@ +DONE \ No newline at end of file diff --git a/emtests/test_simd4.c b/emtests/test_simd4.c new file mode 100644 index 000000000..79207e835 --- /dev/null +++ b/emtests/test_simd4.c @@ -0,0 +1,40 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +float simdAverage(float *src, int len) { + __m128 sumx4 = _mm_setzero_ps(); + for (int i = 0; i < len; i += 4) { + __m128 v = _mm_load_ps(src); + sumx4 = _mm_add_ps(sumx4, v); + src += 4; + } + float sumx4_mem[4]; + float *sumx4_ptr = sumx4_mem; + _mm_store_ps(sumx4_ptr, sumx4); + return (sumx4_mem[0] + sumx4_mem[1] + + sumx4_mem[2] + sumx4_mem[3])/len; +} + +void initArray(float *src, int len) { + for (int i = 0; i < len; ++i) { + src[i] = 0.1 * i; + } +} + +int main() { + const int len = 100000; + float src[len]; + float result = 0.0; + + initArray(src, len); + + result = simdAverage(src, len); + printf("averagex4 result: %.1f\n", result); +} \ No newline at end of file diff --git a/emtests/test_simd4.out b/emtests/test_simd4.out new file mode 100644 index 000000000..994497724 --- /dev/null +++ b/emtests/test_simd4.out @@ -0,0 +1 @@ +averagex4 result: 4999.9 \ No newline at end of file diff --git a/emtests/test_simd5.c b/emtests/test_simd5.c new file mode 100644 index 000000000..a064022dd --- /dev/null +++ b/emtests/test_simd5.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef float float32x4 __attribute__((__vector_size__(16))); + +int main(int argc, char **argv) { + float32x4 a = {1.0, 2.0, 3.0, 4.0}; + float32x4 b = {5.0, 6.0, 7.0, 8.0}; + float32x4 r = __builtin_shufflevector(a, b, 3, 1, 2, 0); + printf("%.1f %.1f %.1f %.1f\n", r[0], r[1], r[2], r[3]); + r = __builtin_shufflevector(a, b, 7, 5, 6, 4); + printf("%.1f %.1f %.1f %.1f\n", r[0], r[1], r[2], r[3]); + r = __builtin_shufflevector(a, b, 1, 2, 5, 4); + printf("%.1f %.1f %.1f %.1f\n", r[0], r[1], r[2], r[3]); + r = __builtin_shufflevector(a, b, 5, 4, 1, 2); + printf("%.1f %.1f %.1f %.1f\n", r[0], r[1], r[2], r[3]); + r = __builtin_shufflevector(a, b, 4, 1, 0, 5); + printf("%.1f %.1f %.1f %.1f\n", r[0], r[1], r[2], r[3]); + r = __builtin_shufflevector(a, b, 0, 7, 2, 3); + printf("%.1f %.1f %.1f %.1f\n", r[0], r[1], r[2], r[3]); + return 0; +} \ No newline at end of file diff --git a/emtests/test_simd5.out b/emtests/test_simd5.out new file mode 100644 index 000000000..738295bc2 --- /dev/null +++ b/emtests/test_simd5.out @@ -0,0 +1,6 @@ +4.0 2.0 3.0 1.0 +8.0 6.0 7.0 5.0 +2.0 3.0 6.0 5.0 +6.0 5.0 2.0 3.0 +5.0 2.0 1.0 6.0 +1.0 8.0 3.0 4.0 \ No newline at end of file diff --git a/emtests/test_simd6.c b/emtests/test_simd6.c new file mode 100644 index 000000000..ffd569b24 --- /dev/null +++ b/emtests/test_simd6.c @@ -0,0 +1,73 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +/* + * x86 _mm_max_ps and _mm_min_ps have defined semantics or NaN and -0.0. Ensure + * that we implement them properly. + */ + +volatile __m128 negzero; +volatile __m128 zero; +volatile __m128 nan_; +volatile __m128 one; + +int main() { + negzero = _mm_set1_ps(-0.0); + zero = _mm_set1_ps(0.0); + one = _mm_set1_ps(1.0); + nan_ = _mm_set1_ps(__builtin_nan("")); + + __m128 expected, result; + + result = _mm_max_ps(negzero, zero); + expected = zero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_max_ps(zero, negzero); + expected = negzero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_max_ps(nan_, zero); + expected = zero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_max_ps(zero, nan_); + expected = nan_; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_max_ps(zero, one); + expected = one; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_min_ps(negzero, zero); + expected = zero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_min_ps(zero, negzero); + expected = negzero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_min_ps(nan_, zero); + expected = zero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_min_ps(zero, nan_); + expected = nan_; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + result = _mm_min_ps(zero, one); + expected = zero; + assert(memcmp(&result, &expected, sizeof(__m128)) == 0); + + printf("DONE"); + return 0; +} diff --git a/emtests/test_simd6.out b/emtests/test_simd6.out new file mode 100644 index 000000000..096264973 --- /dev/null +++ b/emtests/test_simd6.out @@ -0,0 +1 @@ +DONE \ No newline at end of file diff --git a/emtests/test_simd7.c b/emtests/test_simd7.c new file mode 100644 index 000000000..4bded7c4d --- /dev/null +++ b/emtests/test_simd7.c @@ -0,0 +1,13 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + printf("%d\n", _mm_movemask_ps(_mm_set_ps(0.f, 0.f, 0.f, -0.f))); +} diff --git a/emtests/test_simd7.out b/emtests/test_simd7.out new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/emtests/test_simd7.out @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/emtests/test_simd8.c b/emtests/test_simd8.c new file mode 100644 index 000000000..e705bc6b6 --- /dev/null +++ b/emtests/test_simd8.c @@ -0,0 +1,24 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +char buffer[21]; + +int main() { + _mm_storeu_ps((float*)&buffer[1], (__m128){0.1, 2.3, 4.5, 6.7}); + __m128 y = _mm_loadu_ps((float*)&buffer[5]); + + float __attribute__((__aligned__(16))) ar[4]; + *(__m128 *)&ar = y; + for (int i = 0; i < 4; i++) { + printf("%f\n", ar[i]); + } + + return 0; +} diff --git a/emtests/test_simd8.out b/emtests/test_simd8.out new file mode 100644 index 000000000..7d833d097 --- /dev/null +++ b/emtests/test_simd8.out @@ -0,0 +1,4 @@ +2.300000 +4.500000 +6.700000 +0.000000 diff --git a/emtests/test_simd9.c b/emtests/test_simd9.c new file mode 100644 index 000000000..b01a6df6d --- /dev/null +++ b/emtests/test_simd9.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +bool always_true() { return time(NULL) != 0; } // This function always returns true, but the compiler should not know this. + +int main() +{ + __m128 a = always_true() ? _mm_set1_ps(0.f) : _mm_set1_ps(2.f); + printf("%d %d %d %d\n", (int)a[0], (int)a[1], (int)a[2], (int)a[3]); +} diff --git a/emtests/test_simd9.out b/emtests/test_simd9.out new file mode 100644 index 000000000..7abb2cab3 --- /dev/null +++ b/emtests/test_simd9.out @@ -0,0 +1 @@ +0 0 0 0 \ No newline at end of file diff --git a/emtests/test_simd_dyncall.cpp b/emtests/test_simd_dyncall.cpp new file mode 100644 index 000000000..2137c69ee --- /dev/null +++ b/emtests/test_simd_dyncall.cpp @@ -0,0 +1,43 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include + +__m128 getSomeSIMD() { + union { __m128 m; float val[4]; } u; + u.val[0] = 1; + u.val[1] = 3.14159; + u.val[2] = -124234234.5; + u.val[3] = 99; + return u.m; +} + +__attribute__((noinline)) std::string to_str(__m128 m) +{ + union { __m128 m; float val[4]; } u; + u.m = m; + char str[256]; + sprintf(str, "[%f,%f,%f,%f]", u.val[3], u.val[2], u.val[1], u.val[0]); + printf("%s\n", str); + return "?"; +} + +int main() +{ + // part 1 + __m128 m1 = _mm_set1_ps(1.f); + __m128 m2 = _mm_set1_ps(2.f); + __m128 ret = _mm_add_ps(m1, m2); + to_str(m1).c_str(), to_str(m2).c_str(), to_str(ret).c_str(); + + // part 2 + typedef __m128 (*type)(); + volatile type ptr; + ptr = &getSomeSIMD; + to_str(ptr()); +} + diff --git a/emtests/test_simd_dyncall.txt b/emtests/test_simd_dyncall.txt new file mode 100644 index 000000000..267a55b33 --- /dev/null +++ b/emtests/test_simd_dyncall.txt @@ -0,0 +1,4 @@ +[1.000000,1.000000,1.000000,1.000000] +[2.000000,2.000000,2.000000,2.000000] +[3.000000,3.000000,3.000000,3.000000] +[99.000000,-124234232.000000,3.141590,1.000000] diff --git a/emtests/test_simd_float32x4.c b/emtests/test_simd_float32x4.c new file mode 100644 index 000000000..458297804 --- /dev/null +++ b/emtests/test_simd_float32x4.c @@ -0,0 +1,127 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include + +void printFloat(float n) { + if (isnan(n)) { + printf("nan"); + } else { + printf("%f", n); + } +} + +void dump(const char *name, float32x4 vec) +{ + printf("%s: ", name); + printFloat(emscripten_float32x4_extractLane(vec, 0)); + printf(" "); + printFloat(emscripten_float32x4_extractLane(vec, 1)); + printf(" "); + printFloat(emscripten_float32x4_extractLane(vec, 2)); + printf(" "); + printFloat(emscripten_float32x4_extractLane(vec, 3)); + printf("\n"); +} +#define DUMP(V) dump(#V, (V)) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + float32x4 v = emscripten_float32x4_set(-1.f, 0.f, 1.f, 3.5f); + DUMP(v); + float32x4 w = emscripten_float32x4_splat(2.f); + DUMP(w); + DUMP(emscripten_float32x4_add(v, w)); + DUMP(emscripten_float32x4_sub(v, w)); + DUMP(emscripten_float32x4_mul(v, w)); + DUMP(emscripten_float32x4_div(v, w)); + DUMP(emscripten_float32x4_max(v, w)); + DUMP(emscripten_float32x4_min(v, w)); + DUMP(emscripten_float32x4_maxNum(v, w)); + DUMP(emscripten_float32x4_minNum(v, w)); + DUMP(emscripten_float32x4_neg(v)); + DUMP(emscripten_float32x4_sqrt(v)); + float32x4 rcp = emscripten_float32x4_reciprocalApproximation(v); + assert(fabs(emscripten_float32x4_extractLane(rcp, 0) - 1.0 / emscripten_float32x4_extractLane(v, 0)) < 0.1); + assert(isinf(emscripten_float32x4_extractLane(rcp, 1))); + assert(fabs(emscripten_float32x4_extractLane(rcp, 2) - 1.0 / emscripten_float32x4_extractLane(v, 2)) < 0.1); + assert(fabs(emscripten_float32x4_extractLane(rcp, 3) - 1.0 / emscripten_float32x4_extractLane(v, 3)) < 0.1); + float32x4 rcpSqrt = emscripten_float32x4_reciprocalSqrtApproximation(v); + assert(isnan(emscripten_float32x4_extractLane(rcpSqrt, 0))); + assert(isinf(emscripten_float32x4_extractLane(rcpSqrt, 1))); + assert(fabs(emscripten_float32x4_extractLane(rcpSqrt, 2) - 1.0 / sqrt(emscripten_float32x4_extractLane(v, 2))) < 0.1); + assert(fabs(emscripten_float32x4_extractLane(rcpSqrt, 3) - 1.0 / sqrt(emscripten_float32x4_extractLane(v, 3))) < 0.1); + DUMP(emscripten_float32x4_abs(v)); + DUMP(emscripten_float32x4_and(v, w)); + DUMP(emscripten_float32x4_xor(v, w)); + DUMP(emscripten_float32x4_or(v, w)); + DUMP(emscripten_float32x4_not(v)); + DUMP(emscripten_float32x4_lessThan(v, w)); + DUMP(emscripten_float32x4_lessThanOrEqual(v, w)); + DUMP(emscripten_float32x4_greaterThan(v, w)); + DUMP(emscripten_float32x4_greaterThanOrEqual(v, w)); + DUMP(emscripten_float32x4_equal(v, w)); + DUMP(emscripten_float32x4_notEqual(v, w)); + bool32x4 b = emscripten_int32x4_set(0, -1, 0, -1); + DUMP(emscripten_float32x4_select(b, v, w)); + DUMP(emscripten_float32x4_replaceLane(v, 0, 9.f)); + DUMP(emscripten_float32x4_replaceLane(v, 1, -3.f)); + DUMP(emscripten_float32x4_replaceLane(v, 2, 0.f)); + DUMP(emscripten_float32x4_replaceLane(v, 3, -0.f)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store(bytes, v); + DUMPBYTES("emscripten_float32x4_store", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store1(bytes, v); + DUMPBYTES("emscripten_float32x4_store1", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store2(bytes, v); + DUMPBYTES("emscripten_float32x4_store2", bytes); + + emscripten_float32x4_store(bytes, v); + DUMP(emscripten_float32x4_load(bytes)); + DUMP(emscripten_float32x4_load1(bytes)); + DUMP(emscripten_float32x4_load2(bytes)); + // TODO: emscripten_float32x4_fromFloat64x2Bits + // TODO: emscripten_float32x4_fromInt32x4Bits + // TODO: emscripten_float32x4_fromUint32x4Bits + // TODO: emscripten_float32x4_fromInt16x8Bits + // TODO: emscripten_float32x4_fromUint16x8Bits + // TODO: emscripten_float32x4_fromInt8x16Bits + // TODO: emscripten_float32x4_fromUint8x16Bits + // TODO: emscripten_float32x4_fromInt32x4 + // TODO: emscripten_float32x4_fromUint32x4 + DUMP(emscripten_float32x4_swizzle(v, 0, 1, 2, 3)); + DUMP(emscripten_float32x4_swizzle(v, 3, 2, 1, 0)); + DUMP(emscripten_float32x4_swizzle(v, 0, 0, 0, 0)); + DUMP(emscripten_float32x4_swizzle(v, 0, 3, 0, 3)); + DUMP(emscripten_float32x4_swizzle(v, 3, 3, 3, 3)); + float32x4 z = emscripten_float32x4_set(-5.f, 20.f, 14.f, 9.f); + DUMP(z); + DUMP(emscripten_float32x4_shuffle(v, z, 0, 0, 0, 0)); + DUMP(emscripten_float32x4_shuffle(v, z, 4, 4, 4, 4)); + DUMP(emscripten_float32x4_shuffle(v, z, 7, 7, 7, 7)); + DUMP(emscripten_float32x4_shuffle(v, z, 0, 2, 4, 6)); + DUMP(emscripten_float32x4_shuffle(v, z, 7, 0, 3, 5)); + + printf("Done!\n"); +} diff --git a/emtests/test_simd_float32x4.out b/emtests/test_simd_float32x4.out new file mode 100644 index 000000000..d2143c6f5 --- /dev/null +++ b/emtests/test_simd_float32x4.out @@ -0,0 +1,46 @@ +v: -1.000000 0.000000 1.000000 3.500000 +w: 2.000000 2.000000 2.000000 2.000000 +emscripten_float32x4_add(v, w): 1.000000 2.000000 3.000000 5.500000 +emscripten_float32x4_sub(v, w): -3.000000 -2.000000 -1.000000 1.500000 +emscripten_float32x4_mul(v, w): -2.000000 0.000000 2.000000 7.000000 +emscripten_float32x4_div(v, w): -0.500000 0.000000 0.500000 1.750000 +emscripten_float32x4_max(v, w): 2.000000 2.000000 2.000000 3.500000 +emscripten_float32x4_min(v, w): -1.000000 0.000000 1.000000 2.000000 +emscripten_float32x4_maxNum(v, w): 2.000000 2.000000 2.000000 3.500000 +emscripten_float32x4_minNum(v, w): -1.000000 0.000000 1.000000 2.000000 +emscripten_float32x4_neg(v): 1.000000 -0.000000 -1.000000 -3.500000 +emscripten_float32x4_sqrt(v): nan 0.000000 1.000000 1.870829 +emscripten_float32x4_abs(v): 1.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_and(v, w): 0.000000 0.000000 0.000000 2.000000 +emscripten_float32x4_xor(v, w): -inf 2.000000 inf 0.000000 +emscripten_float32x4_or(v, w): -inf 2.000000 inf 3.500000 +emscripten_float32x4_not(v): 4.000000 nan -4.000000 -1.250000 +emscripten_float32x4_lessThan(v, w): nan nan nan 0.000000 +emscripten_float32x4_lessThanOrEqual(v, w): nan nan nan 0.000000 +emscripten_float32x4_greaterThan(v, w): 0.000000 0.000000 0.000000 nan +emscripten_float32x4_greaterThanOrEqual(v, w): 0.000000 0.000000 0.000000 nan +emscripten_float32x4_equal(v, w): 0.000000 0.000000 0.000000 0.000000 +emscripten_float32x4_notEqual(v, w): nan nan nan nan +emscripten_float32x4_select(b, v, w): 2.000000 0.000000 2.000000 3.500000 +emscripten_float32x4_replaceLane(v, 0, 9.f): 9.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_replaceLane(v, 1, -3.f): -1.000000 -3.000000 1.000000 3.500000 +emscripten_float32x4_replaceLane(v, 2, 0.f): -1.000000 0.000000 0.000000 3.500000 +emscripten_float32x4_replaceLane(v, 3, -0.f): -1.000000 0.000000 1.000000 -0.000000 +emscripten_float32x4_store: 00 00 80 BF 00 00 00 00 00 00 80 3F 00 00 60 40 +emscripten_float32x4_store1: 00 00 80 BF FF FF FF FF FF FF FF FF FF FF FF FF +emscripten_float32x4_store2: 00 00 80 BF 00 00 00 00 FF FF FF FF FF FF FF FF +emscripten_float32x4_load(bytes): -1.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_load1(bytes): -1.000000 0.000000 0.000000 0.000000 +emscripten_float32x4_load2(bytes): -1.000000 0.000000 0.000000 0.000000 +emscripten_float32x4_swizzle(v, 0, 1, 2, 3): -1.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_swizzle(v, 3, 2, 1, 0): 3.500000 1.000000 0.000000 -1.000000 +emscripten_float32x4_swizzle(v, 0, 0, 0, 0): -1.000000 -1.000000 -1.000000 -1.000000 +emscripten_float32x4_swizzle(v, 0, 3, 0, 3): -1.000000 3.500000 -1.000000 3.500000 +emscripten_float32x4_swizzle(v, 3, 3, 3, 3): 3.500000 3.500000 3.500000 3.500000 +z: -5.000000 20.000000 14.000000 9.000000 +emscripten_float32x4_shuffle(v, z, 0, 0, 0, 0): -1.000000 -1.000000 -1.000000 -1.000000 +emscripten_float32x4_shuffle(v, z, 4, 4, 4, 4): -5.000000 -5.000000 -5.000000 -5.000000 +emscripten_float32x4_shuffle(v, z, 7, 7, 7, 7): 9.000000 9.000000 9.000000 9.000000 +emscripten_float32x4_shuffle(v, z, 0, 2, 4, 6): -1.000000 1.000000 -5.000000 14.000000 +emscripten_float32x4_shuffle(v, z, 7, 0, 3, 5): 9.000000 -1.000000 3.500000 20.000000 +Done! \ No newline at end of file diff --git a/emtests/test_simd_float64x2.c b/emtests/test_simd_float64x2.c new file mode 100644 index 000000000..102f92204 --- /dev/null +++ b/emtests/test_simd_float64x2.c @@ -0,0 +1,112 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include + +void printFloat(double n) { + if (isnan(n)) { + printf("nan"); + } else { + printf("%f", n); + } +} + +void dump(const char *name, float64x2 vec) +{ + printf("%s: ", name); + printFloat(emscripten_float64x2_extractLane(vec, 0)); + printf(" "); + printFloat(emscripten_float64x2_extractLane(vec, 1)); + printf("\n"); +} +#define DUMP(V) dump(#V, (V)) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + float64x2 v = emscripten_float64x2_set(-1.5f, 2.5f); + DUMP(v); + float64x2 w = emscripten_float64x2_splat(1.5f); + DUMP(w); + DUMP(emscripten_float64x2_add(v, w)); + DUMP(emscripten_float64x2_sub(v, w)); + DUMP(emscripten_float64x2_mul(v, w)); + DUMP(emscripten_float64x2_div(v, w)); + DUMP(emscripten_float64x2_max(v, w)); + DUMP(emscripten_float64x2_min(v, w)); + DUMP(emscripten_float64x2_maxNum(v, w)); + DUMP(emscripten_float64x2_minNum(v, w)); + DUMP(emscripten_float64x2_neg(v)); + DUMP(emscripten_float64x2_sqrt(v)); + float64x2 rcp = emscripten_float64x2_reciprocalApproximation(v); + assert(fabs(emscripten_float64x2_extractLane(rcp, 0) - 1.0 / emscripten_float64x2_extractLane(v, 0)) < 0.1); + assert(fabs(emscripten_float64x2_extractLane(rcp, 1) - 1.0 / emscripten_float64x2_extractLane(v, 1)) < 0.1); + float64x2 rcpSqrt = emscripten_float64x2_reciprocalSqrtApproximation(v); + // assert(isnan(emscripten_float64x2_extractLane(rcpSqrt, 0))); XXX TODO Enable once Float64x2 type lands in SIMD.js. + assert(fabs(emscripten_float64x2_extractLane(rcpSqrt, 1) - 1.0 / sqrt(emscripten_float64x2_extractLane(v, 1))) < 0.1); + DUMP(emscripten_float64x2_abs(v)); + DUMP(emscripten_float64x2_and(v, w)); + DUMP(emscripten_float64x2_xor(v, w)); + DUMP(emscripten_float64x2_or(v, w)); + DUMP(emscripten_float64x2_not(v)); + DUMP(emscripten_float64x2_lessThan(v, w)); + DUMP(emscripten_float64x2_lessThanOrEqual(v, w)); + DUMP(emscripten_float64x2_greaterThan(v, w)); + DUMP(emscripten_float64x2_greaterThanOrEqual(v, w)); + DUMP(emscripten_float64x2_equal(v, w)); + DUMP(emscripten_float64x2_notEqual(v, w)); + //bool64x2 b = emscripten_int64x2_set(0, -1); // TODO: Can't yet use this form, no int64x2. + //DUMP(emscripten_float64x2_select(b, v, w)); + DUMP(emscripten_float64x2_replaceLane(v, 0, 9.f)); + DUMP(emscripten_float64x2_replaceLane(v, 1, -3.f)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float64x2_store(bytes, v); + DUMPBYTES("emscripten_float64x2_store", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float64x2_store1(bytes, v); + DUMPBYTES("emscripten_float64x2_store1", bytes); + + emscripten_float64x2_store(bytes, v); + DUMP(emscripten_float64x2_load(bytes)); + DUMP(emscripten_float64x2_load1(bytes)); + // TODO: emscripten_float64x2_fromFloat64x2Bits + // TODO: emscripten_float64x2_fromInt64x2Bits + // TODO: emscripten_float64x2_fromUint64x2Bits + // TODO: emscripten_float64x2_fromInt16x8Bits + // TODO: emscripten_float64x2_fromUint16x8Bits + // TODO: emscripten_float64x2_fromInt8x16Bits + // TODO: emscripten_float64x2_fromUint8x16Bits + // TODO: emscripten_float64x2_fromInt64x2 + // TODO: emscripten_float64x2_fromUint64x2 + DUMP(emscripten_float64x2_swizzle(v, 0, 1)); + DUMP(emscripten_float64x2_swizzle(v, 1, 0)); + DUMP(emscripten_float64x2_swizzle(v, 0, 0)); + DUMP(emscripten_float64x2_swizzle(v, 1, 1)); + float64x2 z = emscripten_float64x2_set(-5.5f, 20.5f); + DUMP(z); + DUMP(emscripten_float64x2_shuffle(v, z, 0, 0)); + DUMP(emscripten_float64x2_shuffle(v, z, 2, 2)); + DUMP(emscripten_float64x2_shuffle(v, z, 3, 3)); + DUMP(emscripten_float64x2_shuffle(v, z, 0, 2)); + DUMP(emscripten_float64x2_shuffle(v, z, 3, 1)); + + printf("Done!\n"); +} diff --git a/emtests/test_simd_float64x2.out b/emtests/test_simd_float64x2.out new file mode 100644 index 000000000..e8c38ecc4 --- /dev/null +++ b/emtests/test_simd_float64x2.out @@ -0,0 +1,40 @@ +v: -1.500000 2.500000 +w: 1.500000 1.500000 +emscripten_float64x2_add(v, w): 0.000000 4.000000 +emscripten_float64x2_sub(v, w): -3.000000 1.000000 +emscripten_float64x2_mul(v, w): -2.250000 3.750000 +emscripten_float64x2_div(v, w): -1.000000 1.666667 +emscripten_float64x2_max(v, w): 1.500000 2.500000 +emscripten_float64x2_min(v, w): -1.500000 1.500000 +emscripten_float64x2_maxNum(v, w): 1.500000 2.500000 +emscripten_float64x2_minNum(v, w): -1.500000 1.500000 +emscripten_float64x2_neg(v): 1.500000 -2.500000 +emscripten_float64x2_sqrt(v): nan 1.581139 +emscripten_float64x2_abs(v): 1.500000 2.500000 +emscripten_float64x2_and(v, w): 1.500000 0.000000 +emscripten_float64x2_xor(v, w): -0.000000 nan +emscripten_float64x2_or(v, w): -1.500000 nan +emscripten_float64x2_not(v): 3.000000 -1.750000 +emscripten_float64x2_lessThan(v, w): nan 0.000000 +emscripten_float64x2_lessThanOrEqual(v, w): nan 0.000000 +emscripten_float64x2_greaterThan(v, w): 0.000000 nan +emscripten_float64x2_greaterThanOrEqual(v, w): 0.000000 nan +emscripten_float64x2_equal(v, w): 0.000000 0.000000 +emscripten_float64x2_notEqual(v, w): nan nan +emscripten_float64x2_replaceLane(v, 0, 9.f): 9.000000 2.500000 +emscripten_float64x2_replaceLane(v, 1, -3.f): -1.500000 -3.000000 +emscripten_float64x2_store: 00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 04 40 +emscripten_float64x2_store1: 00 00 00 00 00 00 F8 BF FF FF FF FF FF FF FF FF +emscripten_float64x2_load(bytes): -1.500000 2.500000 +emscripten_float64x2_load1(bytes): -1.500000 0.000000 +emscripten_float64x2_swizzle(v, 0, 1): -1.500000 2.500000 +emscripten_float64x2_swizzle(v, 1, 0): 2.500000 -1.500000 +emscripten_float64x2_swizzle(v, 0, 0): -1.500000 -1.500000 +emscripten_float64x2_swizzle(v, 1, 1): 2.500000 2.500000 +z: -5.500000 20.500000 +emscripten_float64x2_shuffle(v, z, 0, 0): -1.500000 -1.500000 +emscripten_float64x2_shuffle(v, z, 2, 2): -5.500000 -5.500000 +emscripten_float64x2_shuffle(v, z, 3, 3): 20.500000 20.500000 +emscripten_float64x2_shuffle(v, z, 0, 2): -1.500000 -5.500000 +emscripten_float64x2_shuffle(v, z, 3, 1): 20.500000 2.500000 +Done! \ No newline at end of file diff --git a/emtests/test_simd_int16x8.c b/emtests/test_simd_int16x8.c new file mode 100644 index 000000000..e1ef050f1 --- /dev/null +++ b/emtests/test_simd_int16x8.c @@ -0,0 +1,103 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +void dump(const char *name, int16x8 vec) +{ + printf("%s: %d %d %d %d %d %d %d %d\n", name, emscripten_int16x8_extractLane(vec, 0), emscripten_int16x8_extractLane(vec, 1), emscripten_int16x8_extractLane(vec, 2), emscripten_int16x8_extractLane(vec, 3), + emscripten_int16x8_extractLane(vec, 4), emscripten_int16x8_extractLane(vec, 5), emscripten_int16x8_extractLane(vec, 6), emscripten_int16x8_extractLane(vec, 7)); +} +#define DUMP(V) dump(#V, (V)) +#define DUMPINT(V) printf("%s: %d\n", #V, V) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + int16x8 v = emscripten_int16x8_set(1, 0, 1, 32767, -2, 9, 13, -32768); + DUMP(v); + int16x8 w = emscripten_int16x8_splat(2); + DUMP(w); + DUMP(emscripten_int16x8_add(v, w)); + DUMP(emscripten_int16x8_sub(v, w)); + DUMP(emscripten_int16x8_mul(v, w)); + DUMP(emscripten_int16x8_neg(v)); + DUMP(emscripten_int16x8_and(v, w)); + DUMP(emscripten_int16x8_xor(v, w)); + DUMP(emscripten_int16x8_or(v, w)); + DUMP(emscripten_int16x8_not(v)); + DUMP(emscripten_int16x8_lessThan(v, w)); + DUMP(emscripten_int16x8_lessThanOrEqual(v, w)); + DUMP(emscripten_int16x8_greaterThan(v, w)); + DUMP(emscripten_int16x8_greaterThanOrEqual(v, w)); + DUMP(emscripten_int16x8_equal(v, w)); + DUMP(emscripten_int16x8_notEqual(v, w)); +// DUMPINT(emscripten_int16x8_anyTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int16x8->bool16x8 and enable this, or remove if this doesn't make sense. +// DUMPINT(emscripten_int16x8_allTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int16x8->bool16x8 and enable this, or remove if this doesn't make sense. + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 0)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 1)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 2)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 16)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 32)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 48)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 0)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 1)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 2)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 16)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 32)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 48)); + bool32x4 b = emscripten_int16x8_set(0, -1, 0, -1, 0, -1, 0, -1); + DUMP(emscripten_int16x8_select(b, v, w)); + DUMP(emscripten_int16x8_addSaturate(v, w)); + DUMP(emscripten_int16x8_subSaturate(v, w)); + DUMP(emscripten_int16x8_replaceLane(v, 0, 9)); + DUMP(emscripten_int16x8_replaceLane(v, 1, 3)); + DUMP(emscripten_int16x8_replaceLane(v, 2, 0)); + DUMP(emscripten_int16x8_replaceLane(v, 3, 91)); + DUMP(emscripten_int16x8_replaceLane(v, 4, 32767)); + DUMP(emscripten_int16x8_replaceLane(v, 5, 100)); + DUMP(emscripten_int16x8_replaceLane(v, 6, -100)); + DUMP(emscripten_int16x8_replaceLane(v, 7, -32768)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int16x8_store(bytes, v); + DUMPBYTES("emscripten_int16x8_store", bytes); + DUMP(emscripten_int16x8_load(bytes)); + // TODO: emscripten_int16x8_fromFloat64x2Bits + // TODO: emscripten_int16x8_fromint16x8Bits + // TODO: emscripten_int16x8_fromUint16x8Bits + // TODO: emscripten_int16x8_fromInt16x8Bits + // TODO: emscripten_int16x8_fromUint16x8Bits + // TODO: emscripten_int16x8_fromInt8x16Bits + // TODO: emscripten_int16x8_fromUint8x16Bits + // TODO: emscripten_int16x8_fromint16x8 + // TODO: emscripten_int16x8_fromUint16x8 + DUMP(emscripten_int16x8_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7)); + DUMP(emscripten_int16x8_swizzle(v, 7, 6, 5, 4, 3, 2, 1, 0)); + DUMP(emscripten_int16x8_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int16x8_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6)); + DUMP(emscripten_int16x8_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3)); + int16x8 z = emscripten_int16x8_set(-5, 20, 14, 9, 0, 11, 32764, -32750); + DUMP(z); + DUMP(emscripten_int16x8_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int16x8_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4)); + DUMP(emscripten_int16x8_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7)); + DUMP(emscripten_int16x8_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14)); + DUMP(emscripten_int16x8_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4)); + printf("Done!\n"); +} diff --git a/emtests/test_simd_int16x8.out b/emtests/test_simd_int16x8.out new file mode 100644 index 000000000..0784dcd78 --- /dev/null +++ b/emtests/test_simd_int16x8.out @@ -0,0 +1,53 @@ +v: 1 0 1 32767 -2 9 13 -32768 +w: 2 2 2 2 2 2 2 2 +emscripten_int16x8_add(v, w): 3 2 3 -32767 0 11 15 -32766 +emscripten_int16x8_sub(v, w): -1 -2 -1 32765 -4 7 11 32766 +emscripten_int16x8_mul(v, w): 2 0 2 -2 -4 18 26 0 +emscripten_int16x8_neg(v): -1 0 -1 -32767 2 -9 -13 -32768 +emscripten_int16x8_and(v, w): 0 0 0 2 2 0 0 0 +emscripten_int16x8_xor(v, w): 3 2 3 32765 -4 11 15 -32766 +emscripten_int16x8_or(v, w): 3 2 3 32767 -2 11 15 -32766 +emscripten_int16x8_not(v): -2 -1 -2 -32768 1 -10 -14 32767 +emscripten_int16x8_lessThan(v, w): -1 -1 -1 0 -1 0 0 -1 +emscripten_int16x8_lessThanOrEqual(v, w): -1 -1 -1 0 -1 0 0 -1 +emscripten_int16x8_greaterThan(v, w): 0 0 0 -1 0 -1 -1 0 +emscripten_int16x8_greaterThanOrEqual(v, w): 0 0 0 -1 0 -1 -1 0 +emscripten_int16x8_equal(v, w): 0 0 0 0 0 0 0 0 +emscripten_int16x8_notEqual(v, w): -1 -1 -1 -1 -1 -1 -1 -1 +emscripten_int16x8_shiftLeftByScalar(v, 0): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftLeftByScalar(v, 1): 2 0 2 -2 -4 18 26 0 +emscripten_int16x8_shiftLeftByScalar(v, 2): 4 0 4 -4 -8 36 52 0 +emscripten_int16x8_shiftLeftByScalar(v, 16): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftLeftByScalar(v, 32): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftLeftByScalar(v, 48): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftRightByScalar(v, 0): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftRightByScalar(v, 1): 0 0 0 16383 -1 4 6 -16384 +emscripten_int16x8_shiftRightByScalar(v, 2): 0 0 0 8191 -1 2 3 -8192 +emscripten_int16x8_shiftRightByScalar(v, 16): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftRightByScalar(v, 32): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftRightByScalar(v, 48): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_select(b, v, w): 2 0 2 32767 2 9 2 -32768 +emscripten_int16x8_addSaturate(v, w): 3 2 3 32767 0 11 15 -32766 +emscripten_int16x8_subSaturate(v, w): -1 -2 -1 32765 -4 7 11 -32768 +emscripten_int16x8_replaceLane(v, 0, 9): 9 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 1, 3): 1 3 1 32767 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 2, 0): 1 0 0 32767 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 3, 91): 1 0 1 91 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 4, 32767): 1 0 1 32767 32767 9 13 -32768 +emscripten_int16x8_replaceLane(v, 5, 100): 1 0 1 32767 -2 100 13 -32768 +emscripten_int16x8_replaceLane(v, 6, -100): 1 0 1 32767 -2 9 -100 -32768 +emscripten_int16x8_replaceLane(v, 7, -32768): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_store: 01 00 00 00 01 00 FF 7F FE FF 09 00 0D 00 00 80 +emscripten_int16x8_load(bytes): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_swizzle(v, 7, 6, 5, 4, 3, 2, 1, 0): -32768 13 9 -2 32767 1 0 1 +emscripten_int16x8_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 +emscripten_int16x8_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6): 1 32767 1 32767 -32768 0 1 13 +emscripten_int16x8_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3): 32767 32767 32767 32767 32767 32767 32767 32767 +z: -5 20 14 9 0 11 32764 -32750 +emscripten_int16x8_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 +emscripten_int16x8_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4): -2 -2 -2 -2 -2 -2 -2 -2 +emscripten_int16x8_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7): -32750 -32750 -32750 -32750 -32768 -32768 -32768 -32768 +emscripten_int16x8_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14): 1 1 -2 13 -5 14 0 32764 +emscripten_int16x8_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4): -32768 1 32767 9 20 9 0 -2 +Done! diff --git a/emtests/test_simd_int32x4.c b/emtests/test_simd_int32x4.c new file mode 100644 index 000000000..1c2bb6a41 --- /dev/null +++ b/emtests/test_simd_int32x4.c @@ -0,0 +1,106 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +void dump(const char *name, int32x4 vec) +{ + printf("%s: %d %d %d %d\n", name, emscripten_int32x4_extractLane(vec, 0), emscripten_int32x4_extractLane(vec, 1), emscripten_int32x4_extractLane(vec, 2), emscripten_int32x4_extractLane(vec, 3)); +} +#define DUMP(V) dump(#V, (V)) +#define DUMPINT(V) printf("%s: %d\n", #V, V) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + int32x4 v = emscripten_int32x4_set(1, 0, 1, 4); + DUMP(v); + int32x4 w = emscripten_int32x4_splat(2); + DUMP(w); + DUMP(emscripten_int32x4_add(v, w)); + DUMP(emscripten_int32x4_sub(v, w)); + DUMP(emscripten_int32x4_mul(v, w)); + DUMP(emscripten_int32x4_neg(v)); + DUMP(emscripten_int32x4_and(v, w)); + DUMP(emscripten_int32x4_xor(v, w)); + DUMP(emscripten_int32x4_or(v, w)); + DUMP(emscripten_int32x4_not(v)); + DUMP(emscripten_int32x4_lessThan(v, w)); + DUMP(emscripten_int32x4_lessThanOrEqual(v, w)); + DUMP(emscripten_int32x4_greaterThan(v, w)); + DUMP(emscripten_int32x4_greaterThanOrEqual(v, w)); + DUMP(emscripten_int32x4_equal(v, w)); + DUMP(emscripten_int32x4_notEqual(v, w)); +// DUMPINT(emscripten_int32x4_anyTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int32x4->bool32x4 and enable this, or remove if this doesn't make sense. +// DUMPINT(emscripten_int32x4_allTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int32x4->bool32x4 and enable this, or remove if this doesn't make sense. + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 0)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 1)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 2)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 16)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 32)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 48)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 0)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 1)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 2)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 16)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 32)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 48)); + bool32x4 b = emscripten_int32x4_set(0, -1, 0, -1); + DUMP(emscripten_int32x4_select(b, v, w)); + DUMP(emscripten_int32x4_replaceLane(v, 0, 9)); + DUMP(emscripten_int32x4_replaceLane(v, 1, 3)); + DUMP(emscripten_int32x4_replaceLane(v, 2, 0)); + DUMP(emscripten_int32x4_replaceLane(v, 3, 91)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store(bytes, v); + DUMPBYTES("emscripten_int32x4_store", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store1(bytes, v); + DUMPBYTES("emscripten_int32x4_store1", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store2(bytes, v); + DUMPBYTES("emscripten_int32x4_store2", bytes); + + emscripten_int32x4_store(bytes, v); + DUMP(emscripten_int32x4_load(bytes)); + DUMP(emscripten_int32x4_load1(bytes)); + DUMP(emscripten_int32x4_load2(bytes)); + // TODO: emscripten_int32x4_fromFloat64x2Bits + // TODO: emscripten_int32x4_fromInt32x4Bits + // TODO: emscripten_int32x4_fromUint32x4Bits + // TODO: emscripten_int32x4_fromInt16x8Bits + // TODO: emscripten_int32x4_fromUint16x8Bits + // TODO: emscripten_int32x4_fromInt8x16Bits + // TODO: emscripten_int32x4_fromUint8x16Bits + // TODO: emscripten_int32x4_fromInt32x4 + // TODO: emscripten_int32x4_fromUint32x4 + DUMP(emscripten_int32x4_swizzle(v, 0, 1, 2, 3)); + DUMP(emscripten_int32x4_swizzle(v, 3, 2, 1, 0)); + DUMP(emscripten_int32x4_swizzle(v, 0, 0, 0, 0)); + DUMP(emscripten_int32x4_swizzle(v, 0, 3, 0, 3)); + DUMP(emscripten_int32x4_swizzle(v, 3, 3, 3, 3)); + int32x4 z = emscripten_int32x4_set(-5, 20, 14, 9); + DUMP(z); + DUMP(emscripten_int32x4_shuffle(v, z, 0, 0, 0, 0)); + DUMP(emscripten_int32x4_shuffle(v, z, 4, 4, 4, 4)); + DUMP(emscripten_int32x4_shuffle(v, z, 7, 7, 7, 7)); + DUMP(emscripten_int32x4_shuffle(v, z, 0, 2, 4, 6)); + DUMP(emscripten_int32x4_shuffle(v, z, 7, 0, 3, 5)); + printf("Done!\n"); +} diff --git a/emtests/test_simd_int32x4.out b/emtests/test_simd_int32x4.out new file mode 100644 index 000000000..55e2e130f --- /dev/null +++ b/emtests/test_simd_int32x4.out @@ -0,0 +1,51 @@ +v: 1 0 1 4 +w: 2 2 2 2 +emscripten_int32x4_add(v, w): 3 2 3 6 +emscripten_int32x4_sub(v, w): -1 -2 -1 2 +emscripten_int32x4_mul(v, w): 2 0 2 8 +emscripten_int32x4_neg(v): -1 0 -1 -4 +emscripten_int32x4_and(v, w): 0 0 0 0 +emscripten_int32x4_xor(v, w): 3 2 3 6 +emscripten_int32x4_or(v, w): 3 2 3 6 +emscripten_int32x4_not(v): -2 -1 -2 -5 +emscripten_int32x4_lessThan(v, w): -1 -1 -1 0 +emscripten_int32x4_lessThanOrEqual(v, w): -1 -1 -1 0 +emscripten_int32x4_greaterThan(v, w): 0 0 0 -1 +emscripten_int32x4_greaterThanOrEqual(v, w): 0 0 0 -1 +emscripten_int32x4_equal(v, w): 0 0 0 0 +emscripten_int32x4_notEqual(v, w): -1 -1 -1 -1 +emscripten_int32x4_shiftLeftByScalar(v, 0): 1 0 1 4 +emscripten_int32x4_shiftLeftByScalar(v, 1): 2 0 2 8 +emscripten_int32x4_shiftLeftByScalar(v, 2): 4 0 4 16 +emscripten_int32x4_shiftLeftByScalar(v, 16): 65536 0 65536 262144 +emscripten_int32x4_shiftLeftByScalar(v, 32): 1 0 1 4 +emscripten_int32x4_shiftLeftByScalar(v, 48): 65536 0 65536 262144 +emscripten_int32x4_shiftRightByScalar(v, 0): 1 0 1 4 +emscripten_int32x4_shiftRightByScalar(v, 1): 0 0 0 2 +emscripten_int32x4_shiftRightByScalar(v, 2): 0 0 0 1 +emscripten_int32x4_shiftRightByScalar(v, 16): 0 0 0 0 +emscripten_int32x4_shiftRightByScalar(v, 32): 1 0 1 4 +emscripten_int32x4_shiftRightByScalar(v, 48): 0 0 0 0 +emscripten_int32x4_select(b, v, w): 2 0 2 4 +emscripten_int32x4_replaceLane(v, 0, 9): 9 0 1 4 +emscripten_int32x4_replaceLane(v, 1, 3): 1 3 1 4 +emscripten_int32x4_replaceLane(v, 2, 0): 1 0 0 4 +emscripten_int32x4_replaceLane(v, 3, 91): 1 0 1 91 +emscripten_int32x4_store: 01 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 +emscripten_int32x4_store1: 01 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF +emscripten_int32x4_store2: 01 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF +emscripten_int32x4_load(bytes): 1 0 1 4 +emscripten_int32x4_load1(bytes): 1 0 0 0 +emscripten_int32x4_load2(bytes): 1 0 0 0 +emscripten_int32x4_swizzle(v, 0, 1, 2, 3): 1 0 1 4 +emscripten_int32x4_swizzle(v, 3, 2, 1, 0): 4 1 0 1 +emscripten_int32x4_swizzle(v, 0, 0, 0, 0): 1 1 1 1 +emscripten_int32x4_swizzle(v, 0, 3, 0, 3): 1 4 1 4 +emscripten_int32x4_swizzle(v, 3, 3, 3, 3): 4 4 4 4 +z: -5 20 14 9 +emscripten_int32x4_shuffle(v, z, 0, 0, 0, 0): 1 1 1 1 +emscripten_int32x4_shuffle(v, z, 4, 4, 4, 4): -5 -5 -5 -5 +emscripten_int32x4_shuffle(v, z, 7, 7, 7, 7): 9 9 9 9 +emscripten_int32x4_shuffle(v, z, 0, 2, 4, 6): 1 1 -5 14 +emscripten_int32x4_shuffle(v, z, 7, 0, 3, 5): 9 1 4 20 +Done! diff --git a/emtests/test_simd_int8x16.c b/emtests/test_simd_int8x16.c new file mode 100644 index 000000000..260c7cf89 --- /dev/null +++ b/emtests/test_simd_int8x16.c @@ -0,0 +1,113 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +void dump(const char *name, int8x16 vec) +{ + printf("%s: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", name, emscripten_int8x16_extractLane(vec, 0), emscripten_int8x16_extractLane(vec, 1), emscripten_int8x16_extractLane(vec, 2), emscripten_int8x16_extractLane(vec, 3), + emscripten_int8x16_extractLane(vec, 4), emscripten_int8x16_extractLane(vec, 5), emscripten_int8x16_extractLane(vec, 6), emscripten_int8x16_extractLane(vec, 7), + emscripten_int8x16_extractLane(vec, 8), emscripten_int8x16_extractLane(vec, 9), emscripten_int8x16_extractLane(vec, 10), emscripten_int8x16_extractLane(vec, 11), + emscripten_int8x16_extractLane(vec, 12), emscripten_int8x16_extractLane(vec, 13), emscripten_int8x16_extractLane(vec, 14), emscripten_int8x16_extractLane(vec, 15)); +} +#define DUMP(V) dump(#V, (V)) +#define DUMPINT(V) printf("%s: %d\n", #V, V) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + int8x16 v = emscripten_int8x16_set(1, 0, 1, 127, -2, 9, 13, -128, 3, 19, 73, -53, 42, 66, 10, 100); + DUMP(v); + int8x16 w = emscripten_int8x16_splat(2); + DUMP(w); + DUMP(emscripten_int8x16_add(v, w)); + DUMP(emscripten_int8x16_sub(v, w)); + DUMP(emscripten_int8x16_mul(v, w)); + DUMP(emscripten_int8x16_neg(v)); + DUMP(emscripten_int8x16_and(v, w)); + DUMP(emscripten_int8x16_xor(v, w)); + DUMP(emscripten_int8x16_or(v, w)); + DUMP(emscripten_int8x16_not(v)); + DUMP(emscripten_int8x16_lessThan(v, w)); + DUMP(emscripten_int8x16_lessThanOrEqual(v, w)); + DUMP(emscripten_int8x16_greaterThan(v, w)); + DUMP(emscripten_int8x16_greaterThanOrEqual(v, w)); + DUMP(emscripten_int8x16_equal(v, w)); + DUMP(emscripten_int8x16_notEqual(v, w)); +// DUMPINT(emscripten_int8x16_anyTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int8x16->bool8x16 and enable this, or remove if this doesn't make sense. +// DUMPINT(emscripten_int8x16_allTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int8x16->bool8x16 and enable this, or remove if this doesn't make sense. + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 0)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 1)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 2)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 16)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 32)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 48)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 0)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 1)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 2)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 16)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 32)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 48)); + bool32x4 b = emscripten_int8x16_set(0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1); + DUMP(emscripten_int8x16_select(b, v, w)); + DUMP(emscripten_int8x16_addSaturate(v, w)); + DUMP(emscripten_int8x16_subSaturate(v, w)); + DUMP(emscripten_int8x16_replaceLane(v, 0, 9)); + DUMP(emscripten_int8x16_replaceLane(v, 1, 3)); + DUMP(emscripten_int8x16_replaceLane(v, 2, 0)); + DUMP(emscripten_int8x16_replaceLane(v, 3, 91)); + DUMP(emscripten_int8x16_replaceLane(v, 4, 127)); + DUMP(emscripten_int8x16_replaceLane(v, 5, 100)); + DUMP(emscripten_int8x16_replaceLane(v, 6, -100)); + DUMP(emscripten_int8x16_replaceLane(v, 7, -128)); + DUMP(emscripten_int8x16_replaceLane(v, 8, 9)); + DUMP(emscripten_int8x16_replaceLane(v, 9, 3)); + DUMP(emscripten_int8x16_replaceLane(v, 10, 0)); + DUMP(emscripten_int8x16_replaceLane(v, 11, 91)); + DUMP(emscripten_int8x16_replaceLane(v, 12, 127)); + DUMP(emscripten_int8x16_replaceLane(v, 13, 100)); + DUMP(emscripten_int8x16_replaceLane(v, 14, -100)); + DUMP(emscripten_int8x16_replaceLane(v, 15, -128)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int8x16_store(bytes, v); + DUMPBYTES("emscripten_int8x16_store", bytes); + DUMP(emscripten_int8x16_load(bytes)); + // TODO: emscripten_int8x16_fromFloat64x2Bits + // TODO: emscripten_int8x16_fromint8x16Bits + // TODO: emscripten_int8x16_fromUint8x16Bits + // TODO: emscripten_int8x16_fromInt8x16Bits + // TODO: emscripten_int8x16_fromUint8x16Bits + // TODO: emscripten_int8x16_fromInt8x16Bits + // TODO: emscripten_int8x16_fromUint8x16Bits + // TODO: emscripten_int8x16_fromint8x16 + // TODO: emscripten_int8x16_fromUint8x16 + DUMP(emscripten_int8x16_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)); + DUMP(emscripten_int8x16_swizzle(v, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); + DUMP(emscripten_int8x16_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int8x16_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6, 9, 14, 5, 12, 15, 4, 10, 2)); + DUMP(emscripten_int8x16_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)); + int8x16 z = emscripten_int8x16_set(-5, 20, 14, 9, 0, 11, 120, -120, 40, 50, 60, 70, 80, 90, 100, 110); + DUMP(z); + DUMP(emscripten_int8x16_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int8x16_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)); + DUMP(emscripten_int8x16_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7, 31, 31, 31, 31, 15, 14, 13, 12)); + DUMP(emscripten_int8x16_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30)); + DUMP(emscripten_int8x16_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4, 6, 12, 19, 4, 9, 0, 2, 3)); + printf("Done!\n"); +} diff --git a/emtests/test_simd_int8x16.out b/emtests/test_simd_int8x16.out new file mode 100644 index 000000000..7d0f37497 --- /dev/null +++ b/emtests/test_simd_int8x16.out @@ -0,0 +1,61 @@ +v: 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +w: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 +emscripten_int8x16_add(v, w): 3 2 3 -127 0 11 15 -126 5 21 75 -51 44 68 12 102 +emscripten_int8x16_sub(v, w): -1 -2 -1 125 -4 7 11 126 1 17 71 -55 40 64 8 98 +emscripten_int8x16_mul(v, w): 2 0 2 -2 -4 18 26 0 6 38 -110 -106 84 -124 20 -56 +emscripten_int8x16_neg(v): -1 0 -1 -127 2 -9 -13 -128 -3 -19 -73 53 -42 -66 -10 -100 +emscripten_int8x16_and(v, w): 0 0 0 2 2 0 0 0 2 2 0 2 2 2 2 0 +emscripten_int8x16_xor(v, w): 3 2 3 125 -4 11 15 -126 1 17 75 -55 40 64 8 102 +emscripten_int8x16_or(v, w): 3 2 3 127 -2 11 15 -126 3 19 75 -53 42 66 10 102 +emscripten_int8x16_not(v): -2 -1 -2 -128 1 -10 -14 127 -4 -20 -74 52 -43 -67 -11 -101 +emscripten_int8x16_lessThan(v, w): -1 -1 -1 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_lessThanOrEqual(v, w): -1 -1 -1 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_greaterThan(v, w): 0 0 0 -1 0 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 +emscripten_int8x16_greaterThanOrEqual(v, w): 0 0 0 -1 0 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 +emscripten_int8x16_equal(v, w): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +emscripten_int8x16_notEqual(v, w): -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +emscripten_int8x16_shiftLeftByScalar(v, 0): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftLeftByScalar(v, 1): 2 0 2 -2 -4 18 26 0 6 38 -110 -106 84 -124 20 -56 +emscripten_int8x16_shiftLeftByScalar(v, 2): 4 0 4 -4 -8 36 52 0 12 76 36 44 -88 8 40 -112 +emscripten_int8x16_shiftLeftByScalar(v, 16): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftLeftByScalar(v, 32): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftLeftByScalar(v, 48): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftRightByScalar(v, 0): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftRightByScalar(v, 1): 0 0 0 63 -1 4 6 -64 1 9 36 -27 21 33 5 50 +emscripten_int8x16_shiftRightByScalar(v, 2): 0 0 0 31 -1 2 3 -32 0 4 18 -14 10 16 2 25 +emscripten_int8x16_shiftRightByScalar(v, 16): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftRightByScalar(v, 32): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftRightByScalar(v, 48): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_select(b, v, w): 2 0 2 127 2 9 2 -128 2 19 2 -53 2 66 2 100 +emscripten_int8x16_addSaturate(v, w): 3 2 3 127 0 11 15 -126 5 21 75 -51 44 68 12 102 +emscripten_int8x16_subSaturate(v, w): -1 -2 -1 125 -4 7 11 -128 1 17 71 -55 40 64 8 98 +emscripten_int8x16_replaceLane(v, 0, 9): 9 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 1, 3): 1 3 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 2, 0): 1 0 0 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 3, 91): 1 0 1 91 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 4, 127): 1 0 1 127 127 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 5, 100): 1 0 1 127 -2 100 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 6, -100): 1 0 1 127 -2 9 -100 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 7, -128): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 8, 9): 1 0 1 127 -2 9 13 -128 9 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 9, 3): 1 0 1 127 -2 9 13 -128 3 3 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 10, 0): 1 0 1 127 -2 9 13 -128 3 19 0 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 11, 91): 1 0 1 127 -2 9 13 -128 3 19 73 91 42 66 10 100 +emscripten_int8x16_replaceLane(v, 12, 127): 1 0 1 127 -2 9 13 -128 3 19 73 -53 127 66 10 100 +emscripten_int8x16_replaceLane(v, 13, 100): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 100 10 100 +emscripten_int8x16_replaceLane(v, 14, -100): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 -100 100 +emscripten_int8x16_replaceLane(v, 15, -128): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 -128 +emscripten_int8x16_store: 01 00 01 7F FE 09 0D 80 03 13 49 CB 2A 42 0A 64 +emscripten_int8x16_load(bytes): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_swizzle(v, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0): 100 10 66 42 -53 73 19 3 -128 13 9 -2 127 1 0 1 +emscripten_int8x16_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +emscripten_int8x16_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6, 9, 14, 5, 12, 15, 4, 10, 2): 1 127 1 127 -128 0 1 13 19 10 9 42 100 -2 73 1 +emscripten_int8x16_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3): 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 +z: -5 20 14 9 0 11 120 -120 40 50 60 70 80 90 100 110 +emscripten_int8x16_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +emscripten_int8x16_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4): -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 +emscripten_int8x16_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7, 31, 31, 31, 31, 15, 14, 13, 12): 100 100 100 100 -128 -128 -128 -128 110 110 110 110 100 10 66 42 +emscripten_int8x16_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30): 1 1 -2 13 3 73 42 10 -5 14 0 120 40 60 80 100 +emscripten_int8x16_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4, 6, 12, 19, 4, 9, 0, 2, 3): -128 1 127 9 19 -53 0 -2 13 42 9 -2 19 1 1 127 +Done! diff --git a/emtests/test_simd_set_epi64x.c b/emtests/test_simd_set_epi64x.c new file mode 100644 index 000000000..b702cd975 --- /dev/null +++ b/emtests/test_simd_set_epi64x.c @@ -0,0 +1,21 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +void print128_num(__m128i var) +{ + int32_t *v32val = (int32_t*) &var; + printf("%.8d %.8d %.8d %.8d\n", v32val[3], v32val[2], v32val[1], v32val[0]); +} + +int main() { + __m128i var = _mm_set_epi64x(-1588454185101182573, 437384867522774919); + print128_num(var); +} diff --git a/emtests/test_simd_set_epi64x.out b/emtests/test_simd_set_epi64x.out new file mode 100644 index 000000000..384b555c4 --- /dev/null +++ b/emtests/test_simd_set_epi64x.out @@ -0,0 +1 @@ +-369840811 -1425032813 101836600 986941319 diff --git a/emtests/test_simd_shift_right.c b/emtests/test_simd_shift_right.c new file mode 100644 index 000000000..8e782f568 --- /dev/null +++ b/emtests/test_simd_shift_right.c @@ -0,0 +1,22 @@ +/* + * Copyright 2018 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef int int32x4 __attribute__((__vector_size__(16), __may_alias__)); +typedef unsigned int uint32x4 __attribute__((__vector_size__(16), __may_alias__)); + +int main() { + + uint32x4 v = { 0, 0x80000000u, 0x7fffffff, 0xffffffffu}; + v = v >> 2; + printf("%x %x %x %x\n", v[0], v[1], v[2], v[3]); + + int32x4 w = { 0, 0x80000000u, 0x7fffffff, 0xffffffffu}; + w = w >> 2; + printf("%x %x %x %x\n", w[0], w[1], w[2], w[3]); +} diff --git a/emtests/test_simd_shift_right.out b/emtests/test_simd_shift_right.out new file mode 100644 index 000000000..ae1f9af97 --- /dev/null +++ b/emtests/test_simd_shift_right.out @@ -0,0 +1,2 @@ +0 20000000 1fffffff 3fffffff +0 e0000000 1fffffff ffffffff \ No newline at end of file diff --git a/emtests/test_simd_sitofp.c b/emtests/test_simd_sitofp.c new file mode 100644 index 000000000..729f87919 --- /dev/null +++ b/emtests/test_simd_sitofp.c @@ -0,0 +1,16 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef int int32x4 __attribute__((__vector_size__(16), __may_alias__)); +typedef float float32x4 __attribute__((__vector_size__(16), __may_alias__)); + +int main() { + float32x4 v = __builtin_convertvector((int32x4) { 255, 255, 255, 255}, float32x4); + printf("%f\n", v[0]); +} diff --git a/emtests/test_simd_sitofp.out b/emtests/test_simd_sitofp.out new file mode 100644 index 000000000..cc00e6f2e --- /dev/null +++ b/emtests/test_simd_sitofp.out @@ -0,0 +1 @@ +255.000000 \ No newline at end of file diff --git a/emtests/test_sintvars.c b/emtests/test_sintvars.c new file mode 100644 index 000000000..10e2c414b --- /dev/null +++ b/emtests/test_sintvars.c @@ -0,0 +1,31 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct S { + char *match_start; + char *strstart; +}; +int main() { + struct S _s; + struct S *s = &_s; + unsigned short int sh; + + s->match_start = (char *)32522; + s->strstart = (char *)(32780); + printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, + (int)(s->strstart - s->match_start)); + sh = s->strstart - s->match_start; + printf("*%d,%d*\n", sh, sh >> 7); + + s->match_start = (char *)32999; + s->strstart = (char *)(32780); + printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, + (int)(s->strstart - s->match_start)); + sh = s->strstart - s->match_start; + printf("*%d,%d*\n", sh, sh >> 7); +} diff --git a/emtests/test_sintvars.out b/emtests/test_sintvars.out new file mode 100644 index 000000000..aea5592ed --- /dev/null +++ b/emtests/test_sintvars.out @@ -0,0 +1,4 @@ +*32780,32522,258* +*258,2* +*32780,32999,-219* +*65317,510* \ No newline at end of file diff --git a/emtests/test_sintvars.wasm b/emtests/test_sintvars.wasm new file mode 100644 index 000000000..f2713acf2 Binary files /dev/null and b/emtests/test_sintvars.wasm differ diff --git a/emtests/test_sizeof.cpp b/emtests/test_sizeof.cpp new file mode 100644 index 000000000..e398b5383 --- /dev/null +++ b/emtests/test_sizeof.cpp @@ -0,0 +1,34 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include "emscripten.h" + +struct A { + int x, y; +}; + +int main(int argc, const char *argv[]) { + int *a = new int[10]; + int *b = new int[1]; + int *c = new int[10]; + for (int i = 0; i < 10; i++) a[i] = 2; + *b = 5; + for (int i = 0; i < 10; i++) c[i] = 8; + printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); + // Should overwrite a, but not touch b! + memcpy(a, c, 10 * sizeof(int)); + printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); + + // Part 2 + A as[3] = {{5, 12}, {6, 990}, {7, 2}}; + memcpy(&as[0], &as[2], sizeof(A)); + + printf("*%d,%d,%d,%d,%d,%d*\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, + as[2].y); + + return 0; +} diff --git a/emtests/test_sizeof.out b/emtests/test_sizeof.out new file mode 100644 index 000000000..0cab34221 --- /dev/null +++ b/emtests/test_sizeof.out @@ -0,0 +1,3 @@ +*2,2,5,8,8* +*8,8,5,8,8* +*7,2,6,990,7,2* diff --git a/emtests/test_sizeof.wasm b/emtests/test_sizeof.wasm new file mode 100644 index 000000000..792eb5c1c Binary files /dev/null and b/emtests/test_sizeof.wasm differ diff --git a/emtests/test_sscanf.c b/emtests/test_sscanf.c new file mode 100644 index 000000000..aa38be3dc --- /dev/null +++ b/emtests/test_sscanf.c @@ -0,0 +1,100 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { +#define CHECK(str) \ + { \ + char name[1000]; \ + memset(name, 0, 1000); \ + int prio = 99; \ + sscanf(str, "%s %d", name, &prio); \ + printf("%s : %d\n", name, prio); \ + } + CHECK("en-us 2"); + CHECK("en-r"); + CHECK("en 3"); + + printf("%f, %f\n", atof("1.234567"), atof("cheez")); + + char float_formats[] = "fegE"; + char format[] = "%_"; + for (int i = 0; i < 4; ++i) { + format[1] = float_formats[i]; + + float n = -1; + sscanf(" 2.8208", format, &n); + printf("%.4f\n", n); + + float a = -1; + sscanf("-3.03", format, &a); + printf("%.4f\n", a); + } + + char buffy[100]; + sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + + int numverts = -1; + printf("%d\n", + sscanf(" numverts 1499\n", " numverts %d", + &numverts)); // white space is the same, even if tab vs space + printf("%d\n", numverts); + + int index; + float u, v; + short start, count; + printf("%d\n", + sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", + " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count)); + printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count); + + int neg, neg2, neg3 = 0; + printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); + printf("%d,%u,%d\n", neg, neg2, neg3); + + { + int a = 0; + sscanf("1", "%i", &a); + printf("%i\n", a); + } + + char buf1[100], buf2[100], buf3[100], buf4[100]; + memset(buf4, 0, 100); + + + int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%c", + 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; +} diff --git a/emtests/test_sscanf.out b/emtests/test_sscanf.out new file mode 100644 index 000000000..f9c3d4786 --- /dev/null +++ b/emtests/test_sscanf.out @@ -0,0 +1,29 @@ +en-us : 2 +en-r : 99 +en : 3 +1.234567, 0.000000 +2.8208 +-3.0300 +2.8208 +-3.0300 +2.8208 +-3.0300 +2.8208 +-3.0300 +|some| +|something| +|somethingmoar| +1 +1499 +5 +87,0.481565,0.059481,0,1 +3 +-123,4294966531,-34 +1 +4, level, 4, ref, 3 +2, def, 456 +2, 3-4, -ab +2, Hello, World +1, Hello +1, Java +2, [, ] \ No newline at end of file diff --git a/emtests/test_sscanf.wasm b/emtests/test_sscanf.wasm new file mode 100644 index 000000000..cc29ac176 Binary files /dev/null and b/emtests/test_sscanf.wasm differ diff --git a/emtests/test_sscanf_3.c b/emtests/test_sscanf_3.c new file mode 100644 index 000000000..f655132a0 --- /dev/null +++ b/emtests/test_sscanf_3.c @@ -0,0 +1,24 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + + int64_t s, m, l; + printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, + &m, &l)); + printf("%lld,%lld,%lld\n", s, m, l); + + int64_t negS, negM, negL; + printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", + &negS, &negM, &negL)); + printf("%lld,%lld,%lld\n", negS, negM, negL); + + return 0; +} diff --git a/emtests/test_sscanf_3.out b/emtests/test_sscanf_3.out new file mode 100644 index 000000000..fe1d5b418 --- /dev/null +++ b/emtests/test_sscanf_3.out @@ -0,0 +1,4 @@ +3 +123,1073741823,1125899906842620 +3 +-123,-1073741823,-1125899906842620 diff --git a/emtests/test_sscanf_3.wasm b/emtests/test_sscanf_3.wasm new file mode 100644 index 000000000..42b8398c8 Binary files /dev/null and b/emtests/test_sscanf_3.wasm differ diff --git a/emtests/test_sscanf_4.c b/emtests/test_sscanf_4.c new file mode 100644 index 000000000..2ba007a7e --- /dev/null +++ b/emtests/test_sscanf_4.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main() { + char pYear[16], pMonth[16], pDay[16], pDate[64]; + printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear)); + printf("day %s, month %s, year %s \n", pDay, pMonth, pYear); + return (0); +} diff --git a/emtests/test_sscanf_4.out b/emtests/test_sscanf_4.out new file mode 100644 index 000000000..02dba361a --- /dev/null +++ b/emtests/test_sscanf_4.out @@ -0,0 +1,2 @@ +3 +day 19, month Nov, year 2012 \ No newline at end of file diff --git a/emtests/test_sscanf_4.wasm b/emtests/test_sscanf_4.wasm new file mode 100644 index 000000000..a2adcc209 Binary files /dev/null and b/emtests/test_sscanf_4.wasm differ diff --git a/emtests/test_sscanf_5.c b/emtests/test_sscanf_5.c new file mode 100644 index 000000000..8f9556128 --- /dev/null +++ b/emtests/test_sscanf_5.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include "stdio.h" + +static const char *colors[] = {" c black", ". c #001100", "X c #111100"}; + +int main() { + unsigned char code; + char color[32]; + int rcode; + for (int i = 0; i < 3; i++) { + rcode = sscanf(colors[i], "%c c %s", &code, color); + printf("%i, %c, %s\n", rcode, code, color); + } +} diff --git a/emtests/test_sscanf_5.out b/emtests/test_sscanf_5.out new file mode 100644 index 000000000..823ae41f3 --- /dev/null +++ b/emtests/test_sscanf_5.out @@ -0,0 +1,3 @@ +2, , black +2, ., #001100 +2, X, #111100 \ No newline at end of file diff --git a/emtests/test_sscanf_5.wasm b/emtests/test_sscanf_5.wasm new file mode 100644 index 000000000..e64414157 Binary files /dev/null and b/emtests/test_sscanf_5.wasm differ diff --git a/emtests/test_sscanf_6.c b/emtests/test_sscanf_6.c new file mode 100644 index 000000000..98ddd7432 --- /dev/null +++ b/emtests/test_sscanf_6.c @@ -0,0 +1,36 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { + const char *date = "18.07.2013w"; + char c[10]; + memset(c, 0, 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); + + { + const char *date = "18.07.2013"; + char c; + int y, m, d, i; + if ((i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, &c)) == 3) + { + printf("date: %s; day %2d, month %2d, year %4d \n", date, d, m, y); + } + else + { + printf("Error in sscanf: actually parsed %d", i); + } + } +} + diff --git a/emtests/test_sscanf_6.out b/emtests/test_sscanf_6.out new file mode 100644 index 000000000..7256b03bc --- /dev/null +++ b/emtests/test_sscanf_6.out @@ -0,0 +1,3 @@ +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 +date: 18.07.2013; day 18, month 7, year 2013 diff --git a/emtests/test_sscanf_6.wasm b/emtests/test_sscanf_6.wasm new file mode 100644 index 000000000..3501c80bc Binary files /dev/null and b/emtests/test_sscanf_6.wasm differ diff --git a/emtests/test_sscanf_caps.c b/emtests/test_sscanf_caps.c new file mode 100644 index 000000000..b594e244f --- /dev/null +++ b/emtests/test_sscanf_caps.c @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include "stdio.h" + +int main() { + unsigned int a; + float e, f, g; + sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g); + printf("%d %.1F %.1F %.1F\n", a, e, f, g); +} diff --git a/emtests/test_sscanf_caps.out b/emtests/test_sscanf_caps.out new file mode 100644 index 000000000..20e20fe82 --- /dev/null +++ b/emtests/test_sscanf_caps.out @@ -0,0 +1 @@ +10 1.1 1.1 1.1 \ No newline at end of file diff --git a/emtests/test_sscanf_caps.wasm b/emtests/test_sscanf_caps.wasm new file mode 100644 index 000000000..4d3f14f43 Binary files /dev/null and b/emtests/test_sscanf_caps.wasm differ diff --git a/emtests/test_sscanf_float.c b/emtests/test_sscanf_float.c new file mode 100644 index 000000000..15ff3d2a4 --- /dev/null +++ b/emtests/test_sscanf_float.c @@ -0,0 +1,17 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include "stdio.h" + +int main() { + float f1, f2, f3, f4, f5, f6, f7, f8, f9; + sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", + "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, + &f9); + printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, + f8, f9); +} diff --git a/emtests/test_sscanf_float.out b/emtests/test_sscanf_float.out new file mode 100644 index 000000000..ea5a276d4 --- /dev/null +++ b/emtests/test_sscanf_float.out @@ -0,0 +1,2 @@ + +0.512000, 0.250000, 5.129000, -9.980000, 1.120000, 54320.000000, 54320.000000, 0.087500, 0.087500 diff --git a/emtests/test_sscanf_float.wasm b/emtests/test_sscanf_float.wasm new file mode 100644 index 000000000..09613ac7a Binary files /dev/null and b/emtests/test_sscanf_float.wasm differ diff --git a/emtests/test_sscanf_hex.cpp b/emtests/test_sscanf_hex.cpp new file mode 100644 index 000000000..11e0a54bc --- /dev/null +++ b/emtests/test_sscanf_hex.cpp @@ -0,0 +1,32 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include + +int main() +{ + unsigned int a, b; + sscanf("0x12AB 12AB", "%x %x", &a, &b); + printf("%d %d\n", a, b); + + std::string hexstr("0102037F00FF"); + const char * cstr = hexstr.c_str(); + int len = hexstr.length() / 2; + char * tmp_data = new char[len]; + for(int i = 0; i < len; i++) + { + sscanf(cstr, "%2hhx", &tmp_data[i]); + cstr += 2 * sizeof(char); + } + + for (int j = 0; j < len; j++) + printf("%i, ", tmp_data[j]); + printf("\n"); + delete[] tmp_data; +} + + diff --git a/emtests/test_sscanf_hex.out b/emtests/test_sscanf_hex.out new file mode 100644 index 000000000..6e7f66aae --- /dev/null +++ b/emtests/test_sscanf_hex.out @@ -0,0 +1,2 @@ +4779 4779 +1, 2, 3, 127, 0, -1, diff --git a/emtests/test_sscanf_hex.wasm b/emtests/test_sscanf_hex.wasm new file mode 100644 index 000000000..5e1c2cb73 Binary files /dev/null and b/emtests/test_sscanf_hex.wasm differ diff --git a/emtests/test_sscanf_n.c b/emtests/test_sscanf_n.c new file mode 100644 index 000000000..4c3f897ff --- /dev/null +++ b/emtests/test_sscanf_n.c @@ -0,0 +1,26 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int main() { + const char *line = "version 1.0"; + int i, l, lineno; + char word[80]; + if (sscanf(line, "%s%n", word, &l) != 1) { + printf("Header format error, line %d\n", lineno); + } + printf("[DEBUG] word 1: %s, l: %d\n", word, l); + + int x = sscanf("one %n two", "%s %n", word, &l); + printf("%d,%s,%d\n", x, word, l); + { + int a, b, c, count; + count = sscanf("12345 6789", "%d %n%d", &a, &b, &c); + printf("%i %i %i %i\n", count, a, b, c); + } + return 0; +} diff --git a/emtests/test_sscanf_n.out b/emtests/test_sscanf_n.out new file mode 100644 index 000000000..c3ce6f046 --- /dev/null +++ b/emtests/test_sscanf_n.out @@ -0,0 +1,3 @@ +[DEBUG] word 1: version, l: 7 +1,one,4 +2 12345 6 6789 diff --git a/emtests/test_sscanf_n.wasm b/emtests/test_sscanf_n.wasm new file mode 100644 index 000000000..d699770c5 Binary files /dev/null and b/emtests/test_sscanf_n.wasm differ diff --git a/emtests/test_sscanf_other_whitespace.c b/emtests/test_sscanf_other_whitespace.c new file mode 100644 index 000000000..b3bde3771 --- /dev/null +++ b/emtests/test_sscanf_other_whitespace.c @@ -0,0 +1,30 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main() { + int x; + int y; + + const char* buffer[] = { + "\t2\t3\t", /* TAB - horizontal tab */ + "\t\t5\t\t7\t\t", "\n11\n13\n", /* LF - line feed */ + "\n\n17\n\n19\n\n", "\v23\v29\v", /* VT - vertical tab */ + "\v\v31\v\v37\v\v", "\f41\f43\f", /* FF - form feed */ + "\f\f47\f\f53\f\f", "\r59\r61\r", /* CR - carrage return */ + "\r\r67\r\r71\r\r"}; + + for (int i = 0; i < 10; ++i) { + x = 0; + y = 0; + sscanf(buffer[i], " %d %d ", &x, &y); + printf("%d, %d, ", x, y); + } + + return 0; +} diff --git a/emtests/test_sscanf_other_whitespace.out b/emtests/test_sscanf_other_whitespace.out new file mode 100644 index 000000000..0d0f4bebf --- /dev/null +++ b/emtests/test_sscanf_other_whitespace.out @@ -0,0 +1 @@ +2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, \ No newline at end of file diff --git a/emtests/test_sscanf_other_whitespace.wasm b/emtests/test_sscanf_other_whitespace.wasm new file mode 100644 index 000000000..5c8301ac2 Binary files /dev/null and b/emtests/test_sscanf_other_whitespace.wasm differ diff --git a/emtests/test_sscanf_skip.c b/emtests/test_sscanf_skip.c new file mode 100644 index 000000000..0f09db4ce --- /dev/null +++ b/emtests/test_sscanf_skip.c @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + int val1; + printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1)); + printf("%d\n", val1); + + int64_t large, val2; + printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", + "%lld %*lld %lld %*d", &large, &val2)); + printf("%lld,%lld\n", large, val2); + + return 0; +} diff --git a/emtests/test_sscanf_skip.out b/emtests/test_sscanf_skip.out new file mode 100644 index 000000000..cf1cdfb8e --- /dev/null +++ b/emtests/test_sscanf_skip.out @@ -0,0 +1,4 @@ +1 +30 +2 +1000000,-123 diff --git a/emtests/test_sscanf_skip.wasm b/emtests/test_sscanf_skip.wasm new file mode 100644 index 000000000..ac151b825 Binary files /dev/null and b/emtests/test_sscanf_skip.wasm differ diff --git a/emtests/test_sscanf_whitespace.c b/emtests/test_sscanf_whitespace.c new file mode 100644 index 000000000..425bab619 --- /dev/null +++ b/emtests/test_sscanf_whitespace.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main() { + short int x; + short int y; + + const char* buffer[] = {"173,16", " 16,173", "183, 173", + " 17, 287", " 98, 123, "}; + + for (int i = 0; i < 5; ++i) { + sscanf(buffer[i], "%hd,%hd", &x, &y); + printf("%d:%d,%d ", i, x, y); + } + + return 0; +} diff --git a/emtests/test_sscanf_whitespace.out b/emtests/test_sscanf_whitespace.out new file mode 100644 index 000000000..9a26dd1d4 --- /dev/null +++ b/emtests/test_sscanf_whitespace.out @@ -0,0 +1 @@ +0:173,16 1:16,173 2:183,173 3:17,287 4:98,123 \ No newline at end of file diff --git a/emtests/test_sscanf_whitespace.wasm b/emtests/test_sscanf_whitespace.wasm new file mode 100644 index 000000000..9766b2c27 Binary files /dev/null and b/emtests/test_sscanf_whitespace.wasm differ diff --git a/emtests/test_stack.c b/emtests/test_stack.c new file mode 100644 index 000000000..cec1417a8 --- /dev/null +++ b/emtests/test_stack.c @@ -0,0 +1,27 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +int test(int i) { + int x = 10; + int ret = reinterpret_cast(&x); // both for the number, and forces x to not be nativized + if (i > 0) { + if ((i % 2001) != 1500) + return test(i - 1); + else + return test(i - 1) + test(i - 2); + } + return ret; +} +int main(int argc, char **argv) { + // We should get the same value for the first and last - stack has unwound + int x1 = test(argc - 2); + int x2 = test(100); + int x3 = test((argc - 2) / 4); + printf("*%d,%d*\n", x3 - x1, x2 != x1); + return 0; +} diff --git a/emtests/test_stack.out b/emtests/test_stack.out new file mode 100644 index 000000000..687e8ad64 --- /dev/null +++ b/emtests/test_stack.out @@ -0,0 +1 @@ +*0,1* \ No newline at end of file diff --git a/emtests/test_stack_align.cpp b/emtests/test_stack_align.cpp new file mode 100644 index 000000000..58775f0aa --- /dev/null +++ b/emtests/test_stack_align.cpp @@ -0,0 +1,34 @@ +// Copyright 2014 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +#define ALIGN(num_bytes) __attribute__((aligned(num_bytes))) + +struct Aligned { + char ALIGN(4) a4; + char ALIGN(8) a8; + char ALIGN(16) a16; + char ALIGN(32) a32; +}; + +__attribute__((noinline)) +void Test(const void* p, int size) { + printf("align %d: %d\n", size, reinterpret_cast(p) % size); +} + +int main() { + Aligned a; + Test(&a.a4, 4); + Test(&a.a8, 8); + Test(&a.a16, 16); + Test(&a.a32, 32); + + int p = reinterpret_cast(&a); + printf("base align: %d, %d, %d, %d\n", p%4, p%8, p%16, p%32); + + return 0; +} + diff --git a/emtests/test_stack_align.wasm b/emtests/test_stack_align.wasm new file mode 100644 index 000000000..a4dbce9fc Binary files /dev/null and b/emtests/test_stack_align.wasm differ diff --git a/emtests/test_stack_byval.c b/emtests/test_stack_byval.c new file mode 100644 index 000000000..51084a775 --- /dev/null +++ b/emtests/test_stack_byval.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +// We should also not blow up the stack with byval arguments +#include +struct vec { + int x, y, z; + vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {} + static vec add(vec a, vec b) { return vec(a.x + b.x, a.y + b.y, a.z + b.z); } +}; +int main() { + int total = 0; + for (int i = 0; i < 1000; i++) { + for (int j = 0; j < 1000; j++) { + vec c(i + i % 10, j * 2, i % 255); + vec d(j * 2, j % 255, i % 120); + vec f = vec::add(c, d); + total += (f.x + f.y + f.z) % 100; + total %= 10240; + } + } + printf("sum:%d*\n", total); + return 0; +} diff --git a/emtests/test_stack_byval.out b/emtests/test_stack_byval.out new file mode 100644 index 000000000..62f1b081b --- /dev/null +++ b/emtests/test_stack_byval.out @@ -0,0 +1 @@ +sum:9780* \ No newline at end of file diff --git a/emtests/test_stack_restore.c b/emtests/test_stack_restore.c new file mode 100644 index 000000000..8b4478240 --- /dev/null +++ b/emtests/test_stack_restore.c @@ -0,0 +1,37 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +extern "C" { + +__attribute__((noinline)) int no_stack_usage(void) { + return 6; +} + +__attribute__((noinline)) int alloca_gets_restored(int count) { + char *buf = (char*)alloca(count); + sprintf(buf, "%d", 6444); + return strlen(buf); +} + +__attribute__((noinline)) int stack_usage(void) { + char buf[1024]; + sprintf(buf, "%d", 60); + return strlen(buf); +} + +int main(int argc, char **argv) { + printf("%d\n", no_stack_usage()); + printf("%d\n", alloca_gets_restored(200)); + printf("%d\n", stack_usage()); + return 0; +} + +} diff --git a/emtests/test_stack_restore.out b/emtests/test_stack_restore.out new file mode 100644 index 000000000..02c399868 --- /dev/null +++ b/emtests/test_stack_restore.out @@ -0,0 +1,3 @@ +6 +4 +2 diff --git a/emtests/test_stack_varargs.c b/emtests/test_stack_varargs.c new file mode 100644 index 000000000..a815f5fa4 --- /dev/null +++ b/emtests/test_stack_varargs.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +// We should not blow up the stack with numerous varargs +#include +#include + +void func(int i) { + printf( + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d," + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", + i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, + i, i, i, i, i, i, i, i, i, i, i, i, i, i); +} +int main() { + for (int i = 0; i < 1024; i++) func(i); + printf("ok!\n"); + return 0; +} diff --git a/emtests/test_stack_varargs.out b/emtests/test_stack_varargs.out new file mode 100644 index 000000000..e036282ac --- /dev/null +++ b/emtests/test_stack_varargs.out @@ -0,0 +1 @@ +ok! \ No newline at end of file diff --git a/emtests/test_stack_varargs.wasm b/emtests/test_stack_varargs.wasm new file mode 100644 index 000000000..080b557a7 Binary files /dev/null and b/emtests/test_stack_varargs.wasm differ diff --git a/emtests/test_stack_void.c b/emtests/test_stack_void.c new file mode 100644 index 000000000..b9ba92184 --- /dev/null +++ b/emtests/test_stack_void.c @@ -0,0 +1,41 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +static char s[100] = "aaaaa"; +static int func(void) { + if (s[0] != 'a') return 0; + printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001); + return 0; +} +int main() { + int i; + for (i = 0; i < 5000; i++) func(); + printf(".ok.\n"); +} diff --git a/emtests/test_stack_void.out b/emtests/test_stack_void.out new file mode 100644 index 000000000..c8e99c4e8 --- /dev/null +++ b/emtests/test_stack_void.out @@ -0,0 +1 @@ +.ok. diff --git a/emtests/test_stack_void.wasm b/emtests/test_stack_void.wasm new file mode 100644 index 000000000..b13ab4556 Binary files /dev/null and b/emtests/test_stack_void.wasm differ diff --git a/emtests/test_static_variable.c b/emtests/test_static_variable.c new file mode 100644 index 000000000..0659df494 --- /dev/null +++ b/emtests/test_static_variable.c @@ -0,0 +1,25 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +struct DATA { + int value; + + DATA() { value = 0; } +}; + +DATA& GetData() { + static DATA data; + + return data; +} + +int main() { + GetData().value = 10; + printf("value:%i", GetData().value); +} diff --git a/emtests/test_static_variable.out b/emtests/test_static_variable.out new file mode 100644 index 000000000..8ab80f3b2 --- /dev/null +++ b/emtests/test_static_variable.out @@ -0,0 +1 @@ +value:10 \ No newline at end of file diff --git a/emtests/test_statics.c b/emtests/test_statics.c new file mode 100644 index 000000000..dab5a936c --- /dev/null +++ b/emtests/test_statics.c @@ -0,0 +1,42 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +#define CONSTRLEN 32 + +char *(*func)(char *, const char *) = NULL; + +void conoutfv(const char *fmt) { + static char buf[CONSTRLEN]; + func(buf, fmt); // call by function pointer to make sure we test strcpy here + puts(buf); +} + +struct XYZ { + float x, y, z; + XYZ(float a, float b, float c) : x(a), y(b), z(c) {} + static const XYZ &getIdentity() { + static XYZ iT(1, 2, 3); + return iT; + } +}; +struct S { + static const XYZ &getIdentity() { + static const XYZ iT(XYZ::getIdentity()); + return iT; + } +}; + +int main() { + func = &strcpy; + conoutfv("*staticccz*"); + printf("*%.2f,%.2f,%.2f*\n", S::getIdentity().x, S::getIdentity().y, + S::getIdentity().z); + return 0; +} diff --git a/emtests/test_statics.out b/emtests/test_statics.out new file mode 100644 index 000000000..c34f2cb6a --- /dev/null +++ b/emtests/test_statics.out @@ -0,0 +1,2 @@ +*staticccz* +*1.00,2.00,3.00* \ No newline at end of file diff --git a/emtests/test_statvfs.c b/emtests/test_statvfs.c new file mode 100644 index 000000000..9a879396c --- /dev/null +++ b/emtests/test_statvfs.c @@ -0,0 +1,31 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + struct statvfs s; + + printf("result: %d\n", statvfs("/test", &s)); + printf("errno: %d\n", errno); + + printf("f_bsize: %lu\n", s.f_bsize); + printf("f_frsize: %lu\n", s.f_frsize); + printf("f_blocks: %lu\n", s.f_blocks); + printf("f_bfree: %lu\n", s.f_bfree); + printf("f_bavail: %lu\n", s.f_bavail); + printf("f_files: %d\n", s.f_files > 5); + printf("f_ffree: %lu\n", s.f_ffree); + printf("f_favail: %lu\n", s.f_favail); + printf("f_fsid: %lu\n", s.f_fsid); + printf("f_flag: %lu\n", s.f_flag); + printf("f_namemax: %lu\n", s.f_namemax); + + return 0; +} diff --git a/emtests/test_statvfs.out b/emtests/test_statvfs.out new file mode 100644 index 000000000..8c414d094 --- /dev/null +++ b/emtests/test_statvfs.out @@ -0,0 +1,13 @@ +result: 0 +errno: 0 +f_bsize: 4096 +f_frsize: 4096 +f_blocks: 1000000 +f_bfree: 500000 +f_bavail: 500000 +f_files: 1 +f_ffree: 1000000 +f_favail: 1000000 +f_fsid: 42 +f_flag: 2 +f_namemax: 255 diff --git a/emtests/test_statvfs.wasm b/emtests/test_statvfs.wasm new file mode 100644 index 000000000..116a57c82 Binary files /dev/null and b/emtests/test_statvfs.wasm differ diff --git a/emtests/test_std_cout_new.cpp b/emtests/test_std_cout_new.cpp new file mode 100644 index 000000000..b475a8247 --- /dev/null +++ b/emtests/test_std_cout_new.cpp @@ -0,0 +1,26 @@ +// Copyright 2016 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +struct NodeInfo { // structure that we want to transmit to our shaders + float x; + float y; + float s; + float c; +}; +const int nbNodes = 100; +NodeInfo* data = new NodeInfo[nbNodes]; // our data that will be transmitted + // using float texture. + +template +void printText(const char (&text)[i]) { + std::cout << text << std::endl; +} + +int main() { + printText("some string constant"); + return 0; +} diff --git a/emtests/test_std_cout_new.out b/emtests/test_std_cout_new.out new file mode 100644 index 000000000..ddb4b681d --- /dev/null +++ b/emtests/test_std_cout_new.out @@ -0,0 +1 @@ +some string constant \ No newline at end of file diff --git a/emtests/test_std_cout_new.wasm b/emtests/test_std_cout_new.wasm new file mode 100644 index 000000000..8a154c5cd Binary files /dev/null and b/emtests/test_std_cout_new.wasm differ diff --git a/emtests/test_stdlibs.c b/emtests/test_stdlibs.c new file mode 100644 index 000000000..0dba652d9 --- /dev/null +++ b/emtests/test_stdlibs.c @@ -0,0 +1,59 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +void clean() +{ + printf("*cleaned*\n"); +} + +int comparer(const void *a, const void *b) { + int aa = *((int*)a); + int bb = *((int*)b); + return aa - bb; +} + +int main() { + // timeofday + timeval t; + gettimeofday(&t, NULL); + printf("*%d,%d\n", int(t.tv_sec), int(t.tv_usec)); // should not crash + + // atexit + atexit(clean); + + // qsort + int values[6] = { 3, 2, 5, 1, 5, 6 }; + qsort(values, 5, sizeof(int), comparer); + printf("*%d,%d,%d,%d,%d,%d*\n", values[0], values[1], values[2], values[3], values[4], values[5]); + + printf("*stdin==0:%d*\n", stdin == 0); // check that external values are at least not NULL + printf("*%%*\n"); + printf("*%.1ld*\n", 5); + + printf("*%.1f*\n", strtod("66", NULL)); // checks dependency system, as our strtod needs _isspace etc. + + printf("*%ld*\n", strtol("10", NULL, 0)); + printf("*%ld*\n", strtol("0", NULL, 0)); + printf("*%ld*\n", strtol("-10", NULL, 0)); + printf("*%ld*\n", strtol("12", NULL, 16)); + + printf("*%lu*\n", strtoul("10", NULL, 0)); + printf("*%lu*\n", strtoul("0", NULL, 0)); + printf("*%lu*\n", strtoul("-10", NULL, 0)); + + malloc(0); + printf("*malloc(0) does not fail horribly (spec allows 0 or non-zero)*\n"); + + printf("tolower_l: %c\n", tolower_l('A', 0)); + + return 0; +} diff --git a/emtests/test_stdlibs.out b/emtests/test_stdlibs.out new file mode 100644 index 000000000..432bad5da --- /dev/null +++ b/emtests/test_stdlibs.out @@ -0,0 +1,15 @@ +*1,2,3,5,5,6* +*stdin==0:0* +*%* +*5* +*66.0* +*10* +*0* +*-10* +*18* +*10* +*0* +*4294967286* +*malloc(0) does not fail horribly (spec allows 0 or non-zero)* +tolower_l: a +*cleaned* diff --git a/emtests/test_stdvec.c b/emtests/test_stdvec.c new file mode 100644 index 000000000..1a54d7f38 --- /dev/null +++ b/emtests/test_stdvec.c @@ -0,0 +1,32 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +struct S { + int a; + float b; +}; + +void foo(int a, float b) { printf("%d:%.2f\n", a, b); } + +int main(int argc, char *argv[]) { + std::vector ar; + S s; + + s.a = 789; + s.b = 123.456f; + ar.push_back(s); + + s.a = 0; + s.b = 100.1f; + ar.push_back(s); + + foo(ar[0].a, ar[0].b); + foo(ar[1].a, ar[1].b); +} diff --git a/emtests/test_stdvec.out b/emtests/test_stdvec.out new file mode 100644 index 000000000..cb3a61fce --- /dev/null +++ b/emtests/test_stdvec.out @@ -0,0 +1,2 @@ +789:123.46 +0:100.1 \ No newline at end of file diff --git a/emtests/test_strcasecmp.c b/emtests/test_strcasecmp.c new file mode 100644 index 000000000..c38b4bfd8 --- /dev/null +++ b/emtests/test_strcasecmp.c @@ -0,0 +1,86 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int sign(int x) { + if (x < 0) return -1; + if (x > 0) return 1; + return 0; +} +int main() { + printf("*\n"); + + printf("%d\n", sign(strcasecmp("hello", "hello"))); + printf("%d\n", sign(strcasecmp("hello1", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "hello1"))); + printf("%d\n", sign(strcasecmp("hello1", "hello1"))); + printf("%d\n", sign(strcasecmp("iello", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "iello"))); + printf("%d\n", sign(strcasecmp("A", "hello"))); + printf("%d\n", sign(strcasecmp("Z", "hello"))); + printf("%d\n", sign(strcasecmp("a", "hello"))); + printf("%d\n", sign(strcasecmp("z", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "a"))); + printf("%d\n", sign(strcasecmp("hello", "z"))); + + printf("%d\n", sign(strcasecmp("Hello", "hello"))); + printf("%d\n", sign(strcasecmp("Hello1", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "hello1"))); + printf("%d\n", sign(strcasecmp("Hello1", "hello1"))); + printf("%d\n", sign(strcasecmp("Iello", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "iello"))); + printf("%d\n", sign(strcasecmp("A", "hello"))); + printf("%d\n", sign(strcasecmp("Z", "hello"))); + printf("%d\n", sign(strcasecmp("a", "hello"))); + printf("%d\n", sign(strcasecmp("z", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "a"))); + printf("%d\n", sign(strcasecmp("Hello", "z"))); + + printf("%d\n", sign(strcasecmp("hello", "Hello"))); + printf("%d\n", sign(strcasecmp("hello1", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "Hello1"))); + printf("%d\n", sign(strcasecmp("hello1", "Hello1"))); + printf("%d\n", sign(strcasecmp("iello", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "Iello"))); + printf("%d\n", sign(strcasecmp("A", "Hello"))); + printf("%d\n", sign(strcasecmp("Z", "Hello"))); + printf("%d\n", sign(strcasecmp("a", "Hello"))); + printf("%d\n", sign(strcasecmp("z", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "a"))); + printf("%d\n", sign(strcasecmp("hello", "z"))); + + printf("%d\n", sign(strcasecmp("Hello", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello1", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "Hello1"))); + printf("%d\n", sign(strcasecmp("Hello1", "Hello1"))); + printf("%d\n", sign(strcasecmp("Iello", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "Iello"))); + printf("%d\n", sign(strcasecmp("A", "Hello"))); + printf("%d\n", sign(strcasecmp("Z", "Hello"))); + printf("%d\n", sign(strcasecmp("a", "Hello"))); + printf("%d\n", sign(strcasecmp("z", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "a"))); + printf("%d\n", sign(strcasecmp("Hello", "z"))); + + printf("%d\n", sign(strncasecmp("hello", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello1", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "hello1", 3))); + printf("%d\n", sign(strncasecmp("hello1", "hello1", 3))); + printf("%d\n", sign(strncasecmp("iello", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "iello", 3))); + printf("%d\n", sign(strncasecmp("A", "hello", 3))); + printf("%d\n", sign(strncasecmp("Z", "hello", 3))); + printf("%d\n", sign(strncasecmp("a", "hello", 3))); + printf("%d\n", sign(strncasecmp("z", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "a", 3))); + printf("%d\n", sign(strncasecmp("hello", "z", 3))); + + printf("*\n"); + + return 0; +} diff --git a/emtests/test_strcasecmp.out b/emtests/test_strcasecmp.out new file mode 100644 index 000000000..b572c269d --- /dev/null +++ b/emtests/test_strcasecmp.out @@ -0,0 +1,62 @@ +* +0 +1 +-1 +0 +1 +-1 +-1 +1 +-1 +1 +1 +-1 +0 +1 +-1 +0 +1 +-1 +-1 +1 +-1 +1 +1 +-1 +0 +1 +-1 +0 +1 +-1 +-1 +1 +-1 +1 +1 +-1 +0 +1 +-1 +0 +1 +-1 +-1 +1 +-1 +1 +1 +-1 +0 +0 +0 +0 +1 +-1 +-1 +1 +-1 +1 +1 +-1 +* diff --git a/emtests/test_strcasecmp.wasm b/emtests/test_strcasecmp.wasm new file mode 100644 index 000000000..d3fbe9f9a Binary files /dev/null and b/emtests/test_strcasecmp.wasm differ diff --git a/emtests/test_strcmp_uni.c b/emtests/test_strcmp_uni.c new file mode 100644 index 000000000..7f1ca4d35 --- /dev/null +++ b/emtests/test_strcmp_uni.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { +#define TEST(func) \ + { \ + char *word = (char*)"WORD"; \ + char wordEntry[2] = {-61, -126}; /* "Â"; */ \ + int cmp = func(word, wordEntry, 2); \ + if (cmp < 0) cmp = -1; \ + else if (cmp > 0) cmp = 1; \ + printf("Compare value " #func " is %d\n", cmp); \ + } + TEST(strncmp); + TEST(strncasecmp); + TEST(memcmp); +} diff --git a/emtests/test_strcmp_uni.out b/emtests/test_strcmp_uni.out new file mode 100644 index 000000000..58e237d76 --- /dev/null +++ b/emtests/test_strcmp_uni.out @@ -0,0 +1,3 @@ +Compare value strncmp is -1 +Compare value strncasecmp is -1 +Compare value memcmp is -1 diff --git a/emtests/test_strcmp_uni.wasm b/emtests/test_strcmp_uni.wasm new file mode 100644 index 000000000..8a6fde118 Binary files /dev/null and b/emtests/test_strcmp_uni.wasm differ diff --git a/emtests/test_strftime.cpp b/emtests/test_strftime.cpp new file mode 100644 index 000000000..2694565b0 --- /dev/null +++ b/emtests/test_strftime.cpp @@ -0,0 +1,185 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +void test(int result, const char* comment, const char* parsed = "") { + printf("%s: %d\n", comment, result); + if (!result) { + printf("\nERROR: %s (\"%s\")\n", comment, parsed); +#ifdef REPORT_RESULT + abort(); +#endif + } +} + +int cmp(const char* s1, const char* s2) { + for (; *s1 == *s2; s1++, s2++) { + if (*s1 == '\0') break; + } + + return (*s1 - *s2); +} + +int main() { + struct tm tm; + char s[1000]; + size_t size; + + tm.tm_sec = 4; + tm.tm_min = 23; + tm.tm_hour = 20; + tm.tm_mday = 21; + tm.tm_mon = 1; + tm.tm_year = 74; + tm.tm_wday = 4; + tm.tm_yday = 51; + tm.tm_isdst = 0; + + size = strftime(s, 1000, "", &tm); + test((size == 0) && (*s == '\0'), "strftime test #1", s); + + size = strftime(s, 1000, "%a", &tm); + test((size == 3) && !cmp(s, "Thu"), "strftime test #2", s); + + size = strftime(s, 1000, "%A", &tm); + test((size == 8) && !cmp(s, "Thursday"), "strftime test #3", s); + + size = strftime(s, 1000, "%b", &tm); + test((size == 3) && !cmp(s, "Feb"), "strftime test #4", s); + + size = strftime(s, 1000, "%B", &tm); + test((size == 8) && !cmp(s, "February"), "strftime test #5", s); + + size = strftime(s, 1000, "%d", &tm); + test((size == 2) && !cmp(s, "21"), "strftime test #6", s); + + size = strftime(s, 1000, "%H", &tm); + test((size == 2) && !cmp(s, "20"), "strftime test #7", s); + + size = strftime(s, 1000, "%I", &tm); + test((size == 2) && !cmp(s, "08"), "strftime test #8", s); + + size = strftime(s, 1000, "%j", &tm); + test((size == 3) && !cmp(s, "052"), "strftime test #9", s); + + size = strftime(s, 1000, "%m", &tm); + test((size == 2) && !cmp(s, "02"), "strftime test #10", s); + + size = strftime(s, 1000, "%M", &tm); + test((size == 2) && !cmp(s, "23"), "strftime test #11", s); + + size = strftime(s, 1000, "%p", &tm); + test((size == 2) && !cmp(s, "PM"), "strftime test #12", s); + + size = strftime(s, 1000, "%S", &tm); + test((size == 2) && !cmp(s, "04"), "strftime test #13", s); + + size = strftime(s, 1000, "%U", &tm); + test((size == 2) && !cmp(s, "07"), "strftime test #14", s); + + size = strftime(s, 1000, "%w", &tm); + test((size == 1) && !cmp(s, "4"), "strftime test #15", s); + + size = strftime(s, 1000, "%W", &tm); + test((size == 2) && !cmp(s, "07"), "strftime test #16", s); + + size = strftime(s, 1000, "%y", &tm); + test((size == 2) && !cmp(s, "74"), "strftime test #17", s); + + size = strftime(s, 1000, "%Y", &tm); + test((size == 4) && !cmp(s, "1974"), "strftime test #18", s); + + size = strftime(s, 1000, "%%", &tm); + test((size == 1) && !cmp(s, "%"), "strftime test #19", s); + + size = strftime(s, 5, "%Y", &tm); + test((size == 4) && !cmp(s, "1974"), "strftime test #20", s); + + size = strftime(s, 4, "%Y", &tm); + test((size == 0), "strftime test #21", s); + + tm.tm_mon = 0; + tm.tm_mday = 1; + size = strftime(s, 10, "%U", &tm); + test((size == 2) && !cmp(s, "00"), "strftime test #22", s); + + size = strftime(s, 10, "%W", &tm); + test((size == 2) && !cmp(s, "00"), "strftime test #23", s); + + // 1/1/1973 was a Sunday and is in CW 1 + tm.tm_year = 73; + size = strftime(s, 10, "%W", &tm); + test((size == 2) && !cmp(s, "01"), "strftime test #24", s); + + // 1/1/1978 was a Monday and is in CW 1 + tm.tm_year = 78; + size = strftime(s, 10, "%U", &tm); + test((size == 2) && !cmp(s, "01"), "strftime test #25", s); + + // 2/1/1999 + tm.tm_year = 99; + tm.tm_yday = 1; + size = strftime(s, 10, "%G (%V)", &tm); + test((size == 9) && !cmp(s, "1998 (53)"), "strftime test #26", s); + + size = strftime(s, 10, "%g", &tm); + test((size == 2) && !cmp(s, "98"), "strftime test #27", s); + + // 30/12/1997 + tm.tm_year = 97; + tm.tm_yday = 363; + size = strftime(s, 10, "%G (%V)", &tm); + test((size == 9) && !cmp(s, "1998 (01)"), "strftime test #28", s); + + size = strftime(s, 10, "%g", &tm); + test((size == 2) && !cmp(s, "98"), "strftime test #29", s); + + // timezones + time_t xmas2002 = 1040786563ll; + time_t summer2002 = 1025528525ll; + localtime_r(&summer2002, &tm); + int ahead = timegm(&tm) >= summer2002; + size = strftime(s, 50, "%z", &tm); + test((size == 5) && strchr(s, ahead ? '+' : '-'), "strftime zone test #1", s); + size = strftime(s, 50, "%Z", &tm); + test(strcmp(s, tzname[tm.tm_isdst]) == 0, "strftime zone test #2", s); + + localtime_r(&xmas2002, &tm); + ahead = timegm(&tm) >= xmas2002; + size = strftime(s, 50, "%z", &tm); + test((size == 5) && strchr(s, ahead ? '+' : '-'), "strftime zone test #3", s); + size = strftime(s, 50, "%Z", &tm); + test(strcmp(s, tzname[tm.tm_isdst]) == 0, "strftime zone test #4", s); + + // AM/PM + tm.tm_sec = 0; + tm.tm_min = 0; + + tm.tm_hour = 0; + size = strftime(s, 10, "%I %p", &tm); + test(!cmp(s, "12 AM"), "strftime test #32", s); + + tm.tm_hour = 12; + size = strftime(s, 10, "%I %p", &tm); + test(!cmp(s, "12 PM"), "strftime test #33", s); + + tm.tm_min = 1; + + tm.tm_hour = 0; + size = strftime(s, 10, "%I %M %p", &tm); + test(!cmp(s, "12 01 AM"), "strftime test #34", s); + + tm.tm_hour = 12; + size = strftime(s, 10, "%I %M %p", &tm); + test(!cmp(s, "12 01 PM"), "strftime test #35", s); + +#ifdef REPORT_RESULT + REPORT_RESULT(0); +#endif +} diff --git a/emtests/test_strftime.out b/emtests/test_strftime.out new file mode 100644 index 000000000..1ff67172a --- /dev/null +++ b/emtests/test_strftime.out @@ -0,0 +1,37 @@ +strftime test #1: 1 +strftime test #2: 1 +strftime test #3: 1 +strftime test #4: 1 +strftime test #5: 1 +strftime test #6: 1 +strftime test #7: 1 +strftime test #8: 1 +strftime test #9: 1 +strftime test #10: 1 +strftime test #11: 1 +strftime test #12: 1 +strftime test #13: 1 +strftime test #14: 1 +strftime test #15: 1 +strftime test #16: 1 +strftime test #17: 1 +strftime test #18: 1 +strftime test #19: 1 +strftime test #20: 1 +strftime test #21: 1 +strftime test #22: 1 +strftime test #23: 1 +strftime test #24: 1 +strftime test #25: 1 +strftime test #26: 1 +strftime test #27: 1 +strftime test #28: 1 +strftime test #29: 1 +strftime zone test #1: 1 +strftime zone test #2: 1 +strftime zone test #3: 1 +strftime zone test #4: 1 +strftime test #32: 1 +strftime test #33: 1 +strftime test #34: 1 +strftime test #35: 1 diff --git a/emtests/test_strftime.wasm b/emtests/test_strftime.wasm new file mode 100644 index 000000000..64b28dd4d Binary files /dev/null and b/emtests/test_strftime.wasm differ diff --git a/emtests/test_strings.c b/emtests/test_strings.c new file mode 100644 index 000000000..c010d5718 --- /dev/null +++ b/emtests/test_strings.c @@ -0,0 +1,61 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main(int argc, char **argv) { + int x = 5, y = 9, magic = 7; // fool compiler with magic + memmove(&x, &y, magic - 7); // 0 should not crash us + + int xx, yy, zz; + char s[32]; + 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); + puts(argv[1]); + puts(argv[2]); + printf("%d\n", atoi(argv[3]) + 2); + const char *foolingthecompiler = "\rabcd"; + printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - + // should not be a 0 (end string) + // then a D! + printf("%s\n", NULL); // Should print '(null)', not the string at address 0, + // which is a real address for us! + printf("/* a comment */\n"); // Should not break the generated code! + printf("// another\n"); // Should not break the generated code! + + char *strdup_val = strdup("test"); + printf("%s\n", strdup_val); + free(strdup_val); + + { + char *one = "one 1 ONE !"; + char *two = "two 2 TWO ?"; + char three[1024]; + memset(three, '.', 1024); + three[50] = 0; + strncpy(three + argc, one + (argc / 2), argc + 1); + strncpy(three + argc * 3, two + (argc / 3), argc + 2); + printf("waka %s\n", three); + } + + { + char *one = "string number one top notch"; + char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO"; + char three[1000]; + strcpy(three, &one[argc * 2]); + char *four = strcat(three, &two[argc * 3]); + printf("cat |%s|\n", three); + printf("returned |%s|\n", four); + } + + return 0; +} diff --git a/emtests/test_strings.out b/emtests/test_strings.out new file mode 100644 index 000000000..ddf9aee7b --- /dev/null +++ b/emtests/test_strings.out @@ -0,0 +1,13 @@ +4:10,177,543,def +4 +wowie +too +76 +5 +(null) +/* a comment */ +// another +test +waka ....e 1 O...wo 2 T................................ +cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO| +returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO| \ No newline at end of file diff --git a/emtests/test_strings.wasm b/emtests/test_strings.wasm new file mode 100644 index 000000000..fbf12fc94 Binary files /dev/null and b/emtests/test_strings.wasm differ diff --git a/emtests/test_strndup.c b/emtests/test_strndup.c new file mode 100644 index 000000000..3fcd39c9d --- /dev/null +++ b/emtests/test_strndup.c @@ -0,0 +1,45 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +//--------------- +//- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html +//--------------- + +#include +#include +#include + +int main(int argc, char** argv) { + const char* source = + "strndup - duplicate a specific number of bytes from a string"; + + char* strdup_val = strndup(source, 0); + printf("1:%s\n", strdup_val); + free(strdup_val); + + strdup_val = strndup(source, 7); + printf("2:%s\n", strdup_val); + free(strdup_val); + + strdup_val = strndup(source, 1000); + printf("3:%s\n", strdup_val); + free(strdup_val); + + strdup_val = strndup(source, 60); + printf("4:%s\n", strdup_val); + free(strdup_val); + + strdup_val = strndup(source, 19); + printf("5:%s\n", strdup_val); + free(strdup_val); + + strdup_val = strndup(source, -1); + printf("6:%s\n", strdup_val); + free(strdup_val); + + return 0; +} diff --git a/emtests/test_strndup.out b/emtests/test_strndup.out new file mode 100644 index 000000000..f86db64e4 --- /dev/null +++ b/emtests/test_strndup.out @@ -0,0 +1,6 @@ +1: +2:strndup +3:strndup - duplicate a specific number of bytes from a string +4:strndup - duplicate a specific number of bytes from a string +5:strndup - duplicate +6:strndup - duplicate a specific number of bytes from a string diff --git a/emtests/test_strndup.wasm b/emtests/test_strndup.wasm new file mode 100644 index 000000000..bd7fe6c9b Binary files /dev/null and b/emtests/test_strndup.wasm differ diff --git a/emtests/test_strptime_days.c b/emtests/test_strptime_days.c new file mode 100644 index 000000000..ff861cc07 --- /dev/null +++ b/emtests/test_strptime_days.c @@ -0,0 +1,39 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +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); + } +} diff --git a/emtests/test_strptime_days.out b/emtests/test_strptime_days.out new file mode 100644 index 000000000..dc4090326 --- /dev/null +++ b/emtests/test_strptime_days.out @@ -0,0 +1,12 @@ +OK: 1/1/2000 (6th DoW, 0th DoY) +OK: 3/3/2000 (5th DoW, 62th DoY) +OK: 9/9/1999 (4th DoW, 251th DoY) +OK: 5/2/1999 (0th DoW, 121th DoY) +OK: 5/21/2001 (1th DoW, 140th DoY) +OK: 1/27/2006 (5th DoW, 26th DoY) +OK: 5/21/2001 (1th DoW, 140th DoY) +OK: 7/24/2013 (3th DoW, 204th DoY) +OK: 1/1/2000 (6th DoW, 0th DoY) +OK: 1/1/2000 (6th DoW, 0th DoY) +OK: 5/1/2001 (2th DoW, 120th DoY) +OK: 2/22/2001 (4th DoW, 52th DoY) diff --git a/emtests/test_strptime_days.wasm b/emtests/test_strptime_days.wasm new file mode 100644 index 000000000..c8359d48a Binary files /dev/null and b/emtests/test_strptime_days.wasm differ diff --git a/emtests/test_strptime_reentrant.c b/emtests/test_strptime_reentrant.c new file mode 100644 index 000000000..729b0799a --- /dev/null +++ b/emtests/test_strptime_reentrant.c @@ -0,0 +1,52 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include + +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"); +} diff --git a/emtests/test_strptime_reentrant.out b/emtests/test_strptime_reentrant.out new file mode 100644 index 000000000..a0aba9318 --- /dev/null +++ b/emtests/test_strptime_reentrant.out @@ -0,0 +1 @@ +OK \ No newline at end of file diff --git a/emtests/test_strptime_reentrant.wasm b/emtests/test_strptime_reentrant.wasm new file mode 100644 index 000000000..6bcaba009 Binary files /dev/null and b/emtests/test_strptime_reentrant.wasm differ diff --git a/emtests/test_strptime_tm.c b/emtests/test_strptime_tm.c new file mode 100644 index 000000000..b6d17cb73 --- /dev/null +++ b/emtests/test_strptime_tm.c @@ -0,0 +1,65 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +void ReadMonth(const char *month) +{ + tm value = {0}; + if(strptime(month, "%b", &value)) + { + printf("%s: %d\n", month, value.tm_mon); + } +} + +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); + + printf("\n"); + + ReadMonth("jan"); + ReadMonth("january"); + ReadMonth("feb"); + ReadMonth("february"); + ReadMonth("march"); + ReadMonth("mar"); + ReadMonth("april"); + ReadMonth("may"); + ReadMonth("may"); + ReadMonth("june"); + ReadMonth("jul"); + ReadMonth("august"); + ReadMonth("september"); + ReadMonth("oct"); + ReadMonth("nov"); + ReadMonth("november"); + ReadMonth("december"); + + return 0; +} diff --git a/emtests/test_strptime_tm.out b/emtests/test_strptime_tm.out new file mode 100644 index 000000000..c241cbddc --- /dev/null +++ b/emtests/test_strptime_tm.out @@ -0,0 +1,18 @@ +OK: Wed, 1/5/2000 17:41:1 +jan: 0 +january: 0 +feb: 1 +february: 1 +march: 2 +mar: 2 +april: 3 +may: 4 +may: 4 +june: 5 +jul: 6 +august: 7 +september: 8 +oct: 9 +nov: 10 +november: 10 +december: 11 diff --git a/emtests/test_strstr.c b/emtests/test_strstr.c new file mode 100644 index 000000000..51de30317 --- /dev/null +++ b/emtests/test_strstr.c @@ -0,0 +1,39 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + printf("%d\n", !!strstr("\\n", "\\n")); + printf("%d\n", !!strstr("cheezy", "ez")); + printf("%d\n", !!strstr("cheeezy", "ez")); + printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez")); + printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez")); + printf("%d\n", !!strstr("che1ezy", "ez")); + printf("%d\n", !!strstr("che1ezy", "che")); + printf("%d\n", !!strstr("ce1ezy", "che")); + printf("%d\n", !!strstr("ce1ezy", "ezy")); + printf("%d\n", !!strstr("ce1ezyt", "ezy")); + printf("%d\n", !!strstr("ce1ez1y", "ezy")); + printf("%d\n", !!strstr("cheezy", "a")); + printf("%d\n", !!strstr("cheezy", "b")); + printf("%d\n", !!strstr("cheezy", "c")); + printf("%d\n", !!strstr("cheezy", "d")); + printf("%d\n", !!strstr("cheezy", "g")); + printf("%d\n", !!strstr("cheezy", "h")); + printf("%d\n", !!strstr("cheezy", "i")); + printf("%d\n", !!strstr("cheezy", "e")); + printf("%d\n", !!strstr("cheezy", "x")); + printf("%d\n", !!strstr("cheezy", "y")); + printf("%d\n", !!strstr("cheezy", "z")); + printf("%d\n", !!strstr("cheezy", "_")); + + const char *str = "a big string"; + printf("%d\n", strstr(str, "big") - str); + return 0; +} diff --git a/emtests/test_strstr.out b/emtests/test_strstr.out new file mode 100644 index 000000000..aa0d917bf --- /dev/null +++ b/emtests/test_strstr.out @@ -0,0 +1,24 @@ +1 +1 +1 +1 +0 +1 +1 +0 +1 +1 +0 +0 +0 +1 +0 +0 +1 +0 +1 +0 +1 +1 +0 +2 diff --git a/emtests/test_strstr.wasm b/emtests/test_strstr.wasm new file mode 100644 index 000000000..7764d03ad Binary files /dev/null and b/emtests/test_strstr.wasm differ diff --git a/emtests/test_strtod.c b/emtests/test_strtod.c new file mode 100644 index 000000000..b75d7098e --- /dev/null +++ b/emtests/test_strtod.c @@ -0,0 +1,42 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + char* endptr; + printf("\n"); + printf("%g\n", strtod("0", &endptr)); + printf("%g\n", strtod("0.", &endptr)); + printf("%g\n", strtod("0.0", &endptr)); + printf("%g\n", strtod("-0.0", &endptr)); + printf("%g\n", strtod("1", &endptr)); + printf("%g\n", strtod("1.", &endptr)); + printf("%g\n", strtod("1.0", &endptr)); + printf("%g\n", strtod("z1.0", &endptr)); + printf("%g\n", strtod("0.5", &endptr)); + printf("%g\n", strtod(".5", &endptr)); + printf("%g\n", strtod(".a5", &endptr)); + printf("%g\n", strtod("123", &endptr)); + printf("%g\n", strtod("123.456", &endptr)); + printf("%g\n", strtod("-123.456", &endptr)); + printf("%g\n", strtod("1234567891234567890", &endptr)); + printf("%g\n", strtod("1234567891234567890e+50", &endptr)); + printf("%g\n", strtod("84e+220", &endptr)); + printf("%g\n", strtod("123e-50", &endptr)); + printf("%g\n", strtod("123e-250", &endptr)); + printf("%g\n", strtod("123e-450", &endptr)); + printf("%g\n", strtod("0x6", &endptr)); + printf("%g\n", strtod("-0x0p+0", &endptr)); + char str[] = " 12.34e56end"; + printf("%g\n", strtod(str, &endptr)); + printf("%d\n", endptr - str); + printf("%g\n", strtod("84e+420", &endptr)); + printf("%.12f\n", strtod("1.2345678900000000e+08", NULL)); + return 0; +} diff --git a/emtests/test_strtod.out b/emtests/test_strtod.out new file mode 100644 index 000000000..f80511c3d --- /dev/null +++ b/emtests/test_strtod.out @@ -0,0 +1,26 @@ +0 +0 +0 +-0 +1 +1 +1 +0 +0.5 +0.5 +0 +123 +123.456 +-123.456 +1.23457e+18 +1.23457e+68 +8.4e+221 +1.23e-48 +1.23e-248 +0 +6 +-0 +1.234e+57 +10 +inf +123456789.000000000000 diff --git a/emtests/test_strtod.wasm b/emtests/test_strtod.wasm new file mode 100644 index 000000000..7fd3757e9 Binary files /dev/null and b/emtests/test_strtod.wasm differ diff --git a/emtests/test_strtok.c b/emtests/test_strtok.c new file mode 100644 index 000000000..130a476d5 --- /dev/null +++ b/emtests/test_strtok.c @@ -0,0 +1,27 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + char test[80], blah[80]; + const char *sep = "\\/:;=-"; + char *word, *phrase, *brkt, *brkb; + + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); + + for (word = strtok_r(test, sep, &brkt); word; + word = strtok_r(NULL, sep, &brkt)) { + strcpy(blah, "blah:blat:blab:blag"); + for (phrase = strtok_r(blah, sep, &brkb); phrase; + phrase = strtok_r(NULL, sep, &brkb)) { + printf("at %s:%s\n", word, phrase); + } + } + return 0; +} diff --git a/emtests/test_strtok.out b/emtests/test_strtok.out new file mode 100644 index 000000000..1e63af4b2 --- /dev/null +++ b/emtests/test_strtok.out @@ -0,0 +1,32 @@ +at This:blah +at This:blat +at This:blab +at This:blag +at is.a:blah +at is.a:blat +at is.a:blab +at is.a:blag +at test:blah +at test:blat +at test:blab +at test:blag +at of:blah +at of:blat +at of:blab +at of:blag +at the:blah +at the:blat +at the:blab +at the:blag +at string:blah +at string:blat +at string:blab +at string:blag +at tokenizer:blah +at tokenizer:blat +at tokenizer:blab +at tokenizer:blag +at function.:blah +at function.:blat +at function.:blab +at function.:blag diff --git a/emtests/test_strtok.wasm b/emtests/test_strtok.wasm new file mode 100644 index 000000000..45bf18d04 Binary files /dev/null and b/emtests/test_strtok.wasm differ diff --git a/emtests/test_strtol_bin.c b/emtests/test_strtol_bin.c new file mode 100644 index 000000000..5298aa548 --- /dev/null +++ b/emtests/test_strtol_bin.c @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "1 -101 +1011"; + char *end_char; + + // defined base + long l4 = strtol(STRING, &end_char, 2); + long l5 = strtol(end_char, &end_char, 2); + long l6 = strtol(end_char, NULL, 2); + + printf("%d%d%d\n", l4 == 1, l5 == -5, l6 == 11); + return 0; +} diff --git a/emtests/test_strtol_bin.out b/emtests/test_strtol_bin.out new file mode 100644 index 000000000..9d07aa0df --- /dev/null +++ b/emtests/test_strtol_bin.out @@ -0,0 +1 @@ +111 \ No newline at end of file diff --git a/emtests/test_strtol_bin.wasm b/emtests/test_strtol_bin.wasm new file mode 100644 index 000000000..f3889969c Binary files /dev/null and b/emtests/test_strtol_bin.wasm differ diff --git a/emtests/test_strtol_dec.c b/emtests/test_strtol_dec.c new file mode 100644 index 000000000..b9503ccdb --- /dev/null +++ b/emtests/test_strtol_dec.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "4 -38 +4711"; + char *end_char; + + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); + + // defined base + long l4 = strtol(STRING, &end_char, 10); + long l5 = strtol(end_char, &end_char, 10); + long l6 = strtol(end_char, NULL, 10); + + printf("%d%d%d%d%d%d\n", l1 == 4, l2 == -38, l3 == 4711, l4 == 4, l5 == -38, + l6 == 4711); + return 0; +} diff --git a/emtests/test_strtol_dec.out b/emtests/test_strtol_dec.out new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/emtests/test_strtol_dec.out @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/emtests/test_strtol_dec.wasm b/emtests/test_strtol_dec.wasm new file mode 100644 index 000000000..2532eb3c9 Binary files /dev/null and b/emtests/test_strtol_dec.wasm differ diff --git a/emtests/test_strtol_hex.c b/emtests/test_strtol_hex.c new file mode 100644 index 000000000..f1ac5cd1c --- /dev/null +++ b/emtests/test_strtol_hex.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "0x4 -0x3A +0xDEAD"; + char *end_char; + + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); + + // defined base + long l4 = strtol(STRING, &end_char, 16); + long l5 = strtol(end_char, &end_char, 16); + long l6 = strtol(end_char, NULL, 16); + + printf("%d%d%d%d%d%d\n", l1 == 0x4, l2 == -0x3a, l3 == 0xdead, l4 == 0x4, + l5 == -0x3a, l6 == 0xdead); + return 0; +} diff --git a/emtests/test_strtol_hex.out b/emtests/test_strtol_hex.out new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/emtests/test_strtol_hex.out @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/emtests/test_strtol_hex.wasm b/emtests/test_strtol_hex.wasm new file mode 100644 index 000000000..2cc341554 Binary files /dev/null and b/emtests/test_strtol_hex.wasm differ diff --git a/emtests/test_strtol_oct.c b/emtests/test_strtol_oct.c new file mode 100644 index 000000000..5ba5dbcf7 --- /dev/null +++ b/emtests/test_strtol_oct.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "0 -035 +04711"; + char *end_char; + + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); + + // defined base + long l4 = strtol(STRING, &end_char, 8); + long l5 = strtol(end_char, &end_char, 8); + long l6 = strtol(end_char, NULL, 8); + + printf("%d%d%d%d%d%d\n", l1 == 0, l2 == -29, l3 == 2505, l4 == 0, l5 == -29, + l6 == 2505); + return 0; +} diff --git a/emtests/test_strtol_oct.out b/emtests/test_strtol_oct.out new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/emtests/test_strtol_oct.out @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/emtests/test_strtol_oct.wasm b/emtests/test_strtol_oct.wasm new file mode 100644 index 000000000..9beabeecf Binary files /dev/null and b/emtests/test_strtol_oct.wasm differ diff --git a/emtests/test_strtold.c b/emtests/test_strtold.c new file mode 100644 index 000000000..c3f2dbd93 --- /dev/null +++ b/emtests/test_strtold.c @@ -0,0 +1,42 @@ +/* + * Copyright 2017 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + char* endptr; + printf("\n"); + printf("%Lg\n", strtold("0", &endptr)); + printf("%Lg\n", strtold("0.", &endptr)); + printf("%Lg\n", strtold("0.0", &endptr)); + printf("%Lg\n", strtold("-0.0", &endptr)); + printf("%Lg\n", strtold("1", &endptr)); + printf("%Lg\n", strtold("1.", &endptr)); + printf("%Lg\n", strtold("1.0", &endptr)); + printf("%Lg\n", strtold("z1.0", &endptr)); + printf("%Lg\n", strtold("0.5", &endptr)); + printf("%Lg\n", strtold(".5", &endptr)); + printf("%Lg\n", strtold(".a5", &endptr)); + printf("%Lg\n", strtold("123", &endptr)); + printf("%Lg\n", strtold("123.456", &endptr)); + printf("%Lg\n", strtold("-123.456", &endptr)); + printf("%Lg\n", strtold("1234567891234567890", &endptr)); + printf("%Lg\n", strtold("1234567891234567890e+50", &endptr)); + printf("%Lg\n", strtold("84e+220", &endptr)); + printf("%Lg\n", strtold("123e-50", &endptr)); + printf("%Lg\n", strtold("123e-250", &endptr)); + printf("%Lg\n", strtold("123e-450", &endptr)); + printf("%Lg\n", strtold("0x6", &endptr)); + printf("%Lg\n", strtold("-0x0p+0", &endptr)); + char str[] = " 12.34e56end"; + printf("%Lg\n", strtold(str, &endptr)); + printf("%d\n", endptr - str); + printf("%Lg\n", strtold("84e+420", &endptr)); + printf("%.12Lf\n", strtold("1.2345678900000000e+08", NULL)); + return 0; +} diff --git a/emtests/test_strtold.out b/emtests/test_strtold.out new file mode 100644 index 000000000..33d40d5d1 --- /dev/null +++ b/emtests/test_strtold.out @@ -0,0 +1,26 @@ +0 +0 +0 +-0 +1 +1 +1 +0 +0.5 +0.5 +0 +123 +123.456 +-123.456 +1.23457e+18 +1.23457e+68 +8.4e+221 +1.23e-48 +1.23e-248 +1.23e-448 +6 +-0 +1.234e+57 +10 +8.4e+421 +123456789.000000000000 diff --git a/emtests/test_strtold.wasm b/emtests/test_strtold.wasm new file mode 100644 index 000000000..78640890e Binary files /dev/null and b/emtests/test_strtold.wasm differ diff --git a/emtests/test_strtoll_bin.c b/emtests/test_strtoll_bin.c new file mode 100644 index 000000000..66ebe2539 --- /dev/null +++ b/emtests/test_strtoll_bin.c @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "1 -101 +1011"; + char *end_char; + + // defined base + long long int l4 = strtoll(STRING, &end_char, 2); + long long int l5 = strtoll(end_char, &end_char, 2); + long long int l6 = strtoll(end_char, NULL, 2); + + printf("%d%d%d\n", l4 == 1, l5 == -5, l6 == 11); + return 0; +} diff --git a/emtests/test_strtoll_bin.out b/emtests/test_strtoll_bin.out new file mode 100644 index 000000000..9d07aa0df --- /dev/null +++ b/emtests/test_strtoll_bin.out @@ -0,0 +1 @@ +111 \ No newline at end of file diff --git a/emtests/test_strtoll_bin.wasm b/emtests/test_strtoll_bin.wasm new file mode 100644 index 000000000..305f849d3 Binary files /dev/null and b/emtests/test_strtoll_bin.wasm differ diff --git a/emtests/test_strtoll_dec.c b/emtests/test_strtoll_dec.c new file mode 100644 index 000000000..6a474ec84 --- /dev/null +++ b/emtests/test_strtoll_dec.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "4 -38 +4711"; + char *end_char; + + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); + + // defined base + long long int l4 = strtoll(STRING, &end_char, 10); + long long int l5 = strtoll(end_char, &end_char, 10); + long long int l6 = strtoll(end_char, NULL, 10); + + printf("%d%d%d%d%d%d\n", l1 == 4, l2 == -38, l3 == 4711, l4 == 4, l5 == -38, + l6 == 4711); + return 0; +} diff --git a/emtests/test_strtoll_dec.out b/emtests/test_strtoll_dec.out new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/emtests/test_strtoll_dec.out @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/emtests/test_strtoll_dec.wasm b/emtests/test_strtoll_dec.wasm new file mode 100644 index 000000000..ef8d5d020 Binary files /dev/null and b/emtests/test_strtoll_dec.wasm differ diff --git a/emtests/test_strtoll_hex.c b/emtests/test_strtoll_hex.c new file mode 100644 index 000000000..0b5448bc1 --- /dev/null +++ b/emtests/test_strtoll_hex.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "0x4 -0x3A +0xDEADBEEF"; + char *end_char; + + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); + + // defined base + long long int l4 = strtoll(STRING, &end_char, 16); + long long int l5 = strtoll(end_char, &end_char, 16); + long long int l6 = strtoll(end_char, NULL, 16); + + printf("%d%d%d%d%d%d\n", l1 == 0x4, l2 == -0x3a, l3 == 0xdeadbeef, l4 == 0x4, + l5 == -0x3a, l6 == 0xdeadbeef); + return 0; +} diff --git a/emtests/test_strtoll_hex.out b/emtests/test_strtoll_hex.out new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/emtests/test_strtoll_hex.out @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/emtests/test_strtoll_hex.wasm b/emtests/test_strtoll_hex.wasm new file mode 100644 index 000000000..2fc8d6f13 Binary files /dev/null and b/emtests/test_strtoll_hex.wasm differ diff --git a/emtests/test_strtoll_oct.c b/emtests/test_strtoll_oct.c new file mode 100644 index 000000000..e42c8ad61 --- /dev/null +++ b/emtests/test_strtoll_oct.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + const char *STRING = "0 -035 +04711"; + char *end_char; + + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); + + // defined base + long long int l4 = strtoll(STRING, &end_char, 8); + long long int l5 = strtoll(end_char, &end_char, 8); + long long int l6 = strtoll(end_char, NULL, 8); + + printf("%d%d%d%d%d%d\n", l1 == 0, l2 == -29, l3 == 2505, l4 == 0, l5 == -29, + l6 == 2505); + return 0; +} diff --git a/emtests/test_strtoll_oct.out b/emtests/test_strtoll_oct.out new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/emtests/test_strtoll_oct.out @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/emtests/test_strtoll_oct.wasm b/emtests/test_strtoll_oct.wasm new file mode 100644 index 000000000..2525c0e91 Binary files /dev/null and b/emtests/test_strtoll_oct.wasm differ diff --git a/emtests/test_struct_varargs.c b/emtests/test_struct_varargs.c new file mode 100644 index 000000000..d54363a81 --- /dev/null +++ b/emtests/test_struct_varargs.c @@ -0,0 +1,78 @@ +/* + * Copyright 2014 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +struct A { + int x; +}; + +struct B { + double x; +}; + +void foo(int unused, ...) +{ + va_list vl; + va_start(vl, unused); + struct A a = va_arg(vl, struct A); + struct B b = va_arg(vl, struct B); + va_end(vl); + + printf("%d\n", a.x); + printf("%f\n", b.x); +} + +void a() { + struct A a = { + .x = 42, + }; + struct B b = { + .x = 42.314, + }; + foo(0, a, b); +} + +struct tiny +{ + short c; +}; + +void f (int n, ...) +{ + struct tiny x; + int i; + va_list ap; + va_start (ap,n); + for (i = 0; i < n; i++) + { + x = va_arg (ap,struct tiny); + printf("%d : %d\n", i, x.c); + if (x.c != i + 10) abort(); + } + va_end (ap); +} + +void b () +{ + struct tiny x[3]; + struct tiny y; + printf("sizeof tiny: %d (3 of them: %d)\n", sizeof(y), sizeof(x)); + x[0].c = 10; + x[1].c = 11; + x[2].c = 12; + f (3, x[0], x[1], x[2]); +} + +int main() { + a(); + b(); + printf("ok.\n"); +} + diff --git a/emtests/test_struct_varargs.out b/emtests/test_struct_varargs.out new file mode 100644 index 000000000..f6214ba1c --- /dev/null +++ b/emtests/test_struct_varargs.out @@ -0,0 +1,7 @@ +42 +42.314000 +sizeof tiny: 2 (3 of them: 6) +0 : 10 +1 : 11 +2 : 12 +ok. diff --git a/emtests/test_struct_varargs.wasm b/emtests/test_struct_varargs.wasm new file mode 100644 index 000000000..a8c4ac729 Binary files /dev/null and b/emtests/test_struct_varargs.wasm differ diff --git a/emtests/test_structs.c b/emtests/test_structs.c new file mode 100644 index 000000000..9b08fa210 --- /dev/null +++ b/emtests/test_structs.c @@ -0,0 +1,28 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +struct S { + int x, y; +}; +int main() { + S a, b; + a.x = 5; + a.y = 6; + b.x = 101; + b.y = 7009; + S *c, *d; + c = &a; + c->x *= 2; + c = &b; + c->y -= 1; + d = c; + d->y += 10; + printf("*%d,%d,%d,%d,%d,%d,%d,%d*\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, + d->y); + return 0; +} diff --git a/emtests/test_structs.out b/emtests/test_structs.out new file mode 100644 index 000000000..7748b49e9 --- /dev/null +++ b/emtests/test_structs.out @@ -0,0 +1 @@ +*10,6,101,7018,101,7018,101,7018* \ No newline at end of file diff --git a/emtests/test_time_c.c b/emtests/test_time_c.c new file mode 100644 index 000000000..b98c4023b --- /dev/null +++ b/emtests/test_time_c.c @@ -0,0 +1,14 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + time_t t = time(0); + printf("time: %s\n", ctime(&t)); +} diff --git a/emtests/test_time_c.out b/emtests/test_time_c.out new file mode 100644 index 000000000..dc3e339b4 --- /dev/null +++ b/emtests/test_time_c.out @@ -0,0 +1 @@ +time: \ No newline at end of file diff --git a/emtests/test_time_c.wasm b/emtests/test_time_c.wasm new file mode 100644 index 000000000..048fdea4b Binary files /dev/null and b/emtests/test_time_c.wasm differ diff --git a/emtests/test_timeb.c b/emtests/test_timeb.c new file mode 100644 index 000000000..caf399ce9 --- /dev/null +++ b/emtests/test_timeb.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +int main() { + timeb tb; + tb.timezone = 1; + printf("*%d\n", ftime(&tb)); + assert(tb.time > 10000); + assert(tb.timezone == 0); + assert(tb.dstflag == 0); + return 0; +} diff --git a/emtests/test_timeb.out b/emtests/test_timeb.out new file mode 100644 index 000000000..488c9af75 --- /dev/null +++ b/emtests/test_timeb.out @@ -0,0 +1 @@ +*0 diff --git a/emtests/test_tinyfuncstr.c b/emtests/test_tinyfuncstr.c new file mode 100644 index 000000000..1b30eebbb --- /dev/null +++ b/emtests/test_tinyfuncstr.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +struct Class { + static char *name1() { return "nameA"; } + char *name2() { return "nameB"; } +}; + +int main() { + printf("*%s,%s*\n", Class::name1(), (new Class())->name2()); + return 0; +} diff --git a/emtests/test_tinyfuncstr.out b/emtests/test_tinyfuncstr.out new file mode 100644 index 000000000..ed0d2567f --- /dev/null +++ b/emtests/test_tinyfuncstr.out @@ -0,0 +1 @@ +*nameA,nameB* \ No newline at end of file diff --git a/emtests/test_tracing.c b/emtests/test_tracing.c new file mode 100644 index 000000000..d055046be --- /dev/null +++ b/emtests/test_tracing.c @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main(int argc, const char* argv[]) { + + emscripten_trace_configure_for_test(); + + emscripten_trace_enter_context("Application Startup"); + emscripten_trace_log_message("Application", "starting up"); + emscripten_trace_exit_context(); + + emscripten_trace_record_frame_start(); + emscripten_trace_record_frame_end(); + + return 0; +} diff --git a/emtests/test_tracing.out b/emtests/test_tracing.out new file mode 100644 index 000000000..654cf7cd7 --- /dev/null +++ b/emtests/test_tracing.out @@ -0,0 +1,5 @@ +Tracing enter-context,0,Application Startup +Tracing log-message,0,Application,starting up +Tracing exit-context,0 +Tracing frame-start,0 +Tracing frame-end,0 diff --git a/emtests/test_tracing.wasm b/emtests/test_tracing.wasm new file mode 100644 index 000000000..f7128d247 Binary files /dev/null and b/emtests/test_tracing.wasm differ diff --git a/emtests/test_transtrcase.c b/emtests/test_transtrcase.c new file mode 100644 index 000000000..bbbbbb168 --- /dev/null +++ b/emtests/test_transtrcase.c @@ -0,0 +1,18 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +int main() { + char szToupr[] = "hello, "; + char szTolwr[] = "EMSCRIPTEN"; + strupr(szToupr); + strlwr(szTolwr); + puts(szToupr); + puts(szTolwr); + return 0; +} diff --git a/emtests/test_transtrcase.out b/emtests/test_transtrcase.out new file mode 100644 index 000000000..d234d1352 --- /dev/null +++ b/emtests/test_transtrcase.out @@ -0,0 +1,2 @@ +HELLO, +emscripten diff --git a/emtests/test_transtrcase.wasm b/emtests/test_transtrcase.wasm new file mode 100644 index 000000000..47d64722a Binary files /dev/null and b/emtests/test_transtrcase.wasm differ diff --git a/emtests/test_trickystring.c b/emtests/test_trickystring.c new file mode 100644 index 000000000..eded1b2c0 --- /dev/null +++ b/emtests/test_trickystring.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +typedef struct { + int (*f)(void *); + void *d; + char s[16]; +} LMEXFunctionStruct; + +int f(void *user) { return 0; } + +static LMEXFunctionStruct const a[] = {{f, (void *)(int)'a', "aa"}}; + +int main() { + printf("ok\n"); + return a[0].f(a[0].d); +} diff --git a/emtests/test_trickystring.out b/emtests/test_trickystring.out new file mode 100644 index 000000000..9766475a4 --- /dev/null +++ b/emtests/test_trickystring.out @@ -0,0 +1 @@ +ok diff --git a/emtests/test_trickystring.wasm b/emtests/test_trickystring.wasm new file mode 100644 index 000000000..3aedb7e41 Binary files /dev/null and b/emtests/test_trickystring.wasm differ diff --git a/emtests/test_typeid.c b/emtests/test_typeid.c new file mode 100644 index 000000000..f832faa51 --- /dev/null +++ b/emtests/test_typeid.c @@ -0,0 +1,59 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include +int main() { + printf("*\n"); +#define MAX 100 + int ptrs[MAX]; + int groups[MAX]; + memset(ptrs, 0, MAX * sizeof(int)); + memset(groups, 0, MAX * sizeof(int)); + int next_group = 1; +#define TEST(X) \ + { \ + int ptr = (int)&typeid(X); \ + int group = 0; \ + int i; \ + for (i = 0; i < MAX; i++) { \ + if (!groups[i]) break; \ + if (ptrs[i] == ptr) { \ + group = groups[i]; \ + break; \ + } \ + } \ + if (!group) { \ + groups[i] = group = next_group++; \ + ptrs[i] = ptr; \ + } \ + printf("%s:%d\n", #X, group); \ + } + TEST(int); + TEST(unsigned int); + TEST(unsigned); + TEST(signed int); + TEST(long); + TEST(unsigned long); + TEST(signed long); + TEST(long long); + TEST(unsigned long long); + TEST(signed long long); + TEST(short); + TEST(unsigned short); + TEST(signed short); + TEST(char); + TEST(unsigned char); + TEST(signed char); + TEST(float); + TEST(double); + TEST(long double); + TEST(void); + TEST(void*); + printf("*\n"); +} diff --git a/emtests/test_typeid.out b/emtests/test_typeid.out new file mode 100644 index 000000000..6355c27dc --- /dev/null +++ b/emtests/test_typeid.out @@ -0,0 +1,23 @@ +* +int:1 +unsigned int:2 +unsigned:2 +signed int:1 +long:3 +unsigned long:4 +signed long:3 +long long:5 +unsigned long long:6 +signed long long:5 +short:7 +unsigned short:8 +signed short:7 +char:9 +unsigned char:10 +signed char:11 +float:12 +double:13 +long double:14 +void:15 +void*:16 +* diff --git a/emtests/test_uname.c b/emtests/test_uname.c new file mode 100644 index 000000000..4ca20f36e --- /dev/null +++ b/emtests/test_uname.c @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + struct utsname u; + printf("ret: %d\n", uname(&u)); + printf("sysname: %s\n", u.sysname); + printf("nodename: %s\n", u.nodename); + printf("release: %s\n", u.release); + printf("version: %s\n", u.version); + printf("machine: %s\n", u.machine); + printf("invalid: %d\n", uname(0)); + return 0; +} diff --git a/emtests/test_uname.out b/emtests/test_uname.out new file mode 100644 index 000000000..cd36c5318 --- /dev/null +++ b/emtests/test_uname.out @@ -0,0 +1,6 @@ +ret: 0 +sysname: Emscripten +nodename: emscripten +release: 1.0 +version: #1 +machine: x86-JS diff --git a/emtests/test_uname.wasm b/emtests/test_uname.wasm new file mode 100644 index 000000000..770bc8353 Binary files /dev/null and b/emtests/test_uname.wasm differ diff --git a/emtests/test_unary_literal.cpp b/emtests/test_unary_literal.cpp new file mode 100644 index 000000000..5d929a7b1 --- /dev/null +++ b/emtests/test_unary_literal.cpp @@ -0,0 +1,41 @@ +// Copyright 2018 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include + +class UnaryTest { +public: + static const UnaryTest STATIC_INSTANCE; + static const double STATIC_PROPERTY; + + double p; + + UnaryTest(double p); +}; + +const UnaryTest UnaryTest::STATIC_INSTANCE(-1); +const double UnaryTest::STATIC_PROPERTY(-1); +const double STATIC_DOUBLE(-1); + +UnaryTest::UnaryTest(double inP) : p(inP) { } + +int main(int, char**){ + const double t1 = -1; + double t2 = -1; + + double p1 = -UnaryTest::STATIC_INSTANCE.p; + double p2 = -UnaryTest::STATIC_PROPERTY; + double p3 = -STATIC_DOUBLE; + double p4 = -t1; + double p5 = -t2; + + printf("%.2f\n", p1); + printf("%.2f\n", p2); + printf("%.2f\n", p3); + printf("%.2f\n", p4); + printf("%.2f\n", p5); + + return 0; +} diff --git a/emtests/test_unary_literal.out b/emtests/test_unary_literal.out new file mode 100644 index 000000000..2a7afaf32 --- /dev/null +++ b/emtests/test_unary_literal.out @@ -0,0 +1,5 @@ +1.00 +1.00 +1.00 +1.00 +1.00 diff --git a/emtests/test_unary_literal.wasm b/emtests/test_unary_literal.wasm new file mode 100644 index 000000000..1240c3cb6 Binary files /dev/null and b/emtests/test_unary_literal.wasm differ diff --git a/emtests/test_utf.c b/emtests/test_utf.c new file mode 100644 index 000000000..9690c6c95 --- /dev/null +++ b/emtests/test_utf.c @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +int main() { + char *c = "μ†ℱ ╋ℯ╳╋ 😇"; + printf("%d %d %d %d %s\n", c[0] & 0xff, c[1] & 0xff, c[2] & 0xff, c[3] & 0xff, + c); + emscripten_run_script( + "cheez = _malloc(100);" + "Module.stringToUTF8(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez, 100);" + "out([Pointer_stringify(cheez), Module.getValue(cheez, " + "'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, " + "Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, " + "'i8')&0xff].join(','));"); +} diff --git a/emtests/test_utf.out b/emtests/test_utf.out new file mode 100644 index 000000000..a2af5f8b9 --- /dev/null +++ b/emtests/test_utf.out @@ -0,0 +1,2 @@ +206 188 226 128 μ†ℱ ╋ℯ╳╋ 😇 +μ†ℱ ╋ℯ╳╋ 😇,206,188,226,128 diff --git a/emtests/test_utf.wasm b/emtests/test_utf.wasm new file mode 100644 index 000000000..bd016cdf3 Binary files /dev/null and b/emtests/test_utf.wasm differ diff --git a/emtests/test_varargs.c b/emtests/test_varargs.c new file mode 100644 index 000000000..87f9c0974 --- /dev/null +++ b/emtests/test_varargs.c @@ -0,0 +1,107 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +void vary(const char *s, ...) { + va_list v; + va_start(v, s); + char d[20]; + vsnprintf(d, 20, s, v); + puts(d); + + // Try it with copying + va_list tempva; + va_copy(tempva, v); + vsnprintf(d, 20, s, tempva); + puts(d); + + va_end(v); +} + +void vary2(char color, const char *s, ...) { + va_list v; + va_start(v, s); + char d[21]; + d[0] = color; + vsnprintf(d + 1, 20, s, v); + puts(d); + va_end(v); +} + +void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration) { + while (count > 0) { + const char *string = va_arg(ap, const char *); + printf("%s", string); + count--; + } + printf("\n"); +} + +void varags_listoffsets_list_copy(int count, va_list ap, int iteration) { + va_list ap_copy; + va_copy(ap_copy, ap); + varargs_listoffsets_list_evaluate(count, ap_copy, iteration); + va_end(ap_copy); +} + +void varargs_listoffsets_args(int type, int count, ...) { + va_list ap; + va_start(ap, count); + + // evaluate a copied list + varags_listoffsets_list_copy(count, ap, 1); + varags_listoffsets_list_copy(count, ap, 2); + varags_listoffsets_list_copy(count, ap, 3); + varags_listoffsets_list_copy(count, ap, 4); +} + +void varargs_listoffsets_main() { + varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "", + "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "", ""); +} + +#define GETMAX(pref, type) \ + type getMax##pref(int num, ...) { \ + va_list vv; \ + va_start(vv, num); \ + type maxx = va_arg(vv, type); \ + for (int i = 1; i < num; i++) { \ + type curr = va_arg(vv, type); \ + maxx = curr > maxx ? curr : maxx; \ + } \ + va_end(vv); \ + return maxx; \ + } +GETMAX(i, int); +GETMAX(D, double); + +int main(int argc, char **argv) { + vary("*cheez: %d+%d*", 0, + 24); // Also tests that '0' is not special as an array ender + vary("*albeit*"); // Should not fail with no var args in vararg function + vary2('Q', "%d*", 85); + + int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19); + printf("maxxi:%d*\n", maxxi); + double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, + (double)-10.1, (double)19.1, (double)2); + printf("maxxD:%.2f*\n", (float)maxxD); + + // And, as a function pointer + void (*vfp)(const char * s, ...) = argc == 1211 ? NULL : vary; + vfp("*vfp:%d,%d*", 22, 199); + + // ensure lists work properly when copied, reinited etc. + varargs_listoffsets_main(); + + return 0; +} diff --git a/emtests/test_varargs.out b/emtests/test_varargs.out new file mode 100644 index 000000000..45fa0a267 --- /dev/null +++ b/emtests/test_varargs.out @@ -0,0 +1,13 @@ +*cheez: 0+24* +*cheez: 0+24* +*albeit* +*albeit* +Q85* +maxxi:21* +maxxD:22.10* +*vfp:22,199* +*vfp:22,199* +abcdefghijklmno +abcdefghijklmno +abcdefghijklmno +abcdefghijklmno diff --git a/emtests/test_varargs.wasm b/emtests/test_varargs.wasm new file mode 100644 index 000000000..d4add6eba Binary files /dev/null and b/emtests/test_varargs.wasm differ diff --git a/emtests/test_varargs_multi.c b/emtests/test_varargs_multi.c new file mode 100644 index 000000000..6b4669b10 --- /dev/null +++ b/emtests/test_varargs_multi.c @@ -0,0 +1,41 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +void print_vararg(int n, va_list v) { + for (int i = 0; i < n; ++i) { + if (i > 0) { + printf(", "); + } + printf("%d", va_arg(v, int)); + } + printf("\n"); +} + +void multi_vararg(int n, ...) { + va_list v; + + va_start(v, n); + print_vararg(n, v); + print_vararg(n, v); // the value of v is undefined for this call + va_end(v); + + va_start(v, n); + print_vararg(n, v); + va_end(v); +} + +int main() { + multi_vararg(5, + 8, 6, 4, 2, 0, + 1, 3, 5, 7, 9, + 4, 5, 6, 7, 8 + ); + return 0; +} diff --git a/emtests/test_varargs_multi.out b/emtests/test_varargs_multi.out new file mode 100644 index 000000000..49d16c2fa --- /dev/null +++ b/emtests/test_varargs_multi.out @@ -0,0 +1,3 @@ +8, 6, 4, 2, 0 +1, 3, 5, 7, 9 +8, 6, 4, 2, 0 \ No newline at end of file diff --git a/emtests/test_varargs_multi.wasm b/emtests/test_varargs_multi.wasm new file mode 100644 index 000000000..caa021a0d Binary files /dev/null and b/emtests/test_varargs_multi.wasm differ diff --git a/emtests/test_vprintf.c b/emtests/test_vprintf.c new file mode 100644 index 000000000..c797c05fb --- /dev/null +++ b/emtests/test_vprintf.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +void print(const char* format, ...) { + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); +} + +int main() { + print("Call with %d variable argument.\n", 1); + print("Call with %d variable %s.\n", 2, "arguments"); + + return 0; +} diff --git a/emtests/test_vprintf.out b/emtests/test_vprintf.out new file mode 100644 index 000000000..16f215109 --- /dev/null +++ b/emtests/test_vprintf.out @@ -0,0 +1,2 @@ +Call with 1 variable argument. +Call with 2 variable arguments. diff --git a/emtests/test_vprintf.wasm b/emtests/test_vprintf.wasm new file mode 100644 index 000000000..e3c47e72d Binary files /dev/null and b/emtests/test_vprintf.wasm differ diff --git a/emtests/test_vsnprintf.c b/emtests/test_vsnprintf.c new file mode 100644 index 000000000..dc386c5a8 --- /dev/null +++ b/emtests/test_vsnprintf.c @@ -0,0 +1,48 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include +#include + +void printy(const char *f, ...) { + char buffer[256]; + va_list args; + va_start(args, f); + vsnprintf(buffer, 256, f, args); + puts(buffer); + va_end(args); +} + +int main(int argc, char **argv) { + int64_t x = argc - 1; + int64_t y = argc - 1 + 0x400000; + if (x % 3 == 2) y *= 2; + + printy("0x%llx_0x%llx", x, y); + printy("0x%llx_0x%llx", x, x); + printy("0x%llx_0x%llx", y, x); + printy("0x%llx_0x%llx", y, y); + + { + uint64_t A = 0x800000; + uint64_t B = 0x800000000000ULL; + printy("0x%llx_0x%llx", A, B); + } + { + uint64_t A = 0x800; + uint64_t B = 0x12340000000000ULL; + printy("0x%llx_0x%llx", A, B); + } + { + uint64_t A = 0x000009182746756; + uint64_t B = 0x192837465631ACBDULL; + printy("0x%llx_0x%llx", A, B); + } + + return 0; +} diff --git a/emtests/test_vsnprintf.out b/emtests/test_vsnprintf.out new file mode 100644 index 000000000..ef8a3f7ef --- /dev/null +++ b/emtests/test_vsnprintf.out @@ -0,0 +1,7 @@ +0x0_0x400000 +0x0_0x0 +0x400000_0x0 +0x400000_0x400000 +0x800000_0x800000000000 +0x800_0x12340000000000 +0x9182746756_0x192837465631acbd diff --git a/emtests/test_vsnprintf.wasm b/emtests/test_vsnprintf.wasm new file mode 100644 index 000000000..b2c976567 Binary files /dev/null and b/emtests/test_vsnprintf.wasm differ diff --git a/emtests/test_wprintf.cpp b/emtests/test_wprintf.cpp new file mode 100644 index 000000000..5e9185241 --- /dev/null +++ b/emtests/test_wprintf.cpp @@ -0,0 +1,70 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include + +void PrintWide ( const wchar_t * format, ... ) +{ + wchar_t buffer[256]; + memset(buffer, 0, 256); + va_list args; + va_start ( args, format ); + wprintf(L"format starts with 0x%x\n", *(int*)format); + wprintf(L"fmt continues with 0x%x\n", *(((int*)format) + 1)); + wprintf(L"fmt continues with 0x%x\n", *(((int*)format) + 2)); + int r = vswprintf ( buffer, 256, format, args ); + wprintf(L"vswprintf told us %d\n", r); + wprintf(L"vswoutput st-rts with 0x%x\n", *(int*)buffer); + wprintf(L"vsw continues with 0x%x\n", *(((int*)buffer) + 1)); + wprintf(L"vsw continues with 0x%x\n", *(((int*)buffer) + 2)); + wprintf(buffer); + va_end ( args ); +} + +int main () +{ + FILE *f = fopen("test.dat", "wb"); + int num = fwprintf(f, L"hello %d", 5); + wprintf(L"fwprintf told us %d\n", num); + fclose(f); + f = fopen("test.dat", "rb"); + fseek(f, 0, SEEK_END); + int size = ftell(f); + fclose(f); + wprintf(L"file size is %d\n", size); + + wchar_t str[] = L"test string has %d wide characters.\n"; + wprintf(L"str starts with 0x%x\n", *(int*)str); + wprintf(L"str continues with 0x%x\n", *(((int*)str) + 1)); + wprintf(L"str continues with 0x%x\n", *(((int*)str) + 2)); + PrintWide ( str, wcslen(str) ); + PrintWide ( str, wcslen(str) ); + PrintWide ( str, wcslen(str) ); + + wprintf (L"Characters: %lc %lc \n", L'a', 65); + wprintf (L"Decimals: %d %ld\n", 1977, 650000L); + wprintf (L"Preceding with blanks: %10d \n", 1977); + wprintf (L"Preceding with zeros: %010d \n", 1977); + wprintf (L"Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100); + wprintf (L"floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416); + wprintf (L"Width trick: %*d \n", 5, 10); + wprintf (L"%ls \n", L"A wide string"); + + wchar_t buffer [100]; + memset(buffer, 0, sizeof(buffer)); + int cx; + cx = swprintf(buffer, 100, L"The half of %d is %d", 80, 80/2); + wprintf(L"swprintf told us %d\n", cx); + for (int i = 0; i < 10; i++) wprintf(L"pre %d\n", ((int*)buffer)[i]); + swprintf (buffer+cx, 100-cx-1, L", and the half of that is %d.\n", 80/2/2); + for (int i = 0; i < 10; i++) wprintf(L"post %d\n", ((int*)buffer)[i]); + wprintf(buffer); + + return 0; +} + diff --git a/emtests/test_wprintf.out b/emtests/test_wprintf.out new file mode 100644 index 000000000..8dfed67ac --- /dev/null +++ b/emtests/test_wprintf.out @@ -0,0 +1,59 @@ +fwprintf told us 7 +file size is 7 +str starts with 0x74 +str continues with 0x65 +str continues with 0x73 +format starts with 0x74 +fmt continues with 0x65 +fmt continues with 0x73 +vswprintf told us 36 +vswoutput st-rts with 0x74 +vsw continues with 0x65 +vsw continues with 0x73 +test string has 36 wide characters. +format starts with 0x74 +fmt continues with 0x65 +fmt continues with 0x73 +vswprintf told us 36 +vswoutput st-rts with 0x74 +vsw continues with 0x65 +vsw continues with 0x73 +test string has 36 wide characters. +format starts with 0x74 +fmt continues with 0x65 +fmt continues with 0x73 +vswprintf told us 36 +vswoutput st-rts with 0x74 +vsw continues with 0x65 +vsw continues with 0x73 +test string has 36 wide characters. +Characters: a A +Decimals: 1977 650000 +Preceding with blanks: 1977 +Preceding with zeros: 0000001977 +Some different radixes: 100 64 144 0x64 0144 +floats: 3.14 +3e+00 3.141600E+00 +Width trick: 10 +A wide string +swprintf told us 20 +pre 84 +pre 104 +pre 101 +pre 32 +pre 104 +pre 97 +pre 108 +pre 102 +pre 32 +pre 111 +post 84 +post 104 +post 101 +post 32 +post 104 +post 97 +post 108 +post 102 +post 32 +post 111 +The half of 80 is 40, and the half of that is 20. diff --git a/emtests/test_wprintf.wasm b/emtests/test_wprintf.wasm new file mode 100644 index 000000000..2396f1859 Binary files /dev/null and b/emtests/test_wprintf.wasm differ diff --git a/emtests/test_write_stdout_fileno.c b/emtests/test_write_stdout_fileno.c new file mode 100644 index 000000000..2c766c50d --- /dev/null +++ b/emtests/test_write_stdout_fileno.c @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + char msg[] = "Hello!\n"; + write(STDOUT_FILENO, msg, strlen(msg)); +} diff --git a/emtests/test_write_stdout_fileno.out b/emtests/test_write_stdout_fileno.out new file mode 100644 index 000000000..05a682bd4 --- /dev/null +++ b/emtests/test_write_stdout_fileno.out @@ -0,0 +1 @@ +Hello! \ No newline at end of file diff --git a/emtests/test_write_stdout_fileno.wasm b/emtests/test_write_stdout_fileno.wasm new file mode 100644 index 000000000..a7062fd30 Binary files /dev/null and b/emtests/test_write_stdout_fileno.wasm differ diff --git a/emtests/test_zero_multiplication.c b/emtests/test_zero_multiplication.c new file mode 100644 index 000000000..9933fab14 --- /dev/null +++ b/emtests/test_zero_multiplication.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +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; +} diff --git a/emtests/test_zero_multiplication.out b/emtests/test_zero_multiplication.out new file mode 100644 index 000000000..bb69c6718 --- /dev/null +++ b/emtests/test_zero_multiplication.out @@ -0,0 +1 @@ +0 0 0 0 -0 -0 \ No newline at end of file diff --git a/emtests/test_zero_multiplication.wasm b/emtests/test_zero_multiplication.wasm new file mode 100644 index 000000000..df2a0d73e Binary files /dev/null and b/emtests/test_zero_multiplication.wasm differ diff --git a/emtests/test_zerodiv.c b/emtests/test_zerodiv.c new file mode 100644 index 000000000..4d4132133 --- /dev/null +++ b/emtests/test_zerodiv.c @@ -0,0 +1,35 @@ +/* + * Copyright 2016 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include +#include + +void printCanonicalizedNan(char* name, float value) { + if (!isnan(value)) { + printf("%s: %f\n", name, value); + } else { + printf("%s: nan\n", name); + } +} + +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; + + printCanonicalizedNan("f3", f3); + printCanonicalizedNan("f4", f4); + printCanonicalizedNan("f5", f5); + printCanonicalizedNan("f6", f6); + + return 0; +} diff --git a/emtests/test_zerodiv.out b/emtests/test_zerodiv.out new file mode 100644 index 000000000..3bb47f8aa --- /dev/null +++ b/emtests/test_zerodiv.out @@ -0,0 +1,4 @@ +f3: nan +f4: nan +f5: nan +f6: nan diff --git a/emtests/test_zerodiv.wasm b/emtests/test_zerodiv.wasm new file mode 100644 index 000000000..f4c1f4192 Binary files /dev/null and b/emtests/test_zerodiv.wasm differ diff --git a/src/emtests/emscripten_get_compiler_setting.rs b/src/emtests/emscripten_get_compiler_setting.rs new file mode 100644 index 000000000..df0f5283b --- /dev/null +++ b/src/emtests/emscripten_get_compiler_setting.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_emscripten_get_compiler_setting() { + assert_emscripten_output!( + "../../emtests/emscripten_get_compiler_setting.wasm", + "emscripten_get_compiler_setting", + vec![], + "../../emtests/emscripten_get_compiler_setting.out" + ); +} diff --git a/src/emtests/fs_exports.rs b/src/emtests/fs_exports.rs new file mode 100644 index 000000000..f915cf071 --- /dev/null +++ b/src/emtests/fs_exports.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_fs_exports() { + assert_emscripten_output!( + "../../emtests/FS_exports.wasm", + "fs_exports", + vec![], + "../../emtests/FS_exports.txt" + ); +} diff --git a/src/emtests/getvalue_setvalue.rs b/src/emtests/getvalue_setvalue.rs new file mode 100644 index 000000000..8e7e1bcc4 --- /dev/null +++ b/src/emtests/getvalue_setvalue.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_getvalue_setvalue() { + assert_emscripten_output!( + "../../emtests/getValue_setValue.wasm", + "getvalue_setvalue", + vec![], + "../../emtests/getValue_setValue.txt" + ); +} diff --git a/src/emtests/legacy_exported_runtime_numbers.rs b/src/emtests/legacy_exported_runtime_numbers.rs new file mode 100644 index 000000000..65cb9a690 --- /dev/null +++ b/src/emtests/legacy_exported_runtime_numbers.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_legacy_exported_runtime_numbers() { + assert_emscripten_output!( + "../../emtests/legacy_exported_runtime_numbers.wasm", + "legacy_exported_runtime_numbers", + vec![], + "../../emtests/legacy_exported_runtime_numbers.txt" + ); +} diff --git a/src/emtests/mod.rs b/src/emtests/mod.rs index b5572f6dd..256e92cb9 100644 --- a/src/emtests/mod.rs +++ b/src/emtests/mod.rs @@ -4,6 +4,176 @@ // The _common module is not autogenerated, as it provides common macros for the emtests #[macro_use] mod _common; +mod emscripten_get_compiler_setting; mod env; +mod fs_exports; +mod getvalue_setvalue; +mod legacy_exported_runtime_numbers; +mod modularize_closure_pre; mod printf; mod puts; +mod stackalloc; +mod test_addr_of_stacked; +mod test_alloca; +mod test_alloca_stack; +mod test_array2; +mod test_array2b; +mod test_atomic; +mod test_atox; +mod test_bsearch; +mod test_ccall; +mod test_complex; +mod test_demangle_stacks; +mod test_demangle_stacks_noassert; +mod test_dlmalloc_partial_2; +mod test_double_varargs; +mod test_em_asm; +mod test_em_asm_2; +mod test_em_asm_parameter_pack; +mod test_em_asm_signatures; +mod test_em_asm_unicode; +mod test_em_asm_unused_arguments; +mod test_em_js; +mod test_emscripten_api; +mod test_erf; +mod test_errar; +mod test_exceptions_2; +mod test_exceptions_multi; +mod test_exceptions_std; +mod test_exceptions_white_list; +mod test_fast_math; +mod test_flexarray_struct; +mod test_float32_precise; +mod test_float_builtins; +mod test_frexp; +mod test_funcptr; +mod test_funcptr_namecollide; +mod test_funcptrfunc; +mod test_funcs; +mod test_functionpointer_libfunc_varargs; +mod test_fwrite_0; +mod test_getgep; +mod test_getloadavg; +mod test_getopt; +mod test_getopt_long; +mod test_globaldoubles; +mod test_globals; +mod test_gmtime; +mod test_hello_world; +mod test_i16_emcc_intrinsic; +mod test_i32_mul_precise; +mod test_i64; +mod test_i64_4; +mod test_i64_7z; +mod test_i64_cmp2; +mod test_i64_i16; +mod test_i64_llabs; +mod test_i64_precise; +mod test_i64_precise_needed; +mod test_i64_precise_unneeded; +mod test_i64_qdouble; +mod test_i64_umul; +mod test_i64_varargs; +mod test_i64_zextneg; +mod test_if; +mod test_if_else; +mod test_indirectbr; +mod test_indirectbr_many; +mod test_isnan; +mod test_libcextra; +mod test_libgen; +mod test_literal_negative_zero; +mod test_llrint; +mod test_llvm_fabs; +mod test_llvm_intrinsics; +mod test_llvmswitch; +mod test_longjmp; +mod test_longjmp2; +mod test_longjmp3; +mod test_longjmp4; +mod test_longjmp_exc; +mod test_longjmp_funcptr; +mod test_longjmp_repeat; +mod test_longjmp_stacked; +mod test_longjmp_throw; +mod test_longjmp_unwind; +mod test_loop; +mod test_lower_intrinsics; +mod test_main_thread_async_em_asm; +mod test_mainenv; +mod test_mathfuncptr; +mod test_memcpy2; +mod test_memcpy3; +mod test_memcpy_memcmp; +mod test_memmove; +mod test_memmove2; +mod test_memmove3; +mod test_memset; +mod test_mmap; +mod test_negative_zero; +mod test_nested_struct_varargs; +mod test_nl_types; +mod test_perrar; +mod test_phiundef; +mod test_poll; +mod test_posixtime; +mod test_printf_2; +mod test_printf_more; +mod test_regex; +mod test_relocatable_void_function; +mod test_rounding; +mod test_set_align; +mod test_siglongjmp; +mod test_sintvars; +mod test_sizeof; +mod test_sscanf; +mod test_sscanf_3; +mod test_sscanf_4; +mod test_sscanf_5; +mod test_sscanf_6; +mod test_sscanf_caps; +mod test_sscanf_float; +mod test_sscanf_hex; +mod test_sscanf_n; +mod test_sscanf_other_whitespace; +mod test_sscanf_skip; +mod test_sscanf_whitespace; +mod test_stack_varargs; +mod test_stack_void; +mod test_statvfs; +mod test_std_cout_new; +mod test_strcasecmp; +mod test_strcmp_uni; +mod test_strftime; +mod test_strings; +mod test_strndup; +mod test_strptime_days; +mod test_strptime_reentrant; +mod test_strstr; +mod test_strtod; +mod test_strtok; +mod test_strtol_bin; +mod test_strtol_dec; +mod test_strtol_hex; +mod test_strtol_oct; +mod test_strtold; +mod test_strtoll_bin; +mod test_strtoll_dec; +mod test_strtoll_hex; +mod test_strtoll_oct; +mod test_struct_varargs; +mod test_time_c; +mod test_tracing; +mod test_transtrcase; +mod test_trickystring; +mod test_uname; +mod test_unary_literal; +mod test_utf; +mod test_varargs; +mod test_varargs_multi; +mod test_vprintf; +mod test_vsnprintf; +mod test_wprintf; +mod test_write_stdout_fileno; +mod test_zero_multiplication; +mod test_zerodiv; diff --git a/src/emtests/modularize_closure_pre.rs b/src/emtests/modularize_closure_pre.rs new file mode 100644 index 000000000..a92b73ce8 --- /dev/null +++ b/src/emtests/modularize_closure_pre.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_modularize_closure_pre() { + assert_emscripten_output!( + "../../emtests/modularize_closure_pre.wasm", + "modularize_closure_pre", + vec![], + "../../emtests/modularize_closure_pre.out" + ); +} diff --git a/src/emtests/printf.rs b/src/emtests/printf.rs index 9114fef3e..6f5da28f1 100644 --- a/src/emtests/printf.rs +++ b/src/emtests/printf.rs @@ -1,4 +1,9 @@ #[test] fn test_printf() { - assert_emscripten_output!("../../emtests/printf.wasm", "printf", vec![], "../../emtests/printf.out"); + assert_emscripten_output!( + "../../emtests/printf.wasm", + "printf", + vec![], + "../../emtests/printf.out" + ); } diff --git a/src/emtests/puts.rs b/src/emtests/puts.rs index dae9e2f36..7348a3033 100644 --- a/src/emtests/puts.rs +++ b/src/emtests/puts.rs @@ -1,4 +1,9 @@ #[test] fn test_puts() { - assert_emscripten_output!("../../emtests/puts.wasm", "puts", vec![], "../../emtests/puts.out"); + assert_emscripten_output!( + "../../emtests/puts.wasm", + "puts", + vec![], + "../../emtests/puts.out" + ); } diff --git a/src/emtests/stackalloc.rs b/src/emtests/stackalloc.rs new file mode 100644 index 000000000..8c928945c --- /dev/null +++ b/src/emtests/stackalloc.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_stackalloc() { + assert_emscripten_output!( + "../../emtests/stackAlloc.wasm", + "stackalloc", + vec![], + "../../emtests/stackAlloc.txt" + ); +} diff --git a/src/emtests/test_addr_of_stacked.rs b/src/emtests/test_addr_of_stacked.rs new file mode 100644 index 000000000..cced39cc1 --- /dev/null +++ b/src/emtests/test_addr_of_stacked.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_addr_of_stacked() { + assert_emscripten_output!( + "../../emtests/test_addr_of_stacked.wasm", + "test_addr_of_stacked", + vec![], + "../../emtests/test_addr_of_stacked.out" + ); +} diff --git a/src/emtests/test_alloca.rs b/src/emtests/test_alloca.rs new file mode 100644 index 000000000..d7debe033 --- /dev/null +++ b/src/emtests/test_alloca.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_alloca() { + assert_emscripten_output!( + "../../emtests/test_alloca.wasm", + "test_alloca", + vec![], + "../../emtests/test_alloca.out" + ); +} diff --git a/src/emtests/test_alloca_stack.rs b/src/emtests/test_alloca_stack.rs new file mode 100644 index 000000000..aa0dffa0f --- /dev/null +++ b/src/emtests/test_alloca_stack.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_alloca_stack() { + assert_emscripten_output!( + "../../emtests/test_alloca_stack.wasm", + "test_alloca_stack", + vec![], + "../../emtests/test_alloca_stack.out" + ); +} diff --git a/src/emtests/test_array2.rs b/src/emtests/test_array2.rs new file mode 100644 index 000000000..a5f32b2e0 --- /dev/null +++ b/src/emtests/test_array2.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_array2() { + assert_emscripten_output!( + "../../emtests/test_array2.wasm", + "test_array2", + vec![], + "../../emtests/test_array2.out" + ); +} diff --git a/src/emtests/test_array2b.rs b/src/emtests/test_array2b.rs new file mode 100644 index 000000000..d91952685 --- /dev/null +++ b/src/emtests/test_array2b.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_array2b() { + assert_emscripten_output!( + "../../emtests/test_array2b.wasm", + "test_array2b", + vec![], + "../../emtests/test_array2b.out" + ); +} diff --git a/src/emtests/test_atomic.rs b/src/emtests/test_atomic.rs new file mode 100644 index 000000000..b7cea7ca5 --- /dev/null +++ b/src/emtests/test_atomic.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_atomic() { + assert_emscripten_output!( + "../../emtests/test_atomic.wasm", + "test_atomic", + vec![], + "../../emtests/test_atomic.out" + ); +} diff --git a/src/emtests/test_atox.rs b/src/emtests/test_atox.rs new file mode 100644 index 000000000..8b5823eb8 --- /dev/null +++ b/src/emtests/test_atox.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_atox() { + assert_emscripten_output!( + "../../emtests/test_atoX.wasm", + "test_atox", + vec![], + "../../emtests/test_atoX.out" + ); +} diff --git a/src/emtests/test_bsearch.rs b/src/emtests/test_bsearch.rs new file mode 100644 index 000000000..032740801 --- /dev/null +++ b/src/emtests/test_bsearch.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_bsearch() { + assert_emscripten_output!( + "../../emtests/test_bsearch.wasm", + "test_bsearch", + vec![], + "../../emtests/test_bsearch.out" + ); +} diff --git a/src/emtests/test_ccall.rs b/src/emtests/test_ccall.rs new file mode 100644 index 000000000..37205b31d --- /dev/null +++ b/src/emtests/test_ccall.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_ccall() { + assert_emscripten_output!( + "../../emtests/test_ccall.wasm", + "test_ccall", + vec![], + "../../emtests/test_ccall.out" + ); +} diff --git a/src/emtests/test_complex.rs b/src/emtests/test_complex.rs new file mode 100644 index 000000000..78bfcbd7f --- /dev/null +++ b/src/emtests/test_complex.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_complex() { + assert_emscripten_output!( + "../../emtests/test_complex.wasm", + "test_complex", + vec![], + "../../emtests/test_complex.out" + ); +} diff --git a/src/emtests/test_demangle_stacks.rs b/src/emtests/test_demangle_stacks.rs new file mode 100644 index 000000000..e4ce42398 --- /dev/null +++ b/src/emtests/test_demangle_stacks.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_demangle_stacks() { + assert_emscripten_output!( + "../../emtests/test_demangle_stacks.wasm", + "test_demangle_stacks", + vec![], + "../../emtests/test_demangle_stacks.out" + ); +} diff --git a/src/emtests/test_demangle_stacks_noassert.rs b/src/emtests/test_demangle_stacks_noassert.rs new file mode 100644 index 000000000..3346023a0 --- /dev/null +++ b/src/emtests/test_demangle_stacks_noassert.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_demangle_stacks_noassert() { + assert_emscripten_output!( + "../../emtests/test_demangle_stacks_noassert.wasm", + "test_demangle_stacks_noassert", + vec![], + "../../emtests/test_demangle_stacks_noassert.out" + ); +} diff --git a/src/emtests/test_dlmalloc_partial_2.rs b/src/emtests/test_dlmalloc_partial_2.rs new file mode 100644 index 000000000..cc8866e48 --- /dev/null +++ b/src/emtests/test_dlmalloc_partial_2.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_dlmalloc_partial_2() { + assert_emscripten_output!( + "../../emtests/test_dlmalloc_partial_2.wasm", + "test_dlmalloc_partial_2", + vec![], + "../../emtests/test_dlmalloc_partial_2.out" + ); +} diff --git a/src/emtests/test_double_varargs.rs b/src/emtests/test_double_varargs.rs new file mode 100644 index 000000000..5d485532c --- /dev/null +++ b/src/emtests/test_double_varargs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_double_varargs() { + assert_emscripten_output!( + "../../emtests/test_double_varargs.wasm", + "test_double_varargs", + vec![], + "../../emtests/test_double_varargs.out" + ); +} diff --git a/src/emtests/test_em_asm.rs b/src/emtests/test_em_asm.rs new file mode 100644 index 000000000..b58c6154e --- /dev/null +++ b/src/emtests/test_em_asm.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_asm() { + assert_emscripten_output!( + "../../emtests/test_em_asm.wasm", + "test_em_asm", + vec![], + "../../emtests/test_em_asm.out" + ); +} diff --git a/src/emtests/test_em_asm_2.rs b/src/emtests/test_em_asm_2.rs new file mode 100644 index 000000000..c03369cbf --- /dev/null +++ b/src/emtests/test_em_asm_2.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_asm_2() { + assert_emscripten_output!( + "../../emtests/test_em_asm_2.wasm", + "test_em_asm_2", + vec![], + "../../emtests/test_em_asm_2.out" + ); +} diff --git a/src/emtests/test_em_asm_parameter_pack.rs b/src/emtests/test_em_asm_parameter_pack.rs new file mode 100644 index 000000000..167fb96b1 --- /dev/null +++ b/src/emtests/test_em_asm_parameter_pack.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_asm_parameter_pack() { + assert_emscripten_output!( + "../../emtests/test_em_asm_parameter_pack.wasm", + "test_em_asm_parameter_pack", + vec![], + "../../emtests/test_em_asm_parameter_pack.out" + ); +} diff --git a/src/emtests/test_em_asm_signatures.rs b/src/emtests/test_em_asm_signatures.rs new file mode 100644 index 000000000..0f0431cdf --- /dev/null +++ b/src/emtests/test_em_asm_signatures.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_asm_signatures() { + assert_emscripten_output!( + "../../emtests/test_em_asm_signatures.wasm", + "test_em_asm_signatures", + vec![], + "../../emtests/test_em_asm_signatures.out" + ); +} diff --git a/src/emtests/test_em_asm_unicode.rs b/src/emtests/test_em_asm_unicode.rs new file mode 100644 index 000000000..1f7c79e45 --- /dev/null +++ b/src/emtests/test_em_asm_unicode.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_asm_unicode() { + assert_emscripten_output!( + "../../emtests/test_em_asm_unicode.wasm", + "test_em_asm_unicode", + vec![], + "../../emtests/test_em_asm_unicode.out" + ); +} diff --git a/src/emtests/test_em_asm_unused_arguments.rs b/src/emtests/test_em_asm_unused_arguments.rs new file mode 100644 index 000000000..e6bc22978 --- /dev/null +++ b/src/emtests/test_em_asm_unused_arguments.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_asm_unused_arguments() { + assert_emscripten_output!( + "../../emtests/test_em_asm_unused_arguments.wasm", + "test_em_asm_unused_arguments", + vec![], + "../../emtests/test_em_asm_unused_arguments.out" + ); +} diff --git a/src/emtests/test_em_js.rs b/src/emtests/test_em_js.rs new file mode 100644 index 000000000..8818cc85d --- /dev/null +++ b/src/emtests/test_em_js.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_em_js() { + assert_emscripten_output!( + "../../emtests/test_em_js.wasm", + "test_em_js", + vec![], + "../../emtests/test_em_js.out" + ); +} diff --git a/src/emtests/test_emscripten_api.rs b/src/emtests/test_emscripten_api.rs new file mode 100644 index 000000000..8226ebaba --- /dev/null +++ b/src/emtests/test_emscripten_api.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_emscripten_api() { + assert_emscripten_output!( + "../../emtests/test_emscripten_api.wasm", + "test_emscripten_api", + vec![], + "../../emtests/test_emscripten_api.out" + ); +} diff --git a/src/emtests/test_erf.rs b/src/emtests/test_erf.rs new file mode 100644 index 000000000..638430d78 --- /dev/null +++ b/src/emtests/test_erf.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_erf() { + assert_emscripten_output!( + "../../emtests/test_erf.wasm", + "test_erf", + vec![], + "../../emtests/test_erf.out" + ); +} diff --git a/src/emtests/test_errar.rs b/src/emtests/test_errar.rs new file mode 100644 index 000000000..7ac7da0d7 --- /dev/null +++ b/src/emtests/test_errar.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_errar() { + assert_emscripten_output!( + "../../emtests/test_errar.wasm", + "test_errar", + vec![], + "../../emtests/test_errar.out" + ); +} diff --git a/src/emtests/test_exceptions_2.rs b/src/emtests/test_exceptions_2.rs new file mode 100644 index 000000000..550336510 --- /dev/null +++ b/src/emtests/test_exceptions_2.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_exceptions_2() { + assert_emscripten_output!( + "../../emtests/test_exceptions_2.wasm", + "test_exceptions_2", + vec![], + "../../emtests/test_exceptions_2.out" + ); +} diff --git a/src/emtests/test_exceptions_multi.rs b/src/emtests/test_exceptions_multi.rs new file mode 100644 index 000000000..d3b60c01b --- /dev/null +++ b/src/emtests/test_exceptions_multi.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_exceptions_multi() { + assert_emscripten_output!( + "../../emtests/test_exceptions_multi.wasm", + "test_exceptions_multi", + vec![], + "../../emtests/test_exceptions_multi.out" + ); +} diff --git a/src/emtests/test_exceptions_std.rs b/src/emtests/test_exceptions_std.rs new file mode 100644 index 000000000..571f20427 --- /dev/null +++ b/src/emtests/test_exceptions_std.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_exceptions_std() { + assert_emscripten_output!( + "../../emtests/test_exceptions_std.wasm", + "test_exceptions_std", + vec![], + "../../emtests/test_exceptions_std.out" + ); +} diff --git a/src/emtests/test_exceptions_white_list.rs b/src/emtests/test_exceptions_white_list.rs new file mode 100644 index 000000000..e5cdfb407 --- /dev/null +++ b/src/emtests/test_exceptions_white_list.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_exceptions_white_list() { + assert_emscripten_output!( + "../../emtests/test_exceptions_white_list.wasm", + "test_exceptions_white_list", + vec![], + "../../emtests/test_exceptions_white_list.out" + ); +} diff --git a/src/emtests/test_fast_math.rs b/src/emtests/test_fast_math.rs new file mode 100644 index 000000000..9a003045f --- /dev/null +++ b/src/emtests/test_fast_math.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_fast_math() { + assert_emscripten_output!( + "../../emtests/test_fast_math.wasm", + "test_fast_math", + vec![], + "../../emtests/test_fast_math.out" + ); +} diff --git a/src/emtests/test_flexarray_struct.rs b/src/emtests/test_flexarray_struct.rs new file mode 100644 index 000000000..f07a06580 --- /dev/null +++ b/src/emtests/test_flexarray_struct.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_flexarray_struct() { + assert_emscripten_output!( + "../../emtests/test_flexarray_struct.wasm", + "test_flexarray_struct", + vec![], + "../../emtests/test_flexarray_struct.out" + ); +} diff --git a/src/emtests/test_float32_precise.rs b/src/emtests/test_float32_precise.rs new file mode 100644 index 000000000..8f79d6ae0 --- /dev/null +++ b/src/emtests/test_float32_precise.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_float32_precise() { + assert_emscripten_output!( + "../../emtests/test_float32_precise.wasm", + "test_float32_precise", + vec![], + "../../emtests/test_float32_precise.out" + ); +} diff --git a/src/emtests/test_float_builtins.rs b/src/emtests/test_float_builtins.rs new file mode 100644 index 000000000..51d5baced --- /dev/null +++ b/src/emtests/test_float_builtins.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_float_builtins() { + assert_emscripten_output!( + "../../emtests/test_float_builtins.wasm", + "test_float_builtins", + vec![], + "../../emtests/test_float_builtins.out" + ); +} diff --git a/src/emtests/test_frexp.rs b/src/emtests/test_frexp.rs new file mode 100644 index 000000000..3ef3514fb --- /dev/null +++ b/src/emtests/test_frexp.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_frexp() { + assert_emscripten_output!( + "../../emtests/test_frexp.wasm", + "test_frexp", + vec![], + "../../emtests/test_frexp.out" + ); +} diff --git a/src/emtests/test_funcptr.rs b/src/emtests/test_funcptr.rs new file mode 100644 index 000000000..a6b1831e3 --- /dev/null +++ b/src/emtests/test_funcptr.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_funcptr() { + assert_emscripten_output!( + "../../emtests/test_funcptr.wasm", + "test_funcptr", + vec![], + "../../emtests/test_funcptr.out" + ); +} diff --git a/src/emtests/test_funcptr_namecollide.rs b/src/emtests/test_funcptr_namecollide.rs new file mode 100644 index 000000000..310e6f5af --- /dev/null +++ b/src/emtests/test_funcptr_namecollide.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_funcptr_namecollide() { + assert_emscripten_output!( + "../../emtests/test_funcptr_namecollide.wasm", + "test_funcptr_namecollide", + vec![], + "../../emtests/test_funcptr_namecollide.out" + ); +} diff --git a/src/emtests/test_funcptrfunc.rs b/src/emtests/test_funcptrfunc.rs new file mode 100644 index 000000000..0cddd51e7 --- /dev/null +++ b/src/emtests/test_funcptrfunc.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_funcptrfunc() { + assert_emscripten_output!( + "../../emtests/test_funcptrfunc.wasm", + "test_funcptrfunc", + vec![], + "../../emtests/test_funcptrfunc.out" + ); +} diff --git a/src/emtests/test_funcs.rs b/src/emtests/test_funcs.rs new file mode 100644 index 000000000..3faa4dc2e --- /dev/null +++ b/src/emtests/test_funcs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_funcs() { + assert_emscripten_output!( + "../../emtests/test_funcs.wasm", + "test_funcs", + vec![], + "../../emtests/test_funcs.out" + ); +} diff --git a/src/emtests/test_functionpointer_libfunc_varargs.rs b/src/emtests/test_functionpointer_libfunc_varargs.rs new file mode 100644 index 000000000..54f7a9a6c --- /dev/null +++ b/src/emtests/test_functionpointer_libfunc_varargs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_functionpointer_libfunc_varargs() { + assert_emscripten_output!( + "../../emtests/test_functionpointer_libfunc_varargs.wasm", + "test_functionpointer_libfunc_varargs", + vec![], + "../../emtests/test_functionpointer_libfunc_varargs.out" + ); +} diff --git a/src/emtests/test_fwrite_0.rs b/src/emtests/test_fwrite_0.rs new file mode 100644 index 000000000..4c72ff0f7 --- /dev/null +++ b/src/emtests/test_fwrite_0.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_fwrite_0() { + assert_emscripten_output!( + "../../emtests/test_fwrite_0.wasm", + "test_fwrite_0", + vec![], + "../../emtests/test_fwrite_0.out" + ); +} diff --git a/src/emtests/test_getgep.rs b/src/emtests/test_getgep.rs new file mode 100644 index 000000000..89d09bd81 --- /dev/null +++ b/src/emtests/test_getgep.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_getgep() { + assert_emscripten_output!( + "../../emtests/test_getgep.wasm", + "test_getgep", + vec![], + "../../emtests/test_getgep.out" + ); +} diff --git a/src/emtests/test_getloadavg.rs b/src/emtests/test_getloadavg.rs new file mode 100644 index 000000000..077fa5112 --- /dev/null +++ b/src/emtests/test_getloadavg.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_getloadavg() { + assert_emscripten_output!( + "../../emtests/test_getloadavg.wasm", + "test_getloadavg", + vec![], + "../../emtests/test_getloadavg.out" + ); +} diff --git a/src/emtests/test_getopt.rs b/src/emtests/test_getopt.rs new file mode 100644 index 000000000..b8eed280f --- /dev/null +++ b/src/emtests/test_getopt.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_getopt() { + assert_emscripten_output!( + "../../emtests/test_getopt.wasm", + "test_getopt", + vec![], + "../../emtests/test_getopt.out" + ); +} diff --git a/src/emtests/test_getopt_long.rs b/src/emtests/test_getopt_long.rs new file mode 100644 index 000000000..9ffb2be9e --- /dev/null +++ b/src/emtests/test_getopt_long.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_getopt_long() { + assert_emscripten_output!( + "../../emtests/test_getopt_long.wasm", + "test_getopt_long", + vec![], + "../../emtests/test_getopt_long.out" + ); +} diff --git a/src/emtests/test_globaldoubles.rs b/src/emtests/test_globaldoubles.rs new file mode 100644 index 000000000..dbe8b5867 --- /dev/null +++ b/src/emtests/test_globaldoubles.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_globaldoubles() { + assert_emscripten_output!( + "../../emtests/test_globaldoubles.wasm", + "test_globaldoubles", + vec![], + "../../emtests/test_globaldoubles.out" + ); +} diff --git a/src/emtests/test_globals.rs b/src/emtests/test_globals.rs new file mode 100644 index 000000000..f004409fa --- /dev/null +++ b/src/emtests/test_globals.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_globals() { + assert_emscripten_output!( + "../../emtests/test_globals.wasm", + "test_globals", + vec![], + "../../emtests/test_globals.out" + ); +} diff --git a/src/emtests/test_gmtime.rs b/src/emtests/test_gmtime.rs new file mode 100644 index 000000000..a418095ef --- /dev/null +++ b/src/emtests/test_gmtime.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_gmtime() { + assert_emscripten_output!( + "../../emtests/test_gmtime.wasm", + "test_gmtime", + vec![], + "../../emtests/test_gmtime.out" + ); +} diff --git a/src/emtests/test_hello_world.rs b/src/emtests/test_hello_world.rs new file mode 100644 index 000000000..5e5ba1360 --- /dev/null +++ b/src/emtests/test_hello_world.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_hello_world() { + assert_emscripten_output!( + "../../emtests/test_hello_world.wasm", + "test_hello_world", + vec![], + "../../emtests/test_hello_world.out" + ); +} diff --git a/src/emtests/test_i16_emcc_intrinsic.rs b/src/emtests/test_i16_emcc_intrinsic.rs new file mode 100644 index 000000000..84be78d83 --- /dev/null +++ b/src/emtests/test_i16_emcc_intrinsic.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_i16_emcc_intrinsic() { + assert_emscripten_output!( + "../../emtests/test_i16_emcc_intrinsic.wasm", + "test_i16_emcc_intrinsic", + vec![], + "../../emtests/test_i16_emcc_intrinsic.out" + ); +} diff --git a/src/emtests/test_i32_mul_precise.rs b/src/emtests/test_i32_mul_precise.rs new file mode 100644 index 000000000..1ec564a19 --- /dev/null +++ b/src/emtests/test_i32_mul_precise.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i32_mul_precise() { + assert_emscripten_output!( + "../../emtests/test_i32_mul_precise.wasm", + "test_i32_mul_precise", + vec![], + "../../emtests/test_i32_mul_precise.out" + ); +} diff --git a/src/emtests/test_i64.rs b/src/emtests/test_i64.rs new file mode 100644 index 000000000..b540bbf88 --- /dev/null +++ b/src/emtests/test_i64.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_i64() { + assert_emscripten_output!( + "../../emtests/test_i64.wasm", + "test_i64", + vec![], + "../../emtests/test_i64.out" + ); +} diff --git a/src/emtests/test_i64_4.rs b/src/emtests/test_i64_4.rs new file mode 100644 index 000000000..4fae69a4d --- /dev/null +++ b/src/emtests/test_i64_4.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_4() { + assert_emscripten_output!( + "../../emtests/test_i64_4.wasm", + "test_i64_4", + vec![], + "../../emtests/test_i64_4.out" + ); +} diff --git a/src/emtests/test_i64_7z.rs b/src/emtests/test_i64_7z.rs new file mode 100644 index 000000000..87cec8e69 --- /dev/null +++ b/src/emtests/test_i64_7z.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_i64_7z() { + assert_emscripten_output!( + "../../emtests/test_i64_7z.wasm", + "test_i64_7z", + vec![], + "../../emtests/test_i64_7z.out" + ); +} diff --git a/src/emtests/test_i64_cmp2.rs b/src/emtests/test_i64_cmp2.rs new file mode 100644 index 000000000..d94f52983 --- /dev/null +++ b/src/emtests/test_i64_cmp2.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_cmp2() { + assert_emscripten_output!( + "../../emtests/test_i64_cmp2.wasm", + "test_i64_cmp2", + vec![], + "../../emtests/test_i64_cmp2.out" + ); +} diff --git a/src/emtests/test_i64_i16.rs b/src/emtests/test_i64_i16.rs new file mode 100644 index 000000000..db7e848a7 --- /dev/null +++ b/src/emtests/test_i64_i16.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_i16() { + assert_emscripten_output!( + "../../emtests/test_i64_i16.wasm", + "test_i64_i16", + vec![], + "../../emtests/test_i64_i16.out" + ); +} diff --git a/src/emtests/test_i64_llabs.rs b/src/emtests/test_i64_llabs.rs new file mode 100644 index 000000000..7496a74d0 --- /dev/null +++ b/src/emtests/test_i64_llabs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_llabs() { + assert_emscripten_output!( + "../../emtests/test_i64_llabs.wasm", + "test_i64_llabs", + vec![], + "../../emtests/test_i64_llabs.out" + ); +} diff --git a/src/emtests/test_i64_precise.rs b/src/emtests/test_i64_precise.rs new file mode 100644 index 000000000..16ea27056 --- /dev/null +++ b/src/emtests/test_i64_precise.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_precise() { + assert_emscripten_output!( + "../../emtests/test_i64_precise.wasm", + "test_i64_precise", + vec![], + "../../emtests/test_i64_precise.out" + ); +} diff --git a/src/emtests/test_i64_precise_needed.rs b/src/emtests/test_i64_precise_needed.rs new file mode 100644 index 000000000..0afc59512 --- /dev/null +++ b/src/emtests/test_i64_precise_needed.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_precise_needed() { + assert_emscripten_output!( + "../../emtests/test_i64_precise_needed.wasm", + "test_i64_precise_needed", + vec![], + "../../emtests/test_i64_precise_needed.out" + ); +} diff --git a/src/emtests/test_i64_precise_unneeded.rs b/src/emtests/test_i64_precise_unneeded.rs new file mode 100644 index 000000000..324ab98ea --- /dev/null +++ b/src/emtests/test_i64_precise_unneeded.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_precise_unneeded() { + assert_emscripten_output!( + "../../emtests/test_i64_precise_unneeded.wasm", + "test_i64_precise_unneeded", + vec![], + "../../emtests/test_i64_precise_unneeded.out" + ); +} diff --git a/src/emtests/test_i64_qdouble.rs b/src/emtests/test_i64_qdouble.rs new file mode 100644 index 000000000..de58f5bdd --- /dev/null +++ b/src/emtests/test_i64_qdouble.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_qdouble() { + assert_emscripten_output!( + "../../emtests/test_i64_qdouble.wasm", + "test_i64_qdouble", + vec![], + "../../emtests/test_i64_qdouble.out" + ); +} diff --git a/src/emtests/test_i64_umul.rs b/src/emtests/test_i64_umul.rs new file mode 100644 index 000000000..4ddc08c5b --- /dev/null +++ b/src/emtests/test_i64_umul.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_umul() { + assert_emscripten_output!( + "../../emtests/test_i64_umul.wasm", + "test_i64_umul", + vec![], + "../../emtests/test_i64_umul.out" + ); +} diff --git a/src/emtests/test_i64_varargs.rs b/src/emtests/test_i64_varargs.rs new file mode 100644 index 000000000..e0558ff75 --- /dev/null +++ b/src/emtests/test_i64_varargs.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_i64_varargs() { + assert_emscripten_output!( + "../../emtests/test_i64_varargs.wasm", + "test_i64_varargs", + vec![], + "../../emtests/test_i64_varargs.out" + ); +} diff --git a/src/emtests/test_i64_zextneg.rs b/src/emtests/test_i64_zextneg.rs new file mode 100644 index 000000000..93adaad2c --- /dev/null +++ b/src/emtests/test_i64_zextneg.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_i64_zextneg() { + assert_emscripten_output!( + "../../emtests/test_i64_zextneg.wasm", + "test_i64_zextneg", + vec![], + "../../emtests/test_i64_zextneg.out" + ); +} diff --git a/src/emtests/test_if.rs b/src/emtests/test_if.rs new file mode 100644 index 000000000..ea111fa56 --- /dev/null +++ b/src/emtests/test_if.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_if() { + assert_emscripten_output!( + "../../emtests/test_if.wasm", + "test_if", + vec![], + "../../emtests/test_if.out" + ); +} diff --git a/src/emtests/test_if_else.rs b/src/emtests/test_if_else.rs new file mode 100644 index 000000000..df50aa171 --- /dev/null +++ b/src/emtests/test_if_else.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_if_else() { + assert_emscripten_output!( + "../../emtests/test_if_else.wasm", + "test_if_else", + vec![], + "../../emtests/test_if_else.out" + ); +} diff --git a/src/emtests/test_indirectbr.rs b/src/emtests/test_indirectbr.rs new file mode 100644 index 000000000..9997ea553 --- /dev/null +++ b/src/emtests/test_indirectbr.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_indirectbr() { + assert_emscripten_output!( + "../../emtests/test_indirectbr.wasm", + "test_indirectbr", + vec![], + "../../emtests/test_indirectbr.out" + ); +} diff --git a/src/emtests/test_indirectbr_many.rs b/src/emtests/test_indirectbr_many.rs new file mode 100644 index 000000000..fba25e6b2 --- /dev/null +++ b/src/emtests/test_indirectbr_many.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_indirectbr_many() { + assert_emscripten_output!( + "../../emtests/test_indirectbr_many.wasm", + "test_indirectbr_many", + vec![], + "../../emtests/test_indirectbr_many.out" + ); +} diff --git a/src/emtests/test_isnan.rs b/src/emtests/test_isnan.rs new file mode 100644 index 000000000..d1b560b13 --- /dev/null +++ b/src/emtests/test_isnan.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_isnan() { + assert_emscripten_output!( + "../../emtests/test_isnan.wasm", + "test_isnan", + vec![], + "../../emtests/test_isnan.out" + ); +} diff --git a/src/emtests/test_libcextra.rs b/src/emtests/test_libcextra.rs new file mode 100644 index 000000000..4dcff5c00 --- /dev/null +++ b/src/emtests/test_libcextra.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_libcextra() { + assert_emscripten_output!( + "../../emtests/test_libcextra.wasm", + "test_libcextra", + vec![], + "../../emtests/test_libcextra.out" + ); +} diff --git a/src/emtests/test_libgen.rs b/src/emtests/test_libgen.rs new file mode 100644 index 000000000..f9db3686a --- /dev/null +++ b/src/emtests/test_libgen.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_libgen() { + assert_emscripten_output!( + "../../emtests/test_libgen.wasm", + "test_libgen", + vec![], + "../../emtests/test_libgen.out" + ); +} diff --git a/src/emtests/test_literal_negative_zero.rs b/src/emtests/test_literal_negative_zero.rs new file mode 100644 index 000000000..71d50c9c2 --- /dev/null +++ b/src/emtests/test_literal_negative_zero.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_literal_negative_zero() { + assert_emscripten_output!( + "../../emtests/test_literal_negative_zero.wasm", + "test_literal_negative_zero", + vec![], + "../../emtests/test_literal_negative_zero.out" + ); +} diff --git a/src/emtests/test_llrint.rs b/src/emtests/test_llrint.rs new file mode 100644 index 000000000..2d1da70df --- /dev/null +++ b/src/emtests/test_llrint.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_llrint() { + assert_emscripten_output!( + "../../emtests/test_llrint.wasm", + "test_llrint", + vec![], + "../../emtests/test_llrint.out" + ); +} diff --git a/src/emtests/test_llvm_fabs.rs b/src/emtests/test_llvm_fabs.rs new file mode 100644 index 000000000..a356f7055 --- /dev/null +++ b/src/emtests/test_llvm_fabs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_llvm_fabs() { + assert_emscripten_output!( + "../../emtests/test_llvm_fabs.wasm", + "test_llvm_fabs", + vec![], + "../../emtests/test_llvm_fabs.out" + ); +} diff --git a/src/emtests/test_llvm_intrinsics.rs b/src/emtests/test_llvm_intrinsics.rs new file mode 100644 index 000000000..95a9e8ce3 --- /dev/null +++ b/src/emtests/test_llvm_intrinsics.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_llvm_intrinsics() { + assert_emscripten_output!( + "../../emtests/test_llvm_intrinsics.wasm", + "test_llvm_intrinsics", + vec![], + "../../emtests/test_llvm_intrinsics.out" + ); +} diff --git a/src/emtests/test_llvmswitch.rs b/src/emtests/test_llvmswitch.rs new file mode 100644 index 000000000..edeb31701 --- /dev/null +++ b/src/emtests/test_llvmswitch.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_llvmswitch() { + assert_emscripten_output!( + "../../emtests/test_llvmswitch.wasm", + "test_llvmswitch", + vec![], + "../../emtests/test_llvmswitch.out" + ); +} diff --git a/src/emtests/test_longjmp.rs b/src/emtests/test_longjmp.rs new file mode 100644 index 000000000..c125f5d21 --- /dev/null +++ b/src/emtests/test_longjmp.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp() { + assert_emscripten_output!( + "../../emtests/test_longjmp.wasm", + "test_longjmp", + vec![], + "../../emtests/test_longjmp.out" + ); +} diff --git a/src/emtests/test_longjmp2.rs b/src/emtests/test_longjmp2.rs new file mode 100644 index 000000000..44989e08f --- /dev/null +++ b/src/emtests/test_longjmp2.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp2() { + assert_emscripten_output!( + "../../emtests/test_longjmp2.wasm", + "test_longjmp2", + vec![], + "../../emtests/test_longjmp2.out" + ); +} diff --git a/src/emtests/test_longjmp3.rs b/src/emtests/test_longjmp3.rs new file mode 100644 index 000000000..4ce0e2e6f --- /dev/null +++ b/src/emtests/test_longjmp3.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp3() { + assert_emscripten_output!( + "../../emtests/test_longjmp3.wasm", + "test_longjmp3", + vec![], + "../../emtests/test_longjmp3.out" + ); +} diff --git a/src/emtests/test_longjmp4.rs b/src/emtests/test_longjmp4.rs new file mode 100644 index 000000000..f3c53ea56 --- /dev/null +++ b/src/emtests/test_longjmp4.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp4() { + assert_emscripten_output!( + "../../emtests/test_longjmp4.wasm", + "test_longjmp4", + vec![], + "../../emtests/test_longjmp4.out" + ); +} diff --git a/src/emtests/test_longjmp_exc.rs b/src/emtests/test_longjmp_exc.rs new file mode 100644 index 000000000..bdf663094 --- /dev/null +++ b/src/emtests/test_longjmp_exc.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp_exc() { + assert_emscripten_output!( + "../../emtests/test_longjmp_exc.wasm", + "test_longjmp_exc", + vec![], + "../../emtests/test_longjmp_exc.out" + ); +} diff --git a/src/emtests/test_longjmp_funcptr.rs b/src/emtests/test_longjmp_funcptr.rs new file mode 100644 index 000000000..a40316558 --- /dev/null +++ b/src/emtests/test_longjmp_funcptr.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp_funcptr() { + assert_emscripten_output!( + "../../emtests/test_longjmp_funcptr.wasm", + "test_longjmp_funcptr", + vec![], + "../../emtests/test_longjmp_funcptr.out" + ); +} diff --git a/src/emtests/test_longjmp_repeat.rs b/src/emtests/test_longjmp_repeat.rs new file mode 100644 index 000000000..6fbc65527 --- /dev/null +++ b/src/emtests/test_longjmp_repeat.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp_repeat() { + assert_emscripten_output!( + "../../emtests/test_longjmp_repeat.wasm", + "test_longjmp_repeat", + vec![], + "../../emtests/test_longjmp_repeat.out" + ); +} diff --git a/src/emtests/test_longjmp_stacked.rs b/src/emtests/test_longjmp_stacked.rs new file mode 100644 index 000000000..b145e6da4 --- /dev/null +++ b/src/emtests/test_longjmp_stacked.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp_stacked() { + assert_emscripten_output!( + "../../emtests/test_longjmp_stacked.wasm", + "test_longjmp_stacked", + vec![], + "../../emtests/test_longjmp_stacked.out" + ); +} diff --git a/src/emtests/test_longjmp_throw.rs b/src/emtests/test_longjmp_throw.rs new file mode 100644 index 000000000..5f97462ad --- /dev/null +++ b/src/emtests/test_longjmp_throw.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp_throw() { + assert_emscripten_output!( + "../../emtests/test_longjmp_throw.wasm", + "test_longjmp_throw", + vec![], + "../../emtests/test_longjmp_throw.out" + ); +} diff --git a/src/emtests/test_longjmp_unwind.rs b/src/emtests/test_longjmp_unwind.rs new file mode 100644 index 000000000..eec134135 --- /dev/null +++ b/src/emtests/test_longjmp_unwind.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_longjmp_unwind() { + assert_emscripten_output!( + "../../emtests/test_longjmp_unwind.wasm", + "test_longjmp_unwind", + vec![], + "../../emtests/test_longjmp_unwind.out" + ); +} diff --git a/src/emtests/test_loop.rs b/src/emtests/test_loop.rs new file mode 100644 index 000000000..3cfa9ad91 --- /dev/null +++ b/src/emtests/test_loop.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_loop() { + assert_emscripten_output!( + "../../emtests/test_loop.wasm", + "test_loop", + vec![], + "../../emtests/test_loop.out" + ); +} diff --git a/src/emtests/test_lower_intrinsics.rs b/src/emtests/test_lower_intrinsics.rs new file mode 100644 index 000000000..118e537ba --- /dev/null +++ b/src/emtests/test_lower_intrinsics.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_lower_intrinsics() { + assert_emscripten_output!( + "../../emtests/test_lower_intrinsics.wasm", + "test_lower_intrinsics", + vec![], + "../../emtests/test_lower_intrinsics.out" + ); +} diff --git a/src/emtests/test_main_thread_async_em_asm.rs b/src/emtests/test_main_thread_async_em_asm.rs new file mode 100644 index 000000000..dae6da6e7 --- /dev/null +++ b/src/emtests/test_main_thread_async_em_asm.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_main_thread_async_em_asm() { + assert_emscripten_output!( + "../../emtests/test_main_thread_async_em_asm.wasm", + "test_main_thread_async_em_asm", + vec![], + "../../emtests/test_main_thread_async_em_asm.out" + ); +} diff --git a/src/emtests/test_mainenv.rs b/src/emtests/test_mainenv.rs new file mode 100644 index 000000000..54d04e865 --- /dev/null +++ b/src/emtests/test_mainenv.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_mainenv() { + assert_emscripten_output!( + "../../emtests/test_mainenv.wasm", + "test_mainenv", + vec![], + "../../emtests/test_mainenv.out" + ); +} diff --git a/src/emtests/test_mathfuncptr.rs b/src/emtests/test_mathfuncptr.rs new file mode 100644 index 000000000..28e80ef0d --- /dev/null +++ b/src/emtests/test_mathfuncptr.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_mathfuncptr() { + assert_emscripten_output!( + "../../emtests/test_mathfuncptr.wasm", + "test_mathfuncptr", + vec![], + "../../emtests/test_mathfuncptr.out" + ); +} diff --git a/src/emtests/test_memcpy2.rs b/src/emtests/test_memcpy2.rs new file mode 100644 index 000000000..806402ea7 --- /dev/null +++ b/src/emtests/test_memcpy2.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_memcpy2() { + assert_emscripten_output!( + "../../emtests/test_memcpy2.wasm", + "test_memcpy2", + vec![], + "../../emtests/test_memcpy2.out" + ); +} diff --git a/src/emtests/test_memcpy3.rs b/src/emtests/test_memcpy3.rs new file mode 100644 index 000000000..85bb10a35 --- /dev/null +++ b/src/emtests/test_memcpy3.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_memcpy3() { + assert_emscripten_output!( + "../../emtests/test_memcpy3.wasm", + "test_memcpy3", + vec![], + "../../emtests/test_memcpy3.out" + ); +} diff --git a/src/emtests/test_memcpy_memcmp.rs b/src/emtests/test_memcpy_memcmp.rs new file mode 100644 index 000000000..3e8c4ba78 --- /dev/null +++ b/src/emtests/test_memcpy_memcmp.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_memcpy_memcmp() { + assert_emscripten_output!( + "../../emtests/test_memcpy_memcmp.wasm", + "test_memcpy_memcmp", + vec![], + "../../emtests/test_memcpy_memcmp.out" + ); +} diff --git a/src/emtests/test_memmove.rs b/src/emtests/test_memmove.rs new file mode 100644 index 000000000..65102f65b --- /dev/null +++ b/src/emtests/test_memmove.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_memmove() { + assert_emscripten_output!( + "../../emtests/test_memmove.wasm", + "test_memmove", + vec![], + "../../emtests/test_memmove.out" + ); +} diff --git a/src/emtests/test_memmove2.rs b/src/emtests/test_memmove2.rs new file mode 100644 index 000000000..abacdd55c --- /dev/null +++ b/src/emtests/test_memmove2.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_memmove2() { + assert_emscripten_output!( + "../../emtests/test_memmove2.wasm", + "test_memmove2", + vec![], + "../../emtests/test_memmove2.out" + ); +} diff --git a/src/emtests/test_memmove3.rs b/src/emtests/test_memmove3.rs new file mode 100644 index 000000000..7635102f8 --- /dev/null +++ b/src/emtests/test_memmove3.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_memmove3() { + assert_emscripten_output!( + "../../emtests/test_memmove3.wasm", + "test_memmove3", + vec![], + "../../emtests/test_memmove3.out" + ); +} diff --git a/src/emtests/test_memset.rs b/src/emtests/test_memset.rs new file mode 100644 index 000000000..00d4f9f76 --- /dev/null +++ b/src/emtests/test_memset.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_memset() { + assert_emscripten_output!( + "../../emtests/test_memset.wasm", + "test_memset", + vec![], + "../../emtests/test_memset.out" + ); +} diff --git a/src/emtests/test_mmap.rs b/src/emtests/test_mmap.rs new file mode 100644 index 000000000..65fcfb6ae --- /dev/null +++ b/src/emtests/test_mmap.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_mmap() { + assert_emscripten_output!( + "../../emtests/test_mmap.wasm", + "test_mmap", + vec![], + "../../emtests/test_mmap.out" + ); +} diff --git a/src/emtests/test_negative_zero.rs b/src/emtests/test_negative_zero.rs new file mode 100644 index 000000000..047bcfcba --- /dev/null +++ b/src/emtests/test_negative_zero.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_negative_zero() { + assert_emscripten_output!( + "../../emtests/test_negative_zero.wasm", + "test_negative_zero", + vec![], + "../../emtests/test_negative_zero.out" + ); +} diff --git a/src/emtests/test_nested_struct_varargs.rs b/src/emtests/test_nested_struct_varargs.rs new file mode 100644 index 000000000..189784588 --- /dev/null +++ b/src/emtests/test_nested_struct_varargs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_nested_struct_varargs() { + assert_emscripten_output!( + "../../emtests/test_nested_struct_varargs.wasm", + "test_nested_struct_varargs", + vec![], + "../../emtests/test_nested_struct_varargs.out" + ); +} diff --git a/src/emtests/test_nl_types.rs b/src/emtests/test_nl_types.rs new file mode 100644 index 000000000..101ee4894 --- /dev/null +++ b/src/emtests/test_nl_types.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_nl_types() { + assert_emscripten_output!( + "../../emtests/test_nl_types.wasm", + "test_nl_types", + vec![], + "../../emtests/test_nl_types.out" + ); +} diff --git a/src/emtests/test_perrar.rs b/src/emtests/test_perrar.rs new file mode 100644 index 000000000..96f491f49 --- /dev/null +++ b/src/emtests/test_perrar.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_perrar() { + assert_emscripten_output!( + "../../emtests/test_perrar.wasm", + "test_perrar", + vec![], + "../../emtests/test_perrar.out" + ); +} diff --git a/src/emtests/test_phiundef.rs b/src/emtests/test_phiundef.rs new file mode 100644 index 000000000..fbe4203f7 --- /dev/null +++ b/src/emtests/test_phiundef.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_phiundef() { + assert_emscripten_output!( + "../../emtests/test_phiundef.wasm", + "test_phiundef", + vec![], + "../../emtests/test_phiundef.out" + ); +} diff --git a/src/emtests/test_poll.rs b/src/emtests/test_poll.rs new file mode 100644 index 000000000..b23969a58 --- /dev/null +++ b/src/emtests/test_poll.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_poll() { + assert_emscripten_output!( + "../../emtests/test_poll.wasm", + "test_poll", + vec![], + "../../emtests/test_poll.out" + ); +} diff --git a/src/emtests/test_posixtime.rs b/src/emtests/test_posixtime.rs new file mode 100644 index 000000000..29602724d --- /dev/null +++ b/src/emtests/test_posixtime.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_posixtime() { + assert_emscripten_output!( + "../../emtests/test_posixtime.wasm", + "test_posixtime", + vec![], + "../../emtests/test_posixtime.out" + ); +} diff --git a/src/emtests/test_printf_2.rs b/src/emtests/test_printf_2.rs new file mode 100644 index 000000000..62151b8a4 --- /dev/null +++ b/src/emtests/test_printf_2.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_printf_2() { + assert_emscripten_output!( + "../../emtests/test_printf_2.wasm", + "test_printf_2", + vec![], + "../../emtests/test_printf_2.out" + ); +} diff --git a/src/emtests/test_printf_more.rs b/src/emtests/test_printf_more.rs new file mode 100644 index 000000000..6dc34233f --- /dev/null +++ b/src/emtests/test_printf_more.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_printf_more() { + assert_emscripten_output!( + "../../emtests/test_printf_more.wasm", + "test_printf_more", + vec![], + "../../emtests/test_printf_more.out" + ); +} diff --git a/src/emtests/test_regex.rs b/src/emtests/test_regex.rs new file mode 100644 index 000000000..03ab62295 --- /dev/null +++ b/src/emtests/test_regex.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_regex() { + assert_emscripten_output!( + "../../emtests/test_regex.wasm", + "test_regex", + vec![], + "../../emtests/test_regex.out" + ); +} diff --git a/src/emtests/test_relocatable_void_function.rs b/src/emtests/test_relocatable_void_function.rs new file mode 100644 index 000000000..7cdd382b8 --- /dev/null +++ b/src/emtests/test_relocatable_void_function.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_relocatable_void_function() { + assert_emscripten_output!( + "../../emtests/test_relocatable_void_function.wasm", + "test_relocatable_void_function", + vec![], + "../../emtests/test_relocatable_void_function.out" + ); +} diff --git a/src/emtests/test_rounding.rs b/src/emtests/test_rounding.rs new file mode 100644 index 000000000..defd8df6f --- /dev/null +++ b/src/emtests/test_rounding.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_rounding() { + assert_emscripten_output!( + "../../emtests/test_rounding.wasm", + "test_rounding", + vec![], + "../../emtests/test_rounding.out" + ); +} diff --git a/src/emtests/test_set_align.rs b/src/emtests/test_set_align.rs new file mode 100644 index 000000000..039d7f0c8 --- /dev/null +++ b/src/emtests/test_set_align.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_set_align() { + assert_emscripten_output!( + "../../emtests/test_set_align.wasm", + "test_set_align", + vec![], + "../../emtests/test_set_align.out" + ); +} diff --git a/src/emtests/test_siglongjmp.rs b/src/emtests/test_siglongjmp.rs new file mode 100644 index 000000000..3407023b4 --- /dev/null +++ b/src/emtests/test_siglongjmp.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_siglongjmp() { + assert_emscripten_output!( + "../../emtests/test_siglongjmp.wasm", + "test_siglongjmp", + vec![], + "../../emtests/test_siglongjmp.out" + ); +} diff --git a/src/emtests/test_sintvars.rs b/src/emtests/test_sintvars.rs new file mode 100644 index 000000000..cf506e10c --- /dev/null +++ b/src/emtests/test_sintvars.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sintvars() { + assert_emscripten_output!( + "../../emtests/test_sintvars.wasm", + "test_sintvars", + vec![], + "../../emtests/test_sintvars.out" + ); +} diff --git a/src/emtests/test_sizeof.rs b/src/emtests/test_sizeof.rs new file mode 100644 index 000000000..516f0c58f --- /dev/null +++ b/src/emtests/test_sizeof.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sizeof() { + assert_emscripten_output!( + "../../emtests/test_sizeof.wasm", + "test_sizeof", + vec![], + "../../emtests/test_sizeof.out" + ); +} diff --git a/src/emtests/test_sscanf.rs b/src/emtests/test_sscanf.rs new file mode 100644 index 000000000..72353b9db --- /dev/null +++ b/src/emtests/test_sscanf.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf() { + assert_emscripten_output!( + "../../emtests/test_sscanf.wasm", + "test_sscanf", + vec![], + "../../emtests/test_sscanf.out" + ); +} diff --git a/src/emtests/test_sscanf_3.rs b/src/emtests/test_sscanf_3.rs new file mode 100644 index 000000000..816045fd5 --- /dev/null +++ b/src/emtests/test_sscanf_3.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_3() { + assert_emscripten_output!( + "../../emtests/test_sscanf_3.wasm", + "test_sscanf_3", + vec![], + "../../emtests/test_sscanf_3.out" + ); +} diff --git a/src/emtests/test_sscanf_4.rs b/src/emtests/test_sscanf_4.rs new file mode 100644 index 000000000..d859d1767 --- /dev/null +++ b/src/emtests/test_sscanf_4.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_4() { + assert_emscripten_output!( + "../../emtests/test_sscanf_4.wasm", + "test_sscanf_4", + vec![], + "../../emtests/test_sscanf_4.out" + ); +} diff --git a/src/emtests/test_sscanf_5.rs b/src/emtests/test_sscanf_5.rs new file mode 100644 index 000000000..22d4d5315 --- /dev/null +++ b/src/emtests/test_sscanf_5.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_5() { + assert_emscripten_output!( + "../../emtests/test_sscanf_5.wasm", + "test_sscanf_5", + vec![], + "../../emtests/test_sscanf_5.out" + ); +} diff --git a/src/emtests/test_sscanf_6.rs b/src/emtests/test_sscanf_6.rs new file mode 100644 index 000000000..52be26949 --- /dev/null +++ b/src/emtests/test_sscanf_6.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_6() { + assert_emscripten_output!( + "../../emtests/test_sscanf_6.wasm", + "test_sscanf_6", + vec![], + "../../emtests/test_sscanf_6.out" + ); +} diff --git a/src/emtests/test_sscanf_caps.rs b/src/emtests/test_sscanf_caps.rs new file mode 100644 index 000000000..5f2d64b90 --- /dev/null +++ b/src/emtests/test_sscanf_caps.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_caps() { + assert_emscripten_output!( + "../../emtests/test_sscanf_caps.wasm", + "test_sscanf_caps", + vec![], + "../../emtests/test_sscanf_caps.out" + ); +} diff --git a/src/emtests/test_sscanf_float.rs b/src/emtests/test_sscanf_float.rs new file mode 100644 index 000000000..39d3b5cba --- /dev/null +++ b/src/emtests/test_sscanf_float.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_float() { + assert_emscripten_output!( + "../../emtests/test_sscanf_float.wasm", + "test_sscanf_float", + vec![], + "../../emtests/test_sscanf_float.out" + ); +} diff --git a/src/emtests/test_sscanf_hex.rs b/src/emtests/test_sscanf_hex.rs new file mode 100644 index 000000000..077bc57e9 --- /dev/null +++ b/src/emtests/test_sscanf_hex.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_sscanf_hex() { + assert_emscripten_output!( + "../../emtests/test_sscanf_hex.wasm", + "test_sscanf_hex", + vec![], + "../../emtests/test_sscanf_hex.out" + ); +} diff --git a/src/emtests/test_sscanf_n.rs b/src/emtests/test_sscanf_n.rs new file mode 100644 index 000000000..57f90b142 --- /dev/null +++ b/src/emtests/test_sscanf_n.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_sscanf_n() { + assert_emscripten_output!( + "../../emtests/test_sscanf_n.wasm", + "test_sscanf_n", + vec![], + "../../emtests/test_sscanf_n.out" + ); +} diff --git a/src/emtests/test_sscanf_other_whitespace.rs b/src/emtests/test_sscanf_other_whitespace.rs new file mode 100644 index 000000000..40f7e05b7 --- /dev/null +++ b/src/emtests/test_sscanf_other_whitespace.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_sscanf_other_whitespace() { + assert_emscripten_output!( + "../../emtests/test_sscanf_other_whitespace.wasm", + "test_sscanf_other_whitespace", + vec![], + "../../emtests/test_sscanf_other_whitespace.out" + ); +} diff --git a/src/emtests/test_sscanf_skip.rs b/src/emtests/test_sscanf_skip.rs new file mode 100644 index 000000000..f8df1660a --- /dev/null +++ b/src/emtests/test_sscanf_skip.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_sscanf_skip() { + assert_emscripten_output!( + "../../emtests/test_sscanf_skip.wasm", + "test_sscanf_skip", + vec![], + "../../emtests/test_sscanf_skip.out" + ); +} diff --git a/src/emtests/test_sscanf_whitespace.rs b/src/emtests/test_sscanf_whitespace.rs new file mode 100644 index 000000000..9b5ecc4c3 --- /dev/null +++ b/src/emtests/test_sscanf_whitespace.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_sscanf_whitespace() { + assert_emscripten_output!( + "../../emtests/test_sscanf_whitespace.wasm", + "test_sscanf_whitespace", + vec![], + "../../emtests/test_sscanf_whitespace.out" + ); +} diff --git a/src/emtests/test_stack_varargs.rs b/src/emtests/test_stack_varargs.rs new file mode 100644 index 000000000..7507e9ec9 --- /dev/null +++ b/src/emtests/test_stack_varargs.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_stack_varargs() { + assert_emscripten_output!( + "../../emtests/test_stack_varargs.wasm", + "test_stack_varargs", + vec![], + "../../emtests/test_stack_varargs.out" + ); +} diff --git a/src/emtests/test_stack_void.rs b/src/emtests/test_stack_void.rs new file mode 100644 index 000000000..2a89f51fe --- /dev/null +++ b/src/emtests/test_stack_void.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_stack_void() { + assert_emscripten_output!( + "../../emtests/test_stack_void.wasm", + "test_stack_void", + vec![], + "../../emtests/test_stack_void.out" + ); +} diff --git a/src/emtests/test_statvfs.rs b/src/emtests/test_statvfs.rs new file mode 100644 index 000000000..79e1de4f2 --- /dev/null +++ b/src/emtests/test_statvfs.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_statvfs() { + assert_emscripten_output!( + "../../emtests/test_statvfs.wasm", + "test_statvfs", + vec![], + "../../emtests/test_statvfs.out" + ); +} diff --git a/src/emtests/test_std_cout_new.rs b/src/emtests/test_std_cout_new.rs new file mode 100644 index 000000000..0ec8746c0 --- /dev/null +++ b/src/emtests/test_std_cout_new.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_std_cout_new() { + assert_emscripten_output!( + "../../emtests/test_std_cout_new.wasm", + "test_std_cout_new", + vec![], + "../../emtests/test_std_cout_new.out" + ); +} diff --git a/src/emtests/test_strcasecmp.rs b/src/emtests/test_strcasecmp.rs new file mode 100644 index 000000000..294017872 --- /dev/null +++ b/src/emtests/test_strcasecmp.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strcasecmp() { + assert_emscripten_output!( + "../../emtests/test_strcasecmp.wasm", + "test_strcasecmp", + vec![], + "../../emtests/test_strcasecmp.out" + ); +} diff --git a/src/emtests/test_strcmp_uni.rs b/src/emtests/test_strcmp_uni.rs new file mode 100644 index 000000000..e729c00ae --- /dev/null +++ b/src/emtests/test_strcmp_uni.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strcmp_uni() { + assert_emscripten_output!( + "../../emtests/test_strcmp_uni.wasm", + "test_strcmp_uni", + vec![], + "../../emtests/test_strcmp_uni.out" + ); +} diff --git a/src/emtests/test_strftime.rs b/src/emtests/test_strftime.rs new file mode 100644 index 000000000..ea98fe0c8 --- /dev/null +++ b/src/emtests/test_strftime.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_strftime() { + assert_emscripten_output!( + "../../emtests/test_strftime.wasm", + "test_strftime", + vec![], + "../../emtests/test_strftime.out" + ); +} diff --git a/src/emtests/test_strings.rs b/src/emtests/test_strings.rs new file mode 100644 index 000000000..8c0bfd113 --- /dev/null +++ b/src/emtests/test_strings.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_strings() { + assert_emscripten_output!( + "../../emtests/test_strings.wasm", + "test_strings", + vec![], + "../../emtests/test_strings.out" + ); +} diff --git a/src/emtests/test_strndup.rs b/src/emtests/test_strndup.rs new file mode 100644 index 000000000..62ac406e9 --- /dev/null +++ b/src/emtests/test_strndup.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strndup() { + assert_emscripten_output!( + "../../emtests/test_strndup.wasm", + "test_strndup", + vec![], + "../../emtests/test_strndup.out" + ); +} diff --git a/src/emtests/test_strptime_days.rs b/src/emtests/test_strptime_days.rs new file mode 100644 index 000000000..ea6accc62 --- /dev/null +++ b/src/emtests/test_strptime_days.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_strptime_days() { + assert_emscripten_output!( + "../../emtests/test_strptime_days.wasm", + "test_strptime_days", + vec![], + "../../emtests/test_strptime_days.out" + ); +} diff --git a/src/emtests/test_strptime_reentrant.rs b/src/emtests/test_strptime_reentrant.rs new file mode 100644 index 000000000..35f89ae3d --- /dev/null +++ b/src/emtests/test_strptime_reentrant.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_strptime_reentrant() { + assert_emscripten_output!( + "../../emtests/test_strptime_reentrant.wasm", + "test_strptime_reentrant", + vec![], + "../../emtests/test_strptime_reentrant.out" + ); +} diff --git a/src/emtests/test_strstr.rs b/src/emtests/test_strstr.rs new file mode 100644 index 000000000..080d3bbda --- /dev/null +++ b/src/emtests/test_strstr.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strstr() { + assert_emscripten_output!( + "../../emtests/test_strstr.wasm", + "test_strstr", + vec![], + "../../emtests/test_strstr.out" + ); +} diff --git a/src/emtests/test_strtod.rs b/src/emtests/test_strtod.rs new file mode 100644 index 000000000..cab755982 --- /dev/null +++ b/src/emtests/test_strtod.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtod() { + assert_emscripten_output!( + "../../emtests/test_strtod.wasm", + "test_strtod", + vec![], + "../../emtests/test_strtod.out" + ); +} diff --git a/src/emtests/test_strtok.rs b/src/emtests/test_strtok.rs new file mode 100644 index 000000000..1399ef683 --- /dev/null +++ b/src/emtests/test_strtok.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtok() { + assert_emscripten_output!( + "../../emtests/test_strtok.wasm", + "test_strtok", + vec![], + "../../emtests/test_strtok.out" + ); +} diff --git a/src/emtests/test_strtol_bin.rs b/src/emtests/test_strtol_bin.rs new file mode 100644 index 000000000..fd847c186 --- /dev/null +++ b/src/emtests/test_strtol_bin.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtol_bin() { + assert_emscripten_output!( + "../../emtests/test_strtol_bin.wasm", + "test_strtol_bin", + vec![], + "../../emtests/test_strtol_bin.out" + ); +} diff --git a/src/emtests/test_strtol_dec.rs b/src/emtests/test_strtol_dec.rs new file mode 100644 index 000000000..a485bfa97 --- /dev/null +++ b/src/emtests/test_strtol_dec.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtol_dec() { + assert_emscripten_output!( + "../../emtests/test_strtol_dec.wasm", + "test_strtol_dec", + vec![], + "../../emtests/test_strtol_dec.out" + ); +} diff --git a/src/emtests/test_strtol_hex.rs b/src/emtests/test_strtol_hex.rs new file mode 100644 index 000000000..57f108259 --- /dev/null +++ b/src/emtests/test_strtol_hex.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtol_hex() { + assert_emscripten_output!( + "../../emtests/test_strtol_hex.wasm", + "test_strtol_hex", + vec![], + "../../emtests/test_strtol_hex.out" + ); +} diff --git a/src/emtests/test_strtol_oct.rs b/src/emtests/test_strtol_oct.rs new file mode 100644 index 000000000..9e4340f04 --- /dev/null +++ b/src/emtests/test_strtol_oct.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtol_oct() { + assert_emscripten_output!( + "../../emtests/test_strtol_oct.wasm", + "test_strtol_oct", + vec![], + "../../emtests/test_strtol_oct.out" + ); +} diff --git a/src/emtests/test_strtold.rs b/src/emtests/test_strtold.rs new file mode 100644 index 000000000..935001356 --- /dev/null +++ b/src/emtests/test_strtold.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_strtold() { + assert_emscripten_output!( + "../../emtests/test_strtold.wasm", + "test_strtold", + vec![], + "../../emtests/test_strtold.out" + ); +} diff --git a/src/emtests/test_strtoll_bin.rs b/src/emtests/test_strtoll_bin.rs new file mode 100644 index 000000000..1276f0c85 --- /dev/null +++ b/src/emtests/test_strtoll_bin.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtoll_bin() { + assert_emscripten_output!( + "../../emtests/test_strtoll_bin.wasm", + "test_strtoll_bin", + vec![], + "../../emtests/test_strtoll_bin.out" + ); +} diff --git a/src/emtests/test_strtoll_dec.rs b/src/emtests/test_strtoll_dec.rs new file mode 100644 index 000000000..6e902d0ed --- /dev/null +++ b/src/emtests/test_strtoll_dec.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtoll_dec() { + assert_emscripten_output!( + "../../emtests/test_strtoll_dec.wasm", + "test_strtoll_dec", + vec![], + "../../emtests/test_strtoll_dec.out" + ); +} diff --git a/src/emtests/test_strtoll_hex.rs b/src/emtests/test_strtoll_hex.rs new file mode 100644 index 000000000..cc98e0fd0 --- /dev/null +++ b/src/emtests/test_strtoll_hex.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtoll_hex() { + assert_emscripten_output!( + "../../emtests/test_strtoll_hex.wasm", + "test_strtoll_hex", + vec![], + "../../emtests/test_strtoll_hex.out" + ); +} diff --git a/src/emtests/test_strtoll_oct.rs b/src/emtests/test_strtoll_oct.rs new file mode 100644 index 000000000..13ed7f5b2 --- /dev/null +++ b/src/emtests/test_strtoll_oct.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_strtoll_oct() { + assert_emscripten_output!( + "../../emtests/test_strtoll_oct.wasm", + "test_strtoll_oct", + vec![], + "../../emtests/test_strtoll_oct.out" + ); +} diff --git a/src/emtests/test_struct_varargs.rs b/src/emtests/test_struct_varargs.rs new file mode 100644 index 000000000..71f66595b --- /dev/null +++ b/src/emtests/test_struct_varargs.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_struct_varargs() { + assert_emscripten_output!( + "../../emtests/test_struct_varargs.wasm", + "test_struct_varargs", + vec![], + "../../emtests/test_struct_varargs.out" + ); +} diff --git a/src/emtests/test_time_c.rs b/src/emtests/test_time_c.rs new file mode 100644 index 000000000..6a4c73189 --- /dev/null +++ b/src/emtests/test_time_c.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_time_c() { + assert_emscripten_output!( + "../../emtests/test_time_c.wasm", + "test_time_c", + vec![], + "../../emtests/test_time_c.out" + ); +} diff --git a/src/emtests/test_tracing.rs b/src/emtests/test_tracing.rs new file mode 100644 index 000000000..957e87c10 --- /dev/null +++ b/src/emtests/test_tracing.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_tracing() { + assert_emscripten_output!( + "../../emtests/test_tracing.wasm", + "test_tracing", + vec![], + "../../emtests/test_tracing.out" + ); +} diff --git a/src/emtests/test_transtrcase.rs b/src/emtests/test_transtrcase.rs new file mode 100644 index 000000000..f9d169287 --- /dev/null +++ b/src/emtests/test_transtrcase.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_transtrcase() { + assert_emscripten_output!( + "../../emtests/test_transtrcase.wasm", + "test_transtrcase", + vec![], + "../../emtests/test_transtrcase.out" + ); +} diff --git a/src/emtests/test_trickystring.rs b/src/emtests/test_trickystring.rs new file mode 100644 index 000000000..cf5698528 --- /dev/null +++ b/src/emtests/test_trickystring.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_trickystring() { + assert_emscripten_output!( + "../../emtests/test_trickystring.wasm", + "test_trickystring", + vec![], + "../../emtests/test_trickystring.out" + ); +} diff --git a/src/emtests/test_uname.rs b/src/emtests/test_uname.rs new file mode 100644 index 000000000..ad1f339ee --- /dev/null +++ b/src/emtests/test_uname.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_uname() { + assert_emscripten_output!( + "../../emtests/test_uname.wasm", + "test_uname", + vec![], + "../../emtests/test_uname.out" + ); +} diff --git a/src/emtests/test_unary_literal.rs b/src/emtests/test_unary_literal.rs new file mode 100644 index 000000000..06f61b92c --- /dev/null +++ b/src/emtests/test_unary_literal.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_unary_literal() { + assert_emscripten_output!( + "../../emtests/test_unary_literal.wasm", + "test_unary_literal", + vec![], + "../../emtests/test_unary_literal.out" + ); +} diff --git a/src/emtests/test_utf.rs b/src/emtests/test_utf.rs new file mode 100644 index 000000000..f1dba3bca --- /dev/null +++ b/src/emtests/test_utf.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_utf() { + assert_emscripten_output!( + "../../emtests/test_utf.wasm", + "test_utf", + vec![], + "../../emtests/test_utf.out" + ); +} diff --git a/src/emtests/test_varargs.rs b/src/emtests/test_varargs.rs new file mode 100644 index 000000000..8fafe9687 --- /dev/null +++ b/src/emtests/test_varargs.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_varargs() { + assert_emscripten_output!( + "../../emtests/test_varargs.wasm", + "test_varargs", + vec![], + "../../emtests/test_varargs.out" + ); +} diff --git a/src/emtests/test_varargs_multi.rs b/src/emtests/test_varargs_multi.rs new file mode 100644 index 000000000..581b854fc --- /dev/null +++ b/src/emtests/test_varargs_multi.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_varargs_multi() { + assert_emscripten_output!( + "../../emtests/test_varargs_multi.wasm", + "test_varargs_multi", + vec![], + "../../emtests/test_varargs_multi.out" + ); +} diff --git a/src/emtests/test_vprintf.rs b/src/emtests/test_vprintf.rs new file mode 100644 index 000000000..1a5cdb142 --- /dev/null +++ b/src/emtests/test_vprintf.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_vprintf() { + assert_emscripten_output!( + "../../emtests/test_vprintf.wasm", + "test_vprintf", + vec![], + "../../emtests/test_vprintf.out" + ); +} diff --git a/src/emtests/test_vsnprintf.rs b/src/emtests/test_vsnprintf.rs new file mode 100644 index 000000000..c5cbbf091 --- /dev/null +++ b/src/emtests/test_vsnprintf.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_vsnprintf() { + assert_emscripten_output!( + "../../emtests/test_vsnprintf.wasm", + "test_vsnprintf", + vec![], + "../../emtests/test_vsnprintf.out" + ); +} diff --git a/src/emtests/test_wprintf.rs b/src/emtests/test_wprintf.rs new file mode 100644 index 000000000..3043df12d --- /dev/null +++ b/src/emtests/test_wprintf.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_wprintf() { + assert_emscripten_output!( + "../../emtests/test_wprintf.wasm", + "test_wprintf", + vec![], + "../../emtests/test_wprintf.out" + ); +} diff --git a/src/emtests/test_write_stdout_fileno.rs b/src/emtests/test_write_stdout_fileno.rs new file mode 100644 index 000000000..df3da00a5 --- /dev/null +++ b/src/emtests/test_write_stdout_fileno.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_write_stdout_fileno() { + assert_emscripten_output!( + "../../emtests/test_write_stdout_fileno.wasm", + "test_write_stdout_fileno", + vec![], + "../../emtests/test_write_stdout_fileno.out" + ); +} diff --git a/src/emtests/test_zero_multiplication.rs b/src/emtests/test_zero_multiplication.rs new file mode 100644 index 000000000..88d37d78d --- /dev/null +++ b/src/emtests/test_zero_multiplication.rs @@ -0,0 +1,10 @@ +#[test] +#[ignore] +fn test_test_zero_multiplication() { + assert_emscripten_output!( + "../../emtests/test_zero_multiplication.wasm", + "test_zero_multiplication", + vec![], + "../../emtests/test_zero_multiplication.out" + ); +} diff --git a/src/emtests/test_zerodiv.rs b/src/emtests/test_zerodiv.rs new file mode 100644 index 000000000..86712f6b5 --- /dev/null +++ b/src/emtests/test_zerodiv.rs @@ -0,0 +1,9 @@ +#[test] +fn test_test_zerodiv() { + assert_emscripten_output!( + "../../emtests/test_zerodiv.wasm", + "test_zerodiv", + vec![], + "../../emtests/test_zerodiv.out" + ); +}