Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing

Add regression tests for every bug fix (add-regression-tests)

When a bug is fixed, a test that would have caught the bug should accompany the fix.

Include the necessary context in code comments to explain the test. Do not hide the context of the test behind an issue link. Only include an issue link in the code if it provides useful additional information to future readers. If an issue link is included, explain when and why readers should open it.

See also: PR #2962.

Test user-visible behavior, not internals (test-visible-behavior)

Tests should validate observable, user-facing outcomes. Prefer testing through public APIs rather than exposing internal constants in test code.

Name tests after the behavior or specification concept being verified, not after internal implementation details. Using kernel-internal names in user-space regression tests creates unnecessary coupling.

See also: PR #2926.

Use assertion macros, not manual inspection (use-assertions)

Use language- or framework-provided assertion helpers instead of printing values and manually inspecting output. Assertions provide clear failure messages and make tests self-checking.

See also: PR #2877 and #2926.

Clean up resources after every test (test-cleanup)

Always clean up resources after a test: close file descriptors, unlink temporary files, and call waitpid on child processes. Leftover resources can cause flaky failures in subsequent tests.

// Good — cleanup after use
int fd = open("/tmp/test_file", O_CREAT | O_RDWR, 0644);
// ... test logic ...
close(fd);
unlink("/tmp/test_file");

See also: PR #2926 and #2969.