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