diff options
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 100 |
1 files changed, 95 insertions, 5 deletions
diff --git a/tests/runner.py b/tests/runner.py index d10a7c40..7085f5f9 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# This Python file uses the following encoding: utf-8 ''' Simple test runner @@ -14,7 +15,7 @@ will use 4 processes. To install nose do something like ''' from subprocess import Popen, PIPE, STDOUT -import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib, webbrowser, hashlib, threading, platform, BaseHTTPServer, multiprocessing, functools +import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib, webbrowser, hashlib, threading, platform, BaseHTTPServer, multiprocessing, functools, stat if len(sys.argv) == 1: @@ -296,7 +297,7 @@ process(sys.argv[1]) os.makedirs(ret) return ret - def get_library(self, name, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=True): + def get_library(self, name, generated_libs, configure=['sh', './configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=True, env_init={}): build_dir = self.get_build_dir() output_dir = self.get_dir() @@ -316,7 +317,7 @@ process(sys.argv[1]) print >> sys.stderr, '<building and saving into cache> ', return Building.build_library(name, build_dir, output_dir, generated_libs, configure, configure_args, make, make_args, self.library_cache, cache_name, - copy_project=True) + copy_project=True, env_init=env_init) def clear(self): for name in os.listdir(self.get_dir()): @@ -977,6 +978,36 @@ m_divisor is 1091269979 ''' self.do_run(src, ',0,,2,C!,0,C!,0,,65535,C!,0,') + def test_bswap(self): + if self.emcc_args == None: return self.skip('needs ta2') + + src = r''' + #include <stdio.h> + + extern "C" { + extern unsigned short llvm_bswap_i16(unsigned short x); + extern unsigned int llvm_bswap_i32(unsigned int x); + } + + int main(void) { + unsigned short x = 0xc8ef; + printf("%x,%x\n", x&0xff, x >> 8); + x = llvm_bswap_i16(x); + printf("%x,%x\n", x&0xff, x >> 8); + + unsigned int y = 0xc5de158a; + 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); + return 0; + } + ''' + self.do_run(src, '''ef,c8 +c8,ef +8a,15,de,c5 +c5,de,15,8a +''') + def test_sha1(self): if self.emcc_args == None: return self.skip('needs ta2') @@ -3969,6 +4000,10 @@ at function.:blag printf("%f, %f\n", atof("1.234567"), atof("cheez")); + float n = -1; + sscanf(" 2.8208", "%f", &n); + printf("%.4f\n", n); + float a = -1; sscanf("-3.03", "%f", &a); printf("%.4f\n", a); @@ -3998,7 +4033,7 @@ at function.:blag return 0; } ''' - self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n-3.0300\n|some|\n|something|\n|somethingmoar|\n' + + self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n2.8208\n-3.0300\n|some|\n|something|\n|somethingmoar|\n' + '1\n1499\n' + '5\n87,0.481565,0.059481,0,1\n' + '3\n-123,4294966531,-34\n') @@ -4478,6 +4513,22 @@ def process(filename): ''' self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected), post_build=add_pre_run_and_checks) + def test_utf(self): + self.banned_js_engines = [SPIDERMONKEY_ENGINE] # only node handles utf well + src = r''' + #include <stdio.h> + #include <emscripten.h> + + int main() { + char *c = "μ†ℱ ╋ℯ╳╋"; + printf("%d %d %d %d %s\n", c[0]&0xff, c[1]&0xff, c[2]&0xff, c[3]&0xff, c); + emscripten_run_script("cheez = Module._malloc(100);" + "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋\", cheez);" + "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, 'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, 'i8')&0xff, ]);"); + } + ''' + self.do_run(src, '206 188 226 128 μ†ℱ ╋ℯ╳╋\nμ†ℱ ╋ℯ╳╋,206,188,226,128\n'); + def test_direct_string_constant_usage(self): if self.emcc_args is None: return self.skip('requires libcxx') @@ -5274,6 +5325,7 @@ def process(filename): [os.path.join('utils', 'pdftoppm.o'), os.path.join('utils', 'parseargs.o'), os.path.join('poppler', '.libs', 'libpoppler.a')], + env_init={ 'FONTCONFIG_CFLAGS': ' ', 'FONTCONFIG_LIBS': ' ' }, configure_args=['--disable-libjpeg', '--disable-libpng', '--disable-poppler-qt', '--disable-poppler-qt4', '--disable-cms', '--disable-cairo-output', '--disable-abiword-output', '--enable-shared=no']) # Combine libraries @@ -5305,7 +5357,7 @@ def process(filename): )) ).replace( '// {{POST_RUN_ADDITIONS}}', - "Module.print('Data: ' + JSON.stringify(FS.root.contents['image.raw'].contents));" + "Module.print('Data: ' + JSON.stringify(FS.analyzePath('image.raw').object.contents));" ) open(filename, 'w').write(src) ''' @@ -8403,6 +8455,44 @@ elif 'sanity' in str(sys.argv): output = self.check_working([EMCC, '-O2', 'tests/hello_world.cpp'], '') assert os.path.exists('a.out.js') + def test_llvm(self): + LLVM_WARNING = 'warning: LLVM version appears incorrect' + + restore() + + # Clang should report the version number we expect, and emcc should not warn + assert ('clang version ' + '.'.join(map(str, EXPECTED_LLVM_VERSION))) in Popen([CLANG, '-v'], stderr=PIPE).communicate()[1] + output = self.check_working(EMCC) + assert LLVM_WARNING not in output, output + + # Fake a different llvm version + restore() + f = open(CONFIG_FILE, 'a') + f.write('LLVM_ROOT = "' + path_from_root('tests', 'fake') + '"') + f.close() + + if not os.path.exists(path_from_root('tests', 'fake')): + os.makedirs(path_from_root('tests', 'fake')) + + try: + os.environ['EM_IGNORE_SANITY'] = '1' + for x in range(-2, 3): + for y in range(-2, 3): + f = open(path_from_root('tests', 'fake', 'clang'), 'w') + f.write('#!/bin/sh\n') + f.write('echo "clang version %d.%d" 1>&2\n' % (EXPECTED_LLVM_VERSION[0] + x, EXPECTED_LLVM_VERSION[1] + y)) + f.close() + shutil.copyfile(path_from_root('tests', 'fake', 'clang'), path_from_root('tests', 'fake', 'clang++')) + os.chmod(path_from_root('tests', 'fake', 'clang'), stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) + os.chmod(path_from_root('tests', 'fake', 'clang++'), stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) + if x != 0 or y != 0: + output = self.check_working(EMCC, LLVM_WARNING) + else: + output = self.check_working(EMCC) + assert LLVM_WARNING not in output, output + finally: + del os.environ['EM_IGNORE_SANITY'] + def test_emcc(self): SANITY_MESSAGE = 'Emscripten: Running sanity checks' SANITY_FAIL_MESSAGE = 'sanity check failed to run' |