From 56ecae8bc49214a6008a246f977d4e646f760de6 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Wed, 25 Nov 2026 05:26:45 -0800 Subject: [PATCH] test: characterize obs_output_set_service (Refs #5664) Client-Checks: {"checks":{"base":"1a371e8bc576a915376715bf91ad39d30518b860","coverage":"all-tracked-applicable-files","diff":["test/cmocka/build/test-graph.json","test/cmocka/test_output_set_service.c"],"head":"d8c7642acca68bb025d27c4ab862fb2856427a53","tools":{"orchestrator-python":"3.13.15 (main, Aug 14 2026, 15:34:59) [Clang 22.1.3 ]","schema-dependencies":"3.13.15 (main, Aug 14 2026, 15:34:59) [Clang 22.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21503\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ISO8859X Regexps Automata RelaxNG Schemas Modules Debug"},"tracked-digest":"8b27f30be1d2bb590941e52e5dc26cb48703270eb906990c27b219ad4d1dde56","tree":"c8abfa30919e65db94a51b72fcabf37360957300"}} Ci-Attestation: {"at":1795669124,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1a371e8bc576a915376715bf91ad39d30518b860"],"secs":82,"stamp":"65ffa288cf55ea6e50c539251a456257","tree":"c8abfa30919e65db94a51b72fcabf37360957300","v":1,"via":"run"} Ci-Attestation: {"at":1795669124,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1a371e8bc576a915376715bf91ad39d30518b860"],"secs":82,"stamp":"eb34961baa22644ddc5ef180f04d6579","tree":"c8abfa30919e65db94a51b72fcabf37360957300","v":1,"via":"run"} Ci-Attestation: {"at":1795669124,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1a371e8bc576a915376715bf91ad39d30518b860"],"secs":82,"stamp":"d1a71f8a14d80483b48e4828e9056426","tree":"c8abfa30919e65db94a51b72fcabf37360957300","v":1,"via":"run"} Ci-Attestation: {"at":1795669124,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1a371e8bc576a915376715bf91ad39d30518b860"],"secs":82,"stamp":"a3674ead2c5f781127dbc27768167978","tree":"c8abfa30919e65db94a51b72fcabf37360957300","v":1,"via":"run"} Ci-Attestation: {"at":1796412299,"gate":"general/all/client-lint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"e59f71ff5166e77bb0ce1ef0e6fff17f","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1795669124,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1a371e8bc576a915376715bf91ad39d30518b860"],"secs":82,"stamp":"43da2d00e40295830a02b2c03abda882","tree":"c8abfa30919e65db94a51b72fcabf37360957300","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"bab797e382b10bc9877d784be3771705","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"ba47970eb6e90dced72b53d20e337027","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"41d761c8b6448a7661fe46628c6d0f6b","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"924abb7bab0cd283603b536dd76b6308","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412299,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"d88e7339b770ba504c3d4d478e2f4548","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412299,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"6538030448fb79d200d7b078e5c33770","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"2ea4f04d58a46ebc1c48785696aaeb23","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"1313a56fea0a366fc5330a320412a353","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412299,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"cf40c416f9ae3da828bd757f108417b8","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412300,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"42f29b4fa16a4987170762cc1e649890","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412299,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"e902d6dee053e3ec803b27c11473955e","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1796412299,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"1f9a9884997f334dc201b539e50994a6d09183ef822bb84f27c3ac7c8a66bf4d","lane":"client-lint","parents":["f4b266b71bab7a58eac7e2cad3f1c1a6e4e0231b"],"secs":27,"stamp":"3e758ad20f922f4b3726748232e1cd70","tree":"c0feef3bffc699dcd2592189eeb2292fa0b8dfd5","v":1,"via":"run"} Ci-Attestation: {"at":1795669395,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"2c3e8cbfbd7b9600f34095b3dd0bd9acc48b7e55a275faaccff5ee79a4f59f3e","lane":"client-test-x86_64-unknown-linux-gnu","parents":["1a371e8bc576a915376715bf91ad39d30518b860"],"secs":269,"stamp":"bb8d036a0ef1d5e55b8f64794447ccbe","tree":"c8abfa30919e65db94a51b72fcabf37360957300","v":1,"via":"run"} --- .../test-graph.d/test_output_set_service.json | 29 +++ test/cmocka/test_output_set_service.c | 179 ++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 test/cmocka/build/test-graph.d/test_output_set_service.json create mode 100644 test/cmocka/test_output_set_service.c diff --git a/test/cmocka/build/test-graph.d/test_output_set_service.json b/test/cmocka/build/test-graph.d/test_output_set_service.json new file mode 100644 index 0000000000..253bb4d023 --- /dev/null +++ b/test/cmocka/build/test-graph.d/test_output_set_service.json @@ -0,0 +1,29 @@ +{ + "schema": 1, + "targets": { + "test_output_set_service": { + "sources": [ + "test/cmocka/test_output_set_service.c" + ], + "libraries": [ + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "SIMDe::SIMDe", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ] + } + }, + "tests": { + "test_output_set_service": { + "target": "test_output_set_service", + "command": [ + "${target}" + ] + } + } +} diff --git a/test/cmocka/test_output_set_service.c b/test/cmocka/test_output_set_service.c new file mode 100644 index 0000000000..dddec92d20 --- /dev/null +++ b/test/cmocka/test_output_set_service.c @@ -0,0 +1,179 @@ +/* Direct actual-library characterization of obs_output_set_service. + * Private-layout fixtures need no core startup, allocation, or destruction: + * this setter only checks flags/active state and writes borrowed links. + * In particular, replacing an output's service leaves the old service's + * reverse link intact: characterized, not endorsed. */ +#include +#include +#include +#include +#include +#include +#include "obs-internal.h" + +struct capture { + unsigned count; + int level; + char text[256]; +}; + +static struct capture logs; +static log_handler_t previous_handler; +static void *previous_param; + +static void capture_log(int level, const char *format, va_list args, void *param) +{ + struct capture *capture = param; + capture->count++; + capture->level = level; + vsnprintf(capture->text, sizeof(capture->text), format, args); +} + +static int setup(void **state) +{ + (void)state; + memset(&logs, 0, sizeof(logs)); + base_get_log_handler(&previous_handler, &previous_param); + base_set_log_handler(capture_log, &logs); + return 0; +} + +static int teardown(void **state) +{ + (void)state; + base_set_log_handler(previous_handler, previous_param); + return 0; +} + +struct links { + struct obs_output outputs[2]; + struct obs_service services[2]; +}; + +static void initialize(struct links *links) +{ + memset(links, 0, sizeof(*links)); + links->outputs[0].context.name = "target"; + links->outputs[0].info.flags = OBS_OUTPUT_SERVICE; + links->outputs[1].context.name = "old output"; + links->outputs[1].info.flags = OBS_OUTPUT_SERVICE; +} + +static void null_output(void **state) +{ + (void)state; + struct obs_service service = {0}, before; + memcpy(&before, &service, sizeof(before)); + obs_output_set_service(NULL, &service); + assert_memory_equal(&service, &before, sizeof(service)); + assert_int_equal(logs.count, 1); + assert_int_equal(logs.level, LOG_DEBUG); + assert_string_equal(logs.text, "obs_output_set_service: Null 'output' parameter"); + obs_output_set_service(NULL, NULL); + assert_int_equal(logs.count, 2); +} + +static void refusal_gates(void **state) +{ + (void)state; + /* Every combination pins the flag warning before later refusals. A + * NULL service is a refusal, never a request to clear an existing link. */ + for (unsigned flags = 0; flags < 2; flags++) { + for (unsigned output_active = 0; output_active < 2; output_active++) { + for (unsigned service_active = 0; service_active < 2; service_active++) { + for (unsigned missing = 0; missing < 2; missing++) { + if (flags && !output_active && !service_active && !missing) + continue; + struct links links, before; + initialize(&links); + links.outputs[0].info.flags = flags ? OBS_OUTPUT_SERVICE : OBS_OUTPUT_VIDEO; + links.outputs[0].active = output_active != 0; + links.outputs[0].service = &links.services[0]; + links.services[0].output = &links.outputs[0]; + links.outputs[1].service = &links.services[1]; + links.services[1].output = &links.outputs[1]; + links.services[1].active = service_active != 0; + memcpy(&before, &links, sizeof(before)); + memset(&logs, 0, sizeof(logs)); + obs_output_set_service(&links.outputs[0], missing ? NULL : &links.services[1]); + assert_memory_equal(&links, &before, sizeof(links)); + assert_int_equal(logs.count, flags ? 0 : 1); + if (!flags) { + assert_int_equal(logs.level, LOG_WARNING); + assert_string_equal( + logs.text, + "Output 'target': Tried to use obs_output_set_service on a non-service output"); + } + } + } + } + } +} + +static void assign_and_repeat(void **state) +{ + (void)state; + struct links links, expected; + initialize(&links); + /* Unrelated output flags do not prevent service attachment. */ + links.outputs[0].info.flags |= OBS_OUTPUT_VIDEO | OBS_OUTPUT_ENCODED; + memcpy(&expected, &links, sizeof(expected)); + expected.outputs[0].service = &links.services[0]; + expected.services[0].output = &links.outputs[0]; + obs_output_set_service(&links.outputs[0], &links.services[0]); + assert_memory_equal(&links, &expected, sizeof(links)); + obs_output_set_service(&links.outputs[0], &links.services[0]); + assert_memory_equal(&links, &expected, sizeof(links)); + assert_int_equal(logs.count, 0); +} + +static void transfer_detaches_old_output(void **state) +{ + (void)state; + struct links links, expected; + initialize(&links); + /* The old output's active state and service flag are not admission gates. */ + links.outputs[1].active = true; + links.outputs[1].info.flags = 0; + links.outputs[1].service = &links.services[0]; + links.services[0].output = &links.outputs[1]; + memcpy(&expected, &links, sizeof(expected)); + expected.outputs[1].service = NULL; + expected.outputs[0].service = &links.services[0]; + expected.services[0].output = &links.outputs[0]; + obs_output_set_service(&links.outputs[0], &links.services[0]); + assert_memory_equal(&links, &expected, sizeof(links)); + assert_int_equal(logs.count, 0); +} + +static void replacement_keeps_former_reverse_link(void **state) +{ + (void)state; + struct links links, expected; + initialize(&links); + links.outputs[0].service = &links.services[0]; + links.services[0].output = &links.outputs[0]; + links.outputs[1].service = &links.services[1]; + links.services[1].output = &links.outputs[1]; + memcpy(&expected, &links, sizeof(expected)); + expected.outputs[1].service = NULL; + expected.outputs[0].service = &links.services[1]; + expected.services[1].output = &links.outputs[0]; + /* No refcount, ownership, or former-service cleanup is added here. */ + obs_output_set_service(&links.outputs[0], &links.services[1]); + assert_memory_equal(&links, &expected, sizeof(links)); + assert_ptr_equal(links.services[0].output, &links.outputs[0]); + assert_int_equal(logs.count, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(null_output, setup, teardown), + cmocka_unit_test_setup_teardown(refusal_gates, setup, teardown), + cmocka_unit_test_setup_teardown(assign_and_repeat, setup, teardown), + cmocka_unit_test_setup_teardown(transfer_detaches_old_output, setup, teardown), + cmocka_unit_test_setup_teardown(replacement_keeps_former_reverse_link, setup, teardown), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +}