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
112 changes: 112 additions & 0 deletions Runner/suites/Kernel/Baseport/dmabuf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# DMA-BUF Configuration Validation Test

## Overview

This test validates the DMA-BUF subsystem configuration on Qualcomm platforms, including kernel configuration, device tree setup, and system interfaces.

## Test Coverage

### 1. Kernel Configuration Validation
**Mandatory**:
- `CONFIG_DMA_SHARED_BUFFER CONFIG_DMABUF_HEAPS CONFIG_DMABUF_HEAPS_SYSTEM` - Core DMA-BUF support

**Optional but Recommended**:
- `CONFIG_DMA_HEAP` - Modern DMA heap interface
- `CONFIG_DMA_CMA` - Contiguous Memory Allocator
- `CONFIG_TEE_DMABUF_HEAPS`
- `CONFIG_HAS_DMA`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The README currently claims “Memory region sizes and configurations” under DT coverage, but the current run.sh does not actually parse/report reserved-memory sizes or configuration details. Please either align the README to the implementation or extend the script to match this claim.


### 2. Device Tree Validation
- Reserved memory nodes (`/proc/device-tree/reserved-memory`)
- Platform-specific DMA heap nodes
- Memory region sizes and configurations

## Usage

### Run directly:
```bash
cd /path/to/Runner/suites/Kernel/Baseport/dmabuf
./run.sh
```

### Run via test runner:
```bash
cd /path/to/Runner
./run-test.sh dmabuf
```

## Test Results

Generates:
- `dmabuf.res` - Final result (PASS/FAIL)
- Console output with detailed validation steps

## Prerequisites

### Required:
- `CONFIG_DMA_SHARED_BUFFER=y` in kernel config


## Expected Output

```
[INFO] 2026-03-23 12:39:05 - ================================================================================
[INFO] 2026-03-23 12:39:05 - ============ Starting dmabuf Testcase =======================================
[INFO] 2026-03-23 12:39:05 - ================================================================================
[INFO] 2026-03-23 12:39:05 - === Kernel Configuration Validation ===
[PASS] 2026-03-23 12:39:05 - Kernel config CONFIG_DMA_SHARED_BUFFER is enabled
[PASS] 2026-03-23 12:39:05 - Kernel config CONFIG_DMABUF_HEAPS is enabled
[PASS] 2026-03-23 12:39:06 - Kernel config CONFIG_DMABUF_HEAPS_SYSTEM is enabled
[PASS] 2026-03-23 12:39:06 - Core DMA-BUF configs available
[INFO] 2026-03-23 12:39:06 - Checking optional DMA-BUF configurations...
[PASS] 2026-03-23 12:39:06 - Kernel config CONFIG_TEE_DMABUF_HEAPS is enabled
[PASS] 2026-03-23 12:39:06 - CONFIG_TEE_DMABUF_HEAPS: enabled
[PASS] 2026-03-23 12:39:06 - Kernel config CONFIG_HAS_DMA is enabled
[PASS] 2026-03-23 12:39:06 - CONFIG_HAS_DMA: enabled
[WARN] 2026-03-23 12:39:06 - Kernel config CONFIG_DMA_HEAP is missing or not enabled
[WARN] 2026-03-23 12:39:06 - CONFIG_DMA_HEAP: not enabled (optional)
[WARN] 2026-03-23 12:39:06 - Kernel config CONFIG_DMA_CMA is missing or not enabled
[WARN] 2026-03-23 12:39:06 - CONFIG_DMA_CMA: not enabled (optional)
[INFO] 2026-03-23 12:39:06 - === Device Tree Validation ===
[INFO] 2026-03-23 12:39:06 - Found reserved-memory node
[INFO] 2026-03-23 12:39:06 - Region: adsp-region@95c00000
[INFO] 2026-03-23 12:39:06 - Region: adsp-rpc-remote-heap-region@94a00000
[INFO] 2026-03-23 12:39:06 - Region: aop-cmd-db-region@90860000
[INFO] 2026-03-23 12:39:06 - Region: aop-image-region@90800000
[INFO] 2026-03-23 12:39:06 - Region: camera-region@95200000
[INFO] 2026-03-23 12:39:06 - Region: cdsp-region@99980000
[INFO] 2026-03-23 12:39:06 - Region: cvp-region@9b782000
[INFO] 2026-03-23 12:39:06 - Region: gpdsp-region@97b00000
[INFO] 2026-03-23 12:39:06 - Region: gpu-microcode-region@9b780000
[INFO] 2026-03-23 12:39:06 - Region: lpass-machine-learning-region@93b00000
[INFO] 2026-03-23 12:39:06 - Region: q6-adsp-dtb-region@97a00000
[INFO] 2026-03-23 12:39:06 - Region: q6-cdsp-dtb-region@99900000
[INFO] 2026-03-23 12:39:06 - Region: q6-gpdsp-dtb-region@97a80000
[INFO] 2026-03-23 12:39:06 - Region: smem@90900000
[INFO] 2026-03-23 12:39:06 - Region: video-region@9be82000
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/soc*/dma* /proc/device-tree/soc*/qcom,ion* /proc/device-tree/ion*
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/soc@0/dma-controller@1dc4000
[PASS] 2026-03-23 12:39:06 - Device tree node exists: /proc/device-tree/soc@0/dma-controller@1dc4000
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/soc@0/dma-controller@900000
[PASS] 2026-03-23 12:39:06 - Device tree node exists: /proc/device-tree/soc@0/dma-controller@900000
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/soc@0/dma-controller@a00000
[PASS] 2026-03-23 12:39:06 - Device tree node exists: /proc/device-tree/soc@0/dma-controller@a00000
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/soc@0/dma-controller@b00000
[PASS] 2026-03-23 12:39:06 - Device tree node exists: /proc/device-tree/soc@0/dma-controller@b00000
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/soc*/qcom,ion*
[INFO] 2026-03-23 12:39:06 - /proc/device-tree/ion*
[PASS] 2026-03-23 12:39:06 - At least one node was found.
[PASS] 2026-03-23 12:39:06 - Device tree validation passed (found 1 relevant nodes)
[INFO] 2026-03-23 12:39:06 - Found DMA heap device directory: /dev/dma_heap
[PASS] 2026-03-23 12:39:06 - Available heap: system
[PASS] 2026-03-23 12:39:06 - Total heaps found: 1
[INFO] 2026-03-23 12:39:06 - DMA-BUF buffer information:
[INFO] 2026-03-23 12:39:06 - Total DMA-BUF buffers: 1
[PASS] 2026-03-23 12:39:06 - dmabuf : Test Passed
[INFO] 2026-03-23 12:39:06 - -------------------Completed dmabuf Testcase----------------------------
```

## License

Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
SPDX-License-Identifier: BSD-3-Clause
23 changes: 23 additions & 0 deletions Runner/suites/Kernel/Baseport/dmabuf/dmabuf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
metadata:
format: Lava-Test Test Definition 1.0
name: dmabuf
description: "DMA-BUF kernel configuration and device tree validation"
maintainer:
- vnarapar@qti.qualcomm.com
os:
- openembedded
scope:
- functional
devices:
- rb3gen2
- qcs6490
- qcs8300
- qcs9100
- sa8775p

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/Kernel/Baseport/dmabuf
- ./run.sh
- $REPO_PATH/Runner/utils/send-to-lava.sh dmabuf.res
145 changes: 145 additions & 0 deletions Runner/suites/Kernel/Baseport/dmabuf/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/sh

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

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

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use the unset-safe form here:

if [ -z "${__INIT_ENV_LOADED:-}" ]; then

Expanding "$__INIT_ENV_LOADED" directly is less robust when the variable is unset.

# shellcheck disable=SC1090
. "$INIT_ENV"
fi

# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="dmabuf"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1
res_file="./$TESTNAME.res"

log_info "================================================================================"
log_info "============ Starting $TESTNAME Testcase ======================================="
log_info "================================================================================"

check_dependencies "find grep basename"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check_dependencies is called here, but its return code is not used. Can we gate this properly and SKIP early if required tools are missing, following the standard testkit dependency-check pattern?


pass=true

log_info "=== Kernel Configuration Validation ==="

if [ ! -f /proc/config.gz ]; then
log_warn "/proc/config.gz not found — kernel config checks will be skipped"
log_warn "Ensure CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC are enabled in the kernel"
else
CORE_CONFIGS="CONFIG_DMA_SHARED_BUFFER CONFIG_DMABUF_HEAPS CONFIG_DMABUF_HEAPS_SYSTEM"

if ! check_kernel_config "$CORE_CONFIGS"; then
log_fail "Core DMA-BUF kernel config validation failed"
pass=false
else
log_pass "Core DMA-BUF configs available"
fi

OPTIONAL_CONFIGS="CONFIG_TEE_DMABUF_HEAPS CONFIG_HAS_DMA CONFIG_DMA_HEAP CONFIG_DMA_CMA"

log_info "Checking optional DMA-BUF configurations..."
for cfg in $OPTIONAL_CONFIGS; do
if check_optional_config "$cfg" 2>/dev/null; then
log_pass " $cfg: enabled"
else
log_warn " $cfg: not enabled (optional)"
fi
done
fi

log_info "=== Device Tree Validation ==="

found_nodes=0

if [ -d "/proc/device-tree/reserved-memory" ]; then
log_info "Found reserved-memory node"

for region in /proc/device-tree/reserved-memory/*; do
if [ -d "$region" ]; then
region_name=$(basename "$region")
log_info " Region: $region_name"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This reserved-memory enumeration is useful as info, but it is not really DMA-BUF-specific validation yet. Can we either narrow this to relevant DMA-BUF/heap-related nodes or clearly keep it informational in the README/log wording?

fi
done
fi

if check_dt_nodes "/proc/device-tree/soc*/dma* /proc/device-tree/soc*/qcom,ion* /proc/device-tree/ion*"; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good to reuse check_dt_nodes(), but these patterns are still very generic (soc*/dma*, qcom,ion*, ion*). Generic DMA controller nodes can exist even when the DMA-BUF heap configuration we care about is not really validated. Can we narrow these checks or explain why these are the right DT signals for this testcase?

log_pass "At least one node was found."
found_nodes=$((found_nodes + 1))
else
log_fail "None of the requested nodes were found."
echo "$TESTNAME FAIL" > "$res_file"
exit 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please do not exit immediately here after writing FAIL. This bypasses the usual summary/end-of-test flow. Better to set pass=false and let the script finish consistently through the common result path.

fi

if [ "$found_nodes" -gt 0 ]; then
log_pass "Device tree validation passed (found $found_nodes relevant nodes)"
else
log_fail "No DMA-BUF specific device-tree nodes found"
pass=false
fi

# Check for DMA heap devices
if [ -d "/dev/dma_heap" ]; then
log_info "Found DMA heap device directory: /dev/dma_heap"

heap_count=0
for heap in /dev/dma_heap/*; do
if [ -e "$heap" ]; then
heap_name=$(basename "$heap")
log_pass " Available heap: $heap_name"
heap_count=$((heap_count + 1))
fi
done
log_pass "Total heaps found: $heap_count"
else
log_fail "DMA heap device directory not found"
pass=false
fi

if [ -f "/sys/kernel/debug/dma_buf/bufinfo" ]; then
log_info "DMA-BUF buffer information:"

# Count total buffers
total_bufs=$(grep -c "^Dma-buf" /sys/kernel/debug/dma_buf/bufinfo 2>/dev/null || echo 0)
log_info " Total DMA-BUF buffers: $total_bufs"

# Calculate total size (if available)
if grep -q "size:" /sys/kernel/debug/dma_buf/bufinfo 2>/dev/null; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bufinfo is useful, but if this visibility check depends on debugfs, should we do a best-effort debugfs mount first (or at least log explicitly that this part is conditional on debugfs being mounted)? Right now this silently downgrades part of the validation to WARN-only.

total_size=$(awk '/size:/ {sum+=$2} END {print sum}' /sys/kernel/debug/dma_buf/bufinfo 2>/dev/null || echo 0)
total_size_mb=$((total_size / 1024 / 1024))
log_info " Total DMA-BUF memory: ${total_size_mb} MB"
fi
else
log_warn "DMA-BUF bufinfo not available (debugfs may not be mounted)"
fi

if $pass; then
log_pass "$TESTNAME : Test Passed"
echo "$TESTNAME PASS" > "$res_file"
else
log_fail "$TESTNAME : Test Failed"
echo "$TESTNAME FAIL" > "$res_file"
fi
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
exit 0
Loading
Loading