Whamcloud - gitweb
LU-12511 utils: Move utilies specific values out of Lustre UAPI headers
[fs/lustre-release.git] / lustre / tests / lnet-selftest.sh
1 #!/bin/bash
2
3 LUSTRE=${LUSTRE:-$(dirname $0)/..}
4 . $LUSTRE/tests/test-framework.sh
5 init_test_env $@
6 init_logging
7
8 ALWAYS_EXCEPT="$LNET_SELFTEST_EXCEPT"
9 if (( $LINUX_VERSION_CODE >= $(version_code 4.4.0) )); then
10         # bug number for skipped test: LU-10073
11         ALWAYS_EXCEPT+="               smoke "
12 fi
13
14 if [[ $(uname -m) = ppc64 ]]; then
15         # bug number for skipped test: LU-10073
16         ALWAYS_EXCEPT+="               smoke "
17 fi
18
19 build_test_filter
20
21 [ x$LST = x ] && skip_env "lst not found LST=$LST"
22
23 # FIXME: what is the reasonable value here?
24 lst_LOOP=${lst_LOOP:-100000}
25 lst_CONCR=${lst_CONCR:-"1 2 4 8"}
26 lst_SIZES=${lst_SIZES:-"4k 8k 256k 1M"}
27 if [ "$SLOW" = no ]; then
28     lst_CONCR="1 8"
29     lst_SIZES="4k 1M"
30     lst_LOOP=1000
31 fi
32
33 smoke_DURATION=${smoke_DURATION:-1800}
34 if [ "$SLOW" = no ]; then
35     [ $smoke_DURATION -le 300 ] || smoke_DURATION=300
36 fi
37
38 lst_TESTS=${lst_TESTS:-"write read ping"}
39
40 # "none" -> LST_BRW_CHECK_NONE
41 # "full" -> LST_BRW_CHECK_FULL
42 # "simple" -> LST_BRW_CHECK_SIMPLE
43 lst_CHECK=${lst_CHECK:-"full"}
44
45 lst_FROM=${lst_FROM:-"cs"}
46
47 case $lst_CHECK in
48         full|simple) check="check=$lst_CHECK";;
49         none) check="";;
50         *) error Unknown flag $lst_CHECK;;
51 esac
52 nodes=$(comma_list "$(osts_nodes) $(mdts_nodes)")
53 lst_SERVERS=${lst_SERVERS:-$(comma_list "$(host_nids_address $nodes $NETTYPE)")}
54 lst_CLIENTS=${lst_CLIENTS:-$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")}
55 interim_umount=false
56 interim_umount1=false
57
58 #
59 # _restore_mount(): This function calls restore_mount function for "MOUNT" and
60 # "MOUNT2" paths to mount clients if they were not mounted and were umounted
61 # in this file earlier.
62 # Parameter: None
63 # Returns: None. Exit with error if client mount fails.
64 #
65 _restore_mount () {
66         if $interim_umount && ! is_mounted $MOUNT; then
67                 restore_mount $MOUNT || error "Restore $MOUNT failed"
68         fi
69
70         if $interim_umount1 && ! is_mounted $MOUNT2; then
71                 restore_mount $MOUNT2 || error "Restore $MOUNT2 failed"
72         fi
73 }
74
75 if local_mode; then
76    lst_SERVERS=`hostname`
77    lst_CLIENTS=`hostname`
78 fi
79
80 # FIXME: do we really need to unload lustre modules on all nodes?
81 # bug 19387, comment 9
82 # unloading lustre modules is not strictly necessary but unmounting
83 # /mnt/lustre before running lst would be useful:
84 # 1) because lustre messages clutter logs - we needn't them for testing LNET
85 # 2) it's theoretically possible that lst tests congest comm paths so tightly
86 # that mounted lustre wouldn't able to perform some of its background activities
87 if is_mounted $MOUNT; then
88         cleanup_mount $MOUNT || error "Fail to unmount client $MOUNT"
89         interim_umount=true
90 fi
91
92 if is_mounted $MOUNT2; then
93         cleanup_mount $MOUNT2 || error "Fail to unmount client $MOUNT2"
94         interim_umount1=true
95 fi
96
97 lst_prepare () {
98     # Workaround for bug 15619
99     lst_cleanup_all
100     lst_setup_all
101 }
102
103 # make batch
104 test_smoke_sub () {
105     local servers=$1
106     local clients=$2
107
108     local nc=$(echo ${clients//,/ } | wc -w)
109     local ns=$(echo ${servers//,/ } | wc -w)
110     echo '#!/bin/bash'
111     echo 'set -e'
112
113     echo 'cleanup () { trap 0; echo killing $1 ... ; kill -9 $1 || true; }'
114
115     echo "$LST new_session --timeo 100000 hh"
116     echo "$LST add_group c $(nids_list $clients)"
117     echo "$LST add_group s $(nids_list $servers)"
118     echo "$LST add_batch b"
119
120         declare -a tests
121
122         case $lst_FROM in
123                 c) tests[0]="${nc}:${ns} --from c --to s";;
124                 s) tests[0]="${ns}:${nc} --from s --to c";;
125                 cs)tests[0]="${nc}:${ns} --from c --to s"
126                    tests[1]="${ns}:${nc} --from s --to c";;
127                 *) error Unknown flag $lst_FROM;;
128         esac
129
130         pre="$LST add_test --batch b --loop $lst_LOOP "
131         for t in $lst_TESTS; do
132                 for s in $lst_SIZES; do
133                         for c in $lst_CONCR; do
134                                 for ((i=0; i<${#tests[@]}; i++)); do
135                                         echo -n "$pre --concurrency $c"\
136                                                 " --distribute ${tests[i]} "
137                                         case $t in
138                                                 read|write)
139                                                         echo -n "brw $t" \
140                                                         " $check size=$s";;
141                                                 ping)
142                                                         echo -n $t;;
143                                                 *) error Unknonwn LST test;;
144                                         esac
145                                         echo
146                                 done
147                         done
148                 done
149         done
150
151     echo $LST run b
152     echo sleep 1
153     echo "$LST stat --delay 10 --timeout 10 c s &"
154     echo 'pid=$!'
155     echo 'trap "cleanup $pid" INT TERM'
156     echo sleep $smoke_DURATION
157     echo 'cleanup $pid'
158     
159 }
160
161 run_lst () {
162    local file=$1
163
164    export LST_SESSION=$$
165
166    # start lst
167    sh $file
168 }
169
170 check_lst_err () {
171         local log=$1
172
173         grep ^Total $log
174
175         if awk '/^Total.*nodes/ {print $2}' $log | grep -vq '^0$'; then
176                 _restore_mount
177                 error 'lst Error found'
178         fi
179 }
180
181 test_smoke () {
182         lst_prepare
183
184         local servers=$lst_SERVERS
185         local clients=$lst_CLIENTS
186
187         local runlst=$TMP/smoke.sh
188
189         local log=$TMP/$tfile.log
190         local rc=0
191
192         test_smoke_sub $servers $clients 2>&1 > $runlst
193
194         cat $runlst
195
196         run_lst $runlst | tee $log
197         rc=${PIPESTATUS[0]}
198         [ $rc = 0 ] || { _restore_mount; error "$runlst failed: $rc"; }
199
200         lst_end_session --verbose | tee -a $log
201
202         # error counters in "lst show_error" should be checked
203         check_lst_err $log
204         lst_cleanup_all
205 }
206 run_test smoke "lst regression test"
207
208 complete $SECONDS
209 _restore_mount
210 check_and_cleanup_lustre
211 exit_status