xref: /freebsd/libexec/rtld-elf/tests/dlopen_hash_test.c (revision 72252591ac01037fa53501adb88f00d5d3cc09ed)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2026 Alex S <iwtcex@gmail.com>
5  * Copyright 2026 The FreeBSD Foundation
6  *
7  * Portions of this software were developed by
8  * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
9  * the FreeBSD Foundation.
10  */
11 
12 #include <atf-c.h>
13 #include <dlfcn.h>
14 #include <fcntl.h>
15 #include <link.h>
16 #include <stdio.h>
17 
18 ATF_TC_WITHOUT_HEAD(dlopen_hash);
ATF_TC_BODY(dlopen_hash,tc)19 ATF_TC_BODY(dlopen_hash, tc)
20 {
21 	void *handle;
22 	char *pathfds;
23 	char *name;
24 	int testdir;
25 
26 	handle = dlopen("libpythagoras.so.0", RTLD_LAZY);
27 	ATF_REQUIRE(handle == NULL);
28 
29 	testdir = open(atf_tc_get_config_var(tc, "srcdir"),
30 	    O_RDONLY | O_DIRECTORY);
31 	ATF_REQUIRE(testdir >= 0);
32 
33 	ATF_REQUIRE(asprintf(&pathfds, "%d", testdir) > 0);
34 	ATF_REQUIRE(rtld_set_var("LIBRARY_PATH_FDS", pathfds) == 0);
35 
36 	ATF_REQUIRE(asprintf(&name, "#%d/libpythagoras.so.0", testdir) > 0);
37 	handle = dlopen(name,  RTLD_LAZY);
38 	ATF_REQUIRE(handle != NULL);
39 }
40 
ATF_TP_ADD_TCS(tp)41 ATF_TP_ADD_TCS(tp)
42 {
43 	ATF_TP_ADD_TC(tp, dlopen_hash);
44 	return atf_no_error();
45 }
46