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