Skip to content

Commit cb54f91

Browse files
Add device-passthrough testcase for CH platform
Add test case to verify if passthrough-devices are visible to guest for CH platform Signed-off-by: Smit Gardhariya <[email protected]>
1 parent 7b264b4 commit cb54f91

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT license.
3+
from pathlib import Path
4+
from typing import Any, Dict, cast
5+
6+
from lisa import (
7+
Environment,
8+
Logger,
9+
Node,
10+
TestCaseMetadata,
11+
TestSuite,
12+
TestSuiteMetadata,
13+
schema,
14+
)
15+
from lisa.sut_orchestrator import CLOUD_HYPERVISOR
16+
from lisa.sut_orchestrator.libvirt.ch_platform import CloudHypervisorPlatform
17+
from lisa.sut_orchestrator.libvirt.context import get_node_context as get_ch_context
18+
from lisa.sut_orchestrator.libvirt.schema import BaseLibvirtNodeSchema
19+
from lisa.testsuite import TestResult, simple_requirement
20+
from lisa.tools import Lspci
21+
from lisa.util import LisaException, SkippedException
22+
23+
24+
@TestSuiteMetadata(
25+
area="device_passthrough",
26+
category="functional",
27+
description="""
28+
This test suite is for testing device passthrough functional tests.
29+
""",
30+
)
31+
class DevicePassthroughFunctionalTests(TestSuite):
32+
@TestCaseMetadata(
33+
description="""
34+
Check if passthrough device is visible to guest.
35+
This testcase support only on CLOUD_HYPERVISOR
36+
platform of LISA.
37+
""",
38+
priority=4,
39+
requirement=simple_requirement(
40+
supported_platform_type=[CLOUD_HYPERVISOR],
41+
),
42+
)
43+
def verify_device_passthrough_on_guest(
44+
self,
45+
log: Logger,
46+
node: Node,
47+
environment: Environment,
48+
log_path: Path,
49+
result: TestResult,
50+
variables: Dict[str, Any],
51+
) -> None:
52+
ctx = get_ch_context(node)
53+
if not ctx.passthrough_devices:
54+
raise SkippedException("No device-passthrough is set for node")
55+
56+
lspci = node.tools[Lspci]
57+
platform = cast(CloudHypervisorPlatform, environment.platform)
58+
pool_vendor_device_map = {}
59+
for pool in platform.platform_runbook.device_pools:
60+
pool_type = str(pool.type.value)
61+
vendor_device_id = {
62+
"vendord_id": pool.devices[0].vendor_id,
63+
"device_id": pool.devices[0].device_id,
64+
}
65+
pool_vendor_device_map[pool_type] = vendor_device_id
66+
67+
for node_space in environment.runbook.nodes_requirement:
68+
node_runbook: BaseLibvirtNodeSchema = node_space.get_extended_runbook(
69+
BaseLibvirtNodeSchema, CLOUD_HYPERVISOR
70+
)
71+
for req in node_runbook.device_passthrough:
72+
pool_type = str(req.pool_type.value)
73+
ven_dev_id_of_pool = pool_vendor_device_map[pool_type]
74+
ven_id = ven_dev_id_of_pool["vendor_id"]
75+
dev_id = ven_dev_id_of_pool["device_id"]
76+
devices = lspci.get_devices_by_vendor_device_id(
77+
vendor_id=ven_id,
78+
device_id=dev_id,
79+
force_run=True,
80+
)
81+
if len(devices) != req.count:
82+
raise LisaException(
83+
f"Device count don't match, got total: {len(devices)} "
84+
f"As per runbook, Required device count: {req.count}, "
85+
f"for pool_type: {pool_type} having Vendor/Device ID as "
86+
f"vendor_id = {ven_id}, device_id={dev_id}"
87+
)

0 commit comments

Comments
 (0)