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