File: test_sge_schedd_conf.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (183 lines) | stat: -rw-r--r-- 5,548 bytes parent folder | download | duplicates (6)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *   Copyright: 2001 by Sun Microsystems, Inc.
 *
 *   All Rights Reserved.
 *
 ************************************************************************/
/*___INFO__MARK_END__*/                                   

#include <stdio.h>
#include <stdlib.h>

#include "uti/sge_rmon.h"

#include "cull/cull.h"

#include "sgeobj/sge_all_listsL.h"
#include "sgeobj/sge_answer.h"
#include "sgeobj/sge_schedd_conf.h"

/**
 * This test only tests issue: 1826. A complete
 * test of the scheduler configuration is needed
 * and currently missing.
 *
 * TODO: a complete scheduler config test
 */

typedef struct {
   int  test_nr;                /* identifies the test */
   char *test_value;            /* the test setting */
   bool result;                 /* expected result; true = valid setting */
} conf_settings_t;

typedef struct {
   u_long      test_attribute;   /* identifies the attribute to test */
   u_long      type;             /* identifies the attribute type */
   char        *description;     /* the test description */
} schedd_conf_t;

/**
 * Defines the atribute, which is tested.
 * Supported types are:
 * - lStringT
 * - lDoubleT
 * - lUlongT
 */
static schedd_conf_t conf_tests[] = {
   {SC_halflife_decay_list, lStringT,"test the halflife_decay_list settings"},
   {0,0,NULL}
};

static conf_settings_t tests[] = {
   {0, "NONE", true},
   {0, "nonesense", false},
   {0, "what:ever=this_is", false},
   {0, "cpu=1", true},
   {0, "cpu=1:", true},
   {0, "cpu=1:io=-1", true},
   {0, "cpu=1:io=0:", true},
   {0, "cpu=1:io=-1:mem=0", true},
   {0, "cpu=1:io=-1:mem=0:help=-1", true},
   {-1, NULL, false}
};

static int
test(conf_settings_t *setting, schedd_conf_t *test, int test_counter) 
{
   lListElem *schedd_conf = sconf_create_default();
   lList *schedd_list = lCreateList("schedd_conf", SC_Type);
   lList *answer_list = NULL;
   int ret = 0;

   if (schedd_conf != NULL && schedd_list != NULL) {
      lAppendElem(schedd_list, schedd_conf); 

      switch (test->type) {
         case lStringT :
               lSetString(schedd_conf, (int)conf_tests->test_attribute, setting->test_value);
            break;
         case lDoubleT :
            break;
         case lUlongT :
            break;
         default :
               printf("ERROR: requested type %d is not suported by the test infrastructure\n", (int) test->type);
               ret = 1;
            break;
      }
     
      if (sconf_validate_config(&answer_list, schedd_list) != setting->result ) {
         printf("ERROR: the test failed\n");
         printf("ERROR: expected that the validate function returns %s\n", setting->result?"TRUE":"FALSE");
         answer_list_output(&answer_list);
      }
   }
   else {
      printf("ERROR: failed to create the required elements\n");
      ret = 1;
   }
            
   return ret;
}


/****** test_sge_calendar/main() ***********************************************
*  NAME
*     main() -- calendar test
*
*  SYNOPSIS
*     int main(int argc, char* argv[]) 
*
*  FUNCTION
*     calendar test
*
*  INPUTS
*     int argc     - nr. of args 
*     char* argv[] - args
*
*  RESULT
*     int -  nr of failed tests
*
*******************************************************************************/
int main(int argc, char* argv[])
{
   int test_counter = 0;
   int failed = 0;
   int past_test = -1;
   lInit(nmv);
   
   printf("==> Scheduler config test <==\n");

   while (tests[test_counter].test_nr != -1) {
      if (past_test != tests[test_counter].test_nr) {
         past_test = tests[test_counter].test_nr;
         printf("\n-----------------------\nNr: %d/%d\n", test_counter, past_test);
         printf("Test:    %s\n", conf_tests[past_test].description);
      }
      else {
         printf("-------------\nNr: %d/%d\n", test_counter, past_test);
      }
      printf("Setting: %s\n", tests[test_counter].test_value);
      printf("Should be accepted: %s\n", tests[test_counter].result?"YES":"NO");
      if (test(&(tests[test_counter]), 
               &(conf_tests[tests[test_counter].test_nr]), 
               test_counter) != 0) {
         failed++; 
      }   
      test_counter++;
   }
   printf("\n-----------------------");
   if (failed == 0) {
      printf("\n==> All tests are okay <==\n");
   }
   else {
      printf("\n==> %d/%d test(s) failed <==\n", failed, test_counter);
   }
   
   return failed;
}