summaryrefslogtreecommitdiff
path: root/tests/tests-driver.sh
blob: ff1a2c1201e2fe93b1b7c675056ecaf2ffa5a6da (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
#!/bin/sh
# Copyright (C) 2020  Ali Abdallah <ali.abdallah@suse.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, see <http://www.gnu.org/licenses/>.

XFCONFD_DIR=$1
TEST=$2
XFCONFD=$XFCONFD_DIR/xfconfd

XFCONF_RUN_IN_TEST_MODE=1; export XFCONF_RUN_IN_TEST_MODE;

exec_xfconfd()
{
	rm $XFCONFD_DIR/.xfconfd-test-pid >/dev/null 2>&1
	rm $XFCONFD_DIR/.xfconfd-sum >/dev/null 2>&1

	exec ${XFCONFD} &
	echo $! > $XFCONFD_DIR/.xfconfd-test-pid
	pid=`cat $XFCONFD_DIR/.xfconfd-test-pid`
	sum $XFCONFD > $XFCONFD_DIR/.xfconfd-sum
}

cleanup()
{
	pid=`cat $XFCONFD_DIR/.xfconfd-test-pid`

	rm $XFCONFD_DIR/.xfconfd-test-pid >/dev/null 2>&1
	rm $XFCONFD_DIR/.xfconfd-sum >/dev/null 2>&1

	while kill -0 $pid >/dev/null 2>&1; do
		kill -s TERM $pid >/dev/null 2>&1
		sleep 0.1
	done
}

prepare()
{
	if [ ! -f $XFCONFD ]; then
		exit 1
	fi

	# Start xfconfd only if it is not started already
	if [ ! -f $XFCONFD_DIR/.xfconfd-test-pid ]; then
		exec_xfconfd
	elif [ ! -f $XFCONFD_DIR/.xfconfd-sum ]; then
		cleanup
		exec_xfconfd
	else
		oldsum=`cat $XFCONFD_DIR/.xfconfd-sum`
		newsum=`sum ${XFCONFD}`

		# Did xfconfd changes ?
		if [ "$newsum" != "$oldsum" ]; then
			cleanup
			exec_xfconfd
		else
			pid=`cat $XFCONFD_DIR/.xfconfd-test-pid`
			kill -s 0 $pid >/dev/null 2>&1

			# Is it still running ?
			if [ $? != 0 ]; then
				cleanup
				exec_xfconfd
			fi
		fi
	fi
}

sigint()
{
	cleanup
	exit 1
}

trap 'sigint'  INT

# Last test, cleanup
TEST_NAME=$(basename $TEST)

if [ "$TEST_NAME" = "t-tests-end" ]; then
	cleanup
	exit 0
fi
# Prepare xfconfd
prepare

$TEST
ret=$?
# Test failed, cleanup
if [ $ret -ne 0 ]; then
  cleanup
fi
exit $ret