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

« back to all changes in this revision

Viewing changes to source/libs/sched/test_resource_utilization.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: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <stdio.h>
 
34
 
 
35
#include "sgeobj/sge_centry.h"
 
36
#include "sched/sge_resource_utilization.h"
 
37
#include "rmon/sgermon.h"
 
38
#include "sge_all_listsL.h"
 
39
#include "sge_mt_init.h"
 
40
 
 
41
#include "sge_qeti.h"
 
42
 
 
43
typedef struct {
 
44
   u_long32 start_time;
 
45
   u_long32 duration;
 
46
   double uti;
 
47
} test_array_t;
 
48
 
 
49
static int do_utilization_test(lListElem *cr, test_array_t *ta);
 
50
static int do_qeti_test(lListElem *cr, u_long32 *qeti_expected_result);
 
51
 
 
52
static int test_normal_utilization(void);
 
53
static int test_extensive_utilization(void);
 
54
 
 
55
int main(int argc, char *argv[]) 
 
56
{
 
57
   int ret = 0;
 
58
 
 
59
   DENTER_MAIN(TOP_LAYER, "test_resource_utilization");
 
60
 
 
61
   sge_mt_init();
 
62
 
 
63
   lInit(nmv);
 
64
 
 
65
   ret += test_normal_utilization();
 
66
   ret += test_extensive_utilization();
 
67
 
 
68
   if (ret != 0) {
 
69
      printf("\ntest failed!\n");
 
70
   }
 
71
 
 
72
   return ret;
 
73
}
 
74
 
 
75
static int do_utilization_test(lListElem *cr, test_array_t *ta)
 
76
{
 
77
   int ret = 0;
 
78
   double uti;
 
79
   int i;
 
80
 
 
81
   for (i = 0; ta[i].start_time != 0; i++) {
 
82
      uti = utilization_max(cr, ta[i].start_time, ta[i].duration);
 
83
      if (uti != ta[i].uti) {
 
84
         printf("failed: utilization(cr, "sge_U32CFormat", "sge_U32CFormat") returned %f, expected %f\n",
 
85
                sge_u32c(ta[i].start_time), sge_u32c(ta[i].duration), uti, ta[i].uti);
 
86
         ret++;
 
87
      } else {
 
88
         printf("success: utilization(cr, "sge_U32CFormat", "sge_U32CFormat") returned %f\n",
 
89
                sge_u32c(ta[i].start_time), sge_u32c(ta[i].duration), uti);
 
90
      }
 
91
   }
 
92
 
 
93
   return ret;
 
94
}
 
95
 
 
96
static int do_qeti_test(lListElem *cr, u_long32 *qeti_expected_result)
 
97
{
 
98
   lList *cr_list;
 
99
   sge_qeti_t *iter;
 
100
   u_long32 pe_time;
 
101
   int ret = 0;
 
102
   int i = 0;
 
103
 
 
104
   /* sge_qeti_allocate() */
 
105
   cr_list = lCreateList("", RUE_Type);
 
106
   lAppendElem(cr_list, cr);
 
107
   iter = sge_qeti_allocate2(cr_list);
 
108
 
 
109
   /* sge_qeti_first() */
 
110
   for (pe_time = sge_qeti_first(iter), i=0; pe_time; pe_time = sge_qeti_next(iter), i++) {
 
111
      if (qeti_expected_result == NULL) {
 
112
         printf("failed: qeti returned "sge_U32CFormat", expected no iteration\n", sge_u32c(pe_time));
 
113
         ret++;
 
114
      } else if (qeti_expected_result[i] != pe_time) {
 
115
         printf("failed: qeti returned "sge_U32CFormat", expected "sge_U32CFormat"\n", sge_u32c(pe_time), sge_u32c(qeti_expected_result[i]));
 
116
         ret++;
 
117
      } else {
 
118
         printf("success: QETI returned "sge_U32CFormat"\n", sge_u32c(pe_time));
 
119
      }
 
120
   }
 
121
 
 
122
   lDechainElem(cr_list, cr);
 
123
   sge_qeti_release(&iter);
 
124
   lFreeList(&cr_list);
 
125
 
 
126
   return ret;
 
127
}
 
128
 
 
129
static int test_normal_utilization(void)
 
130
{
 
131
   /*
 
132
    *  8-|          --------    ----
 
133
    *    |
 
134
    *  4-|                  ---- 
 
135
    *    |
 
136
    *  0----------------------------------->
 
137
    *               |       |   |   |
 
138
    *              800     1000
 
139
    */
 
140
   int ret = 0;
 
141
 
 
142
   static u_long32 qeti_expected_result[] = {
 
143
      1200,
 
144
      1100,
 
145
      1000,
 
146
      800
 
147
   };
 
148
 
 
149
   test_array_t test_array[] = {
 
150
   {1000, 100, 4},
 
151
   {1200, 150, 0},
 
152
   {700, 150, 8},
 
153
   {0, 0, 0}
 
154
   };
 
155
 
 
156
   lListElem *cr = lCreateElem(RUE_Type);
 
157
   lSetString(cr, RUE_name, "slots");
 
158
 
 
159
   printf("\n - test simple reservation - \n\n");
 
160
 
 
161
 
 
162
   printf("adding a 200s now assignment of 8 starting at 800\n");
 
163
   utilization_add(cr, 800, 200, 8, 100, 1, PE_TAG, "pe_slots", "STARTING", false);
 
164
 
 
165
   printf("adding a 100s now assignment of 4 starting at 1000\n");
 
166
   utilization_add(cr, 1000, 100, 4, 101, 1, PE_TAG, "pe_slots", "STARTING", false);
 
167
 
 
168
   printf("adding a 100s reservation of 8 starting at 1100\n");
 
169
   utilization_add(cr, 1100, 100, 8, 102, 1, PE_TAG, "pe_slots", "RESERVING", false);
 
170
 
 
171
   ret += do_utilization_test(cr, test_array);
 
172
   ret += do_qeti_test(cr, qeti_expected_result);
 
173
 
 
174
   lFreeElem(&cr);
 
175
   return ret;
 
176
}
 
177
 
 
178
static int test_extensive_utilization(void) {
 
179
   int ret = 0;
 
180
   
 
181
   lListElem *cr = lCreateElem(RUE_Type);
 
182
   lSetString(cr, RUE_name, "slots");
 
183
 
 
184
   printf("\n - test INIFNITY reservation & unreservation - \n\n");
 
185
 
 
186
   {
 
187
      /*
 
188
       *  8-|          |-------|             |-----......
 
189
       *    |
 
190
       *  4-|                  |---|----------------.... 
 
191
       *    |
 
192
       *  0-------------------------------------->
 
193
       *               |       |   |         |
 
194
       *              800     1000          2000
 
195
       */
 
196
 
 
197
      static u_long32 qeti_expected_result[] = {
 
198
         U_LONG32_MAX,
 
199
         2000,
 
200
         1000,
 
201
         800
 
202
      };
 
203
 
 
204
      test_array_t test_array[] = {
 
205
      {1000, 100, 4},
 
206
      {1200, U_LONG32_MAX, 8},
 
207
      {200, U_LONG32_MAX, 8},
 
208
      {700, 150, 8},
 
209
      {700, 100, 0},
 
210
      {3600, 150, 8},
 
211
      {1000, 1000, 4},
 
212
      {0, 0, 0}
 
213
      };
 
214
 
 
215
      printf("1. reserved and verify result\n\n");
 
216
 
 
217
      printf("adding a 200s now assignment of 8 starting at 800\n");
 
218
      utilization_add(cr, 800, 200, 8, 100, 1, PE_TAG, "pe_slots", "STARTING", false);
 
219
 
 
220
      printf("adding a 100s now assignment of 4 starting at 1000\n");
 
221
      utilization_add(cr, 1000, 100, 4, 101, 1, PE_TAG, "pe_slots", "STARTING", false);
 
222
 
 
223
      printf("adding a unlimited reservation of 4 starting at 1100\n");
 
224
      utilization_add(cr, 1100, U_LONG32_MAX, 4, 102, 1, PE_TAG, "pe_slots", "RESERVING", false);
 
225
 
 
226
      printf("adding a unlimited reservation of 4 starting at 2000\n");
 
227
      utilization_add(cr, 2000, U_LONG32_MAX, 4, 103, 1, PE_TAG, "pe_slots", "RESERVING", false);
 
228
 
 
229
      ret += do_utilization_test(cr, test_array);
 
230
      ret += do_qeti_test(cr, qeti_expected_result);
 
231
   }
 
232
 
 
233
   {
 
234
      /*
 
235
       *  8-|          |-------|
 
236
       *    |
 
237
       *  4-|                                |-----......
 
238
       *    |
 
239
       *  0-------------------------------------->
 
240
       *               |       |   |         |
 
241
       *              800     1000          2000
 
242
       */
 
243
 
 
244
      static u_long32 qeti_expected_result[] = {
 
245
         U_LONG32_MAX,
 
246
         2000,
 
247
         1000,
 
248
         800
 
249
      };
 
250
 
 
251
      test_array_t test_array[] = {
 
252
      {1000, 100, 0},
 
253
      {1200, U_LONG32_MAX, 4},
 
254
      {200, U_LONG32_MAX, 8},
 
255
      {700, 150, 8},
 
256
      {700, 100, 0},
 
257
      {3600, 150, 4},
 
258
      {1000, 1000, 0},
 
259
      {0, 0, 0}
 
260
      };
 
261
 
 
262
      printf("2. unreserve some and test result\n\n");
 
263
 
 
264
      printf("removing a 100s now assignment of 4 starting at 1000\n");
 
265
      utilization_add(cr, 1000, 100, -4, 101, 1, PE_TAG, "pe_slots", "STARTING", false);
 
266
 
 
267
      printf("removing a unlimited reservation of 4 starting at 1100\n");
 
268
      utilization_add(cr, 1100, U_LONG32_MAX, -4, 102, 1, PE_TAG, "pe_slots", "RESERVING", false);
 
269
 
 
270
      ret += do_utilization_test(cr, test_array);
 
271
      ret += do_qeti_test(cr, qeti_expected_result);
 
272
   }
 
273
 
 
274
   {
 
275
      test_array_t test_array[] = {
 
276
      {1000, 100, 0},
 
277
      {1200, U_LONG32_MAX, 0},
 
278
      {200, U_LONG32_MAX, 0},
 
279
      {700, 150, 0},
 
280
      {700, 100, 0},
 
281
      {3600, 150, 0},
 
282
      {1000, 1000, 0},
 
283
      {0, 0, 0}
 
284
      };
 
285
 
 
286
      printf("3. unreserve all\n\n");
 
287
 
 
288
      printf("removing a 200s now assignment of 8 starting at 800\n");
 
289
      utilization_add(cr, 800, 200, -8, 100, 1, PE_TAG, "pe_slots", "STARTING", false);
 
290
 
 
291
      printf("removing a unlimited reservation of 4 starting at 2000\n");
 
292
      utilization_add(cr, 2000, U_LONG32_MAX, -4, 103, 1, PE_TAG, "pe_slots", "RESERVING", false);
 
293
 
 
294
      ret += do_utilization_test(cr, test_array);
 
295
      ret += do_qeti_test(cr, NULL);
 
296
   }
 
297
 
 
298
   lFreeElem(&cr);
 
299
 
 
300
   return ret;
 
301
}