Debian Codegraph @

test/dapltest/cmd/dapl_fft_cmd.c

raw
1 /*
2 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
3 *
4 * This Software is licensed under one of the following licenses:
5 *
6 * 1) under the terms of the "Common Public License 1.0" a copy of which is
7 * in the file LICENSE.txt in the root directory. The license is also
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is in the file
12 * LICENSE2.txt in the root directory. The license is also available from
13 * the Open Source Initiative, see
14 * http://www.opensource.org/licenses/bsd-license.php.
15 *
16 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
17 * copy of which is in the file LICENSE3.txt in the root directory. The
18 * license is also available from the Open Source Initiative, see
19 * http://www.opensource.org/licenses/gpl-license.php.
20 *
21 * Licensee has the right to choose one of the above licenses.
22 *
23 * Redistributions of source code must retain the above copyright
24 * notice and one of the license notices.
25 *
26 * Redistributions in binary form must reproduce both the above copyright
27 * notice, one of the license notices in the documentation
28 * and/or other materials provided with the distribution.
29 */
30
31 #include "dapl_proto.h"
32
33 //---------------------------------------------------------------------------
34 void DT_FFT_Cmd_Init(FFT_Cmd_t * cmd)
35 {
36 int i;
37 memset((void *)cmd, 0, sizeof(FFT_Cmd_t));
38 cmd->fft_type = NONE;
39 cmd->device_name[0] = '\0';
40 cmd->server_name[0] = '\0';
41 for (i = 0; i < MAXCASES; i++) {
42 cmd->cases_flag[i] = false;
43 }
44 cmd->size = 0;
45 cmd->num_iter = 1000;
46 cmd->num_threads = 10;
47 cmd->num_vis = 500;
48 cmd->port = SERVER_PORT_NUMBER;
49 cmd->ReliabilityLevel = DAT_QOS_BEST_EFFORT;
50 }
51
52 //------------------------------------------------------------------------------
53 bool DT_FFT_Cmd_Parse(FFT_Cmd_t * cmd,
54 int my_argc, char **my_argv, mygetopt_t * opts)
55 {
56 int c;
57 int i, caseNum;
58 unsigned int len;
59
60 for (;;) {
61 c = DT_mygetopt_r(my_argc, my_argv, "D:f:s:i:t:v:R:n:", opts);
62 if (c == EOF) {
63 break;
64 }
65 switch (c) {
66 case 'D': //device name
67 {
68 strcpy(cmd->device_name, opts->optarg);
69 break;
70 }
71 case 's': //server name
72 {
73 strcpy(cmd->server_name, opts->optarg);
74 break;
75 }
76 case 'i': // num iterations
77 {
78 len = strspn(opts->optarg, "0123456789");
79 if (len == 0 || len != strlen(opts->optarg)) {
80 DT_Mdep_printf
81 ("Syntax Error -i<iterations> option\n");
82 DT_FFT_Cmd_Usage();
83 return (false);
84 }
85 cmd->num_iter = atoi(opts->optarg);
86 break;
87 }
88 case 't': // num threads
89 {
90 len = strspn(opts->optarg, "0123456789");
91 if (len == 0 || len != strlen(opts->optarg)) {
92 DT_Mdep_printf
93 ("Syntax Error -t<num_threads> option\n");
94 DT_FFT_Cmd_Usage();
95 return (false);
96 }
97 cmd->num_threads = atoi(opts->optarg);
98 break;
99 }
100 case 'v': // num vis
101 {
102 len = strspn(opts->optarg, "0123456789");
103 if (len == 0 || len != strlen(opts->optarg)) {
104 DT_Mdep_printf
105 ("Syntax Error -v<num_vis> option\n");
106 DT_FFT_Cmd_Usage();
107 return (false);
108 }
109 cmd->num_vis = atoi(opts->optarg);
110 break;
111 }
112 case 'f': //function feature
113 {
114 if (strcmp(opts->optarg, "hwconn") == 0) {
115 cmd->fft_type = HWCONN;
116 cmd->size = 4; //4 cases for hwconn
117 break;
118 }
119 #if 0 // not yet implemented
120 else if (strcmp(opts->optarg, "cqmgt") == 0) {
121 cmd->fft_type = CQMGT;
122 cmd->size = 10; //10 cases for cqmgt
123 break;
124 }
125 #endif
126 else if (strcmp(opts->optarg, "endpoint") == 0) {
127 cmd->fft_type = ENDPOINT;
128 cmd->size = 3; //13 cases for endpoint
129 break;
130 } else if (strcmp(opts->optarg, "pz") == 0) {
131 cmd->fft_type = PTAGMGT;
132 cmd->size = 3; //10 cases for Ptagmgt
133 break;
134 } else if (strcmp(opts->optarg, "mem") == 0) {
135 cmd->fft_type = MEMMGT;
136 cmd->size = 5; //12 cases for Memmgt
137 break;
138 } else if (strcmp(opts->optarg, "connmgt") == 0) {
139 cmd->fft_type = CONNMGT;
140 cmd->size = 2; //16 cases for connmgt
141 break;
142 }
143 #if 0 // not yet implemented
144 else if (strcmp(opts->optarg, "connmgt_client")
145 == 0) {
146 cmd->fft_type = CONNMGT_CLIENT;
147 cmd->size = 16; //16 cases for connmgt_client
148 break;
149 }
150 #endif
151 else if (strcmp(opts->optarg, "queryinfo") == 0) {
152 cmd->fft_type = QUERYINFO;
153 #ifndef __KDAPLTEST__
154 cmd->size = 18; //18 cases for UDAPL queryinfo
155 #else
156 cmd->size = 16; //16 cases for KDAPL queryinfo
157 #endif
158 break;
159 }
160 #if 0 // not yet implemented
161 else if (strcmp(opts->optarg, "ns") == 0) {
162 cmd->fft_type = NS;
163 cmd->size = 10; //10 cases for ns
164 break;
165 } else if (strcmp(opts->optarg, "errhand") == 0) {
166 cmd->fft_type = ERRHAND;
167 cmd->size = 2; //2 cases for errhand
168 break;
169 } else if (strcmp(opts->optarg, "unsupp") == 0) {
170 cmd->fft_type = UNSUPP;
171 cmd->size = 2; //2 cases for unsupp
172 break;
173 } else if (strcmp(opts->optarg, "stress") == 0) {
174 cmd->fft_type = STRESS;
175 cmd->size = 6; //6 cases for stress
176 break;
177 } else if (strcmp(opts->optarg, "stress_client")
178 == 0) {
179 cmd->fft_type = STRESS_CLIENT;
180 cmd->size = 6; //6 cases for stress_client
181 break;
182 }
183 #endif
184 else {
185 DT_Mdep_printf
186 ("don't know this function feature: %s\n",
187 opts->optarg);
188 DT_FFT_Cmd_Usage();
189 return (false);
190 }
191 }
192 case 'R': // Service Reliability Level
193 {
194 cmd->ReliabilityLevel =
195 DT_ParseQoS(opts->optarg);
196 if (0 == cmd->ReliabilityLevel) {
197 DT_Mdep_printf
198 ("Invalid FFT Test Parameter: %c\n",
199 c);
200 DT_FFT_Cmd_Usage();
201 return (false);
202 }
203 break;
204 }
205 case 'n':
206 {
207 cmd->port = atoi(opts->optarg);
208 break;
209 }
210 case '?':
211 default:
212 {
213 DT_Mdep_printf
214 ("Invalid FFT Test Parameter: %c\n", c);
215 DT_FFT_Cmd_Usage();
216 return (false);
217 }
218 }
219 }
220 if (cmd->device_name[0] == '\0') {
221 if (!DT_Mdep_GetDefaultDeviceName(cmd->device_name)) {
222 DT_Mdep_printf("can't get default device name\n");
223 DT_FFT_Cmd_Usage();
224 return (false);
225 }
226 }
227
228 if (cmd->fft_type == NONE) {
229 DT_Mdep_printf
230 ("must define the function feature with -f to test\n");
231 DT_FFT_Cmd_Usage();
232 return (false);
233 }
234 if (cmd->server_name[0] == '\0' &&
235 (cmd->fft_type == CONNMGT_CLIENT || cmd->fft_type == DATAXFER_CLIENT
236 || cmd->fft_type == UNSUPP || cmd->fft_type == STRESS_CLIENT)) {
237 DT_Mdep_printf("must define the server name with -s option\n");
238 DT_FFT_Cmd_Usage();
239 return (false);
240 }
241
242 if (cmd->server_name[0] == '\0' && cmd->fft_type == NS) {
243 DT_Mdep_printf("\
244 Must specify host name or host IP address with -s option to be tested\n");
245 DT_FFT_Cmd_Usage();
246 return (false);
247 }
248 //now parse the test cases
249 if (opts->optind == my_argc) //default: test all cases
250 {
251 for (i = 0; i < cmd->size; i++) {
252 cmd->cases_flag[i] = true;
253 }
254 return true;
255 }
256 //test specified cases
257 i = opts->optind;
258 while (i < my_argc) {
259 if (strlen(my_argv[i]) < 5
260 || strncmp(my_argv[i], "case", 4) != 0) {
261 DT_Mdep_printf("test cases format is not correct: %s\n",
262 my_argv[i]);
263 DT_FFT_Cmd_Usage();
264 return (false);
265 }
266 len = strspn(my_argv[i] + 4, "0123456789");
267 if (len == 0 || len != strlen(my_argv[i] + 4)) {
268 DT_Mdep_printf("must specify case number: %s\n",
269 my_argv[i]);
270 DT_FFT_Cmd_Usage();
271 return (false);
272 }
273 caseNum = atoi(my_argv[i] + 4);
274 if (caseNum < 0 || caseNum >= cmd->size) {
275 DT_Mdep_printf
276 ("test case number must be within range : 0 -- %d\n",
277 cmd->size - 1);
278 DT_FFT_Cmd_Usage();
279 return (false);
280 }
281 cmd->cases_flag[caseNum] = true;
282 i++;
283 }
284 return (true);
285 }
286
287 //--------------------------------------------------------------
288 void DT_FFT_Cmd_Usage(void)
289 {
290 char usage[] = {
291 "dapltest -T F [-D <dev_name>] -f <funcfeature> [-i <iter_num>] \n"
292 "[-t <num_threads>] [-v <num_vis>] [-s <server_name>] [case0] [case1] [...]\n"
293 "USAGE: [-D <device Name>]\n"
294 "USAGE: [-n <server port number>]\n"
295 "USAGE: -f <func_feature>\n"
296 "USAGE: hwconn\n"
297 "USAGE: endpoint\n"
298 "USAGE: pz\n"
299 "USAGE: mem\n"
300 "USAGE: connmgt\n"
301 "USAGE: queryinfo\n"
302 #if 0 // not yet implemented
303 "USAGE: connmgt_client (not yet implemented)\n"
304 "USAGE: cqmgt (not yet implemented)\n"
305 "USAGE: ns (not yet implemented)\n"
306 "USAGE: errhand (not yet implemented)\n"
307 "USAGE: unsupp (not yet implemented)\n"
308 "USAGE: stress (not yet implemented)\n"
309 "USAGE: stress_client (not yet implemented)\n"
310 #endif
311 "USAGE: -i <iter_num>: itreration time for stress test\n"
312 "USAGE: -t <num_threads>: number of threads for stress test\n"
313 "USAGE: -v <num_vis>: number of vis for stress test\n"
314 "USAGE: -s <server_name>\n"
315 "USAGE: server host name or ip address\n"
316 "USAGE: [-R <service reliability>]\n"
317 "USAGE: (BE == QOS_BEST_EFFORT - Default )\n"
318 "USAGE: (HT == QOS_HIGH_THROUGHPUT))\n"
319 "USAGE: (LL == QOS_LOW_LATENCY)\n"
320 "USAGE: (EC == QOS_ECONOMY)\n"
321 "USAGE: (PM == QOS_PREMIUM)\n"
322 "NOTE: iter_num is just for stress_client test, default 100000\n"
323 "NOTE: Server_name must be specified for connmgt_client, \n"
324 " NS and unsupp function feature.\n"
325 "NOTE: if test cases are not specified, test all cases in that function\n"
326 " feature. else just test the specified cases\n"
327 };
328
329 DT_Mdep_printf("USAGE: -------FFT TEST------------\n");
330 DT_Mdep_printf("%s\n", usage);
331 }