Skip to content

Commit 53f8ec9

Browse files
Sebastien Boeufbryteise
authored andcommitted
ch_integration_tests: Add multiple vCPUs test
Adding a new integration test for validating the VM has been created with the right amount of vCPUs. Signed-off-by: Sebastien Boeuf <[email protected]>
1 parent ae2594d commit 53f8ec9

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

ch_integration_tests/tests/integration.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod tests {
3131

3232
#[derive(Debug)]
3333
enum Error {
34+
Parsing(std::num::ParseIntError),
3435
SshCommand(SshCommandError),
3536
WaitForBoot(WaitForBootError),
3637
}
@@ -166,7 +167,6 @@ mod tests {
166167
.map_err(Error::WaitForBoot)
167168
}
168169

169-
#[allow(dead_code)]
170170
fn ssh_command(&self, command: &str) -> Result<String, SshCommandError> {
171171
ssh_command_ip(
172172
command,
@@ -175,6 +175,13 @@ mod tests {
175175
DEFAULT_SSH_TIMEOUT,
176176
)
177177
}
178+
179+
fn get_cpu_count(&self) -> Result<u8, Error> {
180+
self.ssh_command("grep -c processor /proc/cpuinfo")?
181+
.trim()
182+
.parse()
183+
.map_err(Error::Parsing)
184+
}
178185
}
179186

180187
fn spawn_libvirtd() -> io::Result<Child> {
@@ -251,6 +258,62 @@ mod tests {
251258
assert!(r.is_ok());
252259
}
253260

261+
#[test]
262+
fn test_multi_cpu() {
263+
cleanup_libvirt_state();
264+
let mut libvirtd = spawn_libvirtd().unwrap();
265+
thread::sleep(std::time::Duration::new(5, 0));
266+
267+
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
268+
let guest = Guest::new(&mut disk);
269+
270+
let domain_path = guest.create_domain(4, DEFAULT_RAM_SIZE);
271+
272+
let r = std::panic::catch_unwind(|| {
273+
spawn_virsh(&["create", domain_path.to_str().unwrap()])
274+
.unwrap()
275+
.wait()
276+
.unwrap();
277+
278+
guest.wait_vm_boot(None).unwrap();
279+
280+
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
281+
282+
#[cfg(target_arch = "x86_64")]
283+
assert_eq!(
284+
guest
285+
.ssh_command(r#"dmesg | grep "smpboot: Allowing" | sed "s/\[\ *[0-9.]*\] //""#)
286+
.unwrap()
287+
.trim(),
288+
"smpboot: Allowing 4 CPUs, 0 hotplug CPUs"
289+
);
290+
#[cfg(target_arch = "aarch64")]
291+
assert_eq!(
292+
guest
293+
.ssh_command(r#"dmesg | grep "smp: Brought up" | sed "s/\[\ *[0-9.]*\] //""#)
294+
.unwrap()
295+
.trim(),
296+
"smp: Brought up 1 node, 4 CPUs"
297+
);
298+
});
299+
300+
spawn_virsh(&["destroy", &guest.vm_name])
301+
.unwrap()
302+
.wait()
303+
.unwrap();
304+
305+
libvirtd.kill().unwrap();
306+
let libvirtd_output = libvirtd.wait_with_output().unwrap();
307+
308+
eprintln!(
309+
"libvirtd stdout\n\n{}\n\nlibvirtd stderr\n\n{}",
310+
std::str::from_utf8(&libvirtd_output.stdout).unwrap(),
311+
std::str::from_utf8(&libvirtd_output.stderr).unwrap()
312+
);
313+
314+
assert!(r.is_ok());
315+
}
316+
254317
#[test]
255318
fn test_uri() {
256319
cleanup_libvirt_state();

0 commit comments

Comments
 (0)