Home | History | Annotate | Download | only in rwho
      1 #!/bin/sh
      2 #
      3 #   Copyright (c) International Business Machines  Corp., 2000
      4 #
      5 #   This program is free software;  you can redistribute it and/or modify
      6 #   it under the terms of the GNU General Public License as published by
      7 #   the Free Software Foundation; either version 2 of the License, or
      8 #   (at your option) any later version.
      9 #
     10 #   This program is distributed in the hope that it will be useful,
     11 #   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13 #   the GNU General Public License for more details.
     14 #
     15 #   You should have received a copy of the GNU General Public License
     16 #   along with this program;  if not, write to the Free Software
     17 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18 #
     19 #
     20 #
     21 #  FILE   : rwho
     22 #
     23 #  PURPOSE: To test the basic functionality of the rwhod daemon using the
     24 #           `rwho` and `ruptime` commands.
     25 #
     26 #  SETUP: The home directory of root on the machine exported as "RHOST"
     27 #         MUST have a ".rhosts" file with the hostname of the machine
     28 #         where the test is executed. Also, both machines MUST have
     29 #         the rwhod daemon installed. However, it does not need to be
     30 #         active, the test will handle this.
     31 #
     32 #  HISTORY:
     33 #    06/09 Manoj Iyer manjo (at] mail.utexas.edu
     34 #    - Modified to use test harness API and also fix defects
     35 #    03/01 Robbie Williamson (robbiew (at] us.ibm.com)
     36 #      -Ported
     37 #
     38 #
     39 #==============================================================================
     40 # error codes:  0 rwho/ruptime successful
     41 #             1 rwho failed no local and remote host in file
     42 #             2 ruptime failed no local and remote host in file
     43 #==============================================================================
     44 
     45 #-----------------------------------------------------------------------
     46 #
     47 # FUNCTION:  do_setup
     48 #
     49 #-----------------------------------------------------------------------
     50 
     51 LHOST_PID=""
     52 RHOST_PID=""
     53 
     54 do_setup()
     55 {
     56     TCtmp=${TCtmp:-$LTPROOT/testcases/bin/$TC${EXEC_SUFFIX}$$}
     57 
     58     SLEEPTIME=${SLEEPTIME:-5}
     59     NUMLOOPS=${NUMLOOPS:-25}
     60     OUTFILE=${OUTFILE:-$TCtmp/${TC}.out}
     61 
     62     tst_setup
     63 
     64     exists awk cut hostname killall ps rsh rwho
     65 
     66     LHOST=`hostname | cut -f1 -d.`
     67     RHOST=${RHOST:-$LHOST}
     68 
     69     trap do_cleanup EXIT
     70 
     71     if ! pgrep -x rwhod > /dev/null; then
     72         tst_resm TINFO "Starting rwhod on $LHOST"
     73         rwhod || end_testcase "Unable to start rwhod on $LHOST"
     74         LHOST_PID=$(pgrep -x rwhod)
     75         sleep $SLEEPTIME
     76     fi
     77 
     78     if [ "$(rsh -n -l root $RHOST pgrep -x rwhod)" == "" ]; then
     79         tst_resm TINFO "Starting rwhod on $RHOST"
     80         rsh -n -l root $RHOST /usr/sbin/rwhod
     81         RHOST_PID=$(rsh -n -l root $RHOST pgrep -x rwhod)
     82         if [ -z "$RHOST_PID" ]; then
     83             end_testcase "Unable to start rwhod on $RHOST"
     84         fi
     85         sleep $SLEEPTIME
     86     fi
     87 
     88     RHOSTNAME=`rsh -n -l root $RHOST hostname | cut -f1 -d.`
     89     if [ -z "$RHOSTNAME" ]; then
     90         end_testcase "Unable to determine RHOSTNAME"
     91     fi
     92 }
     93 
     94 #-----------------------------------------------------------------------
     95 #
     96 # FUNCTION:  do_test
     97 #
     98 #-----------------------------------------------------------------------
     99 
    100 do_test()
    101 {
    102     while [ $TST_COUNT -le $NUMLOOPS ]; do
    103         rwho -a > $OUTFILE
    104         HOST=`grep $LHOST $OUTFILE | sed 's/[^ ]* *//; s/:.*//' | uniq`
    105         [ "$HOST" = "$LHOST" ] || end_testcase "$LHOST is not in rwho outfile"
    106         HOST=`grep $RHOSTNAME $OUTFILE | sed 's/[^ ]* *//; s/:.*//' | uniq`
    107         [ "$HOST" = "$RHOSTNAME" ] || end_testcase "$RHOSTNAME is not in rwho outfile"
    108 
    109         ruptime -a > $OUTFILE
    110         HOST=`grep $LHOST $OUTFILE | sed 's/ .*//' | uniq`
    111         [ "$HOST" = "$LHOST" ] || end_testcase "$LHOST is not in ruptime outfile"
    112         HOST=`grep $RHOSTNAME $OUTFILE | sed 's/ .*//' | uniq`
    113         [ "$HOST" = "$RHOSTNAME" ] || end_testcase "$RHOSTNAME is not in ruptime outfile"
    114 
    115         tst_resm TINFO "Test $TST_COUNT of $NUMLOOPS complete"
    116         incr_tst_count
    117     done
    118 }
    119 
    120 #-----------------------------------------------------------------------
    121 #
    122 # FUNCTION:  do_cleanup
    123 #
    124 #-----------------------------------------------------------------------
    125 
    126 do_cleanup()
    127 {
    128     if [ -n "$LHOST_PID" ]; then
    129         tst_resm TINFO "Stopping rwhod on $LHOST"
    130         killall rwhod
    131     fi
    132 
    133     if [ -n "$RHOST_PID" ]; then
    134         tst_resm TINFO "Stopping rwhod on $RHOST"
    135         rsh -n -l root $RHOST "killall rwhod"
    136     fi
    137 
    138     tst_cleanup
    139 }
    140 
    141 #-----------------------------------------------------------------------
    142 #
    143 # FUNCTION:  MAIN
    144 #
    145 #-----------------------------------------------------------------------
    146 . net_cmdlib.sh
    147 
    148 read_opts $*
    149 do_setup
    150 do_test
    151 do_cleanup
    152 end_testcase
    153