12 def normalize_ext(e, ext):
13 alias = e["ALIAS_EXT_" + ext]
14 return alias if alias != "" else ext
17 for e in e["EXTENSIONS"].split():
20 raise moe.MoeError, "Unknown extension: " + ext
22 def locate(e, filename=None):
23 e.log.progress("Locating source... ")
29 dir, file = os.path.split(filename)
33 base, ext = os.path.splitext(file)
35 if not os.path.exists(os.path.join(dir, file)):
36 raise moe.SolutionError, "No solution of %s called %s found" % (task,file)
41 for ext in e["EXTENSIONS"].split():
42 if os.path.exists(os.path.join(dir, base + "." + ext)):
45 raise moe.SolutionError, "No solution of %s found" % task
47 raise moe.SolutionError, "Multiple solutions of %s found" % task
49 file = base + "." + ext
51 orig_path = os.path.join(dir, file)
52 norm_ext = normalize_ext(e, ext)
53 e.log.verbose("Found solution %s\n" % orig_path)
55 copy = e["TASK"] + "." + norm_ext
56 copy_path = os.path.join(e["TDIR"], copy)
58 e.log.verbose("Renaming to %s\n" % copy)
59 moe.util.link_or_copy(orig_path, copy_path)
61 e.builtins.set("SRC", copy)
62 e.builtins.set("EXT", norm_ext)
63 e.cfgs.apply_overrides("EXT_" + norm_ext + "_")
65 e.stat["source"] = file
67 e.log.progress(file + "\n")
70 e.log.progress("Compiling... ")
71 boxdir = moe.box.setup(e)
74 shutil.copyfile(os.path.join(tdir, e["SRC"]), os.path.join(boxdir, e["SRC"]))
75 for x in e["EXTRAS"].split() + e["COMP_EXTRAS"].split():
76 xx = os.path.join(tdir, x)
77 if not os.path.isfile(xx):
78 xx = os.path.join(pdir, x)
79 e.log.verbose("Copying extra file %s\n" % xx)
80 shutil.copyfile(xx, os.path.join(boxdir, x))
83 moe.box.show(e, "compiler input")
85 e.log.verbose("Compilation command: %s\n" % cc)
86 rc = moe.box.run(e, e["COMP_SANDBOX_OPTS"], cc)
88 e.log.progress("FAILED\n")
89 ## FIXME: status file ... or generate an exception?
90 raise moe.pipeline.MoeAbortPipeline(200)
91 moe.box.show(e, "compiler output")
95 shutil.copyfile(os.path.join(e["BOXDIR"], e["EXE"]), os.path.join(e["TDIR"], e["EXE"]))
97 raise moe.MoeError, "Compiler succeeded, but produced no output"
98 e.log.progress("OK\n")
102 boxdir = moe.box.setup(e)
103 inn = e["TESTCASE_IN"]
104 in_type = e["IN_TYPE"] or e["IO_TYPE"]
105 out_type = e["OUT_TYPE"] or e["IO_TYPE"]
106 is_interactive = e["TASK_TYPE"] == "interactive"
107 sandbox_opts = "-M" + os.path.join(tdir, e["TESTCASE_STATUS"])
109 if not os.path.exists(os.path.join(tdir, e["EXE"])):
110 raise TestError("Compilation failed", "CE")
111 shutil.copyfile(os.path.join(tdir, e["EXE"]), os.path.join(boxdir, e["EXE"]))
112 os.chmod(os.path.join(boxdir, e["EXE"]), 0555)
114 if in_type == "file":
115 in_name = e["IN_NAME"]
116 e.log.verbose("Input file: %s (copied from %s)\n" % (in_name, os.path.join(e["PDIR"], inn)))
117 shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name))
118 if not is_interactive:
119 sandbox_opts += " -i/dev/null"
120 elif in_type == "stdio":
121 e.log.verbose("Input file: <stdin> (copied from %s)\n" % os.path.join(e["PDIR"], inn))
122 shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin"))
123 sandbox_opts += " -i.stdin"
124 elif in_type == "none":
125 e.log.verbose("Input file: <none>\n")
126 if not is_interactive:
127 sandbox_opts += " -i/dev/null"
128 elif in_type == "dir":
130 raise MoeError, "Directory input not yet implemented"
132 raise MoeError, "Unknown input type %s" % in_type
134 if out_type == "file":
135 out_name = e["OUT_NAME"]
136 e.log.verbose("Output file: %s\n" % out_name)
137 if not is_interactive:
138 sandbox_opts += " -o/dev/null"
139 elif out_type == "stdio":
140 e.log.verbose("Output file: <stdout>\n")
141 sandbox_opts += " -o.stdout"
142 elif out_type == "none":
143 e.log.verbose("Output file: <none>\n")
144 if not is_interactive:
145 sandbox_opts += " -o/dev/null"
147 raise MoeError, "Unknown output type %s" % out_type
149 e.test_builtins.set("BOX_IO_OPTS", sandbox_opts)
152 e.log.verbose("Time limit: %s s\n" % e["TIME_LIMIT"])
153 e.log.verbose("Memory limit: %s KB\n" % e["MEM_LIMIT"])
154 moe.box.show(e, "test input")
155 e.log.progress("<run> ")
156 rc = moe.box.run(e, e["TEST_SANDBOX_OPTS"], e["TEST_EXEC_CMD"])
157 moe.testcase.collect_status(e)
158 moe.box.show(e, "test output")
160 raise moe.TestError("Wrong answer", "WA")
165 out_type = e["OUT_TYPE"] or e["IO_TYPE"]
166 is_interactive = e["TASK_TYPE"] == "interactive"
168 if out_type == "file":
169 out_path = e["OUT_NAME"]
170 elif out_type == "stdio":
172 if not os.path.exists(os.path.join(boxdir, out_path)):
173 raise moe.TestError("No output file", "NO")
174 shutil.copyfile(os.path.join(boxdir, out_path), os.path.join(tdir, e["TESTCASE_OUT"]))
178 e.test_pipe.insert(100, "prepare", test_in)
179 e.test_pipe.insert(200, "run", test_run)
180 e.test_pipe.insert(300, "collect", test_collect)
181 moe.testcase.run_tests(e)
184 e.main_pipe.insert(100, "compile-init", compile_init)
185 e.main_pipe.insert(150, "compile-run", compile_run)
186 e.main_pipe.insert(190, "compile-done", compile_done)
187 e.main_pipe.insert(200, "batch-tests", tests)