summaryrefslogtreecommitdiffstats
path: root/run-tests.sh
blob: f52ef07690ddc63499ff4c0a804268b21f7d96d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/bin/bash
# Copyright (c) 2013-2014 Red Hat, Inc. <http://www.redhat.com>
#

export TZ=UTC
function check_dependencies()
{
    ## Check all dependencies are present
    MISSING=""

    # Check for dbench
    env dbench --usage > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING dbench"
    fi

    # Check for git
    env git --version > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING git"
    fi

    # Check for nfs-utils (Linux-only: built-in NetBSD with different name)
    if [ "x`uname -s`" = "xLinux" ] ; then
      env mount.nfs -V > /dev/null 2>&1
      if [ $? -ne 0 ]; then
          MISSING="$MISSING nfs-utils"
      fi
    fi

    # Check for the Perl Test Harness
    env prove --version > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING perl-Test-Harness"
    fi

    which json_verify > /dev/null
    if [ $? -ne 0 ]; then
        MISSING="$MISSING json_verify"
    fi

    # Check for XFS programs (Linux Only: NetBSD does without)
    if [ "x`uname -s`" = "xLinux" ] ; then
      env mkfs.xfs -V > /dev/null 2>&1
      if [ $? -ne 0 ]; then
          MISSING="$MISSING xfsprogs"
      fi
    fi

    # Check for attr
    env getfattr --version > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING attr"
    fi

    # Check for pidof
    pidof pidof > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING pidof"
    fi

    # check for psutil python package
    test `uname -s` == "Darwin" || test `uname -s` == "FreeBSD" && {
        pip show psutil | grep -q psutil >/dev/null 2>&1
        if [ $? -ne 0 ]; then
            MISSING="$MISSING psutil"
        fi
    }

    ## If dependencies are missing, warn the user and abort
    if [ "x$MISSING" != "x" ]; then
        test "x${force}" != "xyes" && echo "Aborting."
        echo
        echo "The following required tools are missing:"
        echo
        for pkg in $MISSING; do
            echo "  * $pkg"
        done
        echo
        test "x${force}" = "xyes" && return
        echo "Please install them and try again."
        echo
        exit 2
    fi
}

function check_location()
{
    regression_testsdir=$(dirname $0);

    if [ ! -f ${regression_testsdir}/tests/include.rc ]; then
        echo "Aborting."
        echo
        echo "The tests/ subdirectory seems to be missing."
        echo
        echo "Please correct the problem and try again."
        echo
        exit 1
    fi
}

function check_user()
{
    # If we're not running as root, warn the user and abort
    MYUID=`/usr/bin/id -u`
    if [ 0${MYUID} -ne 0 ]; then
        echo "Aborting."
        echo
        echo "The GlusterFS Test Framework must be run as root."
        echo
        echo "Please change to the root user and try again."
        echo
        exit 3
    fi
}

function run_tests()
{
    declare -A DONE
    match()
    {
        # Patterns considered valid:
        # 1. full or partial file/directory names
        #   basic         matches tests/basic
        #   basic/afr     matches tests/basic/afr
        # 2. globs
        #   basic/*       matches all files and directories in basic
        #   basic/*/      matches subdirectories in basic (afr|ec)
        # 3. numbered bug matching
        #   884455        matches bugs/bug-884455.t
        #   859927        matches bugs/859927, bugs/bug-859927.t
        #   1015990       matches /bugs/bug-1015990-rep.t, bug-1015990.t
        # ...lots of other cases accepted as well, since globbing is tricky.
        local t=$1
        local mt=$1
        shift
        local a
        local match=1
        if [ -d $t ] ; then
            # Allow matching on globs like 'basic/*/'
            mt=$t/
        fi
        for a in "$@" ; do
            case "$mt" in
                *$a|*/bugs/$a/|*/bugs/$a.t|*/bugs/bug-$a.t|*/bugs/bug-$a-*.t)
                    match=0
                    ;;
            esac
        done
        if [ "${DONE[$(dirname $t)]}" != "" ] ; then
            # Parentdir is already matched
            match=1
            if [ -d $t ] ; then
                # Ignore subdirectory as well
                DONE[$t]=$t
            fi
       elif [ $match -eq 0 -a -d $t ] ; then
            # Make sure children of this matched directory will be ignored
            DONE[$t]=$t
        elif [[ -f $t && ! $t =~ .*\.t ]] ; then
            # Ignore files not ending in .t
            match=1
        fi
        return $match
    }
    RES=0
    for t in $(find ${regression_testsdir}/tests | grep -v geo-rep \
    | LC_COLLATE=C sort) ; do
        if match $t "$@" ; then
            if [ -d $t ] ; then
                echo "Running tests in directory $t"
                prove -rf --timer $t
            elif  [ -f $t ] ; then
                echo "Running tests in file $t"
                prove -f --timer $t
            fi
            TMP_RES=$?
            if [ ${TMP_RES} -ne 0 ] ; then
                RES=${TMP_RES}
                FAILED="$FAILED $t"
            fi
        fi
    done
    if [ ${RES} -ne 0 ] ; then
        FAILED=$( echo ${FAILED} | tr ' ' '\n' | sort -u )
        echo "Failed tests ${FAILED}"
    fi
    return ${RES}
}

# If you're submitting a fix related to one of these tests and want its result
# to be considered, you'll need to remove it from the list as part of your
# patch.
function is_bad_test ()
{
    local name=$1
    for bt in ./tests/basic/volume-snapshot-clone.t	\
    	      ./tests/basic/uss.t			\
              ./tests/basic/afr/entry-self-heal.t       \
              ./tests/bugs/replicate/bug-1015990.t      \
              ./tests/basic/afr/read-subvol-entry.t     \
              ./tests/basic/ec/quota.t  \
              ./tests/basic/tier/tier.t \
              ./tests/basic/quota-nfs.t \
              ./tests/bugs/quota/bug-1035576.t  \
              ./tests/basic/uss.t       \
              ./tests/bugs/glusterfs/bug-867253.t       \
              ./tests/bugs/glusterd/bug-974007.t        \
              ./tests/basic/volume-snapshot-clone.t     \
              ./tests/basic/quota-anon-fd-nfs.t \
              ./tests/bugs/snapshot/bug-1112559.t       \
              ./tests/bugs/disperse/bug-1187474.t       \
              ./tests/basic/afr/sparse-file-self-heal.t \
              ./tests/basic/mount-nfs-auth.t            \
              ./tests/performance/open-behind.t         \
              ./tests/basic/ec/ec-5-1.t                 \
	      ; do
        [ x"$name" = x"$bt" ] && return 0 # bash: zero means true/success
    done
    return 1				  # bash: non-zero means false/failure
}

function run_all ()
{
    find ${regression_testsdir}/tests -name '*.t' \
    | grep -v geo-rep \
    | LC_COLLATE=C sort \
    | while read t; do
	old_cores=$(ls /core.* 2> /dev/null | wc -l)
        retval=0
        prove -f --timer $t
        TMP_RES=$?
        if [ ${TMP_RES} -ne 0 ] ; then
            echo "$t: bad status $TMP_RES"
            retval=$((retval+1))
        fi
        new_cores=$(ls /core.* 2> /dev/null | wc -l)
        if [ x"$new_cores" != x"$old_cores" ]; then
            core_diff=$((new_cores-old_cores))
            echo "$t: $core_diff new core files"
            retval=$((retval+2))
        fi
        if [ $retval -ne 0 ]; then
	    if is_bad_test $t; then
		echo  "Ignoring failure from known-bad test $t"
	    else
		return $retval
	    fi
        fi
    done
}

function main()
{
    if [ $# -lt 1 ]; then
        echo "Running all the regression test cases (new way)"
        #prove -rf --timer ${regression_testsdir}/tests;
        run_all
    else
        run_tests "$@"
    fi
}

function main_and_retry()
{
    RESFILE=`mktemp /tmp/${0##*/}.XXXXXX` || exit 1
    main "$@" | tee ${RESFILE}
    RET=$?

    FAILED=$( awk '/Failed: /{print $1}' ${RESFILE} )
    if [ "x${FAILED}" != "x" ] ; then
       echo ""
       echo "       *********************************"
       echo "       *       REGRESSION FAILED       *"
       echo "       * Retrying failed tests in case *"
       echo "       * we got some spurous failures  *"
       echo "       *********************************"
       echo ""
       main ${FAILED}
       RET=$?
    fi

    rm -f ${RESFILE}
    return ${RET}
}

echo
echo ... GlusterFS Test Framework ...
echo

force="no"
retry="no"
args=`getopt fr $*`
set -- $args
while [ $# -gt 0 ]; do
    case "$1" in
    -f)    force="yes" ;;
    -r)    retry="yes" ;;
    --)    shift; break;;
    esac
    shift
done

# Make sure we're running as the root user
check_user

# Make sure the needed programs are available
check_dependencies

# Check we're running from the right location
check_location

# Run the tests
if [ "x${retry}" = "xyes" ] ; then
    main_and_retry $@
else
    main "$@"
fi