I don’t know about you, but the rapid increase of the inflows of pull requests to the server is very dual edged to me. Don’t get me wrong, I’m super happy that people use the casparcg server and want to contribute to making it better, but it is also quite stressful. We’re not that many team members that have merge rights to master, and all of us have our primary income from other endeavours.
One particular thing that stops me from merging a lot more than I do is the need for testing. No one wants to be the one that approves and merges a change that starts crashing the server, and testing takes time.
I know this has been discussed before, in many different contexts, but I really think that it is time that we get automated tests in the source tree. I know that there are great test harnesses out there already, testing various parts of the servers output and operations. My own Claude sessions have (re)invented a couple and just thrown them away after the session, and I know that @Sidon, for example, has an amazing automated setup for testing various gamut- and colour space conversions.
With tests in place, at least I would be very much more inclined to approve and merge changes in to master. A quick glance that things are architecturally sound and aligns with how we want the server to evolve, then let the tests do the rest. Most PRs aren’t even new features, just bug fixes and minor improvements. Things like that should be able to get merged within hours, not weeks or months, if ever, like it is now.
Before pushing yet another PR for something like this, that just adds to the currently ever growing list of open PRs, I think we should try to reach some kind of consensus of want we’d want from such tests.
What do we want? (I didn’t run this by the AI yet).
I would like isolated tests of the modules and the core pipeline (comparing output frames to known expected outputs) and some basic end to end tests to begin with.
yeah I feel the same. I’m not actually really even using CasparCG myself these days, so finding time to want to sit down and test things (especially features/areas I dont use) is hard. Its not an easy thing to sit and do on the sofa either, so other side projects end up winning the fight for time.
Perhaps some of this is needing to figure out a way of doing the testing more portably, which could mean running casparcg on a pc in the office and getting an output feed onto a tablet or window on my laptop in a good way. Doesn’t help for everything though, but could for some manual testing.
I know this has been discussed before, in many different contexts, but I really think that it is time that we get automated tests in the source tree.
I am very open to some tests, how viable that is depends on what we want to cover. Its the end to end tests that need a decklink which are hard (due to the hardware requirement), but unit tests and e2e that utilise ndi and ffmpeg should be easily achievable.
I suspect we will also have some challenge in running them due to our need for a gpu, but I’m sure we could convince someone to host an old machine for us (hopefully with a decklink too)
I would like isolated tests of the modules and the core pipeline (comparing output frames to known expected outputs) and some basic end to end tests to begin with.
Sounds good to me
In a related note, I enabled coderabbit in the repo today as an ai pre-review. I’ve been happy with it in other projects, and it has often caught things human reviews have missed, but does sometimes need correcting. It will learn as we give it feedback on its comments
I noticed the code rabbit addition. I have had good experience with it elsewhere also but that doesn’t replace actual test runs. We need to define what sort of test infrastructure we need. Once we have the tests defined we can figure out how and where to run them. I know I have been startled at times at how fast some pull requests get merged and frustrated with how long it takes others to get reviewed and merged.
It would also be good to get some sort of performance utilization metric on those module tests so we can predict the overhead impact of specific changes early on without having to do a full up test and debug.
A modular test infrastructure would also increase the AI generation efficiency as doing a full build with a 2 core code spaces VM takes a long time. (Yes I know I need to get a local AI setup built)
Are you guys thinking of a GitHub actions based test suite or more of a test suite that maintainers can run locally? They do allow for local actions runners.
If we could get some prototypes and methods set up for how these sorts of tests go, then everyone developing new features can actually add tests for features as we build them and for each module as we add patches and improvements.
The isolated tests of the different parts of the code would basically be unit tests, runnable on the dev computer as a verification step for humans and AI-agents alike, and/or as part of some CI step when creating a PR. The issue is of course as @Julusian remarks the modules that uses dedicated hardware. But I guess it would be trivial to skip those tests when the hardware can’t be found.
I suspect we will also have some challenge in running them due to our need for a gpu, but I’m sure we could convince someone to host an old machine for us (hopefully with a decklink too)
Yea, I don’t think it will be a problem to find somewhere to co-host a dedicated machine for this. Maybe even get a decklink donated.
The end to end tests I was thinking of was more like long running, with monitoring of metrics like thread count, file descriptor count, memory and cpu usage etc. And setup to capture and dump information on crashes. Basically enabling every module and feature and having a scheduled rundown looping in a semi-realistic manner. But I think that this could be added in a later stage. This would have to be per platform as well, so it would require even more physical resources.
Does anyone here have hands on experience with any c/c++ testing frameworks?
Some of the A/B comparisons and output checks on my current harness heavily rely on a feature I have on the forks that I do experiments with. I called it ‘PRINT RAW’ and allows me to export a png directly after the decoding step, and before the mixer has touched anything. That is important for changes on the ffmpeg decoder (it should prove useful when adding the hardware acceleration paths) and also for any colour space changes, both in ffmpeg and the mixer.
This was also invaluable when testing all the new mixer (vulkan) workflows.
The ‘print raw’ feature is currently soft-blocked by a couple of core quirks, but I think with 3 contained PRs it can be merged safely. Here’s a rough layout of what Claude suggests:
Right now is just a private repo, but I can offer the harness code to see if it’s a suitable starting point for the automated tests. Right now what I have is a vibe-coded (and human tested) python app, usable mostly by cli but most cases have the gui option as well (pyside6).
~152 CLI commands, the repo calls them “batteries” (test suites). Each one covers one subsystem: colour, grading, blending, decode, outputs, API, timing, and so on.
~110k lines in cli.py and core/.
~2,500 unit tests that check the harness itself.
Checking CasparCG’s output against CasparCG’s own output only proves it is consistent, not that it is correct. So every check compares against something independent, at one of two levels:
Kind
Input
Where the right answer comes from
Gate
Conformance battery
Flat colour patches: no file, no decode, no resampling
The shader’s maths re-derived in Python from the published standard (ITU-R, SMPTE, ACES, OCIO)
1 LSB, the smallest step a pixel value can take
Picture test
Real media (ProRes, HAP, NotchLC, H.264/265, DNxHD, EXR…)
An FFmpeg render of the same file, or an OCIO library reference
PSNR/SSIM in dB
How a run works:
Matrix expansion: Test cases are generated from YAML combinations: video mode × mixer (OpenGL / Vulkan) × bit depth × colour space × HDR transfer (SDR / PQ / HLG) × codec × consumer. Invalid combinations are pruned by rules (for example, NDI is 8-bit only).
Server management: The harness generates a casparcg.config from Jinja2 templates, launches the server, and drives it over AMCP, the HTTP/WebSocket control API and OSC. Servers run in parallel (when hardware allows it) and restart only when the config changes.
Capture: The ‘normal’ IMAGE consumer gives the result of the mixer output. A raw grab gives the decoded frame, before the mixer. Both get compared to expected results of both steps. For Decklink, a physical SDI loopback is captured first by FFmpeg (it needs to be a build that includes the decklink sdk) and then also CasparCG’s own Decklink producer. Ideally the ffmpeg version matches the one used by the caspar build we’re testing.
Comparison and diagnosis: On a failure it works out where things went wrong: decoder fault versus mixer fault (by comparing decoded, mixed and reference frames), red/blue channel swaps, garbled frames, and regressions against previous runs. It writes diff heatmaps for each comparison.
Results: Stored in SQLite (with history and per-build baselines), per-test PNG folders and JSON. A sweep script runs the right set of batteries for a given kind of change, on both mixers. Note: enforcing 100% mixer parity on my experiments has allowed me to find and fix errors more easily than if I dropped OpenGL already.
Log triage: Every warning and error in every server log is classified. A server whose boot self-test complains is refused, even if every battery passes.
What it covers
Colour: colour spaces, HDR transfers, ACES, OCIO displays, looks and 3D LUTs, the grading chain, blend modes and alpha.
Decode: every codec path, including GPU-direct; seek accuracy checked against frame numbers burnt into the clips; loop boundaries.
Outputs: DeckLink SDI out and in, including HDR metadata and the keyer;
NDI, FFmpeg recording and streaming, screen, Vulkan output;
colour signalling metadata.
Performance: late frames, decode and encode cost, how many channels or recordings a machine sustains.
Robustness: every command is sent a typo and must refuse it, then sent the valid value and must accept it (a sweep of 298 checks);
The harness also tests its own tests. Batteries are checked by planting a known bug (a “mutation”) and confirming the check goes red. It also has explicit rules against checks that cannot fail, such as a check whose expected answer is the same as “nothing happened” (this had happened several times in fact).
Things to know about its current state:
Mostly built for a fork: which includes a lot of ‘why not try this’ features not tested in production. Many batteries drive fork-only commands: grading and OCIO, TRACKING, TIMELINE, NODES… but it could be forked and scaled back to exclude those.
Built around Windows, NVIDIA GPUs, DeckLink loopback cabling and VB-Audio virtual cables. Linux support is limited to a small smoke test.
Test media: Around 14 GB, regenerated by a ffmpeg script (media/generate_media.py) rather than distributed.
The post is getting quite long, if anyone wants to read more about the gritty parts I uploaded this doc (unrelated branch, just for convenience now)
Thank you @Sidon for the thorough breakdown of your harness.
I’ve been mulling over this for some days and this is my proposal. Some of the text is copy-pasted from conversations with Claude.
Test tiers
Tier
Covers
Needs
Tooling
Module
One producer or consumer in isolation. Decode, output, performance, robustness
Nothing by default
GoogleTest + a test-support library
Compositor
Frames through stage, layer, mixer and image_mixer, on both ogl and vulkan. Colour, performance
A GL or Vulkan context (GPU or Mesa software drivers)
Same harness with a real accelerator
End-to-end
The server over AMCP. Robustness
The installed binary
pytest
Unit
Pure logic in common, protocol and core
Nothing
GoogleTest + CTest
Each tier has a CTest label (unit, module, compositor, e2e). Requirement labels (accelerator, cef, decklink, etc) mark what a test needs, so it can be excluded where that is missing. Sanitizer builds (ASan, TSan) run the unit, module and end-to-end tiers.
Module
Producers and consumers have pretty clean interfaces that make them easy to test in isolation. This is the perfect place to test decode and output against expected artifacts. Also very good for roubustness as we can stress test and test specific scenarios without having to run the whole server. Could also be used to evaluate performance of individual modules.
Overview
A harness runs one producer or consumer without a server, AMCP or GPU. Producers are created through the registry with the same parameters as from AMCP.
Producers: the harness plays the channel, ticking fields and audio cadence. Generated test clips carry a frame index and an audio ramp, so output is checked exactly.
Consumers: the harness feeds generated frames, and output is captured and checked. For hardware consumers, tests only run only when the required hardware is present, and hardware configuration for capturing needs to be described in README.
Layout: tests live next to each module (src/modules/<name>/tests/), with shared helpers in a caspar_test_support library.
Concurrency checks
Module tests can all run these checks by default:
Deadlines on every call into the producer or consumer, destructor included. On a timeout, the harness dumps all thread stacks and fails the test.
Leak accounting after teardown: threads, frames, file handles and the object itself must be released.
Background errors: an error logged on any thread fails the test unless expected.
Race scenarios: helpers that run call() alongside receive() or destroy mid-operation, with optional jitter and repeat runs.
Sanitizers: TSan for data races, ASan for memory errors and leaks.
Compositor
Covers primarily Colour and mixer state, ogl and vulkan parity. Would allow testing massive amounts of permutations of state and input attributes without having to run the entire server and amcp client. Test media and “source of truth artifacts” can be generated locally using separate tools scripts, the same way as @Sidon is doing. I think this approach will be much more lightweight compared to spinning up the entire server for each test, and no need for the PRINT RAW frame export.
End-to-end and Unit
I don’t think these need any explanation.
Making tests work for AI agents
One command per tier, non-interactive, with a meaningful exit code.
Short failure output with paths to logs, plus diff images when images don’t match.
Helpers that keep a test to a few lines, so committing one is cheaper than writing a throwaway script.
Tests that need a GPU, CEF or special HW skip with a reason when it’s missing.
A CLAUDE.md / AGENTS.md saying: commit tests written to verify a change; never delete or loosen a test without saying so; where tests go and how to run them.
First steps and practical considerations
I think the first step would be to:
Get the basic harness and one or two test in place for the modules. frame factory, the producer and consumer harnesses with deadlines, log capture and thread, frame and fd accounting built.
Get some worked through end-to-ends tests and helpers in, that subsequent tests can build on.
Add a CLAUDE.md / AGENTS.md telling agents to use the plumbing that is provided for test and to commit tests along with new features and fixes.
Compare the suggested compositor test setup with @Sidon 's harness.
Unit tests are not super important for me initially, but after the steps above, all plumbing for unit tests will be in place as well.
The following suggestions are based primarily on what AI agents prefer and tend to use when not promted to use anything specific.
Test framework for C++ (GoogleTest)
Language for e2e tests and tools (Python (with pytest))
Where tests live (next to each module, plus `src/tests/` for shared and core tests)
How long would it take to get this basic framework put together? Getting the ability to safely test and merge more efficiently is important given the volume of stuff that is coming in right now. I have several patches waiting in the wings that have test harness stuff in it and I’m not sure if it should include or exclude that part until we have the basic framework merged.
I’ve been working on this on and off since I last posted. I have a hard time hitting the sweetspot regarding ease of use / complexity etc. I was hoping to have a concrete suggestion a week or so after my last post, but I’ve been swamped in work at the university lately.
Anyone is more than welcome to provide your their own take on where to start, either via a PR or continuing the discussion here. Hopefully my workload a the university will go down in a week or so.
I guess something, anything, is better than nothing…. I’ll try to tidy up and push what I have when I get home tonight
I had let the AI do too much on it’s own before I hade a thorough review, so “tidying up” was not really an option. I’ve cut out step 1 above for now just to get something up.
You are not alone. It seems more and more projects are restricting or out-right prohibiting AI-generated PRs for this and other reasons. Here is an interesting read:
Maybe CasparCG can also implement some sort of policy on this?
I personally use AI to help me understand or analyze other people’s code, or give me some ideas on how to solve problems. But, I am yet to see good code written by AI outside of some simple things.