testlib-cpp-judging
Guide C++ competitive-programming judging with the bundled testlib.h. Use when the user asks to author special or scored checkers, strict validators, deterministic generators, basic interactors, or a minimal local solution-checker workflow.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- testlib-cpp-judging
- description
- Guide C++ competitive-programming judging with the bundled testlib.h. Use when the user asks to author special or scored checkers, strict validators, deterministic generators, basic interactors, or a minimal local solution-checker workflow.
02 资源文件 3
- 参考文档references/testlib-usage.md10.4 KB
- 参考文档references/troubleshooting.md2.9 KB
- 脚本scripts/testlib.h201.6 KB
03 SKILL.md 正文
Testlib C++ Judging
Scope
Use this skill when a task involves testlib.h, a special judge, a custom
checker or scorer, an input validator, a deterministic test generator, or a
testlib interactor. It is intentionally C++-only and header-only. Do not create
a Python harness for the ordinary local judging workflow.
This skill owns concrete Testlib APIs, streams, verdicts, command lines, and templates. When evaluator-facing evidence has triggered independent contract or oracle work, use checker and local evaluation to choose checker/scorer/interactor architecture, reconstruct legality and objectives, and validate the evaluator itself. Do not enter that route merely because a previously specified generator or validator is being implemented.
Start Here
- Read the testlib usage guide before writing checker, validator, generator, or interactor code.
- Copy the bundled testlib.h into the working directory beside the C++ sources, or add its directory to the compiler include path.
- Put
#include "testlib.h"before other includes. - Select exactly one registration function for each executable.
- For ordinary offline judging, use the minimal commands below rather than building a separate evaluation framework.
Choose the Executable Role
| Role | Registration | Main testlib interfaces | Purpose |
|---|---|---|---|
| Checker | registerTestlibCmd(argc, argv) |
inf, ouf, ans, quitf |
Judge contestant output against the input and reference answer |
| Validator | registerValidation(argc, argv) |
strict inf, ensuref |
Reject malformed or out-of-constraint input |
| Generator | registerGen(argc, argv, 1) |
rnd, opt, println |
Produce deterministic tests from command-line parameters |
| Interactor | registerInteraction(argc, argv) |
inf, ouf, tout, stdout |
Exchange a protocol with an interactive solution |
Generate Data as Reproducible Code
Testlib includes input-generation support; it is not limited to checkers and validators. When a local problem-finding campaign needs randomized, batch, or maximum-scale data, implement a problem-specific generator.cpp instead of hand-authoring large inputs or copying many variants. Parameterize the relevant case family, size, density/bias, structure, and seed tag with opt; use rnd for all randomness. The full command line determines Testlib's deterministic seed, so preserve that command exactly.
Define the coverage families and their expected oracle, invariant, or failure target before generating volume. Use one deterministic generator invocation per case, or a small coded batch driver that records every invocation in a manifest. Validate every intended-valid generated case with an independent validator before running the solution, and retain the generator command, input hash, validator result, and any failing seed and artifacts. Follow Checker and Local Evaluation for the complete coverage-to-retention workflow.
Critical Checker Contract
Always invoke a checker in this exact order:
checker <input-file> <contestant-output> <standard-answer>
After registration, the mapping is:
inf: input fileouf: contestant or participant outputans: standard or jury answer
Never swap ouf and ans. Even a checker that does not use the standard
answer still needs the third file argument; pass an empty placeholder file if
necessary.
Minimal Local Judging Flow
Run these commands from a directory containing testlib.h, solution.cpp,
checker.cpp, case.in, and case.ans:
g++ -std=c++17 -O2 solution.cpp -o solution
g++ -std=c++17 -O2 -I. checker.cpp -o checker
timeout 2s ./solution < case.in > case.out
solver_status=$?
if [ "$solver_status" -ne 0 ]; then
echo "solution failed with status $solver_status" >&2
exit "$solver_status"
fi
./checker case.in case.out case.ans
checker_status=$?
echo "$checker_status"
exit "$checker_status"
If the problem has validator.cpp, compile it and validate the input before
running the solution:
g++ -std=c++17 -O2 -I. validator.cpp -o validator
./validator < case.in || exit 1
Capture solver_status before running the checker; a timeout, signal, or other
nonzero solution exit is a solver failure and must not be relabeled as an output
verdict. Capture checker_status immediately after the checker. For a
verdict-only checker under the default local Testlib configuration, status 0
means accepted and nonzero means rejection or judge failure. A points checker
using quitp instead returns a partial-points status (default 7) that a
points-aware runner must parse separately. Preserve checker diagnostics and any
reported points with the status.
Authoring Rules
- Use testlib readers instead of raw parsing for judged files.
- Return
_wafor a semantically wrong contestant answer,_pefor malformed contestant output when you detect it explicitly,_failfor a broken jury answer or checker invariant, and_okonly after all required checks pass. - In validators, describe the exact grammar with
readSpace,readEoln, andreadEof; use bounded reads andensureffor semantic constraints. - In generators, use
rndrather thanrand,srand, orrandom_shuffle; identical command lines should reproduce identical data. - Implement batch and large-case generation in generator code; do not maintain hand-edited large input files as the source of truth.
- Run every intended-valid generated case through the independent validator and preserve its full generator command and seed tag.
- Flush every interactor query with
std::endlor an explicit flush. - Keep
solution.cpp, checker logic, validator logic, and answer generation as separate concerns.
Boundaries
- This skill explains the public
testlib.hworkflow, not development of the testlib repository itself. - For evaluator roles, this skill implements a previously derived contract. Use checker and local evaluation only when contract, reconstruction, score-transform, or fidelity uncertainty is evidence-triggered and blocks the current decision, or when official and local behavior disagree.
- This skill owns concrete testlib implementation. Use interactive problem solving for protocol modeling, hidden hypotheses, query design, and adversarial strategy.
- It does not bundle a Python evaluator, a build system, repository tests, or CI configuration.
- The simple three-file flow is for non-interactive judging. Interactive solutions require a bidirectional process runner supplied by the judge.
- Partial scoring needs a runner that understands testlib points verdicts; do not interpret every nonzero checker status as ordinary wrong answer in that mode.
Troubleshooting
- Read troubleshooting when compilation, checker arguments, strict whitespace, exit status, generator reproducibility, or interactor flushing causes a failure.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).