def main(delete): suite = unittest.TestSuite() gen = printf_generator() for i in xrange(TEST_ITERATIONS): sys.stdout.write('\rbuilding tests %.02f%%' % (float(i) / float(TEST_ITERATIONS) * 100)) sys.stdout.flush() c_file, printfs = generate_printfs_for_c_file(gen) if not delete: print c_file oracle = run_against_libc(c_file) result = run_against_musl(c_file) test = Test_Case(oracle, result, printfs) suite.addTest(test) if delete: os.remove(c_file) sys.stdout.write('\rTest Building Complete. Running ...\n') sys.stdout.flush() os.remove(O_BIN) os.remove(T_BIN) runner = unittest.TextTestRunner(verbosity=2) runner.run(suite) return 0;
def generate_printfs_for_c_file(printf): commands = [] with tempfile.NamedTemporaryFile(suffix='.c', delete=False) as tmp: tmp.write('\n#include <stdio.h>\nint main(void) {\n') for i in xrange(PRINTFS_IN_FILE): try: random_printf = next(printf) except StopIteration: printf = printf_generator() random_printf = next(printf) tmp.write(random_printf) tmp.write('\n') commands.append(random_printf) tmp.write('return 0;\n}\n') return (tmp.name, commands)