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 that pthread_create() creates a new thread with attributes specified
9 * by 'attr', within a process.
10 *
11 * Steps:
12 * 1. Create a thread using pthread_create()
13 * 2. Cancel that thread with pthread_cancel()
14 * 3. If that thread doesn't exist, then it pthread_cancel() will return
15 * an error code. This would mean that pthread_create() did not create
16 * a thread successfully.
17 */
18
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include "posixtest.h"
24
a_thread_func()25 static void *a_thread_func()
26 {
27 sleep(10);
28
29 /* Shouldn't reach here. If we do, then the pthread_cancel()
30 * function did not succeed. */
31 fprintf(stderr, "Could not send cancel request correctly\n");
32
33 return NULL;
34 }
35
posix_testcase(void)36 static int posix_testcase(void)
37 {
38 pthread_t new_th;
39 int ret;
40
41 ret = pthread_create(&new_th, NULL, a_thread_func, NULL);
42 if (ret) {
43 fprintf(stderr, "pthread_create(): %s\n", strerror(ret));
44 return PTS_UNRESOLVED;
45 }
46
47 /* Try to cancel the newly created thread. If an error is returned,
48 * then the thread wasn't created successfully. */
49 ret = pthread_cancel(new_th);
50 if (ret) {
51 printf("Test FAILED: A new thread wasn't created: %s\n",
52 strerror(ret));
53 return PTS_FAIL;
54 }
55
56 printf("Test PASSED\n");
57 return PTS_PASS;
58 }
59 #include <rtt_utest_internal.h>
60 UTEST_TC_EXPORT(testcase, "posix.pthread_create.1-2.c", RT_NULL, RT_NULL, 10);
61
62