summaryrefslogtreecommitdiffstats
path: root/tests/include.rc
blob: cfa9390aaef49dc779118059ce9c8b36f28bf52a (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
M0=${M0:=/mnt/glusterfs/0};   # 0th mount point for FUSE
M1=${M1:=/mnt/glusterfs/1};   # 1st mount point for FUSE
N0=${N0:=/mnt/nfs/0};         # 0th mount point for NFS
N1=${N1:=/mnt/nfs/1};         # 1st mount point for NFS
V0=${V0:=patchy};             # volume name to use in tests
B0=${B0:=/d/backends};        # top level of brick directories
H0=${H0:=`hostname --fqdn`};  # hostname
DEBUG=${DEBUG:=0}             # turn on debugging?

CLI="gluster --mode=script";

mkdir -p $B0;
mkdir -p $M0 $M1;
mkdir -p $N0 $N1;

testcnt=`egrep '^[ \t]*(EXPECT|TEST|EXPECT_WITHIN)' $0 | wc -l`;
echo 1..$testcnt

t=1

function dbg()
{
	[ "x$DEBUG" = "x0" ] || echo "$*" >&2;
}


function test_header()
{
	dbg "=========================";
	dbg "TEST $t (line $TESTLINE): $*";
}


function test_footer()
{
	RET=$?

	if [ $RET -eq 0 ]; then
	     	echo "ok $t";
	else
		echo "not ok $t";
	fi

	dbg "RESULT $t: $RET";

	t=`expr $t + 1`;
}


function _EXPECT()
{
	TESTLINE=$1;
	shift;

	test_header "$@";

	e="$1";
	shift;
	"$@" | tail -1 | egrep -q "^${e}\$"

	test_footer;
}


function _TEST()
{
	TESTLINE=$1;
	shift;

	test_header "$@";

	eval "$@" >/dev/null 2>&1

	test_footer;
}

function _EXPECT_WITHIN()
{
        TESTLINE=$1
        shift;

        local timeout=$1
        shift;

        test_header "$@"

        e=$1;
        shift;

        local endtime=$(( ${timeout}+`date +%s` ))

        local success=0
        while [ `date +%s` -lt $endtime ]; do
                "$@" | tail -1 | egrep -q "^${e}\$"
                if [ $? -eq 0 ]; then
                        success=1;
                        break;
                fi
                sleep 1;
        done

        if [ $success -eq 1 ]; then
                true;
        else
                false;
        fi

        test_footer;
}


function cleanup()
{
	killall -15 glusterfs glusterfsd glusterd 2>/dev/null || true;
	killall -9 glusterfs glusterfsd glusterd 2>/dev/null || true;
	rm -rf /var/lib/glusterd/* $B0/* /etc/glusterd/*;

	umount -l $M0 2>/dev/null || true;
	umount -l $M1 2>/dev/null || true;
	umount -l $N0 2>/dev/null || true;
	umount -l $N1 2>/dev/null || true;
}


alias EXPECT='_EXPECT $LINENO'
alias TEST='_TEST $LINENO'
alias EXPECT_WITHIN='_EXPECT_WITHIN $LINENO'
shopt -s expand_aliases