Skip to content

Conversation

@leidwang
Copy link
Contributor

@leidwang leidwang commented Dec 9, 2025

Test vsock driver in Windows VM, will check vsock driver status and provider.

ID:4795

Summary by CodeRabbit

  • Tests

    • Added a Windows-only VSock driver validation test that boots a VM, installs the guest VSock driver, verifies driver readiness, and runs a provider test tool to confirm functionality.
  • Chores

    • Added a Windows-only test configuration containing metadata, paths, and per-architecture mappings to support 32‑bit and 64‑bit VSock validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 9, 2025

Walkthrough

Adds a Windows-only VSock driver validation to the QEMU test suite. Introduces qemu/tests/cfg/vsock_driver_check.cfg with VirtIO vsock metadata (driver name, hardware IDs, devcon path mappings per architecture, media and test tool names, and a driver inquiry command). Adds test module qemu/tests/vsock_driver_check.py that loads host vhost_vsock, boots a guest, installs the vsock driver via virtio media, verifies driver readiness inside the guest, locates the provider INF, runs viosocklib-test.exe, and closes the session.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a script to test the vsock driver, which is reflected in both the new Python test module and the configuration file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
qemu/tests/cfg/vsock_driver_check.cfg (1)

19-20: Consider parameterizing the destination directory.

The test tool destination is hardcoded to C:\ in both the configuration and test code (line 50 of vsock_driver_check.py). Consider making this configurable for flexibility.

qemu/tests/vsock_driver_check.py (4)

30-32: Consider verifying the vsock device presence.

The test assumes the VM is configured with a vhost-vsock-pci device (per step 2 in the docstring), but there's no verification. Consider checking the device is present before proceeding with driver installation to provide clearer error messages if misconfigured.

You could verify the device using:

# Verify vsock device is present in VM
vsock_id = params.get("vsocks", "").split()[0] if params.get("vsocks") else None
if not vsock_id:
    test.error("No vsock device configured for VM")

34-42: Consider parameterizing the driver name.

The driver name is hardcoded as "viosock". While this is correct for the current use case, parameterizing it (e.g., params.get("vsock_driver_name", "viosock")) would make the test more flexible.


51-53: Improve error message informativeness.

The failure message doesn't show the actual output, making debugging difficult. Consider including the command output in the error message.

 output = session.cmd_output(params["vsock_provider_check"])
 if params["vsock_provider"] not in output:
-    test.fail("Not find vsock provider in guest.")
+    test.fail(f"VSock provider '{params['vsock_provider']}' not found in output: {output}")

32-55: Consider using try-finally for session cleanup.

The session is created at line 32 but only closed at line 55. If any intermediate step fails (test.fail() or exception), the session may not be properly closed. Consider wrapping the test logic in a try-finally block to ensure cleanup.

 session = vm.wait_for_login()
+try:
+    LOG_JOB.info("Install vsock driver in guest")
+    install_driver_by_virtio_media(
+        session,
+        test,
+        devcon_path=params["devcon_path"],
+        media_type=params["virtio_win_media_type"],
+        driver_name="viosock",
+        device_hwid=params["viosock_hwid"],
+    )
 
-LOG_JOB.info("Install vsock driver in guest")
-install_driver_by_virtio_media(
-    session,
-    test,
-    devcon_path=params["devcon_path"],
-    media_type=params["virtio_win_media_type"],
-    driver_name="viosock",
-    device_hwid=params["viosock_hwid"],
-)
-
-LOG_JOB.info("Check vsock driver status in guest")
-if session.cmd_status(params["vio_driver_chk_cmd"]):
-    test.fail("Vsock driver status is not ready.")
-
-LOG_JOB.info("Check vsock prodiver in guest")
-src_file = os.path.join(data_dir.get_deps_dir("virtio_sock"), params["test_tool"])
-vm.copy_files_to(src_file, "C:")
-output = session.cmd_output(params["vsock_provider_check"])
-if params["vsock_provider"] not in output:
-    test.fail("Not find vsock provider in guest.")
-
-session.close()
+    LOG_JOB.info("Check vsock driver status in guest")
+    if session.cmd_status(params["vio_driver_chk_cmd"]):
+        test.fail("Vsock driver status is not ready.")
+
+    LOG_JOB.info("Check vsock provider in guest")
+    src_file = os.path.join(data_dir.get_deps_dir("virtio_sock"), params["test_tool"])
+    vm.copy_files_to(src_file, "C:")
+    output = session.cmd_output(params["vsock_provider_check"])
+    if params["vsock_provider"] not in output:
+        test.fail(f"VSock provider '{params['vsock_provider']}' not found in output: {output}")
+finally:
+    session.close()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1339503 and 8a0dd45.

📒 Files selected for processing (2)
  • qemu/tests/cfg/vsock_driver_check.cfg (1 hunks)
  • qemu/tests/vsock_driver_check.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
qemu/tests/vsock_driver_check.py (2)
provider/win_driver_utils.py (1)
  • install_driver_by_virtio_media (159-194)
qemu/deps/win_driver_install/win_driver_install.py (1)
  • cmd_output (12-28)
🔇 Additional comments (7)
qemu/tests/cfg/vsock_driver_check.cfg (3)

13-16: LGTM!

The architecture-specific devcon directory mappings are correct for Windows conventions (x86 for 32-bit, amd64 for 64-bit).


6-7: [Your rewritten review comment text here]
[Exactly ONE classification tag]


12-12: Verify the hardware ID quoting pattern.

The viosock_hwid uses mixed quoting: '"PCI\VEN_1AF4&DEV_1053"'. Standard DevCon commands quote hardware IDs with & characters using double quotes (e.g., "PCI\VEN_1AF4&DEV_1053"), not the single-quoted-outer-double-quoted-inner pattern shown here. Confirm whether this quoting is required by the autotest framework when passing the HWID to driver installation commands, or if it should be simplified to standard double quoting.

qemu/tests/vsock_driver_check.py (4)

1-10: LGTM!

Imports are appropriate and align with the avocado testing framework and virttest utilities.


12-26: LGTM!

The function signature and documentation follow virttest conventions. The test steps are clearly outlined.


44-46: LGTM!

The driver status check logic is correct, and the error message is clear.


49-49: Verify the dependency directory exists.

The test tool path assumes virtio_sock exists in the deps directory. Ensure this directory and the test tool file are properly documented as test dependencies.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
qemu/tests/cfg/vsock_driver_check.cfg (1)

1-20: Config block is consistent with other virtio/Windows tests; a couple of details worth confirming

Overall this looks well-aligned with the new vsock_driver_check test: Windows-only gating, virtio-win version ranges, devcon_path construction (arch-specific devcon_dirname), and the driverquery-based vio_driver_chk_cmd all fit the usual tp-qemu patterns. I don’t see any blockers here.

Two minor points to double‑check:

  • Line 9: vsocks = vhost_vsock0 – ensure this value matches what the Python test actually expects on your supported hosts (e.g., whether it treats this as a device/node name versus a module/identifier). If the code uses it directly as a device path or name, a mismatch with the real host vsock device could cause the test to fail or silently skip functionality.

  • Line 20: vsock_provider_check = "C:\${test_tool} /e" assumes the provider test tool is copied to C:\ specifically. If vsock_driver_check.py ever starts placing the tool elsewhere (or you run with a non‑C system drive), this will drift. You might consider either:

    • Adding a separate test_tool_dir parameter and composing the command in Python, or
    • Keeping just the executable name here and letting the Python test prepend the directory when building the command.

These are non‑blocking and can be deferred, but tightening them up will make the test a bit more robust to environment changes.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a0dd45 and 1fd515c.

⛔ Files ignored due to path filters (1)
  • deps/virtio_sock/viosocklib-test.exe is excluded by !**/*.exe
📒 Files selected for processing (2)
  • qemu/tests/cfg/vsock_driver_check.cfg (1 hunks)
  • qemu/tests/vsock_driver_check.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • qemu/tests/vsock_driver_check.py

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
qemu/tests/vsock_driver_check.py (1)

28-29: Add error handling for module loading.

The module load operation should verify success before proceeding to guest operations.

This issue was already flagged in a previous review.

🧹 Nitpick comments (4)
qemu/tests/vsock_driver_check.py (4)

34-42: Consider parameterizing the driver name.

The driver name "viosock" is hardcoded on line 40. For consistency with other test parameters, consider adding a config parameter like vsock_driver_name = "viosock" and using params["vsock_driver_name"].

Apply this diff to parameterize the driver name:

     install_driver_by_virtio_media(
         session,
         test,
         devcon_path=params["devcon_path"],
         media_type=params["virtio_win_media_type"],
-        driver_name="viosock",
+        driver_name=params.get("vsock_driver_name", "viosock"),
         device_hwid=params["viosock_hwid"],
     )

And add to the config file (qemu/tests/cfg/vsock_driver_check.cfg):

vsock_driver_name = "viosock"

44-46: Add timeout and improve error message.

The driver status check should specify an explicit timeout to prevent potential hangs, and the error message should include the command that was executed for better debugging.

Apply this diff:

     LOG_JOB.info("Check vsock driver status in guest")
-    if session.cmd_status(params["vio_driver_chk_cmd"]):
-        test.fail("Vsock driver status is not ready.")
+    chk_cmd = params["vio_driver_chk_cmd"]
+    if session.cmd_status(chk_cmd, timeout=60):
+        test.fail(f"Vsock driver not found. Command '{chk_cmd}' failed.")

51-54: Add timeout and improve error message.

The provider check should specify an explicit timeout, and the error message should include the actual command output for debugging purposes.

Apply this diff:

-    output = session.cmd_output(params["vsock_provider_check"])
+    provider_check_cmd = params["vsock_provider_check"]
+    output = session.cmd_output(provider_check_cmd, timeout=120)
     if params["vsock_provider"] not in output:
-        test.fail("Not find vsock provider in guest.")
+        test.fail(
+            f"Vsock provider '{params['vsock_provider']}' not found.\n"
+            f"Command: {provider_check_cmd}\nOutput: {output}"
+        )

55-55: Consider module cleanup.

The session is properly closed, but the vhost_vsock module loaded on line 29 is never explicitly unloaded. Consider whether module cleanup should be added to a finally block or teardown method to ensure proper resource cleanup, or verify that the test framework handles this automatically.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fd515c and b29b7b4.

⛔ Files ignored due to path filters (1)
  • deps/virtio_sock/viosocklib-test.exe is excluded by !**/*.exe
📒 Files selected for processing (2)
  • qemu/tests/cfg/vsock_driver_check.cfg (1 hunks)
  • qemu/tests/vsock_driver_check.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
qemu/tests/vsock_driver_check.py (1)
provider/win_driver_utils.py (1)
  • install_driver_by_virtio_media (159-194)
🔇 Additional comments (7)
qemu/tests/cfg/vsock_driver_check.cfg (4)

1-7: LGTM! Configuration setup is correct.

The test type, Windows constraint, VirtIO media configuration, and version requirements are properly defined.


8-12: LGTM! VSock device configuration is correct.

The module name, device identifiers, and hardware IDs for VirtIO vsock (both modern 1053 and transitional 1012 device IDs) are properly configured.


13-17: LGTM! Architecture-specific devcon paths are correctly configured.

The configuration properly handles both 32-bit and 64-bit Windows architectures with appropriate devcon.exe paths.


18-20: LGTM! Command definitions are correct.

The driver check command using driverquery and the provider check tool invocation are properly configured for Windows.

qemu/tests/vsock_driver_check.py (3)

1-10: LGTM! Imports and logger setup are correct.

All necessary dependencies are imported and the logger is properly configured.


12-26: LGTM! Test function signature and documentation are correct.

The function follows the standard QEMU test pattern with proper decorator and clear docstring describing all test steps.


30-32: LGTM! VM initialization follows standard pattern.

The VM retrieval, liveness verification, and session establishment follow the correct QEMU test framework pattern.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
qemu/tests/cfg/vsock_driver_check.cfg (1)

10-13: Optional: consider centralising viosock metadata with other VirtIO drivers

You’re introducing driver_name, vsock_name, and a viosock_hwid list here, while other drivers keep similar metadata in win_driver_utils.driver_info_dict. For future maintainability, it might be worth adding a viosock entry there and reusing it instead of hard-coding HWIDs and display names in this cfg block.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b29b7b4 and e3a3e62.

📒 Files selected for processing (2)
  • qemu/tests/cfg/vsock_driver_check.cfg (1 hunks)
  • qemu/tests/vsock_driver_check.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • qemu/tests/vsock_driver_check.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Python 3.12
🔇 Additional comments (1)
qemu/tests/cfg/vsock_driver_check.cfg (1)

1-20: Config wiring and parameters look consistent with the Python test

The block defines exactly the parameters vsock_driver_check.py expects (virtio_win_media_type, driver_name, test_tool, devcon_path, viosock_hwid, vio_driver_chk_cmd, vsock_provider), and the HWID format matches install_driver_by_virtio_media’s expectations. From a wiring standpoint this cfg is coherent with the new test.

@leidwang
Copy link
Contributor Author

JOB LOG : /root/avocado/job-results/job-2025-12-09T10.04-524cb9a/job.log
(1/1) Host_RHEL.m10.ux.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2022.x86_64.io-github-autotest-qemu.vsock_driver_check.q35: STARTED
(1/1) Host_RHEL.m10.ux.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2022.x86_64.io-github-autotest-qemu.vsock_driver_check.q35: PASS (128.15 s)

@leidwang
Copy link
Contributor Author

Hi @JinLiul Could you please help review this PR?Thanks.

@JinLiul
Copy link
Contributor

JinLiul commented Dec 22, 2025

LGTM.

linux_modules.load_module("vhost_vsock")
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it's also fine, but vm.wait_for_login() would covered vm.verify_alive().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, vm.verify_alive() has been removed.Thanks!

Test vsock driver in Windows VM, will check vsock driver
status and provider.

ID:4795

Signed-off-by: Leidong Wang <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
qemu/tests/vsock_driver_check.py (2)

54-54: Use os.path for safer path handling.

The string manipulation path[: path.rfind("\\")] has an edge case: if rfind returns -1 (backslash not found), path[:-1] incorrectly slices off the last character. While get_driver_inf_path should always return Windows paths with backslashes, defensive coding is safer.

♻️ Refactor using os.path for robustness

Add os import at the top:

+import os
 import logging

Then replace the path construction:

-    test_tool_path = path[: path.rfind("\\")] + "\\" + test_tool
+    test_tool_path = os.path.join(os.path.dirname(path), test_tool)

55-57: Add error handling for test tool execution.

If the test tool doesn't exist at the constructed path or execution fails, cmd_output will raise an exception, causing the test to crash with an unclear error. Add validation or error handling to provide a clearer failure message.

🛡️ Add error handling
     LOG_JOB.info("Check vsock provider in guest")
     path = get_driver_inf_path(session, test, virtio_win_media_type, driver_name)
     test_tool_path = path[: path.rfind("\\")] + "\\" + test_tool
-    output = session.cmd_output("%s /e" % test_tool_path)
+    status, output = session.cmd_status_output("%s /e" % test_tool_path)
+    if status:
+        test.fail(f"Failed to execute test tool at {test_tool_path}: {output}")
     if params["vsock_provider"] not in output:
         test.fail("Not find vsock provider in guest.")
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8660ee5 and 79bf6f2.

📒 Files selected for processing (2)
  • qemu/tests/cfg/vsock_driver_check.cfg
  • qemu/tests/vsock_driver_check.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • qemu/tests/cfg/vsock_driver_check.cfg
🧰 Additional context used
🧬 Code graph analysis (1)
qemu/tests/vsock_driver_check.py (1)
provider/win_driver_utils.py (2)
  • get_driver_inf_path (123-155)
  • install_driver_by_virtio_media (159-194)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants