#include "rcs.hh"
#include "nmldiag.hh"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for nmltest.cc:
Go to the source code of this file.
Enumerations | |
enum | LOCAL_CONNECT { LC_NOT_ATTEMPTED = 0, LC_FAILED, LC_SUCCEEDED } |
enum | REMOTE_CONNECT { RC_NOT_ATTEMPTED = 0, RC_FAILED, RC_SUCCEEDED } |
Functions | |
int | nmltest_format (NMLTYPE type, void *buffer, CMS *cms) |
void | clean_string (char *str, int len) |
int | main (int argc, char **argv) |
Variables | |
char | program_id [] = "nmltest version 3.0 compiled on " __DATE__ |
char | LC_ARRAY [3][3] = { "NA", "F", "S" } |
char | RC_ARRAY [3][3] = { "NA", "F", "S" } |
|
Definition at line 23 of file nmltest.cc. 00024 { 00025 LC_NOT_ATTEMPTED = 0, 00026 LC_FAILED, 00027 LC_SUCCEEDED, 00028 }; |
|
Definition at line 32 of file nmltest.cc. 00033 { 00034 00035 00036 RC_NOT_ATTEMPTED = 0, 00037 RC_FAILED, 00038 RC_SUCCEEDED, 00039 }; |
|
Definition at line 44 of file nmltest.cc. 00045 { 00046 rcs_print ("nmltest_format called.\n"); 00047 return (0); 00048 } |
|
Definition at line 51 of file nmltest.cc. 00052 { 00053 if (NULL == str) 00054 { 00055 return; 00056 } 00057 if (len > 1024) 00058 { 00059 return; 00060 } 00061 str[len - 1] = 0; 00062 char *temp = (char *) malloc (len); 00063 memset (temp, 0, len); 00064 char *t = temp; 00065 char *s = str; 00066 char c = *s; 00067 while (c != 0) 00068 { 00069 if (c != ' ' && c != '\t' && c != '\r' && c != '\n') 00070 { 00071 *t = c; 00072 t++; 00073 } 00074 s++; 00075 c = *s; 00076 } 00077 strcpy (str, temp); 00078 free (temp); 00079 } |
|
Definition at line 101 of file nmltest.cc. 00103 { 00104 INET_FILE *fp; 00105 LOCAL_CONNECT local_connect_status = LC_NOT_ATTEMPTED; 00106 REMOTE_CONNECT remote_connect_status = RC_NOT_ATTEMPTED; 00107 char proc_line[CMS_CONFIG_LINELEN]; 00108 char line[CMS_CONFIG_LINELEN]; 00109 char output_line[80]; 00110 char buffer_name[CMS_CONFIG_LINELEN]; 00111 char buffer_host[CMS_CONFIG_LINELEN]; 00112 NMLTYPE lc_msg_type = 0; 00113 NMLTYPE rc_msg_type = 0; 00114 int msg_size = 0; 00115 int line_len, line_number = 0; 00116 RCS_LINKED_LIST *output_list; 00117 00118 /* Print the program name and version info. */ 00119 rcs_print ("\n***** NML Test Program **************************\n"); 00120 rcs_print (" This program can be used to test whether all buffers\n"); 00121 rcs_print (" in a configuration file can be connected to or it can test\n"); 00122 rcs_print (" only one buffer/process connection.\n"); 00123 rcs_print 00124 (" It is best to use a version of nmltest using the same version\n"); 00125 rcs_print (" of the RCS library your application(s) use.\n"); 00126 rcs_print ("Just press enter when prompted to accept default.\n"); 00127 print_rcs_version (); 00128 puts (program_id); 00129 rcs_print ("\n\n"); 00130 00131 00132 output_list = new RCS_LINKED_LIST; 00133 if (NULL == output_list) 00134 { 00135 printf ("Couldn`t malloc output list.\n"); 00136 exit (-1); 00137 } 00138 00139 set_rcs_print_destination (RCS_PRINT_TO_STDOUT); 00140 #ifndef VXWORKS 00141 char config_file[80]; 00142 strcpy (config_file, "UNDEFINED"); 00143 char host_name[80]; 00144 strcpy (host_name, "UNDEFINED"); 00145 int master = -1; 00146 int wait_for_read = -1; 00147 int test_all = -1; 00148 int show_diag_info = -1; 00149 int use_passwd = 0; 00150 if (argc > 4) 00151 { 00152 /* Get host_name and config_file from command line */ 00153 strcpy (config_file, argv[1]); 00154 strcpy (host_name, argv[2]); 00155 master = (argv[3][0] == 'y' || argv[3][0] == 'Y'); 00156 wait_for_read = (argv[4][0] == 'y' || argv[4][0] == 'Y'); 00157 } 00158 #endif 00159 00160 /* Prompt user for config_file and host name */ 00161 #ifdef VXWORKS 00162 if (NULL == config_file) 00163 { 00164 config_file = (char *) malloc (80); 00165 printf ("Configuration File? "); 00166 fgets (config_file, 80, stdin); 00167 } 00168 #else 00169 if (!strcmp (config_file, "UNDEFINED")) 00170 { 00171 printf ("Configuration File? "); 00172 fgets (config_file, 80, stdin); 00173 } 00174 #endif 00175 clean_string (config_file, 80); 00176 00177 #ifndef VXWORKS 00178 if (-1 == test_all) 00179 { 00180 char test_all_str[80]; 00181 memset (test_all_str, 0, 80); 00182 printf ("Test all buffers in the file? [yn] (default = No) "); 00183 fgets (test_all_str, 80, stdin); 00184 test_all = (test_all_str[0] == 'y' || test_all_str[0] == 'Y'); 00185 } 00186 #endif 00187 00188 char proc_name[80]; 00189 int cmd_type = 0; 00190 int stat_type = 0; 00191 int dump_hex_data = 0; 00192 if (test_all) 00193 { 00194 #ifdef VXWORKS 00195 if (NULL == host_name) 00196 { 00197 host_name = (char *) malloc (80); 00198 printf ("Host Name? "); 00199 fgets (host_name, 80, stdin); 00200 clean_string (host_name, 80); 00201 } 00202 #else 00203 if (!strcmp (host_name, "UNDEFINED")) 00204 { 00205 printf ("Host Name? "); 00206 fgets (host_name, 80, stdin); 00207 clean_string (host_name, 80); 00208 } 00209 #endif 00210 if (-1 == show_diag_info) 00211 { 00212 char show_diag_info_str[80]; 00213 memset (show_diag_info_str, 0, 80); 00214 printf ("Show Diagnostics Info? [yn] (default = No) "); 00215 fgets (show_diag_info_str, 80, stdin); 00216 show_diag_info = (show_diag_info_str[0] == 'y' 00217 || show_diag_info_str[0] == 'Y'); 00218 } 00219 00220 if (-1 == master) 00221 { 00222 char master_str[80]; 00223 memset (master_str, 0, 80); 00224 printf ("Master? [yn] (default = No) "); 00225 fgets (master_str, 80, stdin); 00226 master = (master_str[0] == 'y' || master_str[0] == 'Y'); 00227 } 00228 00229 if (-1 == wait_for_read) 00230 { 00231 char wait_for_read_str[80]; 00232 memset (wait_for_read_str, 0, 80); 00233 printf ("Wait for read? [yn] (default = No) "); 00234 fgets (wait_for_read_str, 80, stdin); 00235 wait_for_read = (wait_for_read_str[0] == 'y' 00236 || wait_for_read_str[0] == 'Y'); 00237 } 00238 } 00239 else 00240 { 00241 printf ("Buffer Name? "); 00242 fgets (buffer_name, 80, stdin); 00243 clean_string (buffer_name, 80); 00244 printf ("Process Name? "); 00245 fgets (proc_name, 80, stdin); 00246 clean_string (proc_name, 80); 00247 char cmd_type_str[80]; 00248 memset (cmd_type_str, 0, 80); 00249 printf ("RCS_CMD_CHANNEL ? [yn] (default = No) "); 00250 fgets (cmd_type_str, 80, stdin); 00251 cmd_type = (cmd_type_str[0] == 'y' || cmd_type_str[0] == 'Y'); 00252 char stat_type_str[80]; 00253 memset (stat_type_str, 0, 80); 00254 printf ("RCS_STAT_CHANNEL ? [yn] (default = No) "); 00255 fgets (stat_type_str, 80, stdin); 00256 stat_type = (stat_type_str[0] == 'y' || stat_type_str[0] == 'Y'); 00257 char dump_hex_data_str[80]; 00258 memset (dump_hex_data_str, 0, 80); 00259 printf ("Dump Hex Data ? [yn] (default = No) "); 00260 fgets (dump_hex_data_str, 80, stdin); 00261 dump_hex_data = (dump_hex_data_str[0] == 'y' 00262 || dump_hex_data_str[0] == 'Y'); 00263 00264 00265 if (-1 == show_diag_info) 00266 { 00267 char show_diag_info_str[80]; 00268 memset (show_diag_info_str, 0, 80); 00269 printf ("Show Diagnostics Info? [yn] (default = No) "); 00270 fgets (show_diag_info_str, 80, stdin); 00271 show_diag_info = (show_diag_info_str[0] == 'y' 00272 || show_diag_info_str[0] == 'Y'); 00273 } 00274 } 00275 00276 00277 #ifndef VXWORKS 00278 char use_passwd_str[80]; 00279 memset (use_passwd_str, 0, 80); 00280 printf ("Use_Passwd? [yn] (default = No) "); 00281 fgets (use_passwd_str, 80, stdin); 00282 use_passwd = (use_passwd_str[0] == 'y' || use_passwd_str[0] == 'Y'); 00283 #endif 00284 00285 char login[16]; 00286 char passwd[16]; 00287 00288 memset (login, 0, 16); 00289 memset (passwd, 0, 16); 00290 00291 if (use_passwd) 00292 { 00293 printf ("login:"); 00294 fgets (login, 16, stdin); 00295 clean_string (login, 16); 00296 printf ("passwd:"); 00297 fgets (passwd, 16, stdin); 00298 clean_string (passwd, 16); 00299 } 00300 00301 if (!test_all) 00302 { 00303 NML *nml = NULL; 00304 rcs_print ("Calling constructor . . .\n"); 00305 if (cmd_type) 00306 { 00307 nml = 00308 new RCS_CMD_CHANNEL (nmltest_format, buffer_name, proc_name, 00309 config_file, -1); 00310 } 00311 else if (stat_type) 00312 { 00313 nml = 00314 new RCS_STAT_CHANNEL (nmltest_format, buffer_name, proc_name, 00315 config_file, -1); 00316 } 00317 else 00318 { 00319 nml = 00320 new NML (nmltest_format, buffer_name, proc_name, config_file, -1, 00321 0); 00322 } 00323 rcs_print ("Constructor returned %p.\n", nml); 00324 if (nml == NULL) 00325 { 00326 exit (-1); 00327 } 00328 if (!nml->valid ()) 00329 { 00330 rcs_print ("NML object is NOT valid.\n"); 00331 rcs_print ("nml->error_type = %d\n", nml->error_type); 00332 exit (-1); 00333 } 00334 int type = nml->peek (); 00335 rcs_print ("NML::peek() returned %d\n", type); 00336 rcs_print ("\n"); 00337 rcs_print ("nml->cms->header.write_id = %d\n", 00338 nml->cms->header.write_id); 00339 rcs_print ("nml->cms->header.was_read = %d\n", 00340 nml->cms->header.write_id); 00341 NMLmsg *msg = nml->get_address (); 00342 if (type > 0 && msg != NULL) 00343 { 00344 if (cmd_type) 00345 { 00346 RCS_CMD_MSG *cmd_msg = (RCS_CMD_MSG *) nml->get_address (); 00347 rcs_print ("RCS_CMD_MSG *cmd_msg = nml->get_address() = %p\n", 00348 cmd_msg); 00349 rcs_print ("cmd_msg->type = %d\n", cmd_msg->type); 00350 rcs_print ("cmd_msg->size = %d\n", cmd_msg->size); 00351 rcs_print ("cmd_msg->serial_number = %d\n", 00352 cmd_msg->serial_number); 00353 } 00354 else if (stat_type) 00355 { 00356 RCS_STAT_MSG *stat_msg = (RCS_STAT_MSG *) nml->get_address (); 00357 rcs_print ("RCS_STAT_MSG *stat_msg = nml->get_address() = %p\n", 00358 stat_msg); 00359 rcs_print ("stat_msg->type = %d\n", stat_msg->type); 00360 rcs_print ("stat_msg->size = %d\n", stat_msg->size); 00361 rcs_print ("stat_msg->command_type = %d\n", 00362 stat_msg->command_type); 00363 rcs_print ("stat_msg->echo_serial_number = %d\n", 00364 stat_msg->echo_serial_number); 00365 rcs_print ("stat_msg->status = %d\n", stat_msg->status); 00366 rcs_print ("stat_msg->state = %d\n", stat_msg->state); 00367 rcs_print ("stat_msg->line = %d\n", stat_msg->line); 00368 rcs_print ("stat_msg->line = %d\n", stat_msg->line); 00369 rcs_print ("stat_msg->source_line = %d\n", 00370 stat_msg->source_line); 00371 rcs_print ("stat_msg->source_file = %s\n", 00372 stat_msg->source_file); 00373 } 00374 else 00375 { 00376 rcs_print ("NMLmsg *msg = nml->get_address() = %p\n", msg); 00377 rcs_print ("msg->type = %d\n", msg->type); 00378 rcs_print ("msg->size = %d\n", msg->size); 00379 } 00380 00381 if (dump_hex_data) 00382 { 00383 rcs_print ("\n Raw Data:\n"); 00384 char *cdata = (char *) msg; 00385 for (int i = 0; i < msg->size; i++) 00386 { 00387 unsigned int x = (0xFF & ((unsigned int) cdata[i])); 00388 rcs_print ("%2.2X", x); 00389 if (i % 4 == 3) 00390 { 00391 rcs_print (" "); 00392 } 00393 if (i % 16 == 15) 00394 { 00395 rcs_print ("\n"); 00396 } 00397 if (i % 64 == 63) 00398 { 00399 rcs_print ("\n"); 00400 } 00401 } 00402 if (NULL != nml->cms->encoded_data) 00403 { 00404 rcs_print ("\n Encoded Data:\n"); 00405 char *ecdata = (char *) nml->cms->encoded_data; 00406 for (int i = 0; i < msg->size; i++) 00407 { 00408 unsigned int x = (0xFF & ((unsigned int) ecdata[i])); 00409 rcs_print ("%2.2X", x); 00410 if (i % 4 == 3) 00411 { 00412 rcs_print (" "); 00413 } 00414 if (i % 16 == 15) 00415 { 00416 rcs_print ("\n"); 00417 } 00418 if (i % 64 == 63) 00419 { 00420 rcs_print ("\n"); 00421 } 00422 } 00423 } 00424 } 00425 } 00426 if (show_diag_info) 00427 { 00428 NML_DIAGNOSTICS_INFO *ndi = nml->get_diagnostics_info (); 00429 if (NULL != ndi) 00430 { 00431 rcs_print ("********************************************\n"); 00432 rcs_print ("* Diagnostics for %s\n", nml->cms->BufferName); 00433 ndi->print (); 00434 rcs_print ("********************************************\n"); 00435 00436 } 00437 else 00438 { 00439 rcs_print ("No diagnostics available.\n"); 00440 } 00441 } 00442 if (NULL != nml) 00443 { 00444 delete nml; 00445 nml = NULL; 00446 } 00447 rcs_print ("\n"); 00448 exit (0); 00449 } 00450 00451 /* Open the configuration file. */ 00452 if ((fp = inet_file_open (config_file, "r")) == NULL) 00453 { 00454 rcs_print_error ("nmltest: can't open '%s'\n", config_file); 00455 exit (-1); 00456 } 00457 00458 00459 /* Read the configuration file line by line to find buffers. */ 00460 while (!inet_file_eof (fp)) 00461 { 00462 NML *lc_nml = (NML *) NULL; 00463 NML *rc_nml = (NML *) NULL; 00464 00465 if ((inet_file_gets (line, CMS_CONFIG_LINELEN, fp)) == NULL) 00466 { 00467 break; 00468 } 00469 00470 line_number++; 00471 line_len = strlen (line); 00472 if (line_len > CMS_CONFIG_LINELEN) 00473 { 00474 rcs_print_error 00475 ("cms_cfg: Line length of line number %d in %s exceeds max length of %d", 00476 line_number, config_file, CMS_CONFIG_LINELEN); 00477 } 00478 00479 if (line_len > 1) 00480 { 00481 if (line[line_len - 2] == '\\') 00482 { 00483 if ( 00484 (inet_file_gets 00485 (line + line_len - 2, CMS_CONFIG_LINELEN - line_len, 00486 fp)) == NULL) 00487 { 00488 break; 00489 } 00490 line_number++; 00491 } 00492 } 00493 00494 00495 if (line[0] != 'B') 00496 { 00497 continue; 00498 } 00499 00500 sscanf (line + 1, "%s %*s %s", buffer_name, buffer_host); 00501 00502 /* Try to connect locally if the buffer host matches this one. */ 00503 00504 if (!strcmp (buffer_host, host_name)) 00505 { 00506 printf ("\nAttempting to connect to %s locally . . .\n", 00507 buffer_name); 00508 sprintf (proc_line, "P nmltest %s LOCAL %s R 0 5 %d 0\n", 00509 buffer_name, buffer_host, master); 00510 lc_nml = new NML (line, proc_line); 00511 if (NULL != lc_nml) 00512 { 00513 lc_nml->ignore_format_chain = 1; 00514 lc_nml->login (login, passwd); 00515 if (lc_nml->valid ()) 00516 { 00517 if (wait_for_read) 00518 { 00519 printf ("Waiting for the buffer to be read.\n"); 00520 while (!lc_nml->check_if_read ()); 00521 printf ("Buffer was read.\n"); 00522 } 00523 lc_msg_type = lc_nml->peek (); 00524 if (lc_msg_type != -1) 00525 { 00526 msg_size = (lc_nml->get_address ())->size; 00527 local_connect_status = LC_SUCCEEDED; 00528 } 00529 else 00530 { 00531 printf ("NML::peek returned -1\n"); 00532 local_connect_status = LC_FAILED; 00533 } 00534 if (lc_msg_type == 0) 00535 { 00536 lc_msg_type = (lc_nml->get_address ())->type; 00537 } 00538 00539 } 00540 else 00541 { 00542 printf ("NML::valid returned 0.\n"); 00543 printf ("NML::error_type = %d\n", lc_nml->error_type); 00544 local_connect_status = LC_FAILED; 00545 } 00546 if (show_diag_info) 00547 { 00548 NML_DIAGNOSTICS_INFO *ndi = lc_nml->get_diagnostics_info (); 00549 if (NULL != ndi) 00550 { 00551 ndi->print (); 00552 } 00553 } 00554 } 00555 else 00556 { 00557 local_connect_status = LC_FAILED; 00558 } 00559 } 00560 if (!master) 00561 { 00562 printf ("\nAttempting to connect to %s remotely . . .\n", 00563 buffer_name); 00564 sprintf (proc_line, "P nmltest %s REMOTE %s R 0 5 0 0\n", 00565 buffer_name, host_name); 00566 rc_nml = new NML (line, proc_line); 00567 if (NULL != rc_nml) 00568 { 00569 if (login[0] != 0 && login[0] != '\n' && login[0] != '\r') 00570 { 00571 rc_nml->login (login, passwd); 00572 } 00573 rc_nml->ignore_format_chain = 1; 00574 if (rc_nml->valid ()) 00575 { 00576 if (wait_for_read) 00577 { 00578 printf ("Waiting for the buffer to be read.\n"); 00579 while (!rc_nml->check_if_read ()); 00580 printf ("Buffer was read.\n"); 00581 } 00582 rc_msg_type = rc_nml->peek (); 00583 if (rc_msg_type != -1) 00584 { 00585 msg_size = (rc_nml->get_address ())->size; 00586 remote_connect_status = RC_SUCCEEDED; 00587 } 00588 else 00589 { 00590 printf ("NML::peek returned -1\n"); 00591 remote_connect_status = RC_FAILED; 00592 } 00593 if (rc_msg_type == 0) 00594 { 00595 rc_msg_type = (rc_nml->get_address ())->type; 00596 } 00597 00598 } 00599 else 00600 { 00601 printf ("NML::valid returned 0.\n"); 00602 printf ("NML::error_type = %d\n", rc_nml->error_type); 00603 remote_connect_status = RC_FAILED; 00604 } 00605 if (show_diag_info) 00606 { 00607 NML_DIAGNOSTICS_INFO *ndi = rc_nml->get_diagnostics_info (); 00608 if (NULL != ndi) 00609 { 00610 ndi->print (); 00611 } 00612 } 00613 } 00614 else 00615 { 00616 remote_connect_status = RC_FAILED; 00617 } 00618 } 00619 00620 if (local_connect_status == LC_SUCCEEDED) 00621 { 00622 sprintf (output_line, "%20.20s\t%s\t%s\t%ld\t%d\t%ld\t%ld", 00623 buffer_name, 00624 LC_ARRAY[local_connect_status], 00625 RC_ARRAY[remote_connect_status], 00626 lc_msg_type, 00627 msg_size, 00628 lc_nml->cms->header.write_id, 00629 lc_nml->cms->header.was_read); 00630 } 00631 else if (remote_connect_status == RC_SUCCEEDED) 00632 { 00633 sprintf (output_line, "%20.20s\t%s\t%s\t%ld\t%d\t%ld\t%ld", 00634 buffer_name, 00635 LC_ARRAY[local_connect_status], 00636 RC_ARRAY[remote_connect_status], 00637 rc_msg_type, 00638 msg_size, 00639 rc_nml->cms->header.write_id, 00640 rc_nml->cms->header.was_read); 00641 } 00642 else 00643 { 00644 sprintf (output_line, "%20.20s\t%s\t%s\t--\t--\t--\t--", 00645 buffer_name, 00646 LC_ARRAY[local_connect_status], 00647 RC_ARRAY[remote_connect_status]); 00648 } 00649 output_list->store_at_tail (output_line, strlen (output_line) + 1, 1); 00650 00651 if (NULL != lc_nml) 00652 { 00653 delete lc_nml; 00654 } 00655 if (NULL != rc_nml) 00656 { 00657 delete rc_nml; 00658 } 00659 00660 } 00661 00662 00663 /* Print a nice header. */ 00664 printf ("NMLTEST: terminology\n"); 00665 printf 00666 ("LCS - Local Connect Status S(Success)|F(Fail)|NA(Not Attempted)\n"); 00667 printf 00668 ("RCS - Remote Connect Status (What did you think RCS stood for?)\n"); 00669 printf ("msg - NML message type\n"); 00670 printf ("size - sizeof(NML message)\n"); 00671 printf ("cnt - Number of times this buffer has been written to.\n"); 00672 printf 00673 ("read? - Has this message been read by someone other than NMLTEST?\n"); 00674 printf ("\n"); 00675 00676 00677 00678 printf ("NMLTEST: Summary\n"); 00679 printf ("%20.20s\tLCS\tRCS\tmsg\tsize\tcnt\tread?\n", "BufferName"); 00680 00681 00682 00683 if (NULL != output_list) 00684 { 00685 char *next_line; 00686 next_line = (char *) output_list->get_head (); 00687 while (NULL != next_line) 00688 { 00689 puts (next_line); 00690 next_line = (char *) output_list->get_next (); 00691 } 00692 delete output_list; 00693 } 00694 00695 } |
|
Definition at line 3 of file nmltest.cc. |
|
Definition at line 30 of file nmltest.cc. |
|
Definition at line 41 of file nmltest.cc. |