Whamcloud - gitweb
LU-13581 build: xarray and lockdep_is_held const clash
[fs/lustre-release.git] / lustre / tests / racer / racer.sh
1 #!/bin/bash
2 #set -x
3
4 DIR="$1"
5 MAX_FILES=${MAX_FILES:-20}
6 DURATION=${DURATION:-$((60*5))}
7 MDSCOUNT=${MDSCOUNT:-1}
8
9 NUM_THREADS=${NUM_THREADS:-$2}
10 NUM_THREADS=${NUM_THREADS:-3}
11
12 RACER_MAX_CLEANUP_WAIT=${RACER_MAX_CLEANUP_WAIT:-$DURATION}
13
14 mkdir -p $DIR
15
16 RACER_PROGS="file_create dir_create file_rm file_rename file_link file_symlink \
17 file_list file_concat file_exec file_chown file_chmod file_mknod file_truncate \
18 file_delxattr file_getxattr file_setxattr"
19
20 if $RACER_ENABLE_REMOTE_DIRS || $RACER_ENABLE_STRIPED_DIRS; then
21         RACER_PROGS+=' dir_remote'
22 fi
23
24 if $RACER_ENABLE_MIGRATION; then
25         RACER_PROGS+=' dir_migrate'
26 fi
27
28 racer_cleanup()
29 {
30         echo "racer cleanup"
31         for P in $RACER_PROGS; do
32                 killall -q $P.sh
33         done
34         trap 0
35
36         local TOT_WAIT=0
37         local SHORT_WAIT=5
38
39         local rc
40         while [[ $TOT_WAIT -le $RACER_MAX_CLEANUP_WAIT ]]; do
41                 rc=0
42                 echo sleeping $SHORT_WAIT sec ...
43                 sleep $SHORT_WAIT
44                 # this only checks whether processes exist
45                 for P in $RACER_PROGS; do
46                         killall -0 $P.sh
47                         [[ $? -eq 0 ]] && (( rc+=1 ))
48                 done
49
50                 # Kill dd processes to speedup cleanup
51                 local pids=$(ps uax | grep "$DIR" | grep dd | grep -v grep |
52                                 awk '{print $2}')
53                 for pid in $pids; do
54                         kill $pid
55                 done
56
57                 if [[ $rc -eq 0 ]]; then
58                         echo there should be NO racer processes:
59                         ps uww -C "${RACER_PROGS// /.sh,}.sh"
60                         return 0
61                 fi
62                 (( TOT_WAIT+=SHORT_WAIT ))
63                 echo -n "Waited $TOT_WAIT, rc=$rc "
64                 (( SHORT_WAIT+=SHORT_WAIT ))
65         done
66         ps uww -C "${RACER_PROGS// /.sh,}.sh"
67         return 1
68 }
69
70 RC=0
71
72 echo "Running $0 for $DURATION seconds. CTRL-C to exit"
73 trap "
74         echo \"Cleaning up\" 
75         racer_cleanup
76         exit 0
77 " INT TERM
78
79 cd `dirname $0`
80 for N in `seq 1 $NUM_THREADS`; do
81         for P in $RACER_PROGS; do
82                 ./$P.sh $DIR $MAX_FILES &
83         done
84 done
85
86 sleep $DURATION
87 racer_cleanup || RC=$?
88
89 # Check our to see whether our test DIR is still available.
90 df $DIR
91 (( RC+=$? ))
92 [ $RC -eq 0 ] && echo "We survived $0 for $DURATION seconds."
93 exit $RC