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

« back to all changes in this revision

Viewing changes to source/libs/comm/test_virtual_gdi_client.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
 
 
34
#include <stdio.h>
 
35
#include <string.h>
 
36
#include <sys/time.h>
 
37
#include <stdlib.h>
 
38
#include <signal.h>
 
39
#include <unistd.h>
 
40
 
 
41
#include "cl_lists.h"
 
42
#include "cl_commlib.h"
 
43
 
 
44
#include "uti/sge_profiling.h"
 
45
 
 
46
/* shutdown when test client can't connect for more than 15 min */
 
47
#define SGE_TEST_VIRTUAL_CLIENT_SHUTDOWN_TIMEOUT 15*60
 
48
#define DATA_SIZE 5000
 
49
#define PACKAGE_COUNTER
 
50
 
 
51
/* counters */
 
52
static int rcv_messages = 0;
 
53
static int snd_messages = 0;
 
54
 
 
55
void sighandler_client(int sig);
 
56
static int do_shutdown = 0;
 
57
 
 
58
static cl_com_handle_t* handle = NULL; 
 
59
 
 
60
void sighandler_client(
 
61
int sig 
 
62
) {
 
63
/*   thread_signal_receiver = pthread_self(); */
 
64
   if (sig == SIGPIPE) {
 
65
      return;
 
66
   }
 
67
 
 
68
   if (sig == SIGHUP) {
 
69
      return;
 
70
   }
 
71
   printf("do_shutdown\n");
 
72
   /* shutdown all sockets */
 
73
   do_shutdown = 1;
 
74
}
 
75
 
 
76
 
 
77
 
 
78
 
 
79
#ifdef __CL_FUNCTION__
 
80
#undef __CL_FUNCTION__
 
81
#endif
 
82
#define __CL_FUNCTION__ "main()"
 
83
extern int main(int argc, char** argv)
 
84
{
 
85
  struct sigaction sa;
 
86
  
 
87
  struct timeval now;
 
88
  time_t shutdown_time = 0;
 
89
  time_t last_time = 0;
 
90
  int no_output = 0;
 
91
  int reconnect = 0;
 
92
#ifndef PACKAGE_COUNTER
 
93
  char data[DATA_SIZE] = "gdi request";
 
94
#endif
 
95
 
 
96
  cl_xml_ack_type_t ack_type = CL_MIH_MAT_NAK;
 
97
  cl_bool_t synchron = CL_FALSE;
 
98
 
 
99
  prof_mt_init();
 
100
 
 
101
  if (argc < 5) {
 
102
      printf("syntax: debug_level vmaster_port vmaster_host reconnect [no_output]\n");
 
103
      exit(1);
 
104
  }
 
105
 
 
106
  if (argc >= 6) {
 
107
     if (strcmp(argv[5],"no_output") == 0) {
 
108
        no_output = 1;
 
109
        printf("virtual gdi client: no_output option set\n");
 
110
     }
 
111
  }
 
112
 
 
113
  reconnect = atoi(argv[4]);
 
114
 
 
115
  if (reconnect == 1) {
 
116
   /* do all stuff synchron */
 
117
      ack_type = CL_MIH_MAT_ACK;
 
118
      synchron = CL_TRUE; 
 
119
  }
 
120
 
 
121
  /* setup signalhandling */
 
122
  memset(&sa, 0, sizeof(sa));
 
123
  sa.sa_handler = sighandler_client;  /* one handler for all signals */
 
124
  sigemptyset(&sa.sa_mask);
 
125
  sigaction(SIGINT, &sa, NULL);
 
126
  sigaction(SIGTERM, &sa, NULL);
 
127
  sigaction(SIGHUP, &sa, NULL);
 
128
  sigaction(SIGPIPE, &sa, NULL);
 
129
 
 
130
  gettimeofday(&now, NULL);
 
131
  shutdown_time = now.tv_sec + SGE_TEST_VIRTUAL_CLIENT_SHUTDOWN_TIMEOUT;
 
132
 
 
133
  printf("virtual gdi client is connecting to the virtual qmaster for each request.\n"); 
 
134
 
 
135
  cl_com_setup_commlib(CL_NO_THREAD , (cl_log_t)atoi(argv[1]), NULL );
 
136
 
 
137
  while (do_shutdown == 0) {
 
138
     char *snd_data = NULL;
 
139
     gettimeofday(&now, NULL);
 
140
 
 
141
     if (now.tv_sec > shutdown_time ) {
 
142
        printf("shutting down test - timeout\n");
 
143
        do_shutdown = 1;
 
144
     }
 
145
 
 
146
     cl_com_setup_commlib(CL_NO_THREAD , (cl_log_t)atoi(argv[1]), NULL);
 
147
   
 
148
     handle = cl_com_create_handle(NULL, CL_CT_TCP, CL_CM_CT_MESSAGE, CL_FALSE, atoi(argv[2]), CL_TCP_DEFAULT, "virtual_gdi_client", 0, 1, 0);
 
149
     if (handle == NULL) {
 
150
        printf("could not get handle\n");
 
151
        exit(1);
 
152
     }
 
153
 
 
154
#if 0
 
155
     printf("local hostname is \"%s\"\n", handle->local->comp_host);
 
156
     printf("local component is \"%s\"\n", handle->local->comp_name);
 
157
     printf("local component id is \"%ld\"\n", handle->local->comp_id);
 
158
#endif
 
159
   
 
160
#if 0
 
161
     {
 
162
        int i;
 
163
        cl_com_get_connect_port(handle, &i);
 
164
        printf("connecting to port \"%d\" on host \"%s\"\n", i, argv[3]);
 
165
     }
 
166
#endif
 
167
   
 
168
     while (do_shutdown == 0) {
 
169
        int                retval  = 0;
 
170
        cl_com_message_t*  message = NULL;
 
171
        cl_com_endpoint_t* sender  = NULL;
 
172
        if (snd_data == NULL) {
 
173
           snd_data = malloc(DATA_SIZE);
 
174
#ifdef PACKAGE_COUNTER
 
175
           sprintf(snd_data, "%d\n", snd_messages);
 
176
#else
 
177
           memcpy(snd_data, data, DATA_SIZE);
 
178
#endif
 
179
        }
 
180
#ifdef PACKAGE_COUNTER
 
181
        else {
 
182
           sprintf(snd_data, "%d\n", snd_messages);
 
183
        }
 
184
#endif
 
185
   
 
186
        gettimeofday(&now,NULL);
 
187
        if (now.tv_sec > shutdown_time ) {
 
188
           printf("shutting down test - timeout\n");
 
189
           do_shutdown = 1;
 
190
        }
 
191
 
 
192
        retval = cl_commlib_send_message(handle, argv[3], "virtual_master", 1,
 
193
                                         ack_type,
 
194
                                         (cl_byte_t**)(&snd_data), DATA_SIZE,
 
195
                                         NULL, 0, 0 , CL_FALSE, synchron);
 
196
        if (retval == CL_RETVAL_OK) {
 
197
           snd_messages++;
 
198
           retval = cl_commlib_receive_message(handle, NULL, NULL, 0,  /* handle, comp_host, comp_name , comp_id, */
 
199
                                               CL_TRUE, 0,                   /* syncron, response_mid */
 
200
                                               &message, &sender);
 
201
           if (retval == CL_RETVAL_OK) {
 
202
                 gettimeofday(&now,NULL);
 
203
                 shutdown_time = now.tv_sec + SGE_TEST_VIRTUAL_CLIENT_SHUTDOWN_TIMEOUT;
 
204
 
 
205
                 snd_data = (char*)message->message;
 
206
                 message->message = NULL;
 
207
 
 
208
#ifdef PACKAGE_COUNTER
 
209
                 if (atoi(snd_data) != rcv_messages) {
 
210
                    printf("!!!! %d. message was lost, got %s\n", rcv_messages, snd_data);
 
211
                    do_shutdown = 1;
 
212
                 }
 
213
#endif
 
214
 
 
215
                 if (now.tv_sec != last_time && !no_output) {
 
216
                    printf("virtual gdi client message count[received |%d| / sent |%d|]...\n", rcv_messages, snd_messages);
 
217
                    last_time = now.tv_sec;
 
218
                 }
 
219
                 
 
220
                 rcv_messages++;
 
221
                 cl_com_free_message(&message);
 
222
                 cl_com_free_endpoint(&sender);
 
223
           } else {
 
224
              /* shutdown when virtual qmaster is not running anymore */
 
225
              if (rcv_messages > 0) {
 
226
                 printf("cl_commlib_receive_message returned: %s\n", cl_get_error_text(retval));
 
227
                 do_shutdown = 1;
 
228
              } else {
 
229
                /* we are not connected, sleep one second */
 
230
                snd_messages = 0;
 
231
                sleep(1);
 
232
              }
 
233
           }
 
234
        } else {
 
235
           /* shutdown when virtual qmaster is not running anymore */
 
236
           if (rcv_messages > 0) {
 
237
              printf("cl_commlib_send_message returned: %s\n", cl_get_error_text(retval));
 
238
              do_shutdown = 1;
 
239
           }
 
240
        } 
 
241
        if (reconnect == 1) {
 
242
            break;
 
243
        }
 
244
     }
 
245
     cl_commlib_shutdown_handle(handle, CL_FALSE);
 
246
  }
 
247
  cl_com_cleanup_commlib();
 
248
  
 
249
  printf("main done\n");
 
250
  return 0;
 
251
}
 
252