summaryrefslogtreecommitdiffstats
path: root/run-tests.sh
blob: e98977060669fcb2e2e154cab0c9c2c6e836e6bb (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
#!/bin/bash
# Copyright (c) 2013-2014 Red Hat, Inc. <http://www.redhat.com>
#

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

    # Check for dbench
    if [ ! -x /usr/bin/dbench ]; 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 mock
    if [ ! -e /usr/bin/mock ]; then
        MISSING="$MISSING mock"
    fi

    # Check for nfs-utils
    env mount.nfs -V > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING nfs-utils"
    fi

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

    # Check for XFS programs
    env mkfs.xfs -V > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        MISSING="$MISSING xfsprogs"
    fi

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

    ## If dependencies are missing, warn the user and abort
    if [ "x$MISSING" != "x" ]; then
        echo "Aborting."
        echo
        echo "The following required tools are missing:"
        echo
        for pkg in $MISSING; do
            echo "  * $pkg"
        done
        echo
        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 main()
{
    if [ $# -lt 1 ]; then
        echo "Running all the regression test cases"
        prove -rf --timer ${regression_testsdir}/tests;
    else
        ## TODO
        echo "Running single regression test.."
        echo "WARNING: yet to be implemented.. exiting safely"
        exit 0
        #export DEBUG=1;
        #echo "Automatically setting up DEBUG=1 for this test $1";
    fi
}

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

# 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
main "$@"