Exemple #1
0
 def try_js(args):
   shared.try_delete(filename + '.js')
   print '(compile)'
   shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args, stderr=PIPE)
   assert os.path.exists(filename + '.js')
   print '(run)'
   js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1, check_timeout=True)
   assert correct1 == js or correct2 == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct1.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')])
Exemple #2
0
 def try_js(args):
   shared.try_delete(filename + '.js')
   print '(compile)'
   shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args, stderr=PIPE)
   assert os.path.exists(filename + '.js')
   print '(run)'
   js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1, check_timeout=True)
   assert correct1 == js or correct2 == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct1.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')])
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 + args,
                   stderr=PIPE)
    assert os.path.exists(filename + '.js')
    js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1)
    assert correct == js, ''.join([
        a.rstrip() + '\n' for a in difflib.unified_diff(correct.split('\n'),
                                                        js.split('\n'),
                                                        fromfile='expected',
                                                        tofile='actual')
    ])
Exemple #4
0
 def try_js(args):
     shared.try_delete(filename + ".js")
     print "(compile)"
     shared.execute(
         [shared.EMCC, "-O2", "-s", "ASM_JS=1", filename + ".c", "-o", filename + ".js"] + CSMITH_CFLAGS + args,
         stderr=PIPE,
     )
     assert os.path.exists(filename + ".js")
     print "(run)"
     js = shared.run_js(filename + ".js", stderr=PIPE, engine=engine1, check_timeout=True)
     assert correct1 == js or correct2 == js, "".join(
         [
             a.rstrip() + "\n"
             for a in difflib.unified_diff(
                 correct1.split("\n"), js.split("\n"), fromfile="expected", tofile="actual"
             )
         ]
     )
Exemple #5
0
def init_download(download_list, audio_dir):
    # Tell get_iplayer to download audio programs in download_list PIDs
    download_str = ','.join(download_list)
    for path in sh.execute([
            'get_iplayer', '--type=radio', '--pid=' + download_str,
            '--file-prefix=<pid>', '--radiomode=good', '--output=' + audio_dir,
            '--force', '--overwrite'
    ]):
        logging.debug(path)
    # TO DO: Add better error logging
    return
Exemple #6
0
filename = os.path.join(shared.CANONICAL_TEMP_DIR, 'fuzzcode')

shared.DEFAULT_TIMEOUT = 1

tried = 0

notes = { 'invalid': 0, 'unaligned': 0, 'embug': 0 }

fails = 0

while 1:
  print 'Tried %d, notes: %s' % (tried, notes)
  print '1) Generate C'
  shared.execute([CSMITH, '--no-volatiles', '--no-math64', '--no-packed-struct'],# +
                 #['--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'],
                 stdout=open(filename + '.c', 'w'))
  #shutil.copyfile(filename + '.c', 'testcase%d.c' % tried)
  print '1) Generate C... %.2f K of C source' % (len(open(filename + '.c').read())/1024.)

  tried += 1

  print '2) Compile natively'
  shared.try_delete(filename)
  shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename + '1'] + CSMITH_CFLAGS, stderr=PIPE) #  + shared.EMSDK_OPTS
  shared.execute([shared.CLANG_CC, '-O2', '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', filename + '.c', '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS, stderr=PIPE)
  shared.execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc'], stdout=PIPE, stderr=PIPE)
  shutil.move(filename + '.bc.run', filename + '2')
  shared.execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS, stderr=PIPE)
  print '3) Run natively'
  try:
import os, sys, difflib
from subprocess import Popen, PIPE, STDOUT

sys.path += [
    os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
                 'tools')
]
import shared

filename = sys.argv[1]
print 'testing file', filename

print '2) Compile natively'
shared.try_delete(filename)
shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename] +
               CSMITH_CFLAGS,
               stderr=PIPE)
assert os.path.exists(filename)
print '3) Run natively'
try:
    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
    os.exit(0)  # boring

print '4) Compile JS-ly and compare'


def try_js(args):
Exemple #8
0
filename = os.path.join(shared.CANONICAL_TEMP_DIR, "fuzzcode")

shared.DEFAULT_TIMEOUT = 5

tried = 0

notes = {"invalid": 0, "unaligned": 0, "embug": 0}

fails = 0

while 1:
    print "Tried %d, notes: %s" % (tried, notes)
    print "1) Generate C"
    shared.execute(
        [CSMITH, "--no-volatiles", "--no-math64", "--no-packed-struct"],  # +
        # ['--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'],
        stdout=open(filename + ".c", "w"),
    )
    # shutil.copyfile(filename + '.c', 'testcase%d.c' % tried)
    print "1) Generate C... %.2f K of C source" % (len(open(filename + ".c").read()) / 1024.0)

    tried += 1

    print "2) Compile natively"
    shared.try_delete(filename)
    shared.execute(
        [shared.CLANG_CC, "-O2", filename + ".c", "-o", filename + "1"] + CSMITH_CFLAGS, stderr=PIPE
    )  #  + shared.EMSDK_OPTS
    shared.execute(
        [
            shared.CLANG_CC,
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 + args, stderr=PIPE)
  assert os.path.exists(filename + '.js')
  js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1)
  assert correct == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')])
'''
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(os.path.dirname(__file__))), 'tools')]
import shared

filename = sys.argv[1]
print 'testing file', filename

print '2) Compile natively'
shared.try_delete(filename)
shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename] + CSMITH_CFLAGS, stderr=PIPE)
assert os.path.exists(filename)
print '3) Run natively'
try:
  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
  os.exit(0) # boring 

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 + args, stderr=PIPE)
  assert os.path.exists(filename + '.js')
CSMITH = os.path.expanduser('~/Dev/csmith/src/csmith')
CSMITH_CFLAGS = ['-I' + os.path.expanduser('~/Dev/csmith/runtime/')]

filename = os.path.join(shared.CANONICAL_TEMP_DIR, 'fuzzcode')

shared.DEFAULT_TIMEOUT = 1

tried = 0

notes = { 'invalid': 0, 'unaligned': 0, 'embug': 0 }

while 1:
  print 'Tried %d, notes: %s' % (tried, notes)
  tried += 1
  print '1) Generate C'
  shared.execute([CSMITH, '--no-volatiles', '--no-math64'], stdout=open(filename + '.c', 'w'))

  print '2) Compile natively'
  shared.try_delete(filename)
  shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename] + CSMITH_CFLAGS, stderr=PIPE)
  assert os.path.exists(filename)
  print '3) Run natively'
  try:
    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

  print '4) Compile JS-ly and compare'
Exemple #12
0
filename = os.path.join(shared.CANONICAL_TEMP_DIR, 'fuzzcode')

shared.DEFAULT_TIMEOUT = 5

tried = 0

notes = { 'invalid': 0, 'unaligned': 0, 'embug': 0 }

fails = 0

while 1:
  print 'Tried %d, notes: %s' % (tried, notes)
  print '1) Generate C'
  shared.execute([CSMITH, '--no-volatiles', '--no-math64', '--no-packed-struct'],# +
                 #['--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'],
                 stdout=open(filename + '.c', 'w'))
  #shutil.copyfile(filename + '.c', 'testcase%d.c' % tried)
  print '1) Generate C... %.2f K of C source' % (len(open(filename + '.c').read())/1024.)

  tried += 1

  print '2) Compile natively'
  shared.try_delete(filename)
  shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename + '1'] + CSMITH_CFLAGS, stderr=PIPE) #  + shared.EMSDK_OPTS
  shared.execute([shared.CLANG_CC, '-O2', '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', filename + '.c', '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS, stderr=PIPE)
  shared.execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc'], stdout=PIPE, stderr=PIPE)
  shutil.move(filename + '.bc.run', filename + '2')
  shared.execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS, stderr=PIPE)
  print '3) Run natively'
  try: