From 49087fa55c12b488c147d0002ac9cf675565bcfd Mon Sep 17 00:00:00 2001 From: Eason <30045503+Eason0729@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:57:35 +0800 Subject: [PATCH] fix(Judger): :bug: change return code form 1 to 0 --- judger/justfile | 1 - judger/plugins/c-11/compile.c | 3 ++- judger/plugins/cpp-11/compile.c | 3 ++- judger/plugins/rlua-54/src/main.rs | 6 +++++- judger/src/init/config.rs | 3 +++ judger/src/init/mod.rs | 2 ++ judger/src/init/volumn.rs | 12 ++++++++++++ judger/src/langs/artifact.rs | 2 +- judger/src/main.rs | 3 ++- judger/src/{test => tests}/grpc.rs | 0 judger/src/{test => tests}/langs.rs | 4 ++++ judger/src/{test => tests}/mod.rs | 3 --- judger/src/{test => tests}/sandbox.rs | 0 frontend/rust-toolchain.toml => rust-toolchain.toml | 0 14 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 judger/src/init/volumn.rs rename judger/src/{test => tests}/grpc.rs (100%) rename judger/src/{test => tests}/langs.rs (92%) rename judger/src/{test => tests}/mod.rs (54%) rename judger/src/{test => tests}/sandbox.rs (100%) rename frontend/rust-toolchain.toml => rust-toolchain.toml (100%) diff --git a/judger/justfile b/judger/justfile index f2c3c941..ef0b113c 100644 --- a/judger/justfile +++ b/judger/justfile @@ -33,7 +33,6 @@ test: run: sudo rm -rf .temp/* - mkdir -p .temp cargo run ci-test: diff --git a/judger/plugins/c-11/compile.c b/judger/plugins/c-11/compile.c index cae07cda..43f2085d 100644 --- a/judger/plugins/c-11/compile.c +++ b/judger/plugins/c-11/compile.c @@ -9,6 +9,7 @@ if (e == x) \ { \ printf("4: %m\n", errno); \ + fflush(stdout); \ return 1; \ } \ } @@ -39,5 +40,5 @@ int main() handle(wait(NULL),-1); printf("0: success!\n"); - return 1; + return 0; } \ No newline at end of file diff --git a/judger/plugins/cpp-11/compile.c b/judger/plugins/cpp-11/compile.c index cad6d2cc..dabe1dfe 100644 --- a/judger/plugins/cpp-11/compile.c +++ b/judger/plugins/cpp-11/compile.c @@ -9,6 +9,7 @@ if (e == x) \ { \ printf("4: %m\n", errno); \ + fflush(stdout); \ return 1; \ } \ } @@ -39,5 +40,5 @@ int main() handle(wait(NULL),-1); printf("0: success!\n"); - return 1; + return 0; } \ No newline at end of file diff --git a/judger/plugins/rlua-54/src/main.rs b/judger/plugins/rlua-54/src/main.rs index 18394ba7..a8ab3f5d 100644 --- a/judger/plugins/rlua-54/src/main.rs +++ b/judger/plugins/rlua-54/src/main.rs @@ -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 = std::env::args().collect(); let cmd=args.get(1).unwrap().as_str(); @@ -22,4 +24,6 @@ fn main() { "hello" => println!("hello world"), _ => println!("4: Invalid command: \"{}\"", cmd), }; + + ExitCode::from(0) } diff --git a/judger/src/init/config.rs b/judger/src/init/config.rs index 7f2b6dc5..c2a0390e 100644 --- a/judger/src/init/config.rs +++ b/judger/src/init/config.rs @@ -6,6 +6,7 @@ use tokio::{fs, io::AsyncReadExt, sync::OnceCell}; pub static CONFIG: OnceCell = OnceCell::const_new(); static CONFIG_PATH: &str = "config/config.toml"; +static CONFIG_DIR: &str = "config"; // config #[derive(Serialize, Deserialize, Debug)] @@ -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(); diff --git a/judger/src/init/mod.rs b/judger/src/init/mod.rs index 0599746e..176c8c04 100644 --- a/judger/src/init/mod.rs +++ b/judger/src/init/mod.rs @@ -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)] diff --git a/judger/src/init/volumn.rs b/judger/src/init/volumn.rs new file mode 100644 index 00000000..aae2bc6d --- /dev/null +++ b/judger/src/init/volumn.rs @@ -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(); +} \ No newline at end of file diff --git a/judger/src/langs/artifact.rs b/judger/src/langs/artifact.rs index ddb72b5e..5a79f335 100644 --- a/judger/src/langs/artifact.rs +++ b/judger/src/langs/artifact.rs @@ -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)); } diff --git a/judger/src/main.rs b/judger/src/main.rs index 7922e903..17fc3614 100644 --- a/judger/src/main.rs +++ b/judger/src/main.rs @@ -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() { diff --git a/judger/src/test/grpc.rs b/judger/src/tests/grpc.rs similarity index 100% rename from judger/src/test/grpc.rs rename to judger/src/tests/grpc.rs diff --git a/judger/src/test/langs.rs b/judger/src/tests/langs.rs similarity index 92% rename from judger/src/test/langs.rs rename to judger/src/tests/langs.rs index ae23e3cf..5f3dc1bc 100644 --- a/judger/src/test/langs.rs +++ b/judger/src/tests/langs.rs @@ -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] diff --git a/judger/src/test/mod.rs b/judger/src/tests/mod.rs similarity index 54% rename from judger/src/test/mod.rs rename to judger/src/tests/mod.rs index da4165be..0e581df6 100644 --- a/judger/src/test/mod.rs +++ b/judger/src/tests/mod.rs @@ -1,6 +1,3 @@ -#[cfg(test)] pub mod grpc; -#[cfg(test)] pub mod langs; -#[cfg(test)] pub mod sandbox; diff --git a/judger/src/test/sandbox.rs b/judger/src/tests/sandbox.rs similarity index 100% rename from judger/src/test/sandbox.rs rename to judger/src/tests/sandbox.rs diff --git a/frontend/rust-toolchain.toml b/rust-toolchain.toml similarity index 100% rename from frontend/rust-toolchain.toml rename to rust-toolchain.toml