X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=t%2Fmoe%2Fbatch.py;h=4fb4f1f5ff96a46c4ba07a5329554d09d6228515;hb=dcc852db06f099b6c96b681c79832d41777da334;hp=fb891dabdf7dc4524cc33ad06e87eec577d32788;hpb=9587bd376c403e16a0f79c9046eecc9b8f543cb8;p=moe.git diff --git a/t/moe/batch.py b/t/moe/batch.py index fb891da..4fb4f1f 100644 --- a/t/moe/batch.py +++ b/t/moe/batch.py @@ -1,9 +1,13 @@ #!/usr/bin/env python import os.path -import moe.log +import moe +import moe.box import moe.eval import moe.util +import moe.pipeline +import moe.testcase +import shutil def normalize_ext(e, ext): alias = e.cfgs["ALIAS_EXT_" + ext] @@ -13,9 +17,10 @@ def try_ext(e, ext): for e in e.cfgs["EXTENSIONS"].split(): if e == ext: return - raise moe.eval.MoeEvalErr, "Unknown extension: " + ext + raise moe.MoeErr, "Unknown extension: " + ext def locate(e, filename=None): + e.log.progress("Locating source... ") task = e.cfgs["TASK"] if filename is None: dir = "" @@ -23,12 +28,12 @@ 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 != "": if not os.path.exists(os.path.join(dir, file)): - raise moe.eval.MoeEvalErr, "No solution of %s called %s found" % (task,file) + raise moe.SolutionErr, "No solution of %s called %s found" % (task,file) ext = ext[1:] try_ext(e, ext) else: @@ -37,34 +42,145 @@ def locate(e, filename=None): if os.path.exists(os.path.join(dir, base + "." + ext)): found.append(ext) if len(found) == 0: - raise moe.eval.MoeEvalErr, "No solution of %s found" % task + raise moe.SolutionErr, "No solution of %s found" % task if len(found) > 1: - raise moe.eval.MoeEvalErr, "Multiple solutions of %s found" % task + raise moe.SolutionErr, "Multiple solutions of %s found" % task ext = found[0] file = base + "." + ext orig_path = os.path.join(dir, file) norm_ext = normalize_ext(e, ext) - moe.log.verbose("Found solution %s\n" % orig_path) + 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: - moe.log.verbose("Renaming to %s\n" % 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.meta["source"] = copy + e.stat["source"] = file + e.log.progress(file + "\n") -def compile(e): - pass +def compile_init(e): + e.log.progress("Compiling... ") + boxdir = moe.box.setup(e) + 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(): + 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)) + +def compile_run(e): + moe.box.show(e, "compiler input") + 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") + +def compile_done(e): + 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", compile) + e.main_pipe.insert(100, "compile-init", compile_init) + e.main_pipe.insert(150, "compile-run", compile_run) + e.main_pipe.insert(190, "compile-done", compile_done) e.main_pipe.insert(200, "batch-tests", tests)