Home | History | Annotate | Download | only in echo
      1 #!/bin/sh
      2 unset 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 program;  if not, write to the Free Software
     18 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 (at] us.ibm.com)
     31 #      -Ported
     32 #
     33 #
     34 #***********************************************************************
     35 
     36 #-----------------------------------------------------------------------
     37 #
     38 # FUNCTION:  do_setup
     39 #
     40 #-----------------------------------------------------------------------
     41 
     42 do_setup()
     43 {
     44 
     45     NUMLOOPS=${NUMLOOPS:-2}
     46     TST_TOTAL=$NUMLOOPS
     47 
     48     export TST_COUNT TST_TOTAL
     49 
     50     exists hostname sum
     51     tst_setup
     52 
     53     TC=sine
     54     RHOST=${RHOST:-`hostname`}
     55     TCtmp=${TCtmp:-$LTPROOT/testcases/bin/echo$$}
     56     CLEANUP=${CLEANUP:-ON}
     57     CREATEFILE=createfile
     58     ECHOES=echoes${EXEC_SUFFIX}
     59 
     60     ECHOFILE=${ECHOFILE:-echofile${EXEC_SUFFIX}}
     61     ECHOSIZE=${ECHOSIZE:-8192}
     62     NUMPROCESSES=${NUMPROCESSES:-10}
     63 
     64 }
     65 
     66 #-----------------------------------------------------------------------
     67 #
     68 # FUNCTION:  do_test
     69 # PURPOSE:   Loop until interrupted creating the echo file and then
     70 #	     echoing it to RHOST.
     71 # INPUT:     None.
     72 # OUTPUT:    Informational messages are logged into the run log.
     73 #
     74 #-----------------------------------------------------------------------
     75 
     76 do_test()
     77 {
     78     mkdir $TCtmp
     79     echo  "Creating echo file $ECHOFILE"
     80     if ! "$LTPROOT/testcases/bin/$CREATEFILE" $ECHOSIZE "$TCtmp/$ECHOFILE"; then
     81         end_testcase "$ECHOFILE not created"
     82     fi
     83 
     84     echo "Compute the checksum of this file"
     85     csum1=$(sum $TCtmp/$ECHOFILE | awk '{print $1}')
     86     [ $csum1 ] || end_testcase "initial checksum computation failed"
     87 
     88     while [ $TST_COUNT -le $NUMLOOPS ]; do
     89 
     90         if ! $ECHOES $RHOST "$TCtmp/$ECHOFILE" $NUMPROCESSES; then
     91             end_testcase "Error in $ECHOES test in loop $TST_COUNT"
     92         fi
     93 
     94         NUM=0
     95         while [ $NUM -lt $NUMPROCESSES ]
     96         do
     97             csum2=$(sum "$TCtmp/${ECHOFILE}${NUM}" | awk '{print $1}')
     98             if [ "$csum1" != "$csum2" ]; then
     99                 end_testcase "Checksums differ in loop $TST_COUNT"
    100             fi
    101             NUM=$(( $NUM + 1 ))
    102         done
    103 
    104         tst_resm TINFO "Execution $TST_COUNT passed."
    105 
    106         incr_tst_count
    107         if [ $TST_COUNT -le $NUMLOOPS ]; then
    108             tst_resm TINFO "Sleeping 60 seconds to avoid hitting max. connections setting for service"
    109             sleep 60
    110         fi
    111     done
    112 }
    113 
    114 #-----------------------------------------------------------------------
    115 #
    116 # FUNCTION:  MAIN
    117 # PURPOSE:   To invoke functions that perform the tasks as described in
    118 #	     the design in the prolog above.
    119 # INPUT:     See SETUP in the prolog above.
    120 # OUTPUT:    Logged run results written to testcase run log
    121 #
    122 #-----------------------------------------------------------------------
    123 
    124 . net_cmdlib.sh
    125 
    126 read_opts $*
    127 do_setup
    128 do_test
    129 end_testcase
    130