AI-powered test case generator for C projects
Project description
Genifai
AI-powered test generator that creates test cases for target functions in C standalone programs.
Uses static analysis and call graphs, powered by Claude Anthropic.
Generate + Verify + AI = Genifai
🍏 Free trial available!
Currently in trial period - you can use Genifai without any registration.
Only CLAUDE_API_KEY is required to get started (and AZURE_ENDPOINT if using Azure Databricks).
Installation
pip install genifai
Commands
genifai keys generate- Generate a new Genifai API key for authenticationgenifai configure- Set up API credentials and defaultsgenifai analyze- Extract metadata from source codegenifai graph- Generate call graph from metadatagenifai generate- Generate test cases using AI
Command reference
Common options
-d, --directory- Source/target directory path-m, --metadata- Metadata directory path-o, --output- Output directory path-l, --language- Programming language (currently onlycis supported)
analyze
-b, --build-script- Build script path
generate
-t, --targets- Target functions file path-i, --iterations- Number of test generation iterations-c, --callgraph- Call graph JSON file (optional)
Quick start
1. Get Genifai API key
genifai keys generate
2. Configure API key
# Configuration
genifai configure \
--api-type claude \
--genifai-api-key YOUR_GENIFAI_API_KEY \
--claude-api-key YOUR_CLAUDE_API_KEY
echo 'source /home/ubuntu/.genifai/env' >> ~/.bashrc
source ~/.bashrc
3. Prepare build script
Create a build script named build.sh inside your source directory (the directory you'll pass to -d option).
Your build script must satisfy the following:
- The script filename must be exactly
build.sh - Place it inside the source directory. For example, if your source is at /path/to/source, then the build script should be at /path/to/source/build.sh
- Executable permission:
chmod +x build.sh - Coverage instrumentation: Add
-fprofile-arcs -ftest-coverage(or--coverage) to generate.gcnofiles - Compilation database: Use bear to generate
compile_commands.json
Example with Makefile:
#!/bin/bash
# Ensure your Makefile includes: CFLAGS += -fprofile-arcs -ftest-coverage
make clean
bear -- make all
Example with direct compilation:
#!/bin/bash
bear -- gcc --coverage -o myapp src/*.c -I./include
Example with CMake:
#!/bin/bash
# Ensure CMakeLists.txt includes: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build
cmake --build build
4. Analyze your codebase
# Analyze directory and generate metadata
genifai analyze \
-d /path/to/source \
-b /path/to/source/build_script \
-l c \
-m metadata_output \
-o instrumented_target
5. Prepare target functions file
Create a file specifying the target functions you want to test.
Format: one target per line as relative_file_path:line_number
Example targets.txt:
src/parser.c:145
src/parser.c:203
lib/memory.c:89
6. Generate test cases for the target function(s)
# Generate tests using metadata and call graph
genifai generate \
-d instrumented_target/source \
-l c \
-m metadata_output \
-t /path/to/source/targets.txt \
-i 5 \
-o test_output
Quick start with sample project
Want to try Genifai immediately? We provide a sample project based on libtiff command-line tools, a widely-used TIFF image processing library.
1. Clone and navigate to sample
mkdir workspace
cd workspace
mkdir sample
cd sample
git clone https://gitlab.com/libtiff/libtiff.git
2. Prepare the build scrip
cd libtiff
cat > build.sh << 'EOF'
#!/bin/bash
make clean
# Set coverage instrumentation flags
export CFLAGS="-fprofile-arcs -ftest-coverage -O0 -g"
export CXXFLAGS="-fprofile-arcs -ftest-coverage -O0 -g"
export LDFLAGS="-lgcov --coverage"
# Run configure
./autogen.sh
./configure --prefix=$(pwd)/install --disable-shared --enable-static
# Build while generating compile_commands.json
bear -- make -j$(nproc)
EOF
chmod +x build.sh
Ensure the build script works correctly before proceeding, particularly verify that:
compile_commands.jsonis generated.gcnofiles are generated
./build.sh
3. Prepare the target functions
Specify targets in targets.txt:
cat > targets.txt << 'EOF'
libtiff/tif_dirwrite.c:3033
libtiff/tif_swab.c:120
EOF
The target functions are TIFFWriteDirectoryTagData and TIFFSwabArrayOfLong8.
4. Configure your API key
GENIFAI_KEY=$(genifai keys generate | tail -n 1)
genifai configure \
--api-type claude \
--genifai-api-key $GENIFAI_KEY \
--claude-api-key YOUR_CLAUDE_API_KEY
echo 'source /home/ubuntu/.genifai/env' >> ~/.bashrc
source ~/.bashrc
5. Run the analysis workflow
Before proceeding, make sure your sample project includes:
- Pre-configured
build.shwith coverage flags targets.txtwith example target functions
Now, run the analysis:
cd ../.. # or cd /path/to/workspace
# Analyze the codebase
genifai analyze \
-d sample/libtiff \
-b sample/libtiff/build.sh \
-l c \
-m metadata_output \
-o instrumented_target
Note: The analysis process may take some time depending on the project size. For large projects like libtiff, it can take several minutes to complete.
6. Run the test generation workflow
# Generate test cases
genifai generate \
-d instrumented_target/libtiff \
-l c \
-m metadata_output \
-t sample/libtiff/targets.txt \
-i 5 \
-o test_output
After running genifai generate, test files are created in the output directory:
test_output/testcases/
├── test.c # Test source code
└── {timestamp}.sh # Build and run script
.cfiles: Test programs ready to compile.shfiles: Build and run scripts
7. Run the generated tests
# Copy test files to your source directory
cp test_output/testcases/*.c sample/libtiff/
cp test_output/testcases/*.sh sample/libtiff/
# Navigate and run
cd sample/libtiff
chmod +x *.sh
./{timestamp}.sh
Option
Generate call graph
# Create call graph from metadata
genifai graph \
-l c \
-m metadata_output \
-o graph_output
Generate test cases
# Generate tests using metadata and call graph
genifai generate \
-d /path/to/instrumented_target \
-l c \
-m metadata_output \
-c graph_output/callee.json \
-i 5 \
-o test_output
Supported languages
- C
LLM model
- Genifai uses Claude Sonnet 4.0 (the latest model from Anthropic) for test case generation. This ensures:
- High-quality test cases with deep code understanding
- Efficient and accurate static analysis integration
- Genifai is exclusively powered by Claude (Anthropic), and we have no plans to integrate with other AI APIs. We believe Claude provides the best understanding of code structure and test generation quality.
Note: We will update to Claude Opus 4.5 soon.
LLM API type
You can use one of the following interfaces.
claude: Direct Anthropic API- Use your Claude API key from console.anthropic.com
claude_azure: Azure Databricks Service with Claude- Use Claude models deployed through Microsoft Azure
- Requires Azure subscription and Claude model deployment in your Azure Databricks resource
- See Azure setup guide for details
Environment variables
GENIFAI_API_TYPE # LLM API type
GENIFAI_API_KEY # Your Genifai API key
CLAUDE_API_KEY # Your Claude API key
AZURE_ENDPOINT # Your Azure endpoint
Requirements
- Python 3.8+
- Valid Claude API key
License
MIT
Roadmap 🗺️
- Genifai currently specializes in test case generation for C programming language.
- We are planning to expand support to Rust test case generation, bringing the same AI-powered testing capabilities to the Rust ecosystem.
- Genifai currently targets standalone programs with
main()functions. Library-only projects (without main entry points) will be supported in future releases. - Currently, only the Genifai CLI tool is available. A function-based Genifai API is planned for future release.
- Currently, test case generation focuses on reaching target functions. We plan to add an option for branch coverage-based test case generation in the future.
- We are planning to implement C-to-Rust code translation via the
genifai translatecommand, enabling automated migration of C codebases to Rust.
Feedback & support 💬
We're in early development and your feedback is invaluable!
Help us improve Genifai! Share your thoughts: 👉 Email us: genifai.dev@gmail.com
Contact
- Email: genifai.dev@gmail.com
Website
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genifai-0.1.0.tar.gz.
File metadata
- Download URL: genifai-0.1.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e074de51a30613cbe7b6abcc5ff645dff892d8c056a74713df0a3dc8a0517d55
|
|
| MD5 |
1c2381a774a2d6394c79d0619b8ebd3f
|
|
| BLAKE2b-256 |
3d5e346f8eccffd4381e54798d5cd9671e42653d8c17b300e3ce47d1bc53337c
|
File details
Details for the file genifai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: genifai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd7bb686fab12cf61ea7bd0be0ab7dfebf5be1cecd5fde459ea41c49dae8ca31
|
|
| MD5 |
69530869262c211e2aadc96aeecc7c32
|
|
| BLAKE2b-256 |
87fce05312de8bbfeb0f3ffcf09d9cc4d2e5d6176e9302d59d5c11be2ae35c5b
|