@@ -21,12 +21,23 @@ void *thread_top(void *p1)
21
21
pthread_t self ;
22
22
int oldstate ;
23
23
int val = (u32_t ) p1 ;
24
+ struct sched_param param ;
25
+
26
+ param .priority = N_THR - (s32_t ) p1 ;
27
+
28
+ self = pthread_self ();
29
+ /* Change priority of thread */
30
+ zassert_false (pthread_setschedparam (self , SCHED_RR , & param ),
31
+ "Unable to set thread priority" );
24
32
25
33
if (val % 2 ) {
26
34
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , & oldstate );
27
35
}
28
36
29
- self = pthread_self ();
37
+ if (val >= 2 ) {
38
+ pthread_detach (self );
39
+ }
40
+
30
41
printk ("Cancelling thread %d\n" , (s32_t ) p1 );
31
42
pthread_cancel (self );
32
43
printk ("Thread %d could not be cancelled\n" , (s32_t ) p1 );
@@ -48,29 +59,29 @@ void test_pthread_cancel(void)
48
59
printk ("POSIX thread cancel APIs\n" );
49
60
/* Creating 4 threads with lowest application priority */
50
61
for (i = 0 ; i < N_THR ; i ++ ) {
51
- pthread_attr_init (& attr [i ]);
62
+ ret = pthread_attr_init (& attr [i ]);
63
+ if (ret != 0 ) {
64
+ zassert_false (pthread_attr_destroy (& attr [i ]),
65
+ "Unable to destroy pthread object attrib\n" );
66
+ zassert_false (pthread_attr_init (& attr [i ]),
67
+ "Unable to create pthread object attrib\n" );
68
+ }
52
69
53
- if (i == 0 ) {
70
+ if (i == 1 ) {
54
71
pthread_attr_setdetachstate (& attr [i ],
55
72
PTHREAD_CREATE_JOINABLE );
56
- } else if (i == 1 ) {
57
- pthread_attr_setdetachstate (& attr [i ],
58
- PTHREAD_CREATE_JOINABLE );
59
- } else if (i == 2 ) {
60
- pthread_attr_setdetachstate (& attr [i ],
61
- PTHREAD_CREATE_DETACHED );
62
- } else if (i == 3 ) {
73
+ } else if (i == 2 ) {
63
74
pthread_attr_setdetachstate (& attr [i ],
64
75
PTHREAD_CREATE_DETACHED );
65
76
}
77
+
66
78
schedparam .priority = 2 ;
67
79
pthread_attr_setschedparam (& attr [i ], & schedparam );
68
80
pthread_attr_setstack (& attr [i ], & stacks [i ][0 ], STACKSZ );
69
81
ret = pthread_create (& newthread [i ], & attr [i ], thread_top ,
70
82
(void * )i );
71
83
72
- /*TESTPOINT: Check if thread is created successfully*/
73
- zassert_false (ret , "Number of threads exceeds max limit\n" );
84
+ zassert_false (ret , "Not enough space to create new thread\n" );
74
85
}
75
86
76
87
for (i = 0 ; i < N_THR ; i ++ ) {
@@ -79,12 +90,10 @@ void test_pthread_cancel(void)
79
90
printk ("Pthread %d joined to %s\n" , i , __func__ );
80
91
}
81
92
82
- printk ("Pthread join test over\n" );
93
+ printk ("Pthread join test over %d \n" , exit_count );
83
94
84
95
/* Test PASS if all threads have exited before main exit */
85
96
zassert_equal (exit_count , 1 , "pthread_cancel test failed\n" );
86
-
87
- sleep (ONE_SECOND );
88
97
}
89
98
90
99
void test_main (void )
0 commit comments