home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dax1.exe / CLIENT / STRESS / NLM / STRESS.C < prev   
Text File  |  1992-07-15  |  8KB  |  229 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      stress.c                                              ║
  4. //   ║ abstract:    This module is a stress test for the DAP Engine.      ║
  5. //   ║              This NLM version can create multiple clients, i.e.    ║
  6. //   ║              threads, which will see how well the Engine holds up  ║
  7. //   ║              during high traffic situations.                       ║
  8. //   ║                                                                    ║
  9. //   ║ environment: NetWare 3.x v3.11                                     ║
  10. //   ║              Network C for NLMs SDK                                ║
  11. //   ║              CLib v3.11                                            ║
  12. //   ║                                                                    ║
  13. //   ║  This software is provided as is and carries no warranty           ║
  14. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  15. //   ║  warranties of merchantability, title and fitness for a particular ║
  16. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  17. //   ║  your requirements or that the software is without defect or error ║
  18. //   ║  or that operation of the software will be uninterrupted.  You are ║
  19. //   ║  using the software at your risk.  The software is not a product   ║
  20. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  21. //   ║                                                                    ║
  22. //   ╟────────────────────────────────────────────────────────────────────╢
  23. //   ║ maintenance history:                                               ║
  24. //   ║ level    date      pi   description                                ║
  25. //   ╟────────────────────────────────────────────────────────────────────╢
  26. //   ║  001   02/28/92    kl   initial release.                           ║
  27. //   ╚════════════════════════════════════════════════════════════════════╝
  28.  
  29. #include <stdio.h>
  30. #include <conio.h>
  31. #include <errno.h>
  32. #include <process.h>
  33. #include <nwsemaph.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36.  
  37. #include "h/appl.h"
  38. #include "dap/dapapi.h"
  39.  
  40. LONG    semaIOHandle;
  41.  
  42. //
  43. //  This function prints a message on the screen, in a location relative
  44. //  to the thread number.
  45. //
  46.  
  47. myprintf(int threadnum, char *msg)
  48. {
  49.         if( semaIOHandle ) WaitOnLocalSemaphore(semaIOHandle);
  50.         gotoxy((threadnum % 3) * 25, threadnum / 3);
  51.         while(*msg) putch(*msg++);
  52.         if( semaIOHandle ) SignalLocalSemaphore(semaIOHandle);
  53. }
  54.  
  55. //
  56. //  errorexit() is called if an error is detected on a session.  It calls
  57. //  the internal Debug API DAPDisplaySessionData, which creates a debug
  58. //  file containing relevant info about the session when it failed. i.e. state
  59. //
  60.  
  61. errorexit(int threadnum, int rc, char *msg, DAPDATA *dd)
  62. {
  63.     char    buf[255];
  64.  
  65.     sprintf(buf, "%s:%s",
  66.             msg,
  67.             /* rc, */
  68.             DAPTranslateReturnCode(rc));
  69.     myprintf(threadnum, buf);
  70.  
  71.     if( dd ){
  72.         DAPDisplaySessionData(dd);
  73.         DAPDeInitialize(dd);
  74.     }
  75.     ExitThread(EXIT_THREAD,1);
  76. }
  77.  
  78. //
  79. //  The s_atexit() is called if the application terminates.  All we'll do
  80. //  here is close the semaphore.
  81. //
  82.  
  83. s_atexit()
  84. {
  85.         if( semaIOHandle ) CloseLocalSemaphore(semaIOHandle);
  86. }
  87.  
  88. #define threadAtSay(threadnum, msg)     myprintf(threadnum,msg)
  89.  
  90. #define DEFOUTER    1000
  91. #define DEFINNER    10
  92. LONG    outerlimit = DEFOUTER;
  93. LONG    innerlimit = DEFINNER;
  94.  
  95. WTStatus(int threadNum, DAPDATA *dd)
  96. {
  97.         char    buf[10];
  98.  
  99.         buf[0] = '<';
  100.         buf[1] = (DAPGetNumRetries(dd) > 1) ? '+' : ' ';
  101.         buf[2] = DAPGetNumSendErr(dd) ? '-' : ' ';
  102.         buf[3] = '>'; 
  103.         buf[4] = NULL;
  104.         threadAtSay(threadNum,buf);
  105. }
  106.  
  107. WorkerThread(void *_threadNum)
  108. {
  109.         int     rc;
  110.         int     threadNum = (int)_threadNum;
  111.         long    x,y,z,oldval;
  112.         LONG    iter=0L;
  113.         DAPDATA *dd;
  114.  
  115.         if( (dd = DAPInitialize(SERVERNAME, SERVERTYPE)) == NULL ){
  116.             threadAtSay(threadNum,"Could not initialize");
  117.             ExitThread(EXIT_THREAD,1);
  118.         }
  119.         threadAtSay(threadNum,"Initialized");
  120.         if( (rc = DAPAllocateSession(dd)) != NULL ){
  121.             errorexit(threadNum, rc,"AS",dd);
  122.         }
  123.         threadAtSay(threadNum,"Attached");
  124.         for(x=0; !kbhit() && x < outerlimit; ++x){
  125.             for(y=1; !kbhit() && y < innerlimit; ++y){
  126.                 if( (rc = DAPAddOperands(dd,x,y,&z)) != NULL ){
  127.                     if( DAP_CRITICAL_ERROR(rc) ){
  128.                         errorexit(threadNum,rc,"AR",dd);
  129.                     }
  130.                     else{
  131.                         threadAtSay(threadNum,DAPTranslateReturnCode(rc));
  132.                     }
  133.                 }
  134.                 if( x + y != z ) threadAtSay(threadNum,"Can't Add");
  135.                 WTStatus(threadNum, dd);
  136.  
  137.                 if( (rc = DAPSubtractOperands(dd,x,y,&z)) != NULL ){
  138.                     if( DAP_CRITICAL_ERROR(rc) ){
  139.                         errorexit(threadNum,rc,"SR",dd);
  140.                     }
  141.                     else{
  142.                         threadAtSay(threadNum,DAPTranslateReturnCode(rc));
  143.                     }
  144.                 }
  145.                 if( x - y != z ) threadAtSay(threadNum,"Can't Sub");
  146.                 WTStatus(threadNum, dd);
  147.  
  148.                 if( (rc = DAPMultiplyOperands(dd,x,y,&z)) != NULL ){
  149.                     if( DAP_CRITICAL_ERROR(rc) ){
  150.                         errorexit(threadNum,rc,"MR",dd);
  151.                     }
  152.                     else{
  153.                         threadAtSay(threadNum,DAPTranslateReturnCode(rc));
  154.                     }
  155.                 }
  156.                 if( x * y != z ) threadAtSay(threadNum,"Can't Mul");
  157.                 WTStatus(threadNum, dd);
  158.  
  159.                 if( (rc = DAPDivideOperands(dd,x,y,&z)) != NULL ){
  160.                     if( DAP_CRITICAL_ERROR(rc) ){
  161.                         errorexit(threadNum,rc,"DR",dd);
  162.                     }
  163.                     else{
  164.                         threadAtSay(threadNum,DAPTranslateReturnCode(rc));
  165.                     }
  166.                 }
  167.                 if( x / y != z ) threadAtSay(threadNum,"Can't Div");
  168.                 WTStatus(threadNum, dd);
  169.  
  170.                 if( (rc = DAPStoreValue(dd,z,&oldval)) != NULL ){
  171.                     if( DAP_CRITICAL_ERROR(rc) ){
  172.                         errorexit(threadNum,rc,"SV",dd);
  173.                     }
  174.                     else{
  175.                         threadAtSay(threadNum,DAPTranslateReturnCode(rc));
  176.                     }
  177.                 }
  178.                 WTStatus(threadNum, dd);
  179.                 oldval = z;     // remember z, and see if it comes back ok
  180.                 if( (rc = DAPRecallValue(dd,&z)) != NULL ){
  181.                     if( DAP_CRITICAL_ERROR(rc) ){
  182.                         errorexit(threadNum,rc,"RV",dd);
  183.                     }
  184.                     else{
  185.                         threadAtSay(threadNum,DAPTranslateReturnCode(rc));
  186.                     }
  187.                 }
  188.                 WTStatus(threadNum, dd);
  189.                 if( z != oldval ) threadAtSay(threadNum,"Can't Rem");
  190.  
  191.                 ++iter;
  192.             }
  193.         }
  194.         if( (rc = DAPDeAllocateSession(dd)) != NULL ){
  195.             errorexit(threadNum,rc,"DAR",dd);
  196.         }
  197.         threadAtSay(threadNum,"Detached from server");
  198.         DAPDeInitialize(dd);
  199.         threadAtSay(threadNum,"DeInitialized okay");
  200.         ExitThread(EXIT_THREAD,0);
  201. }
  202.  
  203. main(int argc, char *argv[])
  204. {
  205.         int numclients;
  206.         int threadNum=0;
  207.  
  208.         if( argc < 2 ){
  209.             printf("usage: stress <numClients> [outer] [inner]\n");
  210.             exit(1);
  211.         }
  212.         atexit(s_atexit);
  213.         semaIOHandle = OpenLocalSemaphore(1);
  214.         numclients = atoi(argv[1]);
  215.         if( argc == 4 ){
  216.             outerlimit = atoi(argv[2]);
  217.             innerlimit = atoi(argv[3]);
  218.         }
  219.         while( numclients-- ){
  220.             if(BeginThreadGroup(WorkerThread,NULL,8192,(void *)threadNum) == EFAILURE){
  221.                 threadAtSay(threadNum,"Failed to start");
  222.                 exit(1);
  223.             }
  224.             threadNum++;
  225.             ThreadSwitch();
  226.         }
  227.         return 0;
  228. }
  229.