This commit is contained in:
MeiK 2020-04-24 19:01:12 +08:00
parent 8fd9bdf1b0
commit 11316c2bd5
4 changed files with 101 additions and 8 deletions

View File

@ -1,5 +1,7 @@
use super::config;
use super::error::{Error, Result};
use super::result::TestCaseResult;
use std::fmt;
use std::fs;
use std::io;
use std::path::Path;
@ -14,13 +16,23 @@ pub struct TestCase {
pub result: Option<TestCaseResult>,
}
#[derive(Debug)]
pub enum TestCaseResult {
Accepted,
CompileError(String),
WrongAnswer,
RuntimeError(String),
SystemError(String),
impl fmt::Display for TestCase {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let result = match &self.result {
Some(res) => res.to_string(),
None => "None".to_string()
};
write!(
f,
"input_file: {}
answer_file: {}
time_limit: {}
memory_limit: {}
result: {:?}
",
self.input_file, self.answer_file, self.cpu_time_limit, self.memory_limit, result
)
}
}
pub enum JudgeType {

View File

@ -3,6 +3,8 @@ use std::env;
mod config;
mod error;
mod judger;
mod process;
mod result;
fn main() {
let args: Vec<String> = env::args().collect();
@ -21,7 +23,7 @@ fn main() {
let language = config.language_config_from_name("python");
println!("{}", language.unwrap());
let judge_config = match judger::JudgeConfig::load(&config, "example") {
let mut judge_config = match judger::JudgeConfig::load(&config, "example") {
Ok(value) => value,
Err(err) => {
eprintln!("{}", err);
@ -29,4 +31,6 @@ fn main() {
}
};
println!("{}", judge_config.code.language);
process::run(&mut judge_config);
}

55
src/process.rs Normal file
View File

@ -0,0 +1,55 @@
extern crate libc;
use std::ptr;
use super::judger::{JudgeConfig};
use super::result::{ResourceUsed, TestCaseResult};
pub struct ExecArgs {
pub pathname: *const libc::c_char,
pub argv: *const *const libc::c_char,
pub envp: *const *const libc::c_char,
}
impl ExecArgs {
// TODO: 从配置文件中生成
}
impl Drop for ExecArgs {
fn drop(&mut self) {
println!("Dropping!");
}
}
pub fn run(judge_config: &mut JudgeConfig) {
let resource = ResourceUsed {
time_used: 1024,
memory_used: 65535,
};
for test_case in &mut judge_config.tests {
let _exec_args = ExecArgs {
pathname: ptr::null(),
argv: ptr::null(),
envp: ptr::null()
};
run_one();
test_case.result = Some(TestCaseResult::CompileError(
resource,
"Compile Error!".to_string(),
));
test_case.result = Some(TestCaseResult::WrongAnswer(resource));
test_case.result = Some(TestCaseResult::RuntimeError(
resource,
"Runtime Error!".to_string(),
));
test_case.result = Some(TestCaseResult::SystemError(
resource,
"System Error!".to_string(),
));
test_case.result = Some(TestCaseResult::Accepted(resource));
println!("{}", test_case);
}
}
pub fn run_one() {
println!("Hello World!");
}

22
src/result.rs Normal file
View File

@ -0,0 +1,22 @@
use std::fmt;
#[derive(Debug, Copy, Clone)]
pub struct ResourceUsed {
pub time_used: u32,
pub memory_used: u32,
}
#[derive(Debug)]
pub enum TestCaseResult {
Accepted(ResourceUsed),
CompileError(ResourceUsed, String),
WrongAnswer(ResourceUsed),
RuntimeError(ResourceUsed, String),
SystemError(ResourceUsed, String),
}
impl fmt::Display for TestCaseResult {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}