summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-08-05 20:20:25 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-08-05 20:20:25 +0900
commitadc5cd422ad55fdba9273f2c9fd351c1e1308f36 (patch)
treee6b72101ccdc5500edc23f96c87d1bd9ddc385d0 /src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
parent31e8a528b14ef06418d146a47782c63011c4bea7 (diff)
ecore eina thread queue test - be anal about thread exiting cleanly
Diffstat (limited to '')
-rw-r--r--src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
index 07b8a73d27..5a8346d646 100644
--- a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
+++ b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
@@ -35,6 +35,7 @@ th1_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
35 35
36 usleep((rand() % 10) * 1000); 36 usleep((rand() % 10) * 1000);
37 msg = eina_thread_queue_send(thq1, sizeof(Msg), &ref); 37 msg = eina_thread_queue_send(thq1, sizeof(Msg), &ref);
38 if (!msg) fail();
38 msg->value = val; 39 msg->value = val;
39 memset(msg->pad, 0x32, 10); 40 memset(msg->pad, 0x32, 10);
40 eina_thread_queue_send_done(thq1, ref); 41 eina_thread_queue_send_done(thq1, ref);
@@ -54,11 +55,13 @@ th2_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
54 void *ref; 55 void *ref;
55 56
56 msg = eina_thread_queue_wait(thq1, &ref); 57 msg = eina_thread_queue_wait(thq1, &ref);
58 if (!msg) fail();
57 val = msg->value; 59 val = msg->value;
58 usleep((rand() % 20) * 1000); 60 usleep((rand() % 20) * 1000);
59 eina_thread_queue_wait_done(thq1, ref); 61 eina_thread_queue_wait_done(thq1, ref);
60 62
61 msg = eina_thread_queue_send(thq2, sizeof(Msg), &ref); 63 msg = eina_thread_queue_send(thq2, sizeof(Msg), &ref);
64 if (!msg) fail();
62 msg->value = val; 65 msg->value = val;
63 memset(msg->pad, 0x32, 10); 66 memset(msg->pad, 0x32, 10);
64 eina_thread_queue_send_done(thq2, ref); 67 eina_thread_queue_send_done(thq2, ref);
@@ -74,7 +77,9 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t1)
74 ecore_init(); 77 ecore_init();
75 78
76 thq1 = eina_thread_queue_new(); 79 thq1 = eina_thread_queue_new();
80 if (!thq1) fail();
77 thq2 = eina_thread_queue_new(); 81 thq2 = eina_thread_queue_new();
82 if (!thq2) fail();
78 ecore_thread_feedback_run(th1_do, NULL, NULL, NULL, NULL, EINA_TRUE); 83 ecore_thread_feedback_run(th1_do, NULL, NULL, NULL, NULL, EINA_TRUE);
79 ecore_thread_feedback_run(th2_do, NULL, NULL, NULL, NULL, EINA_TRUE); 84 ecore_thread_feedback_run(th2_do, NULL, NULL, NULL, NULL, EINA_TRUE);
80 85
@@ -83,6 +88,7 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t1)
83 Msg *msg; 88 Msg *msg;
84 void *ref; 89 void *ref;
85 msg = eina_thread_queue_wait(thq2, &ref); 90 msg = eina_thread_queue_wait(thq2, &ref);
91 if (!msg) fail();
86 if (DEBUG) printf("V: %i [%i]\n", msg->value, eina_thread_queue_pending_get(thq2)); 92 if (DEBUG) printf("V: %i [%i]\n", msg->value, eina_thread_queue_pending_get(thq2));
87 if (msg->value != (val + 1)) 93 if (msg->value != (val + 1))
88 { 94 {
@@ -132,20 +138,23 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t2)
132{ 138{
133 Msg2 *msg; 139 Msg2 *msg;
134 void *ref; 140 void *ref;
135 int i; 141 int i, mcount;
136 142
137 eina_init(); 143 eina_init();
138 ecore_init(); 144 ecore_init();
139 145
140 thq1 = eina_thread_queue_new(); 146 thq1 = eina_thread_queue_new();
147 if (!thq1) fail();
141 ecore_thread_feedback_run(thspeed1_do, NULL, NULL, NULL, NULL, EINA_TRUE); 148 ecore_thread_feedback_run(thspeed1_do, NULL, NULL, NULL, NULL, EINA_TRUE);
142 149
143 for (i = 0; i < 10000000; i++) 150 for (i = 0; i < 10000000; i++)
144 { 151 {
145 msg = eina_thread_queue_send(thq1, sizeof(Msg2), &ref); 152 msg = eina_thread_queue_send(thq1, sizeof(Msg2), &ref);
153 if (!msg) fail();
146 if (msg) eina_thread_queue_send_done(thq1, ref); 154 if (msg) eina_thread_queue_send_done(thq1, ref);
147 } 155 }
148 if (msgs < 1000000) 156 mcount = msgs;
157 if (mcount < 1000000)
149 { 158 {
150 printf("ERR: not enough messages recieved\n"); 159 printf("ERR: not enough messages recieved\n");
151 fail(); 160 fail();
@@ -172,6 +181,7 @@ th21_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
172 void *ref; 181 void *ref;
173 182
174 msg = eina_thread_queue_send(thq1, sizeof(Msg3), &ref); 183 msg = eina_thread_queue_send(thq1, sizeof(Msg3), &ref);
184 if (!msg) fail();
175 msg->value = val; 185 msg->value = val;
176 eina_thread_queue_send_done(thq1, ref); 186 eina_thread_queue_send_done(thq1, ref);
177 val++; 187 val++;
@@ -190,6 +200,7 @@ th22_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
190 void *ref; 200 void *ref;
191 201
192 msg = eina_thread_queue_send(thq2, sizeof(Msg3), &ref); 202 msg = eina_thread_queue_send(thq2, sizeof(Msg3), &ref);
203 if (!msg) fail();
193 msg->value = val; 204 msg->value = val;
194 eina_thread_queue_send_done(thq2, ref); 205 eina_thread_queue_send_done(thq2, ref);
195 val++; 206 val++;
@@ -206,8 +217,11 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t3)
206 ecore_init(); 217 ecore_init();
207 218
208 thq1 = eina_thread_queue_new(); 219 thq1 = eina_thread_queue_new();
220 if (!thq1) fail();
209 thq2 = eina_thread_queue_new(); 221 thq2 = eina_thread_queue_new();
222 if (!thq2) fail();
210 thqmaster = eina_thread_queue_new(); 223 thqmaster = eina_thread_queue_new();
224 if (!thqmaster) fail();
211 eina_thread_queue_parent_set(thq1, thqmaster); 225 eina_thread_queue_parent_set(thq1, thqmaster);
212 eina_thread_queue_parent_set(thq2, thqmaster); 226 eina_thread_queue_parent_set(thq2, thqmaster);
213 227
@@ -224,9 +238,11 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t3)
224 Eina_Thread_Queue *thq; 238 Eina_Thread_Queue *thq;
225 Msg3 *msg; 239 Msg3 *msg;
226 void *ref; 240 void *ref;
241
227 sub = eina_thread_queue_wait(thqmaster, &ref); 242 sub = eina_thread_queue_wait(thqmaster, &ref);
228 thq = sub->queue; 243 thq = sub->queue;
229 eina_thread_queue_wait_done(thqmaster, ref); 244 eina_thread_queue_wait_done(thqmaster, ref);
245
230 msg = eina_thread_queue_wait(thq, &ref); 246 msg = eina_thread_queue_wait(thq, &ref);
231 if (DEBUG) printf("V %09i: %p - %i [%i]\n", cnt, thq, msg->value, eina_thread_queue_pending_get(thqmaster)); 247 if (DEBUG) printf("V %09i: %p - %i [%i]\n", cnt, thq, msg->value, eina_thread_queue_pending_get(thqmaster));
232 if (thq == thq1) 248 if (thq == thq1)
@@ -312,6 +328,7 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t4)
312 eina_init(); 328 eina_init();
313 ecore_init(); 329 ecore_init();
314 thq1 = eina_thread_queue_new(); 330 thq1 = eina_thread_queue_new();
331 if (!thq1) fail();
315 ecore_thread_feedback_run(th31_do, NULL, NULL, NULL, NULL, EINA_TRUE); 332 ecore_thread_feedback_run(th31_do, NULL, NULL, NULL, NULL, EINA_TRUE);
316 ecore_thread_feedback_run(th32_do, NULL, NULL, NULL, NULL, EINA_TRUE); 333 ecore_thread_feedback_run(th32_do, NULL, NULL, NULL, NULL, EINA_TRUE);
317 for (;;) 334 for (;;)
@@ -384,10 +401,13 @@ th42_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
384 void *ref; 401 void *ref;
385 402
386 msg = eina_thread_queue_wait(thq1, &ref); 403 msg = eina_thread_queue_wait(thq1, &ref);
404 if (!msg) fail();
387 val = msg->value; 405 val = msg->value;
388 usleep((rand() % 20) * 1000); 406 usleep((rand() % 20) * 1000);
389 eina_thread_queue_wait_done(thq1, ref); 407 eina_thread_queue_wait_done(thq1, ref);
408
390 msg = eina_thread_queue_send(thq2, sizeof(Msg5), &ref); 409 msg = eina_thread_queue_send(thq2, sizeof(Msg5), &ref);
410 if (!msg) fail();
391 msg->value = val; 411 msg->value = val;
392 eina_thread_queue_send_done(thq2, ref); 412 eina_thread_queue_send_done(thq2, ref);
393 if (val == 1100) break; 413 if (val == 1100) break;
@@ -403,7 +423,9 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t5)
403 ecore_init(); 423 ecore_init();
404 424
405 thq1 = eina_thread_queue_new(); 425 thq1 = eina_thread_queue_new();
426 if (!thq1) fail();
406 thq2 = eina_thread_queue_new(); 427 thq2 = eina_thread_queue_new();
428 if (!thq2) fail();
407 ecore_thread_feedback_run(th41_do, NULL, NULL, NULL, NULL, EINA_TRUE); 429 ecore_thread_feedback_run(th41_do, NULL, NULL, NULL, NULL, EINA_TRUE);
408 ecore_thread_feedback_run(th42_do, NULL, NULL, NULL, NULL, EINA_TRUE); 430 ecore_thread_feedback_run(th42_do, NULL, NULL, NULL, NULL, EINA_TRUE);
409 431
@@ -442,7 +464,7 @@ typedef struct
442} Msg6; 464} Msg6;
443 465
444static Eina_Spinlock msgnum_lock; 466static Eina_Spinlock msgnum_lock;
445static int msgnum = 0; 467static volatile int msgnum = 0;
446 468
447static void 469static void
448th51_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 470th51_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
@@ -455,6 +477,7 @@ th51_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
455 void *ref; 477 void *ref;
456 478
457 msg = eina_thread_queue_send(thq1, sizeof(Msg6), &ref); 479 msg = eina_thread_queue_send(thq1, sizeof(Msg6), &ref);
480 if (!msg) fail();
458 msg->value = val; 481 msg->value = val;
459 eina_thread_queue_send_done(thq1, ref); 482 eina_thread_queue_send_done(thq1, ref);
460 val++; 483 val++;
@@ -473,11 +496,17 @@ th52_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
473 Msg6 *msg; 496 Msg6 *msg;
474 void *ref; 497 void *ref;
475 msg = eina_thread_queue_wait(thq1, &ref); 498 msg = eina_thread_queue_wait(thq1, &ref);
499 if (!msg) fail();
476 if (DEBUG) printf("v %08i: %i [%i]\n", cnt, msg->value, eina_thread_queue_pending_get(thq1)); 500 if (DEBUG) printf("v %08i: %i [%i]\n", cnt, msg->value, eina_thread_queue_pending_get(thq1));
477 eina_thread_queue_wait_done(thq1, ref); 501 eina_thread_queue_wait_done(thq1, ref);
478 cnt++; 502 cnt++;
479 eina_spinlock_take(&msgnum_lock); 503 eina_spinlock_take(&msgnum_lock);
480 msgnum++; 504 msgnum++;
505 if (msgnum == 10000)
506 {
507 eina_spinlock_release(&msgnum_lock);
508 break;
509 }
481 eina_spinlock_release(&msgnum_lock); 510 eina_spinlock_release(&msgnum_lock);
482 } 511 }
483} 512}
@@ -492,11 +521,17 @@ th53_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
492 Msg6 *msg; 521 Msg6 *msg;
493 void *ref; 522 void *ref;
494 msg = eina_thread_queue_wait(thq1, &ref); 523 msg = eina_thread_queue_wait(thq1, &ref);
524 if (!msg) fail();
495 if (DEBUG) printf("v %08i: %i [%i]\n", cnt, msg->value, eina_thread_queue_pending_get(thq1)); 525 if (DEBUG) printf("v %08i: %i [%i]\n", cnt, msg->value, eina_thread_queue_pending_get(thq1));
496 eina_thread_queue_wait_done(thq1, ref); 526 eina_thread_queue_wait_done(thq1, ref);
497 cnt++; 527 cnt++;
498 eina_spinlock_take(&msgnum_lock); 528 eina_spinlock_take(&msgnum_lock);
499 msgnum++; 529 msgnum++;
530 if (msgnum == 10000)
531 {
532 eina_spinlock_release(&msgnum_lock);
533 break;
534 }
500 eina_spinlock_release(&msgnum_lock); 535 eina_spinlock_release(&msgnum_lock);
501 } 536 }
502} 537}
@@ -508,6 +543,7 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t6)
508 543
509 eina_spinlock_new(&msgnum_lock); 544 eina_spinlock_new(&msgnum_lock);
510 thq1 = eina_thread_queue_new(); 545 thq1 = eina_thread_queue_new();
546 if (!thq1) fail();
511 ecore_thread_feedback_run(th51_do, NULL, NULL, NULL, NULL, EINA_TRUE); 547 ecore_thread_feedback_run(th51_do, NULL, NULL, NULL, NULL, EINA_TRUE);
512 ecore_thread_feedback_run(th52_do, NULL, NULL, NULL, NULL, EINA_TRUE); 548 ecore_thread_feedback_run(th52_do, NULL, NULL, NULL, NULL, EINA_TRUE);
513 ecore_thread_feedback_run(th53_do, NULL, NULL, NULL, NULL, EINA_TRUE); 549 ecore_thread_feedback_run(th53_do, NULL, NULL, NULL, NULL, EINA_TRUE);
@@ -564,6 +600,7 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t7)
564 ecore_init(); 600 ecore_init();
565 601
566 thq1 = eina_thread_queue_new(); 602 thq1 = eina_thread_queue_new();
603 if (!thq1) fail();
567 if (pipe(p) != 0) 604 if (pipe(p) != 0)
568 { 605 {
569 printf("ERR: pipe create fail\n"); 606 printf("ERR: pipe create fail\n");