1# SPDX-License-Identifier: GPL-2.0-or-later 2#!/bin/sh 3# Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved. 4# Copyright (c) 2017-2020 Petr Vorel <pvorel@suse.cz> 5 6SERVER= 7CLIENT= 8CLIENT_EXTRA_OPTS= 9CLEANER= 10# Program number to register the services to rpcbind 11PROGNUMNOSVC=536875000 12 13TST_TESTFUNC=do_test 14TST_USAGE=usage 15TST_OPTS="c:e:s:" 16TST_SETUP=setup 17TST_CLEANUP=cleanup 18TST_PARSE_ARGS=rpc_parse_args 19TST_NEEDS_CMDS="pkill rpcinfo" 20. rpc_lib.sh 21 22usage() 23{ 24 cat << EOF 25USAGE: $0 [-s sprog] -c clprog [ -e extra ] 26 27Connect to the remote host and start sprog. 28Then execute clprog and passing it the remote host value. 29 30-c clprog client program binary 31-s sprog server program binary 32-e extra extra client options 33EOF 34} 35 36rpc_parse_args() 37{ 38 case "$1" in 39 c) CLIENT="$OPTARG" ;; 40 e) tst_check_cmds sed 41 CLIENT_EXTRA_OPTS="$(echo $OPTARG | sed 's/,/ /')" ;; 42 s) SERVER="$OPTARG" ;; 43 esac 44} 45 46setup() 47{ 48 check_portmap_rpcbind 49 50 if [ -n "$SERVER" ]; then 51 CLEANER="rpc_cleaner" 52 if echo "$SERVER" | grep -q '^tirpc'; then 53 CLEANER="tirpc_cleaner" 54 fi 55 fi 56 57 [ -n "$CLIENT" ] || tst_brk TBROK "client program not set" 58 tst_check_cmds $CLIENT $SERVER || tst_brk TCONF "LTP compiled without TI-RPC support?" 59 60 tst_cmd_available ldd which || return 61 if ldd $(which $CLIENT) |grep -q /libtirpc\.so; then 62 tst_res TINFO "using libtirpc: yes" 63 else 64 tst_res TINFO "using libtirpc: no (probably using glibc)" 65 fi 66} 67 68cleanup() 69{ 70 if [ "$SERVER_STARTED" ]; then 71 pkill -13 -x $SERVER 72 $CLEANER $PROGNUMNOSVC 73 fi 74} 75 76do_test() 77{ 78 local i 79 80 if [ -n "$SERVER" ]; then 81 $SERVER $PROGNUMNOSVC & 82 SERVER_STARTED=1 83 84 for i in $(seq 1 10); do 85 rpcinfo -p localhost | grep -q $PROGNUMNOSVC && break 86 [ "$i" -eq 10 ] && tst_brk TBROK "server not registered" 87 tst_sleep 100ms 88 done 89 fi 90 91 EXPECT_RHOST_PASS $CLIENT $(tst_ipaddr) $PROGNUMNOSVC $CLIENT_EXTRA_OPTS 92} 93 94tst_run 95