1 j.alex 1.2 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 j.alex 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Melvin, IBM (msolomon@in.ibm.com) for PEP# 241
33 //
34 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include "../TestStressTestClient.h"
39
40 PEGASUS_USING_PEGASUS;
41 PEGASUS_USING_STD;
42
43 j.alex 1.2 class TestWrapperStressClient : public TestStressTestClient
44 {
45 };
46
47 Boolean quit = false;
48 Boolean nextCheck = false;
49 String errorInfo;
50 char thisClient[] = "WrapperStressClient";
51
52 /**
53 Signal handler for SIGALARM.
54 @param signum - the alarm identifier
55 */
56 void endTest(int signum)
57 {
58 cout<<"Recieved interupt signal SIGINT!\n"<<endl;
59 quit = true;
60 }
61
62 /**
63 MAIN
64 j.alex 1.2 */
65 int main(int argc, char** argv)
66 {
67 OptionManager om;
68 TestWrapperStressClient wc;
69 pid_t clientPid = getpid();
70 Uint32 validArg = 0;
71 Boolean verboseTest;
72
73 //
74 // Varriables needed for loging and status checking.
75 //
76 String clientId;
77 String pidFile;
78 String clientLog, stopClient;
79 char pid_str[15];
80 int status = CLIENT_UNKNOWN;
81
82 //
83 // Number of times the client command succeeded.
84 //
85 j.alex 1.2 Uint32 successCount = 0;
86
87 //
88 // Number of iterations after which logErrorPercentage() is called.
89 //
90 Uint32 iteration = 0;
91
92 //
93 // Total number of times the client command was executed.
94 //
95 Uint32 totalCount = 0;
96
97 //
98 // Variables needed for Command operation.
99 //
100 String command;
101
102 String options;
103 String help;
104
105 try
106 j.alex 1.2 {
107 struct OptionRow *newOptionsTable = 0;
108 Uint32 newOptionsCount;
109
110 struct OptionRow cOptionTable[] =
111 {
112 {"clientname", "", true, Option::STRING, 0, 0, "clientname",
113 "Client name" },
114
115 {"options", "", true, Option::STRING, 0, 0, "options",
116 "Corresponding Client program's options" }
117 };
118
119 Uint32 cOptionCount = sizeof(cOptionTable) / sizeof(cOptionTable[0]);
120 newOptionsCount = cOptionCount;
121
122 try
123 {
124 //
125 // Generate new option table for this client using OptionManager
126 //
127 j.alex 1.2 newOptionsTable = wc.generateClientOptions(
128 cOptionTable,
129 cOptionCount,
130 newOptionsCount);
131 validArg = wc.GetOptions(
132 om,
133 argc,
134 argv,
135 newOptionsTable,
136 newOptionsCount);
137 }
138 catch (Exception& e)
139 {
140 cerr << argv[0] << ": " << e.getMessage() << endl;
141 exit(1);
142 }
143 catch (...)
144 {
145 cerr << argv[0] << ": Error in Options operations "<< endl;
146 exit(1);
147 }
148 j.alex 1.2
149 verboseTest = om.isTrue("verbose");
150
151 om.lookupValue("clientid", clientId);
152
153 om.lookupValue("pidfile", pidFile);
154
155 om.lookupValue("clientlog", clientLog);
156
157 om.lookupValue("clientname", command);
158
159 om.lookupValue("options", options);
160
161 om.lookupValue("help", help);
162 } /** end of option Try block. */
163 catch (Exception& e)
164 {
165 cerr << argv[0] << ": " << e.getMessage() <<endl;
166 exit(1);
167 }
168 catch (...)
169 j.alex 1.2 {
170 cerr << argv[0] << ": Unknown Error gathering options "
171 << "in Wrapper Client " << endl;
172 exit(1);
173 }
174
175 /** Checking whether the user asked for HELP Info...
176 if (om.valueEquals("help", "true"))
177 {
178 String header = "Usage ";
179 header.append(argv[0]);
180 header.append(" -parameters -clientName [clientName]
181 header.append(" -options [options] -clientid [clientId] ");
182 header.append(" -pidfile [pidFile] -clientlog [clientLog]");
183 String trailer = "Assumes localhost:5988 if host not specified";
184 trailer.append("\nHost may be of the form name or name:port");
185 trailer.append("\nPort 5988 assumed if port number missing.");
186 om.printOptionsHelpTxt(header, trailer);
187 exit(0);
188 }
189 */
190 j.alex 1.2
191 try
192 {
193 if (options.getCString())
194 {
195 command.append(" " + options);
196 }
197 if (verboseTest)
198 {
199 errorInfo.append("client command : ");
200 errorInfo.append(command);
201 wc.errorLog(clientPid, clientLog, errorInfo);
202 errorInfo.clear();
203 }
204
205 //
206 // Signal Handling - SIGINT.
207 //
208 signal(SIGINT, endTest);
209
210 //
211 j.alex 1.2 // Timer Start.
212 //
213 wc.startTime();
214
215 wc.logInfo(clientId, clientPid, status, pidFile);
216 sprintf(pid_str, "%d", clientPid);
217
218 stopClient = String::EMPTY;
219 stopClient.append(FileSystem::extractFilePath(pidFile));
220 stopClient.append("STOP_");
221 stopClient.append(pid_str);
222
223 //
224 // This loop executes till the client gets stop signal from
225 // controller.
226 //
227 while (!quit)
228 {
229 if (FileSystem::exists(stopClient))
230 {
231 if (verboseTest)
232 j.alex 1.2 {
233 String mes("Ending client. ");
234 wc.errorLog(clientPid, clientLog, mes);
235 }
236 break;
237 }
238
239 if (!verboseTest)
240 {
241 #ifdef PEGASUS_OS_TYPE_WINDOWS
242 freopen("nul","w",stdout);
243 #else
244 freopen("/dev/null","w",stdout);
245 #endif
246 }
247
248 int i = system(command.getCString());
249
250 iteration++;
251 totalCount++;
252 switch (i)
253 j.alex 1.2 {
254 case 0:
255 if (status != CLIENT_PASS)
256 {
257 status = CLIENT_PASS;
258 wc.logInfo(clientId, clientPid, status, pidFile);
259 }
260 successCount++;
261 break;
262
263 case 1:
264 status = CLIENT_UNKNOWN;
265 wc.logInfo(clientId, clientPid, status, pidFile);
266 break;
267
268 default:
269 status = CLIENT_FAIL;
270 wc.logInfo(clientId, clientPid, status, pidFile);
271 break;
272 }
273
274 j.alex 1.2 nextCheck = wc.checkTime();
275 if (nextCheck)
276 {
277 wc.logInfo(clientId, clientPid, status, pidFile);
278 nextCheck = false;
279 }
280
281 //
282 // If verbose is set, log success percentage for every 100
283 // iterations. If verbose is not set, log success percentage
284 // for every 1000 iterations.
285 //
286 if (verboseTest)
287 {
288 if (iteration == 100)
289 {
290 wc.logErrorPercentage(
291 successCount,
292 totalCount,
293 clientPid,
294 clientLog,
295 j.alex 1.2 thisClient);
296 iteration = 0;
297 }
298 }
299 else
300 {
301 if (iteration == 1000)
302 {
303 wc.logErrorPercentage(
304 successCount,
305 totalCount,
306 clientPid,
307 clientLog,
308 thisClient);
309 iteration = 0;
310 }
311 }
312 } /** end of while(!quit). */
313 } /** end of command execution try block. */
314 catch (Exception &exp)
315 {
316 j.alex 1.2 String expStr("Exception in WrapperClient causing it to exit: ");
317 expStr.append(exp.getMessage());
318 wc.errorLog(clientPid, clientLog, expStr);
319
320 if (verboseTest)
321 {
322 cerr << expStr.getCString() << endl;
323 }
324 }
325 catch (...)
326 {
327 String expStr("General Exception in WrapperClient causing it to exit");
328 wc.errorLog(clientPid, clientLog, expStr);
329
330 if (verboseTest)
331 {
332 cerr << expStr.getCString() << endl;
333 }
334 }
335
336 //
337 j.alex 1.2 // second delay before shutdown.
338 //
339 #ifndef PEGASUS_OS_TYPE_WINDOWS
340 sleep(1);
341 #else
342 Sleep(1000);
343 #endif
344
345 if(FileSystem::exists(stopClient))
346 {
347 //
348 // Remove STOP file here.
349 //
350 FileSystem::removeFile(stopClient);
351 }
352 if (verboseTest)
353 {
354 errorInfo.append(
355 "++++ TestWrapperStressClient Terminated Normally +++++");
356 wc.errorLog(clientPid, clientLog, errorInfo);
357 errorInfo.clear();
358 j.alex 1.2 }
359 return 0;
360 }
|