From 1ca036cb49050d68d375ea677c70c273738df5ca Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Fri, 6 Sep 2024 17:09:07 +0800 Subject: [PATCH] virtio_page_per_vq: enhance input event file Regarding /dev/input/event* files, there might be some different situation. For example, - No event file exsit at all - Only /dev/input/event0 exists - Only /dev/input/event1 exists - Both /dev/input/event0 and /dev/input/event1 exists - and more ... So this patch is intending to support above situations instead of hardcoding with event1. Signed-off-by: Dan Zheng --- .../tests/cfg/virtio/virtio_page_per_vq.cfg | 2 +- .../tests/src/virtio/virtio_page_per_vq.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libvirt/tests/cfg/virtio/virtio_page_per_vq.cfg b/libvirt/tests/cfg/virtio/virtio_page_per_vq.cfg index 44a6a7c12b..98a7c30804 100644 --- a/libvirt/tests/cfg/virtio/virtio_page_per_vq.cfg +++ b/libvirt/tests/cfg/virtio/virtio_page_per_vq.cfg @@ -41,7 +41,7 @@ - mouse: - tablet: - passthrough: - device_dict = {**${device_dict}, 'source_evdev': '/dev/input/event1'} + device_dict = {**${device_dict}, 'source_evdev': '%s'} - video: only default_start device_dict = {'model_type': 'virtio', **${driver_dict}, 'model_heads': '1'} diff --git a/libvirt/tests/src/virtio/virtio_page_per_vq.py b/libvirt/tests/src/virtio/virtio_page_per_vq.py index f39435fde9..0e29545a3e 100644 --- a/libvirt/tests/src/virtio/virtio_page_per_vq.py +++ b/libvirt/tests/src/virtio/virtio_page_per_vq.py @@ -1,6 +1,8 @@ import os import platform +from avocado.utils import process + from virttest import libvirt_version from virttest import utils_net from virttest import virsh @@ -17,6 +19,24 @@ from virttest.utils_test import libvirt +def get_input_event_file(test): + """ + Get the input event file on the host + + :return: str, the last file path if exists, otherwise skip the test + """ + ret = process.run("ls /dev/input/event*", + shell=True, + verbose=True, + ignore_status=True) + if ret.exit_status != 0: + if ret.stderr_text.count("No such file or directory"): + test.cancel(ret.stderr_text) + else: + test.fail(ret.stderr_text) + return ret.stdout_text.splitlines[-1] + + def run(test, params, env): """ Start guest with virtio page_per_vq attribute - various virtio devices @@ -55,6 +75,8 @@ def prepare_test(vmxml): device_dict['source']['attrs']['file'] = disk_image_path if device_type == "input": device_xml = eval(device_obj)(input_type) + if input_type == "passthrough": + device_dict['source_evdev'] = get_input_event_file(test) else: device_xml = eval(device_obj)() device_xml.setup_attrs(**device_dict)