Skip to content

Commit a40be41

Browse files
authored
Merge branch 'kuasar-io:main' into tzh-version
2 parents 45447dc + 0ecff42 commit a40be41

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

.github/workflows/ci.yml

+1
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 }}

runc/src/sandbox.rs

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl RuncSandbox {
255255
let mut dump_file = OpenOptions::new()
256256
.write(true)
257257
.create(true)
258+
.truncate(true)
258259
.open(&dump_path)
259260
.await
260261
.map_err(Error::IO)?;

vmm/sandbox/src/sandbox.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ where
410410
let mut dump_file = OpenOptions::new()
411411
.write(true)
412412
.create(true)
413+
.truncate(true)
413414
.open(&dump_path)
414415
.await
415416
.map_err(Error::IO)?;
@@ -604,11 +605,7 @@ where
604605

605606
// parse_dnsoptions parse DNS options into resolv.conf format content,
606607
// if none option is specified, will return empty with no error.
607-
fn parse_dnsoptions(
608-
servers: &Vec<String>,
609-
searches: &Vec<String>,
610-
options: &Vec<String>,
611-
) -> String {
608+
fn parse_dnsoptions(servers: &[String], searches: &[String], options: &[String]) -> String {
612609
let mut resolv_content = String::new();
613610

614611
if !searches.is_empty() {
@@ -694,7 +691,7 @@ mod tests {
694691

695692
#[test]
696693
fn test_parse_empty_dns_option() {
697-
let mut dns_test = DnsConfig::default();
694+
let dns_test = DnsConfig::default();
698695
let resolv_content =
699696
parse_dnsoptions(&dns_test.servers, &dns_test.searches, &dns_test.options);
700697
assert!(resolv_content.is_empty())

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

+16-8
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

+6-3
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
}

vmm/sandbox/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub fn vec_to_string<T: ToString>(v: &[T]) -> String {
391391
.join(":")
392392
}
393393

394-
pub fn fds_to_vectors<T>(fds: &Vec<T>) -> String {
394+
pub fn fds_to_vectors<T>(fds: &[T]) -> String {
395395
(2 * fds.len() + 2).to_string()
396396
}
397397

0 commit comments

Comments
 (0)