summary: Check that launcher cgroup functionality works
# This is blacklisted on debian because we first have to get the dpkg-vendor patches
systems: [-debian-8]
prepare: |
    echo "Install snapd-hacker-toolbelt"
    snap install snapd-hacker-toolbelt
execute: |
    cd /
    echo "Clear udev tags and cgroups with non-test device and running snapd-hacker-toolbelt.busybox"
    echo 'KERNEL=="uinput", TAG+="snap_snapd-hacker-toolbelt_busybox"' > /etc/udev/rules.d/70-spread-test.rules
    udevadm control --reload-rules
    udevadm settle
    udevadm trigger
    udevadm settle
    snapd-hacker-toolbelt.busybox echo "Hello World" | grep Hello
    echo "Verify no tags for snapd-hacker-toolbelt.busybox for kmsg"
    if udevadm info /sys/devices/virtual/mem/kmsg | grep snap_snapd-hacker-toolbelt_busybox ; then exit 1; fi
    echo "Manually add udev tags for snapd-hacker-toolbelt.busybox for kmsg"
    echo 'KERNEL=="kmsg", TAG+="snap_snapd-hacker-toolbelt_busybox"' > /etc/udev/rules.d/70-spread-test.rules
    echo "Simulate snapd udev triggers"
    udevadm control --reload-rules
    udevadm settle
    udevadm trigger
    udevadm settle
    echo "Verify udev has tag for kmsg"
    if ! udevadm info /sys/devices/virtual/mem/kmsg | grep snap_snapd-hacker-toolbelt_busybox; then exit 1; fi
    echo "Run snapd-hacker-toolbelt.busybox echo and see if kmsg added to cgroup"
    snapd-hacker-toolbelt.busybox echo "Hello World" | grep Hello
    if ! grep 'c 1:11 rwm' /sys/fs/cgroup/devices/snap.snapd-hacker-toolbelt.busybox/devices.list ; then exit 1; fi
restore: |
    snap remove --purge snapd-hacker-toolbelt
    rm -f /etc/udev/rules.d/70-spread-test.rules
    udevadm control --reload-rules
    udevadm settle
    udevadm trigger
    udevadm settle
    # no way to clear cgroup for snapd-hacker-toolbelt atm
