t_dso_pthread_create.c revision 1.1.4.2 1 1.1.4.2 tls /* $NetBSD: t_dso_pthread_create.c,v 1.1.4.2 2013/06/23 06:28:57 tls Exp $ */
2 1.1.4.2 tls /*-
3 1.1.4.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
4 1.1.4.2 tls * All rights reserved.
5 1.1.4.2 tls *
6 1.1.4.2 tls * This code is derived from software contributed to The NetBSD Foundation
7 1.1.4.2 tls * by Emmanuel Dreyfus
8 1.1.4.2 tls *
9 1.1.4.2 tls * Redistribution and use in source and binary forms, with or without
10 1.1.4.2 tls * modification, are permitted provided that the following conditions
11 1.1.4.2 tls * are met:
12 1.1.4.2 tls *
13 1.1.4.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 tls * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 tls * notice, this list of conditions and the following disclaimer in
17 1.1.4.2 tls * the documentation and/or other materials provided with the
18 1.1.4.2 tls * distribution.
19 1.1.4.2 tls *
20 1.1.4.2 tls * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 1.1.4.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 1.1.4.2 tls * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 1.1.4.2 tls * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 1.1.4.2 tls * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1.4.2 tls * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 1.1.4.2 tls * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 1.1.4.2 tls * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 1.1.4.2 tls * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 1.1.4.2 tls * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 1.1.4.2 tls * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1.4.2 tls * SUCH DAMAGE.
32 1.1.4.2 tls */
33 1.1.4.2 tls
34 1.1.4.2 tls #include <sys/cdefs.h>
35 1.1.4.2 tls __RCSID("$NetBSD: t_dso_pthread_create.c,v 1.1.4.2 2013/06/23 06:28:57 tls Exp $");
36 1.1.4.2 tls
37 1.1.4.2 tls #include <sys/resource.h>
38 1.1.4.2 tls #include <atf-c.h>
39 1.1.4.2 tls #include <dlfcn.h>
40 1.1.4.2 tls #include <pthread.h>
41 1.1.4.2 tls #include <unistd.h>
42 1.1.4.2 tls
43 1.1.4.2 tls #define DSO TESTDIR "/h_pthread_dlopen.so"
44 1.1.4.2 tls
45 1.1.4.2 tls void *
46 1.1.4.2 tls routine(void *arg)
47 1.1.4.2 tls {
48 1.1.4.2 tls ATF_REQUIRE((intptr_t)arg == 0xcafe);
49 1.1.4.2 tls return NULL;
50 1.1.4.2 tls }
51 1.1.4.2 tls
52 1.1.4.2 tls ATF_TC(dso_pthread_create_dso);
53 1.1.4.2 tls
54 1.1.4.2 tls ATF_TC_HEAD(dso_pthread_create_dso, tc)
55 1.1.4.2 tls {
56 1.1.4.2 tls atf_tc_set_md_var(tc, "descr",
57 1.1.4.2 tls "Test if non -lpthread main can call pthread_create() "
58 1.1.4.2 tls "in -lpthread DSO");
59 1.1.4.2 tls }
60 1.1.4.2 tls
61 1.1.4.2 tls ATF_TC_BODY(dso_pthread_create_dso, tc)
62 1.1.4.2 tls {
63 1.1.4.2 tls int ret;
64 1.1.4.2 tls pthread_t thread;
65 1.1.4.2 tls void *arg = (void *)0xcafe;
66 1.1.4.2 tls void *handle;
67 1.1.4.2 tls int (*testf_dso_pthread_create)(pthread_t *, pthread_attr_t *,
68 1.1.4.2 tls void *(*)(void *), void *);
69 1.1.4.2 tls struct rlimit rl;
70 1.1.4.2 tls
71 1.1.4.2 tls atf_tc_expect_signal(6,
72 1.1.4.2 tls "calling pthread_create() requires -lpthread main");
73 1.1.4.2 tls
74 1.1.4.2 tls rl.rlim_max = rl.rlim_cur = 0;
75 1.1.4.2 tls ATF_REQUIRE_EQ(setrlimit(RLIMIT_CORE, &rl), 0);
76 1.1.4.2 tls
77 1.1.4.2 tls handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL);
78 1.1.4.2 tls ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror());
79 1.1.4.2 tls
80 1.1.4.2 tls testf_dso_pthread_create = dlsym(handle, "testf_dso_pthread_create");
81 1.1.4.2 tls ATF_REQUIRE_MSG(testf_dso_pthread_create != NULL,
82 1.1.4.2 tls "dlsym fails: %s", dlerror());
83 1.1.4.2 tls
84 1.1.4.2 tls ret = testf_dso_pthread_create(&thread, NULL, routine, arg);
85 1.1.4.2 tls ATF_REQUIRE(ret == 0);
86 1.1.4.2 tls
87 1.1.4.2 tls ATF_REQUIRE(dlclose(handle) == 0);
88 1.1.4.2 tls
89 1.1.4.2 tls }
90 1.1.4.2 tls
91 1.1.4.2 tls ATF_TP_ADD_TCS(tp)
92 1.1.4.2 tls {
93 1.1.4.2 tls ATF_TP_ADD_TC(tp, dso_pthread_create_dso);
94 1.1.4.2 tls
95 1.1.4.2 tls return atf_no_error();
96 1.1.4.2 tls }
97