‹ 首页

counterexample-to-test-generator

@arabelatso · 收录于 1 周前

Automatically generates executable test cases from model checking counterexample traces. Translates abstract counterexample states and transitions into concrete test inputs, execution steps, and assertions that reproduce property violations. Use when working with model checker outputs (SPIN, CBMC, NuSMV, TLA+, Java PathFinder, etc.) and needing to create regression tests, validate bug fixes, or reproduce verification failures in executable test suites.

适合你,如果经常用模型检查器验证系统属性并需要自动生成测试用例

/ 下载安装
counterexample-to-test-generator.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add arabelatso/skills-4-se/counterexample-to-test-generator
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- arabelatso/skills-4-se/counterexample-to-test-generator
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify arabelatso/skills-4-se/counterexample-to-test-generator
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
137GitHub stars
~1.2K最小装载
~2.7K含声明引用
~4.1K文本包总量
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · Apache-2.0 · 0f00a4f

Counterexample To Test Generator

Overview

This skill transforms counterexample traces from model checkers into executable test cases that reliably reproduce property violations. It bridges formal verification and testing by mapping abstract states to concrete values and generating runnable tests with clear traceability from counterexample steps to test logic.

Workflow
Step 1: Analyze Inputs

Gather and understand the counterexample trace and program:

  1. Identify the model checker format: Determine which tool produced the counterexample (SPIN, CBMC, NuSMV, TLA+, JPF, etc.). See [references/model_checker_formats.md](references/model_checker_formats.md) for format details.
  1. Extract key information:
  2. Initial state values
  3. Sequence of transitions/steps
  4. Variable values at each step
  5. Property violation point
  6. Error condition or assertion failure
  1. Understand the program structure:
  2. Entry points and function signatures
  3. Input parameters and their types
  4. State variables involved in the trace
  5. Control flow relevant to the counterexample
Step 2: Map Abstract States to Concrete Values

Translate the counterexample's abstract representation into concrete test inputs:

  1. Determine concrete values for abstract state variables:
  2. Map symbolic values to concrete instances
  3. Resolve non-deterministic choices to specific values
  4. Handle ranges and constraints from the model
  1. Identify input sequences:
  2. Extract the sequence of function calls or operations
  3. Determine parameter values for each call
  4. Identify timing or ordering constraints
  1. Handle environment assumptions:
  2. External inputs or system calls
  3. Concurrency or scheduling decisions
  4. Resource states (files, network, memory)
Step 3: Generate Test Structure

Create the test case framework in the target language:

  1. Choose test framework based on the program language:
  2. C/C++: Google Test, CUnit, Check
  3. Java: JUnit, TestNG
  4. Python: pytest, unittest
  5. C#: NUnit, xUnit
  1. Structure the test:
  2. Setup phase: Initialize state to match counterexample start
  3. Execution phase: Replay the counterexample sequence
  4. Assertion phase: Verify the property violation occurs
  1. Add traceability comments: Map each test step to counterexample steps for debugging and maintenance.
Step 4: Implement Test Logic

Write the executable test code:

  1. Setup code: ``` // Initialize variables to counterexample initial state // Set up test fixtures or mocks // Configure environment (if needed) ```
  1. Execution sequence: ``` // Step 1 (CE line X): [description] // Execute operation with concrete values

// Step 2 (CE line Y): [description] // Execute next operation ```

  1. Assertions: ``` // Verify property violation (CE line Z) // Assert expected failure condition // Check final state matches counterexample ```
Step 5: Generate Output

Produce the complete test case with documentation:

  1. Test file: Complete, compilable/runnable test code
  2. Mapping document: Table linking counterexample steps to test lines
  3. Execution instructions: How to compile and run the test
  4. Expected behavior: What the test should demonstrate (failure reproduction)
Example Workflow

Input: SPIN counterexample showing a deadlock in a concurrent system

Output:

// test_deadlock.c - Reproduces deadlock from SPIN counterexample trail
#include <pthread.h>
#include <assert.h>

// Counterexample mapping:
// CE Step 1-2: Thread 1 acquires lock A
// CE Step 3-4: Thread 2 acquires lock B
// CE Step 5: Thread 1 waits for lock B (blocks)
// CE Step 6: Thread 2 waits for lock A (deadlock)

void* thread1_func(void* arg) {
    pthread_mutex_lock(&lock_a);  // CE Step 1
    sleep(1);                      // CE Step 2 (timing)
    pthread_mutex_lock(&lock_b);  // CE Step 5 (blocks)
    // ... rest of test
}

void test_deadlock_scenario() {
    // Setup: Initialize locks (CE initial state)
    pthread_mutex_init(&lock_a, NULL);
    pthread_mutex_init(&lock_b, NULL);

    // Execute: Create threads in counterexample order
    pthread_create(&t1, NULL, thread1_func, NULL);
    pthread_create(&t2, NULL, thread2_func, NULL);

    // This test will hang, demonstrating the deadlock
    pthread_join(t1, NULL);  // Will timeout
}
Best Practices
  1. Minimize test complexity: Generate the simplest test that reproduces the violation
  2. Preserve causality: Maintain the exact sequence from the counterexample
  3. Make violations obvious: Use clear assertions and error messages
  4. Add context: Include comments explaining the property being violated
  5. Handle non-determinism: Document any assumptions made when concretizing values
  6. Test the test: Verify the generated test actually fails as expected
Common Challenges

Challenge: Counterexample uses symbolic values without concrete bounds Solution: Use representative values from the domain, document the choice

Challenge: Trace involves complex timing or scheduling Solution: Use synchronization primitives or explicit delays to enforce ordering

Challenge: Program state is partially specified in counterexample Solution: Initialize unspecified variables to default/neutral values

Challenge: Counterexample is very long Solution: Identify the minimal prefix that still triggers the violation

References
  • [references/model_checker_formats.md](references/model_checker_formats.md): Detailed format specifications for common model checkers
  • [assets/test_templates/](assets/test_templates/): Test framework templates for various languages
按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。