Whamcloud - gitweb
LU-15152 tests: auster reports wrong testsuite status
[fs/lustre-release.git] / lustre / tests / posix.sh
1 #!/bin/bash
2 set -e
3
4 ONLY=${ONLY:-"$*"}
5
6 LUSTRE=${LUSTRE:-$(dirname $0)/..}
7 . $LUSTRE/tests/test-framework.sh
8 init_test_env $@
9 init_logging
10
11 ALWAYS_EXCEPT="$POSIX_EXCEPT"
12 build_test_filter
13
14 POSIX_DIR=${POSIX_DIR:-"$LUSTRE/tests/posix"}
15 POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"}
16 BASELINE_FS=${BASELINE_FS:-"ext4"}
17
18 # SLES does not support read-write access to an ext4 file system by default
19 [[ -e /etc/SuSE-release ]] && BASELINE_FS=ext3
20
21 if [[ "$mds1_FSTYPE" = zfs ]]; then
22         BASELINE_FS=zfs
23         ! which $ZFS $ZPOOL >/dev/null 2>&1 &&
24                 skip_env "need $ZFS and $ZPOOL commands"
25
26         POSIX_ZPOOL=$FSNAME-posix
27         POSIX_ZFS=$POSIX_ZPOOL/${POSIX_ZPOOL##$FSNAME-}
28 fi
29
30 check_and_setup_lustre
31
32 cleanup_loop_dev() {
33     local mnt=$1
34     local dev=$2
35     local file=$3
36
37     # if we only have 1 arg, we will search for dev
38     if [[ $# = 1 ]]; then
39         dev=$(losetup -a | grep "$mnt" | cut -d: -f1)
40         [[ -n $dev ]] && losetup -d $dev
41     else # we need all args
42         [[ -z $mnt ]] || [[ -z $dev ]] || [[ -z $file ]] &&
43             error "Can't cleanup loop device"
44         umount -f $mnt
45         losetup -d $dev && rm -rf $mnt
46         rm -f $file
47     fi
48
49         [[ $BASELINE_FS != zfs ]] || destroy_zpool client $POSIX_ZPOOL
50 }
51
52 setup_loop_dev() {
53         local mnt=$1
54         local dev=$2
55         local file=$3
56         local rc=0
57
58         echo "Make a loop file system with $file on $dev"
59         dd if=/dev/zero of=$file bs=1024k count=500 > /dev/null
60         if ! losetup $dev $file; then
61                 rc=$?
62                 echo "can't set up $dev for $file"
63                 return $rc
64         fi
65
66         if [[ $BASELINE_FS = zfs ]]; then
67                 create_zpool client $POSIX_ZPOOL $dev || return ${PIPESTATUS[0]}
68                 create_zfs client $POSIX_ZFS || return ${PIPESTATUS[0]}
69                 dev=$POSIX_ZFS
70
71         elif ! eval mkfs.$BASELINE_FS $dev; then
72                 rc=$?
73                 echo "mkfs.$BASELINE_FS on $dev failed"
74                 return $rc
75         fi
76         mkdir -p $mnt
77         if ! mount -t $BASELINE_FS $dev $mnt; then
78                 rc=$?
79                 echo "mount $BASELINE_FS failed"
80                 return $rc
81         fi
82         echo
83         return $rc
84 }
85
86 test_1() {
87         local allnodes="$(comma_list $(nodes_list))"
88         local tfile="$TMP/$BASELINE_FS-file"
89         local mntpnt=$POSIX_SRC/$BASELINE_FS
90         local loopbase
91         local loopdev
92         local rc=0
93
94         # We start at loop1 because posix build uses loop0
95         [ -b /dev/loop/1 ] && loopbase=/dev/loop/
96         [ -b /dev/loop1 ] && loopbase=/dev/loop
97         if [ -z "$loopbase" ]; then
98                 # there is no /dev/loop by default on EL7, LU-6707.
99                 load_module loop max_loop=8 || error "load loop module failed"
100                 loopbase=/dev/loop
101         fi
102
103         for i in $(seq 1 7); do
104                 losetup $loopbase$i > /dev/null 2>&1 && continue || true
105                 loopdev=$loopbase$i
106                 break
107         done
108
109         [ -z "$loopdev" ] && error "Can not find loop device"
110
111         if ! setup_loop_dev $mntpnt $loopdev $tfile; then
112                 cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
113                 error "Setup loop device failed"
114         fi
115
116         # copy the source over to ext mount point
117         if ! cp -af ${POSIX_SRC}/*.* $mntpnt; then
118                 cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
119                 error "Copy POSIX test suite failed"
120         fi
121         export POSIX_SRC=$mntpnt
122         . $POSIX_DIR/posix.cfg
123
124         setup_posix_users $allnodes
125         if ! setup_posix; then
126                 delete_posix_users $allnodes
127                 cleanup_loop_dev "$POSIX_SRC"
128                 cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
129                 error "Setup POSIX test suite failed"
130         fi
131
132         log "Run POSIX test against lustre filesystem"
133         run_posix $MOUNT $MGSNID $FSNAME compare ||
134                 error_noexit "Run POSIX testsuite on $MOUNT failed"
135
136         [[ -d "$MOUNT/TESTROOT" ]] && rm -fr $MOUNT/TESTROOT
137         delete_posix_users $allnodes
138         cleanup_loop_dev "$POSIX_SRC"
139         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
140 }
141 run_test 1 "install, build, run posix on $BASELINE_FS and lustre, then compare"
142
143 complete $SECONDS
144 check_and_cleanup_lustre
145 exit_status