gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/time_control_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016-2018 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/seccomp" 32 "gitee.com/mysnapcore/mysnapd/interfaces/udev" 33 "gitee.com/mysnapcore/mysnapd/snap" 34 "gitee.com/mysnapcore/mysnapd/testutil" 35 ) 36 37 type TimeControlInterfaceSuite struct { 38 iface interfaces.Interface 39 slotInfo *snap.SlotInfo 40 slot *interfaces.ConnectedSlot 41 plugInfo *snap.PlugInfo 42 plug *interfaces.ConnectedPlug 43 } 44 45 var _ = Suite(&TimeControlInterfaceSuite{ 46 iface: builtin.MustInterface("time-control"), 47 }) 48 49 const timectlConsumerYaml = `name: consumer 50 version: 0 51 apps: 52 app: 53 plugs: [time-control] 54 ` 55 56 const timectlCoreYaml = `name: core 57 version: 0 58 type: os 59 slots: 60 time-control: 61 ` 62 63 func (s *TimeControlInterfaceSuite) SetUpTest(c *C) { 64 s.plug, s.plugInfo = MockConnectedPlug(c, timectlConsumerYaml, nil, "time-control") 65 s.slot, s.slotInfo = MockConnectedSlot(c, timectlCoreYaml, nil, "time-control") 66 } 67 68 func (s *TimeControlInterfaceSuite) TestName(c *C) { 69 c.Assert(s.iface.Name(), Equals, "time-control") 70 } 71 72 func (s *TimeControlInterfaceSuite) TestSanitizeSlot(c *C) { 73 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 74 } 75 76 func (s *TimeControlInterfaceSuite) TestSanitizePlug(c *C) { 77 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 78 } 79 80 func (s *TimeControlInterfaceSuite) TestAppArmorSpec(c *C) { 81 spec := &apparmor.Specification{} 82 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 83 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 84 c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "org/freedesktop/timedate1") 85 } 86 87 func (s *TimeControlInterfaceSuite) TestSecCompSpec(c *C) { 88 spec := &seccomp.Specification{} 89 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 90 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 91 92 snippet := spec.SnippetForTag("snap.consumer.app") 93 for _, needle := range []string{ 94 "settimeofday", 95 "adjtimex", 96 "socket AF_NETLINK - NETLINK_AUDIT", 97 "clock_adjtime", 98 "clock_adjtime64", 99 "clock_settime", 100 "clock_settime64", 101 } { 102 c.Check(snippet, testutil.Contains, needle) 103 } 104 } 105 106 func (s *TimeControlInterfaceSuite) TestUDevSpec(c *C) { 107 spec := &udev.Specification{} 108 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 109 c.Assert(spec.Snippets(), HasLen, 3) 110 c.Assert(spec.Snippets(), testutil.Contains, `# time-control 111 SUBSYSTEM=="rtc", TAG+="snap_consumer_app"`) 112 c.Assert(spec.Snippets(), testutil.Contains, `# time-control 113 KERNEL=="pps[0-9]*", TAG+="snap_consumer_app"`) 114 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)) 115 } 116 117 func (s *TimeControlInterfaceSuite) TestStaticInfo(c *C) { 118 si := interfaces.StaticInfoOf(s.iface) 119 c.Assert(si.ImplicitOnCore, Equals, true) 120 c.Assert(si.ImplicitOnClassic, Equals, true) 121 c.Assert(si.Summary, Equals, `allows setting system date and time`) 122 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "time-control") 123 } 124 125 func (s *TimeControlInterfaceSuite) TestAutoConnect(c *C) { 126 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 127 } 128 129 func (s *TimeControlInterfaceSuite) TestInterfaces(c *C) { 130 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 131 }