Merge lp:~salgado/linaro-image-tools/port-create_boot_cmd into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Approved by: Martin Ohlsson
Approved revision: 169
Merged at revision: 171
Proposed branch: lp:~salgado/linaro-image-tools/port-create_boot_cmd
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~salgado/linaro-image-tools/refactor-create_boot_cmd
Diff against target: 256 lines (+117/-23)
7 files modified
.testr.conf (+1/-1)
README (+21/-0)
linaro-media-create (+21/-22)
media_create/boot_cmd.py (+26/-0)
media_create/tests/__init__.py (+8/-0)
media_create/tests/test_media_create.py (+32/-0)
tests/__init__.py (+8/-0)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/port-create_boot_cmd
Reviewer Review Type Date Requested Status
Martin Ohlsson (community) Approve
Review via email: mp+41208@code.launchpad.net

Description of the change

Port the meat of create_boot_cmd to python and call that from l-m-c.

For now I'm just porting things to python and adding automated tests. Once everything is in python and we have good test coverage we can refactor to avoid duplication and generally improve things.

My plan is to have a separate .py script for every function of l-m-c and then call those scripts from l-m-c. The actual code should be split into as many python functions/classes are necessary, and the python script might need some boilerplate code to handle sys.argv and call its main function. Does that sound sane?

As for the tests, I'm probably keeping them all in a single file for now, but I'd like to know what's the best way to extend the existing test-suite so that a simple 'testr run' runs all tests. Do we need to combine hwpack's and media_create's test_suite's into a single one and use that in .testr.conf?

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

As discussed on the phone, these branches look good to me.

I don't know how to have two test suites run by subunit.run, so we may
need a top level tests.py or something to combine them.

Thanks,

James

169. By Guilherme Salgado

Add instructions for running the tests and create a new top-level test_suite, used to run the whole test suite with subunit

Revision history for this message
Martin Ohlsson (martin-ohlson) wrote :

Hi Guilherme,

The code looks good to me.

/Martin

review: Approve
Revision history for this message
Guilherme Salgado (salgado) wrote :

Thanks for the review, Martin. I'd appreciate if you could review r169 (http://bazaar.launchpad.net/~salgado/linaro-image-tools/port-create_boot_cmd/revision/169) as well, as it was added after your review. That revision adds a top-level test_suite object and instructions for running the test suite.

Revision history for this message
Martin Ohlsson (martin-ohlson) wrote :

Sorry,

I will do that right away.

I'm actually waiting for that branch to be merged so I can use your test
suite and the PYTHONPATH setting in linaro-media-create :)

/Martin

On 23 November 2010 14:31, Guilherme Salgado <email address hidden> wrote:

> Thanks for the review, Martin. I'd appreciate if you could review r169 (
> http://bazaar.launchpad.net/~salgado/linaro-image-tools/port-create_boot_cmd/revision/169<http://bazaar.launchpad.net/%7Esalgado/linaro-image-tools/port-create_boot_cmd/revision/169>)
> as well, as it was added after your review. That revision adds a top-level
> test_suite object and instructions for running the test suite.
> --
>
> https://code.launchpad.net/~salgado/linaro-image-tools/port-create_boot_cmd/+merge/41208<https://code.launchpad.net/%7Esalgado/linaro-image-tools/port-create_boot_cmd/+merge/41208>
> You are reviewing the proposed merge of
> lp:~salgado/linaro-image-tools/port-create_boot_cmd into
> lp:linaro-image-tools.
>

Revision history for this message
Martin Ohlsson (martin-ohlson) wrote :

Hi Guilherme,

I've reviewed the new revision and it looks good!

/Martin

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.testr.conf'
2--- .testr.conf 2010-08-27 19:36:11 +0000
3+++ .testr.conf 2010-11-22 13:47:16 +0000
4@@ -1,3 +1,3 @@
5 [DEFAULT]
6 test_command=python -m subunit.run $IDLIST
7-test_id_list_default=hwpack.tests.test_suite
8+test_id_list_default=tests.test_suite
9
10=== added file 'README'
11--- README 1970-01-01 00:00:00 +0000
12+++ README 2010-11-22 13:47:16 +0000
13@@ -0,0 +1,21 @@
14+This project contains a collection of tools to help creating Linaro bootable
15+images to be used in development boards.
16+
17+= Running tests =
18+
19+Before running any tests you need to install the following packages:
20+
21+ - python-testrepository
22+ - python-subunit
23+
24+And run the following command:
25+
26+ $ testr init
27+
28+After that you can run the whole test suite with:
29+
30+ $ testr run
31+
32+If you want to learn more about testrepository:
33+
34+ $ testr quickstart
35
36=== modified file 'linaro-media-create'
37--- linaro-media-create 2010-11-22 13:47:16 +0000
38+++ linaro-media-create 2010-11-22 13:47:16 +0000
39@@ -27,7 +27,8 @@
40 BINARY_TARBALL='binary-tar.tar.gz'
41 BOOT_LABEL=boot
42 RFS_LABEL=rootfs
43-IS_LIVE=
44+IS_LIVE=0
45+IS_LOWMEM=0
46 FAT_SIZE=32
47 IMAGE_SIZE=2G
48 MMC_PART_OFFSET=0
49@@ -60,7 +61,14 @@
50
51 }
52
53-PATH="$(dirname "$(readlink -f "$0")"):$PATH"
54+# Make sure other scripts are called from the correct place when running this
55+# off of a l-m-c working tree.
56+script_dir=$(dirname "$(readlink -f "$0")")
57+PATH="${script_dir}:$PATH"
58+
59+# Also make sure the necessary python modules are available when running this
60+# off of a l-m-c working tree.
61+export PYTHONPATH="$script_dir"
62
63 ensure_command() {
64 # ensure_command foo foo-package
65@@ -392,18 +400,9 @@
66 }
67
68 create_boot_cmd() {
69- if [ "$IS_LIVE" ]; then
70- boot_snippet='boot=casper'
71- [ "$IS_LOWMEM" ] && lowmem_opt=only-ubiquity
72- else
73- boot_snippet='root=UUID='${RFS_UUID}
74- fi
75-
76- cat > ${TMP_DIR}/boot.cmd << BOOTCMD
77-setenv bootcmd 'fatload mmc $mmc_option $KERNEL_ADDR uImage; fatload mmc $mmc_option $INITRD_ADDR uInitrd; bootm $KERNEL_ADDR $INITRD_ADDR'
78-setenv bootargs '${serial_opts} ${splash_opts} ${lowmem_opt} ${boot_snippet} ${boot_args_options}'
79-boot
80-BOOTCMD
81+ python -m media_create.boot_cmd $IS_LIVE $IS_LOWMEM "$mmc_option" \
82+ "$RFS_UUID" "$KERNEL_ADDR" "$INITRD_ADDR" "$serial_opts" \
83+ "$boot_args_options" "$splash_opts" > ${TMP_DIR}/boot.cmd
84 }
85
86 cleanup_sd() {
87@@ -541,7 +540,7 @@
88 echo "Installing Boot Loader"
89 echo ""
90
91- if [ "$IS_LIVE" ]; then
92+ if [ "$IS_LIVE" -eq 1 ]; then
93 parts_dir=casper
94 else
95 parts_dir=boot
96@@ -792,7 +791,7 @@
97 for c in ${consoles}; do
98 serial_opts="$serial_opts console=$c"
99 done
100- if [ "$IS_LIVE" ]; then
101+ if [ "$IS_LIVE" -eq 1 ]; then
102 serial_opts="$serial_opts serialtty=ttyS2"
103 fi
104 fi
105@@ -815,7 +814,7 @@
106 case "$DEVIMAGE" in
107 beagle|igep)
108 serial_opts="$serial_opts console=tty0 console=ttyS2,115200n8"
109- if [ "$IS_LIVE" ]; then
110+ if [ "$IS_LIVE" -eq 1 ]; then
111 serial_opts="$serial_opts serialtty=ttyS2"
112 fi
113 KERNEL_ADDR="0x80000000"
114@@ -824,7 +823,7 @@
115 ;;
116 panda)
117 serial_opts="$serial_opts console=tty0 console=ttyO2,115200n8"
118- if [ "$IS_LIVE" ]; then
119+ if [ "$IS_LIVE" -eq 1 ]; then
120 serial_opts="$serial_opts serialtty=ttyO2"
121 fi
122 KERNEL_ADDR="0x80200000"
123@@ -833,7 +832,7 @@
124 ;;
125 ux500)
126 serial_opts="$serial_opts console=tty0 console=ttyAMA2,115200n8"
127- if [ "$IS_LIVE" ]; then
128+ if [ "$IS_LIVE" -eq 1 ]; then
129 serial_opts="$serial_opts serialtty=ttyAMA2"
130 fi
131 KERNEL_ADDR="0x00100000"
132@@ -844,7 +843,7 @@
133 ;;
134 mx51evk)
135 serial_opts="$serial_opts console=tty0 console=ttymxc0,115200n8"
136- if [ "$IS_LIVE" ]; then
137+ if [ "$IS_LIVE" -eq 1 ]; then
138 serial_opts="$serial_opts serialtty=ttymxc0"
139 fi
140 KERNEL_ADDR="0x90000000"
141@@ -854,7 +853,7 @@
142 ;;
143 vexpress)
144 serial_opts="$serial_opts console=tty0 console=ttyAMA0,38400n8"
145- if [ "$IS_LIVE" ]; then
146+ if [ "$IS_LIVE" -eq 1 ]; then
147 serial_opts="$serial_opts serialtty=ttyAMA0"
148 fi
149 KERNEL_ADDR="0x60008000"
150@@ -869,7 +868,7 @@
151 ;;
152 esac
153 else
154- if [ "$IS_LIVE" ]; then
155+ if [ "$IS_LIVE" -eq 1 ]; then
156 splash_opts="quiet splash"
157 fi
158 fi
159
160=== added directory 'media_create'
161=== added file 'media_create/__init__.py'
162=== added file 'media_create/boot_cmd.py'
163--- media_create/boot_cmd.py 1970-01-01 00:00:00 +0000
164+++ media_create/boot_cmd.py 2010-11-22 13:47:16 +0000
165@@ -0,0 +1,26 @@
166+import sys
167+
168+
169+def create_boot_cmd(is_live, is_lowmem, mmc_option, root_uuid, kernel_addr,
170+ initrd_addr, serial_opts, boot_args_options,
171+ splash_opts=""):
172+ boot_snippet = 'root=UUID=%s' % root_uuid
173+ lowmem_opt = ''
174+ if is_live:
175+ boot_snippet = 'boot=casper'
176+ if is_lowmem:
177+ lowmem_opt = 'only-ubiquity'
178+
179+ return ("setenv bootcmd 'fatload mmc %(mmc_option)s %(kernel_addr)s "
180+ "uImage; fatload mmc %(mmc_option)s %(initrd_addr)s uInitrd; "
181+ "bootm %(kernel_addr)s %(initrd_addr)s'\n"
182+ "setenv bootargs '%(serial_opts)s %(splash_opts)s %(lowmem_opt)s "
183+ "%(boot_snippet)s %(boot_args_options)s'\n"
184+ "boot" % vars())
185+
186+
187+if __name__ == '__main__':
188+ is_live = int(sys.argv[1])
189+ is_lowmem = int(sys.argv[2])
190+ # Use sys.stdout.write() to avoid the trailing newline added by print.
191+ sys.stdout.write(create_boot_cmd(is_live, is_lowmem, *sys.argv[3:]))
192
193=== added directory 'media_create/tests'
194=== added file 'media_create/tests/__init__.py'
195--- media_create/tests/__init__.py 1970-01-01 00:00:00 +0000
196+++ media_create/tests/__init__.py 2010-11-22 13:47:16 +0000
197@@ -0,0 +1,8 @@
198+import unittest
199+
200+def test_suite():
201+ module_names = ['media_create.tests.test_media_create',
202+ ]
203+ loader = unittest.TestLoader()
204+ suite = loader.loadTestsFromNames(module_names)
205+ return suite
206
207=== added file 'media_create/tests/test_media_create.py'
208--- media_create/tests/test_media_create.py 1970-01-01 00:00:00 +0000
209+++ media_create/tests/test_media_create.py 2010-11-22 13:47:16 +0000
210@@ -0,0 +1,32 @@
211+import subprocess
212+import sys
213+
214+from testtools import TestCase
215+
216+from media_create.boot_cmd import create_boot_cmd
217+
218+
219+class TestCreateBootCMD(TestCase):
220+
221+ expected_boot_cmd = (
222+ "setenv bootcmd 'fatload mmc mmc_option kernel_addr uImage; "
223+ "fatload mmc mmc_option initrd_addr uInitrd; bootm kernel_addr "
224+ "initrd_addr'\nsetenv bootargs 'serial_opts splash_opts "
225+ "root=UUID=root_uuid boot_args'\nboot")
226+
227+ def test_create_boot_cmd(self):
228+ cmd = create_boot_cmd(
229+ is_live=False, is_lowmem=False, mmc_option='mmc_option',
230+ root_uuid='root_uuid', kernel_addr="kernel_addr",
231+ initrd_addr="initrd_addr", serial_opts="serial_opts",
232+ boot_args_options="boot_args", splash_opts="splash_opts")
233+ self.assertEqual(self.expected_boot_cmd, cmd)
234+
235+ def test_create_boot_cmd_as_script(self):
236+ args = "%s -m media_create.boot_cmd " % sys.executable
237+ args += ("0 0 mmc_option root_uuid kernel_addr initrd_addr "
238+ "serial_opts boot_args splash_opts")
239+ process = subprocess.Popen(
240+ args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
241+ stdout, stderr = process.communicate()
242+ self.assertEqual(self.expected_boot_cmd, stdout)
243
244=== added directory 'tests'
245=== added file 'tests/__init__.py'
246--- tests/__init__.py 1970-01-01 00:00:00 +0000
247+++ tests/__init__.py 2010-11-22 13:47:16 +0000
248@@ -0,0 +1,8 @@
249+from hwpack.tests import test_suite as hwpack_suite
250+from media_create.tests import test_suite as media_create_suite
251+
252+
253+def test_suite():
254+ suite = hwpack_suite()
255+ suite.addTests(media_create_suite())
256+ return suite

Subscribers

People subscribed via source and target branches