Home | History | Annotate | Download | only in pthread_create
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  rolla.n.selbak REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7  *
      8  *  Test upon successful completion, pthread_create() shall store the ID of the
      9  *  the created thread in the location referenced by 'thread'.
     10  *
     11  * Steps:
     12  * 1.  Create a thread using pthread_create()
     13  * 2.  Save the thread ID resulting from pthread_create()
     14  * 3.  Get the thread ID from the new thread by calling
     15  *     pthread_self().
     16  * 4.  These 2 values should be equal. (i.e. the one from pthread_create()
     17  *     and the one from pthread_self()).
     18  */
     19 
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 #include <string.h>
     23 #include "posixtest.h"
     24 
     25 static void *a_thread_func();
     26 static pthread_t self_th;
     27 
     28 int main(void)
     29 {
     30 	pthread_t new_th;
     31 	int ret;
     32 
     33 	ret = pthread_create(&new_th, NULL, a_thread_func, NULL);
     34 	if (ret) {
     35 		fprintf(stderr, "pthread_create(): %s\n", strerror(ret));
     36 		return PTS_UNRESOLVED;
     37 	}
     38 
     39 	ret = pthread_join(new_th, NULL);
     40 	if (ret) {
     41 		fprintf(stderr, "pthread_join(): %s\n", strerror(ret));
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	/* If the value of pthread_self() and the return value from
     46 	 * pthread_create() is equal, then the test passes. */
     47 	if (pthread_equal(new_th, self_th) == 0) {
     48 		printf("Test FAILED\n");
     49 		return PTS_FAIL;
     50 	}
     51 
     52 	printf("Test PASSED\n");
     53 	return PTS_PASS;
     54 }
     55 
     56 static void *a_thread_func()
     57 {
     58 	self_th = pthread_self();
     59 	return NULL;
     60 }
     61