github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/hugepages_control_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 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/snap" 29 "github.com/snapcore/snapd/snap/snaptest" 30 "github.com/snapcore/snapd/testutil" 31 ) 32 33 type HugepagesControlSuite struct { 34 iface interfaces.Interface 35 slotInfo *snap.SlotInfo 36 slot *interfaces.ConnectedSlot 37 plugInfo *snap.PlugInfo 38 plug *interfaces.ConnectedPlug 39 } 40 41 var _ = Suite(&HugepagesControlSuite{ 42 iface: builtin.MustInterface("hugepages-control"), 43 }) 44 45 func (s *HugepagesControlSuite) SetUpTest(c *C) { 46 const producerYaml = `name: core 47 version: 0 48 type: os 49 slots: 50 hugepages-control: 51 ` 52 info := snaptest.MockInfo(c, producerYaml, nil) 53 s.slotInfo = info.Slots["hugepages-control"] 54 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 55 56 const consumerYaml = `name: consumer 57 version: 0 58 apps: 59 app: 60 plugs: [hugepages-control] 61 ` 62 info = snaptest.MockInfo(c, consumerYaml, nil) 63 s.plugInfo = info.Plugs["hugepages-control"] 64 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 65 } 66 67 func (s *HugepagesControlSuite) TestName(c *C) { 68 c.Assert(s.iface.Name(), Equals, "hugepages-control") 69 } 70 71 func (s *HugepagesControlSuite) TestSanitizeSlot(c *C) { 72 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 73 } 74 75 func (s *HugepagesControlSuite) TestSanitizePlug(c *C) { 76 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 77 } 78 79 func (s *HugepagesControlSuite) TestAppArmorSpec(c *C) { 80 spec := &apparmor.Specification{} 81 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 82 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 83 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, 84 "/sys/kernel/mm/hugepages/{,hugepages-[0-9]*}/* r,") 85 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, 86 "/sys/kernel/mm/hugepages/{,hugepages-[0-9]*}/nr_{hugepages,hugepages_mempolicy,overcommit_hugepages} w,") 87 } 88 89 func (s *HugepagesControlSuite) TestStaticInfo(c *C) { 90 si := interfaces.StaticInfoOf(s.iface) 91 c.Assert(si.ImplicitOnCore, Equals, true) 92 c.Assert(si.ImplicitOnClassic, Equals, true) 93 c.Assert(si.Summary, Equals, "allows controlling hugepages") 94 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "hugepages-control") 95 } 96 97 func (s *HugepagesControlSuite) TestAutoConnect(c *C) { 98 // FIXME: fix AutoConnect methods to use ConnectedPlug/Slot 99 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 100 } 101 102 func (s *HugepagesControlSuite) TestInterfaces(c *C) { 103 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 104 }