Skip to content

Commit

Permalink
Merge pull request #52 from lf-lang/fix-main-argument
Browse files Browse the repository at this point in the history
Fix a negative value acceptance as the number of federates
  • Loading branch information
chanijjani authored Apr 14, 2024
2 parents f7f1936 + 36a4be5 commit 04029b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 04029b3

Please sign in to comment.