~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/daemons/qmaster/test_sge_calendar.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
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
 
16
 * 
 
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.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2003 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <stdio.h>
 
34
#include <unistd.h>
 
35
#include <string.h>
 
36
#include <ctype.h>
 
37
#include <time.h>
 
38
#include <sys/time.h>
 
39
 
 
40
#include "sge_all_listsL.h"
 
41
#include "sge.h"
 
42
#include "sge_log.h"
 
43
#include "sgermon.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"
 
49
#include "sge_time.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"
 
57
#include "sge_lock.h"
 
58
#include "sge_qinstance_state.h"
 
59
 
 
60
#include "sge_persistence_qmaster.h"
 
61
#include "spool/sge_spooling.h"
 
62
 
 
63
#include "msg_common.h"
 
64
#include "msg_qmaster.h"
 
65
#include "sgermon.h"
 
66
 
 
67
/* new data types */
 
68
 
 
69
typedef struct {
 
70
   char *year_cal; /* year calendar definition */ 
 
71
   char *week_cal; /* week calendar definition */
 
72
   char *description; /* a calendar description for the test output */
 
73
} cal_entry_t;
 
74
 
 
75
typedef struct {
 
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 */
 
82
} date_entry_t;
 
83
 
 
84
typedef struct {
 
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 */
 
89
} time_frame_entry_t;
 
90
 
 
91
/* global test variables */
 
92
 
 
93
/* should the look ahead list be printed? The list is not tested yet */
 
94
static int is_print_look_ahead = 0;
 
95
 
 
96
/**
 
97
 *
 
98
 * Calendar definitions for testing
 
99
 */
 
100
static cal_entry_t calendars[] = { 
 
101
/*year calendar*/                  {"1.2.2004-1.3.2004=suspended","NONE",
 
102
                                    "queue is suspended in March 2004"},
 
103
                                    
 
104
                                   {"1.2.2004-1.3.2004=off","NONE",
 
105
                                    "queue is off in March 2004"},
 
106
                                    
 
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"}, 
 
109
                                    
 
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"}, 
 
112
                                    
 
113
                                   {"1.2.2004-1.4.2004=9:0-18:0=suspended","NONE",
 
114
                                    "queue is suspended in March 2004 during the day"},
 
115
                                    
 
116
                                   {"1.2.2004-1.4.2004=18:0-9:0=suspended","NONE",
 
117
                                    "queue is enabled in March 2004 during the day"}, 
 
118
                                    
 
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."},   
 
121
 
 
122
 
 
123
/* no calendar */                  {"NONE", "NONE",
 
124
                                    "no calendar defined"},
 
125
                                    
 
126
                                    
 
127
/* week calendar*/                 {"NONE", "Mon-Sun=suspended",
 
128
                                    "queue is always disabled"},       
 
129
 
 
130
                                   {"NONE", "Mon-Sun=09:00-18:00=suspended",
 
131
                                    "queue is disabled during the day"},
 
132
                                    
 
133
                                   {"NONE", "Mon-sun=18:00-09:00=suspended",
 
134
                                    "queue is disabled during the night"},
 
135
                                    
 
136
                                   {"NONE", "Mon,Wed,Fri=09:00-18:00=suspended",
 
137
                                    "queue is disabled on Monday, Friday, and Wednesday during the day"},
 
138
 
 
139
                                   {"NONE", "Mon-Wed=09:00-18:00=suspended Mon-Fri=suspended",
 
140
                                    "queue is disabled on Monday till Wednesday during the day"},
 
141
 
 
142
 
 
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."},
 
145
                                     
 
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"},
 
148
                                  
 
149
                                   {"1.2.2004-1.3.2004=suspended", "Mon-Sun=suspended Mon-Sun=09:00-18:00=suspended",   
 
150
                                   "queue is always disabled"}, 
 
151
 
 
152
                                   {"NONE", "Sun-Wed=on Wed-Sat=on", 
 
153
                                   "queue is always enabled"}, 
 
154
                                   
 
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"},  
 
157
 
 
158
                                   {"NONE", "Mon-Wed=on Wed-Fri,Wed-Sat,Sun=on",  
 
159
                                   "queue is always enabled"}, 
 
160
 
 
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"},  
 
163
                                  
 
164
                                   {"NONE", "09:00-18:00=suspended",
 
165
                                    "queue is suspended from 9 to 6 every day"},
 
166
                                 
 
167
                                   {"NONE","Sun-Sat=suspended Wed-Fri=on",
 
168
                                    "queue is always suspended except Wednesday till Friday"},
 
169
 
 
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"},
 
174
 
 
175
/* issue 1787 */                   {"NONE","mon=0:0:0-21:0:0", "queue is off every monday from 0 to 21 hours"},
 
176
 
 
177
 
 
178
/* end of definition */            {NULL, NULL}
 
179
                                };
 
180
/**
 
181
 *
 
182
 * Test definitions
 
183
 *
 
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. 
 
186
 *
 
187
 * The time/date definition is: sec, min, hour, day(starting with 1), 
 
188
 * month(starting with 0) year (since 1900), 0, 0, 0.
 
189
 *
 
190
 * A -1 in state2 means that this entry does not exist.
 
191
 */
 
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},
 
195
 
 
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}, 
 
199
 
 
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}, 
 
205
 
 
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},    
 
211
                                
 
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}, 
 
217
                          
 
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},      
 
222
 
 
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},
 
224
                                
 
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}, 
 
226
                               
 
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}, 
 
228
                               
 
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},
 
232
                               
 
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}, 
 
235
                      
 
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}, 
 
241
 
 
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}, 
 
243
                                
 
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}, 
 
247
 
 
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},
 
254
 
 
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},
 
258
 
 
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},
 
260
 
 
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},
 
265
                               
 
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},  
 
270
                                
 
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}
 
272
                                  };
 
273
 
 
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}
 
294
                              };
 
295
 
 
296
 
 
297
/* test functions */
 
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);
 
301
 
 
302
static int test_time_frame(void *context, time_frame_entry_t *test, cal_entry_t *calendar, int test_nr); 
 
303
 
 
304
/* setup functions */
 
305
static lListElem *createCalObject(void *context, cal_entry_t *calendar);
 
306
 
 
307
/* output functions */
 
308
static void printDateError(time_t *when, struct tm *time);
 
309
 
 
310
 
 
311
 
 
312
/****** test_sge_calendar/test_state_change() **********************************
 
313
*  NAME
 
314
*     test_state_change() -- tests a single state change from the state change list
 
315
*
 
316
*  SYNOPSIS
 
317
*     static int test_state_change(lListElem *stateObject, u_long32 state, 
 
318
*     struct tm *time, int elemNr) 
 
319
*
 
320
*  FUNCTION
 
321
*     tests a single state change from the state change list
 
322
*
 
323
*  INPUTS
 
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
 
328
*
 
329
*  RESULT
 
330
*     static int - 0 okay / 1 test failed
 
331
*
 
332
*  NOTES
 
333
*     MT-NOTE: test_state_change() is MT safe 
 
334
*
 
335
*******************************************************************************/
 
336
static int test_state_change(lListElem *stateObject, u_long32 state, struct tm *time, int elemNr) 
 
337
{
 
338
   int ret = 0;
 
339
 
 
340
   if (lGetUlong(stateObject, CQU_state) != state) {
 
341
      ret = 1;
 
342
      printf("wrong state in state list (elem %d): expected %d, got %d\n", elemNr, (int) state, (int) lGetUlong(stateObject, CQU_state));
 
343
   }
 
344
   else {
 
345
      time_t now  = mktime(time);
 
346
      time_t result = (time_t) lGetUlong(stateObject, CQU_till);
 
347
      if (result != now) {
 
348
         ret = 1;
 
349
         printf("state list elem %d: ", elemNr);
 
350
         printDateError(&result, time);
 
351
      }
 
352
   }
 
353
   
 
354
   return ret;
 
355
}
 
356
 
 
357
/****** test_sge_calendar/test_state_change_list() *****************************
 
358
*  NAME
 
359
*     test_state_change_list() -- evaluates the state change list
 
360
*
 
361
*  SYNOPSIS
 
362
*     static int test_state_change_list(date_entry_t *test, lList 
 
363
*     *state_changes) 
 
364
*
 
365
*  FUNCTION
 
366
*     evaluates the state change list. The state change list is limited to
 
367
*     two states.
 
368
*
 
369
*  INPUTS
 
370
*     date_entry_t *test   - test to perform
 
371
*     lList *state_changes - state change list
 
372
*
 
373
*  RESULT
 
374
*     static int -  0 okay / 1 test failed
 
375
*
 
376
*  NOTES
 
377
*     MT-NOTE: test_state_change_list() is MT safe 
 
378
*
 
379
*******************************************************************************/
 
380
static int test_state_change_list(date_entry_t *test, lList *state_changes) 
 
381
{
 
382
   int ret = 0;
 
383
   int nr;
 
384
   if (is_print_look_ahead != 0) {
 
385
      lWriteListTo(state_changes, stdout);
 
386
   }   
 
387
 
 
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);
 
391
         ret = 1;
 
392
      }
 
393
      else {
 
394
         lListElem *state = lFirst(state_changes);
 
395
         ret |= test_state_change(state, test->state1, &(test->result1), 1);
 
396
 
 
397
         state = lNext(state);
 
398
         ret |= test_state_change(state, test->state2, &(test->result2), 2);
 
399
      }      
 
400
      
 
401
   }
 
402
   else {
 
403
      if ((nr = lGetNumberOfElem(state_changes)) != 1) {
 
404
         printf("wrong number of elemens in state change list. expected: %d, got: %d\n", 1, nr);
 
405
         ret = 1;
 
406
      }
 
407
      else {
 
408
         lListElem *state = lFirst(state_changes);
 
409
         ret |= test_state_change(state, test->state1, &(test->result1), 1);
 
410
      }
 
411
   }
 
412
   
 
413
   return ret;
 
414
}
 
415
 
 
416
/****** test_sge_calendar/printDateError() *************************************
 
417
*  NAME
 
418
*     printDateError() -- print date information in case of an error
 
419
*
 
420
*  SYNOPSIS
 
421
*     static void printDateError(time_t *when, struct tm *time) 
 
422
*
 
423
*  FUNCTION
 
424
*     print date information in case of an error
 
425
*
 
426
*  INPUTS
 
427
*     time_t *when    - result time
 
428
*     struct tm *time - expected time
 
429
*
 
430
*  NOTES
 
431
*     MT-NOTE: printDateError() is MT safe 
 
432
*
 
433
*******************************************************************************/
 
434
static void printDateError(time_t *when, struct tm *time) 
 
435
{
 
436
   struct tm *result;
 
437
   struct tm res;
 
438
 
 
439
   result = localtime_r(when, &res);
 
440
   
 
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",
 
443
      time->tm_sec,
 
444
      time->tm_min,
 
445
      time->tm_hour,
 
446
      time->tm_mday,
 
447
      time->tm_mon,
 
448
      time->tm_year,
 
449
      time->tm_wday,
 
450
      time->tm_yday,
 
451
      time->tm_isdst);
 
452
   printf("got     : sec:%d min:%d hour:%d mday:%d mon:%d year:%d wday:%d yday:%d isdst:%d\n",
 
453
      result->tm_sec,
 
454
      result->tm_min,
 
455
      result->tm_hour,
 
456
      result->tm_mday,
 
457
      result->tm_mon,
 
458
      result->tm_year,
 
459
      result->tm_wday,
 
460
      result->tm_yday,
 
461
      result->tm_isdst);      
 
462
}
 
463
 
 
464
/****** test_sge_calendar/createCalObject() ************************************
 
465
*  NAME
 
466
*     createCalObject() -- creates a calendar object from the cal data structure
 
467
*
 
468
*  SYNOPSIS
 
469
*     static lListElem* createCalObject(cal_entry_t *calendar) 
 
470
*
 
471
*  FUNCTION
 
472
*     creates a calendar object from the cal data structure
 
473
*
 
474
*  INPUTS
 
475
*     cal_entry_t *calendar - calendar definition
 
476
*
 
477
*  RESULT
 
478
*     static lListElem* - calendar object or NULL
 
479
*
 
480
*  NOTES
 
481
*     MT-NOTE: createCalObject() is MT safe 
 
482
*
 
483
*******************************************************************************/
 
484
static lListElem *createCalObject(void *context, cal_entry_t *calendar) 
 
485
{
 
486
   monitoring_t monitor;
 
487
   lListElem *sourceCal = NULL;
 
488
   lListElem *destCal = NULL;
 
489
   lList *answerList = NULL;
 
490
   
 
491
   sge_monitor_init(&monitor, "cal_test", NONE_EXT, NO_WARNING, NO_ERROR);
 
492
   
 
493
   sourceCal = lCreateElem(CAL_Type);
 
494
 
 
495
   lSetString(sourceCal, CAL_name, "test");
 
496
   lSetString(sourceCal, CAL_year_calendar, calendar->year_cal);
 
497
   lSetString(sourceCal, CAL_week_calendar, calendar->week_cal);
 
498
 
 
499
   destCal = lCreateElem(CAL_Type);
 
500
   
 
501
   if (0 != calendar_mod(context, &answerList, destCal, sourceCal, 1, "", "", NULL, 0, &monitor)) {
 
502
      lWriteListTo(answerList, stdout);
 
503
      lFreeElem(&destCal);
 
504
      lFreeList(&answerList);
 
505
   }
 
506
  
 
507
   lFreeElem(&sourceCal);
 
508
   
 
509
   sge_monitor_free(&monitor);
 
510
 
 
511
   return destCal;
 
512
}
 
513
 
 
514
 
 
515
/****** test_sge_calendar/test() ***********************************************
 
516
*  NAME
 
517
*     test() --  performs a single test
 
518
*
 
519
*  SYNOPSIS
 
520
*     static int test(date_entry_t *test, cal_entry_t *calendar, int test_nr) 
 
521
*
 
522
*  FUNCTION
 
523
*     performs a single test
 
524
*
 
525
*  INPUTS
 
526
*     date_entry_t *test    - test to perform
 
527
*     cal_entry_t *calendar - calendar to use
 
528
*     int test_nr           - test nr for output
 
529
*
 
530
*  RESULT
 
531
*     static int -  0 okay / 1 test failed
 
532
*
 
533
*  NOTES
 
534
*     MT-NOTE: test() is MT safe 
 
535
*
 
536
*******************************************************************************/
 
537
static int test(void *context, date_entry_t *test, cal_entry_t *calendar, int test_nr) 
 
538
{
 
539
   lListElem *destCal = NULL;
 
540
   int ret = 1;
 
541
 
 
542
   /* test output*/
 
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),      
 
547
      test->now.tm_mday,
 
548
      (test->now.tm_year + 1900),
 
549
   
 
550
      test->now.tm_hour,
 
551
      test->now.tm_min,
 
552
      test->now.tm_sec,
 
553
      
 
554
      test->now.tm_wday,
 
555
      test->now.tm_yday,
 
556
      (test->now.tm_isdst?"true":"false"));
 
557
   printf("==> year cal: \"%s\" week cal: \"%s\"\n", calendar->year_cal, calendar->week_cal);  
 
558
 
 
559
   /* start test */
 
560
   if ((destCal = createCalObject(context, calendar)) != NULL) {
 
561
      u_long32 current_state;
 
562
      time_t when = 0;
 
563
      time_t now  = mktime(&test->now);
 
564
      lList *state_changes_list = NULL;
 
565
 
 
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");
 
570
            }
 
571
         } else {
 
572
            printDateError(&when, &(test->result1));
 
573
         }
 
574
      } else {
 
575
         printf("wrong state: expected %d, got %d\n", test->state1, (int) current_state);
 
576
      }
 
577
      lFreeList(&state_changes_list);
 
578
   }
 
579
   
 
580
   /* test cleanup */
 
581
   printf("----------------\n");
 
582
   lFreeElem(&destCal);
 
583
   
 
584
   return ret;
 
585
}
 
586
 
 
587
/****** test_sge_calendar/main() ***********************************************
 
588
*  NAME
 
589
*     main() -- calendar test
 
590
*
 
591
*  SYNOPSIS
 
592
*     int main(int argc, char* argv[]) 
 
593
*
 
594
*  FUNCTION
 
595
*     calendar test
 
596
*
 
597
*  INPUTS
 
598
*     int argc     - nr. of args 
 
599
*     char* argv[] - args
 
600
*
 
601
*  RESULT
 
602
*     int -  nr of failed tests
 
603
*
 
604
*******************************************************************************/
 
605
int main(int argc, char* argv[])
 
606
{
 
607
   int test_counter = 0;
 
608
   int i = 0;
 
609
   int failed = 0;
 
610
   void *context = NULL;
 
611
   int cal_index = 0;
 
612
 
 
613
   lInit(nmv);
 
614
   obj_mt_init();
 
615
   
 
616
   printf("==> Calendar test <==\n");
 
617
   printf("---------------------\n");
 
618
 
 
619
   while ((cal_index = tests[i].cal_nr) != -1) {
 
620
      if (test(context, &(tests[i]), 
 
621
               &(calendars[cal_index]), 
 
622
               i) != 0) {
 
623
         failed++; 
 
624
      }   
 
625
      i++;
 
626
   }
 
627
   test_counter+=i;
 
628
 
 
629
   i=0;
 
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]),
 
633
                          i) != 0) {
 
634
         failed++;
 
635
      }
 
636
      i++;
 
637
   }
 
638
   test_counter+=i;
 
639
   
 
640
   if (failed == 0) {
 
641
      printf("\n==> All tests are okay <==\n");
 
642
   }
 
643
   else {
 
644
      printf("\n==> %d/%d test(s) failed <==\n", failed, test_counter);
 
645
   }
 
646
   
 
647
   return failed;
 
648
}
 
649
 
 
650
static int test_time_frame(void *context, time_frame_entry_t *test, cal_entry_t *calendar, int test_nr)
 
651
{
 
652
   int ret = 0;
 
653
   lListElem *destCal = NULL;
 
654
   struct tm *end_tm;
 
655
   struct tm res;
 
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);
 
658
 
 
659
   end_tm = localtime_r(&end_time, &res);
 
660
 
 
661
    /* test output*/
 
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),
 
668
   
 
669
      test->start_time.tm_hour,
 
670
      test->start_time.tm_min,
 
671
      test->start_time.tm_sec,
 
672
      
 
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),      
 
678
      end_tm->tm_mday,
 
679
      (end_tm->tm_year + 1900),
 
680
   
 
681
      end_tm->tm_hour,
 
682
      end_tm->tm_min,
 
683
      end_tm->tm_sec,
 
684
      
 
685
      end_tm->tm_wday,
 
686
      end_tm->tm_yday,
 
687
      (end_tm->tm_isdst?"true":"false"));
 
688
   printf("==> year cal: \"%s\" week cal: \"%s\"\n", calendar->year_cal, calendar->week_cal);  
 
689
 
 
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);
 
694
         ret++;
 
695
      } else {
 
696
         printf("==> Test is okay\n");
 
697
      }
 
698
   }
 
699
 
 
700
   /* test cleanup */
 
701
   printf("----------------\n");
 
702
   lFreeElem(&destCal);
 
703
 
 
704
   return ret;
 
705
}