1 /* $NetBSD: t_name.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved.");
32 __RCSID("$NetBSD: t_name.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
45 #define NAME_TOO_LONG "12345678901234567890123456789012" /* 32 chars */
46 #define NAME_JUST_RIGHT "1234567890123456789012345678901" /* 31 chars */
48 #define CONST_NAME "xyzzy"
49 char non_const_name
[] = CONST_NAME
;
54 pthread_t self
= pthread_self();
57 PTHREAD_REQUIRE(pthread_getname_np(self
, retname
, sizeof(retname
)));
58 ATF_REQUIRE_STREQ(retname
, NAME_JUST_RIGHT
);
60 PTHREAD_REQUIRE(pthread_setname_np(self
, non_const_name
, NULL
));
61 (void) memset(non_const_name
, 0, sizeof(non_const_name
));
62 PTHREAD_REQUIRE(pthread_getname_np(self
, retname
, sizeof(retname
)));
63 ATF_REQUIRE_STREQ(retname
, CONST_NAME
);
71 atf_tc_set_md_var(tc
, "descr",
72 "Checks pthread_{,attr}_{get,set}name_np() API");
76 pthread_t thr
, self
= pthread_self();
80 PTHREAD_REQUIRE(pthread_attr_init(&attr
));
81 PTHREAD_REQUIRE(pthread_attr_getname_np(&attr
, retname
,
82 sizeof(retname
), NULL
));
83 ATF_REQUIRE_EQ(retname
[0], '\0');
84 ATF_REQUIRE_EQ(pthread_attr_setname_np(&attr
, NAME_TOO_LONG
, NULL
), EINVAL
);
85 PTHREAD_REQUIRE(pthread_attr_setname_np(&attr
, "%s",
86 __UNCONST(NAME_JUST_RIGHT
)));
88 (void) strcpy(retname
, "foo");
89 PTHREAD_REQUIRE(pthread_getname_np(self
, retname
, sizeof(retname
)));
90 ATF_REQUIRE_EQ(retname
[0], '\0');
92 PTHREAD_REQUIRE(pthread_create(&thr
, &attr
, threadfunc
, NULL
));
93 PTHREAD_REQUIRE(pthread_join(thr
, NULL
));
95 ATF_REQUIRE_EQ(pthread_getname_np(thr
, retname
, sizeof(retname
)), ESRCH
);
100 ATF_TP_ADD_TC(tp
, name
);
102 return atf_no_error();