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
Wrap
Text File
|
1992-07-15
|
8KB
|
229 lines
// ╔════════════════════════════════════════════════════════════════════╗
// ║ ║
// ║ module: stress.c ║
// ║ abstract: This module is a stress test for the DAP Engine. ║
// ║ This NLM version can create multiple clients, i.e. ║
// ║ threads, which will see how well the Engine holds up ║
// ║ during high traffic situations. ║
// ║ ║
// ║ environment: NetWare 3.x v3.11 ║
// ║ Network C for NLMs SDK ║
// ║ CLib v3.11 ║
// ║ ║
// ║ This software is provided as is and carries no warranty ║
// ║ whatsoever. Novell disclaims and excludes any and all implied ║
// ║ warranties of merchantability, title and fitness for a particular ║
// ║ purpose. Novell does not warrant that the software will satisfy ║
// ║ your requirements or that the software is without defect or error ║
// ║ or that operation of the software will be uninterrupted. You are ║
// ║ using the software at your risk. The software is not a product ║
// ║ of Novell, Inc. or any of subsidiaries. ║
// ║ ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ maintenance history: ║
// ║ level date pi description ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ 001 02/28/92 kl initial release. ║
// ╚════════════════════════════════════════════════════════════════════╝
#include <stdio.h>
#include <conio.h>
#include <errno.h>
#include <process.h>
#include <nwsemaph.h>
#include <stdlib.h>
#include <string.h>
#include "h/appl.h"
#include "dap/dapapi.h"
LONG semaIOHandle;
//
// This function prints a message on the screen, in a location relative
// to the thread number.
//
myprintf(int threadnum, char *msg)
{
if( semaIOHandle ) WaitOnLocalSemaphore(semaIOHandle);
gotoxy((threadnum % 3) * 25, threadnum / 3);
while(*msg) putch(*msg++);
if( semaIOHandle ) SignalLocalSemaphore(semaIOHandle);
}
//
// errorexit() is called if an error is detected on a session. It calls
// the internal Debug API DAPDisplaySessionData, which creates a debug
// file containing relevant info about the session when it failed. i.e. state
//
errorexit(int threadnum, int rc, char *msg, DAPDATA *dd)
{
char buf[255];
sprintf(buf, "%s:%s",
msg,
/* rc, */
DAPTranslateReturnCode(rc));
myprintf(threadnum, buf);
if( dd ){
DAPDisplaySessionData(dd);
DAPDeInitialize(dd);
}
ExitThread(EXIT_THREAD,1);
}
//
// The s_atexit() is called if the application terminates. All we'll do
// here is close the semaphore.
//
s_atexit()
{
if( semaIOHandle ) CloseLocalSemaphore(semaIOHandle);
}
#define threadAtSay(threadnum, msg) myprintf(threadnum,msg)
#define DEFOUTER 1000
#define DEFINNER 10
LONG outerlimit = DEFOUTER;
LONG innerlimit = DEFINNER;
WTStatus(int threadNum, DAPDATA *dd)
{
char buf[10];
buf[0] = '<';
buf[1] = (DAPGetNumRetries(dd) > 1) ? '+' : ' ';
buf[2] = DAPGetNumSendErr(dd) ? '-' : ' ';
buf[3] = '>';
buf[4] = NULL;
threadAtSay(threadNum,buf);
}
WorkerThread(void *_threadNum)
{
int rc;
int threadNum = (int)_threadNum;
long x,y,z,oldval;
LONG iter=0L;
DAPDATA *dd;
if( (dd = DAPInitialize(SERVERNAME, SERVERTYPE)) == NULL ){
threadAtSay(threadNum,"Could not initialize");
ExitThread(EXIT_THREAD,1);
}
threadAtSay(threadNum,"Initialized");
if( (rc = DAPAllocateSession(dd)) != NULL ){
errorexit(threadNum, rc,"AS",dd);
}
threadAtSay(threadNum,"Attached");
for(x=0; !kbhit() && x < outerlimit; ++x){
for(y=1; !kbhit() && y < innerlimit; ++y){
if( (rc = DAPAddOperands(dd,x,y,&z)) != NULL ){
if( DAP_CRITICAL_ERROR(rc) ){
errorexit(threadNum,rc,"AR",dd);
}
else{
threadAtSay(threadNum,DAPTranslateReturnCode(rc));
}
}
if( x + y != z ) threadAtSay(threadNum,"Can't Add");
WTStatus(threadNum, dd);
if( (rc = DAPSubtractOperands(dd,x,y,&z)) != NULL ){
if( DAP_CRITICAL_ERROR(rc) ){
errorexit(threadNum,rc,"SR",dd);
}
else{
threadAtSay(threadNum,DAPTranslateReturnCode(rc));
}
}
if( x - y != z ) threadAtSay(threadNum,"Can't Sub");
WTStatus(threadNum, dd);
if( (rc = DAPMultiplyOperands(dd,x,y,&z)) != NULL ){
if( DAP_CRITICAL_ERROR(rc) ){
errorexit(threadNum,rc,"MR",dd);
}
else{
threadAtSay(threadNum,DAPTranslateReturnCode(rc));
}
}
if( x * y != z ) threadAtSay(threadNum,"Can't Mul");
WTStatus(threadNum, dd);
if( (rc = DAPDivideOperands(dd,x,y,&z)) != NULL ){
if( DAP_CRITICAL_ERROR(rc) ){
errorexit(threadNum,rc,"DR",dd);
}
else{
threadAtSay(threadNum,DAPTranslateReturnCode(rc));
}
}
if( x / y != z ) threadAtSay(threadNum,"Can't Div");
WTStatus(threadNum, dd);
if( (rc = DAPStoreValue(dd,z,&oldval)) != NULL ){
if( DAP_CRITICAL_ERROR(rc) ){
errorexit(threadNum,rc,"SV",dd);
}
else{
threadAtSay(threadNum,DAPTranslateReturnCode(rc));
}
}
WTStatus(threadNum, dd);
oldval = z; // remember z, and see if it comes back ok
if( (rc = DAPRecallValue(dd,&z)) != NULL ){
if( DAP_CRITICAL_ERROR(rc) ){
errorexit(threadNum,rc,"RV",dd);
}
else{
threadAtSay(threadNum,DAPTranslateReturnCode(rc));
}
}
WTStatus(threadNum, dd);
if( z != oldval ) threadAtSay(threadNum,"Can't Rem");
++iter;
}
}
if( (rc = DAPDeAllocateSession(dd)) != NULL ){
errorexit(threadNum,rc,"DAR",dd);
}
threadAtSay(threadNum,"Detached from server");
DAPDeInitialize(dd);
threadAtSay(threadNum,"DeInitialized okay");
ExitThread(EXIT_THREAD,0);
}
main(int argc, char *argv[])
{
int numclients;
int threadNum=0;
if( argc < 2 ){
printf("usage: stress <numClients> [outer] [inner]\n");
exit(1);
}
atexit(s_atexit);
semaIOHandle = OpenLocalSemaphore(1);
numclients = atoi(argv[1]);
if( argc == 4 ){
outerlimit = atoi(argv[2]);
innerlimit = atoi(argv[3]);
}
while( numclients-- ){
if(BeginThreadGroup(WorkerThread,NULL,8192,(void *)threadNum) == EFAILURE){
threadAtSay(threadNum,"Failed to start");
exit(1);
}
threadNum++;
ThreadSwitch();
}
return 0;
}