VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/testcase/tstInstallInit.sh@ 44088

Last change on this file since 44088 was 44088, checked in by vboxsync, 12 years ago

Installer/linux: fixed install_service.sh test case for r82604.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1#!/bin/sh
2# $Id: tstInstallInit.sh 44088 2012-12-11 10:09:39Z vboxsync $
3#
4# VirtualBox init file creator unit test.
5#
6# Copyright (C) 2012 Oracle Corporation
7#
8# This file is part of VirtualBox Open Source Edition (OSE), as
9# available from http://www.virtualbox.org. This file is free software;
10# you can redistribute it and/or modify it under the terms of the GNU
11# General Public License (GPL) as published by the Free Software
12# Foundation, in version 2 as it comes in the "COPYING" file of the
13# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15#
16
17# This will initially be a skeleton with a couple of tests - add more for quick
18# debugging when you suspect that something isn't working as specified.
19
20tab=" "
21tmpbase="/tmp/tstInstallInit 99" # Space in the name for a little stress...
22
23## The function definition at the start of every non-trivial shell script!
24abort()
25{
26 ## $1 Error text to output to standard error in printf format.
27 cat >&2 << EOF
28${TEST_NAME}: $1
29EOF
30 exit 1
31}
32
33## Print a TESTING line.
34print_line()
35{
36 cat >&2 << EOF
37${TEST_NAME}: TESTING $1
38EOF
39}
40
41## Set the failure message if it is not yet set.
42fail_msg()
43{
44 test -z "${failed}" && failed="FAILED: ${1}"
45}
46
47# Get the directory where the script is located and the parent.
48OUR_FOLDER=`dirname "$0"`
49OUR_FOLDER=`cd "${OUR_FOLDER}" && pwd`
50VBOX_FOLDER=`cd "${OUR_FOLDER}/.." && pwd`
51[ -d "${VBOX_FOLDER}" ] ||
52 abort "Failed to change to directory ${VBOX_FOLDER}.\n"
53cd "${VBOX_FOLDER}"
54
55# Get our name for output.
56TEST_NAME="$(basename "$0" .sh)"
57
58# Create a trivial test service in temporary directory $1 with name $2.
59test_service()
60{
61 cat > "${1}/${2}" << EOF
62#!/bin/sh
63trap "touch \"${1}/stopped\"; exit" TERM
64echo "1: \${1} 2: \${2} 3: \${3}" > "${1}/started"
65while true; do true; done
66EOF
67chmod u+x "${1}/${2}"
68}
69
70# Test some dodgy input values against generate_service_file.
71print_line "generation of shell script from template."
72input='TEST1%DESCRIPTION%%%%SERVICE_NAME% TST2 TEST %ARGUMENTS%%COMMAND%'
73out=`echo "${input}" |
74 helpers/generate_service_file --command '/usr/bin
75aries/hello
76world' --arguments 'p\x0a0\n\ \t' --format shell --description ''`
77expected='TEST1%hello
78world TST2 TEST '\''p
790
80 '"${tab}"\'\''/usr/bin
81aries/hello
82world'\'
83case "${out}" in ${expected})
84echo "SUCCESS";;
85*)
86cat << EOF
87FAILED: expected
88${expected}
89but got
90${out}
91EOF
92esac
93
94# Create a simulated init system layout.
95create_simulated_init_tree()
96{
97 tmpdir="${1}"
98 rm -rf "${tmpdir}"
99 mkdir -m 0700 "${tmpdir}" || abort "Failed to create a temporary folder."
100 mkdir -p "${tmpdir}/init.d/" "${tmpdir}/rc.d/init.d/"
101 for i in 0 1 2 3 4 5 6; do
102 mkdir "${tmpdir}/rc${i}.d/" "${tmpdir}/rc.d/rc${i}.d/"
103 done
104 mkdir "${tmpdir}/run"
105}
106
107# Test an init script installation.
108print_line "installing an init script."
109failed=""
110# Create a simulated init system layout.
111tmpdir="${tmpbase}0"
112create_simulated_init_tree "${tmpdir}"
113# Create the service binary.
114test_service "${tmpdir}" "service"
115# And install it.
116helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
117 fail_msg "\"helpers/install_service\" failed."
118# Check that the main service file was created as specified.
119if test -x "${tmpdir}/init.d/service"; then
120 grep "Short-Description: My description" "${tmpdir}/init.d/service" >/dev/null ||
121 fail_msg "Description not set in \"${tmpdir}/init.d/service\""
122else
123 fail_msg "\"${tmpdir}/init.d/service\" not correctly created."
124fi
125test -x "${tmpdir}/init.d/rc.d/service" &&
126 fail_msg "\"${tmpdir}/init.d/rc.d/service\" created but shouldn't have been."
127# Try to start the service using the symbolic links which should have been
128# created.
129if "${tmpdir}/rc3.d/S20service" --prefix "${tmpdir}" --lsb-functions "" start >/dev/null 2>&1; then
130 if grep "1: test 2: of 3: my arguments" "${tmpdir}/started" >/dev/null; then
131 test -f "${tmpdir}/stopped" &&
132 fail_msg "\"${tmpdir}/rc3.d/S20service\" stopped immediately."
133 else
134 fail_msg "\"${tmpdir}/rc3.d/S20service\" did not start correctly."
135 fi
136else
137 fail_msg "could not start \"${tmpdir}/rc3.d/S20service\"."
138fi
139# Check the status.
140"${tmpdir}/rc.d/rc5.d/S20service" --prefix "${tmpdir}" --lsb-functions "" status >/dev/null 2>&1 ||
141 fail_msg "\"${tmpdir}/rc.d/rc5.d/S20service\" reported the wrong status."
142# Try to stop the service using the symbolic links which should have been
143# created.
144if "${tmpdir}/rc.d/rc6.d/K80service" --prefix "${tmpdir}" --lsb-functions "" stop >/dev/null 2>&1; then
145 test -f "${tmpdir}/stopped" ||
146 echo "\"${tmpdir}/rc.d/rc6.d/K80service\" did not stop correctly."
147else
148 fail_msg "could not stop \"${tmpdir}/rc.d/rc6.d/K80service\"."
149fi
150# Check the status again - now it should be stopped.
151"${tmpdir}/rc.d/rc3.d/S20service" --prefix "${tmpdir}" --lsb-functions "" status >/dev/null 2>&1 &&
152 fail_msg "\"${tmpdir}/rc.d/rc3.d/S20service\" reported the wrong status."
153# Final summary.
154if test -n "${failed}"; then
155 echo "${failed}"
156else
157 echo SUCCESS
158fi
159
160# Test an init script removal.
161print_line "removing an init script."
162failed=""
163# Create a simulated init system layout.
164tmpdir="${tmpbase}0"
165create_simulated_init_tree "${tmpdir}"
166# Create the service binary.
167test_service "${tmpdir}" "service"
168# Install it.
169helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
170 fail_msg "\"helpers/install_service\" failed."
171# And remove it again.
172helpers/install_service --command "${tmpdir}/service" --prefix "${tmpdir}" --remove ||
173 fail_msg "\"helpers/install_service\" failed."
174# After uninstallation this should be the only file left in the init tree.
175rm "${tmpdir}/service"
176test "x`find "${tmpdir}" -type f -o -type l`" = "x" ||
177 fail_msg "not all files were removed."
178# Final summary.
179if test -n "${failed}"; then
180 echo "${failed}"
181else
182 echo SUCCESS
183fi
184
185# Test an enabled init script update with --disable.
186print_line "updating an enabled init script with --disable."
187failed=""
188# Create a simulated init system layout.
189tmpdir="${tmpbase}1"
190create_simulated_init_tree "${tmpdir}"
191# Create the service binary.
192test_service "${tmpdir}" "service"
193# Install it.
194helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
195 fail_msg "\"helpers/install_service\" failed."
196# Install it disabled without forcing.
197helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --disable ||
198 fail_msg "\"helpers/install_service\" failed."
199test "x`find "${tmpdir}"/rc*.d -type l | wc -l`" = "x14" ||
200 fail_msg "links were removed on non-forced disable."
201# Final summary.
202if test -n "${failed}"; then
203 echo "${failed}"
204else
205 echo SUCCESS
206fi
207
208# Test updating a disabled init script with --enable.
209print_line "updating a disabled init script with --enable."
210failed=""
211# Create a simulated init system layout.
212tmpdir="${tmpbase}2"
213create_simulated_init_tree "${tmpdir}"
214# Create the service binary.
215test_service "${tmpdir}" "service"
216# Install it.
217helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --disable ||
218 fail_msg "\"helpers/install_service\" failed."
219# Install it disabled without forcing.
220helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
221 fail_msg "\"helpers/install_service\" failed."
222test "x`find "${tmpdir}"/rc*.d -type l`" = "x" ||
223 fail_msg "files were installed on non-forced enable."
224# Final summary.
225if test -n "${failed}"; then
226 echo "${failed}"
227else
228 echo SUCCESS
229fi
230
231# Test an enabled init script update with --force-disable.
232print_line "updating an enabled init script with --force-disable."
233failed=""
234# Create a simulated init system layout.
235tmpdir="${tmpbase}3"
236create_simulated_init_tree "${tmpdir}"
237# Create the service binary.
238test_service "${tmpdir}" "service"
239# Install it.
240helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
241 fail_msg "\"helpers/install_service\" failed."
242# Install it disabled without forcing.
243helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --force-disable ||
244 fail_msg "\"helpers/install_service\" failed."
245test "x`find "${tmpdir}"/rc*.d -type l`" = "x" ||
246 fail_msg "links were not removed on forced disable."
247# Final summary.
248if test -n "${failed}"; then
249 echo "${failed}"
250else
251 echo SUCCESS
252fi
253
254# Test updating a disabled init script with --force-enable.
255print_line "updating a disabled init script with --force-enable."
256failed=""
257# Create a simulated init system layout.
258tmpdir="${tmpbase}4"
259create_simulated_init_tree "${tmpdir}"
260# Create the service binary.
261test_service "${tmpdir}" "service"
262# Install it.
263helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --disable ||
264 fail_msg "\"helpers/install_service\" failed."
265# Install it disabled without forcing.
266helpers/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --force-enable ||
267 fail_msg "\"helpers/install_service\" failed."
268test "x`find "${tmpdir}"/rc*.d -type l | wc -l`" = "x14" ||
269 fail_msg "files were not installed on forced enable."
270# Final summary.
271if test -n "${failed}"; then
272 echo "${failed}"
273else
274 echo SUCCESS
275fi
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette