Skip to content

Added automation of Virsh commands#285

Open
Rohan-in-Qualcomm wants to merge 2 commits intoqualcomm-linux:mainfrom
Rohan-in-Qualcomm:Virtualization
Open

Added automation of Virsh commands#285
Rohan-in-Qualcomm wants to merge 2 commits intoqualcomm-linux:mainfrom
Rohan-in-Qualcomm:Virtualization

Conversation

@Rohan-in-Qualcomm
Copy link

This PR refactors the Virsh Commands into a modular suite of independent KVM test cases.

Key Changes:

  1. Modular Architecture: Split the original script into 5 standalone test cases:
  2. Kvm-Setup: Defines and starts the VM.
  3. Kvm-Reboot: Verifies reboot functionality.
  4. Kvm-Suspend: Verifies suspend/pause functionality.
  5. Kvm-Resume: Verifies resume functionality.
  6. Kvm-UnDefine: Verifies destroy and undefine functionality.

Created kvm_common.sh to handle shared logic (define, start, clean, state checks) and reduce code duplication.

Robust State Verification: Replaced simple exit code checks with a check_vm_state function that parses virsh domstate output to ensure the VM is actually in the expected state (e.g., "running", "paused", "shut off").

Independence: Each test script now manages its own lifecycle (Setup -> Test -> Undefine), allowing them to be run individually or in any order.

Reporting: Added .res file generation (PASS/FAIL) and LAVA-compatible .yaml metadata for automation integration.

@vnarapar
Copy link
Contributor

Please fix the checks

Copy link
Contributor

@smuppand smuppand left a comment

Choose a reason for hiding this comment

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

These changes are not aligned with the repository standards. Please review the contributions README and update accordingly.

@@ -0,0 +1,44 @@
#!/bin/bash

Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid creating a custom folder with your username and sending the pull request.

Copy link
Author

Choose a reason for hiding this comment

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

I have deleted the folder

@Rohan-in-Qualcomm Rohan-in-Qualcomm force-pushed the Virtualization branch 2 times, most recently from 381bdf3 to 9346e9d Compare February 13, 2026 06:40
@Rohan-in-Qualcomm
Copy link
Author

Updated the PR with the requested changes.
Please review the updated commit.

This PR refactors the Virsh Commands into a modular suite of independent KVM test cases.

Key Changes:

Modular Architecture: Split the original script into 5 standalone test cases:
Kvm-Setup: Defines and starts the VM.
Kvm-Reboot: Verifies reboot functionality.
Kvm-Suspend: Verifies suspend/pause functionality.
Kvm-Resume: Verifies resume functionality.
Kvm-UnDefine: Verifies destroy and undefine functionality.
Common Library: Created kvm_common.sh to handle shared logic (define, start, clean, state checks) and reduce code duplication.
Robust State Verification: Replaced simple exit code checks with a check_vm_state function that parses virsh domstate output to ensure the VM is actually in the expected state (e.g., "running", "paused", "shut off").
Independence: Each test script now manages its own lifecycle (Setup -> Test -> UnDefine), allowing them to be run individually or in any order.
Reporting: Added .res file generation (PASS/FAIL) and LAVA-compatible .yaml metadata for automation integration.

Signed-off-by: Rohan Dutta <rohadutt@qti.qualcomm.com>
Signed-off-by: Rohan Dutta <rohadutt@qti.qualcomm.com>
#!/bin/bash

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the license to BSD-3-Clause across the files in the PR

@@ -0,0 +1,93 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Please convert these scripts to POSIX /bin/sh and keep them ShellCheck-clean. The current implementation uses Bash-specific constructs in both the suite run.sh files and kvm_common.sh.

exit 1
fi

TESTNAME="Kvm-Teardown"
Copy link
Contributor

Choose a reason for hiding this comment

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

The Kvm-UnDefine / Kvm-Teardown naming is inconsistent across folder names, YAML paths, result filenames, and README content.

if [ $? -ne 0 ]; then echo "$TESTNAME FAIL" > "$RES_FILE"; exit 1; fi

log_info "Destroying VM $VM_NAME"
virsh destroy "$VM_NAME"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add proper dependency / environment checks for virsh and the required VM setup, and use a clean SKIP path where appropriate instead of failing late.

rm -f "$RES_FILE"

# Clean up old stdout logs from previous runs
rm -f *_stdout_*.log
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid broad cleanup like rm -f stdout.log tests should only remove artifacts created by the current run.

export VM="hk-vm"
export VM_NAME="$VM"
export XML_FILE="/var/gunyah/vm.xml"
export NONRT_IMAGE_DIR="$TOOLS/nonrt_Image"
Copy link
Contributor

Choose a reason for hiding this comment

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

NONRT_IMAGE_DIR is exported here but does not appear to be used in this helper. If it is not needed, please remove it to avoid carrying unused variables.

return 0
}

check_vm_state() {
Copy link
Contributor

Choose a reason for hiding this comment

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

check_vm_state() uses Bash-only syntax (local, ==). Please make this POSIX-compliant. Also, consider whether virsh domstate output may need normalization before comparison.

fi

vm_define && vm_start
if [ $? -ne 0 ]; then echo "$TESTNAME FAIL" > "$RES_FILE"; exit 1; fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid compact patterns like vm_define && vm_start followed by $? checks. Use explicit if ...; then ...; else ...; fi blocks for clarity and ShellCheck friendliness.


log_info "----------- KVM Suspend -----------"

if virsh list --all | grep -q -w "$VM_NAME"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Here the log and command use $VM, while other scripts use $VM_NAME. Please keep naming consistent across the suite to avoid confusion.

@@ -0,0 +1,15 @@
metadata:
Copy link
Contributor

Choose a reason for hiding this comment

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

The YAML structure is very minimal. Please align these with the repository’s standard LAVA test definition style used by other suites in this repo.

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