1 /*- 2 * 3 * Copyright (C) 2024 Kyle Evans <kevans@FreeBSD.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 * 7 */ 8 9 #include <dlfcn.h> 10 11 #include <atf-c.h> 12 13 ATF_TC_WITHOUT_HEAD(dlopen_basic); 14 ATF_TC_BODY(dlopen_basic, tc) 15 { 16 void *hdl, *sym; 17 18 hdl = dlopen("libthr.so", RTLD_NOW); 19 ATF_REQUIRE(hdl != NULL); 20 21 sym = dlsym(hdl, "pthread_create"); 22 ATF_REQUIRE(sym != NULL); 23 24 dlclose(hdl); 25 26 sym = dlsym(hdl, "pthread_create"); 27 ATF_REQUIRE(sym == NULL); 28 } 29 30 ATF_TC_WITHOUT_HEAD(dlopen_recursing); 31 ATF_TC_BODY(dlopen_recursing, tc) 32 { 33 void *hdl; 34 35 /* 36 * If this doesn't crash, we're OK; a regression at one point caused 37 * some infinite recursion here. 38 */ 39 hdl = dlopen("libthr.so", RTLD_NOW | RTLD_GLOBAL); 40 ATF_REQUIRE(hdl != NULL); 41 42 dlclose(hdl); 43 } 44 45 ATF_TP_ADD_TCS(tp) 46 { 47 48 ATF_TP_ADD_TC(tp, dlopen_basic); 49 ATF_TP_ADD_TC(tp, dlopen_recursing); 50 51 return atf_no_error(); 52 } 53