Merge lp:~fgimenez/snappy/hw-assign-test into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Federico Gimenez
Status: Merged
Approved by: Leo Arias
Approved revision: 739
Merged at revision: 745
Proposed branch: lp:~fgimenez/snappy/hw-assign-test
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 145 lines (+120/-0)
4 files modified
_integration-tests/data/snaps/dev-kmsg/bin/reader (+3/-0)
_integration-tests/data/snaps/dev-kmsg/meta/package.yaml (+6/-0)
_integration-tests/data/snaps/dev-kmsg/meta/readme.md (+5/-0)
_integration-tests/tests/hwAssign_test.go (+106/-0)
To merge this branch: bzr merge lp:~fgimenez/snappy/hw-assign-test
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+273413@code.launchpad.net

Commit message

hw-assign integration test

Description of the change

hw-assign integration test

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

cool. Left a couple of comments about typos.

review: Needs Fixing
lp:~fgimenez/snappy/hw-assign-test updated
738. By Federico Gimenez

Fixed typo and wrong sentence

Revision history for this message
Federico Gimenez (fgimenez) wrote :

Thanks Leo, it should be fixed now

Revision history for this message
Leo Arias (elopio) wrote :

START: /home/elopio/workspace/go/src/launchpad.net/snappy/_integration-tests/tests/hwAssign_test.go:48: hwAssignSuite.SetUpTest
fatal error: runtime: out of memory

That's because you are calling SetUpTest in SetUpTest.

The right call is:
s.SnappySuite.SetUpTest(c)

The same problem with tear down.

review: Needs Fixing
lp:~fgimenez/snappy/hw-assign-test updated
739. By Federico Gimenez

Calling fixtures on SnappySuite

Revision history for this message
Federico Gimenez (fgimenez) wrote :

Sorry, it's fixed now.

Thanks!

Revision history for this message
Leo Arias (elopio) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory '_integration-tests/data/snaps/dev-kmsg'
=== added directory '_integration-tests/data/snaps/dev-kmsg/bin'
=== added file '_integration-tests/data/snaps/dev-kmsg/bin/reader'
--- _integration-tests/data/snaps/dev-kmsg/bin/reader 1970-01-01 00:00:00 +0000
+++ _integration-tests/data/snaps/dev-kmsg/bin/reader 2015-10-07 07:39:35 +0000
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3dd if=/dev/kmsg iflag=nonblock
0\ No newline at end of file4\ No newline at end of file
15
=== added directory '_integration-tests/data/snaps/dev-kmsg/meta'
=== added file '_integration-tests/data/snaps/dev-kmsg/meta/package.yaml'
--- _integration-tests/data/snaps/dev-kmsg/meta/package.yaml 1970-01-01 00:00:00 +0000
+++ _integration-tests/data/snaps/dev-kmsg/meta/package.yaml 2015-10-07 07:39:35 +0000
@@ -0,0 +1,6 @@
1name: dev-kmsg
2version: 1.0
3vendor: Snappy Developers <snappy-devel@lists.ubuntu.com>
4icon: meta/snappy64.png
5binaries:
6 - name: bin/reader
07
=== added file '_integration-tests/data/snaps/dev-kmsg/meta/readme.md'
--- _integration-tests/data/snaps/dev-kmsg/meta/readme.md 1970-01-01 00:00:00 +0000
+++ _integration-tests/data/snaps/dev-kmsg/meta/readme.md 2015-10-07 07:39:35 +0000
@@ -0,0 +1,5 @@
1dev-kmsg snap
2
3This simple snap provides a binary to read and output real raw
4data from /dev/kmsg using dd. For it to work it needs that hw
5to be assigned before being run.
06
=== added file '_integration-tests/data/snaps/dev-kmsg/meta/snappy64.png'
1Binary files _integration-tests/data/snaps/dev-kmsg/meta/snappy64.png 1970-01-01 00:00:00 +0000 and _integration-tests/data/snaps/dev-kmsg/meta/snappy64.png 2015-10-07 07:39:35 +0000 differ7Binary files _integration-tests/data/snaps/dev-kmsg/meta/snappy64.png 1970-01-01 00:00:00 +0000 and _integration-tests/data/snaps/dev-kmsg/meta/snappy64.png 2015-10-07 07:39:35 +0000 differ
=== added file '_integration-tests/tests/hwAssign_test.go'
--- _integration-tests/tests/hwAssign_test.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/tests/hwAssign_test.go 2015-10-07 07:39:35 +0000
@@ -0,0 +1,106 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2015 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
20package tests
21
22import (
23 "fmt"
24 "os"
25 "os/exec"
26
27 "launchpad.net/snappy/_integration-tests/testutils/build"
28 "launchpad.net/snappy/_integration-tests/testutils/common"
29
30 "gopkg.in/check.v1"
31)
32
33const (
34 snapName = "dev-kmsg"
35 binName = snapName + ".reader"
36 installedSnapName = snapName + ".sideload"
37 hwName = "/dev/kmsg"
38 hwAssignError = "dd: failed to open ‘" + hwName + "’: Permission denied\n"
39)
40
41var _ = check.Suite(&hwAssignSuite{})
42
43type hwAssignSuite struct {
44 common.SnappySuite
45 snapPath string
46}
47
48func (s *hwAssignSuite) SetUpTest(c *check.C) {
49 s.SnappySuite.SetUpTest(c)
50 var err error
51 s.snapPath, err = build.LocalSnap(c, snapName)
52 c.Assert(err, check.IsNil)
53 common.InstallSnap(c, s.snapPath)
54}
55
56func (s *hwAssignSuite) TearDownTest(c *check.C) {
57 s.SnappySuite.TearDownTest(c)
58 os.Remove(s.snapPath)
59 common.RemoveSnap(c, snapName)
60}
61
62func (s *hwAssignSuite) TestErrorWithoutHwAssign(c *check.C) {
63 cmd := exec.Command(binName)
64 output, err := cmd.CombinedOutput()
65
66 c.Assert(err, check.NotNil)
67 c.Assert(string(output), check.Equals, hwAssignError)
68}
69
70func (s *hwAssignSuite) TestSuccessAfterHwAssign(c *check.C) {
71 assign(c, snapName, hwName)
72 defer unassign(c, snapName, hwName)
73
74 cmd := exec.Command(binName)
75 output, _ := cmd.CombinedOutput()
76
77 c.Assert(string(output), check.Not(check.Equals), hwAssignError)
78}
79
80func (s *hwAssignSuite) TestErrorAfterHwUnAssign(c *check.C) {
81 assign(c, snapName, hwName)
82 unassign(c, snapName, hwName)
83
84 cmd := exec.Command(binName)
85 output, err := cmd.CombinedOutput()
86
87 c.Assert(err, check.NotNil)
88 c.Assert(string(output), check.Equals, hwAssignError)
89}
90
91func assign(c *check.C, snap, hw string) {
92 cmd := exec.Command("sudo", "snappy", "hw-assign", installedSnapName, hwName)
93 output, err := cmd.CombinedOutput()
94 c.Assert(err, check.IsNil)
95 c.Assert(string(output), check.Equals,
96 fmt.Sprintf("'%s' is now allowed to access '%s'\n", installedSnapName, hwName))
97}
98
99func unassign(c *check.C, snap, hw string) {
100 cmd := exec.Command("sudo", "snappy", "hw-unassign", installedSnapName, hwName)
101 output, err := cmd.CombinedOutput()
102 c.Assert(err, check.IsNil)
103 c.Assert(string(output), check.Equals,
104 fmt.Sprintf("'%s' is no longer allowed to access '%s'\n", installedSnapName, hwName))
105
106}

Subscribers

People subscribed via source and target branches