Skip to content

Commit 2560fd2

Browse files
committed
[vmm]: fix cargo test compilation warnings
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]>
1 parent 76fcfa2 commit 2560fd2

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ jobs:
7272
- name: Test
7373
env:
7474
RUST_BACKTRACE: full
75+
RUSTFLAGS: -D warnings
7576
working-directory: ${{ matrix.directories }}
7677
run: sudo -E $(command -v cargo) test ${{ matrix.features }}

vmm/sandbox/src/sandbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ mod tests {
694694

695695
#[test]
696696
fn test_parse_empty_dns_option() {
697-
let mut dns_test = DnsConfig::default();
697+
let dns_test = DnsConfig::default();
698698
let resolv_content =
699699
parse_dnsoptions(&dns_test.servers, &dns_test.searches, &dns_test.options);
700700
assert!(resolv_content.is_empty())

vmm/sandbox/src/stratovirt/devices/block.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,17 @@ impl VirtioBlockDevice {
190190

191191
#[cfg(test)]
192192
mod tests {
193-
use qapi::qmp::BlockdevOptions;
193+
use serde_json::Value;
194194

195195
use super::{VirtioBlockDevice, VIRTIO_BLK_DRIVER};
196196

197+
fn compare_json_strings(json_str1: &str, json_str2: &str) -> bool {
198+
let value1: Value = serde_json::from_str(json_str1).unwrap();
199+
let value2: Value = serde_json::from_str(json_str2).unwrap();
200+
201+
value1 == value2
202+
}
203+
197204
#[test]
198205
fn test_block_device_add_qmp_commands() {
199206
let virtio_blk_device = VirtioBlockDevice::new(
@@ -212,13 +219,11 @@ mod tests {
212219
);
213220

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

218-
if let BlockdevOptions::raw { base, raw } = expected_add_qmp_cmd {
219-
// TODO: compare the all elements
220-
assert!(true);
221-
}
223+
assert!(compare_json_strings(
224+
&blockdev_add_qmp_json_str,
225+
expected_params_str
226+
));
222227
}
223228

224229
#[test]
@@ -239,7 +244,10 @@ mod tests {
239244
);
240245

241246
let expected_params_str = r#"{"driver":"virtio-blk-pci","id":"virtio-drive-0","bus":"pcie.1","addr":"0x0","drive":"drive-0"}"#;
242-
assert!(true);
247+
assert!(compare_json_strings(
248+
&device_add_qmp_json_str,
249+
expected_params_str
250+
));
243251
}
244252

245253
#[test]

vmm/sandbox/src/stratovirt/devices/rng.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ mod tests {
7979
let mut virtio_rng_device =
8080
VirtioRngDevice::new("rng0", "/dev/urandom", Transport::Pci, DEFAULT_PCIE_BUS);
8181
virtio_rng_device.set_device_addr(VIRTIO_RND_DEVICE_ADDR);
82-
let virtio_rng_device_cmd_params = virtio_rng_device.to_cmdline_params("-");
82+
let mut virtio_rng_device_cmd_params = virtio_rng_device.to_cmdline_params("-");
83+
virtio_rng_device_cmd_params.sort();
8384
println!(
8485
"virtio-rng device params: {:?}",
8586
virtio_rng_device_cmd_params
8687
);
8788

88-
let expected_params: Vec<String> = vec![
89+
let mut expected_params: Vec<String> = vec![
8990
"-object",
9091
"rng-random,id=rng0,filename=/dev/urandom",
9192
"-device",
@@ -94,6 +95,8 @@ mod tests {
9495
.iter()
9596
.map(|s| s.to_string())
9697
.collect();
97-
assert!(true);
98+
expected_params.sort();
99+
100+
assert_eq!(expected_params, virtio_rng_device_cmd_params);
98101
}
99102
}

0 commit comments

Comments
 (0)