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: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
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"
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);
52
static int test_normal_utilization(void);
53
static int test_extensive_utilization(void);
55
int main(int argc, char *argv[])
59
DENTER_MAIN(TOP_LAYER, "test_resource_utilization");
65
ret += test_normal_utilization();
66
ret += test_extensive_utilization();
69
printf("\ntest failed!\n");
75
static int do_utilization_test(lListElem *cr, test_array_t *ta)
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);
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);
96
static int do_qeti_test(lListElem *cr, u_long32 *qeti_expected_result)
104
/* sge_qeti_allocate() */
105
cr_list = lCreateList("", RUE_Type);
106
lAppendElem(cr_list, cr);
107
iter = sge_qeti_allocate2(cr_list);
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));
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]));
118
printf("success: QETI returned "sge_U32CFormat"\n", sge_u32c(pe_time));
122
lDechainElem(cr_list, cr);
123
sge_qeti_release(&iter);
129
static int test_normal_utilization(void)
136
* 0----------------------------------->
142
static u_long32 qeti_expected_result[] = {
149
test_array_t test_array[] = {
156
lListElem *cr = lCreateElem(RUE_Type);
157
lSetString(cr, RUE_name, "slots");
159
printf("\n - test simple reservation - \n\n");
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);
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);
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);
171
ret += do_utilization_test(cr, test_array);
172
ret += do_qeti_test(cr, qeti_expected_result);
178
static int test_extensive_utilization(void) {
181
lListElem *cr = lCreateElem(RUE_Type);
182
lSetString(cr, RUE_name, "slots");
184
printf("\n - test INIFNITY reservation & unreservation - \n\n");
188
* 8-| |-------| |-----......
190
* 4-| |---|----------------....
192
* 0-------------------------------------->
197
static u_long32 qeti_expected_result[] = {
204
test_array_t test_array[] = {
206
{1200, U_LONG32_MAX, 8},
207
{200, U_LONG32_MAX, 8},
215
printf("1. reserved and verify result\n\n");
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);
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);
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);
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);
229
ret += do_utilization_test(cr, test_array);
230
ret += do_qeti_test(cr, qeti_expected_result);
239
* 0-------------------------------------->
244
static u_long32 qeti_expected_result[] = {
251
test_array_t test_array[] = {
253
{1200, U_LONG32_MAX, 4},
254
{200, U_LONG32_MAX, 8},
262
printf("2. unreserve some and test result\n\n");
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);
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);
270
ret += do_utilization_test(cr, test_array);
271
ret += do_qeti_test(cr, qeti_expected_result);
275
test_array_t test_array[] = {
277
{1200, U_LONG32_MAX, 0},
278
{200, U_LONG32_MAX, 0},
286
printf("3. unreserve all\n\n");
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);
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);
294
ret += do_utilization_test(cr, test_array);
295
ret += do_qeti_test(cr, NULL);