• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of
8# the License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it would be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# 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 the Free Software Foundation,
17# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18#
19# This is a wrapper script to execute tests from the RPC/TI-RPC tests
20# suite (http://nfsv4.bullopensource.org/doc/rpc_testsuite.php) in LTP
21#
22# This wrapper uses the RHOST environment variable:
23#
24# If the RHOST variable is set, then the rpc server instance (if needed)
25# is started on RHOST, using rsh, and the client program is passed
26# the RHOST value.
27#
28# If the RHOST variable is not set, then the rpc server instance (if needed)
29# is started on the local host, and the client program is passed `hostname`.
30
31SERVER_HOST=${RHOST:-`hostname`}
32SERVER=""
33CLIENT=""
34CLIENT_EXTRA_OPTS=""
35CLEANER=""
36# Program number to register the services to rpcbind
37PROGNUMNOSVC=536875000
38SERVER_STARTUP_SLEEP=1
39
40run_cmd()
41{
42	if [ ! -z "$RHOST" ]; then
43		rsh -n "$RHOST" "$1"
44	else
45		$1
46	fi
47}
48
49cleanup()
50{
51	if [ ! -z "$SERVER" ]; then
52		run_cmd "killall -9 $SERVER"
53		run_cmd "$CLEANER $PROGNUMNOSVC"
54	fi
55}
56
57usage()
58{
59	echo "USAGE: $0 [-s sprog] -c clprog [ -e extra ]"
60	echo ""
61	echo "sprog   - server program binary"
62	echo "clprog  - client program binary"
63	echo "extra   - extra client options"
64	echo ""
65	echo "This scripts connects to the RHOST host by rsh and starts"
66	echo "sprog there. After that it executes clprog passing it the"
67	echo "RHOST value."
68	echo "After the test completes, this script kills sprog on RHOST"
69	echo "and performs a cleaning operation."
70	echo ""
71	echo "If RHOST is not set, the local host is used."
72
73	exit 1
74}
75
76while getopts s:c:e:h arg; do
77	case $arg in
78		s) SERVER="$LTPROOT/testcases/bin/$OPTARG" ;;
79		c) CLIENT="$OPTARG" ;;
80		e) CLIENT_EXTRA_OPTS="$OPTARG" ;;
81		h) usage ;;
82	esac
83done
84
85if [ ! -z "$SERVER" ]; then
86	if `echo "$SERVER" | grep -e '^tirpc'`; then
87		CLEANER="$LTPROOT/testcases/bin/tirpc_cleaner"
88	else
89		CLEANER="$LTPROOT/testcases/bin/rpc_cleaner"
90	fi
91fi
92
93if [ -z "$CLIENT" ]; then
94	echo "client program not set"
95	echo ""
96	usage
97fi
98
99TCID="$CLIENT"
100TST_TOTAL=1
101TST_COUNT=1
102. test.sh
103TST_CLEANUP=cleanup
104
105if [ ! -z "$SERVER" ]; then
106	run_cmd "$SERVER $PROGNUMNOSVC" &
107	sleep "$SERVER_STARTUP_SLEEP"
108fi
109
110"$CLIENT" "$SERVER_HOST" "$PROGNUMNOSVC" $CLIENT_EXTRA_OPTS
111ret=$?
112
113if [ "$ret" -eq 0 ]; then
114	tst_resm TPASS "Test passed"
115else
116	tst_resm TFAIL "Test failed"
117fi
118
119tst_exit
120