Merge lp:~salgado/linaro-image-tools/fix-913819 into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado on 2012-01-24
Status: Merged
Approved by: Mattias Backman on 2012-01-25
Approved revision: 486
Merged at revision: 487
Proposed branch: lp:~salgado/linaro-image-tools/fix-913819
Merge into: lp:linaro-image-tools/11.11
Diff against target: 164 lines (+52/-75)
2 files modified
linaro_image_tools/media_create/boards.py (+4/-1)
linaro_image_tools/media_create/tests/test_media_create.py (+48/-74)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/fix-913819
Reviewer Review Type Date Requested Status
Mattias Backman (community) 2012-01-24 Approve on 2012-01-25
Review via email: mp+89975@code.launchpad.net

Description of the change

Make sure the new --extra-boot-args argument works when the extra_boot_args_options attribute of the board config is set to None

While fixing that I noticed the tests were indirectly testing the things they were interested in (add_boot_args and add_boot_args_from_file) via config._get_boot_env(), so I changed them to test only what we really care about there.

IOW, we now have one test to ensure that extra_boot_args_options is picked up by config._get_boot_env() and all others just ensure that add_boot_args() update extra_boot_args_options appropriately.

To post a comment you must log in.
Mattias Backman (mabac) wrote :

Thanks for fixing this. And good catch on the tests too! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro_image_tools/media_create/boards.py'
2--- linaro_image_tools/media_create/boards.py 2012-01-18 15:27:35 +0000
3+++ linaro_image_tools/media_create/boards.py 2012-01-24 18:52:23 +0000
4@@ -577,7 +577,10 @@
5 @classmethod
6 def add_boot_args(cls, extra_args):
7 if extra_args is not None:
8- cls.extra_boot_args_options += ' %s' % extra_args
9+ if cls.extra_boot_args_options is None:
10+ cls.extra_boot_args_options = extra_args
11+ else:
12+ cls.extra_boot_args_options += ' %s' % extra_args
13
14 @classmethod
15 def add_boot_args_from_file(cls, path):
16
17=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
18--- linaro_image_tools/media_create/tests/test_media_create.py 2012-01-17 14:50:47 +0000
19+++ linaro_image_tools/media_create/tests/test_media_create.py 2012-01-24 18:52:23 +0000
20@@ -1414,96 +1414,70 @@
21
22 class TestExtraBootCmd(TestCaseWithFixtures):
23
24- def test_no_extra_args(self):
25- boot_args = ''.join(
26- random.choice(string.ascii_lowercase) for x in range(15))
27- class config(BoardConfig):
28- extra_boot_args_options = boot_args
29- boot_commands = config._get_boot_env(
30- is_live=False, is_lowmem=False, consoles=['ttyXXX'],
31- rootfs_uuid="deadbeef", d_img_data=None)
32- expected = ' '.join([' console=ttyXXX root=UUID=deadbeef rootwait ro',
33- boot_args])
34- self.assertEqual(expected, boot_commands['bootargs'])
35-
36- def test_none_extra_args(self):
37- boot_args = ''.join(
38- random.choice(string.ascii_lowercase) for x in range(15))
39- extra_args = None
40- class config(BoardConfig):
41- extra_boot_args_options = boot_args
42- config.add_boot_args(extra_args)
43- boot_commands = config._get_boot_env(
44- is_live=False, is_lowmem=False, consoles=['ttyXXX'],
45- rootfs_uuid="deadbeef", d_img_data=None)
46- expected = ' '.join([' console=ttyXXX root=UUID=deadbeef rootwait ro',
47- boot_args])
48- self.assertEqual(expected, boot_commands['bootargs'])
49-
50- def test_string_extra_args(self):
51- boot_args = ''.join(
52- random.choice(string.ascii_lowercase) for x in range(15))
53- extra_args = ''.join(
54- random.choice(string.ascii_lowercase) for x in range(15))
55- class config(BoardConfig):
56- extra_boot_args_options = boot_args
57- config.add_boot_args(extra_args)
58- boot_commands = config._get_boot_env(
59- is_live=False, is_lowmem=False, consoles=['ttyXXX'],
60- rootfs_uuid="deadbeef", d_img_data=None)
61- expected = ' '.join([' console=ttyXXX root=UUID=deadbeef rootwait ro',
62- boot_args, extra_args])
63- self.assertEqual(expected, boot_commands['bootargs'])
64-
65- def test_file_extra_args(self):
66- boot_args = ''.join(
67- random.choice(string.ascii_lowercase) for x in range(15))
68- extra_args = ''.join(
69- random.choice(string.ascii_lowercase) for x in range(15))
70+ def test_extra_boot_args_options_is_picked_by_get_boot_env(self):
71+ boot_args = 'whatever'
72+ class config(BoardConfig):
73+ extra_boot_args_options = boot_args
74+ boot_commands = config._get_boot_env(
75+ is_live=False, is_lowmem=False, consoles=['ttyXXX'],
76+ rootfs_uuid="deadbeef", d_img_data=None)
77+ expected = (
78+ ' console=ttyXXX root=UUID=deadbeef rootwait ro %s' % boot_args)
79+ self.assertEqual(expected, boot_commands['bootargs'])
80+
81+ def test_passing_None_to_add_boot_args(self):
82+ boot_args = 'extra-args'
83+ class config(BoardConfig):
84+ extra_boot_args_options = boot_args
85+ config.add_boot_args(None)
86+ self.assertEqual(boot_args, config.extra_boot_args_options)
87+
88+ def test_passing_string_to_add_boot_args(self):
89+ boot_args = 'extra-args'
90+ extra_args = 'user-args'
91+ class config(BoardConfig):
92+ extra_boot_args_options = boot_args
93+ config.add_boot_args(extra_args)
94+ self.assertEqual(
95+ "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
96+
97+ def test_passing_string_to_add_boot_args_with_no_default_extra_args(self):
98+ extra_args = 'user-args'
99+ class config(BoardConfig):
100+ extra_boot_args_options = None
101+ config.add_boot_args(extra_args)
102+ self.assertEqual(extra_args, config.extra_boot_args_options)
103+
104+ def test_add_boot_args_from_file(self):
105+ boot_args = 'extra-args'
106+ extra_args = 'user-args'
107 boot_arg_path = self.createTempFileAsFixture()
108 with open(boot_arg_path, 'w') as boot_arg_file:
109 boot_arg_file.write(extra_args)
110 class config(BoardConfig):
111 extra_boot_args_options = boot_args
112 config.add_boot_args_from_file(boot_arg_path)
113- boot_commands = config._get_boot_env(
114- is_live=False, is_lowmem=False, consoles=['ttyXXX'],
115- rootfs_uuid="deadbeef", d_img_data=None)
116- expected = ' '.join([' console=ttyXXX root=UUID=deadbeef rootwait ro',
117- boot_args, extra_args])
118- self.assertEqual(expected, boot_commands['bootargs'])
119+ self.assertEqual(
120+ "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
121
122- def test_none_file_extra_args(self):
123- boot_args = ''.join(
124- random.choice(string.ascii_lowercase) for x in range(15))
125- boot_arg_path = None
126+ def test_passing_None_to_add_boot_args_from_file(self):
127+ boot_args = 'extra-args'
128 class config(BoardConfig):
129 extra_boot_args_options = boot_args
130- config.add_boot_args_from_file(boot_arg_path)
131- boot_commands = config._get_boot_env(
132- is_live=False, is_lowmem=False, consoles=['ttyXXX'],
133- rootfs_uuid="deadbeef", d_img_data=None)
134- expected = ' '.join([' console=ttyXXX root=UUID=deadbeef rootwait ro',
135- boot_args])
136- self.assertEqual(expected, boot_commands['bootargs'])
137+ config.add_boot_args_from_file(None)
138+ self.assertEqual(boot_args, config.extra_boot_args_options)
139
140- def test_whitespace_file_extra_args(self):
141- boot_args = ''.join(
142- random.choice(string.ascii_lowercase) for x in range(15))
143- extra_args = ''.join(
144- random.choice(string.ascii_lowercase) for x in range(15))
145+ def test_add_boot_args_from_file_strips_whitespace_from_file(self):
146+ boot_args = 'extra-args'
147+ extra_args = 'user-args'
148 boot_arg_path = self.createTempFileAsFixture()
149 with open(boot_arg_path, 'w') as boot_arg_file:
150 boot_arg_file.write('\n\n \t ' + extra_args + ' \n\n')
151 class config(BoardConfig):
152 extra_boot_args_options = boot_args
153 config.add_boot_args_from_file(boot_arg_path)
154- boot_commands = config._get_boot_env(
155- is_live=False, is_lowmem=False, consoles=['ttyXXX'],
156- rootfs_uuid="deadbeef", d_img_data=None)
157- expected = ' '.join([' console=ttyXXX root=UUID=deadbeef rootwait ro',
158- boot_args, extra_args])
159- self.assertEqual(expected, boot_commands['bootargs'])
160+ self.assertEqual(
161+ "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
162
163
164 class TestGetBootCmdAndroid(TestCase):

Subscribers

People subscribed via source and target branches