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# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 20# 21 22# default command-line options 23user_name="root" 24use_ssh=0 25clients_num=2 26client_requests=2000000 27max_requests=3 28 29TST_TOTAL=1 30TCID="tcp_fastopen" 31 32. test_net.sh 33 34bind_timeout=5 35tfo_result="${TMPDIR}/tfo_result" 36 37while getopts :hu:sr:p:n:R:6 opt; do 38 case "$opt" in 39 h) 40 echo "Usage:" 41 echo "h help" 42 echo "u x server user name" 43 echo "s use ssh to run remote cmds" 44 echo "n x num of clients running in parallel" 45 echo "r x the number of client requests" 46 echo "R x num of requests, after which conn. closed" 47 echo "6 run over IPv6" 48 exit 0 49 ;; 50 u) user_name=$OPTARG ;; 51 s) export TST_USE_SSH=1 ;; 52 n) clients_num=$OPTARG ;; 53 r) client_requests=$OPTARG ;; 54 R) max_requests=$OPTARG ;; 55 6) # skip, test_net library already processed it 56 ;; 57 *) tst_brkm TBROK "unknown option: $opt" ;; 58 esac 59done 60 61cleanup() 62{ 63 tst_resm TINFO "cleanup..." 64 tst_rhost_run -c "pkill -9 tcp_fastopen\$" 65 rm -f $tfo_result 66} 67 68TST_CLEANUP="cleanup" 69trap "tst_brkm TBROK 'test interrupted'" INT 70 71read_result_file() 72{ 73 if [ -f $tfo_result ]; then 74 if [ -r $tfo_result ]; then 75 cat $tfo_result 76 else 77 tst_brkm TBROK "Failed to read result file" 78 fi 79 else 80 tst_brkm TBROK "Failed to find result file" 81 fi 82} 83 84run_client_server() 85{ 86 # kill tcp server on remote machine 87 tst_rhost_run -c "pkill -9 tcp_fastopen\$" 88 89 port=$(tst_rhost_run -c "tst_get_unused_port ipv6 stream") 90 [ $? -ne 0 ] && tst_brkm TBROK "failed to get unused port" 91 92 # run tcp server on remote machine 93 tst_rhost_run -s -b -c "tcp_fastopen -R $max_requests $1 -g $port" 94 sleep $bind_timeout 95 96 # run local tcp client 97 tcp_fastopen -a $clients_num -r $client_requests -l \ 98 -H $(tst_ipaddr rhost) $1 -g $port -d $tfo_result 99 [ "$?" -ne 0 ] && tst_brkm TBROK "Last test has failed" 100 101 run_time=$(read_result_file) 102 103 [ -z "$run_time" -o "$run_time" -eq 0 ] && \ 104 tst_brkm TBROK "Last test result isn't valid: $run_time" 105} 106 107tst_require_root 108 109tst_kvercmp 3 7 0 110[ $? -eq 0 ] && tst_brkm TCONF "test must be run with kernel 3.7 or newer" 111 112tst_kvercmp 3 16 0 113[ $? -eq 0 -a "$TST_IPV6" ] && \ 114 tst_brkm TCONF "test must be run with kernel 3.16 or newer" 115 116run_client_server "-o -O" 117time_tfo_off=$run_time 118 119run_client_server 120time_tfo_on=$run_time 121 122tfo_cmp=$(( 100 - ($time_tfo_on * 100) / $time_tfo_off )) 123 124if [ "$tfo_cmp" -lt 3 ]; then 125 tst_resm TFAIL "TFO performance result is '$tfo_cmp' percent" 126else 127 tst_resm TPASS "TFO performance result is '$tfo_cmp' percent" 128fi 129 130tst_exit 131