bcore-mutation
A mutation testing tool for Bitcoin Core, rewritten in Rust.
This is a complete rewrite of the original Python mutation-core tool, offering improved performance, better error handling, and enhanced concurrency.
"Mutation testing (or mutation analysis or program mutation) is used to design new software tests and evaluate the quality of existing software tests. Mutation testing involves modifying a program in small ways. Each mutated version is called a mutant and tests detect and reject mutants by causing the behaviour of the original version to differ from the mutant. This is called killing the mutant. Test suites are measured by the percentage of mutants that they kill." (Wikipedia)
All original features from the Python version:
- Generate mutants only for code touched in specific branches (useful for testing PRs)
- Security-based mutation operators for testing fuzzing scenarios
- Skip useless mutants (comments, LogPrintf statements, etc.)
- One mutant per line mode for faster analysis
- Support for functional and unit test mutation
- Coverage-guided mutation testing
- Specific mutation operators designed for Bitcoin Core
Installation
From Source
Usage
Basic Usage
Generate Mutants for Specific File
Generate Mutants for Specific PR
Create Skip Lines Configuration
Create a JSON file specifying lines to skip:
Use with:
Advanced Options
Create only one mutant per line (faster analysis):
Create mutants only for tests:
Use coverage file to create mutants only for covered code:
Specify line range:
Security-only mutations (for fuzzing):
Analysis
Analyze all mutation folders:
Analyze specific folder with custom command:
Set timeout and parallel jobs:
Library Usage
The tool can also be used as a Rust library:
use *;
use HashMap;
async
Error Handling
The Rust version provides comprehensive error handling with detailed error messages:
use MutationError;
match run_mutation.await
Testing
Run the test suite:
Contributing
- Fork the repository
- Create a feature branch
- Add tests for your changes
- Ensure all tests pass:
cargo test - Run clippy:
cargo clippy -- -D warnings - Format code:
cargo fmt - Submit a pull request
License
MIT License