|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +# SPDX-License-Identifier: GPL-2.0-only |
| 4 | +# Copyright (c) 2026 Intel Corporation |
| 5 | + |
| 6 | +# Author: Kai Zhang <kai.zhang@intel.com> |
| 7 | +# |
| 8 | +# History: Apr. 2026 - Kai Zhang - creation |
| 9 | + |
| 10 | +import re |
| 11 | + |
| 12 | +from provider import dmesg_router # pylint: disable=unused-import |
| 13 | +from avocado.utils import process |
| 14 | +from virttest import error_context, env_process |
| 15 | +from provider.cpu_utils import check_cpu_flags |
| 16 | + |
| 17 | + |
| 18 | +@error_context.context_aware |
| 19 | +def run(test, params, env): |
| 20 | + """ |
| 21 | + TDX CPU off pinned VM down test: |
| 22 | + 1. Boot TDVM |
| 23 | + 2. Pin a TD VM to a cpu, poweroff the cpu and shutdown the TD VM |
| 24 | +
|
| 25 | + :param test: QEMU test object |
| 26 | + :param params: Dictionary with the test parameters |
| 27 | + :param env: Dictionary with test environment. |
| 28 | + """ |
| 29 | + |
| 30 | + for i in range(0, 20): |
| 31 | + params["smp"] = 64 |
| 32 | + params["start_vm"] = "yes" |
| 33 | + env_process.preprocess_vm(test, params, env, params["main_vm"]) |
| 34 | + vm = env.get_vm(params["main_vm"]) |
| 35 | + vm.verify_alive() |
| 36 | + timeout = params.get_numeric("login_timeout", 240) |
| 37 | + session = vm.wait_for_login(timeout=timeout) |
| 38 | + flags = params["guest_flags"] |
| 39 | + check_cpu_flags(params, flags, test, session) |
| 40 | + pid = process.getoutput("ps -edf | grep qemu | grep -E 'avocado-vt-vm.*' | grep -v grep | awk '{print $2}'") |
| 41 | + process.system(f"taskset -pc 18 {pid}", ignore_status=True) |
| 42 | + process.system("echo 0 > /sys/devices/system/cpu/cpu18/online") |
| 43 | + session.cmd("init 0 &", ignore_all_errors=True) |
| 44 | + process.system("sleep 3") |
| 45 | + |
| 46 | + hkid = params["hkid"] |
| 47 | + tdx_crash_flag = params["tdx_crash_flag"] |
| 48 | + dmesg = process.system_output("dmesg") |
| 49 | + hkid_str = re.findall(r'%s' % hkid, dmesg.decode('utf-8')) |
| 50 | + crash_str = re.findall(r'%s' % tdx_crash_flag, dmesg.decode('utf-8')) |
| 51 | + seamcall_failed_pattern = re.compile(r'^.*SEAMCALL.*failed.*$', re.MULTILINE) |
| 52 | + seamcall_failed_match = seamcall_failed_pattern.search(dmesg.decode('utf-8')) |
| 53 | + if hkid_str or crash_str or seamcall_failed_match: |
| 54 | + test.fail(f"Detected the crash information in {i} time run. Fail!") |
| 55 | + process.system("echo 1 > /sys/devices/system/cpu/cpu18/online") |
| 56 | + session.close() |
0 commit comments