1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/**
* @file event_queue_test.h
*
* @brief Tests for the event_queue_t class.
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <pthread.h>
#include "event_queue_test.h"
#include <utils/allocator.h>
#include <queues/event_queue.h>
#include <queues/jobs/initiate_ike_sa_job.h>
/**
* Number of different times to insert per thread
*/
#define EVENT_QUEUE_TIMES 5
/**
* Number of entries per time per thread
*/
#define EVENT_QUEUE_ENTRY_PER_TIME 20
/**
* Number of test-thread
*/
#define EVENT_QUEUE_INSERT_THREADS 1
/**
* @brief Informations for the involved test-thread used in this test
*
*/
typedef struct event_queue_test_s event_queue_test_t;
struct event_queue_test_s{
tester_t *tester;
event_queue_t *event_queue;
/**
* number of different event times to be inserted in the event-queue by each thread
*/
int insert_times_count;
/**
* number of event to insert at one time
*/
int entries_per_time;
};
static void event_queue_insert_thread(event_queue_test_t * testinfos)
{
timeval_t current_time;
timeval_t time;
job_t * job;
int i,j;
gettimeofday(¤t_time,NULL);
for (i = 0; i < testinfos->insert_times_count;i++)
{
for (j = 0; j < testinfos->entries_per_time;j++)
{
job = (job_t *) initiate_ike_sa_job_create("testvalue");
time.tv_usec = 0;
time.tv_sec = current_time.tv_sec + i;
testinfos->event_queue->add_absolute(testinfos->event_queue,job,time);
}
}
}
void test_event_queue(tester_t *tester)
{
event_queue_t * event_queue = event_queue_create();
event_queue_test_t testinfos;
pthread_t threads[EVENT_QUEUE_INSERT_THREADS];
int i,j, number_of_total_events;
timeval_t current_time, start_time;
testinfos.tester = tester;
testinfos.event_queue = event_queue;
testinfos.insert_times_count = EVENT_QUEUE_TIMES;
testinfos.entries_per_time = EVENT_QUEUE_ENTRY_PER_TIME;
number_of_total_events = EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_TIMES * EVENT_QUEUE_INSERT_THREADS;
gettimeofday(&start_time,NULL);
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
int retval;
retval = pthread_create( &(threads[i]), NULL,(void*(*)(void*)) &event_queue_insert_thread, (void*) &testinfos);
tester->assert_true(tester,(retval== 0), "thread creation call check");
}
/* wait for all threads */
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
int retval;
retval = pthread_join(threads[i], NULL);
tester->assert_true(tester,(retval== 0), "thread creation call check");
}
tester->assert_true(tester,(event_queue->get_count(event_queue) == number_of_total_events), "event count check");
for (i = 0; i < EVENT_QUEUE_TIMES;i++)
{
for (j = 0; j < (EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_INSERT_THREADS);j++)
{
job_t *job;
job = event_queue->get(event_queue);
gettimeofday(¤t_time,NULL);
tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
job->destroy(job);
}
}
event_queue->destroy(event_queue);
return;
}
|