Merge lp:~lool/linaro-image-tools/samsung-v310-v3 into lp:~angus-akkea/linaro-image-tools/Samsung-SMDKV310

Proposed by Loïc Minier
Status: Merged
Merged at revision: 309
Proposed branch: lp:~lool/linaro-image-tools/samsung-v310-v3
Merge into: lp:~angus-akkea/linaro-image-tools/Samsung-SMDKV310
Diff against target: 420 lines (+112/-70)
2 files modified
linaro_media_create/boards.py (+46/-28)
linaro_media_create/tests/test_media_create.py (+66/-42)
To merge this branch: bzr merge lp:~lool/linaro-image-tools/samsung-v310-v3
Reviewer Review Type Date Requested Status
Angus Ainslie Pending
Review via email: mp+52274@code.launchpad.net

Description of the change

This addresses some other comments from Guilherme and adds tests.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro_media_create/boards.py'
--- linaro_media_create/boards.py 2011-03-02 19:57:43 +0000
+++ linaro_media_create/boards.py 2011-03-05 00:53:54 +0000
@@ -95,7 +95,7 @@
95SAMSUNG_V310_UINITRD_START = (95SAMSUNG_V310_UINITRD_START = (
96 SAMSUNG_V310_UIMAGE_START + SAMSUNG_V310_UIMAGE_LEN)96 SAMSUNG_V310_UIMAGE_START + SAMSUNG_V310_UIMAGE_LEN)
97SAMSUNG_V310_UINITRD_RESERVED_LEN = 20480097SAMSUNG_V310_UINITRD_RESERVED_LEN = 204800
98SAMSUNG_V310_UINITRD_COPY_LEN = 32768 98SAMSUNG_V310_UINITRD_COPY_LEN = 32768
99assert SAMSUNG_V310_UINITRD_START == 9281, (99assert SAMSUNG_V310_UINITRD_START == 9281, (
100 "BL2 (u-boot) expects uInitrd at +9281s")100 "BL2 (u-boot) expects uInitrd at +9281s")
101assert SAMSUNG_V310_UINITRD_RESERVED_LEN * SECTOR_SIZE == 100 * 1024 * 1024, (101assert SAMSUNG_V310_UINITRD_RESERVED_LEN * SECTOR_SIZE == 100 * 1024 * 1024, (
@@ -120,6 +120,14 @@
120 return start, end, length120 return start, end, length
121121
122122
123class classproperty(object):
124 """A descriptor that provides @property behavior on class methods."""
125 def __init__(self, getter):
126 self.getter = getter
127 def __get__(self, instance, cls):
128 return self.getter(cls)
129
130
123class BoardConfig(object):131class BoardConfig(object):
124 """The configuration used when building an image for a board."""132 """The configuration used when building an image for a board."""
125 # These attributes may not need to be redefined on some subclasses.133 # These attributes may not need to be redefined on some subclasses.
@@ -178,8 +186,8 @@
178 return '%s,%s,%s,*\n%s,,,-' % (186 return '%s,%s,%s,*\n%s,,,-' % (
179 boot_start, boot_len, partition_type, root_start)187 boot_start, boot_len, partition_type, root_start)
180188
181 @classmethod189 @classproperty
182 def _get_bootcmd(cls):190 def bootcmd(cls):
183 """Get the bootcmd for this board.191 """Get the bootcmd for this board.
184192
185 In general subclasses should not have to override this.193 In general subclasses should not have to override this.
@@ -232,7 +240,7 @@
232 boot_env = {}240 boot_env = {}
233 boot_env["bootargs"] = cls._get_bootargs(241 boot_env["bootargs"] = cls._get_bootargs(
234 is_live, is_lowmem, consoles, rootfs_uuid)242 is_live, is_lowmem, consoles, rootfs_uuid)
235 boot_env["bootcmd"] = cls._get_bootcmd()243 boot_env["bootcmd"] = cls.bootcmd
236 return boot_env244 return boot_env
237245
238 @classmethod246 @classmethod
@@ -255,14 +263,6 @@
255 raise NotImplementedError()263 raise NotImplementedError()
256264
257265
258class classproperty(object):
259 """A descriptor that provides @property behavior on class methods."""
260 def __init__(self, getter):
261 self.getter = getter
262 def __get__(self, instance, cls):
263 return self.getter(cls)
264
265
266class OmapConfig(BoardConfig):266class OmapConfig(BoardConfig):
267 uboot_in_boot_part = True267 uboot_in_boot_part = True
268268
@@ -588,10 +588,7 @@
588588
589def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,589def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,
590 skip=None):590 skip=None):
591 """a generic dd function used to insert blobs into files or devices591 """Wrapper around the dd command"""
592
593 uses the OS dd function
594 """
595 cmd = [592 cmd = [
596 "dd", "if=%s" % input_file, "of=%s" % output_file,593 "dd", "if=%s" % input_file, "of=%s" % output_file,
597 "bs=%s" % block_size, "conv=notrunc"]594 "bs=%s" % block_size, "conv=notrunc"]
@@ -675,11 +672,16 @@
675672
676def make_flashable_env(boot_env, env_size):673def make_flashable_env(boot_env, env_size):
677 env_strings = ["%s=%s" % (k, v) for k, v in boot_env.items()]674 env_strings = ["%s=%s" % (k, v) for k, v in boot_env.items()]
675 env_strings.sort()
678 env = struct.pack('B', 0).join(env_strings)676 env = struct.pack('B', 0).join(env_strings)
679677
680 # pad the rest of the env for the CRC calc678 # we still need to zero-terminate the last string, and 4 bytes for crc
681 while len(env) < (env_size - 4):679 assert len(env) + 1 + 4 <= env_size, (
682 env += struct.pack('B', 0)680 "environment doesn't fit in %s bytes" % env_size)
681
682 # pad the rest of the env for the CRC calc; the "s" format will write zero
683 # bytes to pad the (empty) string to repeat count
684 env += struct.pack('%ss' % (env_size - len(env) - 4), '')
683685
684 crc = crc32(env)686 crc = crc32(env)
685 env = struct.pack('<i', crc) + env687 env = struct.pack('<i', crc) + env
@@ -693,8 +695,14 @@
693695
694696
695def install_mx5_boot_loader(imx_file, boot_device_or_file):697def install_mx5_boot_loader(imx_file, boot_device_or_file):
696 # XXX need to check that the length of imx_file is smaller than698 # bootloader partition starts at +1s but we write the file at +2s, so we
697 # LOADER_MIN_SIZE_S699 # need to check that the bootloader partition minus 1s is at least as large
700 # as the u-boot binary; note that the real bootloader partition might be
701 # larger than LOADER_MIN_SIZE_S, but if u-boot is larger it's a sign we
702 # need to bump LOADER_MIN_SIZE_S
703 max_size = (LOADER_MIN_SIZE_S - 1) * SECTOR_SIZE
704 assert os.path.getsize(imx_file) <= max_size, (
705 "%s is larger than guaranteed bootloader partition size" % imx_file)
698 _dd(imx_file, boot_device_or_file, seek=2)706 _dd(imx_file, boot_device_or_file, seek=2)
699707
700708
@@ -735,23 +743,32 @@
735743
736744
737def install_smdkv310_uImage(uImage_file, boot_device_or_file):745def install_smdkv310_uImage(uImage_file, boot_device_or_file):
738 # XXX need to check that the length of uImage_file is smaller than746 # the layout keeps SAMSUNG_V310_UIMAGE_LEN sectors for uImage; make sure
739 # SAMSUNG_V310_UIMAGE_LEN747 # uImage isn't actually larger or it would be truncated
748 max_size = SAMSUNG_V310_UIMAGE_LEN * SECTOR_SIZE
749 assert os.path.getsize(uImage_file) <= max_size, (
750 "%s is larger than the allocated v310 uImage length" % uImage_file)
740 _dd(uImage_file, boot_device_or_file, count=SAMSUNG_V310_UIMAGE_LEN,751 _dd(uImage_file, boot_device_or_file, count=SAMSUNG_V310_UIMAGE_LEN,
741 seek=SAMSUNG_V310_UIMAGE_START)752 seek=SAMSUNG_V310_UIMAGE_START)
742753
743754
744def install_smdkv310_initrd(initrd_file, boot_device_or_file):755def install_smdkv310_initrd(initrd_file, boot_device_or_file):
745 # XXX need to check that the length of initrd_file is smaller than756 # the layout keeps SAMSUNG_V310_UINITRD_RESERVED_LEN sectors for uInitrd
746 # SAMSUNG_V310_UINITRD_LEN757 # but only SAMSUNG_V310_UINITRD_COPY_LEN sectors are loaded into memory;
747 _dd(initrd_file, boot_device_or_file, 758 # make sure uInitrd isn't actually larger or it would be truncated in
759 # memory
760 max_size = SAMSUNG_V310_UINITRD_COPY_LEN * SECTOR_SIZE
761 assert os.path.getsize(initrd_file) <= max_size, (
762 "%s is larger than the v310 uInitrd length as used by u-boot"
763 % initrd_file)
764 _dd(initrd_file, boot_device_or_file,
748 count=SAMSUNG_V310_UINITRD_COPY_LEN,765 count=SAMSUNG_V310_UINITRD_COPY_LEN,
749 seek=SAMSUNG_V310_UINITRD_START)766 seek=SAMSUNG_V310_UINITRD_START)
750767
751768
752def install_smdkv310_boot_env(env_file, boot_device_or_file):769def install_smdkv310_boot_env(env_file, boot_device_or_file):
753 # XXX need to check that the length of env_file is smaller than770 # the environment file is exactly SAMSUNG_V310_ENV_LEN as created by
754 # SAMSUNG_V310_ENV_LEN771 # make_flashable_env(), so we don't need to check the size of env_file
755 _dd(env_file, boot_device_or_file, count=SAMSUNG_V310_ENV_LEN,772 _dd(env_file, boot_device_or_file, count=SAMSUNG_V310_ENV_LEN,
756 seek=SAMSUNG_V310_ENV_START)773 seek=SAMSUNG_V310_ENV_START)
757774
@@ -773,3 +790,4 @@
773 # SAMSUNG_V310_BL2_LEN790 # SAMSUNG_V310_BL2_LEN
774 _dd(v310_file, boot_device_or_file, seek=SAMSUNG_V310_BL2_START,791 _dd(v310_file, boot_device_or_file, seek=SAMSUNG_V310_BL2_START,
775 skip=(SAMSUNG_V310_BL2_START - SAMSUNG_V310_BL1_START))792 skip=(SAMSUNG_V310_BL2_START - SAMSUNG_V310_BL1_START))
793
776794
=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py 2011-03-02 14:51:14 +0000
+++ linaro_media_create/tests/test_media_create.py 2011-03-05 00:53:54 +0000
@@ -43,9 +43,12 @@
43 )43 )
44import linaro_media_create44import linaro_media_create
45from linaro_media_create.boards import (45from linaro_media_create.boards import (
46 LOADER_MIN_SIZE_S,
47 SECTOR_SIZE,
46 align_up,48 align_up,
47 align_partition,49 align_partition,
48 board_configs,50 board_configs,
51 make_flashable_env,
49 install_mx5_boot_loader,52 install_mx5_boot_loader,
50 install_omap_boot_loader,53 install_omap_boot_loader,
51 make_boot_script,54 make_boot_script,
@@ -621,14 +624,35 @@
621 '-d', 'parts_dir/initrd.img-*-sub_arch', 'boot_disk/uInitrd']624 '-d', 'parts_dir/initrd.img-*-sub_arch', 'boot_disk/uInitrd']
622 self.assertEqual([expected], fixture.mock.calls)625 self.assertEqual([expected], fixture.mock.calls)
623626
627 def test_make_flashable_env_too_small_env(self):
628 env = {'verylong': 'evenlonger'}
629 self.assertRaises(AssertionError, make_flashable_env, env, 8)
630
631 def test_make_flashable_env(self):
632 env_file = self.createTempFileAsFixture()
633 self.useFixture(MockSomethingFixture(
634 tempfile, "mkstemp", lambda: (None, env_file)))
635 env = {'a': 'b', 'x': 'y'}
636 make_flashable_env(env, 12)
637 with open(env_file, "r") as fd:
638 self.assertEqual("\x80\x29\x2E\x89a=b\x00x=y\x00", fd.read())
639
624 def test_install_mx5_boot_loader(self):640 def test_install_mx5_boot_loader(self):
625 fixture = self._mock_Popen()641 fixture = self._mock_Popen()
626 install_mx5_boot_loader("imx_file", "boot_device_or_file")642 imx_file = self.createTempFileAsFixture()
643 install_mx5_boot_loader(imx_file, "boot_device_or_file")
627 expected = [644 expected = [
628 'sudo', 'dd', 'if=imx_file', 'of=boot_device_or_file', 'bs=512',645 'sudo', 'dd', 'if=%s' % imx_file, 'of=boot_device_or_file',
629 'conv=notrunc', 'seek=2']646 'bs=512', 'conv=notrunc', 'seek=2']
630 self.assertEqual([expected], fixture.mock.calls)647 self.assertEqual([expected], fixture.mock.calls)
631648
649 def test_install_mx5_boot_loader_too_large(self):
650 self.useFixture(MockSomethingFixture(
651 os.path, "getsize",
652 lambda s: (LOADER_MIN_SIZE_S - 1) * SECTOR_SIZE + 1))
653 self.assertRaises(AssertionError,
654 install_mx5_boot_loader, "imx_file", "boot_device_or_file")
655
632 def test_install_omap_boot_loader(self):656 def test_install_omap_boot_loader(self):
633 fixture = self._mock_Popen()657 fixture = self._mock_Popen()
634 self.useFixture(MockSomethingFixture(658 self.useFixture(MockSomethingFixture(
@@ -763,9 +787,9 @@
763 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())787 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
764 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())788 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
765789
766 tempfile = self.createTempFileAsFixture()790 tmpfile = self.createTempFileAsFixture()
767 create_partitions(791 create_partitions(
768 board_configs['beagle'], Media(tempfile), 255, 63, '')792 board_configs['beagle'], Media(tmpfile), 255, 63, '')
769793
770 # Unlike the test for partitioning of a regular block device, in this794 # Unlike the test for partitioning of a regular block device, in this
771 # case parted was not called as there's no existing partition table795 # case parted was not called as there's no existing partition table
@@ -773,26 +797,26 @@
773 self.assertEqual([['sync']], popen_fixture.mock.calls)797 self.assertEqual([['sync']], popen_fixture.mock.calls)
774798
775 self.assertEqual(799 self.assertEqual(
776 [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', tempfile)],800 [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', tmpfile)],
777 sfdisk_fixture.mock.calls)801 sfdisk_fixture.mock.calls)
778802
779 def test_run_sfdisk_commands(self):803 def test_run_sfdisk_commands(self):
780 tempfile = self.createTempFileAsFixture()804 tmpfile = self.createTempFileAsFixture()
781 proc = cmd_runner.run(805 proc = cmd_runner.run(
782 ['qemu-img', 'create', '-f', 'raw', tempfile, '10M'],806 ['qemu-img', 'create', '-f', 'raw', tmpfile, '10M'],
783 stdout=subprocess.PIPE)807 stdout=subprocess.PIPE)
784 proc.communicate()808 proc.communicate()
785 stdout, stderr = run_sfdisk_commands(809 stdout, stderr = run_sfdisk_commands(
786 '2,16063,0xDA', 255, 63, '', tempfile, as_root=False,810 '2,16063,0xDA', 255, 63, '', tmpfile, as_root=False,
787 stderr=subprocess.PIPE)811 stderr=subprocess.PIPE)
788 self.assertIn('Successfully wrote the new partition table', stdout)812 self.assertIn('Successfully wrote the new partition table', stdout)
789813
790 def test_run_sfdisk_commands_raises_on_non_zero_returncode(self):814 def test_run_sfdisk_commands_raises_on_non_zero_returncode(self):
791 tempfile = self.createTempFileAsFixture()815 tmpfile = self.createTempFileAsFixture()
792 self.assertRaises(816 self.assertRaises(
793 cmd_runner.SubcommandNonZeroReturnValue,817 cmd_runner.SubcommandNonZeroReturnValue,
794 run_sfdisk_commands,818 run_sfdisk_commands,
795 ',1,0xDA', 255, 63, '', tempfile, as_root=False,819 ',1,0xDA', 255, 63, '', tmpfile, as_root=False,
796 stderr=subprocess.PIPE)820 stderr=subprocess.PIPE)
797821
798822
@@ -808,7 +832,7 @@
808 super(TestPartitionSetup, self).tearDown()832 super(TestPartitionSetup, self).tearDown()
809 time.sleep = self.orig_sleep833 time.sleep = self.orig_sleep
810834
811 def _create_tempfile(self):835 def _create_tmpfile(self):
812 # boot part at +8 MiB, root part at +16 MiB836 # boot part at +8 MiB, root part at +16 MiB
813 return self._create_qemu_img_with_partitions(837 return self._create_qemu_img_with_partitions(
814 '16384,15746,0x0C,*\n32768,,,-')838 '16384,15746,0x0C,*\n32768,,,-')
@@ -823,19 +847,19 @@
823 self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G'))847 self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G'))
824848
825 def test_calculate_partition_size_and_offset(self):849 def test_calculate_partition_size_and_offset(self):
826 tempfile = self._create_tempfile()850 tmpfile = self._create_tmpfile()
827 vfat_size, vfat_offset, linux_size, linux_offset = (851 vfat_size, vfat_offset, linux_size, linux_offset = (
828 calculate_partition_size_and_offset(tempfile))852 calculate_partition_size_and_offset(tmpfile))
829 self.assertEqual(853 self.assertEqual(
830 [8061952L, 8388608L, 14680064L, 16777216L],854 [8061952L, 8388608L, 14680064L, 16777216L],
831 [vfat_size, vfat_offset, linux_size, linux_offset])855 [vfat_size, vfat_offset, linux_size, linux_offset])
832856
833 def test_partition_numbering(self):857 def test_partition_numbering(self):
834 # another Linux partition at +24 MiB after the boot/root parts858 # another Linux partition at +24 MiB after the boot/root parts
835 tempfile = self._create_qemu_img_with_partitions(859 tmpfile = self._create_qemu_img_with_partitions(
836 '16384,15746,0x0C,*\n32768,15427,,-\n49152,,,-')860 '16384,15746,0x0C,*\n32768,15427,,-\n49152,,,-')
837 vfat_size, vfat_offset, linux_size, linux_offset = (861 vfat_size, vfat_offset, linux_size, linux_offset = (
838 calculate_partition_size_and_offset(tempfile))862 calculate_partition_size_and_offset(tmpfile))
839 # check that the linux partition offset starts at +16 MiB so that it's863 # check that the linux partition offset starts at +16 MiB so that it's
840 # the partition immediately following the vfat one864 # the partition immediately following the vfat one
841 self.assertEqual(linux_offset, 32768 * 512)865 self.assertEqual(linux_offset, 32768 * 512)
@@ -843,39 +867,39 @@
843 def test_get_boot_and_root_partitions_for_media_beagle(self):867 def test_get_boot_and_root_partitions_for_media_beagle(self):
844 self.useFixture(MockSomethingFixture(868 self.useFixture(MockSomethingFixture(
845 partitions, '_get_device_file_for_partition_number',869 partitions, '_get_device_file_for_partition_number',
846 lambda dev, partition: '%s%d' % (tempfile, partition)))870 lambda dev, partition: '%s%d' % (tmpfile, partition)))
847 tempfile = self.createTempFileAsFixture()871 tmpfile = self.createTempFileAsFixture()
848 media = Media(tempfile)872 media = Media(tmpfile)
849 media.is_block_device = True873 media.is_block_device = True
850 self.assertEqual(874 self.assertEqual(
851 ("%s%d" % (tempfile, 1), "%s%d" % (tempfile, 2)),875 ("%s%d" % (tmpfile, 1), "%s%d" % (tmpfile, 2)),
852 get_boot_and_root_partitions_for_media(876 get_boot_and_root_partitions_for_media(
853 media, board_configs['beagle']))877 media, board_configs['beagle']))
854878
855 def test_get_boot_and_root_partitions_for_media_mx5(self):879 def test_get_boot_and_root_partitions_for_media_mx5(self):
856 self.useFixture(MockSomethingFixture(880 self.useFixture(MockSomethingFixture(
857 partitions, '_get_device_file_for_partition_number',881 partitions, '_get_device_file_for_partition_number',
858 lambda dev, partition: '%s%d' % (tempfile, partition)))882 lambda dev, partition: '%s%d' % (tmpfile, partition)))
859 tempfile = self.createTempFileAsFixture()883 tmpfile = self.createTempFileAsFixture()
860 media = Media(tempfile)884 media = Media(tmpfile)
861 media.is_block_device = True885 media.is_block_device = True
862 self.assertEqual(886 self.assertEqual(
863 ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)),887 ("%s%d" % (tmpfile, 2), "%s%d" % (tmpfile, 3)),
864 get_boot_and_root_partitions_for_media(media, boards.Mx5Config))888 get_boot_and_root_partitions_for_media(media, boards.Mx5Config))
865889
866 def _create_qemu_img_with_partitions(self, sfdisk_commands):890 def _create_qemu_img_with_partitions(self, sfdisk_commands):
867 tempfile = self.createTempFileAsFixture()891 tmpfile = self.createTempFileAsFixture()
868 proc = cmd_runner.run(892 proc = cmd_runner.run(
869 ['qemu-img', 'create', '-f', 'raw', tempfile, '30M'],893 ['qemu-img', 'create', '-f', 'raw', tmpfile, '30M'],
870 stdout=subprocess.PIPE)894 stdout=subprocess.PIPE)
871 proc.communicate()895 proc.communicate()
872 stdout, stderr = run_sfdisk_commands(896 stdout, stderr = run_sfdisk_commands(
873 sfdisk_commands, 255, 63, '', tempfile, as_root=False,897 sfdisk_commands, 255, 63, '', tmpfile, as_root=False,
874 # Throw away stderr as sfdisk complains a lot when operating on a898 # Throw away stderr as sfdisk complains a lot when operating on a
875 # qemu image.899 # qemu image.
876 stderr=subprocess.PIPE)900 stderr=subprocess.PIPE)
877 self.assertIn('Successfully wrote the new partition table', stdout)901 self.assertIn('Successfully wrote the new partition table', stdout)
878 return tempfile902 return tmpfile
879903
880 def test_ensure_partition_is_not_mounted_for_mounted_partition(self):904 def test_ensure_partition_is_not_mounted_for_mounted_partition(self):
881 self.useFixture(MockSomethingFixture(905 self.useFixture(MockSomethingFixture(
@@ -893,18 +917,18 @@
893 self.assertEqual(None, popen_fixture.mock.calls)917 self.assertEqual(None, popen_fixture.mock.calls)
894918
895 def test_get_boot_and_root_loopback_devices(self):919 def test_get_boot_and_root_loopback_devices(self):
896 tempfile = self._create_tempfile()920 tmpfile = self._create_tmpfile()
897 atexit_fixture = self.useFixture(MockSomethingFixture(921 atexit_fixture = self.useFixture(MockSomethingFixture(
898 atexit, 'register', AtExitRegister()))922 atexit, 'register', AtExitRegister()))
899 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())923 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
900 # We can't test the return value of get_boot_and_root_loopback_devices924 # We can't test the return value of get_boot_and_root_loopback_devices
901 # because it'd require running losetup as root, so we just make sure925 # because it'd require running losetup as root, so we just make sure
902 # it calls losetup correctly.926 # it calls losetup correctly.
903 get_boot_and_root_loopback_devices(tempfile)927 get_boot_and_root_loopback_devices(tmpfile)
904 self.assertEqual(928 self.assertEqual(
905 [['sudo', 'losetup', '-f', '--show', tempfile, '--offset',929 [['sudo', 'losetup', '-f', '--show', tmpfile, '--offset',
906 '8388608', '--sizelimit', '8061952'],930 '8388608', '--sizelimit', '8061952'],
907 ['sudo', 'losetup', '-f', '--show', tempfile, '--offset',931 ['sudo', 'losetup', '-f', '--show', tmpfile, '--offset',
908 '16777216', '--sizelimit', '14680064']],932 '16777216', '--sizelimit', '14680064']],
909 popen_fixture.mock.calls)933 popen_fixture.mock.calls)
910934
@@ -925,7 +949,7 @@
925 # but here we mock Popen() and thanks to that the image is not setup949 # but here we mock Popen() and thanks to that the image is not setup
926 # (via qemu-img) inside setup_partitions. That's why we pass an950 # (via qemu-img) inside setup_partitions. That's why we pass an
927 # already setup image file.951 # already setup image file.
928 tempfile = self._create_tempfile()952 tmpfile = self._create_tmpfile()
929 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())953 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
930 self.useFixture(MockSomethingFixture(954 self.useFixture(MockSomethingFixture(
931 sys, 'stdout', open('/dev/null', 'w')))955 sys, 'stdout', open('/dev/null', 'w')))
@@ -942,14 +966,14 @@
942 partitions, 'get_boot_and_root_loopback_devices',966 partitions, 'get_boot_and_root_loopback_devices',
943 lambda image: ('/dev/loop99', '/dev/loop98')))967 lambda image: ('/dev/loop99', '/dev/loop98')))
944 bootfs_dev, rootfs_dev = setup_partitions(968 bootfs_dev, rootfs_dev = setup_partitions(
945 board_configs['beagle'], Media(tempfile), '2G', 'boot',969 board_configs['beagle'], Media(tmpfile), '2G', 'boot',
946 'root', 'ext3', True, True, True)970 'root', 'ext3', True, True, True)
947 self.assertEqual(971 self.assertEqual(
948 # This is the call that would create a 2 GiB image file.972 # This is the call that would create a 2 GiB image file.
949 [['qemu-img', 'create', '-f', 'raw', tempfile, '2147483648'],973 [['qemu-img', 'create', '-f', 'raw', tmpfile, '2147483648'],
950 # This call would partition the image file.974 # This call would partition the image file.
951 ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S',975 ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S',
952 '63', '-C', '261', tempfile],976 '63', '-C', '261', tmpfile],
953 # Make sure changes are written to disk.977 # Make sure changes are written to disk.
954 ['sync'],978 ['sync'],
955 ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],979 ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],
@@ -962,21 +986,21 @@
962 # Pretend the partitions are mounted.986 # Pretend the partitions are mounted.
963 self.useFixture(MockSomethingFixture(987 self.useFixture(MockSomethingFixture(
964 partitions, 'is_partition_mounted', lambda part: True))988 partitions, 'is_partition_mounted', lambda part: True))
965 tempfile = self._create_tempfile()989 tmpfile = self._create_tmpfile()
966 self.useFixture(MockSomethingFixture(990 self.useFixture(MockSomethingFixture(
967 partitions, '_get_device_file_for_partition_number',991 partitions, '_get_device_file_for_partition_number',
968 lambda dev, partition: '%s%d' % (tempfile, partition)))992 lambda dev, partition: '%s%d' % (tmpfile, partition)))
969 media = Media(tempfile)993 media = Media(tmpfile)
970 # Pretend our tempfile is a block device.994 # Pretend our tmpfile is a block device.
971 media.is_block_device = True995 media.is_block_device = True
972 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())996 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
973 bootfs_dev, rootfs_dev = setup_partitions(997 bootfs_dev, rootfs_dev = setup_partitions(
974 board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3',998 board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3',
975 True, True, True)999 True, True, True)
976 self.assertEqual(1000 self.assertEqual(
977 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],1001 [['sudo', 'parted', '-s', tmpfile, 'mklabel', 'msdos'],
978 ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S',1002 ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S',
979 '63', tempfile],1003 '63', tmpfile],
980 ['sync'],1004 ['sync'],
981 # Since the partitions are mounted, setup_partitions will umount1005 # Since the partitions are mounted, setup_partitions will umount
982 # them before running mkfs.1006 # them before running mkfs.

Subscribers

People subscribed via source and target branches