def run_test(cfg, filename, input, output): logger.info("[RUN] %s", relative_path(cfg.ROOTDIR,input)) argv = cfg.get_run_argv(relative_path(cfg.ROOTDIR, filename)) logger.debug( "cat %s | %s | compare - %s", quote_argv([relative_path(cfg.ROOTDIR, input)]), quote_argv(argv), quote_argv([relative_path(cfg.ROOTDIR, output)])) with open(input,'rb') as f: p = Popen(argv,stdin=f,stdout=PIPE) (got,_) = p.communicate() if p.returncode != 0: logger.error("[ERR] %s: Exit code = %d", relative_path(cfg.ROOTDIR,filename), p.returncode) return with open(output, 'rb') as f: expected = f.read() if compare_output(got, expected): return True logger.error("[ERR] %s: incorrect output", relative_path(cfg.ROOTDIR,filename))
def compile_file(ROOTDIR, argv, source, target=None): logger.info("[COMPILE] %s", relative_path(ROOTDIR, source)) logger.debug(quote_argv(argv)) proc = Popen(argv,stdout=PIPE) result = proc.communicate() if proc.returncode == 0: if target: return target else: return result[0] logger.error("[ERROR] %s: compilation failed", relative_path(ROOTDIR, source))
def compile_file(ROOTDIR, argv, target, input=None, output=False): logger.info("[COMPILE] %s", relative_path(ROOTDIR, target)) logger.debug(quote_argv(argv)) proc = Popen(argv,stdin=None if input is None else PIPE,stdout=PIPE) result = proc.communicate(input) if proc.returncode == 0: if output: with open(target, 'wb') as f: f.write(result[0]) os.fchmod(f.fileno(), 0o0775) return True logger.error("[ERROR] %s: compilation failed", relative_path(ROOTDIR, target))
def run_file(cfg, filename): argv = cfg.get_run_argv(relative_path(cfg.ROOTDIR, filename)) logger.debug(quote_argv(argv)) p = Popen(argv) if p.wait() == 0: return True