Skip to content

Commit

Permalink
[vmm]: fix cargo test compilation warnings
Browse files Browse the repository at this point in the history
fix #115

reason: The result of the cargo test command includes some
compilation warnings that need to be cleaned.

Signed-off-by: flyflypeng <[email protected]>
  • Loading branch information
flyflypeng committed Feb 25, 2024
1 parent 76fcfa2 commit 2560fd2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ jobs:
- name: Test
env:
RUST_BACKTRACE: full
RUSTFLAGS: -D warnings
working-directory: ${{ matrix.directories }}
run: sudo -E $(command -v cargo) test ${{ matrix.features }}
2 changes: 1 addition & 1 deletion vmm/sandbox/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ mod tests {

#[test]
fn test_parse_empty_dns_option() {
let mut dns_test = DnsConfig::default();
let dns_test = DnsConfig::default();
let resolv_content =
parse_dnsoptions(&dns_test.servers, &dns_test.searches, &dns_test.options);
assert!(resolv_content.is_empty())
Expand Down
24 changes: 16 additions & 8 deletions vmm/sandbox/src/stratovirt/devices/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,17 @@ impl VirtioBlockDevice {

#[cfg(test)]
mod tests {
use qapi::qmp::BlockdevOptions;
use serde_json::Value;

use super::{VirtioBlockDevice, VIRTIO_BLK_DRIVER};

fn compare_json_strings(json_str1: &str, json_str2: &str) -> bool {
let value1: Value = serde_json::from_str(json_str1).unwrap();
let value2: Value = serde_json::from_str(json_str2).unwrap();

value1 == value2
}

#[test]
fn test_block_device_add_qmp_commands() {
let virtio_blk_device = VirtioBlockDevice::new(
Expand All @@ -212,13 +219,11 @@ mod tests {
);

let expected_params_str = r#"{"driver":"raw","read-only":false,"node-name":"drive-0","cache":{"direct":true},"file":{"driver":"file","filename":"/dev/dm-8"}}"#;
let expected_add_qmp_cmd: BlockdevOptions =
serde_json::from_str(expected_params_str).unwrap();

if let BlockdevOptions::raw { base, raw } = expected_add_qmp_cmd {
// TODO: compare the all elements
assert!(true);
}
assert!(compare_json_strings(
&blockdev_add_qmp_json_str,
expected_params_str
));
}

#[test]
Expand All @@ -239,7 +244,10 @@ mod tests {
);

let expected_params_str = r#"{"driver":"virtio-blk-pci","id":"virtio-drive-0","bus":"pcie.1","addr":"0x0","drive":"drive-0"}"#;
assert!(true);
assert!(compare_json_strings(
&device_add_qmp_json_str,
expected_params_str
));
}

#[test]
Expand Down
9 changes: 6 additions & 3 deletions vmm/sandbox/src/stratovirt/devices/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ mod tests {
let mut virtio_rng_device =
VirtioRngDevice::new("rng0", "/dev/urandom", Transport::Pci, DEFAULT_PCIE_BUS);
virtio_rng_device.set_device_addr(VIRTIO_RND_DEVICE_ADDR);
let virtio_rng_device_cmd_params = virtio_rng_device.to_cmdline_params("-");
let mut virtio_rng_device_cmd_params = virtio_rng_device.to_cmdline_params("-");
virtio_rng_device_cmd_params.sort();
println!(
"virtio-rng device params: {:?}",
virtio_rng_device_cmd_params
);

let expected_params: Vec<String> = vec![
let mut expected_params: Vec<String> = vec![
"-object",
"rng-random,id=rng0,filename=/dev/urandom",
"-device",
Expand All @@ -94,6 +95,8 @@ mod tests {
.iter()
.map(|s| s.to_string())
.collect();
assert!(true);
expected_params.sort();

assert_eq!(expected_params, virtio_rng_device_cmd_params);
}
}

0 comments on commit 2560fd2

Please sign in to comment.