Skip to content

Commit

Permalink
TDX: Add one max vcpus test case and one negative case
Browse files Browse the repository at this point in the history
Case 1: boot one TD with maximum vcpus number
Caes 2: boot one TD with out of maximum vcpus number, expect
fail to boot.

Signed-off-by: Xudong Hao <[email protected]>
  • Loading branch information
xhao22 committed Aug 9, 2024
1 parent 884992d commit fefb1a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
10 changes: 10 additions & 0 deletions KVM/qemu/td_huge_resource.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
vga = std
auto_cpu_model = "no"
cpu_model = host
variants:
- half:
- max_vcpus:
only q35
check_host_cpu = "yes"
- out_max_vcpus:
# TD can not boot up with vCPU number larger than host pCPU
only q35
overrange_host_cpu = "yes"
xfail = "yes"
33 changes: 25 additions & 8 deletions KVM/qemu/tests/td_huge_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,46 @@ def run(test, params, env):
"""
Boot TD with huge CPU and memory:
1) Caculate the host online CPU number and usable memory size
2) Boot up one TDVM with half resource of host
2) Boot up one TDVM with huge resource of host
3) Shutdown TDVM
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
xfail = False
if (params.get("xfail") is not None) and (params.get("xfail") == "yes"):
xfail = True

timeout = params.get_numeric("login_timeout", 240)
params["start_vm"] = 'yes'
host_cpu = cpu.online_count()
host_free_mem = utils_misc.get_usable_memory_size()
params['smp'] = params['vcpu_maxcpus'] = host_cpu//2
params['mem'] = host_free_mem//2

if (params.get("check_host_cpu") is not None) and (params['check_host_cpu'] == 'yes'):
params['smp'] = params['vcpu_maxcpus'] = host_cpu
elif (params.get("overrange_host_cpu") is not None) and (params['overrange_host_cpu'] == 'yes'):
params['smp'] = params['vcpu_maxcpus'] = host_cpu+1
else:
params['smp'] = params['vcpu_maxcpus'] = host_cpu//2

error_context.context("Booting TDVM with large CPU and memory", test.log.info)
vm_name = params['main_vm']
has_error = False
try:
env_process.preprocess_vm(test, params, env, vm_name)
except:
raise
vm = env.get_vm(vm_name)
vm.verify_alive()
session = vm.wait_for_login(timeout=timeout)
vm.destroy()
session.close()
has_error = True
if xfail is False:
raise

if (has_error is False) and (xfail is True):
test.fail("Test was expected to fail, but it didn't")

if xfail is False:
vm = env.get_vm(vm_name)
vm.verify_alive()
session = vm.wait_for_login(timeout=timeout)
session.close()
vm.destroy()

0 comments on commit fefb1a7

Please sign in to comment.