Skip to content

Commit

Permalink
fix(Judger): 🐛 change return code form 1 to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Jan 28, 2024
1 parent 2a56ffa commit 49087fa
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 9 deletions.
1 change: 0 additions & 1 deletion judger/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ test:

run:
sudo rm -rf .temp/*
mkdir -p .temp
cargo run

ci-test:
Expand Down
3 changes: 2 additions & 1 deletion judger/plugins/c-11/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
if (e == x) \
{ \
printf("4: %m\n", errno); \
fflush(stdout); \
return 1; \
} \
}
Expand Down Expand Up @@ -39,5 +40,5 @@ int main()

handle(wait(NULL),-1);
printf("0: success!\n");
return 1;
return 0;
}
3 changes: 2 additions & 1 deletion judger/plugins/cpp-11/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
if (e == x) \
{ \
printf("4: %m\n", errno); \
fflush(stdout); \
return 1; \
} \
}
Expand Down Expand Up @@ -39,5 +40,5 @@ int main()

handle(wait(NULL),-1);
printf("0: success!\n");
return 1;
return 0;
}
6 changes: 5 additions & 1 deletion judger/plugins/rlua-54/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::process::ExitCode;

mod compile;
mod execute;
mod violate;
const LUA_SRC: &str = "/src/code.txt";

fn main() {
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().collect();

let cmd=args.get(1).unwrap().as_str();
Expand All @@ -22,4 +24,6 @@ fn main() {
"hello" => println!("hello world"),
_ => println!("4: Invalid command: \"{}\"", cmd),
};

ExitCode::from(0)
}
3 changes: 3 additions & 0 deletions judger/src/init/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tokio::{fs, io::AsyncReadExt, sync::OnceCell};
pub static CONFIG: OnceCell<GlobalConfig> = OnceCell::const_new();

static CONFIG_PATH: &str = "config/config.toml";
static CONFIG_DIR: &str = "config";

// config
#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -156,6 +157,8 @@ pub async fn init() {
}
Err(_) => {
println!("Unable to find {}, generating default config", CONFIG_PATH);

fs::create_dir_all(CONFIG_DIR).await.unwrap();

let config: GlobalConfig = toml::from_str("").unwrap();

Expand Down
2 changes: 2 additions & 0 deletions judger/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ pub mod cgroup;
pub mod check;
pub mod config;
pub mod logger;
pub mod volumn;

pub async fn new() {
config::init().await;
logger::init();
cgroup::init();
check::init();
volumn::init().await;
}

#[derive(Error, Debug)]
Expand Down
12 changes: 12 additions & 0 deletions judger/src/init/volumn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::path::Path;

use tokio::fs;

use super::config::CONFIG;


pub async fn init(){
let config=CONFIG.get().unwrap();
let path:&Path=config.runtime.temp.as_ref();
fs::create_dir_all(path).await.unwrap();
}
2 changes: 1 addition & 1 deletion judger/src/langs/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> CompiledArtifact<'a> {

// TODO: We should handle SysError here
if !process.succeed() {
// log::debug!("process status: {:?}", process.status);
log::debug!("process status: {:?}", process.status);
return Ok(TaskResult::Fail(JudgerCode::Re));
}

Expand Down
3 changes: 2 additions & 1 deletion judger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub mod init;
pub mod langs;
pub mod sandbox;
pub mod server;
pub mod test;
#[cfg(test)]
pub mod tests;

#[tokio::main]
async fn main() {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions judger/src/test/langs.rs → judger/src/tests/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ use crate::{grpc::prelude::JudgeMatchRule, init::config::CONFIG, langs::prelude:
async fn test_hello_world(factory: &mut ArtifactFactory, uuid: Uuid, code: &[u8]) {
let mut compiled = factory.compile(&uuid, code).await.unwrap();

assert!(compiled.get_expection().is_none());

let mut result = compiled
.judge(b"", 1000 * 1000, 1024 * 1024 * 128)
.await
.unwrap();

assert!(compiled.get_expection().is_none());

assert!(result.assert(b"hello world", JudgeMatchRule::SkipSnl));
}
#[tokio::test]
Expand Down
3 changes: 0 additions & 3 deletions judger/src/test/mod.rs → judger/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(test)]
pub mod grpc;
#[cfg(test)]
pub mod langs;
#[cfg(test)]
pub mod sandbox;
File renamed without changes.
File renamed without changes.

0 comments on commit 49087fa

Please sign in to comment.