From 1b6347483e613902e791574fccb67b76194cb542 Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Wed, 30 Jul 2025 09:54:05 +0200 Subject: [PATCH 1/2] fix macOS build for plugin unit test MR !10753 breaks macOS build for plugin unit test as its linker doesn't supports `--wrap` option, which is used in in order to mock the function `isc_file_exits()`. To work around the problem, a mocked `isc_file_exits()` is implemented inside the plugin test as a static function before inlining the file using it, which effectively links to this version rather than the isclib one. --- tests/ns/meson.build | 7 ------- tests/ns/plugin_test.c | 17 +++++++++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/ns/meson.build b/tests/ns/meson.build index ca0270ca37..7d4e2e30fa 100644 --- a/tests/ns/meson.build +++ b/tests/ns/meson.build @@ -14,12 +14,6 @@ foreach unit : [ 'plugin', 'query', ] - linkargs = '' - if unit == 'plugin' - linkargs = [ - '-Wl,--wrap=isc_file_exists', - ] - endif test_bin = executable( unit, files(f'@unit@_test.c', 'netmgr_wrap.c'), @@ -37,7 +31,6 @@ foreach unit : [ cmocka_dep, nghttp2_dep, ], - link_args: linkargs, ) test( diff --git a/tests/ns/plugin_test.c b/tests/ns/plugin_test.c index 1de3e7c989..3a23d43476 100644 --- a/tests/ns/plugin_test.c +++ b/tests/ns/plugin_test.c @@ -34,17 +34,18 @@ #include -#include "../ns/hooks.c" - -bool -__wrap_isc_file_exists(const char *pathname); - -bool -__wrap_isc_file_exists(const char *pathname) { +/* + * Mocking isc_file_exists() as it's used inside the tested + * ns_plugin_expandpath() function defined in lib/ns/hooks.c + */ +static bool +isc_file_exists(const char *pathname) { UNUSED(pathname); return mock(); } +#include "../ns/hooks.c" + #include /*% @@ -75,7 +76,7 @@ run_full_path_test(const ns_plugin_expandpath_test_params_t *test, REQUIRE(test->result != ISC_R_SUCCESS || test->output != NULL); if (test->result == ISC_R_SUCCESS) { - will_return(__wrap_isc_file_exists, test->exists); + will_return(isc_file_exists, test->exists); } /* From 32909254f5fa3fdb042ce8fa1e32f7b90ec6f68d Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Wed, 30 Jul 2025 10:35:26 +0200 Subject: [PATCH 2/2] fix ns_plugin_expandpath tests with no extension Parts of ns_plugin_expandpath() test expected the plugin extension to be appened automatically (the plugin name/path is provided without the extension), this enable to test the logic which adds the correct extension based on the platfrom. But the expected expanded paths from the test were hard coded with the `.so` extension, so the test can't pass on macOS platform. This fixes the test by using the macro providing the current-platform extension. --- tests/ns/plugin_test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ns/plugin_test.c b/tests/ns/plugin_test.c index 3a23d43476..521931db57 100644 --- a/tests/ns/plugin_test.c +++ b/tests/ns/plugin_test.c @@ -150,7 +150,7 @@ ISC_RUN_TEST_IMPL(ns_plugin_expandpath) { .exists = false, .output_size = PATH_MAX, .result = ISC_R_SUCCESS, - .output = "/usr/lib/named/foo.so", + .output = "/usr/lib/named/foo" NAMED_PLUGINEXT, }, { NS_TEST_ID("correct use with a relative path and no " @@ -159,7 +159,7 @@ ISC_RUN_TEST_IMPL(ns_plugin_expandpath) { .exists = false, .output_size = PATH_MAX, .result = ISC_R_SUCCESS, - .output = "../../foo.so", + .output = "../../foo" NAMED_PLUGINEXT, }, { NS_TEST_ID("correct use with a filename and no " @@ -168,7 +168,7 @@ ISC_RUN_TEST_IMPL(ns_plugin_expandpath) { .exists = false, .output_size = PATH_MAX, .result = ISC_R_SUCCESS, - .output = NAMED_PLUGINDIR "/foo.so", + .output = NAMED_PLUGINDIR "/foo" NAMED_PLUGINEXT, }, { NS_TEST_ID("correct use with a filename and no " @@ -177,7 +177,7 @@ ISC_RUN_TEST_IMPL(ns_plugin_expandpath) { .exists = false, .output_size = PATH_MAX, .result = ISC_R_SUCCESS, - .output = NAMED_PLUGINDIR "/foo.bar.so", + .output = NAMED_PLUGINDIR "/foo.bar" NAMED_PLUGINEXT, }, { NS_TEST_ID("no space at all in target buffer"),