X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=t%2Fmoe%2Fbatch.py;h=9c839830fee892bdfb1d3e32951138a17a8741b7;hb=d8de72934717e8f287301c07d2ec70f1ca332e79;hp=4fb4f1f5ff96a46c4ba07a5329554d09d6228515;hpb=dcc852db06f099b6c96b681c79832d41777da334;p=eval.git diff --git a/t/moe/batch.py b/t/moe/batch.py index 4fb4f1f..9c83983 100644 --- a/t/moe/batch.py +++ b/t/moe/batch.py @@ -10,41 +10,41 @@ import moe.testcase import shutil def normalize_ext(e, ext): - alias = e.cfgs["ALIAS_EXT_" + ext] + alias = e["ALIAS_EXT_" + ext] return alias if alias != "" else ext def try_ext(e, ext): - for e in e.cfgs["EXTENSIONS"].split(): + for e in e["EXTENSIONS"].split(): if e == ext: return - raise moe.MoeErr, "Unknown extension: " + ext + raise moe.MoeError, "Unknown extension: " + ext def locate(e, filename=None): e.log.progress("Locating source... ") - task = e.cfgs["TASK"] + task = e["TASK"] if filename is None: dir = "" file = task else: dir, file = os.path.split(filename) if dir == "": - dir = e.cfgs["SDIR"] + dir = e["SDIR"] base, ext = os.path.splitext(file) if ext != "": if not os.path.exists(os.path.join(dir, file)): - raise moe.SolutionErr, "No solution of %s called %s found" % (task,file) + raise moe.SolutionError, "No solution of %s called %s found" % (task,file) ext = ext[1:] try_ext(e, ext) else: found = [] - for ext in e.cfgs["EXTENSIONS"].split(): + for ext in e["EXTENSIONS"].split(): if os.path.exists(os.path.join(dir, base + "." + ext)): found.append(ext) if len(found) == 0: - raise moe.SolutionErr, "No solution of %s found" % task + raise moe.SolutionError, "No solution of %s found" % task if len(found) > 1: - raise moe.SolutionErr, "Multiple solutions of %s found" % task + raise moe.SolutionError, "Multiple solutions of %s found" % task ext = found[0] file = base + "." + ext @@ -52,8 +52,8 @@ def locate(e, filename=None): norm_ext = normalize_ext(e, ext) e.log.verbose("Found solution %s\n" % orig_path) - copy = e.cfgs["TASK"] + "." + norm_ext - copy_path = os.path.join(e.cfgs["TDIR"], copy) + copy = e["TASK"] + "." + norm_ext + copy_path = os.path.join(e["TDIR"], copy) if file != copy: e.log.verbose("Renaming to %s\n" % copy) moe.util.link_or_copy(orig_path, copy_path) @@ -63,15 +63,16 @@ def locate(e, filename=None): e.cfgs.apply_overrides("EXT_" + norm_ext + "_") e.stat["source"] = file + e.stat["lang"] = ext e.log.progress(file + "\n") 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(): + pdir = e["PDIR"] + tdir = e["TDIR"] + shutil.copyfile(os.path.join(tdir, e["SRC"]), os.path.join(boxdir, e["SRC"])) + for x in e["EXTRAS"].split() + e["COMP_EXTRAS"].split(): xx = os.path.join(tdir, x) if not os.path.isfile(xx): xx = os.path.join(pdir, x) @@ -80,59 +81,64 @@ def compile_init(e): def compile_run(e): moe.box.show(e, "compiler input") - cc = e.cfgs["COMP"] + cc = e["COMP"] e.log.verbose("Compilation command: %s\n" % cc) - rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], cc) + rc = moe.box.run(e, e["COMP_SANDBOX_OPTS"], cc) if rc > 0: e.log.progress("FAILED\n") - ## FIXME: status file + ## FIXME: status file ... or generate an exception? 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"])) + shutil.copyfile(os.path.join(e["BOXDIR"], e["EXE"]), os.path.join(e["TDIR"], e["EXE"])) except IOError: - raise moe.MoeErr, "Compiler succeeded, but produced no output" + raise moe.MoeError, "Compiler succeeded, but produced no output" e.log.progress("OK\n") def test_in(e): - tdir = e.cfgs["TDIR"] + tdir = e["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) + inn = e["TESTCASE_IN"] + in_type = e["IN_TYPE"] or e["IO_TYPE"] + out_type = e["OUT_TYPE"] or e["IO_TYPE"] + is_interactive = e["TASK_TYPE"] == "interactive" + sandbox_opts = "-M" + os.path.join(tdir, e["TESTCASE_STATUS"]) + + if not os.path.exists(os.path.join(tdir, e["EXE"])): + raise TestError("Compilation failed", "CE") + shutil.copyfile(os.path.join(tdir, e["EXE"]), os.path.join(boxdir, e["EXE"])) + os.chmod(os.path.join(boxdir, e["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)) + in_name = e["IN_NAME"] + e.log.verbose("Input file: %s (copied from %s)\n" % (in_name, os.path.join(e["PDIR"], inn))) + try: + shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name)) + except IOError: + raise moe.MoeError, "Input file not found" if not is_interactive: - sandbox_opts = " -i/dev/null" + 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" + e.log.verbose("Input file: (copied from %s)\n" % os.path.join(e["PDIR"], inn)) + try: + shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin")) + except IOError: + raise moe.MoeError, "Input file not found" + 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" + raise MoeError, "Directory input not yet implemented" else: - raise MoeErr, "Unknown input type %s" % in_type + raise MoeError, "Unknown input type %s" % in_type if out_type == "file": - out_name = e.cfgs["OUT_NAME"] + out_name = e["OUT_NAME"] e.log.verbose("Output file: %s\n" % out_name) if not is_interactive: sandbox_opts += " -o/dev/null" @@ -144,33 +150,34 @@ def test_in(e): if not is_interactive: sandbox_opts += " -o/dev/null" else: - raise MoeErr, "Unknown output type %s" % out_type + raise MoeError, "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"]) + e.log.verbose("Time limit: %s s\n" % e["TIME_LIMIT"]) + e.log.verbose("Memory limit: %s KB\n" % e["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"]) + rc = moe.box.run(e, e["TEST_SANDBOX_OPTS"], e["TEST_EXEC_CMD"]) + moe.testcase.collect_status(e) moe.box.show(e, "test output") - ## FIXME: Parse the status file and delete it - ### Check for runtime errors reported by the box + if rc > 0: + raise moe.TestError("Wrong answer", "WA") 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" + tdir = e["TDIR"] + boxdir = e["BOXDIR"] + out_type = e["OUT_TYPE"] or e["IO_TYPE"] + is_interactive = e["TASK_TYPE"] == "interactive" if out_type == "file": - out_path = e.cfgs["OUT_NAME"] + out_path = e["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"])) + raise moe.TestError("No output file", "NO") + shutil.copyfile(os.path.join(boxdir, out_path), os.path.join(tdir, e["TESTCASE_OUT"])) def tests(e): e.log.progress("\n")