2 * @file send_queue_test.c
4 * @brief Tests for the send_queue_t class.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #include "send_queue_test.h"
27 #include <queues/send_queue.h>
31 * @brief Informations for the involved test-thread used in this test
34 typedef struct send_queue_test_s send_queue_test_t
;
37 struct send_queue_test_s
{
39 * Associated protected_tester_t object
41 protected_tester_t
*tester
;
46 send_queue_t
*send_queue
;
49 * number of items to be inserted in the send-queue by each thread
51 int insert_item_count
;
54 * number of items to be removed by each
55 * receiver thread from the send-queue
57 int remove_item_count
;
61 * @brief sender thread used in the the send_queue test function
63 * @param testinfo informations for the specific thread.
65 static void test_send_queue_sender(send_queue_test_t
* testinfo
)
68 for (i
= 0; i
< testinfo
->insert_item_count
; i
++)
70 packet_t
*packet
= packet_create(AF_INET
);
71 testinfo
->tester
->assert_true(testinfo
->tester
,(packet
!= NULL
), "create packet call check");
72 testinfo
->send_queue
->add(testinfo
->send_queue
,packet
);
77 * @brief receiver thread used in the the send_queue test function
79 * @param testinfo informations for the specific thread.
81 static void test_send_queue_receiver(send_queue_test_t
* testinfo
)
84 for (i
= 0; i
< testinfo
->remove_item_count
; i
++)
87 packet
= testinfo
->send_queue
->get(testinfo
->send_queue
);
89 testinfo
->tester
->assert_true(testinfo
->tester
,( packet
!= NULL
), "packet not NULL call check");
91 packet
->destroy(packet
);
96 * description is in header file
98 void test_send_queue(protected_tester_t
*tester
)
100 int desired_value
, i
;
101 int sender_count
= 10;
102 int receiver_count
= 2;
103 pthread_t sender_threads
[sender_count
];
104 pthread_t receiver_threads
[receiver_count
];
105 send_queue_t
*send_queue
= send_queue_create();
106 send_queue_test_t test_infos
;
108 test_infos
.tester
= tester
;
109 test_infos
.send_queue
= send_queue
;
110 test_infos
.insert_item_count
= 10000;
111 test_infos
.remove_item_count
= 10000;
114 desired_value
= test_infos
.insert_item_count
* sender_count
-
115 test_infos
.remove_item_count
* receiver_count
;
117 for (i
= 0; i
< receiver_count
;i
++)
119 pthread_create( &receiver_threads
[i
], NULL
,(void*(*)(void*)) &test_send_queue_receiver
, (void*) &test_infos
);
122 for (i
= 0; i
< sender_count
;i
++)
124 pthread_create( &sender_threads
[i
], NULL
,(void*(*)(void*)) &test_send_queue_sender
, (void*) &test_infos
);
128 /* Wait for all threads */
129 for (i
= 0; i
< sender_count
;i
++)
131 pthread_join(sender_threads
[i
], NULL
);
133 for (i
= 0; i
< receiver_count
;i
++)
135 pthread_join(receiver_threads
[i
], NULL
);
139 /* the send-queue has to have diserd_value count entries*/
140 tester
->assert_true(tester
,(send_queue
->get_count(send_queue
) == desired_value
), "count value check");
141 send_queue
->destroy(send_queue
);