From e588360079ed31a880422e578fa96876dd5d4d65 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 04:05:08 +0000 Subject: [PATCH 1/6] build(deps): bump rust-vmm-ci from `ae7db2d` to `7f22582` Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `ae7db2d` to `7f22582`. - [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases) - [Commits](https://github.com/rust-vmm/rust-vmm-ci/compare/ae7db2d98a071f52de3d60af9c937204b1f087a4...7f22582590b5816878e7f3f860766979cab297a0) --- updated-dependencies: - dependency-name: rust-vmm-ci dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- rust-vmm-ci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-vmm-ci b/rust-vmm-ci index ae7db2d..7f22582 160000 --- a/rust-vmm-ci +++ b/rust-vmm-ci @@ -1 +1 @@ -Subproject commit ae7db2d98a071f52de3d60af9c937204b1f087a4 +Subproject commit 7f22582590b5816878e7f3f860766979cab297a0 From 726a056254ac882d364c4ff4ae3c1647c5b45008 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 7 Oct 2021 16:43:12 +0530 Subject: [PATCH 2/6] [i2c] Cleanup tests around socket_count argument The socket count argument is optional and defaults to 1, but the tests written for it were more C like and weren't so clean. Use Option to improve upon that. While at it, fix socket names as well. Socket name is name of a socket and shouldn't be used as test-name. Fix the TODOs as well. Signed-off-by: Viresh Kumar --- src/i2c/src/main.rs | 55 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/i2c/src/main.rs b/src/i2c/src/main.rs index b5d1bf7..fd0eb59 100644 --- a/src/i2c/src/main.rs +++ b/src/i2c/src/main.rs @@ -97,7 +97,7 @@ impl TryFrom<&str> for AdapterConfig { for device_str in list[1..].iter() { let addr = device_str .parse::() - .map_err(|_| "Invalid device addr: {}")?; + .map_err(|_| "Invalid device addr")?; adapter.push(addr)?; } @@ -226,41 +226,48 @@ mod tests { } } - fn get_cmd_args(name: &str, devices: &str, count: u32) -> ArgMatches { + fn get_cmd_args(name: &str, devices: &str, count: Option) -> ArgMatches { + let mut args = vec!["prog", "-s", name, "-l", devices]; let yaml = load_yaml!("cli.yaml"); let app = App::from(yaml); + let socket_count_str; - if count != 0 { - app.try_get_matches_from(vec![ - "prog", - "-s", - name, - "-l", - devices, - "-c", - &count.to_string(), - ]) - .unwrap() - } else { - app.try_get_matches_from(vec!["prog", "-s", name, "-l", devices]) - .unwrap() + if let Some(count) = count { + socket_count_str = count.to_string(); + args.extend_from_slice(&["-c", &socket_count_str]); } + app.try_get_matches_from(args).unwrap() } #[test] fn test_parse_failure() { - let cmd_args = get_cmd_args("vi2c.sock_failure", "1:4d", 5); - // TODO: Check against the actual error instead of `is_err`. - assert!(I2cConfiguration::try_from(cmd_args).is_err()); + let socket_name = "vi2c.sock"; - let cmd_args = get_cmd_args("vi2c.sock_duplicate", "1:4,2:32:21,5:4:23", 5); - // TODO: Check against the actual error instead of `is_err`. - assert!(I2cConfiguration::try_from(cmd_args).is_err()); + // Invalid device list + let cmd_args = get_cmd_args(socket_name, "1:4d", Some(5)); + assert_eq!( + I2cConfiguration::try_from(cmd_args).unwrap_err(), + "Invalid device addr" + ); + + // Duplicate client address: 4 + let cmd_args = get_cmd_args(socket_name, "1:4,2:32:21,5:4:23", Some(5)); + assert_eq!( + I2cConfiguration::try_from(cmd_args).unwrap_err(), + "Address already in use: 4" + ); } #[test] fn test_parse_successful() { - let cmd_args = get_cmd_args("vi2c.sock_single", "1:4,2:32:21,5:5:23", 5); + let socket_name = "vi2c.sock"; + + // Missing socket count, default (1) should be used. + let cmd_args = get_cmd_args(socket_name, "1:4,2:32:21,5:5:23", None); + let config = I2cConfiguration::try_from(cmd_args).unwrap(); + assert_eq!(config.socket_count, 1); + + let cmd_args = get_cmd_args(socket_name, "1:4,2:32:21,5:5:23", Some(5)); let config = I2cConfiguration::try_from(cmd_args).unwrap(); let expected_devices = AdapterConfig::new_with(vec![ @@ -271,7 +278,7 @@ mod tests { let expected_config = I2cConfiguration { socket_count: 5, - socket_path: String::from("vi2c.sock_single"), + socket_path: String::from(socket_name), devices: expected_devices, }; From 5cf0b83820c398465e8dae1edefc65881b5bceb7 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 7 Oct 2021 15:35:50 +0530 Subject: [PATCH 3/6] [i2c] Socket count should be greater than 0 Fail early if socket_count is set to 0. Signed-off-by: Viresh Kumar --- src/i2c/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/i2c/src/main.rs b/src/i2c/src/main.rs index fd0eb59..768e4a0 100644 --- a/src/i2c/src/main.rs +++ b/src/i2c/src/main.rs @@ -129,6 +129,10 @@ impl TryFrom for I2cConfiguration { .parse::() .map_err(|_| "Invalid socket_count")?; + if socket_count == 0 { + return Err("Socket count can't be 0".to_string()); + } + let list = cmd_args.value_of("devices").ok_or("Invalid devices list")?; let devices = AdapterConfig::try_from(list)?; Ok(I2cConfiguration { @@ -250,6 +254,13 @@ mod tests { "Invalid device addr" ); + // Invalid socket count + let cmd_args = get_cmd_args(socket_name, "1:4", Some(0)); + assert_eq!( + I2cConfiguration::try_from(cmd_args).unwrap_err(), + "Socket count can't be 0" + ); + // Duplicate client address: 4 let cmd_args = get_cmd_args(socket_name, "1:4,2:32:21,5:4:23", Some(5)); assert_eq!( From 8028571d0ade367bbfdff27b31fd45a7580576e1 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 7 Oct 2021 16:51:57 +0530 Subject: [PATCH 4/6] [i2c] Update coverage score Signed-off-by: Viresh Kumar --- coverage_config_x86_64.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index d8b86b0..ff7665f 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1,5 +1,5 @@ { - "coverage_score": 49.4, + "coverage_score": 49.6, "exclude_path": "", "crate_features": "" } From 3e9efe05cd385d993a06bf46d5edeae6ac6f85ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Oct 2021 04:06:19 +0000 Subject: [PATCH 5/6] build(deps): bump libc from 0.2.102 to 0.2.103 Bumps [libc](https://github.com/rust-lang/libc) from 0.2.102 to 0.2.103. - [Release notes](https://github.com/rust-lang/libc/releases) - [Commits](https://github.com/rust-lang/libc/compare/0.2.102...0.2.103) --- updated-dependencies: - dependency-name: libc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9242376..12e4528 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,9 +120,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.102" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" [[package]] name = "linked-hash-map" From 1f9fdcc1a112afee666992c7954b55b496bf5c9c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Oct 2021 04:06:25 +0000 Subject: [PATCH 6/6] build(deps): bump syn from 1.0.76 to 1.0.80 Bumps [syn](https://github.com/dtolnay/syn) from 1.0.76 to 1.0.80. - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.76...1.0.80) --- updated-dependencies: - dependency-name: syn dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9242376..b87bc8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,9 +195,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.76" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" dependencies = [ "proc-macro2", "quote",