Skip to content

Commit

Permalink
Support TimeLimitExceeded verdict
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Mar 10, 2024
1 parent 7449202 commit 54e90f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions judge-core/src/judge/result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde_derive::Serialize;

use crate::run::sandbox::RawRunResultInfo;
use core::time;
use std::{fmt, ops::Add, time::Duration};

use super::JudgeConfig;
Expand Down Expand Up @@ -44,10 +45,19 @@ pub fn get_max_mem(raw_info: &RawRunResultInfo) -> i64 {
}

pub fn check_user_result(
_config: &JudgeConfig,
config: &JudgeConfig,
raw_info: &RawRunResultInfo,
) -> Option<JudgeVerdict> {
// TODO: If run_time exceeds the time limit, return TimeLimitExceeded
if let Some(time_limit) = config.runtime.rlimit_configs.get_cpu_limit_duration() {
let run_time = get_run_time(raw_info);
// run_time is a little bit shorter than time_limit
if run_time + time::Duration::from_secs_f32(0.02) > time_limit {
log::debug!("User program run time: {:?}", run_time);
log::debug!("Time limit: {:?}", time_limit);
return Some(JudgeVerdict::TimeLimitExceeded);
}
}

let exit_status = raw_info.exit_status;
log::debug!("User program exit status: {}", exit_status);
match exit_status {
Expand Down
4 changes: 4 additions & 0 deletions judge-core/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ impl RlimitConfigs {
}
Ok(())
}

pub fn get_cpu_limit_duration(&self) -> Option<std::time::Duration> {
self.cpu_limit.map(|(soft, _)| std::time::Duration::from_secs(soft))
}
}

0 comments on commit 54e90f9

Please sign in to comment.