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
=== modified file '.testr.conf'
--- .testr.conf 2010-08-27 19:36:11 +0000
+++ .testr.conf 2010-11-22 13:47:16 +0000
@@ -1,3 +1,3 @@
1[DEFAULT]1[DEFAULT]
2test_command=python -m subunit.run $IDLIST2test_command=python -m subunit.run $IDLIST
3test_id_list_default=hwpack.tests.test_suite3test_id_list_default=tests.test_suite
44
=== added file 'README'
--- README 1970-01-01 00:00:00 +0000
+++ README 2010-11-22 13:47:16 +0000
@@ -0,0 +1,21 @@
1This project contains a collection of tools to help creating Linaro bootable
2images to be used in development boards.
3
4= Running tests =
5
6Before running any tests you need to install the following packages:
7
8 - python-testrepository
9 - python-subunit
10
11And run the following command:
12
13 $ testr init
14
15After that you can run the whole test suite with:
16
17 $ testr run
18
19If you want to learn more about testrepository:
20
21 $ testr quickstart
022
=== modified file 'linaro-media-create'
--- linaro-media-create 2010-11-22 13:47:16 +0000
+++ linaro-media-create 2010-11-22 13:47:16 +0000
@@ -27,7 +27,8 @@
27BINARY_TARBALL='binary-tar.tar.gz'27BINARY_TARBALL='binary-tar.tar.gz'
28BOOT_LABEL=boot28BOOT_LABEL=boot
29RFS_LABEL=rootfs29RFS_LABEL=rootfs
30IS_LIVE=30IS_LIVE=0
31IS_LOWMEM=0
31FAT_SIZE=3232FAT_SIZE=32
32IMAGE_SIZE=2G33IMAGE_SIZE=2G
33MMC_PART_OFFSET=034MMC_PART_OFFSET=0
@@ -60,7 +61,14 @@
6061
61}62}
6263
63PATH="$(dirname "$(readlink -f "$0")"):$PATH"64# Make sure other scripts are called from the correct place when running this
65# off of a l-m-c working tree.
66script_dir=$(dirname "$(readlink -f "$0")")
67PATH="${script_dir}:$PATH"
68
69# Also make sure the necessary python modules are available when running this
70# off of a l-m-c working tree.
71export PYTHONPATH="$script_dir"
6472
65ensure_command() {73ensure_command() {
66 # ensure_command foo foo-package74 # ensure_command foo foo-package
@@ -392,18 +400,9 @@
392}400}
393401
394create_boot_cmd() {402create_boot_cmd() {
395 if [ "$IS_LIVE" ]; then403 python -m media_create.boot_cmd $IS_LIVE $IS_LOWMEM "$mmc_option" \
396 boot_snippet='boot=casper'404 "$RFS_UUID" "$KERNEL_ADDR" "$INITRD_ADDR" "$serial_opts" \
397 [ "$IS_LOWMEM" ] && lowmem_opt=only-ubiquity405 "$boot_args_options" "$splash_opts" > ${TMP_DIR}/boot.cmd
398 else
399 boot_snippet='root=UUID='${RFS_UUID}
400 fi
401
402 cat > ${TMP_DIR}/boot.cmd << BOOTCMD
403setenv bootcmd 'fatload mmc $mmc_option $KERNEL_ADDR uImage; fatload mmc $mmc_option $INITRD_ADDR uInitrd; bootm $KERNEL_ADDR $INITRD_ADDR'
404setenv bootargs '${serial_opts} ${splash_opts} ${lowmem_opt} ${boot_snippet} ${boot_args_options}'
405boot
406BOOTCMD
407}406}
408407
409cleanup_sd() {408cleanup_sd() {
@@ -541,7 +540,7 @@
541 echo "Installing Boot Loader"540 echo "Installing Boot Loader"
542 echo ""541 echo ""
543 542
544 if [ "$IS_LIVE" ]; then543 if [ "$IS_LIVE" -eq 1 ]; then
545 parts_dir=casper544 parts_dir=casper
546 else545 else
547 parts_dir=boot546 parts_dir=boot
@@ -792,7 +791,7 @@
792 for c in ${consoles}; do791 for c in ${consoles}; do
793 serial_opts="$serial_opts console=$c"792 serial_opts="$serial_opts console=$c"
794 done793 done
795 if [ "$IS_LIVE" ]; then794 if [ "$IS_LIVE" -eq 1 ]; then
796 serial_opts="$serial_opts serialtty=ttyS2"795 serial_opts="$serial_opts serialtty=ttyS2"
797 fi796 fi
798fi797fi
@@ -815,7 +814,7 @@
815 case "$DEVIMAGE" in814 case "$DEVIMAGE" in
816 beagle|igep)815 beagle|igep)
817 serial_opts="$serial_opts console=tty0 console=ttyS2,115200n8"816 serial_opts="$serial_opts console=tty0 console=ttyS2,115200n8"
818 if [ "$IS_LIVE" ]; then817 if [ "$IS_LIVE" -eq 1 ]; then
819 serial_opts="$serial_opts serialtty=ttyS2"818 serial_opts="$serial_opts serialtty=ttyS2"
820 fi819 fi
821 KERNEL_ADDR="0x80000000"820 KERNEL_ADDR="0x80000000"
@@ -824,7 +823,7 @@
824 ;;823 ;;
825 panda)824 panda)
826 serial_opts="$serial_opts console=tty0 console=ttyO2,115200n8"825 serial_opts="$serial_opts console=tty0 console=ttyO2,115200n8"
827 if [ "$IS_LIVE" ]; then826 if [ "$IS_LIVE" -eq 1 ]; then
828 serial_opts="$serial_opts serialtty=ttyO2"827 serial_opts="$serial_opts serialtty=ttyO2"
829 fi828 fi
830 KERNEL_ADDR="0x80200000"829 KERNEL_ADDR="0x80200000"
@@ -833,7 +832,7 @@
833 ;;832 ;;
834 ux500)833 ux500)
835 serial_opts="$serial_opts console=tty0 console=ttyAMA2,115200n8"834 serial_opts="$serial_opts console=tty0 console=ttyAMA2,115200n8"
836 if [ "$IS_LIVE" ]; then835 if [ "$IS_LIVE" -eq 1 ]; then
837 serial_opts="$serial_opts serialtty=ttyAMA2"836 serial_opts="$serial_opts serialtty=ttyAMA2"
838 fi837 fi
839 KERNEL_ADDR="0x00100000"838 KERNEL_ADDR="0x00100000"
@@ -844,7 +843,7 @@
844 ;;843 ;;
845 mx51evk)844 mx51evk)
846 serial_opts="$serial_opts console=tty0 console=ttymxc0,115200n8"845 serial_opts="$serial_opts console=tty0 console=ttymxc0,115200n8"
847 if [ "$IS_LIVE" ]; then846 if [ "$IS_LIVE" -eq 1 ]; then
848 serial_opts="$serial_opts serialtty=ttymxc0"847 serial_opts="$serial_opts serialtty=ttymxc0"
849 fi848 fi
850 KERNEL_ADDR="0x90000000"849 KERNEL_ADDR="0x90000000"
@@ -854,7 +853,7 @@
854 ;;853 ;;
855 vexpress)854 vexpress)
856 serial_opts="$serial_opts console=tty0 console=ttyAMA0,38400n8"855 serial_opts="$serial_opts console=tty0 console=ttyAMA0,38400n8"
857 if [ "$IS_LIVE" ]; then856 if [ "$IS_LIVE" -eq 1 ]; then
858 serial_opts="$serial_opts serialtty=ttyAMA0"857 serial_opts="$serial_opts serialtty=ttyAMA0"
859 fi858 fi
860 KERNEL_ADDR="0x60008000"859 KERNEL_ADDR="0x60008000"
@@ -869,7 +868,7 @@
869 ;;868 ;;
870 esac869 esac
871else870else
872 if [ "$IS_LIVE" ]; then871 if [ "$IS_LIVE" -eq 1 ]; then
873 splash_opts="quiet splash"872 splash_opts="quiet splash"
874 fi873 fi
875fi874fi
876875
=== added directory 'media_create'
=== added file 'media_create/__init__.py'
=== added file 'media_create/boot_cmd.py'
--- media_create/boot_cmd.py 1970-01-01 00:00:00 +0000
+++ media_create/boot_cmd.py 2010-11-22 13:47:16 +0000
@@ -0,0 +1,26 @@
1import sys
2
3
4def create_boot_cmd(is_live, is_lowmem, mmc_option, root_uuid, kernel_addr,
5 initrd_addr, serial_opts, boot_args_options,
6 splash_opts=""):
7 boot_snippet = 'root=UUID=%s' % root_uuid
8 lowmem_opt = ''
9 if is_live:
10 boot_snippet = 'boot=casper'
11 if is_lowmem:
12 lowmem_opt = 'only-ubiquity'
13
14 return ("setenv bootcmd 'fatload mmc %(mmc_option)s %(kernel_addr)s "
15 "uImage; fatload mmc %(mmc_option)s %(initrd_addr)s uInitrd; "
16 "bootm %(kernel_addr)s %(initrd_addr)s'\n"
17 "setenv bootargs '%(serial_opts)s %(splash_opts)s %(lowmem_opt)s "
18 "%(boot_snippet)s %(boot_args_options)s'\n"
19 "boot" % vars())
20
21
22if __name__ == '__main__':
23 is_live = int(sys.argv[1])
24 is_lowmem = int(sys.argv[2])
25 # Use sys.stdout.write() to avoid the trailing newline added by print.
26 sys.stdout.write(create_boot_cmd(is_live, is_lowmem, *sys.argv[3:]))
027
=== added directory 'media_create/tests'
=== added file 'media_create/tests/__init__.py'
--- media_create/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ media_create/tests/__init__.py 2010-11-22 13:47:16 +0000
@@ -0,0 +1,8 @@
1import unittest
2
3def test_suite():
4 module_names = ['media_create.tests.test_media_create',
5 ]
6 loader = unittest.TestLoader()
7 suite = loader.loadTestsFromNames(module_names)
8 return suite
09
=== added file 'media_create/tests/test_media_create.py'
--- media_create/tests/test_media_create.py 1970-01-01 00:00:00 +0000
+++ media_create/tests/test_media_create.py 2010-11-22 13:47:16 +0000
@@ -0,0 +1,32 @@
1import subprocess
2import sys
3
4from testtools import TestCase
5
6from media_create.boot_cmd import create_boot_cmd
7
8
9class TestCreateBootCMD(TestCase):
10
11 expected_boot_cmd = (
12 "setenv bootcmd 'fatload mmc mmc_option kernel_addr uImage; "
13 "fatload mmc mmc_option initrd_addr uInitrd; bootm kernel_addr "
14 "initrd_addr'\nsetenv bootargs 'serial_opts splash_opts "
15 "root=UUID=root_uuid boot_args'\nboot")
16
17 def test_create_boot_cmd(self):
18 cmd = create_boot_cmd(
19 is_live=False, is_lowmem=False, mmc_option='mmc_option',
20 root_uuid='root_uuid', kernel_addr="kernel_addr",
21 initrd_addr="initrd_addr", serial_opts="serial_opts",
22 boot_args_options="boot_args", splash_opts="splash_opts")
23 self.assertEqual(self.expected_boot_cmd, cmd)
24
25 def test_create_boot_cmd_as_script(self):
26 args = "%s -m media_create.boot_cmd " % sys.executable
27 args += ("0 0 mmc_option root_uuid kernel_addr initrd_addr "
28 "serial_opts boot_args splash_opts")
29 process = subprocess.Popen(
30 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
31 stdout, stderr = process.communicate()
32 self.assertEqual(self.expected_boot_cmd, stdout)
033
=== added directory 'tests'
=== added file 'tests/__init__.py'
--- tests/__init__.py 1970-01-01 00:00:00 +0000
+++ tests/__init__.py 2010-11-22 13:47:16 +0000
@@ -0,0 +1,8 @@
1from hwpack.tests import test_suite as hwpack_suite
2from media_create.tests import test_suite as media_create_suite
3
4
5def test_suite():
6 suite = hwpack_suite()
7 suite.addTests(media_create_suite())
8 return suite

Subscribers

People subscribed via source and target branches