11# Testing
22
3- The SDK includes integration and stress tests using
4- [ Google Test] ( https://github.com/google/googletest ) .
3+ The SDK includes unit, integration and stress tests using
4+ [ Google Test] ( https://github.com/google/googletest ) . It also
5+ includes a memory-leak/resource checking tester.
6+
7+ Unit, integration, and memory tests are run on every PR in CI.
8+ Stress tests are reserved for nightly tests in CI due to their
9+ length.
10+
11+ ## Test binaries
12+
13+ | Executable | Description |
14+ | ------------| -------------|
15+ | ` livekit_unit_tests ` | Unit tests (no server required) |
16+ | ` livekit_integration_tests ` | Integration tests (server required) |
17+ | ` livekit_stress_tests ` | Long-running stress tests (server required) |
18+ | ` livekit_memory_tester ` | Resource leak tester |
519
620## Building the test binaries
721
@@ -19,31 +33,23 @@ The SDK includes integration and stress tests using
1933
2034## Running tests
2135
22- After building, run tests using ` ctest ` or invoke the binaries directly:
23-
2436``` bash
25- # Run all tests via ctest
26- cd build-debug
37+ # Run all tests via ctest (warning, runs all GTest-based tests including stress)
38+ cd build-debug # or build-release
2739ctest --output-on-failure
2840
2941# Or run test executables directly
42+ ./build-debug/bin/livekit_unit_tests
3043./build-debug/bin/livekit_integration_tests
3144./build-debug/bin/livekit_stress_tests
3245
3346# Run specific test suites
47+ ./build-debug/bin/livekit_unit_tests --gtest_filter=" *Room*"
3448./build-debug/bin/livekit_integration_tests --gtest_filter=" *Rpc*"
3549./build-debug/bin/livekit_stress_tests --gtest_filter=" *MaxPayloadStress*"
3650```
3751
38- __ Note:__ The tests require tokens and a running LiveKit server. See the section below for details.
39-
40- ## Test binaries
41-
42- | Executable | Description |
43- | ------------| -------------|
44- | ` livekit_unit_tests ` | Pure unit tests (no server required) |
45- | ` livekit_integration_tests ` | Quick tests (~ 1-2 minutes) for SDK functionality |
46- | ` livekit_stress_tests ` | Long-running tests (configurable, default 1 hour) |
52+ __ Note:__ The integration and stress tests require tokens and a running LiveKit server. See the section below for details.
4753
4854## Running a local LiveKit server for tests
4955
@@ -52,9 +58,10 @@ path is `livekit-server --dev`, which uses the well-known dev API
5258key/secret (` devkey ` / ` secret ` ).
5359
5460Install [ ` livekit-server ` ] ( https://docs.livekit.io/home/self-hosting/local/ )
55- and start it with data tracks enabled:
61+ and start it with data blobs enabled:
5662
5763``` bash
64+ LIVEKIT_CONFIG=" enable_participant_data_blob: true"
5865livekit-server --dev
5966```
6067
@@ -177,7 +184,88 @@ cold runs even though C++ dependencies are reused.
177184- ** RPC** : round-trip calls, max payload (15 KB), timeouts, errors, concurrent calls.
178185- ** Stress** : high throughput, bidirectional RPC, memory pressure.
179186
180- ## Memory checks (valgrind)
187+ ## Memory tester
188+
189+ > Note: Linux only
190+
191+ The memory tester binary catches resource leak regressions in an
192+ automated fashion, and is invoked in CI. This single binary runs individual
193+ or groups of scenarios:
194+
195+ - ` audio-track ` repeatedly initializes the SDK, connects, publishes an audio
196+ track, captures synthetic PCM frames, unpublishes, disconnects, and shuts down.
197+ - ` video-track ` repeatedly initializes the SDK, connects, publishes a video
198+ track, captures synthetic I420 frames, unpublishes, disconnects, and shuts down.
199+ - ` data-track ` repeatedly connects, publishes a data track, pushes synthetic
200+ payloads, unpublishes it, and disconnects.
201+ - ` room-reuse ` repeatedly connects and disconnects the same room object.
202+ - ` room-client-leave ` repeatedly connects, disconnects, and destroys a room.
203+ - ` room-server-delete ` repeatedly connects, publishes one synthetic video
204+ track, captures I420 frames without unpublishing, and uses ` lk ` to delete
205+ the local test room. It then verifies the disconnect and end-of-stream
206+ callbacks.
207+ - ` capture-clock ` repeatedly initializes the SDK, creates and publishes the
208+ GPU-rendered clock capture source, starts and stops its frame pump, joins its
209+ worker, unpublishes, disconnects, and shuts down. Each cycle must produce at
210+ least three frames, so the default 100-cycle run captures at least 300 frames
211+ (10 seconds of video at 30 fps).
212+ - ` capture-pattern ` exercises the same lifecycle with the GPU-rendered gradient
213+ pattern capture source.
214+ - ` capture-gstreamer ` exercises the same lifecycle through an entirely
215+ software-based GStreamer pipeline (` videotestsrc ` and ` vp8enc ` ), including
216+ encoded-frame ingest and WebRTC passthrough.
217+
218+ Each scenario reports process RSS and thread count at cycle 0, after warmup
219+ cycle 20, and after final cycle 100. Checkpoint sampling waits for the thread
220+ count to remain stable for 500 ms so short-lived teardown work does not cause a
221+ false failure. The gate applies to warmup-to-final growth. CI fails above its
222+ blocking limits of 24 MiB RSS or two threads, which protects against large
223+ customer-impacting regressions while allowing for allocator and dependency
224+ variation. It also emits a non-blocking advisory above 8 MiB RSS or zero
225+ threads. If threads grow, the tester reports when the final sustained growth
226+ began and groups the warmup and final threads by their Linux thread names.
227+
228+ The binary can be run directly, or via a helper script at ` scripts/memory-tester.sh ` ,
229+ which invokes the binary but also has GitHub actions support for a results summary table.
230+ The helper defaults ` MALLOC_ARENA_MAX ` to ` 1 ` when launching each tester process.
231+ This limits ` glibc ` 's allocator arenas, reducing Linux thread-churn RSS noise, but it is
232+ not evidence that the default allocator returns all freed pages to the OS.
233+
234+ Start ` livekit-server --dev ` , install the ` lk ` CLI, and source the local test
235+ tokens before running any scenario:
236+
237+ ``` bash
238+ ./build.sh release-tests --capture=all
239+ source scripts/set-test-tokens.sh
240+ scripts/memory-tester.sh --scenario audio-track \
241+ --iterations 100 --warmup 20 \
242+ --max-rss-growth-mib 24 --max-thread-growth 2 \
243+ --advisory-max-rss-growth-mib 8 --advisory-max-thread-growth 0
244+ scripts/memory-tester.sh --scenario video-track \
245+ --iterations 100 --warmup 20 \
246+ --max-rss-growth-mib 24 --max-thread-growth 2 \
247+ --advisory-max-rss-growth-mib 8 --advisory-max-thread-growth 0
248+ ```
249+
250+ Use ` --scenario all ` to run all nine scenarios, each in a fresh tester process:
251+
252+ ``` bash
253+ scripts/memory-tester.sh --scenario data-track
254+ scripts/memory-tester.sh --scenario room-reuse
255+ scripts/memory-tester.sh --scenario room-client-leave
256+ scripts/memory-tester.sh --scenario room-server-delete
257+ scripts/memory-tester.sh --scenario capture-clock
258+ scripts/memory-tester.sh --scenario capture-pattern
259+ scripts/memory-tester.sh --scenario capture-gstreamer
260+ scripts/memory-tester.sh --scenario all
261+ ```
262+
263+ The blocking and advisory limits are command-line options so a longer local run
264+ can use different budgets. When advisory limits are omitted, they default to the
265+ blocking limits. RSS growth thresholds are expressed in MiB and may be
266+ fractional, such as ` --advisory-max-rss-growth-mib 0.5 ` .
267+
268+ ## Additional memory checks (valgrind)
181269
182270Run ` valgrind ` against the test binaries to check for memory leaks and other
183271issues. See [ tools.md] ( tools.md ) for the recipe.
0 commit comments