|
| 1 | +# DMA-BUF Heap Kselftest Test |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +## What is dmabuf-heap kselftest? |
| 8 | + |
| 9 | +The `dmabuf-heap` kselftest is part of the Linux kernel's self-testing framework. It validates: |
| 10 | +- DMA-BUF heap allocation and importing |
| 11 | +- Buffer zeroing behavior |
| 12 | +- Compatibility with older/newer allocation methods |
| 13 | +- Error handling for invalid operations |
| 14 | +- Integration with VGEM (Virtual GEM) driver |
| 15 | + |
| 16 | +## Test Coverage |
| 17 | + |
| 18 | +### 1. Binary Validation |
| 19 | +- Checks if dmabuf-heap binary exists at specified path |
| 20 | +- Verifies binary has execute permissions |
| 21 | + |
| 22 | +### 2. Test Execution |
| 23 | +- Runs the dmabuf-heap kselftest binary |
| 24 | +- Captures all output (stdout and stderr) |
| 25 | +- Displays complete test output in logs |
| 26 | + |
| 27 | +### 3. TAP Output Parsing |
| 28 | +- Parses TAP format output |
| 29 | +- Extracts test counts (pass/fail/skip/error) |
| 30 | +- Identifies skipped tests and reasons |
| 31 | + |
| 32 | +### 4. Result Determination |
| 33 | +- Marks test as PASS if no failures or errors |
| 34 | +- Marks test as FAIL if any test fails or errors occur |
| 35 | +- Reports skipped tests as warnings (not failures) |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +### Default Usage (uses default path): |
| 40 | +```bash |
| 41 | +cd /path/to/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest |
| 42 | +./run.sh |
| 43 | +``` |
| 44 | + |
| 45 | +This uses the default binary path: `/kselftest/dmabuf-heaps/dmabuf-heap` |
| 46 | + |
| 47 | +### Custom Binary Path: |
| 48 | +```bash |
| 49 | +cd /path/to/Runner/suites/Kernel/Baseport/dmabuf_heap_kselftest |
| 50 | +./run.sh --binary-path /custom/path/to/dmabuf-heap |
| 51 | +``` |
| 52 | + |
| 53 | +### Via Test Runner: |
| 54 | +```bash |
| 55 | +cd /path/to/Runner |
| 56 | +./run-test.sh dmabuf_heap_kselftest |
| 57 | +``` |
| 58 | + |
| 59 | +## Test Results |
| 60 | + |
| 61 | +Generates: |
| 62 | +- `dmabuf_heap_kselftest.res` - Final result (PASS/FAIL) |
| 63 | +- Console output with complete test execution details |
| 64 | + |
| 65 | +## Prerequisites |
| 66 | + |
| 67 | +### Required: |
| 68 | +- `dmabuf-heap` binary from kernel selftests |
| 69 | +- DMA-BUF heap support in kernel (`CONFIG_DMA_HEAP`) |
| 70 | +- Execute permissions on the binary |
| 71 | + |
| 72 | +### Optional: |
| 73 | +- VGEM driver (`CONFIG_DRM_VGEM`) - for import/export tests |
| 74 | +- CMA support (`CONFIG_DMA_CMA`) - for contiguous allocations |
| 75 | + |
| 76 | +## Expected Output |
| 77 | + |
| 78 | +### Successful Test Run: |
| 79 | +``` |
| 80 | +[INFO] 1970-01-01 10:20:21 - ================================================================================ |
| 81 | +[INFO] 1970-01-01 10:20:21 - ============ Starting dmabuf_heap_kselftest Testcase ======================================= |
| 82 | +[INFO] 1970-01-01 10:20:21 - ================================================================================ |
| 83 | +[INFO] 1970-01-01 10:20:21 - DMA-BUF Heap Kselftest Binary Path: /kselftest/dmabuf-heaps/dmabuf-heap |
| 84 | +[INFO] 1970-01-01 10:20:21 - === Checking for dmabuf-heap binary === |
| 85 | +[PASS] 1970-01-01 10:20:21 - dmabuf-heap binary found and executable |
| 86 | +[INFO] 1970-01-01 10:20:21 - === Running dmabuf-heap kselftest === |
| 87 | +[INFO] 1970-01-01 10:20:21 - Executing: /kselftest/dmabuf-heaps/dmabuf-heap |
| 88 | +[INFO] 1970-01-01 10:20:21 - Test output: |
| 89 | +[INFO] 1970-01-01 10:20:21 - ---------------------------------------- |
| 90 | +[INFO] 1970-01-01 10:20:21 - TAP version 13 |
| 91 | +[INFO] 1970-01-01 10:20:21 - 1..11 |
| 92 | +[INFO] 1970-01-01 10:20:21 - # Testing heap: system |
| 93 | +[INFO] 1970-01-01 10:20:21 - # ======================================= |
| 94 | +[INFO] 1970-01-01 10:20:21 - # Testing allocation and importing: |
| 95 | +[INFO] 1970-01-01 10:20:21 - ok 1 # SKIP Could not open vgem -1 |
| 96 | +[INFO] 1970-01-01 10:20:21 - ok 2 test_alloc_and_import dmabuf sync succeeded |
| 97 | +[INFO] 1970-01-01 10:20:21 - # Testing alloced 4k buffers are zeroed: |
| 98 | +[INFO] 1970-01-01 10:20:21 - ok 3 Allocate and fill a bunch of buffers |
| 99 | +[INFO] 1970-01-01 10:20:21 - ok 4 Allocate and validate all buffers are zeroed |
| 100 | +[INFO] 1970-01-01 10:20:21 - # Testing alloced 1024k buffers are zeroed: |
| 101 | +[INFO] 1970-01-01 10:20:21 - ok 5 Allocate and fill a bunch of buffers |
| 102 | +[INFO] 1970-01-01 10:20:21 - ok 6 Allocate and validate all buffers are zeroed |
| 103 | +[INFO] 1970-01-01 10:20:21 - # Testing (theoretical) older alloc compat: |
| 104 | +[INFO] 1970-01-01 10:20:21 - ok 7 dmabuf_heap_alloc_older |
| 105 | +[INFO] 1970-01-01 10:20:21 - # Testing (theoretical) newer alloc compat: |
| 106 | +[INFO] 1970-01-01 10:20:21 - ok 8 dmabuf_heap_alloc_newer |
| 107 | +[INFO] 1970-01-01 10:20:21 - # Testing expected error cases: |
| 108 | +[INFO] 1970-01-01 10:20:21 - ok 9 Error expected on invalid fd -1 |
| 109 | +[INFO] 1970-01-01 10:20:21 - ok 10 Error expected on invalid heap flags -1 |
| 110 | +[INFO] 1970-01-01 10:20:21 - ok 11 Error expected on invalid heap flags -1 |
| 111 | +[INFO] 1970-01-01 10:20:21 - # 1 skipped test(s) detected. Consider enabling relevant config options to improve coverage. |
| 112 | +[INFO] 1970-01-01 10:20:21 - # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:1 error:0 |
| 113 | +[INFO] 1970-01-01 10:20:21 - ---------------------------------------- |
| 114 | +[INFO] 1970-01-01 10:20:21 - Test summary: # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:1 error:0 |
| 115 | +[INFO] 1970-01-01 10:20:21 - Passed: 10 |
| 116 | +[INFO] 1970-01-01 10:20:21 - Failed: 0 |
| 117 | +[INFO] 1970-01-01 10:20:21 - Skipped: 1 |
| 118 | +[INFO] 1970-01-01 10:20:21 - Errors: 0 |
| 119 | +[WARN] 1970-01-01 10:20:21 - 1 test(s) were skipped |
| 120 | +[INFO] 1970-01-01 10:20:21 - Consider enabling relevant config options to improve coverage |
| 121 | +[PASS] 1970-01-01 10:20:21 - All tests passed successfully (10 passed, 1 skipped) |
| 122 | +[PASS] 1970-01-01 10:20:21 - dmabuf_heap_kselftest : Test Passed |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | +## Test Details |
| 127 | + |
| 128 | +### Test 1: Allocation and Importing |
| 129 | +- Tests basic DMA-BUF allocation |
| 130 | +- Tests importing buffers between devices |
| 131 | +- Requires VGEM driver (skipped if not available) |
| 132 | + |
| 133 | +### Test 2-6: Buffer Zeroing |
| 134 | +- Validates that newly allocated buffers are zeroed |
| 135 | +- Tests with different buffer sizes (4KB, 1024KB) |
| 136 | +- Ensures no data leakage from previous allocations |
| 137 | + |
| 138 | +### Test 7-8: Compatibility Tests |
| 139 | +- Tests backward compatibility with older allocation methods |
| 140 | +- Tests forward compatibility with newer allocation methods |
| 141 | +- Ensures API stability |
| 142 | + |
| 143 | +### Test 9-11: Error Handling |
| 144 | +- Tests invalid file descriptor handling |
| 145 | +- Tests invalid heap flags |
| 146 | +- Ensures proper error reporting |
| 147 | + |
| 148 | +## Troubleshooting |
| 149 | + |
| 150 | +### Binary Not Found |
| 151 | +**Error**: `dmabuf-heap binary not found at: /kselftest/dmabuf-heaps/dmabuf-heap` |
| 152 | + |
| 153 | +**Solutions**: |
| 154 | +1. Verify kselftest is installed on the system |
| 155 | +2. Check the actual location of the binary: |
| 156 | + ```bash |
| 157 | + find / -name dmabuf-heap 2>/dev/null |
| 158 | + ``` |
| 159 | +3. Provide correct path as argument: |
| 160 | + ```bash |
| 161 | + ./run.sh /actual/path/to/dmabuf-heap |
| 162 | + ``` |
| 163 | + |
| 164 | +### Binary Not Executable |
| 165 | +**Error**: `dmabuf-heap binary is not executable` |
| 166 | + |
| 167 | +**Solution**: |
| 168 | +```bash |
| 169 | +chmod +x /kselftest/dmabuf-heaps/dmabuf-heap |
| 170 | +``` |
| 171 | + |
| 172 | +### VGEM Tests Skipped |
| 173 | +**Warning**: `ok 1 # SKIP Could not open vgem -1` |
| 174 | + |
| 175 | +**Cause**: VGEM driver not loaded or not available |
| 176 | + |
| 177 | +**Solution** (optional - not required for test to pass): |
| 178 | +```bash |
| 179 | +# Load VGEM module |
| 180 | +modprobe vgem |
| 181 | + |
| 182 | +# Or enable in kernel config |
| 183 | +CONFIG_DRM_VGEM=m |
| 184 | +``` |
| 185 | + |
| 186 | +### No DMA Heaps Available |
| 187 | +**Error**: Test fails with heap enumeration errors |
| 188 | + |
| 189 | +**Solution**: Enable DMA heap support in kernel: |
| 190 | +``` |
| 191 | +CONFIG_DMA_HEAP=y |
| 192 | +CONFIG_DMA_CMA=y |
| 193 | +``` |
| 194 | + |
| 195 | +## Building dmabuf-heap Binary |
| 196 | + |
| 197 | +If the binary is not available, you can build it from kernel sources: |
| 198 | + |
| 199 | +```bash |
| 200 | +# Navigate to kernel source |
| 201 | +cd /path/to/linux |
| 202 | + |
| 203 | +# Build dmabuf-heaps selftests |
| 204 | +make -C tools/testing/selftests/dmabuf-heaps |
| 205 | + |
| 206 | +# Binary will be at: |
| 207 | +# tools/testing/selftests/dmabuf-heaps/dmabuf-heap |
| 208 | +``` |
| 209 | + |
| 210 | +## Kernel Config Requirements |
| 211 | + |
| 212 | +### Mandatory: |
| 213 | +``` |
| 214 | +CONFIG_DMABUF_HEAPS =y |
| 215 | +CONFIG_DMA_HEAP=y |
| 216 | +``` |
| 217 | + |
| 218 | +### Recommended: |
| 219 | +``` |
| 220 | +CONFIG_DMA_CMA=y |
| 221 | +CONFIG_DRM_VGEM=m # For import/export tests |
| 222 | +``` |
| 223 | + |
| 224 | +## License |
| 225 | + |
| 226 | +Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 227 | +SPDX-License-Identifier: BSD-3-Clause |
0 commit comments