From 659ac39090378b503bd483a205cc551925164fa0 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 09:07:12 -0800 Subject: [PATCH 1/5] test: add RED null audio-monitoring characterization (Refs #5262) --- test/cmocka/build/test-graph.json | 49 ++++++ test/cmocka/test_null_audio_monitoring.c | 148 ++++++++++++++++++ .../tests.d/test_null_audio_monitoring.cmake | 4 + 3 files changed, 201 insertions(+) create mode 100644 test/cmocka/test_null_audio_monitoring.c create mode 100644 test/cmocka/tests.d/test_null_audio_monitoring.cmake diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index b1e12a5040..2d5bb10592 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -9316,6 +9316,36 @@ "SIMDe::SIMDe" ] }, + "test_null_audio_monitoring": { + "sources": [ + "test/cmocka/test_null_audio_monitoring.c" + ], + "includes": [ + ".", + "libobs" + ], + "libraries": [ + "OBS::libobs", + "OBS::native-test-cmocka" + ], + "watch_inputs": [ + "libobs/audio-monitoring/null/null-audio-monitoring.c.h", + "libobs/build/libobs-nix.pch.h" + ], + "requires": { + "all": [ + { + "any": [ + "OS_LINUX", + "OS_FREEBSD" + ] + }, + { + "not": "ENABLE_PULSEAUDIO" + } + ] + } + }, "test_null_output_stop_thread": { "sources": [ "test/cmocka/test_null_output_stop_thread.c" @@ -25096,6 +25126,25 @@ "${target}" ] }, + "test_null_audio_monitoring": { + "target": "test_null_audio_monitoring", + "command": [ + "${target}" + ], + "requires": { + "all": [ + { + "any": [ + "OS_LINUX", + "OS_FREEBSD" + ] + }, + { + "not": "ENABLE_PULSEAUDIO" + } + ] + } + }, "test_null_output_stop_thread": { "target": "test_null_output_stop_thread", "command": [ diff --git a/test/cmocka/test_null_audio_monitoring.c b/test/cmocka/test_null_audio_monitoring.c new file mode 100644 index 0000000000..19c01f75f1 --- /dev/null +++ b/test/cmocka/test_null_audio_monitoring.c @@ -0,0 +1,148 @@ +/* Null backend characterization, before its Rust swap. The public calls below + * use the real selected libobs (C-reference or hybrid), so registration must + * mirror Linux/FreeBSD's ENABLE_PULSEAUDIO=OFF backend selection. + * + * The four private functions are hidden in libobs. Characterize the unchanged + * whole C backend under distinct names as well; these source-only assertions + * must be mirrored against the Rust implementation in the later swap. */ +#include +#include +#include +#include + +#include "build/libobs-nix.pch.h" + +#define obs_audio_monitoring_available null_c_available +#define obs_enum_audio_monitoring_devices null_c_enum_devices +#define audio_monitor_create null_c_create +#define audio_monitor_reset null_c_reset +#define audio_monitor_destroy null_c_destroy +#define devices_match null_c_devices_match +#include "libobs/audio-monitoring/null/null-audio-monitoring.c.h" +#undef obs_audio_monitoring_available +#undef obs_enum_audio_monitoring_devices +#undef audio_monitor_create +#undef audio_monitor_reset +#undef audio_monitor_destroy +#undef devices_match + +static unsigned log_calls; +static long allocation_count; +static log_handler_t previous_log_handler; +static void *previous_log_data; + +static void count_log(int level, const char *format, va_list args, void *data) +{ + (void)level; + (void)format; + (void)args; + (void)data; + log_calls++; +} + +static int setup(void **state) +{ + (void)state; + base_get_log_handler(&previous_log_handler, &previous_log_data); + base_set_log_handler(count_log, NULL); + log_calls = 0; + allocation_count = bnum_allocs(); + return 0; +} + +static int teardown(void **state) +{ + (void)state; + base_set_log_handler(previous_log_handler, previous_log_data); + assert_int_equal(log_calls, 0); + assert_int_equal(bnum_allocs(), allocation_count); + return 0; +} + +static void availability_is_false_without_startup(void **state) +{ + (void)state; + assert_true(obs_audio_monitoring_available()); /* deliberately wrong RED expectation */ + assert_false(null_c_available()); +} + +static bool unexpected_device(void *data, const char *name, const char *id) +{ + (void)data; + (void)name; + (void)id; + /* No callback, even one that would stop enumeration, may be invoked. */ + fail(); + return false; +} + +static void enumeration_never_calls_back_or_writes_data(void **state) +{ + (void)state; + unsigned char data[] = {0xa5, 0x00, 0xff, 0x5a}; + const unsigned char saved[] = {0xa5, 0x00, 0xff, 0x5a}; + obs_enum_audio_monitoring_devices(unexpected_device, data); + obs_enum_audio_monitoring_devices(unexpected_device, NULL); + obs_enum_audio_monitoring_devices(NULL, data); + obs_enum_audio_monitoring_devices(NULL, NULL); + null_c_enum_devices(unexpected_device, data); + null_c_enum_devices(unexpected_device, NULL); + null_c_enum_devices(NULL, data); + null_c_enum_devices(NULL, NULL); + assert_memory_equal(data, saved, sizeof(data)); +} + +static void lifecycle_ignores_null_and_nonnull_handles(void **state) +{ + (void)state; + /* These bytes are not an OBS object. The null backend never dereferences, + * initializes, takes ownership of, or frees the caller's pointer. */ + union { + long double alignment; + void *pointer_alignment; + unsigned char bytes[64]; + } storage; + memset(&storage, 0xa5, sizeof(storage)); + unsigned char saved[sizeof(storage)]; + memcpy(saved, &storage, sizeof(storage)); + assert_null(null_c_create(NULL)); + assert_null(null_c_create((obs_source_t *)&storage)); + null_c_reset(NULL); + null_c_reset((struct audio_monitor *)&storage); + null_c_destroy(NULL); + null_c_destroy((struct audio_monitor *)&storage); + /* Repeat to characterize the absence of ownership or state changes. */ + null_c_reset((struct audio_monitor *)&storage); + null_c_destroy((struct audio_monitor *)&storage); + assert_null(null_c_create((obs_source_t *)&storage)); + assert_memory_equal(&storage, saved, sizeof(storage)); +} + +static void device_matching_is_always_false(void **state) +{ + (void)state; + char equal1[] = "same"; + char equal2[] = "same"; + char bytes[] = {(char)0xff, (char)0x80, 'x', 0}; + char unterminated[] = {'x', 'y'}; + const char *ids[] = {NULL, "", "default", equal1, equal2, "different", bytes, unterminated}; + for (size_t i = 0; i < sizeof(ids) / sizeof(ids[0]); i++) + for (size_t j = 0; j < sizeof(ids) / sizeof(ids[0]); j++) + assert_false(null_c_devices_match(ids[i], ids[j])); + assert_string_equal(equal1, "same"); + assert_string_equal(equal2, "same"); + const char saved_bytes[] = {(char)0xff, (char)0x80, 'x', 0}; + assert_memory_equal(bytes, saved_bytes, sizeof(bytes)); + assert_memory_equal(unterminated, "xy", sizeof(unterminated)); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(availability_is_false_without_startup, setup, teardown), + cmocka_unit_test_setup_teardown(enumeration_never_calls_back_or_writes_data, setup, teardown), + cmocka_unit_test_setup_teardown(lifecycle_ignores_null_and_nonnull_handles, setup, teardown), + cmocka_unit_test_setup_teardown(device_matching_is_always_false, setup, teardown), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/tests.d/test_null_audio_monitoring.cmake b/test/cmocka/tests.d/test_null_audio_monitoring.cmake new file mode 100644 index 0000000000..cba7b684c0 --- /dev/null +++ b/test/cmocka/tests.d/test_null_audio_monitoring.cmake @@ -0,0 +1,4 @@ +# Target and direct test command live in ../build/test-graph.json. +# Only Linux/FreeBSD with ENABLE_PULSEAUDIO=OFF link the real null backend. +# Public assertions exercise that library; renamed private assertions exercise +# the unchanged C source only, to be mirrored against Rust in the later swap. From c6f80ea9cecde45558a73c81c85acff3d7894ced Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 09:10:30 -0800 Subject: [PATCH 2/5] test: supply private header dependencies for null characterization (Refs #5262) --- test/cmocka/build/test-graph.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 2d5bb10592..8d3839b000 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -9326,6 +9326,8 @@ ], "libraries": [ "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", "OBS::native-test-cmocka" ], "watch_inputs": [ From 4876ad43ecd7259ea13cab2a3544410df5994cb6 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 09:18:01 -0800 Subject: [PATCH 3/5] build: declare null monitor private device matcher before definition (Refs #5262) --- libobs/audio-monitoring/null/null-audio-monitoring.c.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libobs/audio-monitoring/null/null-audio-monitoring.c.h b/libobs/audio-monitoring/null/null-audio-monitoring.c.h index b3b0faceaa..8060439aac 100644 --- a/libobs/audio-monitoring/null/null-audio-monitoring.c.h +++ b/libobs/audio-monitoring/null/null-audio-monitoring.c.h @@ -1,5 +1,9 @@ #include "build/libobs-nix.pch.h" +/* The PulseAudio backend declares this private caller contract in its wrapper + * header. The null backend has no wrapper header, but needs the same prototype. */ +bool devices_match(const char *id1, const char *id2); + bool obs_audio_monitoring_available(void) { return false; From 57b4e5302746d4d1e44e5e7a2a1b0048606237f4 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 09:23:54 -0800 Subject: [PATCH 4/5] test: pin GREEN null audio-monitoring availability (Refs #5262) --- test/cmocka/test_null_audio_monitoring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cmocka/test_null_audio_monitoring.c b/test/cmocka/test_null_audio_monitoring.c index 19c01f75f1..9b21346ad3 100644 --- a/test/cmocka/test_null_audio_monitoring.c +++ b/test/cmocka/test_null_audio_monitoring.c @@ -62,7 +62,7 @@ static int teardown(void **state) static void availability_is_false_without_startup(void **state) { (void)state; - assert_true(obs_audio_monitoring_available()); /* deliberately wrong RED expectation */ + assert_false(obs_audio_monitoring_available()); assert_false(null_c_available()); } From cda275cdd3603ab1165b66fdbd1e0684f2516f5c Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 09:34:49 -0800 Subject: [PATCH 5/5] test: account for fallback-only null monitor inventory (Refs #5262) Ci-Attestation: {"at":1795111012,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":356,"stamp":"a93f3f6328386f2ec4a9c2b2426e41b4","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795111012,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":356,"stamp":"a7f85a5a681bf71a8d5af60a75c2ed70","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795111012,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":356,"stamp":"be059a13f9d2e27e5cc383499e4dc61c","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795111012,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":356,"stamp":"7857ec82c8e5c3719e07847d32dc666a","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110649,"gate":"general/all/client-lint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"bf93a5ccce6ba7ac813a63bb9afa207a","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795111012,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":356,"stamp":"b9b786a4e8ff6f40f3a73f08ba28e070","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110652,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"11ebea8cf23fbc03a3f949f2fdad5e1b","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110652,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"d53079177f988d99be1ee1045652f1bb","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110651,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"1021233bb1317f7f61f57fdb42226fca","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110651,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"4d4ec80e0f342661a83e589125347162","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110650,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"4a4c7e201784e175a59ba4b5a7d2dc63","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110650,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"802f8b5c282a91fb6268e4f14fc4a79b","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110651,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"3acdc9644ccec09a8db1b2c499a1a99c","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110652,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"0c11ab19c6d2efe94c6f704e21302d20","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110650,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"3ba7196f6d9c5e70c694d1d9b57e378e","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110651,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"dbea8437c037cf44cae634c76964c7f0","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110649,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"580ef5b6b8d6af948de9f99f472dccaf","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} Ci-Attestation: {"at":1795110649,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"f8d0276b4057afb899edd4c7353901ac31932e10540208103f3e294848bc0fed","lane":"client-lint","parents":["57b4e5302746d4d1e44e5e7a2a1b0048606237f4"],"secs":500,"stamp":"374074172f8c998db9c585a10da9bbeb","tree":"98ca89d794c5d1472ebb4e13503a754a30975735","v":1,"via":"run"} --- ci/test_native_b2_portability.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/test_native_b2_portability.py b/ci/test_native_b2_portability.py index 2ee3cb275b..453e9b2b8a 100644 --- a/ci/test_native_b2_portability.py +++ b/ci/test_native_b2_portability.py @@ -738,7 +738,9 @@ def selected_tests(): self.assertEqual(len(sdk_selected), len(selected) + 2) for hevc in (False, True): - self.assertEqual(len(inventories[True, hevc]) - len(inventories[False, hevc]), 6) + self.assertEqual(inventories[False, hevc] - inventories[True, hevc], + {"test_null_audio_monitoring"}) + self.assertEqual(len(inventories[True, hevc] - inventories[False, hevc]), 6) for pulse in (False, True): self.assertEqual(len(inventories[pulse, True]) - len(inventories[pulse, False]), 1) self.assertGreaterEqual(len(inventories[False, True]), 417)