2 * @file job_queue_test.c
4 * @brief Tests for the job_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
28 #include "job_queue_test.h"
30 #include <queues/job_queue.h>
31 #include <queues/jobs/initiate_ike_sa_job.h>
34 typedef struct job_queue_test_s job_queue_test_t
;
37 * @brief Informations for the involved test-thread used in this test
40 struct job_queue_test_s
{
41 protected_tester_t
*tester
;
42 job_queue_t
*job_queue
;
44 * number of items to be inserted in the job-queue
46 int insert_item_count
;
48 * number of items to be removed by each
49 * receiver thread from the job-queue
51 int remove_item_count
;
55 * @brief sender thread used in the the job_queue test function
57 * @param testinfo informations for the specific thread.
59 static void test_job_queue_sender(job_queue_test_t
* testinfo
)
62 for (i
= 0; i
< testinfo
->insert_item_count
; i
++)
64 job_t
*job
= (job_t
*) initiate_ike_sa_job_create(NULL
);
65 testinfo
->job_queue
->add(testinfo
->job_queue
,job
);
70 * @brief receiver thread used in the the job_queue test function
72 * @param testinfo informations for the specific thread.
74 static void test_job_queue_receiver(job_queue_test_t
* testinfo
)
77 for (i
= 0; i
< testinfo
->remove_item_count
; i
++)
80 job
= testinfo
->job_queue
->get(testinfo
->job_queue
);
81 testinfo
->tester
->assert_true(testinfo
->tester
,(job
->get_type(job
) == INITIATE_IKE_SA
), "job type check");
87 * description is in header file
89 void test_job_queue(protected_tester_t
*tester
)
92 int sender_count
= 10;
93 int receiver_count
= 2;
94 pthread_t sender_threads
[sender_count
];
95 pthread_t receiver_threads
[receiver_count
];
96 job_queue_t
*job_queue
= job_queue_create();
97 job_queue_test_t test_infos
;
99 test_infos
.tester
= tester
;
100 test_infos
.job_queue
= job_queue
;
101 test_infos
.insert_item_count
= 10000;
102 test_infos
.remove_item_count
= 50000;
105 desired_value
= test_infos
.insert_item_count
* sender_count
-
106 test_infos
.remove_item_count
* receiver_count
;
108 for (i
= 0; i
< receiver_count
;i
++)
110 pthread_create( &receiver_threads
[i
], NULL
,(void*(*)(void*)) &test_job_queue_receiver
, (void*) &test_infos
);
112 for (i
= 0; i
< sender_count
;i
++)
114 pthread_create( &sender_threads
[i
], NULL
,(void*(*)(void*)) &test_job_queue_sender
, (void*) &test_infos
);
118 /* Wait for all threads */
119 for (i
= 0; i
< sender_count
;i
++)
121 pthread_join(sender_threads
[i
], NULL
);
123 for (i
= 0; i
< receiver_count
;i
++)
125 pthread_join(receiver_threads
[i
], NULL
);
128 /* the job-queue has to have disered_value count entries! */
129 tester
->assert_true(tester
,(job_queue
->get_count(job_queue
) == desired_value
), "get count value check");
131 job_queue
->destroy(job_queue
);