mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 00:00:49 +00:00
Merge branch 'master' into feature/vm_refactor
This commit is contained in:
commit
696bc9a0a9
@ -95,6 +95,9 @@ jobs:
|
||||
command: |
|
||||
export PATH="`pwd`/cmake-3.4.1-Darwin-x86_64/CMake.app/Contents/bin:$PATH"
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
# We increase the ulimit for fixing cargo unclosed files in mac
|
||||
ulimit -n 8000
|
||||
sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680
|
||||
make test
|
||||
make lint
|
||||
- run:
|
||||
|
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/).
|
||||
|
||||
```
|
||||
|
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -983,6 +983,16 @@ dependencies = [
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ucd-util"
|
||||
version = "0.1.1"
|
||||
@ -1061,6 +1071,7 @@ dependencies = [
|
||||
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (git+https://github.com/rust-lang/libc)",
|
||||
@ -1074,6 +1085,7 @@ dependencies = [
|
||||
"structopt 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1244,6 +1256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
|
||||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c"
|
||||
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
|
||||
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
|
@ -52,9 +52,11 @@ console = "0.7.1"
|
||||
field-offset = "0.1.1"
|
||||
hashbrown = "0.1"
|
||||
libffi = "0.6.4"
|
||||
time = "0.1.41"
|
||||
|
||||
[build-dependencies]
|
||||
wabt = "0.7.2"
|
||||
glob = "0.2.11"
|
||||
# [dev-dependencies]
|
||||
# libffi = "0.6.4"
|
||||
# maplit = "1.0.1"
|
||||
|
129
build/emtests.rs
129
build/emtests.rs
@ -4,36 +4,43 @@
|
||||
//! - Compile using emcc and get the .wasm from it (wasm)
|
||||
//! - Generate the test that will compare the output of running the .wasm file
|
||||
//! with wasmer with the expected output
|
||||
use glob::glob;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::io::BufReader;
|
||||
|
||||
static BANNER: &str = "// Rust test file autogenerated with cargo build (build/emtests.rs).
|
||||
// Please do NOT modify it by hand, as it will be reseted on next build.\n";
|
||||
|
||||
const TESTS: [&str; 3] = ["emtests/env.c", "emtests/puts.c", "emtests/printf.c"];
|
||||
const EXTENSIONS: [&str; 2] = ["c", "cpp"];
|
||||
const EXCLUDES: [&str; 0] = [];
|
||||
|
||||
pub fn compile(file: &str) -> String {
|
||||
pub fn compile(file: &str, ignores: &Vec<String>) -> Option<String> {
|
||||
let mut output_path = PathBuf::from(file);
|
||||
output_path.set_extension("out");
|
||||
let output_str = output_path.to_str().unwrap();
|
||||
// let output_str = output_path.to_str().unwrap();
|
||||
|
||||
// Compile to .out
|
||||
Command::new("cc")
|
||||
.arg(file)
|
||||
.arg("-o")
|
||||
.arg(output_str)
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
// Command::new("cc")
|
||||
// .arg(file)
|
||||
// .arg("-o")
|
||||
// .arg(output_str)
|
||||
// .output()
|
||||
// .expect("failed to execute process");
|
||||
|
||||
// Get the result of .out
|
||||
let output = Command::new(output_str)
|
||||
.arg(output_str)
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
// let output = Command::new(output_str)
|
||||
// .arg(output_str)
|
||||
// .output()
|
||||
// .expect("failed to execute process");
|
||||
|
||||
// Remove executable
|
||||
fs::remove_file(output_str).unwrap();
|
||||
// fs::remove_file(output_str).unwrap();
|
||||
|
||||
let mut output_path = PathBuf::from(file);
|
||||
output_path.set_extension("js");
|
||||
@ -54,7 +61,12 @@ pub fn compile(file: &str) -> String {
|
||||
// panic!("{}", output.stderr);
|
||||
// }
|
||||
// Remove js file
|
||||
fs::remove_file(output_str).unwrap();
|
||||
|
||||
if Path::new(output_str).is_file() {
|
||||
fs::remove_file(output_str).unwrap();
|
||||
} else {
|
||||
println!("Output JS not found: {}", output_str);
|
||||
}
|
||||
|
||||
let mut output_path = PathBuf::from(file);
|
||||
output_path.set_extension("output");
|
||||
@ -65,26 +77,63 @@ pub fn compile(file: &str) -> String {
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
|
||||
let output_str = output_path.to_str().unwrap();
|
||||
//
|
||||
// let output_str = output_path.to_str().unwrap();
|
||||
|
||||
// Write the output to file
|
||||
fs::write(output_str, output.stdout).expect("Unable to write file");
|
||||
// fs::write(output_str, output.stdout).expect("Unable to write file");
|
||||
|
||||
let rs_module_name = module_name.to_lowercase();
|
||||
let rust_test_filepath = format!(
|
||||
concat!(env!("CARGO_MANIFEST_DIR"), "/src/emtests/{}.rs"),
|
||||
module_name.as_str()
|
||||
rs_module_name.as_str()
|
||||
);
|
||||
|
||||
let contents = format!("#[test]
|
||||
fn test_{module_name}() {{
|
||||
assert_emscripten_output!(\"../../emtests/{module_name}.wasm\", \"{module_name}\", vec![], \"../../emtests/{module_name}.output\");
|
||||
let output_extension = if file.ends_with("c") || module_name.starts_with("test_") {
|
||||
"out"
|
||||
} else {
|
||||
"txt"
|
||||
};
|
||||
|
||||
let ignored = if ignores
|
||||
.iter()
|
||||
.any(|i| &i.to_lowercase() == &module_name.to_lowercase())
|
||||
{
|
||||
"\n#[ignore]"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let module_path = format!("emtests/{}.wasm", module_name);
|
||||
let test_output_path = format!("emtests/{}.{}", module_name, output_extension);
|
||||
if !Path::new(&module_path).is_file() {
|
||||
println!("Path not found to test module: {}", module_path);
|
||||
None
|
||||
} else if !Path::new(&test_output_path).is_file() {
|
||||
println!("Path not found to test output: {}", module_path);
|
||||
None
|
||||
} else {
|
||||
let contents = format!(
|
||||
"#[test]{ignore}
|
||||
fn test_{rs_module_name}() {{
|
||||
assert_emscripten_output!(
|
||||
\"../../{module_path}\",
|
||||
\"{rs_module_name}\",
|
||||
vec![],
|
||||
\"../../{test_output_path}\"
|
||||
);
|
||||
}}
|
||||
", module_name=module_name);
|
||||
",
|
||||
ignore = ignored,
|
||||
module_path = module_path,
|
||||
rs_module_name = rs_module_name,
|
||||
test_output_path = test_output_path
|
||||
);
|
||||
|
||||
fs::write(&rust_test_filepath, contents.as_bytes()).unwrap();
|
||||
|
||||
module_name
|
||||
fs::write(&rust_test_filepath, contents.as_bytes()).unwrap();
|
||||
|
||||
Some(rs_module_name)
|
||||
}
|
||||
// panic!("OUTPUT: {:?}", output);
|
||||
}
|
||||
|
||||
@ -93,10 +142,28 @@ pub fn build() {
|
||||
|
||||
let mut modules: Vec<String> = Vec::new();
|
||||
// modules.reserve_exact(TESTS.len());
|
||||
for test in TESTS.iter() {
|
||||
let moudle_name = compile(test);
|
||||
modules.push(format!("mod {};", moudle_name));
|
||||
|
||||
let ignores = read_ignore_list();
|
||||
|
||||
for ext in EXTENSIONS.iter() {
|
||||
for entry in glob(&format!("emtests/*.{}", ext)).unwrap() {
|
||||
match entry {
|
||||
Ok(path) => {
|
||||
let test = path.to_str().unwrap();
|
||||
if !EXCLUDES.iter().any(|e| test.ends_with(e)) {
|
||||
if let Some(module_name) = compile(test, &ignores) {
|
||||
modules.push(module_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => println!("{:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
modules.sort();
|
||||
let mut modules: Vec<String> = modules.iter().map(|m| format!("mod {};", m)).collect();
|
||||
assert!(modules.len() > 0, "Expected > 0 modules found");
|
||||
|
||||
modules.insert(0, BANNER.to_string());
|
||||
modules.insert(1, "// The _common module is not autogenerated, as it provides common macros for the emtests\n#[macro_use]\nmod _common;".to_string());
|
||||
// We add an empty line
|
||||
@ -109,3 +176,9 @@ pub fn build() {
|
||||
fs::write(&rust_test_modpath, modfile.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn read_ignore_list() -> Vec<String> {
|
||||
let f = File::open("emtests/ignores.txt").unwrap();
|
||||
let f = BufReader::new(f);
|
||||
f.lines().filter_map(Result::ok).collect()
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
extern crate glob;
|
||||
extern crate wabt;
|
||||
|
||||
use std::env;
|
||||
|
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
|
@ -1,21 +1,24 @@
|
||||
This directory contains tests for unit testing each of the functions/syscalls that Emscripten will be doing.
|
||||
|
||||
If you want to generate the wasm files, you will just need to:
|
||||
If you want to generate the wasm files, you will just need:
|
||||
|
||||
Have EMCC (version 1.38.21) installed
|
||||
|
||||
Then run:
|
||||
|
||||
```
|
||||
make emtests
|
||||
```
|
||||
|
||||
**Ignored Tests**
|
||||
Test names included in `emtests/ignores.txt` will be annotated with `#[ignore]` during test generation.
|
||||
|
||||
This process will do something similar to:
|
||||
|
||||
```
|
||||
cc localtime.c -o localtime.out
|
||||
# Execute the out file and save its output
|
||||
./localtime.out > ./localtime.output
|
||||
rm localtime.out
|
||||
|
||||
# Generate the .wasm file
|
||||
emcc localtime.c -o localtime.js
|
||||
# Delte the js file, as we don't need it
|
||||
rm localtime.js
|
||||
```
|
||||
|
||||
|
10
emtests/clock_gettime.c
Normal file
10
emtests/clock_gettime.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
// a simple program that simply calls clock_gettime
|
||||
// not easy to unit test because of non-determinism and so compilation is enough for now
|
||||
int main () {
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_REALTIME, &tp);
|
||||
printf("clock_gettime\n");
|
||||
}
|
1
emtests/clock_gettime.out
Normal file
1
emtests/clock_gettime.out
Normal file
@ -0,0 +1 @@
|
||||
clock_gettime
|
BIN
emtests/clock_gettime.wasm
Normal file
BIN
emtests/clock_gettime.wasm
Normal file
Binary file not shown.
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.
BIN
emtests/env.wasm
BIN
emtests/env.wasm
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)
|
@ -2,19 +2,14 @@
|
||||
#include <time.h>
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
printf("Hello wasmer!\n");
|
||||
time_t rawtime;
|
||||
struct tm *info;
|
||||
char buffer[80];
|
||||
|
||||
time( &rawtime );
|
||||
|
||||
info = localtime( &rawtime );
|
||||
|
||||
printf("Almost!\n");
|
||||
printf("Current local time and date: %s\n", asctime(info));
|
||||
printf("Done!\n");
|
||||
|
||||
struct tm info2;
|
||||
time (&rawtime );
|
||||
struct tm *p = localtime_r(&rawtime, &info2);
|
||||
printf("localtime\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
1
emtests/localtime.output
Normal file
1
emtests/localtime.output
Normal file
@ -0,0 +1 @@
|
||||
localtime
|
Binary file not shown.
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.
Binary file not shown.
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
|
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