gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/allegro_vcu_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 AllegroVcuInterfaceSuite struct { 37 iface interfaces.Interface 38 coreSlotInfo *snap.SlotInfo 39 coreSlot *interfaces.ConnectedSlot 40 plugInfo *snap.PlugInfo 41 plug *interfaces.ConnectedPlug 42 } 43 44 var _ = Suite(&AllegroVcuInterfaceSuite{ 45 iface: builtin.MustInterface("allegro-vcu"), 46 }) 47 48 const allegroVcuConsumerYaml = `name: consumer 49 version: 0 50 apps: 51 app: 52 plugs: [allegro-vcu] 53 ` 54 55 const allegroVcuCoreYaml = `name: core 56 version: 0 57 type: os 58 slots: 59 allegro-vcu: 60 ` 61 62 func (s *AllegroVcuInterfaceSuite) SetUpTest(c *C) { 63 s.plug, s.plugInfo = MockConnectedPlug(c, allegroVcuConsumerYaml, nil, "allegro-vcu") 64 s.coreSlot, s.coreSlotInfo = MockConnectedSlot(c, allegroVcuCoreYaml, nil, "allegro-vcu") 65 } 66 67 func (s *AllegroVcuInterfaceSuite) TestName(c *C) { 68 c.Assert(s.iface.Name(), Equals, "allegro-vcu") 69 } 70 71 func (s *AllegroVcuInterfaceSuite) TestSanitizeSlot(c *C) { 72 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.coreSlotInfo), IsNil) 73 } 74 75 func (s *AllegroVcuInterfaceSuite) TestSanitizePlug(c *C) { 76 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 77 } 78 79 func (s *AllegroVcuInterfaceSuite) TestAppArmorSpec(c *C) { 80 spec := &apparmor.Specification{} 81 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.coreSlot), IsNil) 82 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 83 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/allegroDecodeIP rw,`) 84 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/allegroIP rw,`) 85 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/dmaproxy rw,`) 86 } 87 88 func (s *AllegroVcuInterfaceSuite) TestUDevSpec(c *C) { 89 spec := &udev.Specification{} 90 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.coreSlot), IsNil) 91 c.Assert(spec.Snippets(), HasLen, 4) 92 c.Assert(spec.Snippets(), testutil.Contains, `# allegro-vcu 93 SUBSYSTEM=="allegro_decode_class", KERNEL=="allegroDecodeIP", TAG+="snap_consumer_app"`) 94 c.Assert(spec.Snippets(), testutil.Contains, `# allegro-vcu 95 SUBSYSTEM=="allegro_encode_class", KERNEL=="allegroIP", TAG+="snap_consumer_app"`) 96 c.Assert(spec.Snippets(), testutil.Contains, `# allegro-vcu 97 SUBSYSTEM=="char", KERNEL=="dmaproxy", TAG+="snap_consumer_app"`) 98 c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf( 99 `TAG=="snap_consumer_app", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir)) 100 } 101 102 func (s *AllegroVcuInterfaceSuite) TestStaticInfo(c *C) { 103 si := interfaces.StaticInfoOf(s.iface) 104 c.Assert(si.ImplicitOnCore, Equals, true) 105 c.Assert(si.ImplicitOnClassic, Equals, true) 106 c.Assert(si.Summary, Equals, `allows access to Allegro Video Code Unit`) 107 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true") 108 } 109 110 func (s *AllegroVcuInterfaceSuite) TestInterfaces(c *C) { 111 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 112 }