Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a negative value acceptance as the number of federates #52

Merged
merged 1 commit into from
Apr 14, 2024
Merged
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
1 change: 1 addition & 0 deletions rust/rti/run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions rust/rti/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn process_args(rti: &mut RTIRemote, argv: &[String]) -> Result<(), &'static
let num_federates: i64;
match argv[idx].parse::<i64>() {
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");
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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<String> = 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();
Expand Down
Loading