Testing
KDAL has four layers of testing, each targeting a different part of the stack.
Test Hierarchy
Section titled “Test Hierarchy”| Layer | Location | Runner | Purpose |
|---|---|---|---|
| KUnit | tests/kunit/ |
In-kernel, in QEMU (scripts/ci/kunit-qemu.sh) |
Internal API correctness |
| Userspace smoke | tests/userspace/testapp.c |
User process | End-to-end ioctl validation |
| Integration | tests/integration/kdaltest.c |
User process | Multi-device, power, error paths |
| Benchmark | tests/userspace/benchmark.c |
User process | Throughput measurement |
KUnit Tests
Section titled “KUnit Tests”KUnit tests run inside the kernel at boot (or module load) and exercise internal APIs without userspace involvement.
Running KUnit
Section titled “Running KUnit”KDAL is built out of tree, so kunit.py from the kernel tree does not
apply. The suites are compiled into the module with KDAL_KUNIT=y, and
the module is booted in QEMU (arm64 virt), as CI’s kunit job does:
make KDIR=<arm64 kernel tree> KDAL_KUNIT=y # kdal.ko with its suitesscripts/ci/kunit-qemu.sh <KDIR> <Image> # boot it, check the KTAP resultsThe kernel tree must be prepared (modules_prepare) and its Image built
with CONFIG_KUNIT=y.
Test Suites
Section titled “Test Suites”| Suite (file) | Cases | What they cover |
|---|---|---|
kdal-registry (test_registry.c) |
9 | backend, driver and device registration, lookup, snapshot, iteration, null parameters |
kdal-event (test_event.c) |
6 | emit, poll, null device and parameters, shutdown, overflow |
kdal-core (test_core.c) |
10 | snapshot after init, device lookup per class, driver and backend binding, power transitions |
kdal-driver (test_driver.c) |
8 | driver lookup per class, ops present, attach with null parameters, double attach |
kdal-accel (test_accel.c) |
5 | queue creation, buffer map and unmap, submit, null parameters |
kdal-demand (test_demand.c) |
2 | demand regions reported by a driver, too small a buffer |
Total: 40 test cases across 6 suites.
Writing KUnit Tests
Section titled “Writing KUnit Tests”#include <kunit/test.h>
static void test_register_device(struct kunit *test){ struct kdal_device dev = { .name = "test0" }; int ret = kdal_register_device(&dev); KUNIT_ASSERT_EQ(test, ret, 0); kdal_unregister_device(&dev);}
static struct kunit_case registry_cases[] = { KUNIT_CASE(test_register_device), {}};
static struct kunit_suite registry_suite = { .name = "kdal_registry", .test_cases = registry_cases,};kunit_test_suite(registry_suite);Userspace Smoke Tests
Section titled “Userspace Smoke Tests”The smoke test exercises the full ioctl path through /dev/kdal:
# Preferred: mirror the CI smoke contract locally./scripts/ci/test.shIf you want to run the userspace probe manually against a loaded module, build the helper binary yourself and execute it directly:
cc -std=c99 -Wall -Wextra -pedantic -D_DEFAULT_SOURCE \ -o /tmp/testapp tests/userspace/testapp.csudo insmod kdal.ko/tmp/testappWhat it tests
Section titled “What it tests”KDAL_IOCTL_GET_VERSION- version queryKDAL_IOCTL_LIST_DEVICES- device enumerationKDAL_IOCTL_GET_INFO- device info queryKDAL_IOCTL_SELECT_DEV- device selectionKDAL_IOCTL_SET_POWER- power state transitionsread()/write()- data path through selected device
Integration Tests
Section titled “Integration Tests”Integration tests cover multi-device scenarios, error paths, and power management sequences:
cc -std=c99 -Wall -Wextra -D_DEFAULT_SOURCE -o /tmp/kdaltest tests/integration/kdaltest.csudo insmod kdal.ko/tmp/kdaltestScenarios tested
Section titled “Scenarios tested”- Loopback through several devices in turn (
test_multi_device_loopback) - Power transitions (
test_power_management) - Error paths: invalid device names and requests (
test_error_paths) - Independent selections on separate file descriptors
(
test_independent_fds)
Event polling is not tested: KDAL_IOCTL_POLL_EVENT is defined but the
character device does not dispatch it yet. In CI these programs are only
built and run offline (scripts/ci/test.sh), not against a module.
Benchmark
Section titled “Benchmark”The benchmark tool measures write/read throughput through /dev/kdal:
./benchmark # defaults: uart0, 1000 iterations, 256 bytes./benchmark spi0 50000 256| Parameter | Default | Description |
|---|---|---|
| Device | uart0 |
Target device name |
| Iterations | 1000 | Number of write/read cycles |
| Block size | 256 bytes | Payload per operation |
Uses clock_gettime(CLOCK_MONOTONIC) for nanosecond resolution.
Compiler Tests
Section titled “Compiler Tests”The compiler can be tested by compiling sample .kdc files and verifying
the generated output:
# Compile an example (kdalc does not create the output directory)mkdir -p /tmp/out./build/release/compiler/kdalc examples/kdc_hello/uart_hello.kdc -o /tmp/out
# Verify output existsls /tmp/out/UartHelloDriver.c /tmp/out/Makefile.kbuildThe generated module does not build yet (open finding O7 in KDAL’s
docs/open-findings-20261121.md); CI’s codegen-check workflow records
that.
Auto-Generated Tests
Section titled “Auto-Generated Tests”kdality test-gen creates KUnit test stubs from any .kdc driver:
kdality test-gen examples/kdc_hello/uart_hello.kdc -o tests/generated/This generates one KUNIT_CASE per event handler found in the driver,
with setup/teardown fixtures and suite registration. Known issue: the case
names are built from the handler text, so a handler such as
on read(DEV.DATA) gives a name that is not a valid C identifier.
Development Test Script
Section titled “Development Test Script”The test.sh script mirrors CI stages locally with numbered PASS/FAIL output
and saves reports under the selected variant tree, for example
build/release/test/<target>_<date>.log.
# Run all tests./scripts/dev/test.sh --variant release all
# Test individual targets./scripts/dev/test.sh --variant release kdalc # Compiler binary + sample compilation./scripts/dev/test.sh --variant release kdality # CLI subcommands./scripts/dev/test.sh --variant release cppcheck # C static analysis (mirrors CI)./scripts/dev/test.sh --variant release shellcheck # Shell script linting (mirrors CI)./scripts/dev/test.sh --variant release structure # Project structure validation./scripts/dev/test.sh --variant release e2e # End-to-end test suites./scripts/dev/test.sh help # List all targetsCI Pipeline
Section titled “CI Pipeline”GitHub Actions, on every push and pull request (.github/workflows/ci.yml):
| Job | What it does |
|---|---|
quality-gate |
the quality gate (static analysis, formatting, structure) |
build-and-smoke |
builds the tools on Ubuntu and macOS, runs scripts/ci/test.sh |
e2e |
scripts/e2e/run_all.sh |
kunit |
builds kdal.ko with its suites and boots it in QEMU |
Other workflows: codegen-check (do the generated modules build? not yet,
O7), kunit-stress, weekly-deep, and release (started by hand).