gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/broadcom_asic_control_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2017 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/kmod" 32 "gitee.com/mysnapcore/mysnapd/interfaces/udev" 33 "gitee.com/mysnapcore/mysnapd/snap" 34 "gitee.com/mysnapcore/mysnapd/snap/snaptest" 35 "gitee.com/mysnapcore/mysnapd/testutil" 36 ) 37 38 type BroadcomAsicControlSuite struct { 39 iface interfaces.Interface 40 slotInfo *snap.SlotInfo 41 slot *interfaces.ConnectedSlot 42 plugInfo *snap.PlugInfo 43 plug *interfaces.ConnectedPlug 44 } 45 46 var _ = Suite(&BroadcomAsicControlSuite{ 47 iface: builtin.MustInterface("broadcom-asic-control"), 48 }) 49 50 func (s *BroadcomAsicControlSuite) SetUpTest(c *C) { 51 const producerYaml = `name: core 52 version: 0 53 type: os 54 slots: 55 broadcom-asic-control: 56 ` 57 info := snaptest.MockInfo(c, producerYaml, nil) 58 s.slotInfo = info.Slots["broadcom-asic-control"] 59 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 60 61 const consumerYaml = `name: consumer 62 version: 0 63 apps: 64 app: 65 plugs: [broadcom-asic-control] 66 ` 67 info = snaptest.MockInfo(c, consumerYaml, nil) 68 s.plugInfo = info.Plugs["broadcom-asic-control"] 69 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 70 } 71 72 func (s *BroadcomAsicControlSuite) TestName(c *C) { 73 c.Assert(s.iface.Name(), Equals, "broadcom-asic-control") 74 } 75 76 func (s *BroadcomAsicControlSuite) TestSanitizeSlot(c *C) { 77 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 78 } 79 80 func (s *BroadcomAsicControlSuite) TestSanitizePlug(c *C) { 81 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 82 } 83 84 func (s *BroadcomAsicControlSuite) TestAppArmorSpec(c *C) { 85 spec := &apparmor.Specification{} 86 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 87 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 88 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "/sys/module/linux_kernel_bde/{,**} r,") 89 } 90 91 func (s *BroadcomAsicControlSuite) TestUDevSpec(c *C) { 92 spec := &udev.Specification{} 93 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 94 c.Assert(spec.Snippets(), HasLen, 3) 95 c.Assert(spec.Snippets(), testutil.Contains, `# broadcom-asic-control 96 SUBSYSTEM=="net", KERNEL=="bcm[0-9]*", TAG+="snap_consumer_app"`) 97 c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir)) 98 } 99 100 func (s *BroadcomAsicControlSuite) TestKModSpec(c *C) { 101 spec := &kmod.Specification{} 102 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 103 c.Assert(spec.Modules(), DeepEquals, map[string]bool{ 104 "linux-user-bde": true, 105 "linux-kernel-bde": true, 106 "linux-bcm-knet": true, 107 }) 108 } 109 110 func (s *BroadcomAsicControlSuite) TestStaticInfo(c *C) { 111 si := interfaces.StaticInfoOf(s.iface) 112 c.Assert(si.ImplicitOnCore, Equals, true) 113 c.Assert(si.ImplicitOnClassic, Equals, true) 114 c.Assert(si.Summary, Equals, "allows using the broadcom-asic kernel module") 115 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "broadcom-asic-control") 116 } 117 118 func (s *BroadcomAsicControlSuite) TestAutoConnect(c *C) { 119 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 120 } 121 122 func (s *BroadcomAsicControlSuite) TestInterfaces(c *C) { 123 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 124 }