diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cases/typestr.ll | 19 | ||||
-rw-r--r-- | tests/emscripten_fs_api_browser.cpp | 50 | ||||
-rw-r--r-- | tests/parseInt/output.txt | 37 | ||||
-rwxr-xr-x | tests/runner.py | 124 |
4 files changed, 201 insertions, 29 deletions
diff --git a/tests/cases/typestr.ll b/tests/cases/typestr.ll new file mode 100644 index 00000000..49074637 --- /dev/null +++ b/tests/cases/typestr.ll @@ -0,0 +1,19 @@ +; 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, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] +@.str1227 = private unnamed_addr constant [9 x i8] c" = type \00", align 1 + +; [#uses=0] +define i32 @main() { +entry: + %retval = alloca i32, align 4 ; [#uses=1 type=i32*] + store i32 0, i32* %retval + %call0 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str1227, i32 0, i32 0)) ; [#uses=0 type=i32] + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + ret i32 1 +} + +; [#uses=1] +declare i32 @printf(i8*, ...) diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp index a2a82160..0355287a 100644 --- a/tests/emscripten_fs_api_browser.cpp +++ b/tests/emscripten_fs_api_browser.cpp @@ -9,13 +9,58 @@ 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) { + printf("onLoadedData %d\n", (int)arg); + 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) { + printf("onErrorData %d\n", (int)arg); + get_count++; + assert((int)arg == 246); + data_bad = 1; +} + +int counter = 0; void wait_wgets() { + if (counter++ == 60) { + printf("%d\n", get_count); + counter = 0; + } + if (get_count == 3) { + static bool fired = false; + if (!fired) { + fired = true; + 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(); } + assert(get_count <= 5); } void onLoaded(const char* file) { @@ -23,8 +68,6 @@ void onLoaded(const char* file) { result = 0; } - printf("loaded: %s\n", file); - if (FILE * f = fopen(file, "r")) { printf("exists: %s\n", file); int c = fgetc (f); @@ -39,6 +82,7 @@ void onLoaded(const char* file) { } get_count++; + printf("onLoaded %s\n", file); } void onError(const char* file) { @@ -46,8 +90,8 @@ void onError(const char* file) { result = 0; } - printf("error: %s\n", file); get_count++; + printf("onError %s\n", file); } int main() { 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 8a646524..6f7fbdca 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1155,15 +1155,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) { @@ -1176,6 +1180,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; } ''' @@ -1183,6 +1192,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): @@ -6191,7 +6270,7 @@ void*:16 } ''' self.do_run(src, '*10,22*') - + def test_mmap(self): self.banned_js_engines = [NODE_JS] # slower, and fail on 64-bit @@ -6203,13 +6282,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++) { @@ -6229,6 +6315,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 @@ -8878,7 +8991,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 @@ -8887,9 +9000,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]) |