Skip to content

Commit 20bb5df

Browse files
author
Sebastien Boeuf
committed
ch_integration_tests: Add kernel type
Introduce a new enum to identify what kind of kernel is used for booting the VM. Because at this point the Rust firmware is the only one being used, this is the only valid type for KernelType enum. Signed-off-by: Sebastien Boeuf <[email protected]>
1 parent fdc43f8 commit 20bb5df

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

ch_integration_tests/tests/integration.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ mod tests {
5454
}
5555
}
5656

57+
enum KernelType {
58+
RustFw,
59+
}
60+
61+
impl KernelType {
62+
fn path(&self) -> PathBuf {
63+
let mut kernel_path = dirs::home_dir().unwrap();
64+
kernel_path.push("workloads");
65+
66+
match self {
67+
KernelType::RustFw => {
68+
#[cfg(target_arch = "aarch64")]
69+
kernel_path.push("Image");
70+
#[cfg(target_arch = "x86_64")]
71+
kernel_path.push("hypervisor-fw");
72+
}
73+
}
74+
75+
kernel_path
76+
}
77+
}
78+
5779
struct Guest<'a> {
5880
tmp_dir: TempDir,
5981
vm_name: String,
@@ -160,17 +182,16 @@ mod tests {
160182
domain_path
161183
}
162184

163-
fn new_from_ip_range(disk_config: &'a mut dyn DiskConfig, class: &str, id: u8) -> Self {
185+
fn new_from_ip_range(
186+
disk_config: &'a mut dyn DiskConfig,
187+
class: &str,
188+
id: u8,
189+
kernel: KernelType,
190+
) -> Self {
164191
let tmp_dir = TempDir::new_with_prefix("/tmp/ch").unwrap();
165192

166-
let mut workload_path = dirs::home_dir().unwrap();
167-
workload_path.push("workloads");
193+
let kernel_path = kernel.path();
168194

169-
let mut kernel_path = workload_path;
170-
#[cfg(target_arch = "aarch64")]
171-
kernel_path.push("Image");
172-
#[cfg(target_arch = "x86_64")]
173-
kernel_path.push("hypervisor-fw");
174195
let network = GuestNetworkConfig {
175196
guest_ip: format!("{}.{}.2", class, id),
176197
l2_guest_ip1: format!("{}.{}.3", class, id),
@@ -197,12 +218,12 @@ mod tests {
197218
}
198219
}
199220

200-
fn new(disk_config: &'a mut dyn DiskConfig) -> Self {
221+
fn new(disk_config: &'a mut dyn DiskConfig, kernel: KernelType) -> Self {
201222
let mut guard = NEXT_VM_ID.lock().unwrap();
202223
let id = *guard;
203224
*guard = id + 1;
204225

205-
Self::new_from_ip_range(disk_config, "192.168", id)
226+
Self::new_from_ip_range(disk_config, "192.168", id, kernel)
206227
}
207228

208229
fn wait_vm_boot(&self, custom_timeout: Option<i32>) -> Result<(), Error> {
@@ -271,7 +292,7 @@ mod tests {
271292
thread::sleep(std::time::Duration::new(5, 0));
272293

273294
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
274-
let guest = Guest::new(&mut disk);
295+
let guest = Guest::new(&mut disk, KernelType::RustFw);
275296

276297
let domain_path = guest.create_domain(VcpuConfig::default(), DEFAULT_RAM_SIZE);
277298

@@ -330,7 +351,7 @@ mod tests {
330351
thread::sleep(std::time::Duration::new(5, 0));
331352

332353
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
333-
let guest = Guest::new(&mut disk);
354+
let guest = Guest::new(&mut disk, KernelType::RustFw);
334355
let domain_path = guest.create_domain(VcpuConfig::default(), DEFAULT_RAM_SIZE);
335356
let output = spawn_virsh(&["define", domain_path.to_str().unwrap()])
336357
.unwrap()
@@ -387,7 +408,7 @@ mod tests {
387408
thread::sleep(std::time::Duration::new(5, 0));
388409

389410
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
390-
let guest = Guest::new(&mut disk);
411+
let guest = Guest::new(&mut disk, KernelType::RustFw);
391412
let domain_path = guest.create_domain(VcpuConfig::default(), DEFAULT_RAM_SIZE);
392413

393414
spawn_virsh(&["create", domain_path.to_str().unwrap()])
@@ -427,7 +448,7 @@ mod tests {
427448
thread::sleep(std::time::Duration::new(5, 0));
428449

429450
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
430-
let guest = Guest::new(&mut disk);
451+
let guest = Guest::new(&mut disk, KernelType::RustFw);
431452

432453
let domain_path = guest.create_domain(VcpuConfig::default(), 128 << 30);
433454

@@ -466,7 +487,7 @@ mod tests {
466487
thread::sleep(std::time::Duration::new(5, 0));
467488

468489
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
469-
let guest = Guest::new(&mut disk);
490+
let guest = Guest::new(&mut disk, KernelType::RustFw);
470491

471492
let domain_path = guest.create_domain(VcpuConfig { boot: 2, max: 4 }, DEFAULT_RAM_SIZE);
472493

@@ -549,7 +570,7 @@ mod tests {
549570
thread::sleep(std::time::Duration::new(5, 0));
550571

551572
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
552-
let guest = Guest::new(&mut disk);
573+
let guest = Guest::new(&mut disk, KernelType::RustFw);
553574

554575
let domain_path = guest.create_domain(VcpuConfig::default(), DEFAULT_RAM_SIZE);
555576

@@ -626,7 +647,7 @@ mod tests {
626647
thread::sleep(std::time::Duration::new(5, 0));
627648

628649
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
629-
let guest = Guest::new(&mut disk);
650+
let guest = Guest::new(&mut disk, KernelType::RustFw);
630651

631652
let domain_path = guest.create_domain(VcpuConfig::default(), DEFAULT_RAM_SIZE);
632653

0 commit comments

Comments
 (0)