echo01 revision 0db44a52ea6c12ebb0fb48f4428256f47e02ac55
1#!/bin/sh
2unset LIBPATH
3#
4#   Copyright (c) International Business Machines  Corp., 2000
5#
6#   This program is free software;  you can redistribute it and/or modify
7#   it under the terms of the GNU General Public License as published by
8#   the Free Software Foundation; either version 2 of the License, or
9#   (at your option) any later version.
10#
11#   This program is distributed in the hope that it will be useful,
12#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
13#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14#   the GNU General Public License for more details.
15#
16#   You should have received a copy of the GNU General Public License
17#   along with this pronram;  if not, write to the Free Software
18#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19#
20#
21#
22#  FILE   : echo
23#
24#  PURPOSE: Stresses the inetd/xinetd daemon using the `echo` service.
25#           
26#  SETUP: The echo service MUST be active on the RHOST machine. This is
27#         controlled by the inetd/xinetd daemon.
28#
29#  HISTORY:
30#    03/01 Robbie Williamson (robbiew@us.ibm.com)
31#      -Ported
32#
33#
34#***********************************************************************
35#Uncomment line below for debug output.
36#trace_logic=${trace_logic:-"set -x"}
37$trace_logic
38
39TC=sine
40RHOST=${RHOST:-`hostname`}
41TCbin=${TCbin:-`pwd`}
42TCsrc=${TCsrc:-$TCbin}
43TCtmp=${TCtmp:-$TCsrc/echo$$}
44CLEANUP=${CLEANUP:-ON}
45CREATFILE=createfile
46ECHOES=echoes
47
48EXECUTABLES=${EXECUTABLES:-"$CREATFILE $ECHOES"}
49ECHOFILE=${ECHOFILE:-echofile}
50ECHOSIZE=${ECHOSIZE:-8192}
51NUMLOOPS=${NUMLOOPS:-2}
52NUMPROCESSES=${NUMPROCESSES:-10}
53
54#-----------------------------------------------------------------------
55#
56# FUNCTION:  do_test
57# PURPOSE:   Loop until interrupted creating the echo file and then
58#	     echoing it to RHOST.
59# INPUT:     None.
60# OUTPUT:    Informational messages are logged into the run log.
61#
62#-----------------------------------------------------------------------
63
64do_test() 
65{
66   $trace_logic
67   mkdir $TCtmp 
68   echo  "Creating echo file $ECHOFILE"
69   $TCbin/$CREATFILE $ECHOSIZE $TCtmp/$ECHOFILE
70   [[ $? = 0 ]] || end_testcase "$ECHOFILE not created"
71
72   echo "Compute the checksum of this file"
73   csum1=`sum $TCtmp/$ECHOFILE |awk '{print $1}'`
74   [ $csum1 ] || end_testcase "initial checksum computation failed"
75
76   COUNT=1
77   while [[ $COUNT -le $NUMLOOPS ]]
78   do
79      $TCbin/$ECHOES $RHOST $TCtmp/$ECHOFILE $NUMPROCESSES
80      [[ $? = 0 ]] || end_testcase "Error in $ECHOES test in loop $COUNT"
81
82      NUM=0
83      while [[ $NUM -lt $NUMPROCESSES ]]
84      do
85         csum2=`sum $TCtmp/$ECHOFILE\$NUM |awk '{print $1}'`
86         [[ "$csum1" -eq "$csum2" ]] || end_testcase "Checksums differ in loop $COUNT"
87         NUM=`expr $NUM + 1`
88      done
89
90      echo "Successful execution for loop $COUNT" 
91      COUNT=`expr $COUNT + 1`
92      if [[ $COUNT -le $NUMLOOPS ]]; then
93        echo "Sleeping 60 seconds to avoid hitting max. connections setting for service"
94        sleep 60
95      fi
96   done
97}
98
99#-----------------------------------------------------------------------
100#
101# FUNCTION:	do_cleanup
102# PURPOSE:	Called when the testcase is interrupted by the user
103#		or by interrupt_testcase() when time limit expired
104# INPUT:	None.
105# OUTPUT:	None.
106#
107#-----------------------------------------------------------------------
108
109do_cleanup()
110{
111   $trace_logic
112
113   cd /
114   if [[ $TCtmp = $TCsrc ]]; then
115      rm -f $TCtmp/echofile*
116   else
117      rm -rf $TCtmp
118   fi
119}
120
121#=============================================================================
122# FUNCTION NAME:        end_testcase
123# 
124# FUNCTION DESCRIPTION: Clean up
125# 
126# PARAMETERS:           string, IF AND ONLY IF the testcase fails
127# 
128# RETURNS:              None.
129#=============================================================================
130
131end_testcase()
132{  
133   $trace_logic
134    
135   # Call other cleanup functions
136   [[ $CLEANUP = "ON" ]] && do_cleanup
137
138   [[ $# -eq 0 ]] && { echo "Test Successful"; exit 0; }
139   echo "Test Failed: $@"
140   echo""
141   echo "***NOTE***"
142   echo "Make sure the streamed echo is uncommented in inetd.conf"
143   echo "on the server. Also try increasing max connections from"
144   echo "default of 40, i.e. nowait.400"
145   exit 1
146}   
147
148#-----------------------------------------------------------------------
149#
150# FUNCTION:  MAIN
151# PURPOSE:   To invoke functions that perform the tasks as described in
152#	     the design in the prolog above.
153# INPUT:     See SETUP in the prolog above.
154# OUTPUT:    Logged run results written to testcase run log
155#
156#-----------------------------------------------------------------------
157do_test
158end_testcase
159