t_dlerror-false.c revision 302408
157434Smarkm/*	$NetBSD: t_dlerror-false.c,v 1.1 2010/12/14 05:57:32 skrll Exp $	*/
257434Smarkm
3156813Sru/*
4156813Sru * Copyright (c) 2009 The NetBSD Foundation, Inc.
557434Smarkm * All rights reserved.
660577Skris *
7221420Sdes * Redistribution and use in source and binary forms, with or without
8137018Sdes * modification, are permitted provided that the following conditions
976284Sgreen * are met:
1098685Sdes * 1. Redistributions of source code must retain the above copyright
11124212Sdes *    notice, this list of conditions and the following disclaimer.
12264377Sdes * 2. Redistributions in binary form must reproduce the above copyright
13295367Sdes *    notice, this list of conditions and the following disclaimer in the
14124212Sdes *    documentation and/or other materials provided with the distribution.
15126282Sdes *
16221420Sdes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17262566Sdes * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18296853Sdes * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19296853Sdes * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20147007Sdes * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21147098Sdes * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22197679Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23147098Sdes * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2498707Sdes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25158519Sdes * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26293396Sbdrewery * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2757434Smarkm * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28255460Sdes */
29255460Sdes
30255386Sdes#include <sys/types.h>
31124249Sru
32255460Sdes#include <atf-c.h>
33255460Sdes#include <dlfcn.h>
34255460Sdes#include <link_elf.h>
35255460Sdes
36255460Sdes#include "../../h_macros.h"
37255460Sdes
38255460SdesATF_TC(rtld_dlerror_false);
39156813SruATF_TC_HEAD(rtld_dlerror_false, tc)
40185476Scsjp{
41155563Scsjp	atf_tc_set_md_var(tc, "descr",
42155563Scsjp	    "error set by dlopen persists past a successful dlopen call");
43155563Scsjp}
44155563Scsjp
45156813SruATF_TC_BODY(rtld_dlerror_false, tc)
46255829Sdes{
47293396Sbdrewery	void *handle, *sym;
48255460Sdes	char *error;
49255460Sdes
50255460Sdes	/*
51255460Sdes	 *
5295509Sru	 * Test for dlerror() being set by a successful library open.
5357434Smarkm	 * Requires that the rpath be set to something that does not
54255460Sdes	 * include libm.so.
55255460Sdes	 */
5674818Sru
57265313Skib	handle = dlopen("libm.so", RTLD_LAZY);
58265313Skib	error = dlerror();
59265313Skib	ATF_CHECK(error == NULL);
60265313Skib	ATF_CHECK(handle != NULL);
61265313Skib
62265313Skib	sym = dlsym(handle, "sin");
63265313Skib	error = dlerror();
64265313Skib	ATF_CHECK(sym != NULL);
65265313Skib	ATF_CHECK(error == NULL);
66265313Skib
67233432Seadler	dlclose(handle);
68233432Seadler	error = dlerror();
69233432Seadler
70233432Seadler	ATF_CHECK(error == NULL);
7174818Sru
7274818Sru}
7393221Sru
74ATF_TP_ADD_TCS(tp)
75{
76	ATF_TP_ADD_TC(tp, rtld_dlerror_false);
77
78	return atf_no_error();
79}
80