-
Notifications
You must be signed in to change notification settings - Fork 32
Added automation of Virsh commands #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| metadata: | ||
| name: kvm-reboot | ||
| format: "Lava-Test Test Definition 1.0" | ||
| description: "Reboot an active Gunyah KVM Virtual Machine" | ||
| os: | ||
| - linux | ||
| scope: | ||
| - functional | ||
|
|
||
| run: | ||
| steps: | ||
| - REPO_PATH=$PWD | ||
| - cd Runner/suites/Kernel/Virtualization/Kvm-Reboot | ||
| - ./run.sh || true | ||
| - $REPO_PATH/Runner/utils/send-to-lava.sh Kvm-Reboot.res || true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Kvm-Reboot Test | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few README copy-paste errors and SPDX inconsistencies that should be cleaned up. |
||
| © Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| ## Overview | ||
| This test validates the reboot functionality of the Guest VM. It issues a reboot command via `virsh` and ensures the VM returns to a running state. | ||
|
|
||
| ### The test checks for: | ||
| - Successful execution of `virsh reboot`. | ||
| - VM returning to **"running"** state. | ||
|
|
||
| ## Usage | ||
| ### Quick Example | ||
| ```bash | ||
| cd /var/Runner/suites/Kernel/Virtualization/Kvm-Reboot | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| ### Result Format | ||
| Test result will be saved in Kvm-Reboot.res. | ||
|
|
||
| ### Output | ||
| Kvm-Reboot PASS OR Kvm-Reboot FAIL | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| # Robustly find and source init_env | ||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| SEARCH_PATH="$SCRIPT_DIR" | ||
| LIB_PATH="" | ||
| while [ "$SEARCH_PATH" != "/" ]; do | ||
| if [ -f "$SEARCH_PATH/utils/kvm_common.sh" ]; then | ||
| LIB_PATH="$SEARCH_PATH/utils/kvm_common.sh" | ||
| break | ||
| fi | ||
| SEARCH_PATH=$(dirname "$SEARCH_PATH") | ||
| done | ||
|
|
||
| if [ -f "$LIB_PATH" ]; then | ||
| # shellcheck disable=SC1090 | ||
| . "$LIB_PATH" | ||
| else | ||
| echo "[ERROR] Lib not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| TESTNAME="Kvm-Reboot" | ||
| RES_FILE="${TESTNAME}.res" | ||
| rm -f "$RES_FILE" | ||
|
|
||
| # Clean up old stdout logs from previous runs | ||
| rm -f *_stdout_*.log | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| log_info "----------- KVM Reboot -----------" | ||
|
|
||
| if virsh list --all | grep -q -w "$VM_NAME"; then | ||
| log_info "Existing VM instance found. Cleaning up..." | ||
| vm_clean | ||
| fi | ||
|
|
||
| vm_define && vm_start | ||
| if [ $? -ne 0 ]; then echo "$TESTNAME FAIL" > "$RES_FILE"; exit 1; fi | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| # Test: Reboot | ||
| log_info "Rebooting $VM_NAME" | ||
| virsh reboot "$VM_NAME" | ||
| sleep 5 | ||
|
|
||
| # Verify Running | ||
| check_vm_state "$VM_NAME" "running" | ||
| if [ $? -eq 0 ]; then | ||
| log_pass "VM rebooted successfully." | ||
| echo "$TESTNAME PASS" > "$RES_FILE" | ||
| else | ||
| log_fail "VM not running after reboot." | ||
| echo "$TESTNAME FAIL" > "$RES_FILE" | ||
| fi | ||
|
|
||
| # Cleanup | ||
| vm_clean | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| metadata: | ||
| name: kvm-resume | ||
| format: "Lava-Test Test Definition 1.0" | ||
| description: "Resume a paused Gunyah KVM Virtual Machine" | ||
| os: | ||
| - linux | ||
| scope: | ||
| - functional | ||
|
|
||
| run: | ||
| steps: | ||
| - REPO_PATH=$PWD | ||
| - cd Runner/suites/Kernel/Virtualization/Kvm-Resume | ||
| - ./run.sh || true | ||
| - $REPO_PATH/Runner/utils/send-to-lava.sh Kvm-Resume.res || true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Kvm-Resume Test | ||
| © Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| ## Overview | ||
| This test validates that a suspended VM can be resumed to active execution. | ||
|
|
||
| ### The test checks for: | ||
| - Successful execution of `virsh resume`. | ||
| - VM state transition back to **"running"**. | ||
|
|
||
| ## Usage | ||
| ### Quick Example | ||
| ```bash | ||
| cd /var/Runner/suites/Kernel/Virtualization/Kvm-Resume | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| ### Result Format | ||
| Test result will be saved in Kvm-Reboot.res. | ||
|
|
||
| ### Output | ||
| Kvm-Reboot PASS OR Kvm-Reboot FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| # Robustly find and source init_env | ||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| SEARCH_PATH="$SCRIPT_DIR" | ||
| LIB_PATH="" | ||
| while [ "$SEARCH_PATH" != "/" ]; do | ||
| if [ -f "$SEARCH_PATH/utils/kvm_common.sh" ]; then | ||
| LIB_PATH="$SEARCH_PATH/utils/kvm_common.sh" | ||
| break | ||
| fi | ||
| SEARCH_PATH=$(dirname "$SEARCH_PATH") | ||
| done | ||
|
|
||
| if [ -f "$LIB_PATH" ]; then | ||
| # shellcheck disable=SC1090 | ||
| . "$LIB_PATH" | ||
| else | ||
| echo "[ERROR] Lib not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| TESTNAME="Kvm-Resume" | ||
| RES_FILE="${TESTNAME}.res" | ||
| rm -f "$RES_FILE" | ||
|
|
||
| # Clean up old stdout logs from previous runs | ||
| rm -f *_stdout_*.log | ||
|
|
||
| log_info "----------- KVM Resume -----------" | ||
|
|
||
| if virsh list --all | grep -q -w "$VM_NAME"; then | ||
| log_info "Existing VM instance found. Cleaning up..." | ||
| vm_clean | ||
| fi | ||
|
|
||
| vm_define && vm_start | ||
| if [ $? -ne 0 ]; then echo "$TESTNAME FAIL" > "$RES_FILE"; exit 1; fi | ||
|
|
||
| # Pre-req: Must be suspended first | ||
| log_info "Suspending VM for resume test..." | ||
| virsh suspend "$VM_NAME" | ||
| sleep 2 | ||
|
|
||
| # Test: Resume | ||
| log_info "Resuming $VM_NAME" | ||
| virsh resume "$VM_NAME" | ||
|
|
||
| # Verify Running | ||
| check_vm_state "$VM_NAME" "running" | ||
| if [ $? -eq 0 ]; then | ||
| log_pass "VM resumed successfully." | ||
| echo "$TESTNAME PASS" > "$RES_FILE" | ||
| else | ||
| log_fail "VM failed to resume." | ||
| echo "$TESTNAME FAIL" > "$RES_FILE" | ||
| fi | ||
|
|
||
| # Cleanup | ||
| vm_clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| metadata: | ||
| name: kvm-setup | ||
| format: "Lava-Test Test Definition 1.0" | ||
| description: "Setup and Start Gunyah KVM Virtual Machine" | ||
| os: | ||
| - linux | ||
| scope: | ||
| - functional | ||
|
|
||
| run: | ||
| steps: | ||
| - REPO_PATH=$PWD | ||
| - cd Runner/suites/Kernel/Virtualization/Kvm-Setup | ||
| - ./run.sh || true | ||
| - $REPO_PATH/Runner/utils/send-to-lava.sh Kvm-Setup.res || true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Kvm-Setup Test | ||
| © Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| ## Overview | ||
| This test case initializes the KVM environment by defining the Virtual Machine using an XML configuration and starting the domain. It verifies that the VM transitions to the `running` state. | ||
|
|
||
| ### The test checks for: | ||
| - Successful **definition** of the VM from `vm.xml`. | ||
| - Successful **start** command execution. | ||
| - Verification that the VM state is **"running"**. | ||
|
|
||
| ## Usage | ||
| ### Instructions: | ||
| 1. Ensure the `vm.xml` and guest image files are present in `/var/gunyah/`. | ||
| 2. Navigate to the test directory. | ||
| 3. Run the script. | ||
|
|
||
| ### Quick Example | ||
| ```bash | ||
| cd /var/Runner/suites/Kernel/Virtualization/Kvm-Setup | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| ### Prerequisites | ||
| 1. virsh tool must be installed. | ||
| 2. Gunyah hypervisor must be enabled. | ||
| 3. Root access is required. | ||
|
|
||
| ### Result Format | ||
| Test result will be saved in Kvm-Setup.res. | ||
|
|
||
| ### Output | ||
| Kvm-Setup PASS OR Kvm-Setup FAIL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| # Robustly find and source init_env | ||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| SEARCH_PATH="$SCRIPT_DIR" | ||
| LIB_PATH="" | ||
| while [ "$SEARCH_PATH" != "/" ]; do | ||
| if [ -f "$SEARCH_PATH/utils/kvm_common.sh" ]; then | ||
| LIB_PATH="$SEARCH_PATH/utils/kvm_common.sh" | ||
| break | ||
| fi | ||
| SEARCH_PATH=$(dirname "$SEARCH_PATH") | ||
| done | ||
|
|
||
| if [ -f "$LIB_PATH" ]; then | ||
| # shellcheck disable=SC1090 | ||
| . "$LIB_PATH" | ||
| else | ||
| echo "[ERROR] Lib not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Define Test Metadata | ||
| TESTNAME="Kvm-Setup" | ||
| RES_FILE="${TESTNAME}.res" | ||
|
|
||
| # Clean up old stdout logs from previous runs | ||
| rm -f *_stdout_*.log | ||
|
|
||
| # Execution | ||
| log_info "----------- KVM Setup: Define and Start -----------" | ||
|
|
||
| # Clean up any existing result file | ||
| rm -f "$RES_FILE" | ||
|
|
||
| # Define VM | ||
| if virsh list --all | grep -q -w "$VM_NAME"; then | ||
| log_info "Existing VM instance found. Cleaning up..." | ||
| vm_clean | ||
| fi | ||
|
|
||
| # 2. Define | ||
| vm_define | ||
| if [ $? -ne 0 ]; then echo "$TESTNAME FAIL" > "$RES_FILE"; exit 1; fi | ||
|
|
||
| # 3. Start | ||
| vm_start | ||
| if [ $? -ne 0 ]; then echo "$TESTNAME FAIL" > "$RES_FILE"; exit 1; fi | ||
|
|
||
| # 4. Verify | ||
| check_vm_state "$VM_NAME" "running" | ||
| if [ $? -eq 0 ]; then | ||
| log_pass "VM is running." | ||
| echo "$TESTNAME PASS" > "$RES_FILE" | ||
| else | ||
| log_fail "VM failed to reach 'running' state." | ||
| echo "$TESTNAME FAIL" > "$RES_FILE" | ||
| exit 1 | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| metadata: | ||
| name: kvm-suspend | ||
| format: "Lava-Test Test Definition 1.0" | ||
| description: "Suspend a running Gunyah KVM Virtual Machine" | ||
| os: | ||
| - linux | ||
| scope: | ||
| - functional | ||
|
|
||
| run: | ||
| steps: | ||
| - REPO_PATH=$PWD | ||
| - cd Runner/suites/Kernel/Virtualization/Kvm-Suspend | ||
| - ./run.sh || true | ||
| - $REPO_PATH/Runner/utils/send-to-lava.sh Kvm-Suspend.res || true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Kvm-Suspend Test | ||
| © Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| ## Overview | ||
| This test checks the ability to suspend (pause) the execution of the Guest VM. | ||
|
|
||
| ### The test checks for: | ||
| - Successful execution of `virsh suspend`. | ||
| - VM state transition to **"paused"**. | ||
|
|
||
| ## Usage | ||
| ### Quick Example | ||
| ```bash | ||
| cd /var/Runner/suites/Kernel/Virtualization/Kvm-Suspend | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| ### Result Format | ||
| Test result will be saved in Kvm-Suspend.res. | ||
|
|
||
| ### Output | ||
| Kvm-Suspend PASS OR Kvm-Suspend FAIL |
There was a problem hiding this comment.
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.