github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/interfaces/builtin/dsp_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package builtin_test 21 22 import ( 23 "fmt" 24 25 . "gopkg.in/check.v1" 26 27 "github.com/snapcore/snapd/dirs" 28 "github.com/snapcore/snapd/interfaces" 29 "github.com/snapcore/snapd/interfaces/apparmor" 30 "github.com/snapcore/snapd/interfaces/builtin" 31 "github.com/snapcore/snapd/interfaces/udev" 32 "github.com/snapcore/snapd/snap" 33 "github.com/snapcore/snapd/testutil" 34 ) 35 36 type dspSuite struct { 37 iface interfaces.Interface 38 39 ambarellaSlotInfo *snap.SlotInfo 40 ambarellaSlot *interfaces.ConnectedSlot 41 noFlavorSlotInfo *snap.SlotInfo 42 noFlavorSlot *interfaces.ConnectedSlot 43 plugInfo *snap.PlugInfo 44 plug *interfaces.ConnectedPlug 45 } 46 47 var _ = Suite(&dspSuite{ 48 iface: builtin.MustInterface("dsp"), 49 }) 50 51 const dspMockPlugSnapInfoYaml = ` 52 name: my-device 53 version: 1.0 54 apps: 55 svc: 56 command: bin/foo.sh 57 plugs: 58 - dsp 59 ` 60 61 const gadgetDspSlotYaml = ` 62 name: my-gadget 63 version: 1.0 64 type: gadget 65 slots: 66 dsp-ambarella: 67 interface: dsp 68 flavor: ambarella 69 dsp-no-flavor: 70 interface: dsp 71 ` 72 73 func (s *dspSuite) SetUpTest(c *C) { 74 s.noFlavorSlot, s.noFlavorSlotInfo = MockConnectedSlot(c, gadgetDspSlotYaml, nil, "dsp-no-flavor") 75 s.ambarellaSlot, s.ambarellaSlotInfo = MockConnectedSlot(c, gadgetDspSlotYaml, nil, "dsp-ambarella") 76 s.plug, s.plugInfo = MockConnectedPlug(c, dspMockPlugSnapInfoYaml, nil, "dsp") 77 78 } 79 80 func (s *dspSuite) TestName(c *C) { 81 c.Assert(s.iface.Name(), Equals, "dsp") 82 } 83 84 func (s *dspSuite) TestSanitizeSlotNoFlavor(c *C) { 85 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.noFlavorSlotInfo), IsNil) 86 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.ambarellaSlotInfo), IsNil) 87 } 88 89 func (s *dspSuite) TestSanitizeSlotAmbarella(c *C) { 90 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.ambarellaSlotInfo), IsNil) 91 } 92 93 func (s *dspSuite) TestSanitizePlug(c *C) { 94 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 95 } 96 97 func (s *dspSuite) TestApparmorConnectedPlugAmbarella(c *C) { 98 spec := &apparmor.Specification{} 99 err := spec.AddConnectedPlug(s.iface, s.plug, s.ambarellaSlot) 100 c.Assert(err, IsNil) 101 c.Assert(spec.SnippetForTag("snap.my-device.svc"), testutil.Contains, "/proc/ambarella/vin0_idsp rw,\n") 102 } 103 104 func (s *dspSuite) TestUDevConnectedPlugAmbarella(c *C) { 105 spec := &udev.Specification{} 106 err := spec.AddConnectedPlug(s.iface, s.plug, s.ambarellaSlot) 107 c.Assert(err, IsNil) 108 c.Assert(spec.Snippets(), HasLen, 5) 109 c.Assert(spec.Snippets(), testutil.Contains, `# dsp 110 KERNEL=="iav", TAG+="snap_my-device_svc"`) 111 c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_my-device_svc", RUN+="%v/snap-device-helper $env{ACTION} snap_my-device_svc $devpath $major:$minor"`, dirs.DistroLibExecDir)) 112 } 113 114 func (s *dspSuite) TestUDevConnectedPlugNoFlavor(c *C) { 115 spec := &udev.Specification{} 116 err := spec.AddConnectedPlug(s.iface, s.plug, s.noFlavorSlot) 117 c.Assert(err, IsNil) 118 c.Assert(spec.Snippets(), HasLen, 0) 119 } 120 121 func (s *dspSuite) TestApparmorConnectedPlugNoFlavor(c *C) { 122 spec := &apparmor.Specification{} 123 err := spec.AddConnectedPlug(s.iface, s.plug, s.noFlavorSlot) 124 c.Assert(err, IsNil) 125 c.Assert(spec.Snippets(), HasLen, 0) 126 } 127 128 func (s *dspSuite) TestInterfaces(c *C) { 129 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 130 }