gitee.com/mysnapcore/mysnapd@v0.1.0/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 "gitee.com/mysnapcore/mysnapd/dirs" 28 "gitee.com/mysnapcore/mysnapd/interfaces" 29 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 30 "gitee.com/mysnapcore/mysnapd/interfaces/builtin" 31 "gitee.com/mysnapcore/mysnapd/interfaces/udev" 32 "gitee.com/mysnapcore/mysnapd/snap" 33 "gitee.com/mysnapcore/mysnapd/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 func (s *dspSuite) TestName(c *C) { 80 c.Assert(s.iface.Name(), Equals, "dsp") 81 } 82 83 func (s *dspSuite) TestSanitizeSlotNoFlavor(c *C) { 84 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.noFlavorSlotInfo), IsNil) 85 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.ambarellaSlotInfo), IsNil) 86 } 87 88 func (s *dspSuite) TestSanitizeSlotAmbarella(c *C) { 89 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.ambarellaSlotInfo), IsNil) 90 } 91 92 func (s *dspSuite) TestSanitizePlug(c *C) { 93 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 94 } 95 96 func (s *dspSuite) TestApparmorConnectedPlugAmbarella(c *C) { 97 spec := &apparmor.Specification{} 98 err := spec.AddConnectedPlug(s.iface, s.plug, s.ambarellaSlot) 99 c.Assert(err, IsNil) 100 c.Assert(spec.SnippetForTag("snap.my-device.svc"), testutil.Contains, "/proc/ambarella/vin[0-9]_idsp r,\n") 101 } 102 103 func (s *dspSuite) TestUDevConnectedPlugAmbarella(c *C) { 104 spec := &udev.Specification{} 105 err := spec.AddConnectedPlug(s.iface, s.plug, s.ambarellaSlot) 106 c.Assert(err, IsNil) 107 c.Assert(spec.Snippets(), HasLen, 6) 108 c.Assert(spec.Snippets(), testutil.Contains, `# dsp 109 KERNEL=="iav", TAG+="snap_my-device_svc"`) 110 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)) 111 } 112 113 func (s *dspSuite) TestUDevConnectedPlugNoFlavor(c *C) { 114 spec := &udev.Specification{} 115 err := spec.AddConnectedPlug(s.iface, s.plug, s.noFlavorSlot) 116 c.Assert(err, IsNil) 117 c.Assert(spec.Snippets(), HasLen, 0) 118 } 119 120 func (s *dspSuite) TestApparmorConnectedPlugNoFlavor(c *C) { 121 spec := &apparmor.Specification{} 122 err := spec.AddConnectedPlug(s.iface, s.plug, s.noFlavorSlot) 123 c.Assert(err, IsNil) 124 c.Assert(spec.Snippets(), HasLen, 0) 125 } 126 127 func (s *dspSuite) TestInterfaces(c *C) { 128 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 129 }