More thread queue tests
This commit is contained in:
@@ -95,6 +95,8 @@ static void *test_thread_queue_reader_writer_func(void *arg)
|
|||||||
fail_if(my_msg->a != i);
|
fail_if(my_msg->a != i);
|
||||||
free(my_msg);
|
free(my_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST (test_thread_queue_reader_writer)
|
START_TEST (test_thread_queue_reader_writer)
|
||||||
@@ -149,6 +151,53 @@ START_TEST (test_thread_queue_zero_len)
|
|||||||
|
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
void *test_thread_queue_multiple_writers_func(void *arg)
|
||||||
|
{
|
||||||
|
struct uc_threadqueue *queue = arg;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
|
||||||
|
struct thr_msg *msg = malloc(sizeof *msg);
|
||||||
|
fail_if(msg == NULL);
|
||||||
|
msg->a = i;
|
||||||
|
fail_if(uc_thread_queue_add(queue, &msg->msg) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST (test_thread_queue_multiple_writers)
|
||||||
|
|
||||||
|
struct uc_threadqueue queue;
|
||||||
|
int i;
|
||||||
|
int count_max = 0;
|
||||||
|
pthread_t tid1,tid2,tid3;
|
||||||
|
|
||||||
|
fail_if(uc_thread_queue_init(&queue, 10) != 0);
|
||||||
|
fail_if(pthread_create(&tid1, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
|
||||||
|
fail_if(pthread_create(&tid2, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
|
||||||
|
fail_if(pthread_create(&tid3, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
|
||||||
|
|
||||||
|
for(i = 0; i < READER_WRITER_NUM_MSG * 3; i++) {
|
||||||
|
struct uc_threadmsg *msg;
|
||||||
|
struct thr_msg *my_msg;
|
||||||
|
fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0);
|
||||||
|
my_msg = (struct thr_msg *)msg;
|
||||||
|
|
||||||
|
if(my_msg->a == READER_WRITER_NUM_MSG - 1)
|
||||||
|
count_max++;
|
||||||
|
|
||||||
|
free(my_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_join(tid1, NULL);
|
||||||
|
pthread_join(tid2, NULL);
|
||||||
|
pthread_join(tid3, NULL);
|
||||||
|
|
||||||
|
fail_if(count_max != 3);
|
||||||
|
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
Suite *threadqueue_suite(void)
|
Suite *threadqueue_suite(void)
|
||||||
{
|
{
|
||||||
@@ -161,6 +210,10 @@ Suite *threadqueue_suite(void)
|
|||||||
tcase_add_test(tc1, test_thread_queue_reader_writer);
|
tcase_add_test(tc1, test_thread_queue_reader_writer);
|
||||||
tcase_add_test(tc1, test_thread_queue_reader_writer_len_1);
|
tcase_add_test(tc1, test_thread_queue_reader_writer_len_1);
|
||||||
tcase_add_test(tc1, test_thread_queue_zero_len);
|
tcase_add_test(tc1, test_thread_queue_zero_len);
|
||||||
|
tcase_add_test(tc1, test_thread_queue_multiple_writers);
|
||||||
|
|
||||||
|
//lets start with this:
|
||||||
|
tcase_set_timeout(tc1, 10);
|
||||||
|
|
||||||
suite_add_tcase(s, tc1);
|
suite_add_tcase(s, tc1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user