From 7f4f1f9b5b0ac1d87b592b4ba609f59e96a76798 Mon Sep 17 00:00:00 2001 From: Vamsee Narapareddi Date: Sun, 15 Feb 2026 23:26:13 +0530 Subject: [PATCH] Added tests for dmabuf validations Added the tests to check DMA configs, Device Tree Validation and upstream kselftests Signed-off-by: Vamsee Narapareddi --- .../suites/Kernel/Baseport/dmabuf/README.md | 113 +++++++++ .../suites/Kernel/Baseport/dmabuf/dmabuf.yaml | 21 ++ Runner/suites/Kernel/Baseport/dmabuf/run.sh | 119 +++++++++ .../Baseport/dmabuf_heap_kselftest/README.md | 227 ++++++++++++++++++ .../dmabuf_heap_kselftest.yaml | 21 ++ .../Baseport/dmabuf_heap_kselftest/run.sh | 193 +++++++++++++++ 6 files changed, 694 insertions(+) create mode 100644 Runner/suites/Kernel/Baseport/dmabuf/README.md create mode 100755 Runner/suites/Kernel/Baseport/dmabuf/dmabuf.yaml create mode 100755 Runner/suites/Kernel/Baseport/dmabuf/run.sh create mode 100644 Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/README.md create mode 100755 Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/dmabuf_heap_kselftest.yaml create mode 100755 Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/run.sh diff --git a/Runner/suites/Kernel/Baseport/dmabuf/README.md b/Runner/suites/Kernel/Baseport/dmabuf/README.md new file mode 100644 index 00000000..d9ed8ca6 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/dmabuf/README.md @@ -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 + +**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 diff --git a/Runner/suites/Kernel/Baseport/dmabuf/dmabuf.yaml b/Runner/suites/Kernel/Baseport/dmabuf/dmabuf.yaml new file mode 100755 index 00000000..3fa31510 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/dmabuf/dmabuf.yaml @@ -0,0 +1,21 @@ +metadata: + format: Lava-Test Test Definition 1.0 + name: dmabuf_config + 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 diff --git a/Runner/suites/Kernel/Baseport/dmabuf/run.sh b/Runner/suites/Kernel/Baseport/dmabuf/run.sh new file mode 100755 index 00000000..01bbce6b --- /dev/null +++ b/Runner/suites/Kernel/Baseport/dmabuf/run.sh @@ -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" + +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_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 + 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 \ No newline at end of file diff --git a/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/README.md b/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/README.md new file mode 100644 index 00000000..2f5dbdb4 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/README.md @@ -0,0 +1,227 @@ +# DMA-BUF Heap Kselftest Test + +## Overview + +This test runs the `dmabuf-heap` binary from the Linux kernel selftests suite to validate DMA-BUF heap functionality. The test executes the kselftest binary, parses its TAP (Test Anything Protocol) output, and determines pass/fail based on the results. + +## What is dmabuf-heap kselftest? + +The `dmabuf-heap` kselftest is part of the Linux kernel's self-testing framework. It validates: +- DMA-BUF heap allocation and importing +- Buffer zeroing behavior +- Compatibility with older/newer allocation methods +- Error handling for invalid operations +- Integration with VGEM (Virtual GEM) driver + +## Test Coverage + +### 1. Binary Validation +- Checks if dmabuf-heap binary exists at specified path +- Verifies binary has execute permissions + +### 2. Test Execution +- Runs the dmabuf-heap kselftest binary +- Captures all output (stdout and stderr) +- Displays complete test output in logs + +### 3. TAP Output Parsing +- Parses TAP format output +- Extracts test counts (pass/fail/skip/error) +- Identifies skipped tests and reasons + +### 4. Result Determination +- Marks test as PASS if no failures or errors +- Marks test as FAIL if any test fails or errors occur +- Reports skipped tests as warnings (not failures) + +## Usage + +### Default Usage (uses default path): +```bash +cd /path/to/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest +./run.sh +``` + +This uses the default binary path: `/kselftest/dmabuf-heaps/dmabuf-heap` + +### Custom Binary Path: +```bash +cd /path/to/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest +./run.sh /custom/path/to/dmabuf-heap +``` + +### Via Test Runner: +```bash +cd /path/to/Runner +./run-test.sh dmabuf_heap_kselftest +``` + +## Test Results + +Generates: +- `dmabuf_heap_kselftest.res` - Final result (PASS/FAIL) +- Console output with complete test execution details + +## Prerequisites + +### Required: +- `dmabuf-heap` binary from kernel selftests +- DMA-BUF heap support in kernel (`CONFIG_DMA_HEAP`) +- Execute permissions on the binary + +### Optional: +- VGEM driver (`CONFIG_DRM_VGEM`) - for import/export tests +- CMA support (`CONFIG_DMA_CMA`) - for contiguous allocations + +## Expected Output + +### Successful Test Run: +``` +[INFO] 1970-01-01 10:20:21 - ================================================================================ +[INFO] 1970-01-01 10:20:21 - ============ Starting dmabuf_heap_kselftest Testcase ======================================= +[INFO] 1970-01-01 10:20:21 - ================================================================================ +[INFO] 1970-01-01 10:20:21 - DMA-BUF Heap Kselftest Binary Path: /kselftest/dmabuf-heaps/dmabuf-heap +[INFO] 1970-01-01 10:20:21 - === Checking for dmabuf-heap binary === +[PASS] 1970-01-01 10:20:21 - dmabuf-heap binary found and executable +[INFO] 1970-01-01 10:20:21 - === Running dmabuf-heap kselftest === +[INFO] 1970-01-01 10:20:21 - Executing: /kselftest/dmabuf-heaps/dmabuf-heap +[INFO] 1970-01-01 10:20:21 - Test output: +[INFO] 1970-01-01 10:20:21 - ---------------------------------------- +[INFO] 1970-01-01 10:20:21 - TAP version 13 +[INFO] 1970-01-01 10:20:21 - 1..11 +[INFO] 1970-01-01 10:20:21 - # Testing heap: system +[INFO] 1970-01-01 10:20:21 - # ======================================= +[INFO] 1970-01-01 10:20:21 - # Testing allocation and importing: +[INFO] 1970-01-01 10:20:21 - ok 1 # SKIP Could not open vgem -1 +[INFO] 1970-01-01 10:20:21 - ok 2 test_alloc_and_import dmabuf sync succeeded +[INFO] 1970-01-01 10:20:21 - # Testing alloced 4k buffers are zeroed: +[INFO] 1970-01-01 10:20:21 - ok 3 Allocate and fill a bunch of buffers +[INFO] 1970-01-01 10:20:21 - ok 4 Allocate and validate all buffers are zeroed +[INFO] 1970-01-01 10:20:21 - # Testing alloced 1024k buffers are zeroed: +[INFO] 1970-01-01 10:20:21 - ok 5 Allocate and fill a bunch of buffers +[INFO] 1970-01-01 10:20:21 - ok 6 Allocate and validate all buffers are zeroed +[INFO] 1970-01-01 10:20:21 - # Testing (theoretical) older alloc compat: +[INFO] 1970-01-01 10:20:21 - ok 7 dmabuf_heap_alloc_older +[INFO] 1970-01-01 10:20:21 - # Testing (theoretical) newer alloc compat: +[INFO] 1970-01-01 10:20:21 - ok 8 dmabuf_heap_alloc_newer +[INFO] 1970-01-01 10:20:21 - # Testing expected error cases: +[INFO] 1970-01-01 10:20:21 - ok 9 Error expected on invalid fd -1 +[INFO] 1970-01-01 10:20:21 - ok 10 Error expected on invalid heap flags -1 +[INFO] 1970-01-01 10:20:21 - ok 11 Error expected on invalid heap flags -1 +[INFO] 1970-01-01 10:20:21 - # 1 skipped test(s) detected. Consider enabling relevant config options to improve coverage. +[INFO] 1970-01-01 10:20:21 - # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:1 error:0 +[INFO] 1970-01-01 10:20:21 - ---------------------------------------- +[INFO] 1970-01-01 10:20:21 - Test summary: # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:1 error:0 +[INFO] 1970-01-01 10:20:21 - Passed: 10 +[INFO] 1970-01-01 10:20:21 - Failed: 0 +[INFO] 1970-01-01 10:20:21 - Skipped: 1 +[INFO] 1970-01-01 10:20:21 - Errors: 0 +[WARN] 1970-01-01 10:20:21 - 1 test(s) were skipped +[INFO] 1970-01-01 10:20:21 - Consider enabling relevant config options to improve coverage +[PASS] 1970-01-01 10:20:21 - All tests passed successfully (10 passed, 1 skipped) +[PASS] 1970-01-01 10:20:21 - dmabuf_heap_kselftest : Test Passed +``` + + +## Test Details + +### Test 1: Allocation and Importing +- Tests basic DMA-BUF allocation +- Tests importing buffers between devices +- Requires VGEM driver (skipped if not available) + +### Test 2-6: Buffer Zeroing +- Validates that newly allocated buffers are zeroed +- Tests with different buffer sizes (4KB, 1024KB) +- Ensures no data leakage from previous allocations + +### Test 7-8: Compatibility Tests +- Tests backward compatibility with older allocation methods +- Tests forward compatibility with newer allocation methods +- Ensures API stability + +### Test 9-11: Error Handling +- Tests invalid file descriptor handling +- Tests invalid heap flags +- Ensures proper error reporting + +## Troubleshooting + +### Binary Not Found +**Error**: `dmabuf-heap binary not found at: /kselftest/dmabuf-heaps/dmabuf-heap` + +**Solutions**: +1. Verify kselftest is installed on the system +2. Check the actual location of the binary: + ```bash + find / -name dmabuf-heap 2>/dev/null + ``` +3. Provide correct path as argument: + ```bash + ./run.sh /actual/path/to/dmabuf-heap + ``` + +### Binary Not Executable +**Error**: `dmabuf-heap binary is not executable` + +**Solution**: +```bash +chmod +x /kselftest/dmabuf-heaps/dmabuf-heap +``` + +### VGEM Tests Skipped +**Warning**: `ok 1 # SKIP Could not open vgem -1` + +**Cause**: VGEM driver not loaded or not available + +**Solution** (optional - not required for test to pass): +```bash +# Load VGEM module +modprobe vgem + +# Or enable in kernel config +CONFIG_DRM_VGEM=m +``` + +### No DMA Heaps Available +**Error**: Test fails with heap enumeration errors + +**Solution**: Enable DMA heap support in kernel: +``` +CONFIG_DMA_HEAP=y +CONFIG_DMA_CMA=y +``` + +## Building dmabuf-heap Binary + +If the binary is not available, you can build it from kernel sources: + +```bash +# Navigate to kernel source +cd /path/to/linux + +# Build dmabuf-heaps selftests +make -C tools/testing/selftests/dmabuf-heaps + +# Binary will be at: +# tools/testing/selftests/dmabuf-heaps/dmabuf-heap +``` + +## Kernel Config Requirements + +### Mandatory: +``` +CONFIG_DMA_SHARED_BUFFER=y +CONFIG_DMA_HEAP=y +``` + +### Recommended: +``` +CONFIG_DMA_CMA=y +CONFIG_DRM_VGEM=m # For import/export tests +``` + +## License + +Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +SPDX-License-Identifier: BSD-3-Clause diff --git a/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/dmabuf_heap_kselftest.yaml b/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/dmabuf_heap_kselftest.yaml new file mode 100755 index 00000000..05ffa714 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/dmabuf_heap_kselftest.yaml @@ -0,0 +1,21 @@ +metadata: + format: Lava-Test Test Definition 1.0 + name: dmabuf_heap_kselftest + description: "DMA-BUF heap kselftest binary validation" + maintainer: + - vnarapar@qti.qualcomm.com + os: + - openembedded + scope: + - functional + devices: + - rb3gen2 + - qcs6490 + - qcs8300 + - qcs9100 + - sa8775p + +run: + steps: + - cd $PWD/suites/Kernel/Baseport/dmabuf_heap_kselftest + - ./run.sh diff --git a/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/run.sh b/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/run.sh new file mode 100755 index 00000000..0b7070d1 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest/run.sh @@ -0,0 +1,193 @@ +#!/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 + +if [ -z "$__INIT_ENV_LOADED" ]; then + # shellcheck disable=SC1090 + . "$INIT_ENV" +fi + +# shellcheck disable=SC1090,SC1091 +. "$TOOLS/functestlib.sh" + +TESTNAME="dmabuf_heap_kselftest" +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 + +DEFAULT_BINARY_PATH="/kselftest/dmabuf-heaps/dmabuf-heap" +BINARY_PATH="$DEFAULT_BINARY_PATH" + +print_usage() { + cat < Path to dmabuf-heap test binary + (default: $DEFAULT_BINARY_PATH) + -h, --help Show this help and exit + +Examples: + $(basename "$0") + $(basename "$0") --binary-path /vendor/bin/dmabuf-heap + $(basename "$0") -b /data/local/tmp/dmabuf-heap +EOF +} + +# Simple flag parser (POSIX sh) +while [ $# -gt 0 ]; do + case "$1" in + -b|--binary-path) + shift + if [ $# -eq 0 ]; then + echo "[ERROR] Missing value for --binary-path" >&2 + print_usage + exit 2 + fi + BINARY_PATH="$1" + ;; + -h|--help) + print_usage + exit 0 + ;; + --) # end of options + shift + break + ;; + -*) + echo "[ERROR] Unknown option: $1" >&2 + print_usage + exit 2 + ;; + *) # positional (ignored to avoid old behavior) + ;; + esac + shift +done + +log_info "DMA-BUF Heap Kselftest Binary Path: $BINARY_PATH" + +log_info "=== Checking for dmabuf-heap binary ===" + +if [ ! -f "$BINARY_PATH" ]; then + log_fail "dmabuf-heap binary not found at: $BINARY_PATH" + log_info "Please provide the correct path as an argument:" + log_info " ./run.sh /path/to/dmabuf-heap" + pass=false + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +if [ ! -x "$BINARY_PATH" ]; then + log_fail "dmabuf-heap binary is not executable: $BINARY_PATH" + pass=false + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi + +log_pass "dmabuf-heap binary found and executable" + +log_info "=== Running dmabuf-heap kselftest ===" + +output_file="./OUTPUTFILE.res" + +log_info "Executing: $BINARY_PATH" +if "$BINARY_PATH" > "$output_file" 2>&1; then + test_exit_code=0 +else + test_exit_code=$? +fi + +# Display the output +log_info "Test output:" +log_info "----------------------------------------" +while IFS= read -r line; do + log_info "$line" +done < "$output_file" +log_info "----------------------------------------" + +# Check if output contains TAP format +if ! grep -q "TAP version" "$output_file"; then + log_warn "Output does not appear to be in TAP format" +fi + + +pass_count=0 +fail_count=0 +skip_count=0 +error_count=0 + +# Parse the totals line if present +if grep -q "# Totals:" "$output_file"; then + totals_line=$(grep "# Totals:" "$output_file") + log_info "Test summary: $totals_line" + + pass_count=$(echo "$totals_line" | grep -o " pass:[0-9]*" | cut -d':' -f2) + fail_count=$(echo "$totals_line" | grep -o " fail:[0-9]*" | cut -d':' -f2) + skip_count=$(echo "$totals_line" | grep -o "skip:[0-9]*" | cut -d':' -f2) + error_count=$(echo "$totals_line" | grep -o "error:[0-9]*" | cut -d':' -f2) + + pass_count=${pass_count:-0} + fail_count=${fail_count:-0} + skip_count=${skip_count:-0} + error_count=${error_count:-0} +else + pass_count=$(grep -c "^ok " "$output_file" || echo 0) + fail_count=$(grep -c "^not ok " "$output_file" || echo 0) + skip_count=$(grep -c "# SKIP" "$output_file" || echo 0) +fi + +log_info " Passed: $pass_count" +log_info " Failed: $fail_count" +log_info " Skipped: $skip_count" +log_info " Errors: $error_count" + +if [ "$fail_count" -gt 0 ] || [ "$error_count" -gt 0 ]; then + log_fail "Test FAILED: $fail_count failure(s), $error_count error(s)" + pass=false +elif [ "$test_exit_code" -ne 0 ]; then + log_fail "Test binary exited with non-zero code: $test_exit_code" + pass=false +elif [ "$pass_count" -eq 0 ]; then + log_fail "No tests passed - possible execution issue" + pass=false +else + log_pass "All tests passed successfully ($pass_count passed, $skip_count skipped)" +fi + +rm -f "$output_file" + +if $pass; then + log_pass "$TESTNAME : Test Passed" + echo "$TESTNAME PASS" > "$res_file" + exit 0 +else + log_fail "$TESTNAME : Test Failed" + echo "$TESTNAME FAIL" > "$res_file" + exit 1 +fi \ No newline at end of file