Imported Upstream version 3.13.6
[platform/upstream/nss.git] / mozilla / security / nss / tests / ssl / ssl_dist_stress.sh
1 #! /bin/bash
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 #
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
10 #
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
15 #
16 # The Original Code is the Netscape security libraries.
17 #
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1994-2009
21 # the Initial Developer. All Rights Reserved.
22 #
23 # Contributor(s):
24 #
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
36 #
37 # ***** END LICENSE BLOCK *****
38
39 ########################################################################
40 #
41 # mozilla/security/nss/tests/ssl/ssl_dist_stress.sh
42 #
43 # Script to test NSS SSL - distributed stresstest - this script needs to 
44 # source the regular ssl.sh (for shellfunctions, certs and variables 
45 # initialisation)
46 # create certs
47 # start server
48 # start itself via rsh on different systems to connect back to the server
49
50 #
51 # needs to work on all Unix and Windows platforms
52 #
53 # special strings
54 # ---------------
55 #   FIXME ... known problems, search for this string
56 #   NOTE .... unexpected behavior
57 #
58 ########################################################################
59
60 ############################## ssl_ds_init #############################
61 # local shell function to initialize this script
62 ########################################################################
63 ssl_ds_init()
64 {
65   if [ -z "$GLOB_MIN_CERT" ] ; then
66       GLOB_MIN_CERT=0
67   fi
68   if [ -z "$GLOB_MAX_CERT" ] ; then
69       GLOB_MAX_CERT=200
70   fi
71   IP_PARAM=""
72   CD_QADIR_SSL=""
73
74
75   if [ -n "$1" ] ; then
76       ssl_ds_eval_opts $*
77   fi
78   SCRIPTNAME=ssl_dist_stress.sh      # sourced - $0 would point to all.sh
79
80   if [ -z "${CLEANUP}" ] ; then     # if nobody else is responsible for
81       CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
82   fi
83   
84   ssl_init  # let some other script do the hard work (initialize, generate certs, ...
85
86   SCRIPTNAME=ssl_dist_stress.sh
87   echo "$SCRIPTNAME: SSL distributed stress tests ==============================="
88
89 }
90
91 ######################### ssl_ds_usage #################################
92 # local shell function to explain the usage
93 ########################################################################
94 ssl_ds_usage()
95 {
96   echo "Usage: `basename $1`"
97   echo "        -host hostname "
98   echo "           ...host who runs the server, for distributed stress test"
99   echo "        -stress "
100   echo "           ...runs the server sider of the distributed stress test"
101   echo "        -dir unixdirectory "
102   echo "           ...lets the server side of the distributed stress test"
103   echo "              know where to find the scritp to start on the remote side"
104   echo "        -certnum start-end"
105   echo "           ... provides the range of certs for distributed stress test"
106   echo "               for example -certnum 10-20 will connect 10 times"
107   echo "               no blanks in the range string (not 10 - 20)"
108   echo "               valid range ${GLOB_MIN_CERT}-${GLOB_MAX_CERT}"
109   echo "        -? ...prints this text"
110   exit 1 #does not need to be Exit, very early in script
111 }
112
113 ######################### ssl_ds_eval_opts #############################
114 # local shell function to deal with options and parameters
115 ########################################################################
116 ssl_ds_eval_opts()
117 {
118     #use $0 not $SCRIPTNAM<E, too early, SCRIPTNAME not yet set
119
120   while [ -n "$1" ]
121   do
122     case $1 in
123         -host)
124             BUILD_OPT=1
125             export BUILD_OPT
126             DO_REM_ST="TRUE"
127             shift
128             SERVERHOST=$1
129             HOST=$1
130             if [ -z $SERVERHOST ] ; then
131                 echo "$0 `uname -n`: -host requires hostname"
132                 ssl_ds_usage
133             fi
134             echo "$0 `uname -n`: host $HOST ($1)"
135             ;;
136         -certn*)
137             shift
138             rangeOK=`echo $1  | sed -e 's/[0-9][0-9]*-[0-9][0-9]*/OK/'`
139             MIN_CERT=`echo $1 | sed -e 's/-[0-9][0-9]*//' -e 's/^00*//'`
140             MAX_CERT=`echo $1 | sed -e 's/[0-9][0-9]*-//' -e 's/^00*//'`
141             if [ -z "$rangeOK" -o "$rangeOK" != "OK" -o \
142                          -z "$MIN_CERT" -o -z "$MAX_CERT" -o \
143                         "$MIN_CERT" -gt "$MAX_CERT" -o \
144                         "$MIN_CERT" -lt "$GLOB_MIN_CERT" -o \
145                         "$MAX_CERT" -gt "$GLOB_MAX_CERT" ] ; then
146                 echo "$0 `uname -n`: -certn range not valid"
147                 ssl_ds_usage
148             fi
149             echo "$0 `uname -n`: will use certs from $MIN_CERT to $MAX_CERT"
150             ;;
151         -server|-stress|-dist*st*)
152             BUILD_OPT=1
153             export BUILD_OPT
154             DO_DIST_ST="TRUE"
155             ;;
156         -dir|-unixdir|-uxdir|-qadir)
157             shift
158             UX_DIR=$1
159             #FIXME - we need a default unixdir
160             if [ -z "$UX_DIR" ] ; then # -o ! -d "$UX_DIR" ] ; then can't do, Win doesn't know...
161                 echo "$0 `uname -n`: -dir requires directoryname "
162                 ssl_ds_usage
163             fi
164             CD_QADIR_SSL="cd $UX_DIR"
165             ;;
166         -ip*)
167             shift
168             IP_ADDRESS=$1
169             if [ -z "$IP_ADDRESS" ] ; then
170                 echo "$0 `uname -n`: -ip requires ip-address "
171                 ssl_ds_usage
172             fi
173             USE_IP=TRUE
174             IP_PARAM="-ip $IP_ADDRESS"
175             ;;
176         -h|-help|"-?"|*)
177             ssl_ds_usage
178             ;;
179     esac
180     shift
181   done
182 }
183
184 ############################## ssl_ds_rem_stress #######################
185 # local shell function to perform the client part of the SSL stress test
186 ########################################################################
187
188 ssl_ds_rem_stress()
189 {
190   testname="SSL remote part of Stress test (`uname -n`)"
191   echo "$SCRIPTNAME `uname -n`: $testname"
192
193   #cp -r "${CLIENTDIR}" /tmp/ssl_ds.$$ #FIXME
194   #cd /tmp/ssl_ds.$$
195   #verbose="-v"
196
197   cd ${CLIENTDIR}
198
199   CONTINUE=$MAX_CERT
200   while [ $CONTINUE -ge $MIN_CERT ]
201   do
202       echo "strsclnt -D -p ${PORT} -d ${P_R_CLIENTDIR} -w nss -c 1 $verbose  "
203       echo "         -n TestUser$CONTINUE ${HOSTADDR} #`uname -n`"
204       ${BINDIR}/strsclnt -D -p ${PORT} -d . -w nss -c 1 $verbose  \
205                -n "TestUser$CONTINUE" ${HOSTADDR} &
206                #${HOSTADDR} &
207       CONTINUE=`expr $CONTINUE - 1 `
208       #sleep 4 #give process time to start up
209   done
210
211   html_msg 0 0 "${testname}" #FIXME
212 }
213
214 ######################### ssl_ds_dist_stress ###########################
215 # local shell function to perform the server part of the new, distributed 
216 # SSL stress test
217 ########################################################################
218
219 ssl_ds_dist_stress()
220 {
221   max_clientlist=" 
222                box-200
223                washer-200
224                dryer-200
225                hornet-50
226                shabadoo-50
227                y2sun2-10
228                galileo-10
229                shame-10
230                axilla-10
231                columbus-10
232                smarch-10
233                nugget-10
234                charm-10
235                hp64-10
236                biggayal-10
237                orville-10
238                kwyjibo-10
239                hbombaix-10
240                raven-10
241                jordan-10
242                phaedrus-10
243                louie-10
244                trex-10
245                compaqtor-10"
246
247   #clientlist=" huey-2 dewey-2 hornet-2 shabadoo-2" #FIXME ADJUST
248   clientlist="  box-200 washer-200 huey-200 dewey-200 hornet-200 shabadoo-200 louie-200"
249   #clientlist="  box-2 huey-2 "
250   #clientlist="washer-200 huey-200 dewey-200 hornet-200 "
251
252   html_head "SSL Distributed Stress Test"
253
254   testname="SSL distributed Stress test"
255
256   echo cd "${CLIENTDIR}"
257   cd "${CLIENTDIR}"
258   if [ -z "CD_QADIR_SSL" ] ; then
259       CD_QADIR_SSL="cd $QADIR/ssl"
260   else
261       cp -r $HOSTDIR $HOSTDIR/../../../../../booboo_Solaris8/mozilla/tests_results/security
262   fi
263
264   #sparam=" -t 128 -D -r "
265   sparam=" -t 16 -D -r -r -y "
266   start_selfserv
267
268   for c in $clientlist
269   do
270       client=`echo $c | sed -e "s/-.*//"`
271       number=`echo $c | sed -e "s/.*-//"`
272       CLIENT_OK="TRUE"
273       echo $client
274       ping $client >/dev/null || CLIENT_OK="FALSE"
275       if [ "$CLIENT_OK" = "FALSE" ] ; then
276           echo "$SCRIPTNAME `uname -n`: $client can't be reached - skipping"
277       else
278           get_certrange $number
279           echo "$SCRIPTNAME `uname -n`: $RSH $client -l svbld \\ "
280           echo "       \" $CD_QADIR_SSL ;ssl_dist_stress.sh \\"
281           echo "            -host $HOST -certnum $CERTRANGE $IP_PARAM \" "
282           $RSH $client -l svbld \
283                " $CD_QADIR_SSL;ssl_dist_stress.sh -host $HOST -certnum $CERTRANGE $IP_PARAM " &
284       fi
285   done
286
287   echo cd "${CLIENTDIR}"
288   cd "${CLIENTDIR}"
289
290   sleep 500 # give the clients time to finish #FIXME ADJUST
291  
292   echo "GET /stop HTTP/1.0\n\n" > stdin.txt #check to make sure it has /r/n
293   echo "tstclnt -h $HOSTADDR -p  8443 -d ${P_R_CLIENTDIR} -n TestUser0 "
294   echo "        -w nss -f < stdin.txt"
295   ${BINDIR}/tstclnt -h $HOSTADDR -p  8443 -d ${P_R_CLIENTDIR} -n TestUser0 \
296           -w nss -f < stdin.txt
297   
298   html_msg 0 0 "${testname}"
299   html "</TABLE><BR>"
300 }
301
302 ############################ get_certrange #############################
303 # local shell function to find the range of certs that the next remote 
304 # client is supposed to use (only for server side of the dist stress test
305 ########################################################################
306 get_certrange()
307 {
308   rangeOK=`echo $1  | sed -e 's/[0-9][0-9]*/OK/'`
309   if [ -z "$rangeOK" -o "$rangeOK" != "OK" -o $1 = "OK" ] ; then
310       range=10
311       echo "$SCRIPTNAME `uname -n`: $1 is not a valid number of certs "
312       echo "        defaulting to 10 for $client"
313   else
314       range=$1
315       if [ $range -gt $GLOB_MAX_CERT ] ; then
316           range=$GLOB_MAX_CERT
317       fi
318   fi
319   if [ -z "$FROM_CERT" ] ; then    # start new on top of the cert stack
320       FROM_CERT=$GLOB_MAX_CERT
321   elif [ `expr $FROM_CERT - $range + 1 ` -lt  0 ] ; then 
322           FROM_CERT=$GLOB_MAX_CERT # dont let it fall below 0 on the TO_CERT
323
324   fi
325   TO_CERT=`expr $FROM_CERT - $range + 1 `
326   if [ $TO_CERT -lt 0 ] ; then     # it's not that I'm bad in math, I just 
327       TO_CERT=0                    # don't trust expr...
328   fi
329   CERTRANGE="${TO_CERT}-${FROM_CERT}"
330   FROM_CERT=`expr ${TO_CERT} - 1 ` #start the next  client one below 
331 }
332
333
334 ################## main #################################################
335
336 DO_DIST_ST="TRUE"
337 . ./ssl.sh
338 ssl_ds_init $*
339 if [ -n  "$DO_REM_ST" -a "$DO_REM_ST" = "TRUE" ] ; then
340     ssl_ds_rem_stress
341     exit 0 #no cleanup on purpose
342 elif [ -n  "$DO_DIST_ST" -a "$DO_DIST_ST" = "TRUE" ] ; then
343     ssl_ds_dist_stress
344 fi
345 ssl_cleanup