X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=t%2Fmoe%2Fbatch.py;h=4fb4f1f5ff96a46c4ba07a5329554d09d6228515;hb=dcc852db06f099b6c96b681c79832d41777da334;hp=cd0d93dcffc93f313e1000bd9d7a0a74aadb2a62;hpb=5701572b35e7ebc7c2d96cc603cd720fb2649ac4;p=moe.git diff --git a/t/moe/batch.py b/t/moe/batch.py index cd0d93d..4fb4f1f 100644 --- a/t/moe/batch.py +++ b/t/moe/batch.py @@ -5,6 +5,8 @@ import moe import moe.box import moe.eval import moe.util +import moe.pipeline +import moe.testcase import shutil def normalize_ext(e, ext): @@ -26,7 +28,7 @@ def locate(e, filename=None): else: dir, file = os.path.split(filename) if dir == "": - dir = e.cfgs["SOL_DIR"] + dir = e.cfgs["SDIR"] base, ext = os.path.splitext(file) if ext != "": @@ -51,42 +53,131 @@ def locate(e, filename=None): e.log.verbose("Found solution %s\n" % orig_path) copy = e.cfgs["TASK"] + "." + norm_ext - copy_path = os.path.join(e.cfgs["TEST_DIR"], copy) + copy_path = os.path.join(e.cfgs["TDIR"], copy) if file != copy: e.log.verbose("Renaming to %s\n" % copy) moe.util.link_or_copy(orig_path, copy_path) e.builtins.set("SRC", copy) e.builtins.set("EXT", norm_ext) - e.cfgs.apply_overrides("EXT_" + norm_ext) + e.cfgs.apply_overrides("EXT_" + norm_ext + "_") e.stat["source"] = file e.log.progress(file + "\n") def compile_init(e): + e.log.progress("Compiling... ") boxdir = moe.box.setup(e) - pdir = e.cfgs["TASK_DIR"] - tdir = e.cfgs["TEST_DIR"] + pdir = e.cfgs["PDIR"] + tdir = e.cfgs["TDIR"] shutil.copyfile(os.path.join(tdir, e.cfgs["SRC"]), os.path.join(boxdir, e.cfgs["SRC"])) - for x in e.cfgs["EXTRAS"].split() + e.cfgs["COMP_EXTRAS"].split() + for x in e.cfgs["EXTRAS"].split() + e.cfgs["COMP_EXTRAS"].split(): xx = os.path.join(tdir, x) if not os.path.isfile(xx): xx = os.path.join(pdir, x) e.log.verbose("Copying extra file %s\n" % xx) shutil.copyfile(xx, os.path.join(boxdir, x)) - pass def compile_run(e): moe.box.show(e, "compiler input") - rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], e.cfgs["COMP"]) + cc = e.cfgs["COMP"] + e.log.verbose("Compilation command: %s\n" % cc) + rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], cc) + if rc > 0: + e.log.progress("FAILED\n") + ## FIXME: status file + raise moe.pipeline.MoeAbortPipeline(200) moe.box.show(e, "compiler output") - pass def compile_done(e): - pass + try: + shutil.copyfile(os.path.join(e.cfgs["BOXDIR"], e.cfgs["EXE"]), os.path.join(e.cfgs["TDIR"], e.cfgs["EXE"])) + except IOError: + raise moe.MoeErr, "Compiler succeeded, but produced no output" + e.log.progress("OK\n") + +def test_in(e): + tdir = e.cfgs["TDIR"] + boxdir = moe.box.setup(e) + inn = e.cfgs["TESTCASE_IN"] + in_type = e.cfgs["IN_TYPE"] or e.cfgs["IO_TYPE"] + out_type = e.cfgs["OUT_TYPE"] or e.cfgs["IO_TYPE"] + is_interactive = e.cfgs["TASK_TYPE"] == "interactive" + sandbox_opts = "-M" + os.path.join(tdir, e.cfgs["TEST"] + ".status") + + if not os.path.exists(os.path.join(tdir, e.cfgs["EXE"])): + ## FIXME: status file + raise SolutionErr, "Compilation failed" + shutil.copyfile(os.path.join(tdir, e.cfgs["EXE"]), os.path.join(boxdir, e.cfgs["EXE"])) + os.chmod(os.path.join(boxdir, e.cfgs["EXE"]), 0555) + + if in_type == "file": + in_name = e.cfgs["IN_NAME"] + e.log.verbose("Input file: %s (copied from %s)\n" % (in_name, os.path.join(e.cfgs["PDIR"], inn))) + shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name)) + if not is_interactive: + sandbox_opts = " -i/dev/null" + elif in_type == "stdio": + e.log.verbose("Input file: (copied from %s)\n" % os.path.join(e.cfgs["PDIR"], inn)) + shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin")) + sandbox_opts = " -i.stdin" + elif in_type == "none": + e.log.verbose("Input file: \n") + if not is_interactive: + sandbox_opts += " -i/dev/null" + elif in_type == "dir": + ## FIXME + raise MoeErr, "Directory input not yet implemented" + else: + raise MoeErr, "Unknown input type %s" % in_type + + if out_type == "file": + out_name = e.cfgs["OUT_NAME"] + e.log.verbose("Output file: %s\n" % out_name) + if not is_interactive: + sandbox_opts += " -o/dev/null" + elif out_type == "stdio": + e.log.verbose("Output file: \n") + sandbox_opts += " -o.stdout" + elif out_type == "none": + e.log.verbose("Output file: \n") + if not is_interactive: + sandbox_opts += " -o/dev/null" + else: + raise MoeErr, "Unknown output type %s" % out_type + + e.test_builtins.set("BOX_IO_OPTS", sandbox_opts) + +def test_run(e): + e.log.verbose("Time limit: %s s\n" % e.cfgs["TIME_LIMIT"]) + e.log.verbose("Memory limit: %s KB\n" % e.cfgs["MEM_LIMIT"]) + moe.box.show(e, "test input") + e.log.progress(" ") + moe.box.run(e, e.cfgs["TEST_SANDBOX_OPTS"], e.cfgs["TEST_EXEC_CMD"]) + moe.box.show(e, "test output") + ## FIXME: Parse the status file and delete it + ### Check for runtime errors reported by the box + +def test_collect(e): + tdir = e.cfgs["TDIR"] + boxdir = e.cfgs["BOXDIR"] + out_type = e.cfgs["OUT_TYPE"] or e.cfgs["IO_TYPE"] + is_interactive = e.cfgs["TASK_TYPE"] == "interactive" + + if out_type == "file": + out_path = e.cfgs["OUT_NAME"] + elif out_type == "stdio": + out_path = ".stdout" + if not os.path.exists(os.path.join(boxdir, out_path)): + raise moe.SolutionErr("No output file", "NO") + shutil.copyfile(os.path.join(boxdir, out_path), os.path.join(tdir, e.cfgs["TESTCASE_OUT"])) def tests(e): - pass + e.log.progress("\n") + e.test_pipe.insert(100, "prepare", test_in) + e.test_pipe.insert(200, "run", test_run) + e.test_pipe.insert(300, "collect", test_collect) + moe.testcase.run_tests(e) def prepare_pipe(e): e.main_pipe.insert(100, "compile-init", compile_init)