aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-31 11:49:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-31 11:49:14 -0800
commitada59f0a9d23d8ec19ee6a1326977ddf6e93f5f9 (patch)
tree1e1f079b5569ae2d7269ff2abf4b520ad82d3cdd /tests
parent2f4401a79e96917f78876c3e09b8d31754a26f70 (diff)
parente97f48a2c9376354a6b8927191322322f13808ba (diff)
Merge branch 'incoming'
Diffstat (limited to 'tests')
-rw-r--r--tests/emscripten_fs_api_browser.cpp32
-rw-r--r--tests/parseInt/output.txt37
-rwxr-xr-xtests/runner.py124
3 files changed, 167 insertions, 26 deletions
diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp
index a2a82160..9936a09c 100644
--- a/tests/emscripten_fs_api_browser.cpp
+++ b/tests/emscripten_fs_api_browser.cpp
@@ -9,10 +9,42 @@ extern "C" {
int result = 1;
int get_count = 0;
+int data_ok = 0;
+int data_bad = 0;
+
+void onLoadedData(void *arg, void *buffer, int size) {
+ get_count++;
+ assert(size == 329895);
+ assert((int)arg == 135);
+ unsigned char *b = (unsigned char*)buffer;
+ assert(b[0] == 137);
+ assert(b[1122] == 128);
+ assert(b[1123] == 201);
+ assert(b[202125] == 218);
+ data_ok = 1;
+}
+
+void onErrorData(void *arg) {
+ get_count++;
+ assert((int)arg == 246);
+ data_bad = 1;
+}
void wait_wgets() {
if (get_count == 3) {
+ emscripten_async_wget_data(
+ "http://localhost:8888/screenshot.png",
+ (void*)135,
+ onLoadedData,
+ onErrorData);
+ emscripten_async_wget_data(
+ "http://localhost:8888/fail_me",
+ (void*)246,
+ onLoadedData,
+ onErrorData);
+ } else if (get_count == 5) {
assert(IMG_Load("/tmp/screen_shot.png"));
+ assert(data_ok == 1 && data_bad == 1);
emscripten_cancel_main_loop();
REPORT_RESULT();
}
diff --git a/tests/parseInt/output.txt b/tests/parseInt/output.txt
index 7ab00631..c1406949 100644
--- a/tests/parseInt/output.txt
+++ b/tests/parseInt/output.txt
@@ -1,52 +1,50 @@
strtol("-9223372036854775809") = -2147483648
ERR 34
-strtoll("-9223372036854775809") = -9223372036854775000
+strtoll("-9223372036854775809") = -9223372036854775808
ERR 34
strtoul("-9223372036854775809") = 4294967295
ERR 34
-strtoull("-9223372036854775809") = 9223372036854774000
+strtoull("-9223372036854775809") = 9223372036854775807
strtol("-9223372036854775808") = -2147483648
ERR 34
-strtoll("-9223372036854775808") = -9223372036854775000
-ERR 34
+strtoll("-9223372036854775808") = -9223372036854775808
strtoul("-9223372036854775808") = 4294967295
ERR 34
-strtoull("-9223372036854775808") = 9223372036854774000
+strtoull("-9223372036854775808") = 9223372036854775808
strtol("-9223372036854775807") = -2147483648
ERR 34
-strtoll("-9223372036854775807") = -9223372036854775000
-ERR 34
+strtoll("-9223372036854775807") = -9223372036854775807
strtoul("-9223372036854775807") = 4294967295
ERR 34
-strtoull("-9223372036854775807") = 9223372036854774000
+strtoull("-9223372036854775807") = 9223372036854775809
strtol("-2147483649") = -2147483648
ERR 34
strtoll("-2147483649") = -2147483649
strtoul("-2147483649") = 2147483647
-strtoull("-2147483649") = 18446744071562068000
+strtoull("-2147483649") = 18446744071562067967
strtol("-2147483648") = -2147483648
strtoll("-2147483648") = -2147483648
strtoul("-2147483648") = 2147483648
-strtoull("-2147483648") = 18446744071562068000
+strtoull("-2147483648") = 18446744071562067968
strtol("-2147483647") = -2147483647
strtoll("-2147483647") = -2147483647
strtoul("-2147483647") = 2147483649
-strtoull("-2147483647") = 18446744071562068000
+strtoull("-2147483647") = 18446744071562067969
strtol("-5") = -5
strtoll("-5") = -5
strtoul("-5") = 4294967291
-strtoull("-5") = 18446744069414584000
+strtoull("-5") = 18446744073709551611
strtol("-1") = -1
strtoll("-1") = -1
strtoul("-1") = 4294967295
-strtoull("-1") = 18446744069414584000
+strtoull("-1") = 18446744073709551615
strtol("0") = 0
strtoll("0") = 0
@@ -100,27 +98,28 @@ strtoull("4294967296") = 4294967296
strtol("18446744073709551614") = 2147483647
ERR 34
-strtoll("18446744073709551614") = 9223372036854775000
+strtoll("18446744073709551614") = 9223372036854775807
ERR 34
strtoul("18446744073709551614") = 4294967295
ERR 34
-strtoull("18446744073709551614") = 18446744069414584000
+strtoull("18446744073709551614") = 18446744073709551614
strtol("18446744073709551615") = 2147483647
ERR 34
-strtoll("18446744073709551615") = 9223372036854775000
+strtoll("18446744073709551615") = 9223372036854775807
ERR 34
strtoul("18446744073709551615") = 4294967295
ERR 34
-strtoull("18446744073709551615") = 18446744069414584000
+strtoull("18446744073709551615") = 18446744073709551615
strtol("18446744073709551616") = 2147483647
ERR 34
-strtoll("18446744073709551616") = 9223372036854775000
+strtoll("18446744073709551616") = 9223372036854775807
ERR 34
strtoul("18446744073709551616") = 4294967295
ERR 34
-strtoull("18446744073709551616") = 18446744069414584000
+strtoull("18446744073709551616") = 18446744073709551615
+ERR 34
strtol("0x12", 0, 0) = 18
strtol("0x12", 0, 10) = 0
diff --git a/tests/runner.py b/tests/runner.py
index 1f154aee..b1852ff2 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1151,15 +1151,19 @@ m_divisor is 1091269979
'''
self.do_run(src, ',0,,2,C!,0,C!,0,,65535,C!,0,')
- def test_bswap(self):
+ def test_llvm_intrinsics(self):
if self.emcc_args == None: return self.skip('needs ta2')
src = r'''
#include <stdio.h>
+ #include <sys/types.h>
extern "C" {
extern unsigned short llvm_bswap_i16(unsigned short x);
extern unsigned int llvm_bswap_i32(unsigned int x);
+ extern int32_t llvm_ctlz_i32(int32_t x);
+ extern int64_t llvm_ctlz_i64(int64_t x);
+ extern int llvm_expect_i32(int x, int y);
}
int main(void) {
@@ -1172,6 +1176,11 @@ m_divisor is 1091269979
printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff);
y = llvm_bswap_i32(y);
printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff);
+
+ printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10));
+
+ printf("%d\n", llvm_expect_i32(x % 27, 3));
+
return 0;
}
'''
@@ -1179,6 +1188,76 @@ m_divisor is 1091269979
c8,ef
8a,15,de,c5
c5,de,15,8a
+23,21
+13
+''')
+
+ def test_bswap64(self):
+ if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
+
+ src = r'''
+ #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;
+ }
+ '''
+ self.do_run(src, '''4914553019779824384
+1
+2
+bbccddeeff3344
+4433ffeeddccbb00
+4433ffeeddccbb00
+Succeeded!
''')
def test_sha1(self):
@@ -6160,7 +6239,7 @@ void*:16
}
'''
self.do_run(src, '*10,22*')
-
+
def test_mmap(self):
Settings.TOTAL_MEMORY = 100*1024*1024
@@ -6170,13 +6249,20 @@ void*:16
#include <assert.h>
int main(int argc, char *argv[]) {
+ for (int i = 0; i < 10; i++) {
+ int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0);
+ assert(((int)map) % 4096 == 0); // aligned
+ assert(munmap(map, 5000) == 0);
+ }
+
const int NUM_BYTES = 8 * 1024 * 1024;
const int NUM_INTS = NUM_BYTES / sizeof(int);
int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANON, -1, 0);
assert(map != MAP_FAILED);
-
+
int i;
for (i = 0; i < NUM_INTS; i++) {
@@ -6196,6 +6282,33 @@ void*:16
self.do_run(src, 'hello,world')
self.do_run(src, 'hello,world', force_c=True)
+ def test_mmap_file(self):
+ if self.emcc_args is None: return self.skip('requires emcc')
+ self.emcc_args += ['--embed-file', 'data.dat']
+
+ open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000))
+
+ src = r'''
+ #include <stdio.h>
+ #include <sys/mman.h>
+
+ int main() {
+ printf("*\n");
+ FILE *f = fopen("data.dat", "r");
+ char *m;
+ m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 0);
+ for (int i = 0; i < 20; i++) putchar(m[i]);
+ munmap(m, 9000);
+ printf("\n");
+ m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 5);
+ for (int i = 0; i < 20; i++) putchar(m[i]);
+ munmap(m, 9000);
+ printf("\n*\n");
+ return 0;
+ }
+ '''
+ self.do_run(src, '*\ndata from the file .\nfrom the file ......\n*\n')
+
def test_cubescript(self):
if self.emcc_args is not None and '-O2' in self.emcc_args:
self.emcc_args += ['--closure', '1'] # Use closure here for some additional coverage
@@ -8820,7 +8933,7 @@ fixture: interfaces
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'files.cpp'), '-c']).communicate()
Popen([PYTHON, path_from_root('tools', 'nativize_llvm.py'), os.path.join(self.get_dir(), 'files.o')]).communicate(input)[0]
output = Popen([os.path.join(self.get_dir(), 'files.o.run')], stdin=open(os.path.join(self.get_dir(), 'stdin')), stdout=PIPE, stderr=PIPE).communicate()
- self.assertIdentical('''size: 37
+ self.assertContained('''size: 37
data: 119,97,107,97,32,119,97,107,97,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35
loop: 119 97 107 97 32 119 97 107 97 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35
input:inter-active
@@ -8829,9 +8942,6 @@ $
5 : 10,30,20,11,88
other=ay file...
seeked= file.
-seeked=e...
-seeked=,,.
-fscanfed: 10 - hello
''', output[0])
self.assertIdentical('texte\n', output[1])