function build_testset_outputs() { echo "\nNote: Testcase reference output does not exist or is out of date, generating it now.\n"; $this->create_output_dir(); if (($status = $this->prepare_and_compile()) != 0) { $msg = "Compiling failed with status " . Status::to_text($status) . "\n"; if (file_exists($this->output_dir . '/compiler.err')) { $msg .= file_get_contents($this->output_dir . '/compiler.err', 0, null, 0, 10000); } else { $msg .= "<no message>\n"; } file_put_contents($this->output_dir . "/buildresult", "Failed to build reference implementation."); Log::warning("Failed to build reference implementation.", $this->entity->path()); throw new Exception($msg); } // Now build all testcases foreach ($this->entity->testcases() as $case) { echo " case: " . $case . "\n"; if (!$this->run_case($case)) { $msg = "Runtime error for case {$case}.\n"; if (file_exists($this->output_dir . "/{$case}.err")) { $msg .= file_get_contents($this->output_dir . "/{$case}.err", 0, null, 0, 10000); } file_put_contents($this->output_dir . "/buildresult", "Failed to run reference implementation."); Log::warning("Failed to run reference implementation.", $this->entity->path()); throw new Exception($msg); } } // Done echo "Reference output generated successfully.\n\n"; file_put_contents($this->output_dir . "/buildresult", "Reference output generated successfully."); return true; }
function judge_a_single_submission() { // Clear all caches, otherwise we would use old data! Entity::clear_cache(); // Retrieve a submission global $self; $subm = Submission::get_pending_submission($self->name . micro_nonce()); if (!$subm) { // no submissions right now sleep(DAEMON_SLEEP_TIME); return; } // Some information on this submission if (VERBOSE) { echo "\n"; echo "Submission id: ", $subm->submissionid, "\n"; echo "Submission to: ", $subm->entity_path, "\n"; echo "Submited on: ", format_date($subm->time), "\n"; echo "Submission by: ", User::names_text($subm->users()), "\n"; // this slows things down } // Let's judge it try { $judgement = new SubmissionJudgement($subm); $judgement->judge(); } catch (Exception $e) { Log::error($e, $subm->entity_path, $self->name); echo "Error during judging!\n", $e; } if (VERBOSE) { echo "Result: ", Status::to_text($subm), "\n"; } // free up some memory unset($judgement); unset($subm); if (function_exists('gc_collect_cycles')) { // this doesn't exist in PHP < 5.3.0 :( gc_collect_cycles(); } if (VERBOSE) { echo "Memory usage: ", memory_get_usage(), "\n"; } }
function write_print_submission($subm) { // include this submission? if (!isset($_REQUEST['include_failed'])) { if (!Status::is_passed($subm->status) and !$subm->status == Status::MISSED_DEADLINE) { return; } } // does it match a user filter? if (@$_REQUEST['user_filter'] != '') { $match = stripos(User::names_text($subm->users()), $_REQUEST['user_filter']); if ($match === false) { return; } } // submission header echo '<div class="submission">'; echo '<div class="submission-head">'; echo "<table><tr><td>Submission</td><td>#" . $subm->submissionid . " for <tt>" . htmlspecialchars($subm->entity_path) . "</tt></td></tr>"; echo "<tr><td>by</td><td>" . User::names_html($subm->users()) . "</td></tr>"; echo "<tr><td>on</td><td>" . format_date($subm->time) . "</td></tr>"; if (!Status::is_passed($subm->status)) { echo "<tr><td>status</td><td><strong>" . strtoupper(Status::to_text($subm)) . "</strong></td></tr>"; } echo "</table>"; echo "</div>\n"; if ($subm->is_archived()) { // file header echo "<div class=\"file\">"; echo '<div class="file-head">'; echo 'This submission has been archived'; echo '</div></div>'; } else { // submission files foreach ($subm->get_code_filenames() as $code_name => $filename) { $this->write_print_file($filename, $subm->get_file($code_name)); } } echo "</div>\n"; }
function write_print_submission($subm) { // include this submission? if (!isset($_REQUEST['include_failed'])) { if (!Status::is_passed($subm->status)) { return; } } // does it match a user filter? if (@$_REQUEST['user_filter'] != '') { $match = stripos(User::names_text($subm->users()), $_REQUEST['user_filter']); if ($match === false) { return; } } // submission header echo "\\section*{Submission \\#" . $subm->submissionid . " for " . htmlspecialchars($subm->entity_path) . "}\n"; echo "by " . User::names_html($subm->users()) . ", "; echo "on " . format_date($subm->time) . "\n\n"; if (!Status::is_passed($subm->status)) { echo "(status " . Status::to_text($subm) . ")"; } // submission files foreach ($subm->get_code_filenames() as $code_name => $filename) { $this->write_print_file($filename, $subm->get_file($code_name)); } echo "\\cleardoublepage\n"; }