Home | History | Annotate | Line # | Download | only in dlopen
      1 /*	$NetBSD: t_dso_pthread_create.c,v 1.1 2013/03/21 16:50:21 christos Exp $ */
      2 /*-
      3  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Emmanuel Dreyfus
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  *
     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
     18  *    distribution.
     19  *
     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
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __RCSID("$NetBSD: t_dso_pthread_create.c,v 1.1 2013/03/21 16:50:21 christos Exp $");
     36 
     37 #include <sys/resource.h>
     38 #include <atf-c.h>
     39 #include <dlfcn.h>
     40 #include <pthread.h>
     41 #include <unistd.h>
     42 
     43 #define DSO TESTDIR "/h_pthread_dlopen.so"
     44 
     45 void *
     46 routine(void *arg)
     47 {
     48 	ATF_REQUIRE((intptr_t)arg == 0xcafe);
     49 	return NULL;
     50 }
     51 
     52 ATF_TC(dso_pthread_create_dso);
     53 
     54 ATF_TC_HEAD(dso_pthread_create_dso, tc)
     55 {
     56 	atf_tc_set_md_var(tc, "descr",
     57 	    "Test if non -lpthread main can call pthread_create() "
     58 	    "in -lpthread DSO");
     59 }
     60 
     61 ATF_TC_BODY(dso_pthread_create_dso, tc)
     62 {
     63 	int ret;
     64 	pthread_t thread;
     65 	void *arg = (void *)0xcafe;
     66 	void *handle;
     67 	int (*testf_dso_pthread_create)(pthread_t *, pthread_attr_t *,
     68 	    void *(*)(void *), void *);
     69 	struct rlimit rl;
     70 
     71 	atf_tc_expect_signal(6,
     72 	    "calling pthread_create() requires -lpthread main");
     73 
     74 	rl.rlim_max = rl.rlim_cur = 0;
     75 	ATF_REQUIRE_EQ(setrlimit(RLIMIT_CORE, &rl), 0);
     76 
     77 	handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL);
     78 	ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror());
     79 
     80 	testf_dso_pthread_create = dlsym(handle, "testf_dso_pthread_create");
     81 	ATF_REQUIRE_MSG(testf_dso_pthread_create != NULL,
     82 	    "dlsym fails: %s", dlerror());
     83 
     84 	ret = testf_dso_pthread_create(&thread, NULL, routine, arg);
     85 	ATF_REQUIRE(ret == 0);
     86 
     87 	ATF_REQUIRE(dlclose(handle) == 0);
     88 
     89 }
     90 
     91 ATF_TP_ADD_TCS(tp)
     92 {
     93 	ATF_TP_ADD_TC(tp, dso_pthread_create_dso);
     94 
     95 	return atf_no_error();
     96 }
     97