import moe.box
import moe.eval
import moe.util
+import moe.pipeline
+import moe.testcase
import shutil
def normalize_ext(e, ext):
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 != "":
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: ")
+ 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)
rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], cc)
if rc > 0:
e.log.progress("FAILED\n")
- ## FIXME: fill in the status file and abort the pipeline?
+ ## 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: <stdin> (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: <none>\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: <stdout>\n")
+ sandbox_opts += " -o.stdout"
+ elif out_type == "none":
+ e.log.verbose("Output file: <none>\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("<run> ")
+ 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)