Whamcloud - gitweb
LU-14119 lfsck: check linkea if it's newly added
[fs/lustre-release.git] / lustre / tests / pjdfstest.sh
1 #!/bin/bash
2 set -e
3
4 {
5 cat << 'HEADER'
6 #!/bin/bash
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 SAVE_PWD=$PWD
12 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
13 CLEANUP=${CLEANUP:-:}
14 SETUP=${SETUP:-:}
15 export MULTIOP=${MULTIOP:-multiop}
16
17 . $LUSTRE/tests/test-framework.sh
18 init_test_env $@
19 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
20 get_lustre_env
21 init_logging
22
23 # bug number for skipped test:
24 ALWAYS_EXCEPT="$PJDFSTEST_EXCEPT "
25 # bug number for skipped test: LU-12922         LU-1158
26 ALWAYS_EXCEPT+="               chown_00 utimensat_08"
27 build_test_filter
28
29 PJDFSTEST_DIR=${PJDFSTEST_DIR:-"/usr/share/pjdfstest"}
30 PJDFSTEST_BIN=${PJDFSTEST_BIN:-"/bin/pjdfstest"}
31 EXT4_LOG=${EXT4_LOG:-"$TMP/pjdfstest-ext4"}
32 LUSTRE_LOG=${LUSTRE_LOG:-"$TMP/pjdfstest-lustre"}
33
34 check_and_setup_lustre
35
36 if [[ ! -f $PJDFSTEST_DIR/pjdfstest ]]; then
37         # copy the bin to the suite dir
38         if ! cp -af $PJDFSTEST_BIN $PJDFSTEST_DIR; then
39                 error "Copy pjdfstest binary failed"
40         fi
41 fi
42
43 run_pjdfstest() {
44         local mntpnt=$1
45         local pjdfstest=$2
46         local report=$3
47         local rc=0
48         local cmd
49
50         which prove > /dev/null || skip_env "must have prove installed"
51
52         cmd="prove -f $pjdfstest &> $report"
53
54         pushd $mntpnt > /dev/null
55         echo $cmd
56         if ! eval $cmd; then
57                 rc=${PIPESTATUS[0]}
58         fi
59         popd > /dev/null
60
61         return $rc
62 }
63
64 run_lustre_ext4() {
65         local pjdfstest=$1
66
67         log "Run $pjdfstest against ext4 filesystem"
68         run_pjdfstest $EXT4_MNTPT $pjdfstest $EXT4_LOG
69
70         log "Run $pjdfstest against lustre filesystem"
71         run_pjdfstest $MOUNT $pjdfstest $LUSTRE_LOG
72
73 }
74
75 setup_ext4() {
76         local loop_file=$1
77         local mntpt=$2
78         local size=${3:-50}
79
80         mkdir -p $mntpt || error "mkdir -p $mntpt failed"
81         stack_trap "rm -rf $mntpt"
82         dd if=/dev/zero of=$loop_file bs=1M count=$size
83         stack_trap "rm -f $loop_file"
84         mkfs.ext4 $loop_file > /dev/null ||
85                 error "mkfs.ext4 $loop_file failed"
86         file $loop_file
87         mount -t ext4 -o loop,usrquota,grpquota $loop_file $mntpt ||
88                 error "mount -o loop,usrquota,grpquota $loop_file $mntpt failed"
89         stack_trap "$UMOUNT $mntpt"
90 }
91
92 compare_report() {
93         local ext4_summary=$TMP/pjdfstest-ext4-summary
94         local lustre_summary=$TMP/pjdfstest-lustre-summary
95         local summary="Test Summary Report"
96         local summary_end="Files"
97         local diff=$TMP/pjdfstest-diff
98         local rc=0
99
100         # filter out the summary and delete the duration part to compare
101         sed -n '/'"$summary"'/,/'"$summary_end"'/p' "$EXT4_LOG" |
102                 sed '$d'> $ext4_summary
103         sed -n '/'"$summary"'/,/'"$summary_end"'/p' "$LUSTRE_LOG" |
104                 sed '$d' > $lustre_summary
105         grep -vf $ext4_summary $lustre_summary > $diff
106
107         [ -s $diff ] && rc=1
108         log "ext4 report"
109         cat $EXT4_LOG || error_noexit "Cannot open file"
110         log "lustre report"
111         cat $LUSTRE_LOG || error_noexit "Cannot open file"
112
113         rm -f $TMP/pjdfstest-* ||
114                 error_noexit "Cannot remove pjdfstest tmp files"
115         return $rc
116 }
117
118 # All tests will be run on Lustre and an ext4 file system. Set up
119 # an ext4 file system
120 EXT4_MNTPT=/mnt/pjdfstest.ext4
121 LOOP_FILE=$TMP/loop_file
122 setup_ext4 $LOOP_FILE $EXT4_MNTPT
123
124 # Create users and groups required by the tests
125 mds=$(facet_host mds1)
126
127 USR=(pjd_usr1 pjd_usr2 pjd_usr3)
128 USRID=(65535 65533 65532)
129 GRP=(pjd_grp1 pjd_grp2 pjd_grp3)
130 GRPID=(65535 65533 65531)
131
132 idx=0
133 for grp_id in ${GRPID[@]}; do
134         echo "setup up GRPID $grp_id for group ${GRP[$idx]} on $mds"
135         do_rpc_nodes $mds add_group $grp_id ${GRP[$idx]}
136         stack_trap "do_rpc_nodes $mds groupdel ${GRP[$idx]}"
137         idx=$((idx+1))
138 done
139
140 idx=0
141 for user_id in ${USRID[@]}; do
142         echo "setup up USRID $user_id for user ${USR[$idx]}"
143         do_rpc_nodes $mds add_user $user_id ${USR[$idx]} \
144                 ${GRPID[$idx]} $DIR/${USR[$idx]}
145         stack_trap "do_rpc_nodes $mds userdel ${USR[$idx]}"
146         idx=$((idx+1))
147 done
148 HEADER
149
150 PJDFSTEST_DIR=${PJDFSTEST_DIR:-"/usr/share/pjdfstest"}
151 TMP=${TMP:-/tmp}
152 # enable globstar so ** can get all dir recursively
153 shopt -s globstar
154 for testname in $PJDFSTEST_DIR/**/*.t; do
155         test_dir=$(dirname $testname)
156         test_grp=$(basename $test_dir)
157         sub_t="${test_grp}_$(basename $testname .t)"
158         # execute the "desc=" line and set it the environment for our use
159         eval $(grep "^desc=" $testname)
160
161         cat - <<SUBTEST
162 test_$sub_t() {
163         run_lustre_ext4 $testname
164         compare_report || error "$testname against lustre failed"
165 }
166 run_test $sub_t "$desc"
167 SUBTEST
168 done
169
170 cat << 'TAIL'
171 complete $SECONDS
172 check_and_cleanup_lustre
173 exit_status
174 TAIL
175 } > $TMP/run_pjdfstest.sh
176 bash $TMP/run_pjdfstest.sh
177