aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cases/atomicrmw_unaligned.emcc1
-rw-r--r--tests/cases/atomicrmw_unaligned.ll21
-rw-r--r--tests/cases/atomicrmw_unaligned.txt1
-rw-r--r--tests/cmake/target_js/CMakeLists.txt26
-rw-r--r--tests/cmake/target_js/jslibrary.js7
-rw-r--r--tests/cmake/target_js/jslibrary2.js7
-rw-r--r--tests/cmake/target_js/main.cpp10
-rw-r--r--tests/cmake/target_js/out.txt4
-rw-r--r--tests/cmake/target_js/postjs.js1
-rw-r--r--tests/cmake/target_js/prejs.js1
-rw-r--r--tests/printf/output.txt11
-rw-r--r--tests/printf/output_i64_1.txt11
-rw-r--r--tests/printf/test.c11
-rw-r--r--tests/test_browser.py4
-rw-r--r--tests/test_core.py80
-rw-r--r--tests/test_other.py10
-rw-r--r--tests/unistd/io.c6
-rw-r--r--tests/unistd/io.out4
18 files changed, 194 insertions, 22 deletions
diff --git a/tests/cases/atomicrmw_unaligned.emcc b/tests/cases/atomicrmw_unaligned.emcc
new file mode 100644
index 00000000..9faeda24
--- /dev/null
+++ b/tests/cases/atomicrmw_unaligned.emcc
@@ -0,0 +1 @@
+["-s", "UNALIGNED_MEMORY=1"]
diff --git a/tests/cases/atomicrmw_unaligned.ll b/tests/cases/atomicrmw_unaligned.ll
new file mode 100644
index 00000000..fe479dce
--- /dev/null
+++ b/tests/cases/atomicrmw_unaligned.ll
@@ -0,0 +1,21 @@
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private unnamed_addr constant [15 x i8] c"hello, %d,%d!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %t = alloca i32, align 4 ; [#uses=2 type=i32**]
+ store i32 50, i32* %t, align 4
+ %0 = load i32* %t
+ %1 = atomicrmw add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12]
+ %2 = load i32* %t
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %0, i32 %2) ; [#uses=0 type=i32]
+ %3 = atomicrmw volatile add i32* %t, i32 3 seq_cst, ; [#uses=0 type=i32] [debug line = 21:12]
+ ret i32 1
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
diff --git a/tests/cases/atomicrmw_unaligned.txt b/tests/cases/atomicrmw_unaligned.txt
new file mode 100644
index 00000000..45d16fb1
--- /dev/null
+++ b/tests/cases/atomicrmw_unaligned.txt
@@ -0,0 +1 @@
+hello, 50,53!
diff --git a/tests/cmake/target_js/CMakeLists.txt b/tests/cmake/target_js/CMakeLists.txt
index cee5fc42..244cc70a 100644
--- a/tests/cmake/target_js/CMakeLists.txt
+++ b/tests/cmake/target_js/CMakeLists.txt
@@ -1,11 +1,15 @@
cmake_minimum_required(VERSION 2.8)
-project(hello_world)
+project(test_cmake)
-file(GLOB sourceFiles ../../hello_world.cpp)
+file(GLOB sourceFiles main.cpp)
+
+file(GLOB preJsFiles pre*.js)
+file(GLOB postJsFiles post*.js)
+file(GLOB libraryJsFiles jslibrary*.js)
if (CMAKE_BUILD_TYPE STREQUAL Debug)
- SET(linkFlags "")
+ SET(linkFlags "-g4")
else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimizations enabled.
SET(linkFlags "-O2")
endif()
@@ -28,5 +32,17 @@ if (NOT CMAKE_C_SIZEOF_DATA_PTR)
message(FATAL_ERROR "CMAKE_C_SIZEOF_DATA_PTR was not defined!")
endif()
-add_executable(hello_world ${sourceFiles})
-set_target_properties(hello_world PROPERTIES LINK_FLAGS "${linkFlags}")
+add_executable(test_cmake ${sourceFiles})
+
+# GOTCHA: If your project has custom link flags, these must be set *before* calling any of the em_link_xxx functions!
+set_target_properties(test_cmake PROPERTIES LINK_FLAGS "${linkFlags}")
+
+message(STATUS "js libs '${libraryJsFiles}'")
+# To link .js files using the --js-library flag, use the following helper function.
+em_link_js_library(test_cmake ${libraryJsFiles})
+
+# To link .js files using the --pre-js flag, use the following helper function.
+em_link_pre_js(test_cmake ${preJsFiles})
+
+# To link .js files using the --post-js flag, use the following helper function.
+em_link_post_js(test_cmake ${postJsFiles})
diff --git a/tests/cmake/target_js/jslibrary.js b/tests/cmake/target_js/jslibrary.js
new file mode 100644
index 00000000..63375d8f
--- /dev/null
+++ b/tests/cmake/target_js/jslibrary.js
@@ -0,0 +1,7 @@
+var mylib = {};
+
+mylib.lib_function = function() {
+ console.log('lib_function');
+}
+
+mergeInto(LibraryManager.library, mylib);
diff --git a/tests/cmake/target_js/jslibrary2.js b/tests/cmake/target_js/jslibrary2.js
new file mode 100644
index 00000000..5d322e2d
--- /dev/null
+++ b/tests/cmake/target_js/jslibrary2.js
@@ -0,0 +1,7 @@
+var mylib = {};
+
+mylib.lib_function2 = function() {
+ console.log('lib_function2');
+}
+
+mergeInto(LibraryManager.library, mylib);
diff --git a/tests/cmake/target_js/main.cpp b/tests/cmake/target_js/main.cpp
new file mode 100644
index 00000000..4b61dbf7
--- /dev/null
+++ b/tests/cmake/target_js/main.cpp
@@ -0,0 +1,10 @@
+extern "C" {
+ void lib_function();
+ void lib_function2();
+}
+
+int main()
+{
+ lib_function();
+ lib_function2();
+}
diff --git a/tests/cmake/target_js/out.txt b/tests/cmake/target_js/out.txt
new file mode 100644
index 00000000..76135df7
--- /dev/null
+++ b/tests/cmake/target_js/out.txt
@@ -0,0 +1,4 @@
+prejs executed
+lib_function
+lib_function2
+postjs executed \ No newline at end of file
diff --git a/tests/cmake/target_js/postjs.js b/tests/cmake/target_js/postjs.js
new file mode 100644
index 00000000..5a1b44ce
--- /dev/null
+++ b/tests/cmake/target_js/postjs.js
@@ -0,0 +1 @@
+console.log('postjs executed');
diff --git a/tests/cmake/target_js/prejs.js b/tests/cmake/target_js/prejs.js
new file mode 100644
index 00000000..87beb770
--- /dev/null
+++ b/tests/cmake/target_js/prejs.js
@@ -0,0 +1 @@
+console.log('prejs executed');
diff --git a/tests/printf/output.txt b/tests/printf/output.txt
index 19a6c1c2..0155f0da 100644
--- a/tests/printf/output.txt
+++ b/tests/printf/output.txt
@@ -3,10 +3,15 @@ n=7
Characters: a A
Decimals: 1977 650000 12 4
-Preceding with blanks: 1977
-Preceding with zeros: 0000001977
+Preceding with blanks: 1977 -1977
+Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
+Force sign or space: 1977 -1977 1977 -1977
+Sign overrides space: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
-floats: 3.14 +3e+00 3.141600E+00
+floats: 3.14 +3e+00 3.141600E+00 00003.14
+negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
+Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
diff --git a/tests/printf/output_i64_1.txt b/tests/printf/output_i64_1.txt
index 775f3f8d..e38fb78f 100644
--- a/tests/printf/output_i64_1.txt
+++ b/tests/printf/output_i64_1.txt
@@ -3,10 +3,15 @@ n=7
Characters: a A
Decimals: 1977 650000 12 4
-Preceding with blanks: 1977
-Preceding with zeros: 0000001977
+Preceding with blanks: 1977 -1977
+Preceding with zeros: 0000001977 -000001977
+Force sign: +1977 -1977 +1977 -1977
+Force sign or space: 1977 -1977 1977 -1977
+Sign overrides space: +1977 -1977 +1977 -1977
Some different radixes: 100 64 144 0x64 0144
-floats: 3.14 +3e+00 3.141600E+00
+floats: 3.14 +3e+00 3.141600E+00 00003.14
+negative floats: -3.14 -3e+00 -3.141600E+00 -0003.14
+Force sign or space: 3.14 -3.14 3.14 -3.14
Width trick: 10
A string %
Null string: (null)
diff --git a/tests/printf/test.c b/tests/printf/test.c
index d05ba096..1c8ad9f7 100644
--- a/tests/printf/test.c
+++ b/tests/printf/test.c
@@ -8,10 +8,15 @@ int main() {
printf("\n");
printf("Characters: %c %c\n", 'a', 65);
printf("Decimals: %d %ld %lld %d\n", 1977, 650000L, 12LL, 4);
- printf("Preceding with blanks: %10d\n", 1977);
- printf("Preceding with zeros: %010d\n", 1977);
+ printf("Preceding with blanks: %10d %10d\n", 1977, -1977);
+ printf("Preceding with zeros: %010d %010d\n", 1977, -1977);
+ printf("Force sign: %+d %+d %+6d %+6d\n", 1977, -1977, 1977, -1977);
+ printf("Force sign or space: % d % d % 6d % 6d\n", 1977, -1977, 1977, -1977);
+ printf("Sign overrides space: % +d % +d % +6d % +6d\n", 1977, -1977, 1977, -1977);
printf("Some different radixes: %d %x %o %#x %#o\n", 100, 100, 100, 100, 100);
- printf("floats: %4.2f %+.0e %E\n", 3.1416, 3.1416, 3.1416);
+ printf("floats: %4.2f %+.0e %E %08.2f\n", 3.1416, 3.1416, 3.1416, 3.1416);
+ printf("negative floats: %4.2f %+.0e %E %08.2f\n", -3.1416, -3.1416, -3.1416, -3.1416);
+ printf("Force sign or space: % .2f % .2f % 6.2f % 6.2f\n", 3.1416, -3.1416, 3.1416, -3.1416);
printf("Width trick: %*d\n", 5, 10);
printf("%s %%\n", "A string");
printf("Null string: %7s\n", NULL);
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 6a23b41c..a3b9a1c3 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -1477,7 +1477,9 @@ keydown(100);keyup(100); // trigger the end
}, 2000);
};
''')
- self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js'])
+
+ for mem in [0, 1]:
+ self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js', '--memory-init-file', str(mem)])
def test_worker_api(self):
Popen([PYTHON, EMCC, path_from_root('tests', 'worker_api_worker.cpp'), '-o', 'worker.js', '-s', 'BUILD_AS_WORKER=1', '-s', 'EXPORTED_FUNCTIONS=["_one"]']).communicate()
diff --git a/tests/test_core.py b/tests/test_core.py
index dd3b7c44..ea2fe49e 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1372,6 +1372,33 @@ Succeeded!
'''
self.do_run(src, '*1,10,10.5,1,1.2340,0.00*\n0.50, 3.30, 3.30, 3.30\nsmall: 0.0000010000\n')
+ def test_zerodiv(self):
+ self.do_run(r'''
+ #include <stdio.h>
+ int main(int argc, const char* argv[])
+ {
+ float f1 = 1.0f;
+ float f2 = 0.0f;
+ float f_zero = 0.0f;
+
+ float f3 = 0.0f / f2;
+ float f4 = f2 / 0.0f;
+ float f5 = f2 / f2;
+ float f6 = f2 / f_zero;
+
+ printf("f3: %f\n", f3);
+ printf("f4: %f\n", f4);
+ printf("f5: %f\n", f5);
+ printf("f6: %f\n", f6);
+
+ return 0;
+ }
+ ''', '''f3: nan
+f4: nan
+f5: nan
+f6: nan
+''')
+
def test_isnan(self):
src = r'''
#include <stdio.h>
@@ -5046,7 +5073,7 @@ The current type of b is: 9
src = r'''
int main () {
*(volatile char *)0 = 0;
- return 0;
+ return *(volatile char *)0;
}
'''
self.do_run(src, 'fault on write to 0' if not Settings.ASM_JS else 'abort()')
@@ -6908,6 +6935,29 @@ at function.:blag
printf("%i\n", a);
}
+ char buf1[100], buf2[100], buf3[100], buf4[100];
+
+ int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4);
+ printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4);
+
+ numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2);
+ printf("%d, %s\n", numItems, buf1);
+
+ numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1);
+ printf("%d, %s\n", numItems, buf1);
+
+ numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
return 0;
}
'''
@@ -6915,7 +6965,14 @@ at function.:blag
'1\n1499\n' +
'5\n87,0.481565,0.059481,0,1\n' +
'3\n-123,4294966531,-34\n' +
- '1\n')
+ '1\n' +
+ '4, level, 4, ref, 3\n' +
+ '2, def, 456\n' +
+ '2, 3-4, -ab\n' +
+ '2, Hello, World\n' +
+ '1, Hello\n' +
+ '1, Java\n' +
+ '2, [, ]')
def test_sscanf_2(self):
# doubles
@@ -7171,6 +7228,18 @@ date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3
'''
self.do_run(src, '10 1.1 1.1 1.1');
+ def test_sscanf_hex(self):
+ src = r'''
+ #include "stdio.h"
+
+ int main(){
+ unsigned int a, b;
+ sscanf("0x12AB 12AB", "%x %x", &a, &b);
+ printf("%d %d\n", a, b);
+ }
+ '''
+ self.do_run(src, '4779 4779')
+
def test_langinfo(self):
src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read()
expected = open(path_from_root('tests', 'langinfo', 'output.txt'), 'r').read()
@@ -8895,6 +8964,8 @@ def process(filename):
def test_cases(self):
if Building.LLVM_OPTS: return self.skip("Our code is not exactly 'normal' llvm assembly")
+ emcc_args = self.emcc_args
+
try:
os.environ['EMCC_LEAVE_INPUTS_RAW'] = '1'
Settings.CHECK_OVERFLOWS = 0
@@ -8908,6 +8979,10 @@ def process(filename):
if '_noasm' in shortname and Settings.ASM_JS:
print self.skip('case "%s" not relevant for asm.js' % shortname)
continue
+ self.emcc_args = emcc_args
+ if os.path.exists(shortname + '.emcc'):
+ if not self.emcc_args: continue
+ self.emcc_args = self.emcc_args + json.loads(open(shortname + '.emcc').read())
print >> sys.stderr, "Testing case '%s'..." % shortname
output_file = path_from_root('tests', 'cases', shortname + '.txt')
if Settings.QUANTUM_SIZE == 1:
@@ -8928,6 +9003,7 @@ def process(filename):
finally:
del os.environ['EMCC_LEAVE_INPUTS_RAW']
+ self.emcc_args = emcc_args
def test_fuzz(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
diff --git a/tests/test_other.py b/tests/test_other.py
index b11f22e5..9f331439 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -295,7 +295,7 @@ f.close()
make = make_commands[generator]
cmake_cases = ['target_js', 'target_html']
- cmake_outputs = ['hello_world.js', 'hello_world_gles.html']
+ cmake_outputs = ['test_cmake.js', 'hello_world_gles.html']
for i in range(0, 2):
for configuration in ['Debug', 'Release']:
# CMake can be invoked in two ways, using 'emconfigure cmake', or by directly running 'cmake'.
@@ -342,7 +342,7 @@ f.close()
# Run through node, if CMake produced a .js file.
if cmake_outputs[i].endswith('.js'):
ret = Popen(listify(NODE_JS) + [tempdirname + '/' + cmake_outputs[i]], stdout=PIPE).communicate()[0]
- assert 'hello, world!' in ret, 'Running cmake-based .js application failed!'
+ self.assertTextDataIdentical(open(cmakelistsdir + '/out.txt', 'r').read().strip(), ret.strip())
finally:
os.chdir(path_from_root('tests')) # Move away from the directory we are about to remove.
shutil.rmtree(tempdirname)
@@ -1665,10 +1665,10 @@ f.close()
if multiprocessing.cpu_count() < 2: return self.skip('need multiple cores')
try:
os.environ['EMCC_DEBUG'] = '1'
- os.environ['EMCC_CORES'] = '2'
+ os.environ['EMCC_CORES'] = '2' # standardize over machines
for asm, linkable, chunks, js_chunks in [
- (0, 0, 3, 2), (0, 1, 3, 4),
- (1, 0, 3, 2), (1, 1, 3, 4)
+ (0, 0, 2, 2), (0, 1, 2, 4),
+ (1, 0, 2, 2), (1, 1, 2, 4)
]:
print asm, linkable, chunks, js_chunks
output, err = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp'), '-O1', '-s', 'LINKABLE=%d' % linkable, '-s', 'ASM_JS=%d' % asm] + (['-O2'] if asm else []), stdout=PIPE, stderr=PIPE).communicate()
diff --git a/tests/unistd/io.c b/tests/unistd/io.c
index 0ff5f4fb..6bf22593 100644
--- a/tests/unistd/io.c
+++ b/tests/unistd/io.c
@@ -104,6 +104,12 @@ int main() {
printf("errno: %d\n\n", errno);
errno = 0;
+ printf("pread past end of file: %d\n", pread(f, readBuffer, sizeof readBuffer, 99999999999));
+ printf("data: %s\n", readBuffer);
+ memset(readBuffer, 0, sizeof readBuffer);
+ printf("errno: %d\n\n", errno);
+ errno = 0;
+
printf("seek: %d\n", lseek(f, 3, SEEK_SET));
printf("errno: %d\n\n", errno);
printf("partial read from file: %d\n", read(f, readBuffer, 3));
diff --git a/tests/unistd/io.out b/tests/unistd/io.out
index 037d0c34..c979557e 100644
--- a/tests/unistd/io.out
+++ b/tests/unistd/io.out
@@ -31,6 +31,10 @@ read from file: 10
data: 1234567890
errno: 0
+pread past end of file: 0
+data:
+errno: 0
+
seek: 3
errno: 0