1 /* $NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $ */
3 * Copyright (c) 2013 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $");
44 ATF_TC_HEAD(dlopen
, tc
)
46 atf_tc_set_md_var(tc
, "descr",
47 "Test if dlopen can load -lpthread DSO");
50 #define DSO TESTDIR "/h_pthread_dlopen.so"
52 ATF_TC_BODY(dlopen
, tc
)
55 int (*testf_dso_null
)(void);
56 handle
= dlopen(DSO
, RTLD_NOW
| RTLD_LOCAL
);
57 ATF_REQUIRE_MSG(handle
!= NULL
, "dlopen fails: %s", dlerror());
59 testf_dso_null
= dlsym(handle
, "testf_dso_null");
60 ATF_REQUIRE_MSG(testf_dso_null
!= NULL
, "dlsym fails: %s", dlerror());
62 ATF_REQUIRE(testf_dso_null() == 0xcafe);
64 ATF_REQUIRE(dlclose(handle
) == 0);
69 ATF_TC_HEAD(dlopen_mutex
, tc
)
71 atf_tc_set_md_var(tc
, "descr",
72 "Test if dlopen can load -lpthread DSO without breaking mutex");
75 ATF_TC_BODY(dlopen_mutex
, tc
)
79 int (*testf_dso_null
)(void);
81 ATF_REQUIRE(pthread_mutex_init(&mtx
, NULL
) == 0);
82 ATF_REQUIRE(pthread_mutex_lock(&mtx
) == 0);
84 handle
= dlopen(DSO
, RTLD_NOW
| RTLD_LOCAL
);
85 ATF_REQUIRE_MSG(handle
!= NULL
, "dlopen fails: %s", dlerror());
87 testf_dso_null
= dlsym(handle
, "testf_dso_null");
88 ATF_REQUIRE_MSG(testf_dso_null
!= NULL
, "dlsym fails: %s", dlerror());
90 ATF_REQUIRE(testf_dso_null() == 0xcafe);
92 ATF_REQUIRE(pthread_mutex_unlock(&mtx
) == 0);
94 ATF_REQUIRE(dlclose(handle
) == 0);
96 pthread_mutex_destroy(&mtx
);
99 ATF_TC(dlopen_mutex_libc
);
101 ATF_TC_HEAD(dlopen_mutex_libc
, tc
)
103 atf_tc_set_md_var(tc
, "descr",
104 "Test if dlopen can load -lpthread DSO and use libc locked mutex");
107 ATF_TC_BODY(dlopen_mutex_libc
, tc
)
111 int (*testf_dso_mutex_unlock
)(pthread_mutex_t
*);
113 ATF_REQUIRE(pthread_mutex_init(&mtx
, NULL
) == 0);
114 ATF_REQUIRE(pthread_mutex_lock(&mtx
) == 0);
116 handle
= dlopen(DSO
, RTLD_NOW
| RTLD_LOCAL
);
117 ATF_REQUIRE_MSG(handle
!= NULL
, "dlopen fails: %s", dlerror());
119 testf_dso_mutex_unlock
= dlsym(handle
, "testf_dso_mutex_unlock");
120 ATF_REQUIRE_MSG(testf_dso_mutex_unlock
!= NULL
,
121 "dlsym fails: %s", dlerror());
123 ATF_REQUIRE(testf_dso_mutex_unlock(&mtx
) == 0xcafe);
127 pthread_mutex_destroy(&mtx
);
130 ATF_TC(dlopen_mutex_libpthread
);
132 ATF_TC_HEAD(dlopen_mutex_libpthread
, tc
)
134 atf_tc_set_md_var(tc
, "descr",
135 "Test if dlopen can load -lpthread DSO and use "
136 "libpthread locked mutex");
139 ATF_TC_BODY(dlopen_mutex_libpthread
, tc
)
143 int (*testf_dso_mutex_lock
)(pthread_mutex_t
*);
145 ATF_REQUIRE(pthread_mutex_init(&mtx
, NULL
) == 0);
147 handle
= dlopen(DSO
, RTLD_NOW
| RTLD_LOCAL
);
148 ATF_REQUIRE_MSG(handle
!= NULL
, "dlopen fails: %s", dlerror());
150 testf_dso_mutex_lock
= dlsym(handle
, "testf_dso_mutex_lock");
151 ATF_REQUIRE_MSG(testf_dso_mutex_lock
!= NULL
,
152 "dlsym fails: %s", dlerror());
154 ATF_REQUIRE(testf_dso_mutex_lock(&mtx
) == 0xcafe);
156 ATF_REQUIRE(pthread_mutex_unlock(&mtx
) == 0);
160 pthread_mutex_destroy(&mtx
);
165 ATF_TP_ADD_TC(tp
, dlopen
);
166 ATF_TP_ADD_TC(tp
, dlopen_mutex
);
167 ATF_TP_ADD_TC(tp
, dlopen_mutex_libc
);
168 ATF_TP_ADD_TC(tp
, dlopen_mutex_libpthread
);
170 return atf_no_error();