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
1=== added directory '_integration-tests/data/snaps/dev-kmsg'
2=== added directory '_integration-tests/data/snaps/dev-kmsg/bin'
3=== added file '_integration-tests/data/snaps/dev-kmsg/bin/reader'
4--- _integration-tests/data/snaps/dev-kmsg/bin/reader 1970-01-01 00:00:00 +0000
5+++ _integration-tests/data/snaps/dev-kmsg/bin/reader 2015-10-07 07:39:35 +0000
6@@ -0,0 +1,3 @@
7+#!/bin/sh
8+
9+dd if=/dev/kmsg iflag=nonblock
10\ No newline at end of file
11
12=== added directory '_integration-tests/data/snaps/dev-kmsg/meta'
13=== added file '_integration-tests/data/snaps/dev-kmsg/meta/package.yaml'
14--- _integration-tests/data/snaps/dev-kmsg/meta/package.yaml 1970-01-01 00:00:00 +0000
15+++ _integration-tests/data/snaps/dev-kmsg/meta/package.yaml 2015-10-07 07:39:35 +0000
16@@ -0,0 +1,6 @@
17+name: dev-kmsg
18+version: 1.0
19+vendor: Snappy Developers <snappy-devel@lists.ubuntu.com>
20+icon: meta/snappy64.png
21+binaries:
22+ - name: bin/reader
23
24=== added file '_integration-tests/data/snaps/dev-kmsg/meta/readme.md'
25--- _integration-tests/data/snaps/dev-kmsg/meta/readme.md 1970-01-01 00:00:00 +0000
26+++ _integration-tests/data/snaps/dev-kmsg/meta/readme.md 2015-10-07 07:39:35 +0000
27@@ -0,0 +1,5 @@
28+dev-kmsg snap
29+
30+This simple snap provides a binary to read and output real raw
31+data from /dev/kmsg using dd. For it to work it needs that hw
32+to be assigned before being run.
33
34=== added file '_integration-tests/data/snaps/dev-kmsg/meta/snappy64.png'
35Binary 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
36=== added file '_integration-tests/tests/hwAssign_test.go'
37--- _integration-tests/tests/hwAssign_test.go 1970-01-01 00:00:00 +0000
38+++ _integration-tests/tests/hwAssign_test.go 2015-10-07 07:39:35 +0000
39@@ -0,0 +1,106 @@
40+// -*- Mode: Go; indent-tabs-mode: t -*-
41+
42+/*
43+ * Copyright (C) 2015 Canonical Ltd
44+ *
45+ * This program is free software: you can redistribute it and/or modify
46+ * it under the terms of the GNU General Public License version 3 as
47+ * published by the Free Software Foundation.
48+ *
49+ * This program is distributed in the hope that it will be useful,
50+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
51+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52+ * GNU General Public License for more details.
53+ *
54+ * You should have received a copy of the GNU General Public License
55+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
56+ *
57+ */
58+
59+package tests
60+
61+import (
62+ "fmt"
63+ "os"
64+ "os/exec"
65+
66+ "launchpad.net/snappy/_integration-tests/testutils/build"
67+ "launchpad.net/snappy/_integration-tests/testutils/common"
68+
69+ "gopkg.in/check.v1"
70+)
71+
72+const (
73+ snapName = "dev-kmsg"
74+ binName = snapName + ".reader"
75+ installedSnapName = snapName + ".sideload"
76+ hwName = "/dev/kmsg"
77+ hwAssignError = "dd: failed to open ‘" + hwName + "’: Permission denied\n"
78+)
79+
80+var _ = check.Suite(&hwAssignSuite{})
81+
82+type hwAssignSuite struct {
83+ common.SnappySuite
84+ snapPath string
85+}
86+
87+func (s *hwAssignSuite) SetUpTest(c *check.C) {
88+ s.SnappySuite.SetUpTest(c)
89+ var err error
90+ s.snapPath, err = build.LocalSnap(c, snapName)
91+ c.Assert(err, check.IsNil)
92+ common.InstallSnap(c, s.snapPath)
93+}
94+
95+func (s *hwAssignSuite) TearDownTest(c *check.C) {
96+ s.SnappySuite.TearDownTest(c)
97+ os.Remove(s.snapPath)
98+ common.RemoveSnap(c, snapName)
99+}
100+
101+func (s *hwAssignSuite) TestErrorWithoutHwAssign(c *check.C) {
102+ cmd := exec.Command(binName)
103+ output, err := cmd.CombinedOutput()
104+
105+ c.Assert(err, check.NotNil)
106+ c.Assert(string(output), check.Equals, hwAssignError)
107+}
108+
109+func (s *hwAssignSuite) TestSuccessAfterHwAssign(c *check.C) {
110+ assign(c, snapName, hwName)
111+ defer unassign(c, snapName, hwName)
112+
113+ cmd := exec.Command(binName)
114+ output, _ := cmd.CombinedOutput()
115+
116+ c.Assert(string(output), check.Not(check.Equals), hwAssignError)
117+}
118+
119+func (s *hwAssignSuite) TestErrorAfterHwUnAssign(c *check.C) {
120+ assign(c, snapName, hwName)
121+ unassign(c, snapName, hwName)
122+
123+ cmd := exec.Command(binName)
124+ output, err := cmd.CombinedOutput()
125+
126+ c.Assert(err, check.NotNil)
127+ c.Assert(string(output), check.Equals, hwAssignError)
128+}
129+
130+func assign(c *check.C, snap, hw string) {
131+ cmd := exec.Command("sudo", "snappy", "hw-assign", installedSnapName, hwName)
132+ output, err := cmd.CombinedOutput()
133+ c.Assert(err, check.IsNil)
134+ c.Assert(string(output), check.Equals,
135+ fmt.Sprintf("'%s' is now allowed to access '%s'\n", installedSnapName, hwName))
136+}
137+
138+func unassign(c *check.C, snap, hw string) {
139+ cmd := exec.Command("sudo", "snappy", "hw-unassign", installedSnapName, hwName)
140+ output, err := cmd.CombinedOutput()
141+ c.Assert(err, check.IsNil)
142+ c.Assert(string(output), check.Equals,
143+ fmt.Sprintf("'%s' is no longer allowed to access '%s'\n", installedSnapName, hwName))
144+
145+}

Subscribers

People subscribed via source and target branches