summaryrefslogtreecommitdiffstats
path: root/tests/test-lib.sh
blob: ce4ecffd082456188f2d0e3a518fc68738e0348f (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
#!/bin/bash
#
# test-lib.sh -- library of functions for nfs-utils tests
#
# Copyright (C) 2010  Red Hat, Jeff Layton <jlayton@redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 0211-1301 USA
#

# make sure $srcdir is set and sanity check it
srcdir=${srcdir-.}
if [ ! -d ${srcdir} ]; then
	echo "***ERROR***: bad installation -- \$srcdir=${srcdir}"
	exit 1
fi

export PATH=$PATH:${srcdir}:${srcdir}/nsm_client

# Some tests require root privileges. Check for them and skip the test (exit 77)
# if the caller doesn't have them.
check_root() {
	if [ $EUID -ne 0 ]; then
		echo "*** Skipping this test as it requires root privs ***"
		exit 77
	fi
}

# is lockd registered as a service?
lockd_registered() {
	rpcinfo -p | grep -q nlockmgr
	return $?
}

# start up statd
start_statd() {
	rpcinfo -u 127.0.0.1 status 1 &> /dev/null
	if [ $? -eq 0 ]; then
		echo "***ERROR***: statd is already running and should "
		echo "             be down when starting this test"
		return 1
	fi
	$srcdir/../utils/statd/statd --no-notify
}

# shut down statd
kill_statd() {
	kill `cat /var/run/rpc.statd.pid`
}