github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/vcio_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  	"fmt"
    24  
    25  	. "gopkg.in/check.v1"
    26  
    27  	"github.com/snapcore/snapd/dirs"
    28  	"github.com/snapcore/snapd/interfaces"
    29  	"github.com/snapcore/snapd/interfaces/apparmor"
    30  	"github.com/snapcore/snapd/interfaces/builtin"
    31  	"github.com/snapcore/snapd/interfaces/udev"
    32  	"github.com/snapcore/snapd/snap"
    33  	"github.com/snapcore/snapd/testutil"
    34  )
    35  
    36  type VcioInterfaceSuite struct {
    37  	iface        interfaces.Interface
    38  	coreSlotInfo *snap.SlotInfo
    39  	coreSlot     *interfaces.ConnectedSlot
    40  	plugInfo     *snap.PlugInfo
    41  	plug         *interfaces.ConnectedPlug
    42  }
    43  
    44  var _ = Suite(&VcioInterfaceSuite{
    45  	iface: builtin.MustInterface("vcio"),
    46  })
    47  
    48  const vcioConsumerYaml = `name: consumer
    49  version: 0
    50  apps:
    51   app:
    52    plugs: [vcio]
    53  `
    54  
    55  const vcioCoreYaml = `name: core
    56  version: 0
    57  type: os
    58  slots:
    59    vcio:
    60  `
    61  
    62  func (s *VcioInterfaceSuite) SetUpTest(c *C) {
    63  	s.plug, s.plugInfo = MockConnectedPlug(c, vcioConsumerYaml, nil, "vcio")
    64  	s.coreSlot, s.coreSlotInfo = MockConnectedSlot(c, vcioCoreYaml, nil, "vcio")
    65  }
    66  
    67  func (s *VcioInterfaceSuite) TestName(c *C) {
    68  	c.Assert(s.iface.Name(), Equals, "vcio")
    69  }
    70  
    71  func (s *VcioInterfaceSuite) TestSanitizeSlot(c *C) {
    72  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.coreSlotInfo), IsNil)
    73  }
    74  
    75  func (s *VcioInterfaceSuite) TestSanitizePlug(c *C) {
    76  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    77  }
    78  
    79  func (s *VcioInterfaceSuite) TestAppArmorSpec(c *C) {
    80  	spec := &apparmor.Specification{}
    81  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.coreSlot), IsNil)
    82  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    83  	c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/vcio rw,`)
    84  }
    85  
    86  func (s *VcioInterfaceSuite) TestUDevSpec(c *C) {
    87  	spec := &udev.Specification{}
    88  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.coreSlot), IsNil)
    89  	c.Assert(spec.Snippets(), HasLen, 2)
    90  	c.Assert(spec.Snippets(), testutil.Contains, `# vcio
    91  SUBSYSTEM=="bcm2708_vcio", KERNEL=="vcio", TAG+="snap_consumer_app"`)
    92  	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))
    93  }
    94  
    95  func (s *VcioInterfaceSuite) TestStaticInfo(c *C) {
    96  	si := interfaces.StaticInfoOf(s.iface)
    97  	c.Assert(si.ImplicitOnCore, Equals, true)
    98  	c.Assert(si.ImplicitOnClassic, Equals, true)
    99  	c.Assert(si.Summary, Equals, `allows access to VideoCore I/O`)
   100  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true")
   101  }
   102  
   103  func (s *VcioInterfaceSuite) TestInterfaces(c *C) {
   104  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   105  }