Skip to content

Commit 2b0a669

Browse files
committed
tests: add basic rc-service tests
1 parent fe17d8f commit 2b0a669

File tree

6 files changed

+112
-13
lines changed

6 files changed

+112
-13
lines changed

sh/meson.build

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ sh_config = [
2121
]
2222

2323
scripts_config = [
24-
'gendepends.sh.in',
25-
'openrc-run.sh.in',
2624
'openrc-user.sh.in',
2725
's6-svscanboot.sh.in'
2826
]
@@ -58,12 +56,18 @@ foreach file : sh_config
5856
install_dir : rc_shdir)
5957
endforeach
6058

59+
openrc_run_sh = configure_file(input : 'openrc-run.sh.in',
60+
output : '@BASENAME@', configuration : sh_conf_data,
61+
install_dir : rc_shdir, install_mode : 'rwxr-xr-x')
62+
63+
gendepends_sh = configure_file(input : 'gendepends.sh.in',
64+
output : '@BASENAME@', configuration : sh_conf_data,
65+
install_dir : rc_shdir, install_mode : 'rwxr-xr-x')
66+
6167
foreach file : scripts_config
6268
configure_file(input : file,
63-
output : '@BASENAME@',
64-
configuration : sh_conf_data,
65-
install_dir : rc_shdir,
66-
install_mode : 'rwxr-xr-x')
69+
output : '@BASENAME@', configuration : sh_conf_data,
70+
install_dir : rc_shdir, install_mode : 'rwxr-xr-x')
6771
endforeach
6872

6973
foreach file : scripts_config_os

src/openrc-run/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
executable('openrc-run', 'openrc-run.c',
1+
openrc_run = executable('openrc-run', 'openrc-run.c',
22
dependencies: [rc, einfo, shared, audit_dep, dl_dep, pam_dep, pam_misc_dep, selinux_dep, util_dep, crypt_dep],
33
include_directories: incdir,
44
install: true,

src/rc-service/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
executable('rc-service', 'rc-service.c',
1+
rc_service = executable('rc-service', 'rc-service.c',
22
include_directories: incdir,
33
dependencies: [rc, einfo, shared],
44
install: true,

test/units/meson.build

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
is_older_than = find_program('check-is-older-than.sh')
2-
sh_yesno = find_program('check-sh-yesno.sh')
3-
4-
test('is_older_than', is_older_than, env : test_env)
5-
test('sh_yesno', sh_yesno, env : test_env)
1+
test('is_older_than', find_program('check-is-older-than.sh'), env: test_env)
2+
test('sh_yesno', find_program('check-sh-yesno.sh'), env: test_env)
3+
test('rc-service', find_program('rc-service.sh'),
4+
env: [test_env, 'SUBDIR=' + meson.current_source_dir()],
5+
workdir: meson.project_source_root(),
6+
verbose: true,
7+
args: [ rc_service, openrc_run, openrc_run_sh, gendepends_sh ])

test/units/rc-service.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
. "$SUBDIR/setup-root.sh"
6+
rc_service=${1?}
7+
openrc_run=${2?}
8+
cp "${3?}" "$root/run/openrc/openrc-run.sh"
9+
cp "${4?}" "$root/run/openrc/gendepends.sh"
10+
chmod +x "$root/run/openrc/openrc-run.sh"
11+
chmod +x "$root/run/openrc/gendepends.sh"
12+
13+
rc_service() {
14+
$rc_service "$@" 2>&1
15+
}
16+
17+
in_state() {
18+
state=${1?}
19+
shift
20+
for svc; do
21+
test "$(readlink "$RC_SVCDIR/$state/$svc")" = "$root/etc/init.d/$svc"
22+
done
23+
}
24+
25+
mkservice() {
26+
service="$root/etc/init.d/$1"
27+
cat > "$service" <<-EOF
28+
#!$SOURCE_ROOT/${openrc_run}
29+
depend() {
30+
${2-:;}
31+
}
32+
start() {
33+
${3-sleep 0.1}
34+
}
35+
EOF
36+
chmod +x "$service"
37+
}
38+
39+
mkservice nya
40+
mkservice foo "need nya"
41+
mkservice mew "want foo"
42+
43+
addrunlevel() {
44+
ln -s "$root/etc/init.d/${1?}" "$root/etc/runlevel/${2?}/$1"
45+
}
46+
47+
rc_service nya start
48+
in_state started nya
49+
50+
rc_service nya stop
51+
( ! in_state started nya )
52+
53+
rc_service foo start
54+
in_state started foo nya
55+
56+
rc_service foo stop
57+
in_state started nya
58+
( ! in_state started foo )
59+
60+
rc_service foo start
61+
in_state started foo nya
62+
63+
rc_service nya stop
64+
( ! in_state started foo nya )
65+
66+
rc_service mew start
67+
in_state started foo nya mew
68+
69+
rc_service nya stop
70+
rc_service mew stop
71+
72+
( ! in_state started foo nya mew )

test/units/setup-root.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root=$(mktemp -d --tmpdir rc.XXXXXX)
2+
#trap "rm -r $root" EXIT
3+
4+
sysdir="$root/etc"
5+
export RC_LIBEXECDIR="$BUILD_ROOT"
6+
export RC_SCRIPTDIRS="$sysdir"
7+
export RC_SVCDIR="$root/run/openrc"
8+
mkdir -p "$RC_SVCDIR"
9+
echo "default" > "$RC_SVCDIR/softlevel"
10+
11+
for dir in init.d conf.d runlevels; do
12+
mkdir -p "$sysdir/$dir"
13+
done
14+
for dir in sysinit boot default boop shutdown; do
15+
mkdir -p "$sysdir/runlevels/$dir"
16+
done
17+
18+
for dir in daemons exclusive failed hotplugged inactive init.d \
19+
options scheduled started starting stopping tmp wasinactive; do
20+
mkdir -p "$root/run/openrc/$dir"
21+
done

0 commit comments

Comments
 (0)