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
113 changes: 113 additions & 0 deletions Runner/suites/Kernel/Baseport/dmabuf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# 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 CONFIG_TEE_DMABUF_HEAPS CONFIG_HAS_DMA` - Core DMA-BUF support
Copy link
Contributor

Choose a reason for hiding this comment

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

In run.sh they are WARN-only (good), but README shows FAIL lines for optional configs. That’s confusing. Update README expected output to show WARN/INFO for optional configs only.


**Optional but Recommended**:
- `CONFIG_DMA_HEAP` - Modern DMA heap interface
- `CONFIG_DMA_CMA` - Contiguous Memory Allocator

### 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

```
[Executing test case: dmabuf] 1970-01-01 09:29:40 -
[INFO] 1970-01-01 09:29:40 - ================================================================================
[INFO] 1970-01-01 09:29:40 - ============ Starting dmabuf Testcase =======================================
[INFO] 1970-01-01 09:29:40 - ================================================================================
[INFO] 1970-01-01 09:29:40 - === Kernel Configuration Validation ===
[PASS] 1970-01-01 09:29:40 - Kernel config CONFIG_DMA_SHARED_BUFFER is enabled
[PASS] 1970-01-01 09:29:41 - Kernel config CONFIG_DMABUF_HEAPS is enabled
[PASS] 1970-01-01 09:29:41 - Kernel config CONFIG_DMABUF_HEAPS_SYSTEM is enabled
[PASS] 1970-01-01 09:29:41 - Kernel config CONFIG_TEE_DMABUF_HEAPS is enabled
[PASS] 1970-01-01 09:29:41 - Kernel config CONFIG_HAS_DMA is enabled
[PASS] 1970-01-01 09:29:41 - Core DMA-BUF configs available
[INFO] 1970-01-01 09:29:41 - Checking optional DMA-BUF configurations...
[FAIL] 1970-01-01 09:29:41 - Kernel config CONFIG_DMA_HEAP is missing or not enabled
[WARN] 1970-01-01 09:29:41 - CONFIG_DMA_HEAP: not enabled (optional)
[FAIL] 1970-01-01 09:29:41 - Kernel config CONFIG_DMA_CMA is missing or not enabled
[WARN] 1970-01-01 09:29:41 - CONFIG_DMA_CMA: not enabled (optional)
[INFO] 1970-01-01 09:29:41 - === Device Tree Validation ===
[INFO] 1970-01-01 09:29:41 - Found reserved-memory node
[INFO] 1970-01-01 09:29:41 - Region: adsp-rpc-remote-heap@9cb80000
[INFO] 1970-01-01 09:29:41 - Region: adsp@86100000
[INFO] 1970-01-01 09:29:41 - Region: aop-cmd-db@80860000
[INFO] 1970-01-01 09:29:41 - Region: aop@80800000
[INFO] 1970-01-01 09:29:41 - Region: camera@84300000
[INFO] 1970-01-01 09:29:41 - Region: cdsp-secure-heap@81800000
[INFO] 1970-01-01 09:29:41 - Region: cdsp@88900000
[INFO] 1970-01-01 09:29:41 - Region: cpucp@80b00000
[INFO] 1970-01-01 09:29:41 - Region: cvp@8ae00000
[INFO] 1970-01-01 09:29:41 - Region: debug-vm@d0600000
[INFO] 1970-01-01 09:29:41 - Region: gpu-microcode@8b31a000
[INFO] 1970-01-01 09:29:41 - Region: hyp@80000000
[INFO] 1970-01-01 09:29:41 - Region: ipa-fw@8b300000
[INFO] 1970-01-01 09:29:41 - Region: ipa-gsi@8b310000
[INFO] 1970-01-01 09:29:41 - Region: mpss@8b800000
[INFO] 1970-01-01 09:29:41 - Region: qtee@c1300000
[INFO] 1970-01-01 09:29:41 - Region: sec-apps@808ff000
[INFO] 1970-01-01 09:29:41 - Region: smem@80900000
[INFO] 1970-01-01 09:29:41 - Region: tags@c0100000
[INFO] 1970-01-01 09:29:41 - Region: trusted-apps@c1800000
[INFO] 1970-01-01 09:29:41 - Region: tz-stat@c0000000
[INFO] 1970-01-01 09:29:41 - Region: video@8a700000
[INFO] 1970-01-01 09:29:41 - Region: wlan-fw@80c00000
[INFO] 1970-01-01 09:29:41 - Region: wpss@84800000
[INFO] 1970-01-01 09:29:41 - Region: xbl-uefi-res@80880000
[INFO] 1970-01-01 09:29:41 - Region: xbl@80700000
[INFO] 1970-01-01 09:29:41 - Region: zap@8b71a000
[INFO] 1970-01-01 09:29:41 - Found DMA heap node: /proc/device-tree/soc@0/dma-controller@1dc4000
[INFO] 1970-01-01 09:29:41 - Found DMA heap node: /proc/device-tree/soc@0/dma-controller@3a84000
[INFO] 1970-01-01 09:29:41 - Found DMA heap node: /proc/device-tree/soc@0/dma-controller@900000
[INFO] 1970-01-01 09:29:41 - Found DMA heap node: /proc/device-tree/soc@0/dma-controller@a00000
[INFO] 1970-01-01 09:29:41 - Found DMA heap node: /proc/device-tree/soc@0/dma-ranges
[INFO] 1970-01-01 09:29:41 - Found DMA heap node: /proc/device-tree/soc@0/dma@117f000
[PASS] 1970-01-01 09:29:41 - Device tree validation passed (found 6 relevant nodes)
[INFO] 1970-01-01 09:29:41 - Found DMA heap device directory: /dev/dma_heap
[PASS] 1970-01-01 09:29:41 - Available heap: system
[PASS] 1970-01-01 09:29:41 - Total heaps found: 1
[PASS] 1970-01-01 09:29:41 - dmabuf : Test Passed
[INFO] 1970-01-01 09:29:41 - -------------------Completed dmabuf Testcase----------------------------
```

## License

Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
SPDX-License-Identifier: BSD-3-Clause
21 changes: 21 additions & 0 deletions Runner/suites/Kernel/Baseport/dmabuf/dmabuf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
metadata:
format: Lava-Test Test Definition 1.0
name: dmabuf_config
Copy link
Contributor

Choose a reason for hiding this comment

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

Set YAML name: dmabuf (or rename test folder + TESTNAME + run-test invocation). Don’t mix.

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:
- cd $PWD/suites/Kernel/Baseport/dmabuf
- ./run.sh
119 changes: 119 additions & 0 deletions Runner/suites/Kernel/Baseport/dmabuf/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/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
# 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 "================================================================================"

pass=true

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

CORE_CONFIGS="CONFIG_DMA_SHARED_BUFFER CONFIG_DMABUF_HEAPS CONFIG_DMABUF_HEAPS_SYSTEM CONFIG_TEE_DMABUF_HEAPS CONFIG_HAS_DMA"
Copy link
Contributor

Choose a reason for hiding this comment

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

Core config list is likely too strict / not portable

You require:
CONFIG_TEE_DMABUF_HEAPS as mandatory
CONFIG_DMABUF_HEAPS_SYSTEM mandatory (fine if your baseline expects it)
CONFIG_HAS_DMA mandatory (almost always yes, but not the best signal)

On some upstream configs, TEE_DMABUF_HEAPS might not exist or may be module/disabled but DMA-BUF is still valid.
Recommendation Split “mandatory” into tiers:

Tier-1 mandatory (should fail if absent):
CONFIG_DMA_SHARED_BUFFER
CONFIG_DMABUF_HEAPS (if you’re standardizing on heaps)
optionally CONFIG_DMABUF_HEAPS_SYSTEM only if you require “system heap must exist”.

Tier-2 recommended (warn):
CONFIG_TEE_DMABUF_HEAPS
CONFIG_DMA_HEAP (note: this symbol name may differ across kernels; see below)
CONFIG_DMA_CMA (warn)

Also: there’s a confusion in README between CONFIG_DMA_HEAP and CONFIG_DMA_HEAP vs heaps framework. On upstream kernels, the feature is often CONFIG_DMABUF_HEAPS and the device nodes are /dev/dma_heap/*. Some trees have CONFIG_DMA_HEAP too, but not universal.


if ! check_kernel_config "$CORE_CONFIGS"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing dependency checks / permissions handling

This script assumes:
/proc/config.gz exists (functestlib check_kernel_config uses it)debugfs not needed here

listing /dev/dma_heap doesn’t need root (usually ok)
Use check_dependencies style (you already have it in functestlib).

log_fail "Core DMA-BUF kernel config validation failed"
pass=false
else
log_pass "Core DMA-BUF configs available"
fi

OPTIONAL_CONFIGS="CONFIG_DMA_HEAP CONFIG_DMA_CMA"

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

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"
fi
done
fi

for heap_path in /proc/device-tree/soc*/dma* /proc/device-tree/soc*/qcom,ion* /proc/device-tree/ion* ; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use dt related functions which are already available in functestlib.sh

if [ -e "$heap_path" ]; then
log_info "Found DMA heap node: $heap_path"
found_nodes=$((found_nodes + 1))
fi
done

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 $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
Copy link
Contributor

Choose a reason for hiding this comment

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

Kernel-functional extensions for dmabuf

Right now it’s “presence validation”. To make it functional without requiring special userspace:

Extension 1: Quick allocate/free sanity (if you have an allocator interface)
If /dev/dma_heap/system exists, you can do a minimal allocation test using upstream tool if present, otherwise skip:

Some environments have dma-heap test tools; most don’t.
So best is: detect helper binary (or your own tiny C helper in repo later).

For now:
Add a hook: “if dmabuf_heap_kselftest exists → suggest running that for functional coverage” (but don’t fail).

Extension 2: dmabuf sysfs/debug info (optional)
If present:
/sys/kernel/debug/dma_buf/bufinfo or similar (varies)
/proc/slabinfo for dmabuf-related caches (too noisy though)

Treat as INFO/WARN only.

B) Review: dmabuf_heap_kselftest (runs upstream selftest)

What’s good

Good CLI flag parser (--binary-path), POSIX-friendly.

Captures output to a file and prints it (good for LAVA artifacts and debugging).

Handles TAP totals line if present; otherwise counts ok/not ok/skip.

Issues / fixes needed

  1. README and usage mismatch

README says:

./run.sh /custom/path/to/dmabuf-heap

But the script does not accept positional path (it ignores positional args, only supports -b/--binary-path). It even prints:

log_info " ./run.sh /path/to/dmabuf-heap"

That instruction is wrong.

Fix Either:

support positional path (simpler), OR

fix README + log message to match --binary-path.

I’d recommend supporting positional path because it’s convenient and backwards compatible:

if $1 doesn’t start with -, treat it as binary path.

  1. OUTPUTFILE.res name is confusing and clashes with “.res”

You create:

output_file="./OUTPUTFILE.res"

That’s confusing in this repo because .res is the final verdict file. Also you delete it at end, so it’s not even an artifact.

Fix Use mktemp or ./dmabuf_heap_kselftest.out (or ./logs/... if you have standard log dirs). Better:

output_file="$(mktemp "$TESTNAME.XXXXXX.log")" with trap cleanup

or keep it and don’t delete so LAVA can archive it.

Given your earlier preferences: usually you keep logs.

  1. TAP parsing is fragile (spaces + grep -o portability)

This part:

pass_count=$(echo "$totals_line" | grep -o " pass:[0-9]*" | cut -d':' -f2)

grep -o isn’t guaranteed on very minimal busybox (often present, but not always).

The pattern includes leading space; ok, but still fragile.

Fix Parse with awk reliably:

extract numbers after pass: fail: etc.

Example robust parse:

pass_count=$(echo "$totals_line" | awk -F'pass:| ' '{print $2}' | awk -F' ' '{print $1}')

or one awk script.

  1. Counting ok lines double-counts SKIPs

Fallback:

pass_count=$(grep -c "^ok " ...)
skip_count=$(grep -c "# SKIP" ...)

But TAP marks skip as ok N # SKIP ..., so pass_count includes skipped tests. That leads to inflated pass count.

Fix When using fallback mode:

pass = ok lines that are NOT SKIP

skip = ok lines that are SKIP

Example:

skip_count=$(grep -c "^ok .*# SKIP" "$output_file")

pass_count=$(grep -c "^ok " "$output_file") - skip_count

  1. Exit code handling: inconsistent with “PASS if totals say fail=0”

You set:

pass=false if fail_count>0 OR error_count>0 OR exit_code!=0 OR pass_count==0.

That’s fine, but note:

Some selftests exit non-zero even when TAP shows pass (rare, but possible), or vice versa.

Best practice: trust TAP totals first; if totals show fail=0 and error=0, treat as pass even if exit code non-zero but log warn.

Fix Priority:

  1. If totals exist: use totals as source of truth; log exit code as info/warn.

  2. If no totals: use exit code + ok/not ok.

  1. Missing dependency checks

You use grep, awk, cut, mktemp not used but would be good, basename, etc.

Fix Add:

deps_list="grep awk cut basename date" (whatever your functestlib expects)

If missing -> SKIP, not FAIL.

Loading
Loading