1 1.3 skrll /* $NetBSD: t_dlerror-false.c,v 1.3 2022/01/14 07:34:07 skrll Exp $ */ 2 1.1 skrll 3 1.1 skrll /* 4 1.1 skrll * Copyright (c) 2009 The NetBSD Foundation, Inc. 5 1.1 skrll * All rights reserved. 6 1.1 skrll * 7 1.1 skrll * Redistribution and use in source and binary forms, with or without 8 1.1 skrll * modification, are permitted provided that the following conditions 9 1.1 skrll * are met: 10 1.1 skrll * 1. Redistributions of source code must retain the above copyright 11 1.1 skrll * notice, this list of conditions and the following disclaimer. 12 1.1 skrll * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 skrll * notice, this list of conditions and the following disclaimer in the 14 1.1 skrll * documentation and/or other materials provided with the distribution. 15 1.1 skrll * 16 1.1 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17 1.1 skrll * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 1.1 skrll * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 1.1 skrll * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.1 skrll * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21 1.1 skrll * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 1.1 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 1.1 skrll * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 1.1 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 1.1 skrll * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 1.1 skrll * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 1.1 skrll * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 1.1 skrll */ 29 1.1 skrll 30 1.1 skrll #include <sys/types.h> 31 1.1 skrll 32 1.1 skrll #include <atf-c.h> 33 1.1 skrll #include <dlfcn.h> 34 1.1 skrll #include <link_elf.h> 35 1.1 skrll 36 1.2 christos #include "h_macros.h" 37 1.1 skrll 38 1.1 skrll ATF_TC(rtld_dlerror_false); 39 1.1 skrll ATF_TC_HEAD(rtld_dlerror_false, tc) 40 1.1 skrll { 41 1.1 skrll atf_tc_set_md_var(tc, "descr", 42 1.1 skrll "error set by dlopen persists past a successful dlopen call"); 43 1.1 skrll } 44 1.1 skrll 45 1.1 skrll ATF_TC_BODY(rtld_dlerror_false, tc) 46 1.1 skrll { 47 1.1 skrll void *handle, *sym; 48 1.1 skrll char *error; 49 1.3 skrll 50 1.1 skrll /* 51 1.3 skrll * 52 1.1 skrll * Test for dlerror() being set by a successful library open. 53 1.1 skrll * Requires that the rpath be set to something that does not 54 1.1 skrll * include libm.so. 55 1.1 skrll */ 56 1.1 skrll 57 1.1 skrll handle = dlopen("libm.so", RTLD_LAZY); 58 1.1 skrll error = dlerror(); 59 1.1 skrll ATF_CHECK(error == NULL); 60 1.1 skrll ATF_CHECK(handle != NULL); 61 1.3 skrll 62 1.1 skrll sym = dlsym(handle, "sin"); 63 1.1 skrll error = dlerror(); 64 1.1 skrll ATF_CHECK(sym != NULL); 65 1.1 skrll ATF_CHECK(error == NULL); 66 1.1 skrll 67 1.1 skrll dlclose(handle); 68 1.1 skrll error = dlerror(); 69 1.1 skrll 70 1.1 skrll ATF_CHECK(error == NULL); 71 1.3 skrll 72 1.1 skrll } 73 1.1 skrll 74 1.1 skrll ATF_TP_ADD_TCS(tp) 75 1.1 skrll { 76 1.1 skrll ATF_TP_ADD_TC(tp, rtld_dlerror_false); 77 1.1 skrll 78 1.1 skrll return atf_no_error(); 79 1.1 skrll } 80