File: test_issues.c

package info (click to toggle)
gridengine 6.2u5-1squeeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 57,132 kB
  • ctags: 56,142
  • sloc: ansic: 438,030; java: 66,252; sh: 36,376; jsp: 7,757; xml: 5,850; makefile: 5,514; csh: 4,571; cpp: 2,848; perl: 2,401; tcl: 692; lisp: 669; yacc: 668; ruby: 642; lex: 344
file content (516 lines) | stat: -rw-r--r-- 16,424 bytes parent folder | download | duplicates (2)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

/*___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 <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>

#include "cl_commlib.h"
#include "cl_log_list.h"
#include "cl_endpoint_list.h"
#include "uti/sge_profiling.h"
#define CL_DO_SLOW 0

void sighandler_issue_tests(int sig);

static int do_shutdown = 0;

void sighandler_issue_tests(int sig) {
   if (sig == SIGPIPE) {
      return;
   }

   if (sig == SIGHUP) {
      return;
   }

   do_shutdown = 1;
}



extern int main(int argc, char** argv)
{
  struct sigaction sa;

  cl_com_handle_t* handle = NULL; 
  cl_com_handle_t* handle1 = NULL; 
  cl_com_handle_t* handle2 = NULL; 

  cl_com_message_t* message = NULL;
  cl_com_endpoint_t* sender = NULL;
  int i;
  cl_log_t log_level;
  cl_framework_t framework = CL_CT_TCP;
  cl_bool_t server_mode = CL_FALSE;
  int com_port = 0;
  char* com_host = NULL;
  int main_return = 0;
#if defined(IRIX)
  struct rlimit64 test_issues_limits;
#else
  struct rlimit test_issues_limits;
#endif

  
  if (argc < 4) {
     printf("param1=debug_level param2=framework(TCP/SSL) param3=server/client param4=port param5=hostname\n");
     exit(1);
  }

  if (argv[2]) {
     framework = CL_CT_UNDEFINED;
     if (strcmp(argv[2], "TCP") == 0) {
        framework=CL_CT_TCP;
        printf("using TCP framework\n");
     }
     if (strcmp(argv[2], "SSL") == 0) {
        framework=CL_CT_SSL;
        printf("using SSL framework\n");
     }
     if (framework == CL_CT_UNDEFINED) {
        printf("unexpected framework type\n");
        exit(1);
     }
  }

  if (argv[3]) {
     if (strcmp(argv[3], "server") == 0) {
        server_mode=CL_TRUE;
     }
  }

  if (argv[4]) {
     com_port = atoi(argv[4]);
  }

  if (argv[5]) {
     com_host = argv[5];
  }

  prof_mt_init();

  /* setup signalhandling */
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = sighandler_issue_tests;  /* one handler for all signals */
  sigemptyset(&sa.sa_mask);
  sigaction(SIGINT, &sa, NULL);
  sigaction(SIGTERM, &sa, NULL);
  sigaction(SIGHUP, &sa, NULL);
  sigaction(SIGPIPE, &sa, NULL);

#if defined(RLIMIT_VMEM) 
#if defined(IRIX)
   getrlimit64(RLIMIT_VMEM, &test_issues_limits);
#else
   getrlimit(RLIMIT_VMEM, &test_issues_limits);
#endif 
   test_issues_limits.rlim_max = RLIM_INFINITY;
   test_issues_limits.rlim_cur = RLIM_INFINITY;
#if defined(IRIX)
   setrlimit64(RLIMIT_VMEM, &test_issues_limits);
#else
   setrlimit(RLIMIT_VMEM, &test_issues_limits);
#endif

#else  /* if defined(RLIMIT_VMEM) */
#if defined(RLIMIT_AS)
#if defined(IRIX)
   getrlimit64(RLIMIT_AS, &test_issues_limits);
#else
   getrlimit(RLIMIT_AS, &test_issues_limits);
#endif 
   test_issues_limits.rlim_max = RLIM_INFINITY;
   test_issues_limits.rlim_cur = RLIM_INFINITY;
#if defined(IRIX)
   setrlimit64(RLIMIT_AS, &test_issues_limits);
#else
   setrlimit(RLIMIT_AS, &test_issues_limits);
#endif
#endif /* if defined(RLIMIT_AS) */
#endif /* if defined(RLIMIT_VMEM) */
  
#if defined(RLIMIT_VMEM) 
#if defined(IRIX)
   getrlimit64(RLIMIT_VMEM, &test_issues_limits);
#else
   getrlimit(RLIMIT_VMEM, &test_issues_limits);
#endif 
   printf("vmem limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
#else  /* if defined(RLIMIT_VMEM) */
#if defined(RLIMIT_AS)
#if defined(IRIX)
   getrlimit64(RLIMIT_AS, &test_issues_limits);
#else
   getrlimit(RLIMIT_AS, &test_issues_limits);
#endif 
   printf("vmem limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
#endif /* if defined(RLIMIT_AS) */
#endif /* if defined(RLIMIT_VMEM) */
 

#if defined(IRIX)
   getrlimit64(RLIMIT_STACK, &test_issues_limits);
#else
   getrlimit(RLIMIT_STACK, &test_issues_limits);
#endif 
   test_issues_limits.rlim_cur = test_issues_limits.rlim_max;
#if defined(IRIX)
   setrlimit64(RLIMIT_STACK, &test_issues_limits);
#else
   setrlimit(RLIMIT_STACK, &test_issues_limits);
#endif

#if defined(IRIX)
   getrlimit64(RLIMIT_STACK, &test_issues_limits);
#else
   getrlimit(RLIMIT_STACK, &test_issues_limits);
#endif 
   printf("stacksize limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);

#if defined(IRIX)
   getrlimit64(RLIMIT_DATA, &test_issues_limits);
#else
   getrlimit(RLIMIT_DATA, &test_issues_limits);
#endif 
   test_issues_limits.rlim_max = RLIM_INFINITY;
   test_issues_limits.rlim_cur = RLIM_INFINITY;
#if defined(IRIX)
   setrlimit64(RLIMIT_DATA, &test_issues_limits);
#else
   setrlimit(RLIMIT_DATA, &test_issues_limits);
#endif

#if defined(IRIX)
   getrlimit64(RLIMIT_DATA, &test_issues_limits);
#else
   getrlimit(RLIMIT_DATA, &test_issues_limits);
#endif 
   printf("data size limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);


#if defined(RLIMIT_RSS)
#if defined(IRIX)
   getrlimit64(RLIMIT_RSS, &test_issues_limits);
#else
   getrlimit(RLIMIT_RSS, &test_issues_limits);
#endif 
   test_issues_limits.rlim_cur = test_issues_limits.rlim_max;
#if defined(IRIX)
   setrlimit64(RLIMIT_RSS, &test_issues_limits);
#else
   setrlimit(RLIMIT_RSS, &test_issues_limits);
#endif

#if defined(IRIX)
   getrlimit64(RLIMIT_RSS, &test_issues_limits);
#else
   getrlimit(RLIMIT_RSS, &test_issues_limits);
#endif 
   printf("residet set size limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
#endif


#if defined(IRIX)
   getrlimit64(RLIMIT_FSIZE, &test_issues_limits);
#else
   getrlimit(RLIMIT_FSIZE, &test_issues_limits);
#endif 
   test_issues_limits.rlim_cur = test_issues_limits.rlim_max;
#if defined(IRIX)
   setrlimit64(RLIMIT_FSIZE, &test_issues_limits);
#else
   setrlimit(RLIMIT_FSIZE, &test_issues_limits);
#endif

#if defined(IRIX)
   getrlimit64(RLIMIT_FSIZE, &test_issues_limits);
#else
   getrlimit(RLIMIT_FSIZE, &test_issues_limits);
#endif 
   printf("file size size limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);



  printf("commlib setup ...\n");
  /* this is for compiler warning on irix65 */

  switch (atoi(argv[1])) {
     case 0:
        log_level=CL_LOG_OFF;
        break;
     case 1:
        log_level=CL_LOG_ERROR;
        break;
     case 2:
        log_level=CL_LOG_WARNING;
        break;
     case 3:
        log_level=CL_LOG_INFO;
        break;
     case 4:
        log_level=CL_LOG_DEBUG;
        break;
     default:
        log_level=CL_LOG_OFF;
        break;
  }
  cl_com_setup_commlib(CL_RW_THREAD, log_level, NULL);

  if (server_mode == CL_TRUE) {
     handle=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_TRUE, com_port, CL_TCP_DEFAULT, "server", 1, 1, 0 );
     cl_com_set_max_connection_close_mode(handle,CL_ON_MAX_COUNT_DISABLE_ACCEPT);
  } else {
     handle=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_FALSE, com_port, CL_TCP_DEFAULT, "client", 0, 1, 0 );
  }

#define TEST_ISSUES_READ_WRITE_TIMEOUT 3
  if (handle == NULL) {
     printf("could not get handle\n");
     sge_prof_cleanup();
     exit(101);
  } else {
     /* This is a "hack" to set the read/write timeout to only 4 seconds */
     handle->read_timeout = TEST_ISSUES_READ_WRITE_TIMEOUT;
     handle->write_timeout = TEST_ISSUES_READ_WRITE_TIMEOUT;
  }

  cl_com_get_service_port(handle,&i), 
  printf("running on host \"%s\", port %d, component name is \"%s\", id is %ld\n", 
         handle->local->comp_host, 
         i, 
         handle->local->comp_name,  
         handle->local->comp_id);

  if (server_mode == CL_TRUE) {
     int actual_issue = 0;
     int max_con_test_count = 2;
     unsigned long max_connection_count;

     while (do_shutdown != 1) {
        int ret_val;

        if (actual_issue == 1400) {
           cl_raw_list_lock(handle->connection_list);
           printf("actual connection count     = %lu\n", cl_raw_list_get_elem_count(handle->connection_list) );
           printf("actual max connection count = %lu\n", handle->max_open_connections);
           if (cl_raw_list_get_elem_count(handle->connection_list) > handle->max_open_connections) {
              printf("issue 1400 error found\n");
              main_return = 1;
           }
           cl_raw_list_unlock(handle->connection_list);
        }

        cl_commlib_trigger(handle, 1); 
   
        ret_val = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
        if (message != NULL) {
           int do_reply = 1;
           CL_LOG_STR(CL_LOG_INFO,"received message from",sender->comp_host);
           if (strstr((char*)message->message,"#1400i") && actual_issue != 1400) {
              printf("switching to test #1400\n");
              do_reply = 0;
              actual_issue = 1400;
              cl_com_get_max_connections(handle,&max_connection_count);
              printf("setting max_connection_count from %lu to %lu\n", (unsigned long)max_connection_count, (unsigned long)max_con_test_count);
              cl_com_set_max_connections(handle,max_con_test_count);
           } 

           if (strstr((char*)message->message,"#1400r")) {
              printf("resetting to defaults\n");
              do_reply = 0;
              actual_issue = 0;
              printf("setting max_connection_count from %lu to %lu\n", (unsigned long)max_con_test_count, (unsigned long)max_connection_count);
              cl_com_set_max_connections(handle,max_connection_count);
           } 


           if (do_reply == 1) {
              ret_val = cl_commlib_send_message(handle, 
                                sender->comp_host, 
                                sender->comp_name, 
                                sender->comp_id, CL_MIH_MAT_NAK,  
                                &message->message, 
                                message->message_length, 
                                NULL, 0,0, 
                                CL_FALSE, CL_FALSE);
              if (ret_val != CL_RETVAL_OK) {
                 CL_LOG_STR(CL_LOG_ERROR,"cl_commlib_send_message() returned:",cl_get_error_text(ret_val));
              }
           }
           cl_com_free_message(&message);
           cl_com_free_endpoint(&sender);
        } 
     }
  } else {
     int ret_val;
     char* data = NULL;
     unsigned long data_size = 1024*1024;
     struct timeval now;
     struct timeval start;
     int runtime = 0;
     char iz1400_data[7] = "#1400i";
     cl_byte_t* iz1400_pointer = (cl_byte_t *)iz1400_data;
     char test_data[5] = "test";
     cl_byte_t* test_pointer = (cl_byte_t *)test_data;
     int timeout_reached_count = 0;

     printf("\ntesting issue #1389 ...\n");

     
     while (timeout_reached_count < 5 && do_shutdown == 0 && main_return == 0) {
        if (data_size > 1024*1024*1024) {
           printf("skip malloc() more than 1GB\n");
           printf("issue #1389 failed\n");
           main_return = 1;
           break;
        }
        data = malloc(data_size * sizeof(char));
        memset(data, 0, data_size * sizeof(char));
        if (data == NULL) {
           printf("malloc() error: can't malloc(%ld)\n", data_size * sizeof(char) );
           printf("issue #1389 failed\n");
           main_return = 1;
           break;
        }
        printf("malloced %.2f MB\n", (double) (data_size*sizeof(char))/(1024*1024)  );
   
        sprintf(data, "hallo du");
      
        cl_commlib_send_message(handle, com_host, "server", 1, 
                            CL_MIH_MAT_NAK, 
                            (cl_byte_t**)&data, data_size * sizeof(char), 
                            NULL, 0,0, CL_FALSE, CL_FALSE);
   
        printf("starting measurement...\n");
        gettimeofday(&start, NULL);
        while (do_shutdown == 0) {
           cl_commlib_trigger(handle, 1); 
           ret_val = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
           if (ret_val != CL_RETVAL_OK && ret_val != CL_RETVAL_NO_MESSAGE) {
              printf("cl_commlib_receive_message returned: %s\n", cl_get_error_text(ret_val));
              printf("issue #1389 failed\n");
              main_return = 1;
              break;
           }
           if (message != NULL) {
              printf("received response message from %s with size %lu\n", sender->comp_host, message->message_length);
              cl_com_free_message(&message);
              cl_com_free_endpoint(&sender);
              break;
           } 
        }
        gettimeofday(&now,NULL);
        runtime = now.tv_sec - start.tv_sec;
        printf("send/receive took %d seconds\n", runtime );
        /* adding 2 seconds to be on the save side */
        if (runtime < TEST_ISSUES_READ_WRITE_TIMEOUT + 2) {
           if (data_size < 64*1024*1024) {
              data_size = data_size * 2;
           } else {
              data_size = data_size + 128*1024*1024;
           }
        } else {
           timeout_reached_count++;
           printf("test timeout reached %d times!\n", timeout_reached_count);
        }
     }

     printf("\ntesting issue #1400 ...\n");
     {
        printf("setting up server for test 1400 ...\n");
        cl_commlib_send_message(handle, com_host, "server", 1,
                                CL_MIH_MAT_ACK,
                                &iz1400_pointer, 7,
                                NULL, 0,0, CL_TRUE, CL_TRUE);
     }


     /* to be sure that server waits */
     printf("waiting 10 seconds for server to set max. connected client count ...\n");
     sleep(10);

     printf("creating new connections ...\n");

     handle1=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_FALSE, com_port, CL_TCP_DEFAULT, "client1", 0, 1, 0 );
     handle2=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_FALSE, com_port, CL_TCP_DEFAULT, "client2", 0, 1, 0 );
 
     printf("sending via connection 1 ...\n");
     cl_commlib_send_message(handle, com_host, "server", 1,
                            CL_MIH_MAT_ACK,
                            &test_pointer, 5,
                            NULL, 0,0, CL_TRUE, CL_TRUE);

     printf("sending via connection 2 ...\n");
     cl_commlib_send_message(handle1, com_host, "server", 1,
                            CL_MIH_MAT_ACK,
                            &test_pointer, 5,
                            NULL, 0,0, CL_TRUE, CL_TRUE);

     printf("sending via connection 3 ...\n");
     ret_val = cl_commlib_send_message(handle2, com_host, "server", 1,
                            CL_MIH_MAT_ACK,
                            &test_pointer, 5,
                            NULL, 0,0, CL_TRUE, CL_TRUE);

     if (ret_val == CL_RETVAL_OK) {
        printf("issue #1400 failed\n");
        main_return = 2;
     } else {
        printf("3. connection send returned: \"%s\" and failed - ok\n" , cl_get_error_text(ret_val));
     }

     printf("resetting server ...\n");

     iz1400_data[5] = 'r';
     cl_commlib_send_message(handle, com_host, "server", 1,
                            CL_MIH_MAT_ACK,
                            &iz1400_pointer, 7,
                            NULL, 0,0, CL_TRUE, CL_TRUE);
  }

  printf("shutting down ...\n");
  cl_commlib_shutdown_handle(handle, CL_FALSE);

  printf("commlib cleanup ...\n");
  cl_com_cleanup_commlib();

  printf("main done\n");
  return main_return;
}