debian/tests/timedated: Add tests for "timedatectl set-local-rtc"

This requires the fix for https://github.com/systemd/systemd/issues/2638.
This commit is contained in:
Martin Pitt 2016-02-26 15:57:52 +01:00
parent 74b1a4eda7
commit 45f38dcccc
3 changed files with 131 additions and 3 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
systemd (229-3) UNRELEASED; urgency=medium
* debian/tests/timedated: Add tests for "timedatectl set-local-rtc".
-- Martin Pitt <mpitt@debian.org> Mon, 29 Feb 2016 07:34:58 +0100
systemd (229-2) unstable; urgency=medium
* time-util: map ALARM clockids to non-ALARM clockids in now(), to work on

View File

@ -1,5 +1,13 @@
# utility functions for shell tests
assert_true() {
if ! $1; then
echo "FAIL: command '$1' failed with exit code $?" >&2
exit 1
fi
}
assert_eq() {
if [ "$1" != "$2" ]; then
echo "FAIL: expected: '$2' actual: '$1'" >&2

120
debian/tests/timedated vendored
View File

@ -6,17 +6,131 @@ set -e
ORIG_TZ=`grep -v '^#' /etc/timezone`
echo "original tz: $ORIG_TZ"
# should activate daemon and work
echo 'timedatectl works'
assert_in "Local time:" "`timedatectl --no-pager`"
# change timezone
echo 'change timezone'
assert_eq "`timedatectl --no-pager set-timezone Europe/Moscow 2>&1`" ""
assert_eq "`readlink /etc/localtime | sed 's#^.*zoneinfo/##'`" "Europe/Moscow"
[ -n "$TEST_UPSTREAM" ] || assert_eq "`cat /etc/timezone`" "Europe/Moscow"
assert_in "Time.*zone: Europe/Moscow (MSK, +" "`timedatectl --no-pager`"
# reset timezone to original
echo 'reset timezone to original'
assert_eq "`timedatectl --no-pager set-timezone $ORIG_TZ 2>&1`" ""
assert_eq "`readlink /etc/localtime | sed 's#^.*zoneinfo/##'`" "$ORIG_TZ"
[ -n "$TEST_UPSTREAM" ] || assert_eq "`cat /etc/timezone`" "$ORIG_TZ"
# test setting UTC vs. LOCAL in /etc/adjtime
if [ -e /etc/adjtime ]; then
ORIG_ADJTIME=`cat /etc/adjtime`
trap "echo '$ORIG_ADJTIME' > /etc/adjtime" EXIT INT QUIT PIPE
else
trap "rm -f /etc/adjtime" EXIT INT QUIT PIPE
fi
echo 'no adjtime file'
rm -f /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
echo 'UTC set in adjtime file'
printf '0.0 0 0\n0\nUTC\n' > /etc/adjtime
timedatectl set-local-rtc 0
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
UTC"
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
echo 'non-zero values in adjtime file'
printf '0.1 123 0\n0\nLOCAL\n' > /etc/adjtime
timedatectl set-local-rtc 0
assert_eq "`cat /etc/adjtime`" "0.1 123 0
0
UTC"
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.1 123 0
0
LOCAL"
echo 'fourth line adjtime file'
printf '0.0 0 0\n0\nLOCAL\nsomethingelse\n' > /etc/adjtime
timedatectl set-local-rtc 0
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
UTC
somethingelse"
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL
somethingelse"
echo 'no final newline in adjtime file'
printf '0.0 0 0\n0\nUTC' > /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
printf '0.0 0 0\n0\nUTC' > /etc/adjtime
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
echo 'only one line in adjtime file'
printf '0.0 0 0\n' > /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
printf '0.0 0 0\n' > /etc/adjtime
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
echo 'only one line in adjtime file, no final newline'
printf '0.0 0 0' > /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
printf '0.0 0 0' > /etc/adjtime
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
echo 'only two lines in adjtime file'
printf '0.0 0 0\n0\n' > /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
printf '0.0 0 0\n0\n' > /etc/adjtime
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
echo 'only two lines in adjtime file, no final newline'
printf '0.0 0 0\n0' > /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
printf '0.0 0 0\n0' > /etc/adjtime
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"
echo 'unknown value in 3rd line of adjtime file'
printf '0.0 0 0\n0\nFOO\n' > /etc/adjtime
timedatectl set-local-rtc 0
assert_true '[ ! -e /etc/adjtime ]'
printf '0.0 0 0\n0\nFOO\n' > /etc/adjtime
timedatectl set-local-rtc 1
assert_eq "`cat /etc/adjtime`" "0.0 0 0
0
LOCAL"