Skip to content

Testing

KDAL has four layers of testing, each targeting a different part of the stack.

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 run inside the kernel at boot (or module load) and exercise internal APIs without userspace involvement.

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:

Terminal window
make KDIR=<arm64 kernel tree> KDAL_KUNIT=y # kdal.ko with its suites
scripts/ci/kunit-qemu.sh <KDIR> <Image> # boot it, check the KTAP results

The kernel tree must be prepared (modules_prepare) and its Image built with CONFIG_KUNIT=y.

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.

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

The smoke test exercises the full ioctl path through /dev/kdal:

Terminal window
# Preferred: mirror the CI smoke contract locally
./scripts/ci/test.sh

If you want to run the userspace probe manually against a loaded module, build the helper binary yourself and execute it directly:

Terminal window
cc -std=c99 -Wall -Wextra -pedantic -D_DEFAULT_SOURCE \
-o /tmp/testapp tests/userspace/testapp.c
sudo insmod kdal.ko
/tmp/testapp
  • KDAL_IOCTL_GET_VERSION - version query
  • KDAL_IOCTL_LIST_DEVICES - device enumeration
  • KDAL_IOCTL_GET_INFO - device info query
  • KDAL_IOCTL_SELECT_DEV - device selection
  • KDAL_IOCTL_SET_POWER - power state transitions
  • read() / write() - data path through selected device

Integration tests cover multi-device scenarios, error paths, and power management sequences:

Terminal window
cc -std=c99 -Wall -Wextra -D_DEFAULT_SOURCE -o /tmp/kdaltest tests/integration/kdaltest.c
sudo insmod kdal.ko
/tmp/kdaltest
  • 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.

The benchmark tool measures write/read throughput through /dev/kdal:

Terminal window
./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.

The compiler can be tested by compiling sample .kdc files and verifying the generated output:

Terminal window
# 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 exists
ls /tmp/out/UartHelloDriver.c /tmp/out/Makefile.kbuild

The generated module does not build yet (open finding O7 in KDAL’s docs/open-findings-20261121.md); CI’s codegen-check workflow records that.

Terminal window

kdality test-gen creates KUnit test stubs from any .kdc driver:

Terminal window
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.

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.

Terminal window
# 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 targets

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).