home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmtool.zip / stress.c < prev    next >
Text File  |  1997-11-07  |  12KB  |  385 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*      FILE: STRESS.C                                                        */
  4. /*                                                                            */
  5. /*   PURPOSE: This file contains the IBMTOOL portion of the stress test.      */
  6. /*                                                                            */
  7. /* FUNCTIONS: PutStressParms                                                  */
  8. /*            TTStress                                                        */
  9. /*            StressWksta                                                     */
  10. /*                                                                            */
  11. /* GLOBAL DATA ACCESSED                                                       */
  12. /*      int         CurrMenuOpt                                               */
  13. /*      BOOLEAN     TokenRing                                                 */
  14. /*      ULONG       hWedge                                                    */
  15. /*      SERVICECHAR MACMSC                                                    */
  16. /*      CTRLFRAME   ControlFrame                                              */
  17. /*                                                                            */
  18. /******************************************************************************/
  19.  
  20. #define INCL_SUB
  21. #define INCL_BASE
  22. #define INCL_DOS
  23. #include <os2.h>
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include <malloc.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include "ndis.h"
  31. #include "ibmtool.h"
  32. #include "ioctl.h"
  33.  
  34. #define CTL_KEY             0x0004
  35. #define DEFAULT_TOLERANCE    10000
  36. #define DEFAULT_FRAMECOUNT  100000
  37.  
  38. DWORD   StressTolerance;
  39.  
  40. void PutStressParms (BYTE far *data)
  41. {
  42.   // Put stress parameters in control frame data
  43.   // FrameCount, Tolerance, Data Error Break Flag, Data Checking Flag
  44.   *(DWORD *) data = WedgeCommon->StressCnt;
  45.   data += sizeof (DWORD);
  46.   *(DWORD *) data = StressTolerance;
  47.   data += sizeof (DWORD);
  48.   *(WORD *) data = WedgeCommon->StopOnErr;
  49.   data += sizeof (WORD);
  50.   *(WORD *) data = WedgeCommon->CheckData;
  51. }
  52.  
  53. int TTStress ()
  54. {
  55.   // STRESS [FrameCount] [Tolerance] ["NOSTOP"] ["NOCHK"]
  56.  
  57.   // 1) get parameters
  58.   // 2) send out broadcast frame to alert workstation(s)
  59.   // 3) set stress mode to TRUE
  60.   // 4) loop; display totals, monitor kbd, check for control frames
  61.   // 5) set stress mode to FALSE
  62.  
  63.   char       *token;
  64.   BOOLEAN     UserHalt = FALSE;
  65.   WORD        CheckDataSave = WedgeCommon->CheckData;
  66.   USHORT      tempmenu;
  67.   KBDKEYINFO  KbdInfo;
  68.  
  69.   // initialize stress parameters
  70.   WedgeCommon->StopOnErr = TRUE;
  71.   WedgeCommon->CheckData = TRUE;
  72.   WedgeCommon->StressCnt = DEFAULT_FRAMECOUNT;
  73.   StressTolerance = DEFAULT_TOLERANCE;
  74.  
  75.   /* get stress parameters from command */
  76.  
  77.   // get the frame count (optional)
  78.   if ((token = strtok (NULL, "\n\t ")))
  79.     {
  80.      if ((WedgeCommon->StressCnt = GetNumericParm (token)) < 0)
  81.         return TT_INVALID_PARAMETER;
  82.     }
  83.  
  84.   // get the StressTolerance (optional)
  85.   if ((token = strtok (NULL, "\n\t ")))
  86.     {
  87.      if ((StressTolerance = GetNumericParm (token)) < 0)
  88.         return TT_INVALID_PARAMETER;
  89.     }
  90.  
  91.   // get the integrity parameter (optional)
  92.   if ((token = strtok (NULL, "\n\t ")))
  93.     {
  94.      if (!stricmp (token, "NOSTOP"))
  95.         WedgeCommon->StopOnErr = FALSE;
  96.      else
  97.         return TT_INVALID_PARAMETER;
  98.     }
  99.  
  100.   // get the int 3 parameter (optional)
  101.   if ((token = strtok (NULL, "\n\t ")))
  102.     {
  103.      if (!stricmp (token, "NOCHK"))
  104.         WedgeCommon->CheckData = FALSE;
  105.      else
  106.         return TT_INVALID_PARAMETER;
  107.     }
  108.  
  109.   /* set stress mode to TRUE */
  110.   WedgeCommon->StressMode = TRUE;
  111.  
  112.   /* query all current workstations to make sure their still there */
  113.   WkstaStressCnt = QueryWorkStations ();
  114.  
  115.   /* send out a broadcast frame to alert workstation(s) */
  116.   SendControlFrame (CCSTRESS);
  117.  
  118.   // save current info display
  119.   tempmenu = CurrMenuOpt;
  120.   CurrMenuOpt = -1;
  121.  
  122.   // clear counters
  123.   WedgeCommon->TotalRx =
  124.   WedgeCommon->TotalTx =
  125.   WedgeCommon->TotalRxErr =
  126.   WedgeCommon->TotalTxErr =
  127.   WedgeCommon->TotalTxNoRsrc = 0L;
  128.  
  129.   // display the stress screen
  130.   ShowStressScr ();
  131.  
  132.   KbdInfo.fsState = 0;
  133.  
  134.   // loop
  135.   // SERVER is done being stressed when:
  136.   //    1) ^H is entered                OR
  137.   //    2) StressTolerance is exceeded  OR
  138.   //    3) All WORKSTATIONS have sent the CCENDSTRESS control frame
  139.   while (WedgeCommon->StressMode)
  140.     {
  141.      KbdCharIn (&KbdInfo, IO_NOWAIT, 0);
  142.      if ((KbdInfo.fsState & CTL_KEY) && (KbdInfo.chScan == 0x0023))
  143.        {
  144.         SendControlFrame (CCSRVSTOP);
  145.         WedgeCommon->StressMode = FALSE;
  146.         UserHalt = TRUE;
  147.        }
  148.      if (WedgeCommon->TotalTxNoRsrc > StressTolerance)
  149.         WedgeCommon->StressMode = FALSE;
  150.      CheckIndications ();
  151.      if (WkstaStressCnt == 0)
  152.         WedgeCommon->StressMode = FALSE;
  153.      UpdateStressScr ();
  154.     } /* endwhile */
  155.  
  156.   if (UserHalt)
  157.      aprintf (3, 17, 0x1E, "           Stress Test Incomplete            ");
  158.   else
  159.     {
  160.      aprintf (3, 17, 0x1E, "         Stress Test Complete - ");
  161.      if (WedgeCommon->TotalTxNoRsrc > StressTolerance)
  162.        {
  163.         PrintMsg (RED, "STRESS TOLERANCE EXCEEDED");
  164.         aprintf (3, 49, 0x1C, "FAIL         ");
  165.        }
  166.      if (WedgeCommon->TotalRxErr != 0L)
  167.        {
  168.         PrintMsg (RED, "RECEIVE DATA ERRORS");
  169.         aprintf (3, 49, 0x1C, "FAIL         ");
  170.        }
  171.      else if (WkstaStressCnt != 0)
  172.        {
  173.         PrintMsg (RED, "Stressing WORKSTATION(s) have not checked in");
  174.         PrintMsg (RED, "  Verify that all stations are transmitting and receiving");
  175.         aprintf (3, 49, 0x1C, "FAIL         ");
  176.        }
  177.      else
  178.         aprintf (3, 49, 0x1A, "PASS         ");
  179.     }
  180.  
  181.   KbdInfo.fsState = 0;
  182.   KbdCharIn (&KbdInfo, IO_WAIT, 0);
  183.   while ((!(KbdInfo.fsState & CTL_KEY)) && (KbdInfo.chScan != 0x0023))
  184.      KbdCharIn (&KbdInfo, IO_WAIT, 0);
  185.  
  186.   /* set stress mode to FALSE */
  187.   WedgeCommon->StressMode = FALSE;
  188.  
  189.   // restore check data flag
  190.   WedgeCommon->CheckData = CheckDataSave;
  191.  
  192.   // clear counters
  193.   WedgeCommon->TotalRx =
  194.   WedgeCommon->TotalTx =
  195.   WedgeCommon->TotalRxErr =
  196.   WedgeCommon->TotalTxErr =
  197.   WedgeCommon->TotalTxNoRsrc = 0L;
  198.  
  199.   // restore the info display
  200.   SelectMenuOpt (tempmenu);
  201.  
  202.   return SUCCESS;
  203. }
  204.  
  205. void StressWksta ()
  206. {
  207.   BYTE      far *StressData,
  208.             far *StressDataPhys,
  209.                 *data;
  210.   BOOLEAN        UserQuit = FALSE, UserHalt = FALSE;
  211.   USHORT         i, j,
  212.                  tempmenu,
  213.                  offset;
  214.   WORD           CheckDataSave = WedgeCommon->CheckData;
  215.   KBDKEYINFO     KbdInfo;
  216.   IOCTLDATA      IOData;
  217.   IOCTLDATA far *IODataPtr = &IOData;
  218.  
  219.   // get stress parameters out of the control frame
  220.   data = (BYTE *) ControlFrame.pData;
  221.   WedgeCommon->StressCnt  = *(DWORD *) data;
  222.   data += sizeof (DWORD);
  223.   StressTolerance         = *(DWORD *) data;
  224.   WedgeCommon->StopOnErr  = *(WORD *) data;
  225.   WedgeCommon->CheckData  = *(WORD *) data;
  226.  
  227.   // save current info display
  228.   tempmenu = CurrMenuOpt;
  229.   CurrMenuOpt = -1;
  230.  
  231.   // clear counters
  232.   WedgeCommon->TotalRx =
  233.   WedgeCommon->TotalTx =
  234.   WedgeCommon->TotalRxErr =
  235.   WedgeCommon->TotalTxErr =
  236.   WedgeCommon->TotalTxNoRsrc = 0L;
  237.  
  238.   // display the stress screen
  239.   ShowStressScr ();
  240.  
  241.   /* set up the StressData for WEDGE's use */
  242.   StressData = (BYTE far *) _fcalloc (MACMSC.MscMaxFrame, sizeof (BYTE));
  243.  
  244.   IOData.ReqCode = VIRT_TO_PHYS;
  245.   IOData.Length  = 0;
  246.   IOData.SrcDataPtr = (void far *) StressData;
  247.   IOData.DestDataPtr = NULL;
  248.   GenIoctl ((void far *) IODataPtr, hWedge);
  249.   StressDataPhys = IOData.SrcDataPtr;
  250.  
  251.   for (i=0; i<MACMSC.MscMaxFrame; i++)
  252.      StressData[MACMSC.MscMaxFrame-i-1] = (BYTE) ((i + 1) & 0xFF);
  253.  
  254.   offset = 0;
  255.   if (TokenRing)
  256.     {
  257.      StressData[offset++] = 0x10;
  258.      StressData[offset++] = 0x40;
  259.     }
  260.   _fmemcpy ((void far *) (StressData + offset),
  261.             (void far *) WedgeCommon->ServerAddr,
  262.             MACMSC.MscStnAdrSz);
  263.   offset += MACMSC.MscStnAdrSz;
  264.   _fmemcpy ((void far *) (StressData + offset),
  265.             (void far *) MACMSC.MscCurrStnAdr,
  266.             MACMSC.MscStnAdrSz);
  267.  
  268.   // we haven't heard from SERVER yet
  269.   ServerStressAck = FALSE;
  270.  
  271.   // set stress mode to TRUE
  272.   WedgeCommon->StressMode = TRUE;
  273.  
  274.   // loop
  275.   // WORKSTATIONS are done stressing when:
  276.   //    1) ^H is entered                OR
  277.   //    2) StressTolerance is exceeded  OR
  278.   //    3) StressCnt = 0
  279.   while (WedgeCommon->StressMode)
  280.     {
  281.      KbdCharIn (&KbdInfo, IO_NOWAIT, 0);
  282.      if ((KbdInfo.fsState & CTL_KEY) && (KbdInfo.chScan == 0x0023))
  283.        {
  284.         UserHalt = TRUE;
  285.         WedgeCommon->StressMode = FALSE;
  286.         // restore check data flag
  287.         WedgeCommon->CheckData = CheckDataSave;
  288.         break;
  289.        }
  290.      else if ((WedgeCommon->TotalTxNoRsrc > StressTolerance) ||
  291.               (!WedgeCommon->StressCnt) ||
  292.               ServerStressAck)
  293.         WedgeCommon->StressMode = FALSE;
  294.      else
  295.        {
  296.         IOData.ReqCode = STRESSTX;
  297.         IOData.Length  = WedgeCommon->HeaderLen - 2;
  298.         IOData.SrcDataPtr = (void far *) StressData;
  299.         IOData.DestDataPtr = (void far *) StressDataPhys;
  300.         GenIoctl ((void far *) IODataPtr, hWedge);
  301.        }
  302.      CheckIndications ();
  303.      UpdateStressScr ();
  304.     } /* endwhile */
  305.  
  306.   if (UserHalt)
  307.      aprintf (3, 17, 0x1E, "           Stress Test Incomplete            ");
  308.   else
  309.     {
  310.      aprintf (3, 17, 0x1E, "         Stress Test Complete - ");
  311.      if (WedgeCommon->TotalTxNoRsrc > StressTolerance)
  312.        {
  313.         // we're not transmitting, so don't bother sending ENDSTRESS message
  314.         PrintMsg (RED, "Stress tolerance exceeded");
  315.         aprintf (3, 49, 0x1C, "FAIL         ");
  316.        }
  317.      else
  318.        {
  319.         // send ENDSTRESS frame to SERVER until he responds
  320.         KbdInfo.fsState = 0;
  321.         while (!ServerStressAck)
  322.           {
  323.            // allow user to intervene in case we're really dead
  324.            KbdCharIn (&KbdInfo, IO_NOWAIT, 0);
  325.            if ((KbdInfo.fsState & CTL_KEY) && (KbdInfo.chScan == 0x0023))
  326.              {
  327.               UserQuit = TRUE;
  328.               break;
  329.              }
  330.            SendControlFrame (CCENDSTRESS);
  331.            for (i=0; i<20; ++i)
  332.              {
  333.               CheckIndications ();
  334.               if (ServerStressAck) break;
  335.               DosSleep (100);
  336.              } /* endfor */
  337.           } /* endwhile */
  338.  
  339.         if (WedgeCommon->TotalRxErr != 0L)
  340.           {
  341.            PrintMsg (RED, "RECEIVE DATA ERRORS");
  342.            aprintf (3, 49, 0x1C, "FAIL         ");
  343.           }
  344.         else if (WedgeCommon->StressCnt != 0L && !UserHalt)
  345.           {
  346.            aprintf (3, 17, 0x1E, "           Stress Test Incomplete            ");
  347.            PrintMsg (RED, "Not all stress frames transmitted");
  348.           }
  349.         else if (!ServerStressAck)
  350.           {
  351.            PrintMsg (RED, "Server did not acknowledge END OF STRESS message");
  352.            aprintf (3, 49, 0x1C, "FAIL         ");
  353.           }
  354.         else
  355.            aprintf (3, 49, 0x1A, "PASS         ");
  356.        }
  357.     } /* endif */
  358.  
  359.   if (!UserQuit)
  360.     {
  361.      // insist user intervene - so that display doesn't go away
  362.      KbdInfo.fsState = 0;
  363.      KbdCharIn (&KbdInfo, IO_WAIT, 0);
  364.      while ((!(KbdInfo.fsState & CTL_KEY)) && (KbdInfo.chScan != 0x0023))
  365.         KbdCharIn (&KbdInfo, IO_WAIT, 0);
  366.     }
  367.  
  368.   /* set stress mode to FALSE */
  369.   WedgeCommon->StressMode = FALSE;
  370.  
  371.   // free stress data buffer
  372.   _ffree (StressData);
  373.  
  374.   // clear counters
  375.   WedgeCommon->TotalRx =
  376.   WedgeCommon->TotalTx =
  377.   WedgeCommon->TotalRxErr =
  378.   WedgeCommon->TotalTxErr =
  379.   WedgeCommon->TotalTxNoRsrc = 0L;
  380.  
  381.   // restore the info display
  382.   SelectMenuOpt (tempmenu);
  383. }
  384.  
  385.