Whamcloud - gitweb
LU-13745 tests: skip sanity test_426 for 4.18+
[fs/lustre-release.git] / lustre / tests / sanity-benchmark.sh
1 #!/bin/bash
2 #
3 # Test basic functionality of the filesystem using simple
4 # benchmarks.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
13 init_test_env $@
14 init_logging
15
16 ALWAYS_EXCEPT="$SANITY_BENCHMARK_EXCEPT"
17 [ "$SLOW" = "no" ] && EXCEPT_SLOW="iozone"
18
19 build_test_filter
20
21 MAX_THREADS=${MAX_THREADS:-20}
22 RAMKB=$(awk '/MemTotal:/ { print $2 }' /proc/meminfo)
23 if [ -z "$THREADS" ]; then
24         THREADS=$((RAMKB / 16384))
25         [ $THREADS -gt $MAX_THREADS ] && THREADS=$MAX_THREADS
26 fi
27 SIZE=${SIZE:-$((RAMKB * 2))}
28 RSIZE=${RSIZE:-512}
29
30 DEBUG_LVL=${DEBUG_LVL:-0}
31 DEBUG_OFF=${DEBUG_OFF:-"eval lctl set_param debug=\"$DEBUG_LVL\""}
32 DEBUG_ON=${DEBUG_ON:-"eval lctl set_param debug=0x33f0484"}
33 DIRECTIO=${DIRECTIO:-directio}
34
35 check_and_setup_lustre
36
37 assert_DIR
38 rm -rf $DIR/[df][0-9]*
39
40 test_dbench() {
41     if ! which dbench > /dev/null 2>&1 ; then
42         skip_env "No dbench installed"
43         return
44     fi
45
46     local DBENCHDIR=$DIR/d0.$HOSTNAME
47     mkdir -p $DBENCHDIR
48     local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
49     DB_THREADS=$((SPACE / 50000))
50     [ $THREADS -lt $DB_THREADS ] && DB_THREADS=$THREADS
51     
52     $DEBUG_OFF
53     myUID=$RUNAS_ID
54     myGID=$RUNAS_GID
55     myRUNAS=$RUNAS
56     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
57       { myRUNAS="" && myUID=$UID && myGID=`id -g $USER`; }
58     chown $myUID:$myGID $DBENCHDIR
59     local duration=""
60     [ "$SLOW" = "no" ] && duration=" -t 120"
61     if [ "$SLOW" != "no" -o $DB_THREADS -eq 1 ]; then
62         $myRUNAS bash rundbench -D $DBENCHDIR 1 $duration || error "dbench failed!"
63         $DEBUG_ON
64     fi
65     if [ $DB_THREADS -gt 1 ]; then
66         $DEBUG_OFF
67         $myRUNAS bash rundbench -D $DBENCHDIR $DB_THREADS $duration
68         $DEBUG_ON
69     fi
70     rm -rf $DBENCHDIR
71 }
72 run_test dbench "dbench"
73
74 test_bonnie() {
75     if ! which bonnie++ > /dev/null 2>&1; then
76         skip_env "No bonnie++ installed"
77         return 0
78     fi
79     local BONDIR=$DIR/d0.bonnie
80     mkdir -p $BONDIR
81     $LFS setstripe -c -1 $BONDIR
82     sync
83     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
84     local SPACE=$(( OSTCOUNT * MIN ))
85     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
86     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
87     $DEBUG_OFF
88     myUID=$RUNAS_ID
89     myGID=$RUNAS_GID
90     myRUNAS=$RUNAS
91     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
92       { myRUNAS="" && myUID=$UID && myGID=`id -$USER`; }
93     chown $myUID:$myGID $BONDIR         
94     $myRUNAS bonnie++ -f -r 0 -s$((SIZE / 1024)) -n 10 -u$myUID:$myGID -d$BONDIR
95     $DEBUG_ON
96 }
97 run_test bonnie "bonnie++"
98
99 test_iozone() {
100     if ! which iozone > /dev/null 2>&1; then
101         skip_env "No iozone installed"
102         return 0
103     fi
104
105     export O_DIRECT
106     
107     local IOZDIR=$DIR/d0.iozone
108     wait_delete_completed || true
109     mkdir -p $IOZDIR
110     $LFS setstripe -c -1 $IOZDIR
111     sync
112     local MIN=`lctl get_param -n osc.*.kbytesavail | sort -n | head -n1`
113     local SPACE=$(( OSTCOUNT * MIN ))
114     [ $SPACE -lt $SIZE ] && SIZE=$((SPACE * 3 / 4))
115     log "min OST has ${MIN}kB available, using ${SIZE}kB file size"
116     IOZONE_OPTS="-i 0 -i 1 -i 2 -e -+d -r $RSIZE"
117     IOZFILE="$IOZDIR/iozone"
118     IOZLOG=$TMP/iozone.log
119                 # $SPACE was calculated with all OSTs
120     $DEBUG_OFF
121     myUID=$RUNAS_ID
122     myGID=$RUNAS_GID
123     myRUNAS=$RUNAS
124     FAIL_ON_ERROR=false check_runas_id_ret $myUID $myGID $myRUNAS || \
125         { myRUNAS="" && myUID=$UID && myGID=`id -g $USER`; }
126     chown $myUID:$myGID $IOZDIR
127     $myRUNAS iozone $IOZONE_OPTS -s $SIZE -f $IOZFILE 2>&1 | tee $IOZLOG
128     tail -1 $IOZLOG | grep -q complete || \
129         { error "iozone (1) failed" && return 1; }
130     rm -f $IOZLOG
131     wait_delete_completed || true
132     $DEBUG_ON
133     
134     # check if O_DIRECT support is implemented in kernel
135     if [ -z "$O_DIRECT" ]; then
136         touch $DIR/f.iozone
137         if ! $DIRECTIO write $DIR/f.iozone 0 1; then
138             log "SKIP iozone DIRECT IO test"
139             O_DIRECT=no
140         fi
141         rm -f $DIR/f.iozone
142         wait_delete_completed || true
143     fi
144     if [ "$O_DIRECT" != "no" -a "$IOZONE_DIR" != "no" ]; then
145         $DEBUG_OFF
146         $myRUNAS iozone -I $IOZONE_OPTS -s $SIZE -f $IOZFILE.odir 2>&1 | tee $IOZLOG
147         tail -1 $IOZLOG | grep -q complete || \
148             { error "iozone (2) failed" && return 1; }
149         rm -f $IOZLOG
150         wait_delete_completed || true
151         $DEBUG_ON
152     fi
153
154     SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
155     IOZ_THREADS=$((SPACE / SIZE * 2 / 3 ))
156     [ $THREADS -lt $IOZ_THREADS ] && IOZ_THREADS=$THREADS
157     IOZVER=`iozone -v | awk '/Revision:/ {print $3}' | tr -d .`
158     if [ "$IOZ_THREADS" -gt 1 -a "$IOZVER" -ge 3145 ]; then
159         $LFS setstripe -c -1 $IOZDIR
160         $DEBUG_OFF
161         THREAD=1
162         IOZFILE=" "
163         while [ $THREAD -le $IOZ_THREADS ]; do
164             IOZFILE="$IOZFILE $IOZDIR/iozone.$THREAD"
165             THREAD=$((THREAD + 1))
166         done
167         $myRUNAS iozone $IOZONE_OPTS -s $((SIZE / IOZ_THREADS)) -t $IOZ_THREADS -F $IOZFILE 2>&1 | tee $IOZLOG
168         tail -1 $IOZLOG | grep -q complete || \
169             { error "iozone (3) failed" && return 1; }
170         rm -f $IOZLOG
171         wait_delete_completed || true
172         $DEBUG_ON
173     elif [ $IOZVER -lt 3145 ]; then
174         VER=`iozone -v | awk '/Revision:/ { print $3 }'`
175         echo "iozone $VER too old for multi-thread test"
176     fi
177 }
178 run_test iozone "iozone"
179
180 test_fsx() {
181         local testfile=$DIR/f0.fsxfile
182         FSX_SIZE=$SIZE
183         FSX_COUNT=1000
184         local SPACE=`df -P $MOUNT | tail -n 1 | awk '{ print $4 }'`
185
186         [ $SPACE -lt $FSX_SIZE ] && FSX_SIZE=$((SPACE * 3 / 4))
187         $DEBUG_OFF
188         FSX_SEED=${FSX_SEED:-$RANDOM}
189         rm -f $testfile
190         $LFS setstripe -c -1 $testfile
191         CMD="fsx -c 50 -p 1000 -S $FSX_SEED -P $TMP -l $FSX_SIZE \
192         -N $((FSX_COUNT * 100)) $FSXOPT $testfile"
193         echo "Using: $CMD"
194         $CMD || error "fsx failed"
195         rm -f $testfile
196         $DEBUG_ON
197 }
198 run_test fsx "fsx"
199
200 complete $SECONDS
201 check_and_cleanup_lustre
202 exit_status