This document provides guidance for AI assistants (like Claude) and developers when updating files in this repository.
kernel_patch_verify is a Linux kernel patch static verification helper tool written in bash. It automates running multiple kernel verification tools (checkpatch, sparse, smatch, coccinelle, etc.) against kernel patches to catch issues before submission to upstream.
-
kernel_patch_verify - Main verification script (bash)
- Contains test functions organized as
ptest_*,ftest_*, andbtest_* - Coordinates execution of all verification tools
- Generates consolidated report of findings
- Contains test functions organized as
-
kp_common - Common functions and configurations
- Shared utilities used by other scripts
- Path configurations for cross-compilers
-
kpv - Docker wrapper script
- Executes
kernel_patch_verifyinside Docker container - Handles volume mounts and environment setup
- Executes
-
kps - Shell entry script
- Drops user into shell with same environment as kpv
-
Dockerfile - Docker image definition
- Installs verification tools (sparse, coccinelle, smatch, etc.)
- Sets up build environment
-
build-env.sh - Build environment setup script
- Downloads and installs verification tools
- Configures tool versions and dependencies
- other-configs/ - Additional configurations
- Contains config files for various tools
- Mounted into Docker environment
- README.md - User-facing documentation
- Dockerbuild.md - Docker build instructions
- CLAUDE.md - This file
When modifying the main verification script:
-
Test Organization
ptest_*functions: Test patches (take patch file as argument)ftest_*functions: Test C files impacted by patchbtest_*functions: Build tests (take .o files or build entire kernel)
-
Test Criteria
- Fast tests: Run by default (no
-Cflag needed) - Comprehensive tests: Run with
-Cflag (may take significant time) - Tests should output to stderr, not stdout
- Pass/fail: For f/btest, before/after logs should show 0 diff; for ptest, no output = pass
- Fast tests: Run by default (no
-
Error Handling
- Always check for tool availability before use
- Provide helpful error messages about missing dependencies
- Follow existing error reporting patterns
-
Compatibility
- Maintain bash compatibility (no python/perl)
- Support both native and cross-compilation scenarios
- Test with both Docker and native environments
-
Code Style
- Follow existing bash style conventions
- Use meaningful variable names
- Add comments for non-obvious logic
- Keep functions focused and single-purpose
When modifying Dockerfile or build-env.sh:
-
Tool Versions
- Update version numbers in
build-env.sh - Document version changes in commit messages
- Test that new versions don't break existing workflows
- Update version numbers in
-
Dependencies
- Keep base image minimal
- Document any new apt packages needed
- Verify cross-compiler compatibility
-
Size Considerations
- Avoid including GCC toolchains in image (mount from host)
- Clean up build artifacts to minimize image size
When modifying files in other-configs/:
- Tool Configs
- Test configuration changes with actual kernel code
- Document non-obvious config options
- Ensure configs work in both Docker and native environments
When modifying README.md or Dockerbuild.md:
-
Keep Examples Current
- Test example commands before documenting
- Include expected output when helpful
- Update examples if script options change
-
Maintain Structure
- Follow existing documentation organization
- Use clear section headings
- Keep quick-start section concise
-
Document New Features
- Add usage examples for new options
- Explain when to use new features
- Document any new dependencies
Before committing changes:
-
Functional Testing
- Test with actual kernel patches
- Try both quick (
-1) and comprehensive (-C) modes - Test in Docker environment using
kpv - Verify report generation
-
Environment Testing
- Test with clean Docker container
- Test native execution if applicable
- Verify cross-compilation scenarios work
-
Edge Cases
- Test with single patch and patch series
- Test with patches that have known issues
- Verify error handling for missing tools
- Add tool installation to
build-env.shor Dockerfile - Create test function in
kernel_patch_verify(ptest/ftest/btest) - Add tool detection and error messaging
- Decide if tool is fast (default) or comprehensive (
-C) - Update README.md with new tool info
- Test thoroughly
- Modify version in
build-env.sh - Rebuild Docker image:
make clean && make - Test with known good patches
- Check for behavior changes in tool output
- Update documentation if needed
- Update report generation in
kernel_patch_verify - Test report output with various scenarios
- Ensure backward compatibility if others parse reports
- Document format changes
- Update getopts section in
kernel_patch_verify - Add option handling logic
- Update usage message
- Update README.md examples
- Test new option with other options
From the README:
- Keep this tool in bash (no python/perl alternatives)
- Send pull requests via GitHub
- Focus on practical utility for kernel developers
- Avoid false positives that irritate developers
- Test changes before submitting
- This tool is meant to catch issues before kernel maintainer review
- Speed matters - developers won't use slow tools
- False positives are worse than false negatives
- The tool should never throw errors on stdout (use stderr)
- Cross-platform support (native x86, ARM cross-compile, etc.) is important
For bugs or improvements, submit issues at: https://github.com/nmenon/kernel_patch_verify/issues