Skip to content

Commit bfedbbf

Browse files
committed
Add CPU count configuration to test framework
1 parent 7f023eb commit bfedbbf

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

test/test-manager/src/config/vm.rs

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ pub struct VmConfig {
6060
#[serde(default)]
6161
#[arg(long, requires("tpm"))]
6262
pub ovmf_code_path: Option<String>,
63+
64+
/// Number of vCPUs
65+
#[serde(default)]
66+
#[arg(long)]
67+
pub vcpu: Option<usize>,
6368
}
6469

6570
impl VmConfig {

test/test-manager/src/vm/qemu.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const STDERR_LOG_LEVEL: log::Level = log::Level::Error;
2525
const STDOUT_LOG_LEVEL: log::Level = log::Level::Debug;
2626
const OBTAIN_IP_TIMEOUT: Duration = Duration::from_secs(180);
2727

28+
/// Default number of VCPU cores (passed to -smp)
29+
const DEFAULT_NUM_VCPUS: usize = 2;
30+
2831
#[derive(thiserror::Error, Debug)]
2932
pub enum Error {
3033
#[error("Failed to set up network")]
@@ -83,6 +86,7 @@ pub async fn run(config: &Config, vm_config: &VmConfig) -> Result<QemuInstance>
8386
.map_err(Error::Network)?;
8487

8588
let mut qemu_cmd = Command::new("qemu-system-x86_64");
89+
let vcpus = vm_config.vcpu.unwrap_or(DEFAULT_NUM_VCPUS);
8690
qemu_cmd.args([
8791
"-cpu",
8892
"host",
@@ -91,7 +95,7 @@ pub async fn run(config: &Config, vm_config: &VmConfig) -> Result<QemuInstance>
9195
"-m",
9296
"4096",
9397
"-smp",
94-
"2",
98+
&vcpus.to_string(),
9599
"-drive",
96100
&format!("file={}", vm_config.image_path),
97101
"-device",

test/test-manager/src/vm/tart.rs

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub async fn run(config: &Config, vm_config: &VmConfig) -> Result<TartInstance>
5656
if !vm_config.disks.is_empty() {
5757
log::warn!("Mounting disks is not yet supported")
5858
}
59+
if let Some(cpu) = vm_config.vcpu {
60+
tart_cmd.args(["--cpu", &cpu.to_string()]);
61+
}
5962

6063
match config.runtime_opts.display {
6164
config::Display::None => {

0 commit comments

Comments
 (0)