File: task.yaml

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (95 lines) | stat: -rw-r--r-- 3,651 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
summary: Ensure that the alsa interface works.

details: |
    The alsa interface allows connected plugs to access raw ALSA devices.

    A snap which defines a alsa plug must be shown in the interfaces list.
    The plug must not be autoconnected on install and, as usual, must be able to
    be reconnected.

    A snap declaring a plug on this interface must be able to access to raw ALSA
    devices, for this test we check the low level security rules by creating
    specific devices under /dev/snd, a cgroup if needed and the ALSA state dir,
    exercising in each case the read or read-write permissions that must be in
    place.

# Spread system for Fedora, openSUSE and AMZN2 don't seem to provide any /dev/snd entries
systems: [-fedora-*, -opensuse-*, -amazon-*, -centos-*]

prepare: |
    echo "Given a snap declaring a plug on the alsa interface is installed"
    #shellcheck source=tests/lib/snaps.sh
    . "$TESTSLIB"/snaps.sh
    install_generic_consumer alsa

restore: |
    rm -f /dev/snd/mysnd-dev

execute: |
    echo "When the plug is connected"
    snap connect generic-consumer:alsa

    if ! [ -d /dev/snd/ ]; then
        echo "No sound devices available in the system"
        exit 0
    fi

    echo "Then the snap is able to access snd devices"
    mkdir -p /dev/snd
    generic-consumer.cmd touch /dev/snd/mysnd-dev
    echo "mysnd-dev-content" | tee /dev/snd/mysnd-dev
    generic-consumer.cmd cat /dev/snd/mysnd-dev | MATCH mysnd-dev-content
    generic-consumer.cmd rm /dev/snd/mysnd-dev

    echo "And the snap is able to access the related udev data"
    if [ ! -f /run/udev/data/c116:0 ]; then
        touch /run/udev/data/c116:0
        echo "myudevdata-content" | tee /run/udev/data/c116:0
        generic-consumer.cmd cat /run/udev/data/c116:0 | MATCH myudevdata-content
        rm /run/udev/data/c116:0
    fi

    # TODO: extend test to check /var/lib/alsa with plug connected when
    # https://bugs.launchpad.net/snapd/+bug/1694281 is fixed

    if [ "$(snap debug confinement)" = partial ] ; then
        echo "Do not execute checks with disconnected plug on systems where confinement doesn't work"
        exit 0
    fi

    echo "When the plug is disconnected"
    snap disconnect generic-consumer:alsa

    echo "The snap is not able to access snd devices"
    if generic-consumer.cmd touch /dev/snd/mysnd-dev 2>snd-create.error; then
        echo "Create snd device with disconnected plug should fail"
        exit 1
    fi
    MATCH "Permission denied" ./snd-create.error
    touch /dev/snd/mysnd-dev
    echo "mysnd-content" | tee /dev/snd/mysnd-dev
    if generic-consumer.cmd cat /dev/snd/mysnd-dev 2>snd-read.error; then
        echo "Read snd device with disconnected plug should fail"
        exit 1
    fi
    MATCH "Permission denied" ./snd-read.error
    if generic-consumer.cmd rm /dev/snd/mysnd-dev 2>snd-del.error; then
        echo "Delete snd device with disconnected plug should fail"
        exit 1
    fi
    MATCH "Permission denied" ./snd-del.error

    echo "And the snap is not able to access the related udev data"
    if [ ! -f /run/udev/data/c116:0 ]; then
        touch /run/udev/data/c116:0
        echo "myudevdata-content" | tee /run/udev/data/c116:0
        if generic-consumer.cmd cat /run/udev/data/c116:0 2>udevdata-read.error; then
            echo "Read udev data file with disconnected plug should fail"
            exit 1
        fi
        MATCH "Permission denied" ./udevdata-read.error
        rm /run/udev/data/c116:0
    fi

    # TODO: extend test to check /var/lib/alsa with plug disconnected when
    # https://bugs.launchpad.net/snapd/+bug/1694281 is fixed