1 /* $NetBSD: t_dlvsym.c,v 1.1 2011/06/25 05:45:13 nonaka Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * 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 the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
38 ATF_TC(rtld_dlvsym_v1
);
39 ATF_TC_HEAD(rtld_dlvsym_v1
, tc
)
41 atf_tc_set_md_var(tc
, "descr", "Check dlvsym() function (V_1)");
43 ATF_TC_BODY(rtld_dlvsym_v1
, tc
)
50 /* Clear previous error */
53 handle
= dlopen("libh_helper_symver_dso.so", RTLD_LAZY
);
55 ATF_CHECK(error
== NULL
);
56 ATF_CHECK(handle
!= NULL
);
58 sym
= dlvsym(handle
, "testfunc", "V_1");
60 ATF_CHECK(error
== NULL
);
63 ATF_CHECK(result
== 1);
67 ATF_CHECK(error
== NULL
);
70 ATF_TC(rtld_dlvsym_v3
);
71 ATF_TC_HEAD(rtld_dlvsym_v3
, tc
)
73 atf_tc_set_md_var(tc
, "descr", "Check dlvsym() function (V_3)");
75 ATF_TC_BODY(rtld_dlvsym_v3
, tc
)
82 /* Clear previous error */
85 handle
= dlopen("libh_helper_symver_dso.so", RTLD_LAZY
);
87 ATF_CHECK(error
== NULL
);
88 ATF_CHECK(handle
!= NULL
);
90 sym
= dlvsym(handle
, "testfunc", "V_3");
92 ATF_CHECK(error
== NULL
);
95 ATF_CHECK(result
== 3);
99 ATF_CHECK(error
== NULL
);
102 ATF_TC(rtld_dlvsym_symbol_nonexistent
);
103 ATF_TC_HEAD(rtld_dlvsym_symbol_nonexistent
, tc
)
105 atf_tc_set_md_var(tc
, "descr",
106 "Check dlvsym() function (symbol is nonexistent)");
108 ATF_TC_BODY(rtld_dlvsym_symbol_nonexistent
, tc
)
114 /* Clear previous error */
117 handle
= dlopen("libh_helper_symver_dso.so", RTLD_LAZY
);
119 ATF_CHECK(error
== NULL
);
120 ATF_CHECK(handle
!= NULL
);
122 sym
= dlvsym(handle
, "symbol_nonexistent", "V_3");
124 ATF_CHECK(sym
== NULL
);
125 ATF_CHECK(error
!= NULL
);
129 ATF_CHECK(error
== NULL
);
132 ATF_TC(rtld_dlvsym_version_nonexistent
);
133 ATF_TC_HEAD(rtld_dlvsym_version_nonexistent
, tc
)
135 atf_tc_set_md_var(tc
, "descr",
136 "Check dlvsym() function (version is nonexistent)");
138 ATF_TC_BODY(rtld_dlvsym_version_nonexistent
, tc
)
144 /* Clear previous error */
147 handle
= dlopen("libh_helper_symver_dso.so", RTLD_LAZY
);
149 ATF_CHECK(error
== NULL
);
150 ATF_CHECK(handle
!= NULL
);
152 sym
= dlvsym(handle
, "testfunc", "");
154 ATF_CHECK(sym
== NULL
);
155 ATF_CHECK(error
!= NULL
);
159 ATF_CHECK(error
== NULL
);
162 ATF_TC(rtld_dlvsym_version_null
);
163 ATF_TC_HEAD(rtld_dlvsym_version_null
, tc
)
165 atf_tc_set_md_var(tc
, "descr",
166 "Check dlvsym() function (version is NULL)");
168 ATF_TC_BODY(rtld_dlvsym_version_null
, tc
)
175 /* Clear previous error */
178 handle
= dlopen("libh_helper_symver_dso.so", RTLD_LAZY
);
180 ATF_CHECK(error
== NULL
);
181 ATF_CHECK(handle
!= NULL
);
183 sym
= dlvsym(handle
, "testfunc", NULL
);
185 ATF_CHECK(error
== NULL
);
188 ATF_CHECK(result
== 3);
192 ATF_CHECK(error
== NULL
);
197 ATF_TP_ADD_TC(tp
, rtld_dlvsym_v1
);
198 ATF_TP_ADD_TC(tp
, rtld_dlvsym_v3
);
199 ATF_TP_ADD_TC(tp
, rtld_dlvsym_symbol_nonexistent
);
200 ATF_TP_ADD_TC(tp
, rtld_dlvsym_version_nonexistent
);
201 ATF_TP_ADD_TC(tp
, rtld_dlvsym_version_null
);
202 return atf_no_error();