mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 00:00:49 +00:00
Add Emscripten tests/core tests
This commit is contained in:
parent
8921385fbb
commit
81b952ebec
106
ATTRIBUTIONS.md
106
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/).
|
||||
|
||||
```
|
||||
|
29
emtests/FS_exports.cpp
Normal file
29
emtests/FS_exports.cpp
Normal file
@ -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<emscripten.h>
|
||||
|
||||
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"])))');
|
||||
});
|
||||
}
|
||||
|
1
emtests/FS_exports.txt
Normal file
1
emtests/FS_exports.txt
Normal file
@ -0,0 +1 @@
|
||||
Data: [1,2,3]
|
BIN
emtests/FS_exports.wasm
Normal file
BIN
emtests/FS_exports.wasm
Normal file
Binary file not shown.
1
emtests/FS_exports_2.txt
Normal file
1
emtests/FS_exports_2.txt
Normal file
@ -0,0 +1 @@
|
||||
Data: [1,2,3]
|
1
emtests/FS_exports_assert.txt
Normal file
1
emtests/FS_exports_assert.txt
Normal file
@ -0,0 +1 @@
|
||||
You can force-include filesystem support with -s FORCE_FILESYSTEM=1
|
1
emtests/FS_exports_assert_2.txt
Normal file
1
emtests/FS_exports_assert_2.txt
Normal file
@ -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
|
39
emtests/closebitcasts.c
Normal file
39
emtests/closebitcasts.c
Normal file
@ -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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
2
emtests/closebitcasts.txt
Normal file
2
emtests/closebitcasts.txt
Normal file
@ -0,0 +1,2 @@
|
||||
!1787576325
|
||||
589815810,-179981561!
|
BIN
emtests/closebitcasts.wasm
Normal file
BIN
emtests/closebitcasts.wasm
Normal file
Binary file not shown.
29
emtests/dyncall.c
Normal file
29
emtests/dyncall.c
Normal file
@ -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 <emscripten.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
1
emtests/dyncall.txt
Normal file
1
emtests/dyncall.txt
Normal file
@ -0,0 +1 @@
|
||||
received 1,4,9.
|
BIN
emtests/dyncall.wasm
Normal file
BIN
emtests/dyncall.wasm
Normal file
Binary file not shown.
33
emtests/dyncall_specific.c
Normal file
33
emtests/dyncall_specific.c
Normal file
@ -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 <emscripten.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
1
emtests/dyncall_specific.txt
Normal file
1
emtests/dyncall_specific.txt
Normal file
@ -0,0 +1 @@
|
||||
received 1,4,9.
|
BIN
emtests/dyncall_specific.wasm
Normal file
BIN
emtests/dyncall_specific.wasm
Normal file
Binary file not shown.
18
emtests/emscripten_get_compiler_setting.c
Normal file
18
emtests/emscripten_get_compiler_setting.c
Normal file
@ -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 <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
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"));
|
||||
}
|
||||
|
2
emtests/emscripten_get_compiler_setting.out
Normal file
2
emtests/emscripten_get_compiler_setting.out
Normal file
@ -0,0 +1,2 @@
|
||||
QS: 4
|
||||
EV: waka
|
BIN
emtests/emscripten_get_compiler_setting.wasm
Normal file
BIN
emtests/emscripten_get_compiler_setting.wasm
Normal file
Binary file not shown.
86
emtests/fnmatch.c
Normal file
86
emtests/fnmatch.c
Normal file
@ -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 <fnmatch.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
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<TestCase> 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<TestCase>::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;
|
||||
}
|
||||
}
|
||||
|
23
emtests/fnmatch.out
Normal file
23
emtests/fnmatch.out
Normal file
@ -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.
|
21
emtests/getValue_setValue.cpp
Normal file
21
emtests/getValue_setValue.cpp
Normal file
@ -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<emscripten.h>
|
||||
|
||||
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
|
||||
}
|
||||
|
1
emtests/getValue_setValue.txt
Normal file
1
emtests/getValue_setValue.txt
Normal file
@ -0,0 +1 @@
|
||||
|1234|
|
BIN
emtests/getValue_setValue.wasm
Normal file
BIN
emtests/getValue_setValue.wasm
Normal file
Binary file not shown.
1
emtests/getValue_setValue_assert.txt
Normal file
1
emtests/getValue_setValue_assert.txt
Normal file
@ -0,0 +1 @@
|
||||
'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)
|
72
emtests/ignores.txt
Normal file
72
emtests/ignores.txt
Normal file
@ -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
|
19
emtests/legacy_exported_runtime_numbers.cpp
Normal file
19
emtests/legacy_exported_runtime_numbers.cpp
Normal file
@ -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<emscripten.h>
|
||||
|
||||
int main() {
|
||||
#ifdef DIRECT
|
||||
EM_ASM({
|
||||
out('|' + ALLOC_DYNAMIC + '|');
|
||||
});
|
||||
#else
|
||||
EM_ASM({
|
||||
out('|' + Module['ALLOC_DYNAMIC'] + '|');
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
1
emtests/legacy_exported_runtime_numbers.txt
Normal file
1
emtests/legacy_exported_runtime_numbers.txt
Normal file
@ -0,0 +1 @@
|
||||
|3|
|
BIN
emtests/legacy_exported_runtime_numbers.wasm
Normal file
BIN
emtests/legacy_exported_runtime_numbers.wasm
Normal file
Binary file not shown.
1
emtests/legacy_exported_runtime_numbers_assert.txt
Normal file
1
emtests/legacy_exported_runtime_numbers_assert.txt
Normal file
@ -0,0 +1 @@
|
||||
'ALLOC_DYNAMIC' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)
|
15
emtests/modularize_closure_pre.c
Normal file
15
emtests/modularize_closure_pre.c
Normal file
@ -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 <emscripten.h>
|
||||
|
||||
int main() {
|
||||
EM_ASM({
|
||||
out(Module['on_module']);
|
||||
});
|
||||
}
|
||||
|
1
emtests/modularize_closure_pre.out
Normal file
1
emtests/modularize_closure_pre.out
Normal file
@ -0,0 +1 @@
|
||||
waka
|
BIN
emtests/modularize_closure_pre.wasm
Normal file
BIN
emtests/modularize_closure_pre.wasm
Normal file
Binary file not shown.
35
emtests/stackAlloc.cpp
Normal file
35
emtests/stackAlloc.cpp
Normal file
@ -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 <emscripten.h>
|
||||
|
||||
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.');
|
||||
});
|
||||
}
|
1
emtests/stackAlloc.txt
Normal file
1
emtests/stackAlloc.txt
Normal file
@ -0,0 +1 @@
|
||||
ok.
|
BIN
emtests/stackAlloc.wasm
Normal file
BIN
emtests/stackAlloc.wasm
Normal file
Binary file not shown.
39
emtests/stack_overflow.cpp
Normal file
39
emtests/stack_overflow.cpp
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
BIN
emtests/stack_overflow.wasm
Normal file
BIN
emtests/stack_overflow.wasm
Normal file
Binary file not shown.
15
emtests/test_addr_of_stacked.c
Normal file
15
emtests/test_addr_of_stacked.c
Normal file
@ -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>
|
||||
void alter(int *y) { *y += 5; }
|
||||
int main() {
|
||||
int x = 2;
|
||||
alter(&x);
|
||||
printf("*%d*\n", x);
|
||||
return 0;
|
||||
}
|
1
emtests/test_addr_of_stacked.out
Normal file
1
emtests/test_addr_of_stacked.out
Normal file
@ -0,0 +1 @@
|
||||
*7*
|
BIN
emtests/test_addr_of_stacked.wasm
Normal file
BIN
emtests/test_addr_of_stacked.wasm
Normal file
Binary file not shown.
21
emtests/test_alloca.c
Normal file
21
emtests/test_alloca.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
}
|
1
emtests/test_alloca.out
Normal file
1
emtests/test_alloca.out
Normal file
@ -0,0 +1 @@
|
||||
z:1*
|
BIN
emtests/test_alloca.wasm
Normal file
BIN
emtests/test_alloca.wasm
Normal file
Binary file not shown.
23
emtests/test_alloca_stack.c
Normal file
23
emtests/test_alloca_stack.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
1
emtests/test_alloca_stack.out
Normal file
1
emtests/test_alloca_stack.out
Normal file
@ -0,0 +1 @@
|
||||
ok:-32768*
|
BIN
emtests/test_alloca_stack.wasm
Normal file
BIN
emtests/test_alloca_stack.wasm
Normal file
Binary file not shown.
20
emtests/test_array2.c
Normal file
20
emtests/test_array2.c
Normal file
@ -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 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;
|
||||
}
|
1
emtests/test_array2.out
Normal file
1
emtests/test_array2.out
Normal file
@ -0,0 +1 @@
|
||||
0:-1.00,-0.33 1:0.33,-1.00 2:-0.33,1.00 3:1.00,0.33
|
BIN
emtests/test_array2.wasm
Normal file
BIN
emtests/test_array2.wasm
Normal file
Binary file not shown.
19
emtests/test_array2b.c
Normal file
19
emtests/test_array2b.c
Normal file
@ -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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
2
emtests/test_array2b.out
Normal file
2
emtests/test_array2b.out
Normal file
@ -0,0 +1,2 @@
|
||||
*6,6
|
||||
7,95*
|
BIN
emtests/test_array2b.wasm
Normal file
BIN
emtests/test_array2b.wasm
Normal file
Binary file not shown.
14
emtests/test_assert.c
Normal file
14
emtests/test_assert.c
Normal file
@ -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 <stdio.h>
|
||||
#include <assert.h>
|
||||
int main() {
|
||||
assert(1 == true); // pass
|
||||
assert(1 == false); // fail
|
||||
return 0;
|
||||
}
|
1
emtests/test_assert.out
Normal file
1
emtests/test_assert.out
Normal file
@ -0,0 +1 @@
|
||||
Assertion failed: 1 == false
|
26
emtests/test_atexit.c
Normal file
26
emtests/test_atexit.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
4
emtests/test_atexit.out
Normal file
4
emtests/test_atexit.out
Normal file
@ -0,0 +1,4 @@
|
||||
C 234
|
||||
C 100
|
||||
B
|
||||
A
|
47
emtests/test_atoX.c
Normal file
47
emtests/test_atoX.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
3
emtests/test_atoX.out
Normal file
3
emtests/test_atoX.out
Normal file
@ -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
|
BIN
emtests/test_atoX.wasm
Normal file
BIN
emtests/test_atoX.wasm
Normal file
Binary file not shown.
25
emtests/test_atomic.c
Normal file
25
emtests/test_atomic.c
Normal file
@ -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 <stdio.h>
|
||||
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;
|
||||
}
|
5
emtests/test_atomic.out
Normal file
5
emtests/test_atomic.out
Normal file
@ -0,0 +1,5 @@
|
||||
*15,15*
|
||||
*15,10*
|
||||
*6,10*
|
||||
*10,0*
|
||||
*7,1*
|
BIN
emtests/test_atomic.wasm
Normal file
BIN
emtests/test_atomic.wasm
Normal file
Binary file not shown.
135
emtests/test_atomic_cxx.cpp
Normal file
135
emtests/test_atomic_cxx.cpp
Normal file
@ -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 <atomic>
|
||||
#include <cstdio>
|
||||
|
||||
template<typename TYPE, typename UNSIGNED_TYPE> 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<int>
|
||||
std::atomic<dog> atomicDog(5);
|
||||
printf("atomic<int>.is_lock_free(): %s\n", atomicDog.is_lock_free() ? "true" : "false");
|
||||
printf("atomic<int> 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<<i), memoryOrder[i]);
|
||||
printf("fetch_and %lld: old=%llx, new=%llx\n", (long long)i, (unsigned long long)UNSIGNED_TYPE(old), (unsigned long long)UNSIGNED_TYPE(atomicDog));
|
||||
}
|
||||
|
||||
// fetch_or
|
||||
atomicDog = 0;
|
||||
for (TYPE i = 0; i < numMemoryOrders; i++) {
|
||||
TYPE old = atomicDog.fetch_or((1<<i), memoryOrder[i]);
|
||||
printf("fetch_or %lld: old=%llx, new=%llx\n", (long long)i, (unsigned long long)UNSIGNED_TYPE(old), (unsigned long long)UNSIGNED_TYPE(atomicDog));
|
||||
}
|
||||
|
||||
// fetch_xor
|
||||
atomicDog = 0;
|
||||
for (int i = 0; i < numMemoryOrders; i++) {
|
||||
int old = atomicDog.fetch_xor((1<<i), memoryOrder[i]);
|
||||
printf("fetch_xor %lld: old=%llx, new=%llx\n", (long long)i, (unsigned long long)UNSIGNED_TYPE(old), (unsigned long long)UNSIGNED_TYPE(atomicDog));
|
||||
}
|
||||
|
||||
// operator++, --
|
||||
atomicDog = 0;
|
||||
atomicDog++;
|
||||
printf("operator++: %lld\n", (long long)TYPE(atomicDog));
|
||||
atomicDog--;
|
||||
printf("operator--: %lld\n", (long long)TYPE(atomicDog));
|
||||
|
||||
// operator +=, -=, &=, |=, ^=
|
||||
atomicDog += 10;
|
||||
printf("operator+=: %lld\n", (long long)TYPE(atomicDog));
|
||||
atomicDog -= 5;
|
||||
printf("operator-=: %lld\n", (long long)TYPE(atomicDog));
|
||||
atomicDog |= mask0;
|
||||
printf("operator|=: %llx\n", (unsigned long long)UNSIGNED_TYPE(atomicDog));
|
||||
atomicDog &= mask1;
|
||||
printf("operator&=: %llx\n", (unsigned long long)UNSIGNED_TYPE(atomicDog));
|
||||
atomicDog ^= mask2;
|
||||
printf("operator^=: %llx\n", (unsigned long long)UNSIGNED_TYPE(atomicDog));
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
// test 8, 16, 32 and 64-bit data types
|
||||
printf("\n8 bits\n\n");
|
||||
test<char, unsigned char>(0xFF, 0xF0, 0x0F);
|
||||
printf("\n16 bits\n\n");
|
||||
test<short, unsigned short>(0xFFFF, 0xF0F0, 0x0F0F);
|
||||
printf("\n32 bits\n\n");
|
||||
test<int, unsigned int>(0xFFFFFFFF, 0xF0F0F0F0, 0x0F0F0F0F);
|
||||
printf("\n64 bits\n\n");
|
||||
test<long long, unsigned long long>(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;
|
||||
}
|
||||
|
226
emtests/test_atomic_cxx.txt
Normal file
226
emtests/test_atomic_cxx.txt
Normal file
@ -0,0 +1,226 @@
|
||||
|
||||
8 bits
|
||||
|
||||
atomic<int>.is_lock_free(): true
|
||||
atomic<int> 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<int>.is_lock_free(): true
|
||||
atomic<int> 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<int>.is_lock_free(): true
|
||||
atomic<int> 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<int>.is_lock_free(): false
|
||||
atomic<int> 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.
|
BIN
emtests/test_atomic_cxx.wasm
Normal file
BIN
emtests/test_atomic_cxx.wasm
Normal file
Binary file not shown.
29
emtests/test_bigarray.c
Normal file
29
emtests/test_bigarray.c
Normal file
@ -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 <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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;
|
||||
}
|
1
emtests/test_bigarray.out
Normal file
1
emtests/test_bigarray.out
Normal file
@ -0,0 +1 @@
|
||||
*57*
|
27
emtests/test_bitfields.c
Normal file
27
emtests/test_bitfields.c
Normal file
@ -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 <stdio.h>
|
||||
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;
|
||||
}
|
1
emtests/test_bitfields.out
Normal file
1
emtests/test_bitfields.out
Normal file
@ -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,*
|
52
emtests/test_bsearch.c
Normal file
52
emtests/test_bsearch.c
Normal file
@ -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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
10
emtests/test_bsearch.out
Normal file
10
emtests/test_bsearch.out
Normal file
@ -0,0 +1,10 @@
|
||||
-2
|
||||
-1
|
||||
0
|
||||
6
|
||||
7
|
||||
9
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
BIN
emtests/test_bsearch.wasm
Normal file
BIN
emtests/test_bsearch.wasm
Normal file
Binary file not shown.
55
emtests/test_bswap64.c
Normal file
55
emtests/test_bswap64.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
7
emtests/test_bswap64.out
Normal file
7
emtests/test_bswap64.out
Normal file
@ -0,0 +1,7 @@
|
||||
4914553019779824384
|
||||
1
|
||||
2
|
||||
bbccddeeff3344
|
||||
4433ffeeddccbb00
|
||||
4433ffeeddccbb00
|
||||
Succeeded!
|
54
emtests/test_ccall.cpp
Normal file
54
emtests/test_ccall.cpp
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
30
emtests/test_ccall.out
Normal file
30
emtests/test_ccall.out
Normal file
@ -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.
|
BIN
emtests/test_ccall.wasm
Normal file
BIN
emtests/test_ccall.wasm
Normal file
Binary file not shown.
35
emtests/test_class.c
Normal file
35
emtests/test_class.c
Normal file
@ -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 <stdio.h>
|
||||
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;
|
||||
}
|
1
emtests/test_class.out
Normal file
1
emtests/test_class.out
Normal file
@ -0,0 +1 @@
|
||||
*0*
|
32
emtests/test_complex.c
Normal file
32
emtests/test_complex.c
Normal file
@ -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 <complex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
8
emtests/test_complex.out
Normal file
8
emtests/test_complex.out
Normal file
@ -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
|
BIN
emtests/test_complex.wasm
Normal file
BIN
emtests/test_complex.wasm
Normal file
Binary file not shown.
28
emtests/test_constglobalstructs.c
Normal file
28
emtests/test_constglobalstructs.c
Normal file
@ -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 <stdio.h>
|
||||
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;
|
||||
}
|
1
emtests/test_constglobalstructs.out
Normal file
1
emtests/test_constglobalstructs.out
Normal file
@ -0,0 +1 @@
|
||||
*97,15,3,10*
|
25
emtests/test_conststructs.c
Normal file
25
emtests/test_conststructs.c
Normal file
@ -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 <stdio.h>
|
||||
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;
|
||||
}
|
1
emtests/test_conststructs.out
Normal file
1
emtests/test_conststructs.out
Normal file
@ -0,0 +1 @@
|
||||
*70,97,15,3,3029,90*
|
41
emtests/test_copyop.c
Normal file
41
emtests/test_copyop.c
Normal file
@ -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 <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
4
emtests/test_copyop.out
Normal file
4
emtests/test_copyop.out
Normal file
@ -0,0 +1,4 @@
|
||||
*0.00,0.00,0.00*
|
||||
*0,77,0*
|
||||
*0,77,0*
|
||||
*0,77,0*
|
17
emtests/test_cxx03_do_run.c
Normal file
17
emtests/test_cxx03_do_run.c
Normal file
@ -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>
|
||||
|
||||
#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;
|
||||
}
|
1
emtests/test_cxx03_do_run.out
Normal file
1
emtests/test_cxx03_do_run.out
Normal file
@ -0,0 +1 @@
|
||||
Hello world!
|
31
emtests/test_demangle_stacks.cpp
Normal file
31
emtests/test_demangle_stacks.cpp
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
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;
|
||||
}
|
1
emtests/test_demangle_stacks.out
Normal file
1
emtests/test_demangle_stacks.out
Normal file
@ -0,0 +1 @@
|
||||
NameSpace::Class::Aborter(double, char, int*)
|
BIN
emtests/test_demangle_stacks.wasm
Normal file
BIN
emtests/test_demangle_stacks.wasm
Normal file
Binary file not shown.
26
emtests/test_demangle_stacks_noassert.cpp
Normal file
26
emtests/test_demangle_stacks_noassert.cpp
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
1
emtests/test_demangle_stacks_noassert.out
Normal file
1
emtests/test_demangle_stacks_noassert.out
Normal file
@ -0,0 +1 @@
|
||||
Build with -s ASSERTIONS=1 for more info.
|
BIN
emtests/test_demangle_stacks_noassert.wasm
Normal file
BIN
emtests/test_demangle_stacks_noassert.wasm
Normal file
Binary file not shown.
16
emtests/test_direct_string_constant_usage.c
Normal file
16
emtests/test_direct_string_constant_usage.c
Normal file
@ -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 <iostream>
|
||||
template <int i>
|
||||
void printText(const char (&text)[i]) {
|
||||
std::cout << text;
|
||||
}
|
||||
int main() {
|
||||
printText("some string constant");
|
||||
return 0;
|
||||
}
|
1
emtests/test_direct_string_constant_usage.out
Normal file
1
emtests/test_direct_string_constant_usage.out
Normal file
@ -0,0 +1 @@
|
||||
some string constant
|
30
emtests/test_dlfcn_self.c
Normal file
30
emtests/test_dlfcn_self.c
Normal file
@ -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 <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
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;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user