Home Knowledge Base Coverage-guided generation

Coverage-guided generation is a testing technique that generates test inputs specifically designed to maximize code coverage — using feedback from program execution to guide the generation process toward unexplored code paths, systematically increasing the portion of code that is tested.

What Is Coverage-Guided Generation?

Why Coverage Matters

Coverage Metrics

Coverage-Guided Generation Approaches

Coverage-Guided Fuzzing (CGF)

LLM-Based Coverage-Guided Generation

1. Initial Generation: LLM generates diverse test inputs based on code understanding.

2. Execution and Coverage Measurement: Run tests, measure which code is covered.

3. Coverage Analysis: Identify uncovered branches, statements, or paths.

4. Targeted Generation: LLM generates new inputs specifically designed to cover unexplored code. ```python # Uncovered branch: if user_age < 0: # Never tested raise ValueError("Age cannot be negative")

# LLM generates: test_input = {"user_age": -5} # Targets the uncovered branch ```

5. Iteration: Repeat until coverage goals are met or no progress is made.

Example: Coverage-Guided Test Generation

def calculate_discount(price, customer_type):
    if price < 0:
        raise ValueError("Price cannot be negative")
    
    if customer_type == "premium":
        return price * 0.8  # 20% discount
    elif customer_type == "regular":
        return price * 0.95  # 5% discount
    else:
        return price  # No discount

# Initial test:
assert calculate_discount(100, "regular") == 95.0
# Coverage: 50% (only regular customer path)

# Coverage-guided generation adds:
assert calculate_discount(100, "premium") == 80.0  # Covers premium path
assert calculate_discount(100, "guest") == 100.0  # Covers else path
try:
    calculate_discount(-10, "regular")  # Covers error path
except ValueError:
    pass

# Coverage: 100%

Techniques for Reaching Hard-to-Cover Code

Challenges

Applications

Tools

Benefits

Limitations

Coverage-guided generation is a powerful technique for systematic testing — it ensures that code is thoroughly exercised, increasing confidence in software quality and reducing the risk of undiscovered bugs.

coverage-guided generationsoftware testing

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.