Merge lp:~terceiro/lava-dispatcher/fix-unit-tests into lp:lava-dispatcher

Proposed by Antonio Terceiro
Status: Merged
Merged at revision: 644
Proposed branch: lp:~terceiro/lava-dispatcher/fix-unit-tests
Merge into: lp:lava-dispatcher
Diff against target: 185 lines (+33/-58)
6 files modified
lava_dispatcher/tests/helper.py (+12/-7)
lava_dispatcher/tests/test-config/bin/fake-qemu (+3/-0)
lava_dispatcher/tests/test-config/devices/beaglexm01.conf (+0/-1)
lava_dispatcher/tests/test-config/lava-dispatcher.conf (+0/-1)
lava_dispatcher/tests/test_config.py (+5/-27)
lava_dispatcher/tests/test_device_version.py (+13/-22)
To merge this branch: bzr merge lp:~terceiro/lava-dispatcher/fix-unit-tests
Reviewer Review Type Date Requested Status
Milo Casagrande (community) Approve
Review via email: mp+178186@code.launchpad.net

Description of the change

this branch removes 2 unit tests that are definitively broken beyond repair and leaves the remaining 4 (!!) passing (even though still kind of horrible). Let's assume this the initial spark of the revolution :-)

To post a comment you must log in.
Revision history for this message
Milo Casagrande (milo) wrote :

Antonio, I just tried to run the tests, but I get this error:

Exception: no config files named 'devices/qemu01.conf' found

This is the test that fails:

ERROR: lava_dispatcher.tests.test_device_version.TestDeviceVersion.test_qemu

review: Needs Fixing
645. By Antonio Terceiro

reworking unit test crap

Revision history for this message
Antonio Terceiro (terceiro) wrote :

Just pushed a fix for this. Another bad test went out of the window.

Revision history for this message
Milo Casagrande (milo) wrote :

I had another error:

OSError: [Errno 2] No such file or directory

But I was missing the qemu-system-arm package. Full traceback if you want is here: https://pastebin.linaro.org/view/7072231c

I looked through the README or other files, but couldn't find anything about the lava-dispatcher dependencies other than the one listed in the setup.py file. Might be good to add something in the README (not sure if you want to do it with this MP, in case add when merging). Not sure if this will be a problem if we want to set up a CI job for it.

Overall it looks good to be merged.

review: Approve
Revision history for this message
Antonio Terceiro (terceiro) wrote :

On Thu, Aug 08, 2013 at 06:45:58AM -0000, Milo Casagrande wrote:
> Review: Approve
>
> I had another error:
>
> OSError: [Errno 2] No such file or directory
>
> But I was missing the qemu-system-arm package. Full traceback if you want is here: https://pastebin.linaro.org/view/7072231c
>
> I looked through the README or other files, but couldn't find anything
> about the lava-dispatcher dependencies other than the one listed in
> the setup.py file. Might be good to add something in the README (not
> sure if you want to do it with this MP, in case add when merging). Not
> sure if this will be a problem if we want to set up a CI job for it.

it is a problem, because the test will fail whenever qemu (which is an
optional dependency only required if you actually want to use qemu
devices) is not installed. I will stub that out for the test.

Thanks for your feedback again :-)

646. By Antonio Terceiro

Fake QEMU binary to not require actual QEMU for unit tests

647. By Antonio Terceiro

cleanup: removing unused files - tests are mostly self-contained now

Revision history for this message
Antonio Terceiro (terceiro) wrote :

So I have just pushed an update, and tested against a clean chroot.

Amazing how much work was needed to make 3 unit tests pass. :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_dispatcher/tests/helper.py'
2--- lava_dispatcher/tests/helper.py 2013-07-16 16:09:42 +0000
3+++ lava_dispatcher/tests/helper.py 2013-08-08 09:19:50 +0000
4@@ -19,13 +19,14 @@
5
6 import os
7 from lava_dispatcher.config import get_device_config
8+import lava_dispatcher.config
9
10-__tmp_dir = os.getenv("TMPDIR") or '/tmp'
11-__tmp_config_dir = os.path.join(__tmp_dir, 'lava-dispatcher-config')
12+tmp_dir = os.getenv("TMPDIR") or '/tmp'
13+tmp_config_dir = os.path.join(tmp_dir, 'lava-dispatcher-config')
14
15
16 def create_config(name, data):
17- filename = os.path.join(__tmp_config_dir, name)
18+ filename = os.path.join(tmp_config_dir, name)
19 if not os.path.exists(os.path.dirname(filename)):
20 os.mkdir(os.path.dirname(filename))
21 with open(filename, 'w') as f:
22@@ -35,23 +36,27 @@
23
24 def create_device_config(name, data):
25 create_config("devices/%s.conf" % name, data)
26- return get_device_config(name, __tmp_config_dir)
27+ lava_dispatcher.utils.custom_config_path = tmp_config_dir
28+ config = get_device_config(name)
29+ lava_dispatcher.utils.custom_config_path = None
30+ return config
31
32
33 def setup_config_dir():
34- os.mkdir(__tmp_config_dir)
35+ os.mkdir(tmp_config_dir)
36
37
38 def cleanup_config_dir():
39- os.system('rm -rf %s' % __tmp_config_dir)
40+ os.system('rm -rf %s' % tmp_config_dir)
41
42 from unittest import TestCase
43
44-
45 class LavaDispatcherTestCase(TestCase):
46
47 def setUp(self):
48 setup_config_dir()
49+ lava_dispatcher.config.custom_config_path = tmp_config_dir
50
51 def tearDown(self):
52+ lava_dispatcher.config.custom_config_path = None
53 cleanup_config_dir()
54
55=== added directory 'lava_dispatcher/tests/test-config/bin'
56=== added file 'lava_dispatcher/tests/test-config/bin/fake-qemu'
57--- lava_dispatcher/tests/test-config/bin/fake-qemu 1970-01-01 00:00:00 +0000
58+++ lava_dispatcher/tests/test-config/bin/fake-qemu 2013-08-08 09:19:50 +0000
59@@ -0,0 +1,3 @@
60+#!/bin/sh
61+
62+echo 'QEMU emulator version 1.5.0 (Debian 1.5.0+dfsg-4), Copyright (c) 2003-2008 Fabrice Bellard'
63
64=== removed directory 'lava_dispatcher/tests/test-config/devices'
65=== removed file 'lava_dispatcher/tests/test-config/devices/beaglexm01.conf'
66--- lava_dispatcher/tests/test-config/devices/beaglexm01.conf 2011-11-28 20:27:03 +0000
67+++ lava_dispatcher/tests/test-config/devices/beaglexm01.conf 1970-01-01 00:00:00 +0000
68@@ -1,1 +0,0 @@
69-device_type = beagle-xm
70\ No newline at end of file
71
72=== removed file 'lava_dispatcher/tests/test-config/lava-dispatcher.conf'
73--- lava_dispatcher/tests/test-config/lava-dispatcher.conf 2011-11-28 20:27:03 +0000
74+++ lava_dispatcher/tests/test-config/lava-dispatcher.conf 1970-01-01 00:00:00 +0000
75@@ -1,1 +0,0 @@
76-LAVA_SERVER_IP = 192.168.200.200
77\ No newline at end of file
78
79=== modified file 'lava_dispatcher/tests/test_config.py'
80--- lava_dispatcher/tests/test_config.py 2013-07-16 16:09:24 +0000
81+++ lava_dispatcher/tests/test_config.py 2013-08-08 09:19:50 +0000
82@@ -19,39 +19,17 @@
83
84 from unittest import TestCase
85
86+import lava_dispatcher.config
87 from lava_dispatcher.config import get_config, get_device_config
88 from lava_dispatcher.utils import string_to_list
89
90 from lava_dispatcher.tests.helper import *
91
92-test_config_dir = os.path.join(os.path.dirname(__file__), 'test-config')
93-
94-
95-class TestConfigData(TestCase):
96-
97- def setUp(self):
98- setup_config_dir()
99-
100- def tearDown(self):
101- cleanup_config_dir()
102-
103- def test_beagle01_uboot_cmds(self):
104- beagle01_config = get_device_config("beaglexm01", test_config_dir)
105- expected = [
106- "mmc init",
107- "mmc part 0",
108- "setenv bootcmd 'fatload mmc 0:3 0x80000000 uImage; fatload mmc "
109- "0:3 0x81600000 uInitrd; bootm 0x80000000 0x81600000'",
110- "setenv bootargs ' console=tty0 console=ttyO2,115200n8 "
111- "root=LABEL=testrootfs rootwait ro earlyprintk fixrtc "
112- "nocompcache vram=12M omapfb.debug=y "
113- "omapfb.mode=dvi:1280x720MR-16@60'",
114- "boot"]
115- uboot_cmds = beagle01_config.boot_cmds
116- self.assertEquals(expected, string_to_list(uboot_cmds))
117+class TestConfigData(LavaDispatcherTestCase):
118
119 def test_server_ip(self):
120- server_config = get_config(test_config_dir)
121- expected = "192.168.200.200"
122+ create_config('lava-dispatcher.conf', { 'LAVA_SERVER_IP': '99.99.99.99' })
123+ server_config = get_config()
124+ expected = "99.99.99.99"
125 lava_server_ip = server_config.lava_server_ip
126 self.assertEqual(expected, lava_server_ip)
127
128=== modified file 'lava_dispatcher/tests/test_device_version.py'
129--- lava_dispatcher/tests/test_device_version.py 2013-07-16 16:09:15 +0000
130+++ lava_dispatcher/tests/test_device_version.py 2013-08-08 09:19:50 +0000
131@@ -18,7 +18,9 @@
132 # along with this program; if not, see <http://www.gnu.org/licenses>.
133
134 import re
135-from lava_dispatcher.tests.helper import LavaDispatcherTestCase, create_device_config, create_config, __tmp_config_dir
136+import lava_dispatcher.config
137+from lava_dispatcher.tests.helper import LavaDispatcherTestCase, create_device_config, create_config
138+import os
139
140 from lava_dispatcher.device.target import Target
141 from lava_dispatcher.device.qemu import QEMUTarget
142@@ -34,10 +36,14 @@
143 return target
144
145
146-def _create_qemu_target():
147- create_config('lava-dispatcher.conf', {'default_qemu_binary': 'qemu-system-arm'})
148- device_config = create_device_config('qemu01', {'device_type': 'qemu'})
149- dispatcher_config = get_config(__tmp_config_dir)
150+def _create_qemu_target(extra_device_config={}):
151+ create_config('lava-dispatcher.conf', {})
152+
153+ device_config_data = {'device_type': 'qemu'}
154+ device_config_data.update(extra_device_config)
155+ device_config = create_device_config('qemu01', device_config_data)
156+
157+ dispatcher_config = get_config()
158
159 context = LavaContext('qemu01', dispatcher_config, None, None, None)
160 return QEMUTarget(context, device_config)
161@@ -50,22 +56,7 @@
162 self.assertIsInstance(target.get_device_version(), str)
163
164 def test_qemu(self):
165- target = _create_qemu_target()
166+ fake_qemu = os.path.join(os.path.dirname(__file__), 'test-config', 'bin', 'fake-qemu')
167+ target = _create_qemu_target({ 'qemu_binary': fake_qemu })
168 device_version = target.get_device_version()
169 assert(re.search('^[0-9.]+', device_version))
170-
171- def test_fastmodel(self):
172- banner = "\n".join([
173- "Fast Models [7.1.36 (May 17 2012)]",
174- "Copyright 2000-2012 ARM Limited.",
175- "All Rights Reserved.",
176- "Top component name: RTSM_VE_Cortex_A15x1_A7x1"
177- ])
178- target = _create_fastmodel_target()
179- version = target._parse_fastmodel_version(banner)
180- self.assertEqual('7.1.36', version)
181-
182- def test_fastmodel_wrong_format(self):
183- client = _create_fastmodel_target()
184- version = client._parse_fastmodel_version('random string')
185- self.assertEqual('unknown', version)

Subscribers

People subscribed via source and target branches