From 36a4be5ac99616d8dbe1f1e899796f8cefafb6ad Mon Sep 17 00:00:00 2001 From: Chanhee Lee Date: Sat, 13 Apr 2024 20:34:47 -0700 Subject: [PATCH] Fix a negative value acceptance as the number of federates - Negative values should cause error returns. - Unreachable code detected by unit test cases is deleted. Signed-off-by: Chanhee Lee --- rust/rti/run_unit_tests.sh | 1 + rust/rti/src/lib.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rust/rti/run_unit_tests.sh b/rust/rti/run_unit_tests.sh index ff6a829..c5c14ab 100755 --- a/rust/rti/run_unit_tests.sh +++ b/rust/rti/run_unit_tests.sh @@ -11,6 +11,7 @@ # 1. grcov <== cargo install grcov # 2. llvm-tools-preview <== rustup component add llvm-tools-preview +rm -rf ./target/coverage rm -rf cargo-test-* CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test diff --git a/rust/rti/src/lib.rs b/rust/rti/src/lib.rs index 44f41b9..8960ace 100644 --- a/rust/rti/src/lib.rs +++ b/rust/rti/src/lib.rs @@ -71,7 +71,7 @@ pub fn process_args(rti: &mut RTIRemote, argv: &[String]) -> Result<(), &'static let num_federates: i64; match argv[idx].parse::() { Ok(parsed_value) => { - if parsed_value == 0 || parsed_value == i64::MAX || parsed_value == i64::MIN { + if parsed_value <= 0 || parsed_value == i64::MAX || parsed_value == i64::MIN { println!("--number_of_federates needs a valid positive integer argument."); usage(argc, argv); return Err("Fail to handle number_of_federates option"); @@ -135,11 +135,6 @@ pub fn process_args(rti: &mut RTIRemote, argv: &[String]) -> Result<(), &'static } idx += 1; } - if rti.base().number_of_scheduling_nodes() == 0 { - println!("--number_of_federates needs a valid positive integer argument."); - usage(argc, argv); - return Err("Invalid number of enclaves"); - } Ok(()) } @@ -336,6 +331,16 @@ mod tests { assert!(process_args(&mut rti, &args) == Err("Fail to handle number_of_federates option")); } + #[test] + fn test_process_args_option_n_negative_value_negative() { + let mut rti = initialize_rti(); + let mut args: Vec = Vec::new(); + args.push(String::from("target/debug/rti")); + args.push(String::from("-n")); + args.push(String::from("-1")); + assert!(process_args(&mut rti, &args) == Err("Fail to handle number_of_federates option")); + } + #[test] fn test_process_args_option_n_zero_value_negative() { let mut rti = initialize_rti();