gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/opengl_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/udev" 32 "gitee.com/mysnapcore/mysnapd/snap" 33 "gitee.com/mysnapcore/mysnapd/testutil" 34 ) 35 36 type OpenglInterfaceSuite struct { 37 iface interfaces.Interface 38 slotInfo *snap.SlotInfo 39 slot *interfaces.ConnectedSlot 40 plugInfo *snap.PlugInfo 41 plug *interfaces.ConnectedPlug 42 } 43 44 var _ = Suite(&OpenglInterfaceSuite{ 45 iface: builtin.MustInterface("opengl"), 46 }) 47 48 const openglConsumerYaml = `name: consumer 49 version: 0 50 apps: 51 app: 52 plugs: [opengl] 53 ` 54 55 const openglCoreYaml = `name: core 56 version: 0 57 type: os 58 slots: 59 opengl: 60 ` 61 62 func (s *OpenglInterfaceSuite) SetUpTest(c *C) { 63 s.plug, s.plugInfo = MockConnectedPlug(c, openglConsumerYaml, nil, "opengl") 64 s.slot, s.slotInfo = MockConnectedSlot(c, openglCoreYaml, nil, "opengl") 65 } 66 67 func (s *OpenglInterfaceSuite) TestName(c *C) { 68 c.Assert(s.iface.Name(), Equals, "opengl") 69 } 70 71 func (s *OpenglInterfaceSuite) TestSanitizeSlot(c *C) { 72 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 73 } 74 75 func (s *OpenglInterfaceSuite) TestSanitizePlug(c *C) { 76 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 77 } 78 79 func (s *OpenglInterfaceSuite) 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, `/dev/nvidia* rw,`) 84 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/dri/renderD[0-9]* rw,`) 85 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/mali[0-9]* rw,`) 86 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/galcore rw,`) 87 } 88 89 func (s *OpenglInterfaceSuite) TestUDevSpec(c *C) { 90 spec := &udev.Specification{} 91 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 92 c.Assert(spec.Snippets(), HasLen, 13) 93 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 94 SUBSYSTEM=="drm", KERNEL=="card[0-9]*", TAG+="snap_consumer_app"`) 95 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 96 KERNEL=="renderD[0-9]*", TAG+="snap_consumer_app"`) 97 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 98 KERNEL=="nvhost-*", TAG+="snap_consumer_app"`) 99 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 100 KERNEL=="nvmap", TAG+="snap_consumer_app"`) 101 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 102 KERNEL=="tegra_dc_ctrl", TAG+="snap_consumer_app"`) 103 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 104 KERNEL=="tegra_dc_[0-9]*", TAG+="snap_consumer_app"`) 105 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 106 KERNEL=="pvr_sync", TAG+="snap_consumer_app"`) 107 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 108 KERNEL=="mali[0-9]*", TAG+="snap_consumer_app"`) 109 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 110 KERNEL=="dma_buf_te", TAG+="snap_consumer_app"`) 111 c.Assert(spec.Snippets(), testutil.Contains, `# opengl 112 KERNEL=="galcore", TAG+="snap_consumer_app"`) 113 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)) 114 } 115 116 func (s *OpenglInterfaceSuite) TestStaticInfo(c *C) { 117 si := interfaces.StaticInfoOf(s.iface) 118 c.Assert(si.ImplicitOnCore, Equals, true) 119 c.Assert(si.ImplicitOnClassic, Equals, true) 120 c.Assert(si.Summary, Equals, `allows access to OpenGL stack`) 121 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "opengl") 122 } 123 124 func (s *OpenglInterfaceSuite) TestAutoConnect(c *C) { 125 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 126 } 127 128 func (s *OpenglInterfaceSuite) TestInterfaces(c *C) { 129 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 130 }