Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Runner/suites/Virtualization/KVM/KVM_Driver/KVM_Driver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
metadata:
name: KVM_Driver
format: "Lava-Test Test Definition 1.0"
description: "Validate /dev/kvm device node and KVM ioctl API"
maintainer:
- Srikanth kumar
os:
- linux
scope:
- functional

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/Virtualization/KVM/KVM_Driver
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh KVM_Driver.res
183 changes: 183 additions & 0 deletions Runner/suites/Virtualization/KVM/KVM_Driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# KVM_Driver

## Overview

`KVM_Driver` validates the mandatory KVM host configuration, `/dev/kvm`
runtime device node, and KVM userspace ioctl API.

This test now covers the baseline KVM boot/config validation that was previously
covered separately by `KVM_Boot_Up`, and then performs a stronger functional
driver check by opening `/dev/kvm`, validating the KVM API version, and
attempting a safe `KVM_CREATE_VM` ioctl through the shared `lib_kvm.sh` helper.

This test does not launch QEMU and does not boot a guest VM.

## Test location

```text
Runner/suites/Virtualization/KVM/KVM_Driver/
```

## Files

```text
run.sh
KVM_Driver.yaml
README.md
```

## Dependencies

The test uses common helpers from:

```text
Runner/utils/functestlib.sh
Runner/utils/lib_kvm.sh
```

Required target utilities:

```text
cat grep awk sed tr mkdir uname
```

Additional helper dependency:

```text
python3
```

`python3` is used by `kvm_check_api_version()` to issue the `/dev/kvm` ioctl
checks without requiring a prebuilt C helper binary. If `python3` is not
present, the test reports `SKIP`.

## Validation coverage

The test validates:

1. Mandatory kernel config support:
- `CONFIG_VIRTUALIZATION`
- `CONFIG_KVM`

2. Optional KVM-related configs are logged when visible:
- `CONFIG_HAVE_KVM`
- `CONFIG_HAVE_KVM_IRQCHIP`
- `CONFIG_HAVE_KVM_IRQFD`
- `CONFIG_KVM_ARM_PMU`
- `CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT`

3. Runtime device node:
- `/dev/kvm` exists
- `/dev/kvm` is a character device
- `/dev/kvm` is readable and writable

4. KVM API ioctl path:
- `open("/dev/kvm")`
- `KVM_GET_API_VERSION`
- API version must be `12`
- `KVM_CREATE_VM`

5. Kernel log scan:
- checks for fatal KVM/EL2/HYP/GIC related runtime errors

## Result policy

### PASS

The test reports `PASS` when:

- mandatory KVM configs are enabled,
- `/dev/kvm` is present and accessible,
- KVM ioctl API validation passes,
- no fatal KVM/EL2 errors are detected in kernel logs.

### SKIP

The test reports `SKIP` when:

- `python3` is not available for the ioctl helper,
- required userspace utilities are missing,
- the testcase path or setup environment cannot be resolved before test
execution starts.

### FAIL

The test reports `FAIL` when:

- `CONFIG_VIRTUALIZATION` is not enabled,
- `CONFIG_KVM` is not enabled,
- `/dev/kvm` is not present,
- `/dev/kvm` exists but is not usable,
- KVM ioctl API validation fails,
- fatal KVM/EL2/HYP related errors are detected in kernel logs.

## Manual execution

From the repository root on target:

```sh
cd Runner/suites/Virtualization/KVM/KVM_Driver
./run.sh
cat KVM_Driver.res
```

Expected result file:

```text
KVM_Driver PASS
```

or:

```text
KVM_Driver SKIP
```

or:

```text
KVM_Driver FAIL
```

## LAVA execution

The YAML file runs:

```sh
cd Runner/suites/Virtualization/KVM/KVM_Driver
./run.sh || true
$REPO_PATH/Runner/utils/send-to-lava.sh KVM_Driver.res
```

## Logs

The test creates logs under:

```text
results/KVM_Driver/
```

KVM/EL2 dmesg logs are captured under:

```text
results/KVM_Driver/dmesg/
```

## Notes

`KVM_Driver` intentionally includes the baseline KVM boot/config checks so a
separate `KVM_Boot_Up` test is not required.

This test does not launch QEMU or boot a guest VM. That coverage belongs to:

```text
KVM_Infra
QEMU_VM_Validation
```

This test also does not validate EL2-DTB remoteproc/IOMMU evidence. That is
covered by:

```text
KVM_EL2_DTB
```
152 changes: 152 additions & 0 deletions Runner/suites/Virtualization/KVM/KVM_Driver/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause

TESTNAME="KVM_Driver"

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"

while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

RES_FALLBACK="$SCRIPT_DIR/${TESTNAME}.res"
Comment thread
smuppand marked this conversation as resolved.

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
echo "$TESTNAME SKIP" >"$RES_FALLBACK" 2>/dev/null || true
exit 0
fi

# Only source if not already loaded (idempotent)
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
__INIT_ENV_LOADED=1
fi

# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

# Source KVM helper library
# shellcheck disable=SC1090,SC1091
. "$TOOLS/lib_kvm.sh"

test_path=$(find_test_case_by_name "$TESTNAME")
if [ -z "$test_path" ] || [ ! -d "$test_path" ]; then
log_skip "$TESTNAME SKIP - test path not found"
echo "$TESTNAME SKIP" >"$RES_FALLBACK" 2>/dev/null || true
exit 0
fi

if ! cd "$test_path"; then
log_skip "$TESTNAME SKIP - cannot cd into $test_path"
echo "$TESTNAME SKIP" >"$RES_FALLBACK" 2>/dev/null || true
exit 0
fi

# shellcheck disable=SC2034
res_file="./$TESTNAME.res"
RESULT_DIR="./results/$TESTNAME"
DMESG_DIR="$RESULT_DIR/dmesg"

mkdir -p "$DMESG_DIR" 2>/dev/null || true

log_info "-----------------------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="

deps_list="cat grep awk sed tr mkdir uname"
log_info "Checking dependencies: $deps_list"
if ! check_dependencies "$deps_list"; then
log_skip "$TESTNAME SKIP - missing one or more dependencies: $deps_list"
echo "$TESTNAME SKIP" >"$res_file"
exit 0
fi

if command -v detect_platform >/dev/null 2>&1; then
detect_platform >/dev/null 2>&1 || true
log_info "Platform Details: machine='${PLATFORM_MACHINE:-unknown}' target='${PLATFORM_TARGET:-unknown}' kernel='${PLATFORM_KERNEL:-}' arch='${PLATFORM_ARCH:-}'"
else
log_info "Platform Details: kernel='$(uname -r 2>/dev/null || echo unknown)' arch='$(uname -m 2>/dev/null || echo unknown)'"
fi

log_info "=== KVM Kernel Config Validation ==="

mandatory_cfg_missing=0

for cfg in CONFIG_VIRTUALIZATION CONFIG_KVM; do
if ! check_kernel_config "$cfg"; then
mandatory_cfg_missing=1
fi
done

if [ "$mandatory_cfg_missing" -ne 0 ]; then
log_fail "$TESTNAME FAIL - mandatory KVM kernel config is missing"
echo "$TESTNAME FAIL" >"$res_file"
exit 0
fi

# Optional configs: log only, do not gate test result.
for cfg in \
CONFIG_HAVE_KVM \
CONFIG_HAVE_KVM_IRQCHIP \
CONFIG_HAVE_KVM_IRQFD \
CONFIG_KVM_ARM_PMU \
CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
do
kvm_log_optional_kernel_config "$cfg" || true
done

log_info "=== KVM Device Node Validation ==="
kvm_check_device_node
dev_rc=$?

if [ "$dev_rc" -eq 2 ]; then
log_fail "$TESTNAME FAIL - /dev/kvm is not available"
echo "$TESTNAME FAIL" >"$res_file"
exit 0
fi

if [ "$dev_rc" -ne 0 ]; then
Comment thread
smuppand marked this conversation as resolved.
log_fail "$TESTNAME FAIL - /dev/kvm node validation failed"
echo "$TESTNAME FAIL" >"$res_file"
exit 0
fi

log_info "=== KVM ioctl API Validation ==="
kvm_check_api_version
api_rc=$?

if [ "$api_rc" -eq 2 ]; then
log_skip "$TESTNAME SKIP - KVM API helper dependency is not available"
echo "$TESTNAME SKIP" >"$res_file"
exit 0
fi

if [ "$api_rc" -ne 0 ]; then
log_fail "$TESTNAME FAIL - KVM ioctl API validation failed"
echo "$TESTNAME FAIL" >"$res_file"
exit 0
fi

log_info "=== KVM Driver Dmesg Validation ==="
if ! kvm_check_boot_dmesg_errors "$DMESG_DIR"; then
log_fail "$TESTNAME FAIL - fatal KVM/EL2 dmesg errors detected"
echo "$TESTNAME FAIL" >"$res_file"
exit 0
fi

log_pass "$TESTNAME PASS - KVM kernel config, /dev/kvm, and ioctl API are valid"
echo "$TESTNAME PASS" >"$res_file"

log_info "-------------------Completed $TESTNAME Testcase----------------------------"
exit 0
17 changes: 17 additions & 0 deletions Runner/suites/Virtualization/KVM/KVM_EL2_DTB/KVM_EL2_DTB.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
metadata:
name: KVM_EL2_DTB
format: "Lava-Test Test Definition 1.0"
description: "Validate dynamic EL2-DTB remoteproc/IOMMU runtime evidence for KVM boot"
maintainer:
- Srikanth kumar
os:
- linux
scope:
- functional

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/Virtualization/KVM/KVM_EL2_DTB
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh KVM_EL2_DTB.res
Loading
Loading