Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ jobs:
- name: Setup 'gcc-12' as default
run: ./target/debug/quicktest setup config --label="Language::C.PROGRAM" --value="gcc-12"

- name: Test cmp command
run: cargo test cmp_subcommand -- --test-threads 1
# - name: Test cmp command
# run: cargo test cmp_subcommand -- --test-threads 1

- name: Test stress command
run: cargo test stress_subcommand -- --test-threads 1
# - name: Test stress command
# run: cargo test stress_subcommand -- --test-threads 1

- name: Test check command
run: cargo test check_subcommand -- --test-threads 1
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Ubuntu Workflow

on:
push:
branches:
- main
pull_request:
branches:
- '**'
types: [opened, synchronize, reopened]
# on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - '**'
# types: [opened, synchronize, reopened]

jobs:
build_and_test:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Windows Workflow

on:
push:
branches:
- main
pull_request:
branches:
- '**'
types: [opened, synchronize, reopened]
# on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - '**'
# types: [opened, synchronize, reopened]

jobs:
build_and_test:
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ async-std = "1.13.0"
futures = "0.3.31"
tokio = { version = "1.40.0", features = ["full"] }

[target.'cfg(target_os = "macos")'.dependencies]
libc = "0.2"

[dev-dependencies]
assert_cmd = "2.0.16"
predicates = "3.1.2"
Expand Down
48 changes: 44 additions & 4 deletions src/runner/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use rand::distributions::{Distribution, Uniform};

use super::types::{CPStatus, StatusResponse};

#[cfg(target_os = "macos")]
use std::os::unix::process::CommandExt;

#[allow(unused_variables)]
pub fn execute_program(
timeout: u32,
Expand All @@ -31,10 +34,8 @@ pub fn execute_program(

let mut cmd = Command::new(commands[0]);

#[cfg(any(target_os = "linux", target_os = "windows"))]
let mut memory_factor_needed = 1usize;

#[cfg(any(target_os = "linux", target_os = "windows"))]
if commands[0] == "java" {
memory_factor_needed *= 10usize;
}
Expand All @@ -58,10 +59,35 @@ pub fn execute_program(
cmd.args(&[die.sample(&mut rng).to_string(), testcase.to_string()]);
}

#[cfg(target_os = "macos")]
unsafe {
cmd.pre_exec(move || {
let limit = libc::rlimit {
rlim_cur: memory_limit * memory_factor_needed as u64,
rlim_max: memory_limit * memory_factor_needed as u64,
};

// Set both RLIMIT_AS and RLIMIT_DATA for better memory limit detection on macOS
if libc::setrlimit(libc::RLIMIT_AS, &limit) != 0 {
eprintln!("Warning: Failed to set RLIMIT_AS");
}

if libc::setrlimit(libc::RLIMIT_DATA, &limit) != 0 {
eprintln!("Warning: Failed to set RLIMIT_DATA");
}

Ok(())
});
}

let child: Result<std::process::Child, std::io::Error> =
cmd.stdout(Stdio::piped()).stderr(Stdio::piped()).spawn();

if child.is_err() {
eprintln!(
"[DEBUG SPAWN] Failed to spawn process: {:?}",
child.as_ref().err()
);
return execute_program_response(CPStatus::CE, now);
}

Expand All @@ -82,6 +108,8 @@ pub fn execute_program(
.terminate_for_timeout()
.wait();

eprintln!("[DEBUG RESPONSE] {:?}", response);

if response.is_err() {
return execute_program_response(CPStatus::TLE, now);
}
Expand All @@ -107,13 +135,25 @@ pub fn execute_program(
writer.write_all(&output.stderr).unwrap();
}
} else {
#[cfg(unix)]
eprintln!("[DEBUG SUCCESS] {:?}", output.status.success());
eprintln!("[DEBUG SIGNAL] {:?}", output.status.signal());
eprintln!("[DEBUG CODE] {:?}", output.status.code());

#[cfg(target_os = "macos")]
match output.status.signal() {
Some(6) => res_status = CPStatus::MLE, // SIGABRT: 6
Some(9) => res_status = CPStatus::MLE, // SIGKILL: 9 (memory limit exceeded on macOS)
Some(11) => res_status = CPStatus::RTE, // SIGSEGV: 11
_ => res_status = CPStatus::RTE,
}

#[cfg(target_os = "linux")]
match output.status.signal() {
Some(6) => res_status = CPStatus::MLE, // SIGABRT: 6
_ => res_status = CPStatus::RTE,
}

#[cfg(windows)]
#[cfg(target_os = "windows")]
match output.status.code() {
Some(3221226505) | Some(3) => res_status = CPStatus::MLE, // STATUS_HEAP_CORRUPTION: 3221226505, ERROR_PATH_NOT_FOUND: 3
Some(_) => res_status = CPStatus::RTE,
Expand Down
7 changes: 2 additions & 5 deletions tests/cli/check_subcommand/cpp_mle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::util::{
use super::codes::{CHECKER_CPP_CHECK, GEN_CPP_CHECK, TARGET_CPP_CHECK};

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_check_target_mle_cpp() -> Result<(), Box<dyn Error>> {
create_files_check(
TARGET_FILE_CPP,
Expand All @@ -42,7 +41,7 @@ fn cmd_check_target_mle_cpp() -> Result<(), Box<dyn Error>> {
CHECKER_FILE_CPP,
GEN_FILE_CPP,
cases,
5000usize,
10000usize,
);

cmd.assert()
Expand All @@ -53,7 +52,6 @@ fn cmd_check_target_mle_cpp() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_check_checker_mle_cpp() -> Result<(), Box<dyn Error>> {
create_files_check(
TARGET_FILE_CPP,
Expand All @@ -73,7 +71,7 @@ fn cmd_check_checker_mle_cpp() -> Result<(), Box<dyn Error>> {
CHECKER_FILE_CPP,
GEN_FILE_CPP,
cases,
5000usize,
10000usize,
);

cmd.assert().failure().stderr(predicate::str::contains(
Expand All @@ -84,7 +82,6 @@ fn cmd_check_checker_mle_cpp() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_check_gen_mle_cpp() -> Result<(), Box<dyn Error>> {
create_files_check(
TARGET_FILE_CPP,
Expand Down
3 changes: 0 additions & 3 deletions tests/cli/check_subcommand/cpp_rte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::util::{
use super::codes::{CHECKER_CPP_CHECK, GEN_CPP_CHECK, TARGET_CPP_CHECK};

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_check_target_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_check(
TARGET_FILE_CPP,
Expand Down Expand Up @@ -51,7 +50,6 @@ fn cmd_check_target_rte_cpp() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_check_checker_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_check(
TARGET_FILE_CPP,
Expand Down Expand Up @@ -81,7 +79,6 @@ fn cmd_check_checker_rte_cpp() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_check_gen_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_check(
TARGET_FILE_CPP,
Expand Down
4 changes: 1 addition & 3 deletions tests/cli/cmp_subcommand/c_rte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

// CHECK RTE in Subcommand cmp
#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_cmp_target_rte_c() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_C,
Expand Down Expand Up @@ -51,7 +50,6 @@
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_cmp_correct_rte_c() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_C,
Expand Down Expand Up @@ -82,7 +80,7 @@
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
#[cfg(not(target_os = ""))] // TODO: Fix this test when possible

Check warning on line 83 in tests/cli/cmp_subcommand/c_rte.rs

View workflow job for this annotation

GitHub Actions / MacOS Build and Run test

unexpected `cfg` condition value: ``
fn cmd_cmp_gen_rte_c() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_C,
Expand Down
5 changes: 2 additions & 3 deletions tests/cli/cmp_subcommand/cpp_rte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

// CHECK RTE in Subcommand cmp
#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_cmp_target_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_CPP,
Expand Down Expand Up @@ -52,7 +51,7 @@
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
#[cfg(not(target_os = ""))] // TODO: Fix this test when possible

Check warning on line 54 in tests/cli/cmp_subcommand/cpp_rte.rs

View workflow job for this annotation

GitHub Actions / MacOS Build and Run test

unexpected `cfg` condition value: ``
fn cmd_cmp_correct_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_CPP,
Expand Down Expand Up @@ -82,7 +81,7 @@
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
#[cfg(not(target_os = ""))] // TODO: Fix this test when possible

Check warning on line 84 in tests/cli/cmp_subcommand/cpp_rte.rs

View workflow job for this annotation

GitHub Actions / MacOS Build and Run test

unexpected `cfg` condition value: ``
fn cmd_cmp_gen_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_CPP,
Expand Down
1 change: 0 additions & 1 deletion tests/cli/cmp_subcommand/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::util::{
use super::codes::{CORRECT_RUST_CMP, GEN_RUST_CMP, TARGET_RUST_CMP};

#[test]
#[cfg(not(target_os = "macos"))]
fn cmp_target_cpp_correct_cpp_gen_rust() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_RUST,
Expand Down
2 changes: 0 additions & 2 deletions tests/cli/cmp_subcommand/rust_ce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ fn cmd_cmp_target_ce_rust() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_cmp_correct_ce_rust() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_RUST,
Expand Down Expand Up @@ -81,7 +80,6 @@ fn cmd_cmp_correct_ce_rust() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_cmp_gen_ce_rust() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_RUST,
Expand Down
2 changes: 0 additions & 2 deletions tests/cli/cmp_subcommand/rust_rte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use super::codes::{CORRECT_RUST_CMP, GEN_RUST_CMP, TARGET_RUST_CMP};

// CHECK RTE in Subcommand cmp
#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_cmp_target_rte_rust() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_RUST,
Expand Down Expand Up @@ -53,7 +52,6 @@ fn cmd_cmp_target_rte_rust() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_cmp_correct_rte_rust() -> Result<(), Box<dyn Error>> {
create_files_cmp(
TARGET_FILE_RUST,
Expand Down
2 changes: 0 additions & 2 deletions tests/cli/stress_subcommand/cpp_mle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::util::{
use super::codes::{GEN_CPP_STRESS, TARGET_CPP_STRESS};

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_stress_target_mle_cpp() -> Result<(), Box<dyn Error>> {
create_files_tle(
TARGET_FILE_CPP,
Expand All @@ -42,7 +41,6 @@ fn cmd_stress_target_mle_cpp() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))]
fn cmd_stress_gen_mle_cpp() -> Result<(), Box<dyn Error>> {
create_files_tle(
TARGET_FILE_CPP,
Expand Down
2 changes: 0 additions & 2 deletions tests/cli/stress_subcommand/cpp_rte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::util::{
use super::codes::{GEN_CPP_STRESS, TARGET_CPP_STRESS};

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_stress_target_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_tle(
TARGET_FILE_CPP,
Expand All @@ -41,7 +40,6 @@ fn cmd_stress_target_rte_cpp() -> Result<(), Box<dyn Error>> {
}

#[test]
#[cfg(not(target_os = "macos"))] // TODO: Fix this test when possible
fn cmd_stress_gen_rte_cpp() -> Result<(), Box<dyn Error>> {
create_files_tle(
TARGET_FILE_CPP,
Expand Down
1 change: 1 addition & 0 deletions tests/util/test_command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn execute_command_check_with_timeout(
.arg("--gen-file")
.arg(format!("{}/{}/{}", FOLDER, FOLDER_CHECK, gen_file))
.arg(format!("--timeout={}", timeout))
.arg(format!("--memory-limit={}", 2_147_483_648usize))
.arg(format!("--test-cases={}", cases));
}

Expand Down
1 change: 1 addition & 0 deletions tests/util/test_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ using namespace std;
int main() {
vector<long long> vec;
while(true) vec.push_back(1LL);
return 0;
}
"#;

Expand Down
Loading