github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/interfaces/builtin/framebuffer_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/udev"
    29  	"github.com/snapcore/snapd/snap"
    30  	"github.com/snapcore/snapd/testutil"
    31  )
    32  
    33  type FramebufferInterfaceSuite struct {
    34  	iface    interfaces.Interface
    35  	slotInfo *snap.SlotInfo
    36  	slot     *interfaces.ConnectedSlot
    37  	plugInfo *snap.PlugInfo
    38  	plug     *interfaces.ConnectedPlug
    39  }
    40  
    41  const framebufferConsumerYaml = `
    42  name: consumer
    43  version: 0
    44  apps:
    45    app:
    46      plugs: [framebuffer]
    47  `
    48  
    49  const framebufferOsYaml = `
    50  name: core
    51  version: 0
    52  type: os
    53  slots:
    54    framebuffer:
    55  `
    56  
    57  var _ = Suite(&FramebufferInterfaceSuite{
    58  	iface: builtin.MustInterface("framebuffer"),
    59  })
    60  
    61  func (s *FramebufferInterfaceSuite) SetUpTest(c *C) {
    62  	s.plug, s.plugInfo = MockConnectedPlug(c, framebufferConsumerYaml, nil, "framebuffer")
    63  	s.slot, s.slotInfo = MockConnectedSlot(c, framebufferOsYaml, nil, "framebuffer")
    64  }
    65  
    66  func (s *FramebufferInterfaceSuite) TestName(c *C) {
    67  	c.Assert(s.iface.Name(), Equals, "framebuffer")
    68  }
    69  
    70  func (s *FramebufferInterfaceSuite) TestSanitizeSlot(c *C) {
    71  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    72  }
    73  
    74  func (s *FramebufferInterfaceSuite) TestSanitizePlug(c *C) {
    75  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    76  }
    77  
    78  func (s *FramebufferInterfaceSuite) TestAppArmorSpec(c *C) {
    79  	spec := &apparmor.Specification{}
    80  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    81  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    82  	c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/fb[0-9]* rw,`)
    83  }
    84  
    85  func (s *FramebufferInterfaceSuite) TestUDevSpec(c *C) {
    86  	spec := &udev.Specification{}
    87  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    88  	c.Assert(spec.Snippets(), HasLen, 2)
    89  	c.Assert(spec.Snippets()[0], Equals, `# framebuffer
    90  KERNEL=="fb[0-9]*", TAG+="snap_consumer_app"`)
    91  	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"`)
    92  }
    93  
    94  func (s *FramebufferInterfaceSuite) TestStaticInfo(c *C) {
    95  	si := interfaces.StaticInfoOf(s.iface)
    96  	c.Assert(si.ImplicitOnCore, Equals, true)
    97  	c.Assert(si.ImplicitOnClassic, Equals, true)
    98  	c.Assert(si.Summary, Equals, `allows access to universal framebuffer devices`)
    99  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "framebuffer")
   100  }
   101  
   102  func (s *FramebufferInterfaceSuite) TestAutoConnect(c *C) {
   103  	c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true)
   104  }
   105  
   106  func (s *FramebufferInterfaceSuite) TestInterfaces(c *C) {
   107  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   108  }