|
| 1 | +# Libcamera Camera Test Runner |
| 2 | + |
| 3 | +This repository contains a **POSIX shell** test harness for exercising `libcamera` via its `cam` utility, with robust post‑capture validation and device‑tree (DT) checks. It is designed to run on embedded Linux targets (BusyBox-friendly), including Qualcomm RB platforms. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## What this test does |
| 8 | + |
| 9 | +1. **Discovers repo context** (finds `init_env`, sources `functestlib.sh`, and the camera helpers `Runner/utils/camera/lib_camera.sh`). |
| 10 | +2. **Checks DT readiness** using `dt_confirm_node_or_compatible` for: |
| 11 | + - Sensor compatible(s), e.g. `sony,imx577` |
| 12 | + - ISP / camera blocks, e.g. `isp`, `cam`, `camss` |
| 13 | +3. **Lists available cameras** with `cam -l` (warning/error lines are tolerated when camera listing succeeds). |
| 14 | +4. **Captures frames** with `cam` for one or multiple indices, storing artifacts per camera under `OUT_DIR`. |
| 15 | +5. **Validates output**: sequence continuity, content sanity (PPM/BIN), duplicate detection, and log scanning with noise suppression. |
| 16 | +6. **Summarizes per‑camera PASS/FAIL**, with overall suite verdict and exit code. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Requirements |
| 21 | + |
| 22 | +- `cam` (from libcamera) |
| 23 | +- Standard tools: `awk`, `sed`, `grep`, `sort`, `cut`, `tr`, `wc`, `find`, `stat`, `head`, `tail`, `dd` |
| 24 | +- Optional: `sha256sum` or `md5sum` (for duplicate BIN detection) |
| 25 | +- **BusyBox compatibility**: |
| 26 | + - We avoid `find -printf` and `od -A` options (not available on BusyBox). |
| 27 | + |
| 28 | +> The harness tolerates noisy `cam -l` / `cam -I` output (WARN/ERROR lines). It only requires that cameras and/or stream info are ultimately reported. |
| 29 | +
|
| 30 | +--- |
| 31 | + |
| 32 | +## Quick start |
| 33 | + |
| 34 | +From the test directory (e.g. `Runner/suites/Multimedia/Camera/Libcamera_cam/`): |
| 35 | + |
| 36 | +```sh |
| 37 | +./run.sh |
| 38 | +``` |
| 39 | + |
| 40 | +Default behavior: |
| 41 | +- Auto‑detect first camera index (`cam -l`). |
| 42 | +- Capture **10 frames** per selected camera. |
| 43 | +- Write outputs under `./cam_out/` (per‑camera subfolders `cam#`). |
| 44 | +- Validate and print a summary. |
| 45 | + |
| 46 | +### Common options |
| 47 | + |
| 48 | +```text |
| 49 | +--index N|all|n,m Camera index (default: auto from `cam -l`; `all` = run on every camera) |
| 50 | +--count N Frames to capture (default: 10) |
| 51 | +--out DIR Output directory (default: ./cam_out) |
| 52 | +--ppm Save frames as PPM files (frame-#.ppm) |
| 53 | +--bin Save frames as BIN files (default; frame-#.bin) |
| 54 | +--args "STR" Extra args passed to `cam` |
| 55 | +--strict Enforce strict validation (default) |
| 56 | +--no-strict Relax validation (no seq/err strictness) |
| 57 | +--dup-max-ratio R Fail if max duplicate bucket/total > R (default: 0.5) |
| 58 | +--bin-tol-pct P BIN size tolerance vs bytesused in % (default: 5) |
| 59 | +-h, --help Help |
| 60 | +``` |
| 61 | + |
| 62 | +Examples: |
| 63 | +```sh |
| 64 | +# Run default capture (first detected camera, 10 frames) |
| 65 | +./run.sh |
| 66 | + |
| 67 | +# Run on all cameras, 20 frames, save PPM |
| 68 | +./run.sh --index all --count 20 --ppm |
| 69 | + |
| 70 | +# Run on cameras 0 and 2, pass explicit stream config to cam |
| 71 | +./run.sh --index 0,2 --args "-s width=1920,height=1080,role=viewfinder" |
| 72 | +``` |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## Device‑tree checks |
| 77 | + |
| 78 | +The runner verifies DT node presence **before** capture: |
| 79 | + |
| 80 | +- First it looks for known sensor compatibles (e.g. `sony,imx577`). |
| 81 | +- If the sensor isn’t found, it looks for ISP / camera nodes (e.g. `isp`, `cam`, `camss`). |
| 82 | +- Matching entries are printed cleanly (name, path, compatible). |
| 83 | + |
| 84 | +If neither sensor nor ISP/camera blocks are found, the test **SKIPs** with a message: |
| 85 | +``` |
| 86 | +SKIP – No ISP/camera node/compatible found in DT |
| 87 | +``` |
| 88 | + |
| 89 | +> On large DTs, this scan can take time. The log prints “Verifying the availability of DT nodes, this process may take some time.” |
| 90 | +
|
| 91 | +--- |
| 92 | + |
| 93 | +## IPA file workaround (simple pipeline) |
| 94 | + |
| 95 | +On some builds, allocation may fail if `uncalibrated.yaml` exists for the `simple` IPA. The runner guards this by **renaming** it pre‑run: |
| 96 | + |
| 97 | +```sh |
| 98 | +if [ -f /usr/share/libcamera/ipa/simple/uncalibrated.yaml ]; then |
| 99 | + mv /usr/share/libcamera/ipa/simple/uncalibrated.yaml \ |
| 100 | + /usr/share/libcamera/ipa/simple/uncalibrated.yaml.bk |
| 101 | +fi |
| 102 | +``` |
| 103 | + |
| 104 | +It’s restored automatically at the end (if it was present). |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Output & artifacts |
| 109 | + |
| 110 | +Per‑camera subfolder under `OUT_DIR`: |
| 111 | +- `cam-run-<ts>-camX.log` – raw cam output |
| 112 | +- `cam-info-<ts>-camX.log` – `cam -l` and `cam -I` info |
| 113 | +- `frame-...` files (`.bin` or `.ppm`) – captured frames |
| 114 | +- `.file_seq_map.txt`, `.bytesused.txt`, etc. – validation sidecar files |
| 115 | +- `summary.txt` – per‑camera PASS/FAIL |
| 116 | + |
| 117 | +Console prints a **per‑camera** and **overall** summary. Exit codes: |
| 118 | +- `0` PASS |
| 119 | +- `1` FAIL |
| 120 | +- `2` SKIP |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Validation details |
| 125 | + |
| 126 | +- **Sequence integrity**: checks that frame sequence numbers are contiguous (unless `--no-strict`). |
| 127 | +- **PPM sanity**: header/magic checks and basic content entropy (sampled). |
| 128 | +- **BIN sanity**: size compared to `bytesused` (±`BIN_TOL_PCT`), entropy sample, duplicate detection via hashes. |
| 129 | +- **Error scan**: scans `cam` logs for fatal indicators, then applies **noise suppression** to ignore known benign warnings from `simple` pipeline and sensors like `imx577`. |
| 130 | + |
| 131 | +You can relax strictness with `--no-strict` (skips contiguous sequence enforcement and strict error gating). |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## Multicamera behavior |
| 136 | + |
| 137 | +- `--index all`: detects all indices from `cam -l` and iterates. |
| 138 | +- `--index 0,2,5`: runs each listed index. |
| 139 | +- Each index is independently validated and reported: if **any** camera fails, the **overall** result is **FAIL**. The summary lists which indices passed/failed. |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## Environment overrides |
| 144 | + |
| 145 | +- `INIT_ENV`: If set, the runner uses it instead of walking upward to find `init_env`. |
| 146 | +- `LIBCAM_PATH`: If set, the runner sources this path for `lib_camera.sh` helper functions. |
| 147 | +- Otherwise, the runner searches typical repo locations: |
| 148 | + - `Runner/utils/camera/lib_camera.sh` |
| 149 | + - `Runner/utils/lib_camera.sh` |
| 150 | + - `utils/camera/lib_camera.sh` |
| 151 | + - `utils/lib_camera.sh` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Troubleshooting |
| 156 | + |
| 157 | +- **`cam -l` prints WARN/ERROR but lists cameras**: This is tolerated. The runner parses indices from the “Available cameras” section. |
| 158 | +- **BusyBox `find`/`od` compatibility**: We avoid GNU-only flags; if you see issues, ensure BusyBox provides the required applets mentioned above. |
| 159 | +- **No DT matches**: Ensure your DT exposes sensor compatibles (e.g. `sony,imx577`) or ISP/camera nodes (`isp`, `cam`, `camss`). On dev boards, DT overlays may need to be applied. |
| 160 | +- **Content flagged “near‑constant”**: This typically indicates all-same bytes in sampled regions. Verify the lens cap, sensor mode, or try `--args` with a smaller resolution/role to confirm live changes. |
| 161 | +- **IPA config missing**: See the **IPA file workaround** above. |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Maintainers |
| 166 | + |
| 167 | +- Multimedia/Camera QA |
| 168 | +- Platform Integration |
| 169 | + |
| 170 | +Please submit issues and PRs with logs from `cam-run-*.log`, `cam-info-*.log`, and `summary.txt`. |
0 commit comments