File: task.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (216 lines) | stat: -rw-r--r-- 11,294 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
summary: Ensure that the GPIO chardev interface works.

details: |
    The gpio-chardev interface allows read/write access to specified lines
    of GPIO character devices. GPIO chip devices are emulated using the
    gpio-sim module where they are setup early in boot.

# Kernels on Ubuntu Core <24 does not contain the gpio-sim module and test
# snap is not built for arm.
systems: [-ubuntu-core-18-*, -ubuntu-core-20-*, -ubuntu-core-22-*, -ubuntu-core-*-arm-*]

prepare: |
    # emulate GPIO chips using gpio-sim module
    cat << EOF > /etc/systemd/system/gpio-sim.service
    [Unit]
    Description=Emulate gpio chips early in boot
    After=sysinit.target
    Wants=sysinit.target
    [Service]
    Type=oneshot
    RemainAfterExit=true
    ExecStart=$PWD/mk-sim-chips.sh
    ExecStop=$PWD/rm-sim-chips.sh
    [Install]
    WantedBy=multi-user.target
    EOF
    tests.cleanup defer rm /etc/systemd/system/gpio-sim.service

    systemctl enable --now gpio-sim.service
    tests.cleanup defer systemctl disable --now gpio-sim.service

    sysfs_gpiochip_num=$(find /sys/class/gpio/ -maxdepth 1 -name 'gpiochip*' -printf "%f" -quit | cut -c9-)

    # save the current revision of the pc snap. At this moment the pc snap is
    # the original snap.
    original_revision=$(readlink /snap/pc/current)

    cp /var/lib/snapd/snaps/pc_*.snap gadget.snap
    unsquashfs -d pc-snap gadget.snap
    cp -r pc-snap pc-snap-without-gpio

    cat << EOF >> pc-snap/meta/snap.yaml
    slots:
      gpio-pin:
        interface: gpio
        number: $sysfs_gpiochip_num
        direction: out
      gpio-chardev-0:
        interface: gpio-chardev
        source-chip: [gpio-bank0]
        lines: 0-7
      gpio-chardev-1:
        interface: gpio-chardev
        source-chip: [gpio-bank1]
        lines: 0,6
    EOF

    cat << EOF >> pc-snap-without-gpio/meta/snap.yaml
    slots:
      gpio-chardev-0:
        interface: gpio-chardev
        source-chip: [gpio-bank0]
        lines: 0-7
      gpio-chardev-1:
        interface: gpio-chardev
        source-chip: [gpio-bank1]
        lines: 0,6
    EOF

    snap pack pc-snap --filename=pc_x1.snap
    snap pack pc-snap-without-gpio --filename=pc-snap-without-gpio_x1.snap
    snap install pc_x1.snap --dangerous
    tests.cleanup defer snap revert pc --revision="$original_revision"

    snap install test-snapd-gpio-chardev
    tests.cleanup defer snap remove --purge test-snapd-gpio-chardev

    snap install test-snapd-gpio-control
    tests.cleanup defer snap remove --purge test-snapd-gpio-control

    snap connect test-snapd-gpio-control:gpio-control

    # Install "gpio" consumer snap to test conflict detection
    # of active connections
    "$TESTSTOOLS"/snaps-state install-local gpio-consumer

execute: |
    if [ "$SPREAD_REBOOT" = 0 ]; then
        # Check number of gpiochips before connection
        find /dev/gpiochip* | wc -l | MATCH '^2$'

        echo 'Test conflict detection with "gpio" connection'
        snap connect gpio-consumer:gpio pc:gpio-pin
        not snap connect test-snapd-gpio-chardev:gpio-chardev-0 pc:gpio-chardev-0 2> conflict.out
        MATCH 'interface "gpio-chardev" and "gpio" cannot be connected at the same time: "gpio" is already connected' < conflict.out
        
        snap disconnect gpio-consumer:gpio pc:gpio-pin
        # gpio-chardev connection works  now 
        snap connect test-snapd-gpio-chardev:gpio-chardev-0 pc:gpio-chardev-0

        echo "and vice-versa conflict is also detected"
        not snap connect gpio-consumer:gpio pc:gpio-pin 2> conflict.out
        MATCH 'interface "gpio" and "gpio-chardev" cannot be connected at the same time: "gpio-chardev" is already connected' < conflict.out

        # Test that refreshing the gadget to a revision without "gpio" slots automatically
        # disconnects existing connections
        snap disconnect test-snapd-gpio-chardev:gpio-chardev-0 pc:gpio-chardev-0
        snap connect gpio-consumer:gpio pc:gpio-pin
        # Cannot connect gpio-chardev
        not snap connect test-snapd-gpio-chardev:gpio-chardev-0 pc:gpio-chardev-0 2> conflict.out
        MATCH 'interface "gpio-chardev" and "gpio" cannot be connected at the same time: "gpio" is already connected' < conflict.out
        # Perform gadget refresh
        snap install pc-snap-without-gpio_x1.snap --dangerous
        # Now gpio-chardev can be connected that gpio connections were automatically
        # disconnected due to missing slots
        snap connect test-snapd-gpio-chardev:gpio-chardev-0 pc:gpio-chardev-0
        snap connect test-snapd-gpio-chardev:gpio-chardev-1 pc:gpio-chardev-1

        # Check number of gpiochips after connection
        find /dev/gpiochip* | wc -l | MATCH '^4$'

        echo "The gpio chips are exported for the gadget slot"
        test -c /dev/snap/gpio-chardev/pc/gpio-chardev-0
        test -c /dev/snap/gpio-chardev/pc/gpio-chardev-1
        echo "And symlinks created on the consumer plug side"
        readlink /dev/snap/gpio-chardev/test-snapd-gpio-chardev/gpio-chardev-0 | MATCH /dev/snap/gpio-chardev/pc/gpio-chardev-0
        readlink /dev/snap/gpio-chardev/test-snapd-gpio-chardev/gpio-chardev-1 | MATCH /dev/snap/gpio-chardev/pc/gpio-chardev-1

        echo "and the right lines are being exported"
        # lines 0-7 are exported
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*0:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*1:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*2:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*3:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*4:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*5:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*6:.*consumer=gpio-aggregator.0"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip0 | MATCH "line.*7:.*consumer=gpio-aggregator.0"
        # lines 0 and 6 only are exported
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | MATCH "line.*0:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | NOMATCH "line.*1:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | NOMATCH "line.*2:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | NOMATCH "line.*3:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | NOMATCH "line.*4:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | NOMATCH "line.*5:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | MATCH "line.*6:.*consumer=gpio-aggregator.1"
        test-snapd-gpio-control.gpioinfo --chip /dev/gpiochip1 | NOMATCH "line.*7:.*consumer=gpio-aggregator.1"

        echo "And gpio-chardev setup dependency was injected into snap service"
        systemctl show --property=After snap.test-snapd-gpio-chardev.svc.service | MATCH "gpio-chardev-setup.target"
        systemctl show --property=Wants snap.test-snapd-gpio-chardev.svc.service | MATCH "gpio-chardev-setup.target"

        mkdir -p /var/snap/test-snapd-gpio-chardev/common/gpiochips
        printf "0\n1\n0\n0\n0\n1\n0\n1\n" > /var/snap/test-snapd-gpio-chardev/common/gpiochips/gpio-chardev-0
        printf "1\n1\n" > /var/snap/test-snapd-gpio-chardev/common/gpiochips/gpio-chardev-1

        # Restart service for values to take effect
        snap restart test-snapd-gpio-chardev.svc

        chip=/dev/snap/gpio-chardev/pc/gpio-chardev-0
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 0 | MATCH '^"0"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 1 | MATCH '^"1"=active$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 2 | MATCH '^"2"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 3 | MATCH '^"3"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 4 | MATCH '^"4"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 5 | MATCH '^"5"=active$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 6 | MATCH '^"6"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 7 | MATCH '^"7"=active$'

        chip=/dev/snap/gpio-chardev/pc/gpio-chardev-1
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 0 | MATCH '^"0"=active$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 1 | MATCH '^"1"=active$'

        REBOOT
    elif [ "$SPREAD_REBOOT" = 1 ]; then
        echo "Snap service should have properly set the gpio lines for each chip"

        chip=/dev/snap/gpio-chardev/pc/gpio-chardev-0
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 0 | MATCH '^"0"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 1 | MATCH '^"1"=active$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 2 | MATCH '^"2"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 3 | MATCH '^"3"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 4 | MATCH '^"4"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 5 | MATCH '^"5"=active$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 6 | MATCH '^"6"=inactive$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 7 | MATCH '^"7"=active$'

        chip=/dev/snap/gpio-chardev/pc/gpio-chardev-1
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 0 | MATCH '^"0"=active$'
        test-snapd-gpio-chardev.cmd gpioget --chip "$chip" 1 | MATCH '^"1"=active$'

        echo "Disconnecting unexports the aggregated devices"
        snap disconnect test-snapd-gpio-chardev:gpio-chardev-0 pc:gpio-chardev-0
        snap disconnect test-snapd-gpio-chardev:gpio-chardev-1 pc:gpio-chardev-1
        not test -e /dev/snap/gpio-chardev/pc/gpio-chardev-0
        not test -e /dev/snap/gpio-chardev/pc/gpio-chardev-1
        not test -e /dev/snap/gpio-chardev/test-snapd-gpio-chardev/gpio-chardev-0
        not test -e /dev/snap/gpio-chardev/test-snapd-gpio-chardev/gpio-chardev-1

        # Check number of gpiochips
        find /dev/gpiochip* | wc -l | MATCH '^2$'

        # Reboot one last time to make sure services run normally even when disconnected
        rm -rf /var/snap/test-snapd-gpio-chardev/common/gpiochips
        REBOOT
    elif [ "$SPREAD_REBOOT" = 2 ]; then
        echo "Snap service runs"
        retry -n 20 --wait 2 sh -c 'journalctl -u snap.test-snapd-gpio-chardev.svc | MATCH "no chips found under /var/snap/test-snapd-gpio-chardev/common/gpiochips, exiting..."'

        echo "And aggregated devices are still unexported"
        find /dev/gpiochip* | wc -l | MATCH '^2$'
        not test -e /dev/snap/gpio-chardev/pc/gpio-chardev-0
        not test -e /dev/snap/gpio-chardev/pc/gpio-chardev-1
        not test -e /dev/snap/gpio-chardev/test-snapd-gpio-chardev/gpio-chardev-0
        not test -e /dev/snap/gpio-chardev/test-snapd-gpio-chardev/gpio-chardev-1
    fi