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
|
summary: Check that RTC device nodes are accessible through an interface
details: |
This test makes sure that a snap using the time-control interface
can access the /dev/rtc device node exposed by a slot on the OS
snap properly.
# s390x virtualization does not support hwclock
systems: [-opensuse-*,-fedora-*,-ubuntu-core-*,-ubuntu-14.04-*,-*-s390x,-arch-*]
prepare: |
# Install a snap declaring a plug on time-control
"$TESTSTOOLS"/snaps-state install-local test-snapd-timedate-control-consumer
date +'%m%d%H%M.%y' > now.txt
restore: |
# Restore the initial rtc configuration
if [ -f rtc.txt ]; then
timedatectl set-local-rtc "$(cat rtc.txt)"
fi
# TODO: re-enable once the ntp issue is fixed
#date "$(cat now.txt)"
execute: |
# hwclock with libaudit (ie, core 16) also needs netlink-audit connected.
# This interface is tested elsewhere, so simply connect it here so we can
# test the time-control interface in isolation.
snap connect test-snapd-timedate-control-consumer:netlink-audit
echo "The interface is disconnected by default"
snap interfaces -i time-control | MATCH -- '^- +test-snapd-timedate-control-consumer:time-control'
echo "When the interface is connected"
snap connect test-snapd-timedate-control-consumer:time-control
echo "Then read/write hwclock access should be possible"
test-snapd-timedate-control-consumer.hwclock-time -r -f /dev/rtc
test-snapd-timedate-control-consumer.hwclock-time --systohc -f /dev/rtc
echo "And read access should be possible"
test-snapd-timedate-control-consumer.timedatectl-time status | MATCH "RTC in local TZ:"
echo "And writing the initial value to RTC should be possible"
test-snapd-timedate-control-consumer.timedatectl-time status | grep -oP 'RTC in local TZ: \K(.*)' > rtc.txt
echo "And reading/writing local RTC status should be possible"
test-snapd-timedate-control-consumer.timedatectl-time set-local-rtc yes
[ "$(test-snapd-timedate-control-consumer.timedatectl-time status | grep -oP 'RTC in local TZ: \K(.*)')" = "yes" ]
echo "And resetting the local rtc status should be possible (reading the status is implied AIUI)"
test-snapd-timedate-control-consumer.timedatectl-time set-local-rtc no
[ "$(test-snapd-timedate-control-consumer.timedatectl-time status | grep -oP 'RTC in local TZ: \K(.*)')" = "no" ]
echo "And direct setting via date"
# Ntp synchronization is not done after the date is changed using the date command.
# The issue happens even when the synchronization is manually forced.
# The error displayed in the journal is the following:
# synchronized.go:72: DEBUG: NTPSynchronized state returned by timedate1: false
# TODO: re-enable once the ntp issue is fixed
#nice_when="$(date -d 'tomorrow' +'%m%d%H%M.%y')"
#test-snapd-timedate-control-consumer.date "$nice_when"
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
fi
# make sure that we can access the files in /sys/class/rtc
test-snapd-timedate-control-consumer.sh -c "cat /sys/class/rtc/rtc0/name"
echo "When the plug is disconnected"
snap disconnect test-snapd-timedate-control-consumer:time-control
echo "The timedatectl status cannot be retrieved"
if test-snapd-timedate-control-consumer.timedatectl-time status 2> call.error; then
echo "Expected permission error calling timedatectl status with disconnected plug"
exit 1
fi
MATCH "Permission denied" < call.error
now="$(cat now.txt)"
not test-snapd-timedate-control-consumer.date "$now" 2> call.error
# EPERM because date gets blocked by the seccomp profile
MATCH "cannot set date: Operation not permitted" < call.error
not test-snapd-timedate-control-consumer.sh -c "cat /sys/class/rtc/rtc0/name"
|