diff options
Diffstat (limited to 'test/units')
| -rw-r--r-- | test/units/meson.build | 12 | ||||
| -rwxr-xr-x | test/units/rc-service.sh | 72 | ||||
| -rwxr-xr-x | test/units/rc-update.sh | 77 | ||||
| -rwxr-xr-x | test/units/setup-root.sh | 28 |
4 files changed, 184 insertions, 5 deletions
diff --git a/test/units/meson.build b/test/units/meson.build index 23c2758a..4d1cb8a3 100644 --- a/test/units/meson.build +++ b/test/units/meson.build @@ -1,5 +1,7 @@ -is_older_than = find_program('check-is-older-than.sh') -sh_yesno = find_program('check-sh-yesno.sh') - -test('is_older_than', is_older_than, env : test_env) -test('sh_yesno', sh_yesno, env : test_env) +test('is_older_than', find_program('check-is-older-than.sh'), env: test_env) +test('sh_yesno', find_program('check-sh-yesno.sh'), env: test_env) +test('rc-service', find_program('rc-service.sh'), + env: [test_env, 'SUBDIR=' + meson.current_source_dir()], + workdir: meson.project_source_root(), + args: [ rc_service, openrc_run ], + depends: script_deps) diff --git a/test/units/rc-service.sh b/test/units/rc-service.sh new file mode 100755 index 00000000..e0cd90a8 --- /dev/null +++ b/test/units/rc-service.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +set -e + +. "$SUBDIR/setup-root.sh" +rc_service=${1?} +openrc_run=${2?} +cp "$RC_LIBEXECDIR/sh/openrc-run.sh" "$root/run/openrc/openrc-run.sh" +cp "$RC_LIBEXECDIR/sh/gendepends.sh" "$root/run/openrc/gendepends.sh" +chmod +x "$root/run/openrc/openrc-run.sh" +chmod +x "$root/run/openrc/gendepends.sh" + +rc_service() { + $rc_service "$@" 2>&1 +} + +in_state() { + state=${1?} + shift + for svc; do + test "$(readlink "$RC_SVCDIR/$state/$svc")" = "$root/etc/init.d/$svc" + done +} + +mkservice() { + service="$root/etc/init.d/$1" + cat > "$service" <<-EOF + #!$SOURCE_ROOT/${openrc_run} + depend() { + ${2-:;} + } + start() { + ${3-sleep 0.1} + } + EOF + chmod +x "$service" +} + +mkservice nya +mkservice foo "need nya" +mkservice mew "want foo" + +addrunlevel() { + ln -s "$root/etc/init.d/${1?}" "$root/etc/runlevel/${2?}/$1" +} + +rc_service nya start +in_state started nya + +rc_service nya stop +( ! in_state started nya ) + +rc_service foo start +in_state started foo nya + +rc_service foo stop +in_state started nya +( ! in_state started foo ) + +rc_service foo start +in_state started foo nya + +rc_service nya stop +( ! in_state started foo nya ) + +rc_service mew start +in_state started foo nya mew + +rc_service nya stop +rc_service mew stop + +( ! in_state started foo nya mew ) diff --git a/test/units/rc-update.sh b/test/units/rc-update.sh new file mode 100755 index 00000000..d7437351 --- /dev/null +++ b/test/units/rc-update.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +set -ex + +. ${1?} +rc_update=${2?} + +rc_update() { + "$rc_update" --root "$root" "$@" 2>&1 +} + +in_runlevel() { + test "$(readlink "$root/etc/runlevels/${1?}/${2?}")" = "$root/etc/init.d/$2" +} + +stacked() { + test -d "$root/etc/runlevels/${1?}/${2?}" +} + +# non-existent +( ! rc_update add nya ) +( ! rc_update -s add nya ) +( ! rc_update del nya ) +( ! rc_update -s del nya ) + +cat > "$root/etc/init.d/nya" <<-EOF +#!/sbin/openrc-run +start() { + :; +} +EOF + +# non-executable +( ! rc_update add nya ) +( ! rc_update -s add nya ) + +chmod +x "$root/etc/init.d/nya" + +# implicit runlevel +rc_update add nya +in_runlevel default nya + +rc_update del nya +( ! in_runlevel default nya) +# not in the runlevel +( ! rc_update del nya ) + +# explicit runlevel +rc_update add nya default +in_runlevel default nya +# not in the specified runlevel +( ! rc_update del nya boop ) + +# stacking +rc_update -s add boop +stacked default boop + +rc_update -s del boop +( ! stacked boop nya ) + +rc_update -s add boop default +stacked default boop + +rc_update -s del boop +( ! stacked boop default ) +( ! rc_update -s del boop ) + +# show +rc_update add nya +rc_update | grep -qE "^\s*nya" +rc_update show | grep -qE "^\s*nya" +rc_update show default | grep -qE "^\s*nya" +rc_update del nya +( ! rc_update show | grep -qE "^\s*nya" ) +( ! rc_update show default | grep -qE "^\s*nya" ) + +exit 0 diff --git a/test/units/setup-root.sh b/test/units/setup-root.sh new file mode 100755 index 00000000..6545cb5d --- /dev/null +++ b/test/units/setup-root.sh @@ -0,0 +1,28 @@ +root=$(mktemp -d --tmpdir rc.XXXXXX) +#trap "rm -r $root" EXIT + +sysdir="$root/etc" +export RC_LIBEXECDIR="$BUILD_ROOT" +export RC_PATH="$sysdir" +export RC_SVCDIR="$root/run/openrc" +mkdir -p "$RC_SVCDIR" +echo "default" > "$RC_SVCDIR/softlevel" + +for dir in init.d conf.d runlevels; do + mkdir -p "$sysdir/$dir" +done +for dir in sysinit boot default boop shutdown; do + mkdir -p "$sysdir/runlevels/$dir" +done + +for dir in daemons exclusive failed hotplugged inactive init.d \ + options scheduled started starting stopping tmp wasinactive; do + mkdir -p "$root/run/openrc/$dir" +done + +setup_path() { + local IFS=: + export PATH="$PATH:$*" +} + +setup_path "$BUILD_ROOT"/src/* |
