1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2003 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
40
#include "sge_all_listsL.h"
44
#include "sge_event_master.h"
45
#include "sge_c_gdi.h"
46
#include "sge_calendar_qmaster.h"
47
#include "sge_qmod_qmaster.h"
48
#include "sge_qinstance_qmaster.h"
50
#include "sge_unistd.h"
51
#include "sge_answer.h"
52
#include "sge_cqueue.h"
53
#include "sge_qinstance.h"
54
#include "sge_calendar.h"
55
#include "sge_utility.h"
56
#include "sge_utility_qmaster.h"
58
#include "sge_qinstance_state.h"
60
#include "sge_persistence_qmaster.h"
61
#include "spool/sge_spooling.h"
63
#include "msg_common.h"
64
#include "msg_qmaster.h"
70
char *year_cal; /* year calendar definition */
71
char *week_cal; /* week calendar definition */
72
char *description; /* a calendar description for the test output */
76
int cal_nr; /* the calendar to test */
77
struct tm now; /* the current date */
78
struct tm result1; /* the expected state change date */
79
int state1; /* the expected current state */
80
struct tm result2; /* the expected state change date */
81
int state2; /* the expected state change state */
85
int cal_nr; /* the calendar to test */
86
struct tm start_time; /* start of time frame */
87
u_long32 duration; /* duration of time frame */
88
bool open; /* calendar open or closed */
91
/* global test variables */
93
/* should the look ahead list be printed? The list is not tested yet */
94
static int is_print_look_ahead = 0;
98
* Calendar definitions for testing
100
static cal_entry_t calendars[] = {
101
/*year calendar*/ {"1.2.2004-1.3.2004=suspended","NONE",
102
"queue is suspended in March 2004"},
104
{"1.2.2004-1.3.2004=off","NONE",
105
"queue is off in March 2004"},
107
{"1.2.2004-1.4.2004=off 1.3.2004-1.5.2004=off","NONE",
108
"queue is off from March till June 2004, using 2 calendar entries"},
110
{"1.2.2004-1.4.2004=suspended 1.3.2004-1.5.2004=off","NONE",
111
"two overlapping calendar entries, one off, one suspended"},
113
{"1.2.2004-1.4.2004=9:0-18:0=suspended","NONE",
114
"queue is suspended in March 2004 during the day"},
116
{"1.2.2004-1.4.2004=18:0-9:0=suspended","NONE",
117
"queue is enabled in March 2004 during the day"},
119
{"1.2.2004-1.6.2004=18:0-9:0=suspended 1.3.2004-1.5.2004=suspended","NONE",
120
"queue is supended during the night, and turned suspended for 2 month."},
123
/* no calendar */ {"NONE", "NONE",
124
"no calendar defined"},
127
/* week calendar*/ {"NONE", "Mon-Sun=suspended",
128
"queue is always disabled"},
130
{"NONE", "Mon-Sun=09:00-18:00=suspended",
131
"queue is disabled during the day"},
133
{"NONE", "Mon-sun=18:00-09:00=suspended",
134
"queue is disabled during the night"},
136
{"NONE", "Mon,Wed,Fri=09:00-18:00=suspended",
137
"queue is disabled on Monday, Friday, and Wednesday during the day"},
139
{"NONE", "Mon-Wed=09:00-18:00=suspended Mon-Fri=suspended",
140
"queue is disabled on Monday till Wednesday during the day"},
143
/*mixed calendars */ {"1.2.2004-1.3.2004=suspended","Mon-Sun=09:00-18:00=suspended",
144
"queue is disabled during the day, except from 2/1/2004 till 3/1/2004. During that time it disabled for the whole day."},
146
{"24.12.2004-26.12.2004=on", "Mon-Fri=06:00-18:00=off Mon-Fri=09:00-18:00=suspended",
147
"queue is only enabled on the none working hours and Christmas"},
149
{"1.2.2004-1.3.2004=suspended", "Mon-Sun=suspended Mon-Sun=09:00-18:00=suspended",
150
"queue is always disabled"},
152
{"NONE", "Sun-Wed=on Wed-Sat=on",
153
"queue is always enabled"},
155
{"1.1.2004-1.2.2004=suspended 1.2.2004-1.3.2004=suspended 1.3.2004-1.4.2004=suspended 1.4.2004-30.4.2004=suspended 1.5.2004-1.6.2004=suspended", "NONE",
156
"queue is always disabled"},
158
{"NONE", "Mon-Wed=on Wed-Fri,Wed-Sat,Sun=on",
159
"queue is always enabled"},
161
{"1.2.2004-1.3.2004=on", "Mon-Wed=on Wed-Sun=on Mon-Sun=09:00-18:00=on",
162
"queue is always enabled"},
164
{"NONE", "09:00-18:00=suspended",
165
"queue is suspended from 9 to 6 every day"},
167
{"NONE","Sun-Sat=suspended Wed-Fri=on",
168
"queue is always suspended except Wednesday till Friday"},
170
/* disabling queues */ {"off","NONE","queue is always off"},
171
{"suspended", "NONE","queue is always suspended"},
172
{"NONE", "off", "queue is always off"},
173
{"NONE", "suspended", "queue is always suspended"},
175
/* issue 1787 */ {"NONE","mon=0:0:0-21:0:0", "queue is off every monday from 0 to 21 hours"},
178
/* end of definition */ {NULL, NULL}
184
* If no state change is expected, the result has to be set to:
185
* "0,0,1, 1,0,70, 0,0,0". This coresponds to the time in sec of 0.
187
* The time/date definition is: sec, min, hour, day(starting with 1),
188
* month(starting with 0) year (since 1900), 0, 0, 0.
190
* A -1 in state2 means that this entry does not exist.
192
static date_entry_t tests[] = { {0, {0,0,0, 1,0,104, 0,0,0}, {0,0,0, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,0, 2,2,104, 0,0,0}, QI_DO_CAL_SUSPEND},
193
{0, {0,0,0, 1,1,104, 0,0,0}, {0,0,0, 2,2,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING},
194
{0, {0,0,0, 2,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
196
{1, {0,0,0, 1,0,104, 0,0,0}, {0,0,0, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,0, 2,2,104, 0,0,0}, QI_DO_CAL_DISABLE},
197
{1, {0,0,0, 1,1,104, 0,0,0}, {0,0,0, 2,2,104, 0,0,0}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING},
198
{1, {0,0,0, 2,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
200
{2, {0,0,0, 1,0,104, 0,0,0}, {0,0,0, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE},
201
{2, {0,0,0, 1,1,104, 0,0,0}, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING},
202
{2, {0,0,0, 1,2,104, 0,0,0}, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING},
203
{2, {0,0,0, 1,3,104, 0,0,0}, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING},
204
{2, {0,0,0, 2,4,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
206
{3, {0,0,0, 1,0,104, 0,0,0}, {0,0,0, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,0, 2,3,104, 0,0,1}, QI_DO_CAL_SUSPEND},
207
{3, {0,0,0, 1,1,104, 0,0,0}, {0,0,0, 2,3,104, 0,0,1}, QI_DO_CAL_SUSPEND, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE},
208
{3, {0,0,0, 1,2,104, 0,0,0}, {0,0,0, 2,3,104, 0,0,1}, QI_DO_CAL_SUSPEND, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE},
209
{3, {0,0,0, 2,3,104, 0,0,0}, {0,0,0, 2,4,104, 0,0,1}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING},
210
{3, {0,0,0, 2,4,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
212
{4, {0,0, 0, 1,0,104, 0,0,0}, {0,0, 9, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 1,1,104, 0,0,0}, QI_DO_CAL_SUSPEND},
213
{4, {0,0, 0, 2,2,104, 0,0,0}, {0,0, 9, 2,2,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 2,2,104, 0,0,0}, QI_DO_CAL_SUSPEND},
214
{4, {0,0,10, 2,2,104, 0,0,0}, {0,0,18, 2,2,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,9, 3,2,104, 0,0,0}, QI_DO_NOTHING},
215
{4, {0,0,19, 2,2,104, 0,0,0}, {0,0, 9, 3,2,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 3,2,104, 0,0,0}, QI_DO_CAL_SUSPEND},
216
{4, {0,0,0, 2,4,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
218
{5, {0,0, 0, 1,0,104, 0,0,0}, {0,0,18, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0, 9, 2,1,104, 0,0,0}, QI_DO_CAL_SUSPEND},
219
{5, {0,0,20, 1,2,104, 0,0,0}, {0,0, 9, 2,2,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,18, 2,2,104, 0,0,0}, QI_DO_NOTHING},
220
{5, {0,0,10, 2,2,104, 0,0,0}, {0,0,18, 2,2,104, 0,0,0}, QI_DO_NOTHING, {0,0,9, 3,2,104, 0,0,0}, QI_DO_CAL_SUSPEND},
221
{5, {0,0,0, 2,4,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
223
{6, {0,0, 0, 1,2,104, 0,0,0}, {0,0, 9, 2,4,104, 0,0,1}, QI_DO_CAL_SUSPEND, {0,0,18, 2,4,104, 0,0,1}, QI_DO_NOTHING},
225
{7, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
227
{8, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,1, 1,0, 70, 0,0,0}, -1},
229
{9, {0,0, 0, 1,1,104, 0,0,0}, {0,0, 9, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 1,1,104, 0,0,0}, QI_DO_CAL_SUSPEND},
230
{9, {0,0,10, 1,1,104, 0,0,0}, {0,0,18, 1,1,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0, 9, 2,1,104, 0,0,0}, QI_DO_NOTHING},
231
{9, {0,0,20, 1,1,104, 0,0,0}, {0,0, 9, 2,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 2,1,104, 0,0,0}, QI_DO_CAL_SUSPEND},
233
{10, {0,0, 0, 1,1,104, 0,0,0}, {0,0, 9, 1,1,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,18, 1,1,104, 0,0,0}, QI_DO_NOTHING},
234
{10, {0,0,20, 1,1,104, 0,0,0}, {0,0, 9, 2,1,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,18, 2,1,104, 0,0,0}, QI_DO_NOTHING},
236
{11, {0,0, 0,22,8,104, 0,0,1}, {0,0, 9,22,8,104, 0,0,1}, QI_DO_NOTHING, {0,0,18,22,8,104, 0,0,1}, QI_DO_CAL_SUSPEND},
237
{11, {0,0,10,22,8,104, 0,0,1}, {0,0,18,22,8,104, 0,0,1}, QI_DO_CAL_SUSPEND, {0,0, 9,24,8,104, 0,0,1}, QI_DO_NOTHING},
238
{11, {0,0,20,22,8,104, 0,0,1}, {0,0, 9,24,8,104, 0,0,1}, QI_DO_NOTHING, {0,0,18,24,8,104, 0,0,1}, QI_DO_CAL_SUSPEND},
239
{11, {0,0,20,24,8,104, 0,0,1}, {0,0, 9,27,8,104, 0,0,1}, QI_DO_NOTHING, {0,0,18,27,8,104, 0,0,1}, QI_DO_CAL_SUSPEND},
240
{11, {0,0,20,20,8,104, 0,0,1}, {0,0, 9,22,8,104, 0,0,1}, QI_DO_NOTHING, {0,0,18,22,8,104, 0,0,1}, QI_DO_CAL_SUSPEND},
242
{12, {0,0, 0,20,8,104, 0,0,1}, {0,0, 0,25,8,104, 0,0,1}, QI_DO_CAL_SUSPEND, {0,0, 0,27,8,104, 0,0,1}, QI_DO_NOTHING},
244
{13, {0,0, 0,20,8,104, 0,0,1}, {0,0, 9,20,8,104, 0,0,1}, QI_DO_NOTHING, {0,0,18,20,8,104, 0,0,1}, QI_DO_CAL_SUSPEND},
245
{13, {0,0, 0, 2,1,104, 0,0,0}, {0,0, 0, 2,2,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0, 9, 2,2,104, 0,0,0}, QI_DO_NOTHING},
246
{13, {0,0,10, 1,0,104, 0,0,0}, {0,0,18, 1,0,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0, 9, 2,0,104, 0,0,0}, QI_DO_NOTHING},
248
{14, {0,0, 0,24,11,104, 0,0,0}, {0,0, 6,27,11,104, 0,0,0}, QI_DO_NOTHING, {0,0, 9,27,11,104, 0,0,0}, QI_DO_CAL_DISABLE},
249
{15, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,1, 1,0, 70, 0,0,0}, -1},
250
{16, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
251
{17, {0,0, 0, 2,0,104, 0,0,0}, {0,0,0, 2,5, 104, 0,0,1},QI_DO_CAL_SUSPEND , {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING },
252
{18, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
253
{19, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_NOTHING, {0,0,1, 1,0, 70, 0,0,0}, -1},
255
{20, {0,0, 0, 1,1,104, 0,0,0}, {0,0, 9, 1,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 1,1,104, 0,0,0}, QI_DO_CAL_SUSPEND},
256
{20, {0,0,10, 1,1,104, 0,0,0}, {0,0,18, 1,1,104, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0, 9, 2,1,104, 0,0,0}, QI_DO_NOTHING},
257
{20, {0,0,20, 1,1,104, 0,0,0}, {0,0, 9, 2,1,104, 0,0,0}, QI_DO_NOTHING, {0,0,18, 2,1,104, 0,0,0}, QI_DO_CAL_SUSPEND},
259
{21, {0,0, 0,20,8,104, 0,0,1}, {0,0, 0,22,8,104, 0,0,1}, QI_DO_CAL_SUSPEND, {0,0, 0,25,8,104, 0,0,1}, QI_DO_NOTHING},
261
{22, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, -1},
262
{23, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,1, 1,0, 70, 0,0,0}, -1},
263
{24, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_CAL_DISABLE, {0,0,1, 1,0, 70, 0,0,0}, -1},
264
{25, {0,0, 0, 1,2,104, 0,0,0}, {0,0,1, 1,0, 70, 0,0,0}, QI_DO_CAL_SUSPEND, {0,0,1, 1,0, 70, 0,0,0}, -1},
266
{26, {0,0, 0, 1,2,104, 0,0,0}, {0,0,21, 1,2, 104, 0,0,0}, QI_DO_CAL_DISABLE, {0,0,0, 8,2, 104, 0,0,0}, QI_DO_NOTHING},
267
{26, {0,0, 10, 1,2,104, 0,0,0}, {0,0,21, 1,2, 104, 0,0,0}, QI_DO_CAL_DISABLE, {0,0,0, 8,2, 104, 0,0,0}, QI_DO_NOTHING},
268
{26, {0,0, 22, 1,2,104, 0,0,0}, {0,0,0, 8,2, 104, 0,0,0}, QI_DO_NOTHING, {0,0,21, 8,2, 104, 0,0,0}, QI_DO_CAL_DISABLE},
269
{26, {0,0, 12, 3,2,104, 0,0,0}, {0,0,0, 8,2, 104, 0,0,0}, QI_DO_NOTHING, {0,0,21, 8,2, 104, 0,0,0}, QI_DO_CAL_DISABLE},
271
{-1, {0,0,0, 0,0,104, 0,0,0}, {0,0,0, 0,0,104, 0,0,0}, -1, {0,0,0, 0,0,104, 0,0,0}, -1}
274
static time_frame_entry_t time_frame_tests[] = {
275
/*year calendar*/ {0, {0,0,0, 1,0,104, 0,0,0}, 3600, true},
276
{0, {0,30,23, 31,0,104, 0,0,0}, 3600, false},
277
{0, {0,0,12, 31,0,105, 0,0,0}, 3600, true},
278
{1, {0,0,0, 1,0,104, 0,0,0}, 3600, true},
279
{1, {0,30,23, 31,0,104, 0,0,0}, 3600, false},
280
{1, {0,0,12, 31,0,105, 0,0,0}, 3600, true},
281
{2, {0,0,0, 1,0,104, 0,0,0}, 3600, true},
282
{2, {0,30,23, 31,0,104, 0,0,0}, 3600, false},
283
{2, {0,0,12, 31,0,104, 0,0,0}, 6048000, false}, /* 70 days */
284
/* no calendar */ {7, {0,30,23, 31,0,104, 0,0,0}, 3600, true},
285
/* week calendar*/ {8, {0,0,0, 1,0,104, 0,0,0}, 3600, false},
286
{8, {0,30,23, 31,0,104, 0,0,0}, 3600, false},
287
{8, {0,0,12, 31,0,105, 0,0,0}, 3600, false},
288
{9, {1,0,18, 12,5,105, 0,0,1}, 53999, false}, /* 15 hours minus one second */
289
{9, {1,0,18, 12,5,105, 0,0,1}, 53998, true}, /* 15 hours minus two seconds */
290
{9, {0,0,18, 12,5,105, 0,0,1}, 53999, false}, /* 15 hours minus one seconds */
291
/*mixed calendars */ {13, {1,0,18, 2,2,104, 0,0,0}, 3600, true},
292
{13, {1,0,18, 15,1,104, 0,0,0}, 3600, false},
293
{-1, {0,0,0, 0,0,104, 0,0,0}, 0, false}
298
static int test(void *context, date_entry_t *test, cal_entry_t *calendar, int test_nr);
299
static int test_state_change_list(date_entry_t *test, lList *state_changes);
300
static int test_state_change(lListElem *stateObject, u_long32 state, struct tm *time, int elemNr);
302
static int test_time_frame(void *context, time_frame_entry_t *test, cal_entry_t *calendar, int test_nr);
304
/* setup functions */
305
static lListElem *createCalObject(void *context, cal_entry_t *calendar);
307
/* output functions */
308
static void printDateError(time_t *when, struct tm *time);
312
/****** test_sge_calendar/test_state_change() **********************************
314
* test_state_change() -- tests a single state change from the state change list
317
* static int test_state_change(lListElem *stateObject, u_long32 state,
318
* struct tm *time, int elemNr)
321
* tests a single state change from the state change list
324
* lListElem *stateObject - a state change object
325
* u_long32 state - expected state
326
* struct tm *time - expected time
327
* int elemNr - element nr for output
330
* static int - 0 okay / 1 test failed
333
* MT-NOTE: test_state_change() is MT safe
335
*******************************************************************************/
336
static int test_state_change(lListElem *stateObject, u_long32 state, struct tm *time, int elemNr)
340
if (lGetUlong(stateObject, CQU_state) != state) {
342
printf("wrong state in state list (elem %d): expected %d, got %d\n", elemNr, (int) state, (int) lGetUlong(stateObject, CQU_state));
345
time_t now = mktime(time);
346
time_t result = (time_t) lGetUlong(stateObject, CQU_till);
349
printf("state list elem %d: ", elemNr);
350
printDateError(&result, time);
357
/****** test_sge_calendar/test_state_change_list() *****************************
359
* test_state_change_list() -- evaluates the state change list
362
* static int test_state_change_list(date_entry_t *test, lList
366
* evaluates the state change list. The state change list is limited to
370
* date_entry_t *test - test to perform
371
* lList *state_changes - state change list
374
* static int - 0 okay / 1 test failed
377
* MT-NOTE: test_state_change_list() is MT safe
379
*******************************************************************************/
380
static int test_state_change_list(date_entry_t *test, lList *state_changes)
384
if (is_print_look_ahead != 0) {
385
lWriteListTo(state_changes, stdout);
388
if (test->state2 != -1) {
389
if ((nr = lGetNumberOfElem(state_changes)) != 2) {
390
printf("wrong number of elemens in state change list. expected: %d, got: %d\n", 2, nr);
394
lListElem *state = lFirst(state_changes);
395
ret |= test_state_change(state, test->state1, &(test->result1), 1);
397
state = lNext(state);
398
ret |= test_state_change(state, test->state2, &(test->result2), 2);
403
if ((nr = lGetNumberOfElem(state_changes)) != 1) {
404
printf("wrong number of elemens in state change list. expected: %d, got: %d\n", 1, nr);
408
lListElem *state = lFirst(state_changes);
409
ret |= test_state_change(state, test->state1, &(test->result1), 1);
416
/****** test_sge_calendar/printDateError() *************************************
418
* printDateError() -- print date information in case of an error
421
* static void printDateError(time_t *when, struct tm *time)
424
* print date information in case of an error
427
* time_t *when - result time
428
* struct tm *time - expected time
431
* MT-NOTE: printDateError() is MT safe
433
*******************************************************************************/
434
static void printDateError(time_t *when, struct tm *time)
439
result = localtime_r(when, &res);
441
printf("wrong change date:\n");
442
printf("expected: sec:%d min:%d hour:%d mday:%d mon:%d year:%d wday:%d yday:%d isdst:%d\n",
452
printf("got : sec:%d min:%d hour:%d mday:%d mon:%d year:%d wday:%d yday:%d isdst:%d\n",
464
/****** test_sge_calendar/createCalObject() ************************************
466
* createCalObject() -- creates a calendar object from the cal data structure
469
* static lListElem* createCalObject(cal_entry_t *calendar)
472
* creates a calendar object from the cal data structure
475
* cal_entry_t *calendar - calendar definition
478
* static lListElem* - calendar object or NULL
481
* MT-NOTE: createCalObject() is MT safe
483
*******************************************************************************/
484
static lListElem *createCalObject(void *context, cal_entry_t *calendar)
486
monitoring_t monitor;
487
lListElem *sourceCal = NULL;
488
lListElem *destCal = NULL;
489
lList *answerList = NULL;
491
sge_monitor_init(&monitor, "cal_test", NONE_EXT, NO_WARNING, NO_ERROR);
493
sourceCal = lCreateElem(CAL_Type);
495
lSetString(sourceCal, CAL_name, "test");
496
lSetString(sourceCal, CAL_year_calendar, calendar->year_cal);
497
lSetString(sourceCal, CAL_week_calendar, calendar->week_cal);
499
destCal = lCreateElem(CAL_Type);
501
if (0 != calendar_mod(context, &answerList, destCal, sourceCal, 1, "", "", NULL, 0, &monitor)) {
502
lWriteListTo(answerList, stdout);
504
lFreeList(&answerList);
507
lFreeElem(&sourceCal);
509
sge_monitor_free(&monitor);
515
/****** test_sge_calendar/test() ***********************************************
517
* test() -- performs a single test
520
* static int test(date_entry_t *test, cal_entry_t *calendar, int test_nr)
523
* performs a single test
526
* date_entry_t *test - test to perform
527
* cal_entry_t *calendar - calendar to use
528
* int test_nr - test nr for output
531
* static int - 0 okay / 1 test failed
534
* MT-NOTE: test() is MT safe
536
*******************************************************************************/
537
static int test(void *context, date_entry_t *test, cal_entry_t *calendar, int test_nr)
539
lListElem *destCal = NULL;
543
printf("\n==> Test Nr: %d(%d)\n", test_nr, test->cal_nr);
544
printf("==> Description: %s\n", calendar->description);
545
printf("==> Time: %d/%d/%d %d:%d:%d (wday:%d yday:%d Summer time: %s)\n\n",
546
(test->now.tm_mon + 1),
548
(test->now.tm_year + 1900),
556
(test->now.tm_isdst?"true":"false"));
557
printf("==> year cal: \"%s\" week cal: \"%s\"\n", calendar->year_cal, calendar->week_cal);
560
if ((destCal = createCalObject(context, calendar)) != NULL) {
561
u_long32 current_state;
563
time_t now = mktime(&test->now);
564
lList *state_changes_list = NULL;
566
if (test->state1 == (current_state = calender_state_changes(destCal, &state_changes_list, &when, &now))) {
567
if (when == mktime(&test->result1)) {
568
if ((ret = test_state_change_list(test, state_changes_list)) == 0) {
569
printf("==> Test is okay\n");
572
printDateError(&when, &(test->result1));
575
printf("wrong state: expected %d, got %d\n", test->state1, (int) current_state);
577
lFreeList(&state_changes_list);
581
printf("----------------\n");
587
/****** test_sge_calendar/main() ***********************************************
589
* main() -- calendar test
592
* int main(int argc, char* argv[])
598
* int argc - nr. of args
599
* char* argv[] - args
602
* int - nr of failed tests
604
*******************************************************************************/
605
int main(int argc, char* argv[])
607
int test_counter = 0;
610
void *context = NULL;
616
printf("==> Calendar test <==\n");
617
printf("---------------------\n");
619
while ((cal_index = tests[i].cal_nr) != -1) {
620
if (test(context, &(tests[i]),
621
&(calendars[cal_index]),
630
while ((cal_index = time_frame_tests[i].cal_nr) != -1) {
631
if (test_time_frame(context, &(time_frame_tests[i]),
632
&(calendars[cal_index]),
641
printf("\n==> All tests are okay <==\n");
644
printf("\n==> %d/%d test(s) failed <==\n", failed, test_counter);
650
static int test_time_frame(void *context, time_frame_entry_t *test, cal_entry_t *calendar, int test_nr)
653
lListElem *destCal = NULL;
656
u_long32 start_time = (u_long32)mktime(&test->start_time);
657
time_t end_time = (time_t)duration_add_offset(start_time, test->duration);
659
end_tm = localtime_r(&end_time, &res);
662
printf("\n==> Test Nr: %d(%d)\n", test_nr, test->cal_nr);
663
printf("==> Description: %s\n", calendar->description);
664
printf("==> Start Time: %d/%d/%d %d:%d:%d (wday:%d yday:%d Summer time: %s)\n",
665
(test->start_time.tm_mon + 1),
666
test->start_time.tm_mday,
667
(test->start_time.tm_year + 1900),
669
test->start_time.tm_hour,
670
test->start_time.tm_min,
671
test->start_time.tm_sec,
673
test->start_time.tm_wday,
674
test->start_time.tm_yday,
675
(test->start_time.tm_isdst?"true":"false"));
676
printf("==> End Time: %d/%d/%d %d:%d:%d (wday:%d yday:%d Summer time: %s)\n",
677
(end_tm->tm_mon + 1),
679
(end_tm->tm_year + 1900),
687
(end_tm->tm_isdst?"true":"false"));
688
printf("==> year cal: \"%s\" week cal: \"%s\"\n", calendar->year_cal, calendar->week_cal);
690
if ((destCal = createCalObject(context, calendar)) != NULL) {
691
bool result = calendar_open_in_time_frame(destCal, start_time, test->duration);
692
if (test->open != result) {
693
printf("wrong state for time frame: expected %d, got %d\n", test->open, result);
696
printf("==> Test is okay\n");
701
printf("----------------\n");