diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-02-23 18:06:16 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-02-23 18:06:16 -0800 |
commit | 8af81c7eaeae4befca8790822eddf79c5fddc24f (patch) | |
tree | b12c1b7ffe1cc5bcfaf50f8473388a47828a5fa2 /tests/fuzz | |
parent | dbfd0c57fde6f0252a6c3142a6c0dea44b2270d7 (diff) |
handle nonportable/unaligned code in csmith
Diffstat (limited to 'tests/fuzz')
-rwxr-xr-x | tests/fuzz/csmith_driver.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/tests/fuzz/csmith_driver.py b/tests/fuzz/csmith_driver.py index fcf937f6..cc96a27c 100755 --- a/tests/fuzz/csmith_driver.py +++ b/tests/fuzz/csmith_driver.py @@ -7,7 +7,7 @@ Runs csmith, a C fuzzer, and looks for bugs import os, sys, difflib from subprocess import Popen, PIPE, STDOUT -sys.path += [os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tools')] +sys.path += [os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'tools')] import shared CSMITH = os.path.expanduser('~/Dev/csmith/src/csmith') @@ -18,10 +18,11 @@ filename = os.path.join(shared.CANONICAL_TEMP_DIR, 'fuzzcode') shared.DEFAULT_TIMEOUT = 3 tried = 0 -valid = 0 + +notes = { 'invalid': 0, 'unaligned': 0 } while 1: - print 'Tried %d, valid: %d' % (tried, valid) + print 'Tried %d, notes: %s' % (tried, notes) tried += 1 print '1) Generate C' shared.execute([CSMITH, '--no-volatiles', '--no-math64', '--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'], stdout=open(filename + '.c', 'w')) @@ -35,16 +36,29 @@ while 1: correct = shared.timeout_run(Popen([filename], stdout=PIPE, stderr=PIPE), 3) except Exception, e: print 'Failed or infinite looping in native, skipping', e + notes['invalid'] += 1 continue - valid += 1 - print '4) Compile JS-ly' - shared.try_delete(filename + '.js') - shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', '-s', 'PRECISE_I64_MATH=1', '-s', 'PRECISE_I32_MUL=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS, stderr=PIPE) - assert os.path.exists(filename + '.js') - print '5) Run JS-ly' - js = shared.run_js(filename + '.js', stderr=PIPE) #, engine=...) + print '4) Compile JS-ly and compare' + + def try_js(args): + shared.try_delete(filename + '.js') + shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', '-s', 'PRECISE_I64_MATH=1', '-s', 'PRECISE_I32_MUL=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS, stderr=PIPE) + assert os.path.exists(filename + '.js') + print '5) Run JS-ly' + js = shared.run_js(filename + '.js', stderr=PIPE) #, engine=...) + assert correct == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')]) - print '6) Verify' - assert correct == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')]) + # Try normally, then try unaligned because csmith does generate nonportable code that requires x86 alignment + ok = False + for args, note in [([], None), (['-s', 'UNALIGNED_MEMORY=1'], 'unaligned')]: + try: + try_js(args) + ok = True + if note: + notes[note] += 1 + break + except Exception, e: + print e + if not ok: break |