summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-06-14 15:07:28 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-06-14 16:54:15 +0900
commit44b6eb3e551710019eb437375b6974ecdac4e764 (patch)
tree76f6d5360244fc9b842e09d38f2d2a952b3e2188 /src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c
parentf54d891b2c7ef648e8593242b771f782e4655950 (diff)
tests: Fix eina_thread_queue test case 5 & 6
ecore_test_ecore_thread_eina_thread_queue_t6 failed often for me. eina_thread_queue_wait() was returning NULL. I believe this is because the test case ended abruptly without waiting for the threads to finish. Indeed, both threads tried hard to reach 10000 messages but it didn't make sense for them both to reach this value, only one would end there. This patch adds an exit message sent by thread 1 to the two other threads, and all threads are waited upon using a single semaphore. Note: This also renames some functions to match their test case number. @raster
Diffstat (limited to '')
-rw-r--r--src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c158
1 files changed, 105 insertions, 53 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 5a8346d646..c96b29b3ed 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
@@ -113,7 +113,7 @@ typedef struct
113static volatile int msgs = 0; 113static volatile int msgs = 0;
114 114
115static void 115static void
116thspeed1_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 116thspeed2_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
117{ 117{
118 Msg2 *msg; 118 Msg2 *msg;
119 void *ref; 119 void *ref;
@@ -145,7 +145,7 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t2)
145 145
146 thq1 = eina_thread_queue_new(); 146 thq1 = eina_thread_queue_new();
147 if (!thq1) fail(); 147 if (!thq1) fail();
148 ecore_thread_feedback_run(thspeed1_do, NULL, NULL, NULL, NULL, EINA_TRUE); 148 ecore_thread_feedback_run(thspeed2_do, NULL, NULL, NULL, NULL, EINA_TRUE);
149 149
150 for (i = 0; i < 10000000; i++) 150 for (i = 0; i < 10000000; i++)
151 { 151 {
@@ -171,7 +171,7 @@ typedef struct
171} Msg3; 171} Msg3;
172 172
173static void 173static void
174th21_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 174th31_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
175{ 175{
176 int val = 100; 176 int val = 100;
177 177
@@ -190,7 +190,7 @@ th21_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
190} 190}
191 191
192static void 192static void
193th22_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 193th32_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
194{ 194{
195 int val = 100; 195 int val = 100;
196 196
@@ -230,8 +230,8 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t3)
230 parent = eina_thread_queue_parent_get(thq2); 230 parent = eina_thread_queue_parent_get(thq2);
231 fail_if(parent != thqmaster); 231 fail_if(parent != thqmaster);
232 232
233 ecore_thread_feedback_run(th21_do, NULL, NULL, NULL, NULL, EINA_TRUE); 233 ecore_thread_feedback_run(th31_do, NULL, NULL, NULL, NULL, EINA_TRUE);
234 ecore_thread_feedback_run(th22_do, NULL, NULL, NULL, NULL, EINA_TRUE); 234 ecore_thread_feedback_run(th32_do, NULL, NULL, NULL, NULL, EINA_TRUE);
235 for (;;) 235 for (;;)
236 { 236 {
237 Eina_Thread_Queue_Msg_Sub *sub; 237 Eina_Thread_Queue_Msg_Sub *sub;
@@ -284,7 +284,7 @@ typedef struct
284} Msg4; 284} Msg4;
285 285
286static void 286static void
287th31_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 287th41_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
288{ 288{
289 int val = 100; 289 int val = 100;
290 290
@@ -302,7 +302,7 @@ th31_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
302} 302}
303 303
304static void 304static void
305th32_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 305th42_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
306{ 306{
307 int val = 10000000; 307 int val = 10000000;
308 308
@@ -329,8 +329,8 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t4)
329 ecore_init(); 329 ecore_init();
330 thq1 = eina_thread_queue_new(); 330 thq1 = eina_thread_queue_new();
331 if (!thq1) fail(); 331 if (!thq1) fail();
332 ecore_thread_feedback_run(th31_do, NULL, NULL, NULL, NULL, EINA_TRUE); 332 ecore_thread_feedback_run(th41_do, NULL, NULL, NULL, NULL, EINA_TRUE);
333 ecore_thread_feedback_run(th32_do, NULL, NULL, NULL, NULL, EINA_TRUE); 333 ecore_thread_feedback_run(th42_do, NULL, NULL, NULL, NULL, EINA_TRUE);
334 for (;;) 334 for (;;)
335 { 335 {
336 Msg4 *msg; 336 Msg4 *msg;
@@ -371,8 +371,10 @@ typedef struct
371 char pad[10]; 371 char pad[10];
372} Msg5; 372} Msg5;
373 373
374static Eina_Semaphore th4_sem;
375
374static void 376static void
375th41_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 377th51_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
376{ 378{
377 int val = 100; 379 int val = 100;
378 380
@@ -388,10 +390,12 @@ th41_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
388 if (val == 1100) break; 390 if (val == 1100) break;
389 val++; 391 val++;
390 } 392 }
393
394 eina_semaphore_release(&th4_sem, 1);
391} 395}
392 396
393static void 397static void
394th42_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 398th52_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
395{ 399{
396 int val; 400 int val;
397 401
@@ -412,6 +416,8 @@ th42_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
412 eina_thread_queue_send_done(thq2, ref); 416 eina_thread_queue_send_done(thq2, ref);
413 if (val == 1100) break; 417 if (val == 1100) break;
414 } 418 }
419
420 eina_semaphore_release(&th4_sem, 1);
415} 421}
416 422
417 423
@@ -419,15 +425,15 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t5)
419{ 425{
420 int val = 99; 426 int val = 99;
421 427
422 eina_init();
423 ecore_init(); 428 ecore_init();
429 eina_semaphore_new(&th4_sem, 0);
424 430
425 thq1 = eina_thread_queue_new(); 431 thq1 = eina_thread_queue_new();
426 if (!thq1) fail(); 432 if (!thq1) fail();
427 thq2 = eina_thread_queue_new(); 433 thq2 = eina_thread_queue_new();
428 if (!thq2) fail(); 434 if (!thq2) fail();
429 ecore_thread_feedback_run(th41_do, NULL, NULL, NULL, NULL, EINA_TRUE); 435 ecore_thread_feedback_run(th51_do, NULL, NULL, NULL, NULL, EINA_TRUE);
430 ecore_thread_feedback_run(th42_do, NULL, NULL, NULL, NULL, EINA_TRUE); 436 ecore_thread_feedback_run(th52_do, NULL, NULL, NULL, NULL, EINA_TRUE);
431 437
432 for (;;) 438 for (;;)
433 { 439 {
@@ -453,6 +459,16 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t5)
453 usleep((rand() % 10) * 1000); 459 usleep((rand() % 10) * 1000);
454 } 460 }
455 } 461 }
462
463 eina_semaphore_lock(&th4_sem);
464 eina_semaphore_lock(&th4_sem);
465
466 // All done!
467 eina_semaphore_free(&th4_sem);
468 eina_thread_queue_free(thq1);
469 eina_thread_queue_free(thq2);
470
471 ecore_shutdown();
456} 472}
457END_TEST 473END_TEST
458 474
@@ -465,29 +481,32 @@ typedef struct
465 481
466static Eina_Spinlock msgnum_lock; 482static Eina_Spinlock msgnum_lock;
467static volatile int msgnum = 0; 483static volatile int msgnum = 0;
484static Eina_Semaphore th6_sem;
485const int EXIT_MESSAGE = -42;
468 486
469static void 487static void
470th51_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 488th61_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
471{ 489{
472 int val = 100; 490 int val = 100;
473 491
474 for (;;) 492 for (val = 100; val < 10100; val++)
475 { 493 {
476 Msg6 *msg; 494 Msg6 *msg;
477 void *ref; 495 void *ref;
478 496
479 msg = eina_thread_queue_send(thq1, sizeof(Msg6), &ref); 497 msg = eina_thread_queue_send(thq1, sizeof(Msg6), &ref);
480 if (!msg) fail(); 498 fail_if(!msg);
481 msg->value = val; 499 msg->value = val;
482 eina_thread_queue_send_done(thq1, ref); 500 eina_thread_queue_send_done(thq1, ref);
483 val++;
484 if (val == 10100) break;
485 usleep(1); 501 usleep(1);
486 } 502 }
503
504 eina_semaphore_release(&th6_sem, 1);
505 if (DEBUG) printf("%s: message sending done!\n", __FUNCTION__);
487} 506}
488 507
489static void 508static void
490th52_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 509th62_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
491{ 510{
492 int cnt = 0; 511 int cnt = 0;
493 512
@@ -495,24 +514,29 @@ th52_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
495 { 514 {
496 Msg6 *msg; 515 Msg6 *msg;
497 void *ref; 516 void *ref;
517 int val;
518
498 msg = eina_thread_queue_wait(thq1, &ref); 519 msg = eina_thread_queue_wait(thq1, &ref);
499 if (!msg) fail(); 520 fail_if(!msg);
500 if (DEBUG) printf("v %08i: %i [%i]\n", cnt, msg->value, eina_thread_queue_pending_get(thq1)); 521 if (DEBUG) printf("%s: v %08i: %i [%i]\n", __FUNCTION__, cnt, msg->value, eina_thread_queue_pending_get(thq1));
522 val = msg->value;
501 eina_thread_queue_wait_done(thq1, ref); 523 eina_thread_queue_wait_done(thq1, ref);
524 if (val == EXIT_MESSAGE) break;
502 cnt++; 525 cnt++;
503 eina_spinlock_take(&msgnum_lock); 526 eina_spinlock_take(&msgnum_lock);
504 msgnum++; 527 msgnum++;
505 if (msgnum == 10000)
506 {
507 eina_spinlock_release(&msgnum_lock);
508 break;
509 }
510 eina_spinlock_release(&msgnum_lock); 528 eina_spinlock_release(&msgnum_lock);
511 } 529 }
530
531 eina_spinlock_take(&msgnum_lock);
532 ck_assert_int_eq(msgnum, 10000);
533 eina_spinlock_release(&msgnum_lock);
534 eina_semaphore_release(&th6_sem, 1);
535 if (DEBUG) printf("%s: message reading done!\n", __FUNCTION__);
512} 536}
513 537
514static void 538static void
515th53_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 539th63_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
516{ 540{
517 int cnt = 0; 541 int cnt = 0;
518 542
@@ -520,50 +544,78 @@ th53_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
520 { 544 {
521 Msg6 *msg; 545 Msg6 *msg;
522 void *ref; 546 void *ref;
547 int val;
548
523 msg = eina_thread_queue_wait(thq1, &ref); 549 msg = eina_thread_queue_wait(thq1, &ref);
524 if (!msg) fail(); 550 fail_if(!msg);
525 if (DEBUG) printf("v %08i: %i [%i]\n", cnt, msg->value, eina_thread_queue_pending_get(thq1)); 551 if (DEBUG) printf("%s: v %08i: %i [%i]\n", __FUNCTION__, cnt, msg->value, eina_thread_queue_pending_get(thq1));
552 val = msg->value;
526 eina_thread_queue_wait_done(thq1, ref); 553 eina_thread_queue_wait_done(thq1, ref);
554 if (val == EXIT_MESSAGE) break;
527 cnt++; 555 cnt++;
528 eina_spinlock_take(&msgnum_lock); 556 eina_spinlock_take(&msgnum_lock);
529 msgnum++; 557 msgnum++;
530 if (msgnum == 10000)
531 {
532 eina_spinlock_release(&msgnum_lock);
533 break;
534 }
535 eina_spinlock_release(&msgnum_lock); 558 eina_spinlock_release(&msgnum_lock);
536 } 559 }
560
561 eina_spinlock_take(&msgnum_lock);
562 ck_assert_int_eq(msgnum, 10000);
563 eina_spinlock_release(&msgnum_lock);
564 eina_semaphore_release(&th6_sem, 1);
565 if (DEBUG) printf("%s: message reading done!\n", __FUNCTION__);
537} 566}
538 567
539START_TEST(ecore_test_ecore_thread_eina_thread_queue_t6) 568START_TEST(ecore_test_ecore_thread_eina_thread_queue_t6)
540{ 569{
570 Ecore_Thread *t1, *t2, *t3;
571 int do_break = 0;
572 Msg6 *msg;
573 void *ref;
574
575 if (DEBUG) setbuf(stdout, NULL);
576
541 eina_init(); 577 eina_init();
542 ecore_init(); 578 ecore_init();
543 579
580 eina_semaphore_new(&th6_sem, 0);
544 eina_spinlock_new(&msgnum_lock); 581 eina_spinlock_new(&msgnum_lock);
545 thq1 = eina_thread_queue_new(); 582 thq1 = eina_thread_queue_new();
546 if (!thq1) fail(); 583 fail_if(!thq1);
547 ecore_thread_feedback_run(th51_do, NULL, NULL, NULL, NULL, EINA_TRUE); 584 t1 = ecore_thread_feedback_run(th61_do, NULL, NULL, NULL, NULL, EINA_TRUE);
548 ecore_thread_feedback_run(th52_do, NULL, NULL, NULL, NULL, EINA_TRUE); 585 t2 = ecore_thread_feedback_run(th62_do, NULL, NULL, NULL, NULL, EINA_TRUE);
549 ecore_thread_feedback_run(th53_do, NULL, NULL, NULL, NULL, EINA_TRUE); 586 t3 = ecore_thread_feedback_run(th63_do, NULL, NULL, NULL, NULL, EINA_TRUE);
550 587
551 for (;;) 588 // Spin until we reach 10000 messages sent
589 while (!do_break)
552 { 590 {
553 eina_spinlock_take(&msgnum_lock); 591 eina_spinlock_take(&msgnum_lock);
554 if (DEBUG) printf("msgnum %i\n", msgnum); 592 if (DEBUG) printf("msgnum %i\n", msgnum);
555 if (msgnum == 10000) 593 if (msgnum == 10000) do_break = 1;
556 { 594 else ck_assert_int_lt(msgnum, 10000);
557 eina_spinlock_release(&msgnum_lock);
558 break;
559 }
560 else if (msgnum > 10000)
561 {
562 fail();
563 }
564 eina_spinlock_release(&msgnum_lock); 595 eina_spinlock_release(&msgnum_lock);
565 } 596 }
566 printf("msg multi to 1 ok\n"); 597
598 // Send exit message twice
599 msg = eina_thread_queue_send(thq1, sizeof(Msg6), &ref);
600 msg->value = EXIT_MESSAGE;
601 eina_thread_queue_send_done(thq1, ref);
602
603 msg = eina_thread_queue_send(thq1, sizeof(Msg6), &ref);
604 msg->value = EXIT_MESSAGE;
605 eina_thread_queue_send_done(thq1, ref);
606
607 // Wait for 3 threads
608 fail_if(!eina_semaphore_lock(&th6_sem));
609 fail_if(!eina_semaphore_lock(&th6_sem));
610 fail_if(!eina_semaphore_lock(&th6_sem));
611
612 // All done!
613 eina_semaphore_free(&th6_sem);
614 eina_thread_queue_free(thq1);
615 eina_spinlock_free(&msgnum_lock);
616
617 ecore_shutdown();
618 eina_shutdown();
567} 619}
568END_TEST 620END_TEST
569 621
@@ -577,7 +629,7 @@ typedef struct
577int p[2]; 629int p[2];
578 630
579static void 631static void
580thspeed21_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED) 632thspeed7_do(void *data EINA_UNUSED, Ecore_Thread *th EINA_UNUSED)
581{ 633{
582 Msg7 *msg; 634 Msg7 *msg;
583 void *ref; 635 void *ref;
@@ -611,7 +663,7 @@ START_TEST(ecore_test_ecore_thread_eina_thread_queue_t7)
611 ret = eina_thread_queue_fd_get(thq1); 663 ret = eina_thread_queue_fd_get(thq1);
612 fail_if(ret != p[1]); 664 fail_if(ret != p[1]);
613 665
614 ecore_thread_feedback_run(thspeed21_do, NULL, NULL, NULL, NULL, EINA_TRUE); 666 ecore_thread_feedback_run(thspeed7_do, NULL, NULL, NULL, NULL, EINA_TRUE);
615 for (;;) 667 for (;;)
616 { 668 {
617 char buf; 669 char buf;