agentleFS
MicrosoftKnown publishermicrosoft/voxelpic/.github/skills/c-testing/SKILL.md

c-testing

Skill0 starsChanged 8 months agoMITView on GitHub

Write, build, and run C tests for the VoxelPic library. USE FOR: adding new C test cases, understanding the test data format, debugging test failures, or running the existing C test suite.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All four CMake presets enable VOXELPIC_BUILD_TESTS.

    line 25
  2. Very specific:

    Test data files are generated automatically by Python scripts as a post-build step (defined in test/CMakeLists.txt):

    line 41
  3. Distinctive:

    All test data files follow the same layout:

    line 52
  4. Very specific:

    Read big-endian header integers with the read_be() helper from test/test.h.

    line 69
  5. Very specific:

    Use printf() to log diagnostics on failure (no external assertion library).

    line 84
  6. Very specific:

    Use goto end with a cleanup label to ensure all *New() allocations are matched by *Free() calls, even on error paths:

    line 105
  7. Very specific:

    If the test needs generated data, add a Python generator script and a add_custom_command(TARGET ...

    line 124

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Testing the C Library

Test Suite Overview

There are three C test executables under test/, each registered with CTest:

ExecutableTestsData Files
voxel_testOcTree build round-tripvoxel_1.dat–voxel_5.dat
color_testHue-codec encode/decode(none — self-contained)
image_testLevel encode/decode to imageimage_7.dat–image_9.dat

Building and Running

cmake -B build --preset debug      # or release / debug-clang / release-clang
cmake --build build
ctest --test-dir build -V           # -V for verbose output

All four CMake presets enable VOXELPIC_BUILD_TESTS. To run a single test:

ctest --test-dir build -R color_test -V

To build with AddressSanitizer (clang):

cmake -B build --preset release-clang -DVOXELPIC_SANITIZE=address
cmake --build build
ctest --test-dir build -V

Test Data Generation

Test data files are generated automatically by Python scripts as a post-build step (defined in test/CMakeLists.txt):

  • test/voxel_test_gen.py → produces voxel_1.dat–voxel_5.dat
  • test/image_test_gen.py → produces image_7.dat–image_9.dat

Both scripts use a fixed random seed for reproducibility, and skip generation if the output file already exists. Delete the .dat files to force regeneration.

Binary Data Format

All test data files follow the same layout:

[int32 big-endian]   octree level
[int32 big-endian]   number of points/voxels (N)
  repeated N times:
    [float32 native]  x
    [float32 native]  y
    [float32 native]  z
    [uint8]           r
    [uint8]           g
    [uint8]           b

voxel_test data files additionally contain an expected-output section after the input section with the same [count][positions+colors] layout.

Read big-endian header integers with the read_be() helper from test/test.h.

Conventions for Writing a New C Test

File Structure

  1. Create test/<name>_test.c.
  2. #include <voxelpic/voxelpic.h> and #include "test.h".
  3. Link against voxelpic::voxelpic in test/CMakeLists.txt.
  4. Register with CTest via add_test(...).

Pass / Fail Signalling

  • Return 0 from main() on success, 1 on assertion failure.
  • CTest treats any non-zero exit code as failure.
  • Use printf() to log diagnostics on failure (no external assertion library).

Comparison Pattern

Compare results element-by-element and print details on mismatch. Example:

for (size_t i = 0; i < cloud->size; ++i) {
  if (voxelpicVec3Compare(&actual->positions[i], &expected->positions[i])) {
    printf("Position mismatch at %zu\n", i);
    return 1;
  }
  if (actual->colors[i].value != expected->colors[i].value) {
    printf("Color mismatch at %zu\n", i);
    return 1;
  }
}

Resource Cleanup

Use goto end with a cleanup label to ensure all *New() allocations are matched by *Free() calls, even on error paths:

int main(int argc, char *argv[]) {
  int result = 1;
  voxelpicOcTree *octree = voxelpicOcTreeNew(4, 9);
  voxelpicPointCloud *cloud = voxelpicPointCloudNew(0);
  // ... test logic ...
  result = 0;
end:
  voxelpicOcTreeFree(octree);
  voxelpicPointCloudFree(cloud);
  return result;
}

Test Data Files

If the test needs generated data, add a Python generator script and a add_custom_command(TARGET ... POST_BUILD ...) in test/CMakeLists.txt following the existing pattern. Use struct.pack(">i", ...) for big-endian header integers and native byte order for floats and uint8 colour values.

CMakeLists.txt Registration

add_executable(<name>_test <name>_test.c)
target_link_libraries(<name>_test PRIVATE voxelpic::voxelpic)
add_test(NAME <name>_test COMMAND <name>_test [args...]
         WORKING_DIRECTORY $<TARGET_FILE_DIR:<name>_test>)

Existing Test Details

voxel_test

Tests the full OcTree round-trip: loads a point cloud, builds an OcTree, extracts the level back to a cloud, and compares with expected output. Also verifies save/load I/O for both voxelpicPointCloud and voxelpicLevel.

color_test

Tests voxelpicValueToColor() / voxelpicColorToValue() round-trip across the full [0, VPIC_MAX_ENCODE_VALUE] range, plus many smaller sub-ranges. Tests both explicit-range and implicit-range (auto-detected min/max) modes.

image_test

Tests level-to-image encoding and image-to-level decoding. Builds an OcTree, encodes a level into an RGBA image via voxelpicLevelEncode(), decodes it back with voxelpicLevelDecode(), and compares the reconstructed cloud against the original.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.