t_dlerror-cleared.c revision 272458
11556Srgrimes/*	$NetBSD: t_dlerror-cleared.c,v 1.1 2010/12/14 05:57:32 skrll Exp $	*/
21556Srgrimes
31556Srgrimes/*
41556Srgrimes * Copyright (c) 2009 The NetBSD Foundation, Inc.
51556Srgrimes * All rights reserved.
61556Srgrimes *
71556Srgrimes * Redistribution and use in source and binary forms, with or without
81556Srgrimes * modification, are permitted provided that the following conditions
91556Srgrimes * are met:
101556Srgrimes * 1. Redistributions of source code must retain the above copyright
111556Srgrimes *    notice, this list of conditions and the following disclaimer.
121556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
131556Srgrimes *    notice, this list of conditions and the following disclaimer in the
141556Srgrimes *    documentation and/or other materials provided with the distribution.
151556Srgrimes *
161556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
171556Srgrimes * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
181556Srgrimes * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
191556Srgrimes * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
201556Srgrimes * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
211556Srgrimes * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
231556Srgrimes * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
241556Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
251556Srgrimes * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
261556Srgrimes * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
271556Srgrimes * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281556Srgrimes */
291556Srgrimes
301556Srgrimes#include <sys/types.h>
311556Srgrimes
321556Srgrimes#include <atf-c.h>
331556Srgrimes#include <dlfcn.h>
341556Srgrimes#include <link_elf.h>
353044Sdg
3625227Ssteve#include "../../h_macros.h"
371556Srgrimes
381556SrgrimesATF_TC(rtld_dlerror_cleared);
391556SrgrimesATF_TC_HEAD(rtld_dlerror_cleared, tc)
4020425Ssteve{
411556Srgrimes	atf_tc_set_md_var(tc, "descr",
421556Srgrimes	    "error set by dlopen persists past a successful dlopen call");
4317987Speter}
4417987Speter
4517987SpeterATF_TC_BODY(rtld_dlerror_cleared, tc)
4617987Speter{
471556Srgrimes	void *handle;
481556Srgrimes	char *error;
491556Srgrimes
501556Srgrimes	/*
511556Srgrimes	 * Test that an error set by dlopen() persists past a successful
521556Srgrimes	 * dlopen() call.
531556Srgrimes	 */
541556Srgrimes	handle = dlopen("libnonexistent.so", RTLD_LAZY);
551556Srgrimes	ATF_CHECK(handle == NULL);
561556Srgrimes	handle = dlopen("libm.so", RTLD_NOW);
571556Srgrimes	ATF_CHECK(handle);
581556Srgrimes	error = dlerror();
591556Srgrimes	ATF_CHECK(error);
601556Srgrimes
6117987Speter}
6217987Speter
6317987SpeterATF_TP_ADD_TCS(tp)
641556Srgrimes{
651556Srgrimes	ATF_TP_ADD_TC(tp, rtld_dlerror_cleared);
661556Srgrimes	return 0;
671556Srgrimes}
681556Srgrimes