Home | History | Annotate | Line # | Download | only in lib
      1 /*	$NetBSD: h_pthread_weak.c,v 1.1 2025/10/06 13:16:44 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2025 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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.
     15  *
     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.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __RCSID("$NetBSD: h_pthread_weak.c,v 1.1 2025/10/06 13:16:44 riastradh Exp $");
     31 
     32 #define	_NETBSD_PTHREAD_CREATE_WEAK
     33 
     34 #include "h_pthread_weak.h"
     35 
     36 #include <atf-c.h>
     37 #include <pthread.h>
     38 
     39 #include "h_macros.h"
     40 
     41 static void *
     42 start(void *cookie)
     43 {
     44 	return cookie;
     45 }
     46 
     47 void
     48 test_mutex(void)
     49 {
     50 	pthread_mutex_t mtx;
     51 
     52 	RZ(pthread_mutex_init(&mtx, NULL));
     53 	RZ(pthread_mutex_lock(&mtx));
     54 	RZ(pthread_mutex_unlock(&mtx));
     55 	RZ(pthread_mutex_destroy(&mtx));
     56 }
     57 
     58 void
     59 test_thread_creation(void)
     60 {
     61 	int cookie = 123;
     62 	pthread_attr_t attr;
     63 	pthread_t t;
     64 	void *result;
     65 
     66 	RZ(pthread_attr_init(&attr));
     67 	RZ(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
     68 	RZ(pthread_create(&t, NULL, &start, &cookie));
     69 	RZ(pthread_attr_destroy(&attr));
     70 	RZ(pthread_join(t, &result));
     71 	ATF_CHECK_EQ(result, &cookie);
     72 }
     73 
     74 void
     75 test_thread_creation_failure(void)
     76 {
     77 	int cookie = 123;
     78 	pthread_t t;
     79 	int error;
     80 
     81 	error = pthread_create(&t, NULL, &start, &cookie);
     82 	ATF_CHECK_MSG(error != 0, "pthread_create unexpectedly succeeded");
     83 }
     84