diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-16 18:40:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-17 12:44:21 -0700 |
commit | ee500a3d942327563451bfc81dee0a3044a3cb7e (patch) | |
tree | d5674ccc751f4e004b15b025929a88e6e6e005d7 /tests/runner.py | |
parent | a2b4acbd95c1f307d0d51bfd0134f6a88a087c46 (diff) |
UNALIGNED_MEMORY option to emulate unaligned reads/writes all the time, to support some nonportable code
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/tests/runner.py b/tests/runner.py index de8acaef..db566c3f 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1183,16 +1183,11 @@ c5,de,15,8a } ''' - Settings.EMULATE_UNALIGNED_ACCESSES = 0 - try: self.do_run(src, '*300:1*\n*515559*\n*42949672960*\n') except Exception, e: assert 'must be aligned' in str(e), e # expected to fail without emulation - # XXX TODO Settings.EMULATE_UNALIGNED_ACCESSES = 1 - #self.do_run(src, '*300:1*\n*515559*\n*42949672960*\n') # but succeeds with it - def test_unsigned(self): Settings.CORRECT_SIGNS = 1 # We test for exactly this sort of thing here Settings.CHECK_SIGNS = 0 @@ -7279,6 +7274,26 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'test.cpp'), '-fcatch-undefined-behavior']).communicate() self.assertContained('hello, world!', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_unaligned_memory(self): + open(os.path.join(self.get_dir(), 'test.cpp'), 'w').write(r''' + #include <stdio.h> + + typedef unsigned char Bit8u; + typedef unsigned short Bit16u; + typedef unsigned int Bit32u; + + int main() + { + Bit8u data[4] = {0x01,0x23,0x45,0x67}; + + printf("data: %x\n", *(Bit32u*)data); + printf("data[0,1] 16bit: %x\n", *(Bit16u*)data); + printf("data[1,2] 16bit: %x\n", *(Bit16u*)(data+1)); + } + ''') + Popen(['python', EMCC, os.path.join(self.get_dir(), 'test.cpp'), '-s', 'UNALIGNED_MEMORY=1']).communicate() + self.assertContained('data: 67452301\ndata[0,1] 16bit: 2301\ndata[1,2] 16bit: 4523', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_l_link(self): # Linking with -lLIBNAME and -L/DIRNAME should work |