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)))
118 shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name))
120 raise moe.MoeError, "Input file not found"
121 if not is_interactive:
122 sandbox_opts += " -i/dev/null"
123 elif in_type == "stdio":
124 e.log.verbose("Input file: <stdin> (copied from %s)\n" % os.path.join(e["PDIR"], inn))
126 shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin"))
128 raise moe.MoeError, "Input file not found"
129 sandbox_opts += " -i.stdin"
130 elif in_type == "none":
131 e.log.verbose("Input file: <none>\n")
132 if not is_interactive:
133 sandbox_opts += " -i/dev/null"
134 elif in_type == "dir":
136 raise MoeError, "Directory input not yet implemented"
138 raise MoeError, "Unknown input type %s" % in_type
140 if out_type == "file":
141 out_name = e["OUT_NAME"]
142 e.log.verbose("Output file: %s\n" % out_name)
143 if not is_interactive:
144 sandbox_opts += " -o/dev/null"
145 elif out_type == "stdio":
146 e.log.verbose("Output file: <stdout>\n")
147 sandbox_opts += " -o.stdout"
148 elif out_type == "none":
149 e.log.verbose("Output file: <none>\n")
150 if not is_interactive:
151 sandbox_opts += " -o/dev/null"
153 raise MoeError, "Unknown output type %s" % out_type
155 e.test_builtins.set("BOX_IO_OPTS", sandbox_opts)
158 e.log.verbose("Time limit: %s s\n" % e["TIME_LIMIT"])
159 e.log.verbose("Memory limit: %s KB\n" % e["MEM_LIMIT"])
160 moe.box.show(e, "test input")
161 e.log.progress("<run> ")
162 rc = moe.box.run(e, e["TEST_SANDBOX_OPTS"], e["TEST_EXEC_CMD"])
163 moe.testcase.collect_status(e)
164 moe.box.show(e, "test output")
166 raise moe.TestError("Wrong answer", "WA")
171 out_type = e["OUT_TYPE"] or e["IO_TYPE"]
172 is_interactive = e["TASK_TYPE"] == "interactive"
174 if out_type == "file":
175 out_path = e["OUT_NAME"]
176 elif out_type == "stdio":
178 if not os.path.exists(os.path.join(boxdir, out_path)):
179 raise moe.TestError("No output file", "NO")
180 shutil.copyfile(os.path.join(boxdir, out_path), os.path.join(tdir, e["TESTCASE_OUT"]))
184 e.test_pipe.insert(100, "prepare", test_in)
185 e.test_pipe.insert(200, "run", test_run)
186 e.test_pipe.insert(300, "collect", test_collect)
187 moe.testcase.run_tests(e)
190 e.main_pipe.insert(100, "compile-init", compile_init)
191 e.main_pipe.insert(150, "compile-run", compile_run)
192 e.main_pipe.insert(190, "compile-done", compile_done)
193 e.main_pipe.insert(200, "batch-tests", tests)