diff options
| author | Alex S <iwtcex@gmail.com> | 2026-03-25 00:56:01 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-03-26 23:41:23 +0000 |
| commit | 9f16078b5f8c44d5718ecc940ab0b4ed5a1877a5 (patch) | |
| tree | 2d3c8623ee1219ffed181827ff4216b4534b7024 | |
| parent | f7b368d25fadbfcba5072dfab3738082393fa189 (diff) | |
rtld: add a test for rtld_set_var (with LIBRARY_PATH_FDS)
PR: 294054
Reviewed by: kib
MFC after: 1 week
| -rw-r--r-- | libexec/rtld-elf/tests/Makefile | 1 | ||||
| -rw-r--r-- | libexec/rtld-elf/tests/set_var_test.c | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile index c4b3baab4cb8..3c05b52b83bb 100644 --- a/libexec/rtld-elf/tests/Makefile +++ b/libexec/rtld-elf/tests/Makefile @@ -7,6 +7,7 @@ SUBDIR_DEPEND_target= libpythagoras ATF_TESTS_C= ld_library_pathfds ATF_TESTS_C+= ld_preload_fds +ATF_TESTS_C+= set_var_test .for t in ${ATF_TESTS_C} SRCS.$t= $t.c common.c diff --git a/libexec/rtld-elf/tests/set_var_test.c b/libexec/rtld-elf/tests/set_var_test.c new file mode 100644 index 000000000000..6279bd5ecb44 --- /dev/null +++ b/libexec/rtld-elf/tests/set_var_test.c @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 Alex S <iwtcex@gmail.com> + */ + +#include <atf-c.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <link.h> +#include <stdio.h> + +ATF_TC_WITHOUT_HEAD(set_var_library_path_fds); +ATF_TC_BODY(set_var_library_path_fds, tc) +{ + void *handle; + char *pathfds; + int testdir; + + handle = dlopen("libpythagoras.so.0", RTLD_LAZY); + ATF_REQUIRE(handle == NULL); + + testdir = open(atf_tc_get_config_var(tc, "srcdir"), + O_RDONLY | O_DIRECTORY); + ATF_REQUIRE(testdir >= 0); + + ATF_REQUIRE(asprintf(&pathfds, "%d", testdir) > 0); + ATF_REQUIRE(rtld_set_var("LIBRARY_PATH_FDS", pathfds) == 0); + + handle = dlopen("libpythagoras.so.0", RTLD_LAZY); + ATF_REQUIRE(handle != NULL); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, set_var_library_path_fds); + return atf_no_error(); +} |
