echo01 revision 1e3f8609f62afebf3be544c8751b6fddb277b70d
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}
44CLEANUP=${CLEANUP:-ON}
45CREATFILE=createfile
46ECHOES=echoes
47
48EXECUTABLES=${EXECUTABLES:-"$CREATFILE $ECHOES"}
49ECHOFILE=${ECHOFILE:-echofile}
50NUMLOOPS=${NUMLOOPS:-2}
51NUMPROCESSES=${NUMPROCESSES:-10}
52
53#-----------------------------------------------------------------------
54#
55# FUNCTION:  do_test
56# PURPOSE:   Loop until interrupted creating the echo file and then
57#	     echoing it to RHOST.
58# INPUT:     None.
59# OUTPUT:    Informational messages are logged into the run log.
60#
61#-----------------------------------------------------------------------
62
63do_test() 
64{
65   $trace_logic
66
67   echo  "Creating echo file $ECHOFILE"
68   $TCtmp/$CREATFILE 6144 $TCtmp/$ECHOFILE
69   [[ $? = 0 ]] || end_testcase "$ECHOFILE not created"
70
71   echo "Compute the checksum of this file"
72   csum1=`sum $TCtmp/$ECHOFILE |awk '{print $1}'`
73   [ $csum1 ] || end_testcase "initial checksum computation failed"
74
75   COUNT=1
76   while [[ $COUNT -le $NUMLOOPS ]]
77   do
78      $TCtmp/$ECHOES $RHOST $TCtmp/$ECHOFILE $NUMPROCESSES
79      [[ $? = 0 ]] || end_testcase "Error in $ECHOES test in loop $COUNT"
80
81      NUM=0
82      while [[ $NUM -lt $NUMPROCESSES ]]
83      do
84         csum2=`sum $TCtmp/$ECHOFILE\$NUM |awk '{print $1}'`
85         [[ "$csum1" -eq "$csum2" ]] || end_testcase "Checksums differ in loop $COUNT"
86         NUM=`expr $NUM + 1`
87      done
88
89      echo "Successful execution for loop $COUNT" 
90      COUNT=`expr $COUNT + 1`
91   done
92}
93
94#-----------------------------------------------------------------------
95#
96# FUNCTION:	do_cleanup
97# PURPOSE:	Called when the testcase is interrupted by the user
98#		or by interrupt_testcase() when time limit expired
99# INPUT:	None.
100# OUTPUT:	None.
101#
102#-----------------------------------------------------------------------
103
104do_cleanup()
105{
106   $trace_logic
107
108   cd /
109   if [[ $TCtmp = $TCsrc ]]; then
110      rm -f $TCtmp/echofile*
111   else
112      rm -rf $TCtmp
113   fi
114}
115
116#=============================================================================
117# FUNCTION NAME:        end_testcase
118# 
119# FUNCTION DESCRIPTION: Clean up
120# 
121# PARAMETERS:           string, IF AND ONLY IF the testcase fails
122# 
123# RETURNS:              None.
124#=============================================================================
125
126end_testcase()
127{  
128   $trace_logic
129    
130   # Call other cleanup functions
131   [[ $CLEANUP = "ON" ]] && do_cleanup
132
133   [[ $# -eq 0 ]] && { echo "Test Successful"; exit 0; }
134   echo "Test Failed: $@"
135   echo""
136   echo "***NOTE***"
137   echo "Make sure the streamed echo is uncommented in inetd.conf"
138   echo "on the server. Also try increasing max connections from"
139   echo "default of 40, i.e. nowait.400"
140   exit 1
141}   
142
143#-----------------------------------------------------------------------
144#
145# FUNCTION:  MAIN
146# PURPOSE:   To invoke functions that perform the tasks as described in
147#	     the design in the prolog above.
148# INPUT:     See SETUP in the prolog above.
149# OUTPUT:    Logged run results written to testcase run log
150#
151#-----------------------------------------------------------------------
152do_test
153end_testcase
154