2 * @file event_queue_test.h
4 * @brief Tests to test the Event-Queue type event_queue_t
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
26 #include "event_queue_test.h"
28 #include <utils/allocator.h>
29 #include <queues/event_queue.h>
30 #include <queues/jobs/initiate_ike_sa_job.h>
33 * Number of different times to insert per thread
35 #define EVENT_QUEUE_TIMES 5
37 * Number of entries per time per thread
39 #define EVENT_QUEUE_ENTRY_PER_TIME 20
42 * Number of test-thread
44 #define EVENT_QUEUE_INSERT_THREADS 1
47 * @brief Informations for the involved test-thread used in this test
50 typedef struct event_queue_test_s event_queue_test_t
;
52 struct event_queue_test_s
{
54 event_queue_t
*event_queue
;
57 * number of different event times to be inserted in the event-queue by each thread
59 int insert_times_count
;
62 * number of event to insert at one time
68 static void event_queue_insert_thread(event_queue_test_t
* testinfos
)
70 timeval_t current_time
;
71 tester_t
*tester
= testinfos
->tester
;
76 gettimeofday(¤t_time
,NULL
);
77 for (i
= 0; i
< testinfos
->insert_times_count
;i
++)
80 for (j
= 0; j
< testinfos
->entries_per_time
;j
++)
82 job
= (job_t
*) initiate_ike_sa_job_create("testvalue");
84 time
.tv_sec
= current_time
.tv_sec
+ i
;
86 tester
->assert_true(tester
,(testinfos
->event_queue
->add_absolute(testinfos
->event_queue
,job
,time
) == SUCCESS
), "add call check");
92 void test_event_queue(tester_t
*tester
)
94 event_queue_t
* event_queue
= event_queue_create();
95 event_queue_test_t testinfos
;
96 pthread_t threads
[EVENT_QUEUE_INSERT_THREADS
];
97 int i
,j
, number_of_total_events
;
98 timeval_t current_time
, start_time
;
100 testinfos
.tester
= tester
;
101 testinfos
.event_queue
= event_queue
;
102 testinfos
.insert_times_count
= EVENT_QUEUE_TIMES
;
103 testinfos
.entries_per_time
= EVENT_QUEUE_ENTRY_PER_TIME
;
105 number_of_total_events
= EVENT_QUEUE_ENTRY_PER_TIME
* EVENT_QUEUE_TIMES
* EVENT_QUEUE_INSERT_THREADS
;
107 gettimeofday(&start_time
,NULL
);
109 for (i
= 0; i
< EVENT_QUEUE_INSERT_THREADS
; i
++)
112 retval
= pthread_create( &(threads
[i
]), NULL
,(void*(*)(void*)) &event_queue_insert_thread
, (void*) &testinfos
);
113 tester
->assert_true(tester
,(retval
== 0), "thread creation call check");
117 /* wait for all threads */
118 for (i
= 0; i
< EVENT_QUEUE_INSERT_THREADS
; i
++)
121 retval
= pthread_join(threads
[i
], NULL
);
122 tester
->assert_true(tester
,(retval
== 0), "thread creation call check");
126 tester
->assert_true(tester
,(event_queue
->get_count(event_queue
) == number_of_total_events
), "event count check");
128 for (i
= 0; i
< EVENT_QUEUE_TIMES
;i
++)
130 for (j
= 0; j
< (EVENT_QUEUE_ENTRY_PER_TIME
* EVENT_QUEUE_INSERT_THREADS
);j
++)
134 tester
->assert_true(tester
,(event_queue
->get(event_queue
,&job
) == SUCCESS
), "get call check");
135 gettimeofday(¤t_time
,NULL
);
136 tester
->assert_true(tester
,((current_time
.tv_sec
- start_time
.tv_sec
) == i
), "value of entry check");
137 tester
->assert_true(tester
,(job
->destroy(job
) == SUCCESS
), "job destroy call check");
143 tester
->assert_true(tester
,(event_queue
->destroy(event_queue
) == SUCCESS
), "destroy call check");