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

« back to all changes in this revision

Viewing changes to source/libs/comm/test_issues.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
 
 
2
/*___INFO__MARK_BEGIN__*/
 
3
/*************************************************************************
 
4
 * 
 
5
 *  The Contents of this file are made available subject to the terms of
 
6
 *  the Sun Industry Standards Source License Version 1.2
 
7
 * 
 
8
 *  Sun Microsystems Inc., March, 2001
 
9
 * 
 
10
 * 
 
11
 *  Sun Industry Standards Source License Version 1.2
 
12
 *  =================================================
 
13
 *  The contents of this file are subject to the Sun Industry Standards
 
14
 *  Source License Version 1.2 (the "License"); You may not use this file
 
15
 *  except in compliance with the License. You may obtain a copy of the
 
16
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
17
 * 
 
18
 *  Software provided under this License is provided on an "AS IS" basis,
 
19
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
20
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
21
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
22
 *  See the License for the specific provisions governing your rights and
 
23
 *  obligations concerning the Software.
 
24
 * 
 
25
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
26
 * 
 
27
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
28
 * 
 
29
 *   All Rights Reserved.
 
30
 * 
 
31
 ************************************************************************/
 
32
/*___INFO__MARK_END__*/
 
33
 
 
34
#include <stdio.h>
 
35
#include <stdlib.h>
 
36
#include <string.h>
 
37
#include <unistd.h>
 
38
#include <signal.h>
 
39
#include <sys/time.h>
 
40
#include <sys/resource.h>
 
41
 
 
42
#include "cl_commlib.h"
 
43
#include "cl_log_list.h"
 
44
#include "cl_endpoint_list.h"
 
45
#include "uti/sge_profiling.h"
 
46
#define CL_DO_SLOW 0
 
47
 
 
48
void sighandler_issue_tests(int sig);
 
49
 
 
50
static int do_shutdown = 0;
 
51
 
 
52
void sighandler_issue_tests(int sig) {
 
53
   if (sig == SIGPIPE) {
 
54
      return;
 
55
   }
 
56
 
 
57
   if (sig == SIGHUP) {
 
58
      return;
 
59
   }
 
60
 
 
61
   do_shutdown = 1;
 
62
}
 
63
 
 
64
 
 
65
 
 
66
extern int main(int argc, char** argv)
 
67
{
 
68
  struct sigaction sa;
 
69
 
 
70
  cl_com_handle_t* handle = NULL; 
 
71
  cl_com_handle_t* handle1 = NULL; 
 
72
  cl_com_handle_t* handle2 = NULL; 
 
73
 
 
74
  cl_com_message_t* message = NULL;
 
75
  cl_com_endpoint_t* sender = NULL;
 
76
  int i;
 
77
  cl_log_t log_level;
 
78
  cl_framework_t framework = CL_CT_TCP;
 
79
  cl_bool_t server_mode = CL_FALSE;
 
80
  int com_port = 0;
 
81
  char* com_host = NULL;
 
82
  int main_return = 0;
 
83
#if defined(IRIX)
 
84
  struct rlimit64 test_issues_limits;
 
85
#else
 
86
  struct rlimit test_issues_limits;
 
87
#endif
 
88
 
 
89
  
 
90
  if (argc < 4) {
 
91
     printf("param1=debug_level param2=framework(TCP/SSL) param3=server/client param4=port param5=hostname\n");
 
92
     exit(1);
 
93
  }
 
94
 
 
95
  if (argv[2]) {
 
96
     framework = CL_CT_UNDEFINED;
 
97
     if (strcmp(argv[2], "TCP") == 0) {
 
98
        framework=CL_CT_TCP;
 
99
        printf("using TCP framework\n");
 
100
     }
 
101
     if (strcmp(argv[2], "SSL") == 0) {
 
102
        framework=CL_CT_SSL;
 
103
        printf("using SSL framework\n");
 
104
     }
 
105
     if (framework == CL_CT_UNDEFINED) {
 
106
        printf("unexpected framework type\n");
 
107
        exit(1);
 
108
     }
 
109
  }
 
110
 
 
111
  if (argv[3]) {
 
112
     if (strcmp(argv[3], "server") == 0) {
 
113
        server_mode=CL_TRUE;
 
114
     }
 
115
  }
 
116
 
 
117
  if (argv[4]) {
 
118
     com_port = atoi(argv[4]);
 
119
  }
 
120
 
 
121
  if (argv[5]) {
 
122
     com_host = argv[5];
 
123
  }
 
124
 
 
125
  prof_mt_init();
 
126
 
 
127
  /* setup signalhandling */
 
128
  memset(&sa, 0, sizeof(sa));
 
129
  sa.sa_handler = sighandler_issue_tests;  /* one handler for all signals */
 
130
  sigemptyset(&sa.sa_mask);
 
131
  sigaction(SIGINT, &sa, NULL);
 
132
  sigaction(SIGTERM, &sa, NULL);
 
133
  sigaction(SIGHUP, &sa, NULL);
 
134
  sigaction(SIGPIPE, &sa, NULL);
 
135
 
 
136
#if defined(RLIMIT_VMEM) 
 
137
#if defined(IRIX)
 
138
   getrlimit64(RLIMIT_VMEM, &test_issues_limits);
 
139
#else
 
140
   getrlimit(RLIMIT_VMEM, &test_issues_limits);
 
141
#endif 
 
142
   test_issues_limits.rlim_max = RLIM_INFINITY;
 
143
   test_issues_limits.rlim_cur = RLIM_INFINITY;
 
144
#if defined(IRIX)
 
145
   setrlimit64(RLIMIT_VMEM, &test_issues_limits);
 
146
#else
 
147
   setrlimit(RLIMIT_VMEM, &test_issues_limits);
 
148
#endif
 
149
 
 
150
#else  /* if defined(RLIMIT_VMEM) */
 
151
#if defined(RLIMIT_AS)
 
152
#if defined(IRIX)
 
153
   getrlimit64(RLIMIT_AS, &test_issues_limits);
 
154
#else
 
155
   getrlimit(RLIMIT_AS, &test_issues_limits);
 
156
#endif 
 
157
   test_issues_limits.rlim_max = RLIM_INFINITY;
 
158
   test_issues_limits.rlim_cur = RLIM_INFINITY;
 
159
#if defined(IRIX)
 
160
   setrlimit64(RLIMIT_AS, &test_issues_limits);
 
161
#else
 
162
   setrlimit(RLIMIT_AS, &test_issues_limits);
 
163
#endif
 
164
#endif /* if defined(RLIMIT_AS) */
 
165
#endif /* if defined(RLIMIT_VMEM) */
 
166
  
 
167
#if defined(RLIMIT_VMEM) 
 
168
#if defined(IRIX)
 
169
   getrlimit64(RLIMIT_VMEM, &test_issues_limits);
 
170
#else
 
171
   getrlimit(RLIMIT_VMEM, &test_issues_limits);
 
172
#endif 
 
173
   printf("vmem limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
 
174
#else  /* if defined(RLIMIT_VMEM) */
 
175
#if defined(RLIMIT_AS)
 
176
#if defined(IRIX)
 
177
   getrlimit64(RLIMIT_AS, &test_issues_limits);
 
178
#else
 
179
   getrlimit(RLIMIT_AS, &test_issues_limits);
 
180
#endif 
 
181
   printf("vmem limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
 
182
#endif /* if defined(RLIMIT_AS) */
 
183
#endif /* if defined(RLIMIT_VMEM) */
 
184
 
 
185
 
 
186
#if defined(IRIX)
 
187
   getrlimit64(RLIMIT_STACK, &test_issues_limits);
 
188
#else
 
189
   getrlimit(RLIMIT_STACK, &test_issues_limits);
 
190
#endif 
 
191
   test_issues_limits.rlim_cur = test_issues_limits.rlim_max;
 
192
#if defined(IRIX)
 
193
   setrlimit64(RLIMIT_STACK, &test_issues_limits);
 
194
#else
 
195
   setrlimit(RLIMIT_STACK, &test_issues_limits);
 
196
#endif
 
197
 
 
198
#if defined(IRIX)
 
199
   getrlimit64(RLIMIT_STACK, &test_issues_limits);
 
200
#else
 
201
   getrlimit(RLIMIT_STACK, &test_issues_limits);
 
202
#endif 
 
203
   printf("stacksize limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
 
204
 
 
205
#if defined(IRIX)
 
206
   getrlimit64(RLIMIT_DATA, &test_issues_limits);
 
207
#else
 
208
   getrlimit(RLIMIT_DATA, &test_issues_limits);
 
209
#endif 
 
210
   test_issues_limits.rlim_max = RLIM_INFINITY;
 
211
   test_issues_limits.rlim_cur = RLIM_INFINITY;
 
212
#if defined(IRIX)
 
213
   setrlimit64(RLIMIT_DATA, &test_issues_limits);
 
214
#else
 
215
   setrlimit(RLIMIT_DATA, &test_issues_limits);
 
216
#endif
 
217
 
 
218
#if defined(IRIX)
 
219
   getrlimit64(RLIMIT_DATA, &test_issues_limits);
 
220
#else
 
221
   getrlimit(RLIMIT_DATA, &test_issues_limits);
 
222
#endif 
 
223
   printf("data size limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
 
224
 
 
225
 
 
226
#if defined(RLIMIT_RSS)
 
227
#if defined(IRIX)
 
228
   getrlimit64(RLIMIT_RSS, &test_issues_limits);
 
229
#else
 
230
   getrlimit(RLIMIT_RSS, &test_issues_limits);
 
231
#endif 
 
232
   test_issues_limits.rlim_cur = test_issues_limits.rlim_max;
 
233
#if defined(IRIX)
 
234
   setrlimit64(RLIMIT_RSS, &test_issues_limits);
 
235
#else
 
236
   setrlimit(RLIMIT_RSS, &test_issues_limits);
 
237
#endif
 
238
 
 
239
#if defined(IRIX)
 
240
   getrlimit64(RLIMIT_RSS, &test_issues_limits);
 
241
#else
 
242
   getrlimit(RLIMIT_RSS, &test_issues_limits);
 
243
#endif 
 
244
   printf("residet set size limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
 
245
#endif
 
246
 
 
247
 
 
248
#if defined(IRIX)
 
249
   getrlimit64(RLIMIT_FSIZE, &test_issues_limits);
 
250
#else
 
251
   getrlimit(RLIMIT_FSIZE, &test_issues_limits);
 
252
#endif 
 
253
   test_issues_limits.rlim_cur = test_issues_limits.rlim_max;
 
254
#if defined(IRIX)
 
255
   setrlimit64(RLIMIT_FSIZE, &test_issues_limits);
 
256
#else
 
257
   setrlimit(RLIMIT_FSIZE, &test_issues_limits);
 
258
#endif
 
259
 
 
260
#if defined(IRIX)
 
261
   getrlimit64(RLIMIT_FSIZE, &test_issues_limits);
 
262
#else
 
263
   getrlimit(RLIMIT_FSIZE, &test_issues_limits);
 
264
#endif 
 
265
   printf("file size size limit is set to %ld\n", (unsigned long) test_issues_limits.rlim_cur);
 
266
 
 
267
 
 
268
 
 
269
  printf("commlib setup ...\n");
 
270
  /* this is for compiler warning on irix65 */
 
271
 
 
272
  switch(atoi(argv[1])) {
 
273
     case 0:
 
274
        log_level=CL_LOG_OFF;
 
275
        break;
 
276
     case 1:
 
277
        log_level=CL_LOG_ERROR;
 
278
        break;
 
279
     case 2:
 
280
        log_level=CL_LOG_WARNING;
 
281
        break;
 
282
     case 3:
 
283
        log_level=CL_LOG_INFO;
 
284
        break;
 
285
     case 4:
 
286
        log_level=CL_LOG_DEBUG;
 
287
        break;
 
288
     default:
 
289
        log_level=CL_LOG_OFF;
 
290
        break;
 
291
  }
 
292
  cl_com_setup_commlib(CL_RW_THREAD, log_level, NULL);
 
293
 
 
294
  if (server_mode == CL_TRUE) {
 
295
     handle=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_TRUE, com_port, CL_TCP_DEFAULT, "server", 1, 1, 0 );
 
296
     cl_com_set_max_connection_close_mode(handle,CL_ON_MAX_COUNT_DISABLE_ACCEPT);
 
297
  } else {
 
298
     handle=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_FALSE, com_port, CL_TCP_DEFAULT, "client", 0, 1, 0 );
 
299
  }
 
300
  if (handle == NULL) {
 
301
     printf("could not get handle\n");
 
302
     sge_prof_cleanup();
 
303
     exit(-1);
 
304
  }
 
305
 
 
306
  cl_com_get_service_port(handle,&i), 
 
307
  printf("running on host \"%s\", port %d, component name is \"%s\", id is %ld\n", 
 
308
         handle->local->comp_host, 
 
309
         i, 
 
310
         handle->local->comp_name,  
 
311
         handle->local->comp_id);
 
312
 
 
313
  if (server_mode == CL_TRUE) {
 
314
     int actual_issue = 0;
 
315
     int max_con_test_count = 2;
 
316
     unsigned long max_connection_count;
 
317
 
 
318
     while(do_shutdown != 1) {
 
319
        int ret_val;
 
320
 
 
321
        if (actual_issue == 1400) {
 
322
           cl_raw_list_lock(handle->connection_list);
 
323
           printf("actual connection count     = %lu\n", cl_raw_list_get_elem_count(handle->connection_list) );
 
324
           printf("actual max connection count = %lu\n", handle->max_open_connections);
 
325
           if (cl_raw_list_get_elem_count(handle->connection_list) > handle->max_open_connections) {
 
326
              printf("issue 1400 error found\n");
 
327
              main_return = 1;
 
328
           }
 
329
           cl_raw_list_unlock(handle->connection_list);
 
330
        }
 
331
 
 
332
        cl_commlib_trigger(handle, 1); 
 
333
   
 
334
        ret_val = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
 
335
        if (message != NULL) {
 
336
           int do_reply = 1;
 
337
           CL_LOG_STR(CL_LOG_INFO,"received message from",sender->comp_host);
 
338
           if (strstr((char*)message->message,"#1400i") && actual_issue != 1400) {
 
339
              printf("switching to test #1400\n");
 
340
              do_reply = 0;
 
341
              actual_issue = 1400;
 
342
              cl_com_get_max_connections(handle,&max_connection_count);
 
343
              printf("setting max_connection_count from %lu to %lu\n", (unsigned long)max_connection_count, (unsigned long)max_con_test_count);
 
344
              cl_com_set_max_connections(handle,max_con_test_count);
 
345
           } 
 
346
 
 
347
           if (strstr((char*)message->message,"#1400r")) {
 
348
              printf("resetting to defaults\n");
 
349
              do_reply = 0;
 
350
              actual_issue = 0;
 
351
              printf("setting max_connection_count from %lu to %lu\n", (unsigned long)max_con_test_count, (unsigned long)max_connection_count);
 
352
              cl_com_set_max_connections(handle,max_connection_count);
 
353
           } 
 
354
 
 
355
 
 
356
           if (do_reply == 1) {
 
357
              ret_val = cl_commlib_send_message(handle, 
 
358
                                sender->comp_host, 
 
359
                                sender->comp_name, 
 
360
                                sender->comp_id, CL_MIH_MAT_NAK,  
 
361
                                &message->message, 
 
362
                                message->message_length, 
 
363
                                NULL, 0,0, 
 
364
                                CL_FALSE, CL_FALSE);
 
365
              if (ret_val != CL_RETVAL_OK) {
 
366
                 CL_LOG_STR(CL_LOG_ERROR,"cl_commlib_send_message() returned:",cl_get_error_text(ret_val));
 
367
              }
 
368
           }
 
369
           cl_com_free_message(&message);
 
370
           cl_com_free_endpoint(&sender);
 
371
        } 
 
372
     }
 
373
  } else {
 
374
     int ret_val;
 
375
     char* data = NULL;
 
376
     unsigned long data_size = 1024*1024;
 
377
     struct timeval now;
 
378
     struct timeval start;
 
379
     int runtime = 0;
 
380
     char iz1400_data[7] = "#1400i";
 
381
     cl_byte_t* iz1400_pointer = (cl_byte_t *)iz1400_data;
 
382
     char test_data[5] = "test";
 
383
     cl_byte_t* test_pointer = (cl_byte_t *)test_data;
 
384
 
 
385
     printf("\ntesting issue #1389 ...\n");
 
386
 
 
387
 
 
388
     while(runtime < 45 && do_shutdown == 0 && main_return == 0) {
 
389
        data = malloc(data_size * sizeof(char));
 
390
        if (data == NULL) {
 
391
           printf("malloc() error: can't malloc(%ld)\n", data_size * sizeof(char) );
 
392
           printf("issue #1389 failed\n");
 
393
           main_return = 1;
 
394
           break;
 
395
        }
 
396
        printf("malloced %.2f MB\n", (double) (data_size*sizeof(char))/(1024*1024)  );
 
397
   
 
398
        sprintf(data,"hallo du");
 
399
      
 
400
        cl_commlib_send_message(handle, com_host, "server", 1, 
 
401
                            CL_MIH_MAT_NAK, 
 
402
                            (cl_byte_t**)&data, data_size, 
 
403
                            NULL, 0,0, CL_FALSE, CL_FALSE);
 
404
   
 
405
        printf("starting measurement...\n");
 
406
        gettimeofday(&start,NULL);
 
407
        while(do_shutdown == 0 ) {
 
408
           cl_commlib_trigger(handle, 1); 
 
409
           ret_val = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender);
 
410
           if (ret_val != CL_RETVAL_OK && ret_val != CL_RETVAL_NO_MESSAGE) {
 
411
              printf("cl_commlib_receive_message returned: %s\n", cl_get_error_text(ret_val));
 
412
              printf("issue #1389 failed\n");
 
413
              main_return = 1;
 
414
              break;
 
415
           }
 
416
           if (message != NULL) {
 
417
              printf("received response message from %s with size %lu\n", sender->comp_host, message->message_length);
 
418
              message->message = NULL;
 
419
              cl_com_free_message(&message);
 
420
              cl_com_free_endpoint(&sender);
 
421
              break;
 
422
           } 
 
423
        }
 
424
        gettimeofday(&now,NULL);
 
425
        runtime = now.tv_sec - start.tv_sec;
 
426
        printf("send/receive took %d seconds\n", runtime );
 
427
        if (data_size < 30*1024*1024) {
 
428
           data_size = data_size * 2;
 
429
        } else {
 
430
           data_size = data_size + 16*1024*1024;
 
431
        }
 
432
     }
 
433
 
 
434
     
 
435
     printf("\ntesting issue #1400 ...\n");
 
436
     {
 
437
 
 
438
        printf("setting up server for test 1400 ...\n");
 
439
        cl_commlib_send_message(handle, com_host, "server", 1, 
 
440
                               CL_MIH_MAT_ACK, 
 
441
                               &iz1400_pointer, 7, 
 
442
                               NULL, 0,0, CL_TRUE, CL_TRUE);
 
443
      }
 
444
 
 
445
     printf("creating new connections ...\n");
 
446
 
 
447
     handle1=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_FALSE, com_port, CL_TCP_DEFAULT, "client1", 0, 1, 0 );
 
448
     handle2=cl_com_create_handle(NULL, framework, CL_CM_CT_MESSAGE, CL_FALSE, com_port, CL_TCP_DEFAULT, "client2", 0, 1, 0 );
 
449
 
 
450
     printf("sending via connection 1 ...\n");
 
451
     cl_commlib_send_message(handle, com_host, "server", 1, 
 
452
                            CL_MIH_MAT_ACK, 
 
453
                            &test_pointer, 5, 
 
454
                            NULL, 0,0, CL_TRUE, CL_TRUE);
 
455
 
 
456
     printf("sending via connection 2 ...\n");
 
457
     cl_commlib_send_message(handle1, com_host, "server", 1, 
 
458
                            CL_MIH_MAT_ACK, 
 
459
                            &test_pointer, 5, 
 
460
                            NULL, 0,0, CL_TRUE, CL_TRUE);
 
461
 
 
462
     printf("sending via connection 3 ...\n");
 
463
     ret_val = cl_commlib_send_message(handle2, com_host, "server", 1, 
 
464
                            CL_MIH_MAT_ACK, 
 
465
                            &test_pointer, 5, 
 
466
                            NULL, 0,0, CL_TRUE, CL_TRUE);
 
467
 
 
468
     if (ret_val == CL_RETVAL_OK) {
 
469
        printf("issue #1400 failed\n");
 
470
        main_return = 2;
 
471
     } else {
 
472
        printf("3. connection send returned: \"%s\" and failed - ok\n" , cl_get_error_text(ret_val));
 
473
     }
 
474
 
 
475
     printf("resetting server ...\n");
 
476
 
 
477
     iz1400_data[5] = 'r';
 
478
     cl_commlib_send_message(handle, com_host, "server", 1, 
 
479
                            CL_MIH_MAT_ACK, 
 
480
                            &iz1400_pointer, 7, 
 
481
                            NULL, 0,0, CL_TRUE, CL_TRUE);
 
482
 
 
483
 
 
484
  }
 
485
 
 
486
  printf("shutting down ...\n");
 
487
  cl_commlib_shutdown_handle(handle, CL_FALSE);
 
488
 
 
489
  printf("commlib cleanup ...\n");
 
490
  cl_com_cleanup_commlib();
 
491
  
 
492
  printf("main done\n");
 
493
  return main_return;
 
494
}
 
495
 
 
496
 
 
497
 
 
498
 
 
499