Merge lp:~lool/linaro-image-tools/chs-align-tests into lp:linaro-image-tools/11.11

Proposed by Loïc Minier
Status: Merged
Merged at revision: 299
Proposed branch: lp:~lool/linaro-image-tools/chs-align-tests
Merge into: lp:linaro-image-tools/11.11
Diff against target: 136 lines (+20/-17)
1 file modified
linaro_media_create/tests/test_media_create.py (+20/-17)
To merge this branch: bzr merge lp:~lool/linaro-image-tools/chs-align-tests
Reviewer Review Type Date Requested Status
Guilherme Salgado (community) Approve
Review via email: mp+53874@code.launchpad.net

Description of the change

Use HEADS and SECTORS from partitions.py in the tests instead of hardcoding 128/32.

To post a comment you must log in.
Revision history for this message
Loïc Minier (lool) wrote :

I didn't change the expected values to be computed from BOOT_MIN_SIZE_S etc. as I didn't want to duplicate all the logic to align partitions as this would basically be duplicating the bugs too I guess.

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

On Thu, 2011-03-17 at 18:33 +0000, Loïc Minier wrote:
> I didn't change the expected values to be computed from BOOT_MIN_SIZE_S etc. as I didn't want to duplicate all the logic to align partitions as this would basically be duplicating the bugs too I guess.

I don't see what you mean here, but the changes look good. Thanks!

 review approve

review: Approve
Revision history for this message
Loïc Minier (lool) wrote :

For instance, we could compute the expected offsets from constants such as PART_ALIGN, BOOT_MIN_SIZE etc. in tests which look at the sfdisk commands, but this would duplicate logic

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py 2011-03-12 09:31:11 +0000
+++ linaro_media_create/tests/test_media_create.py 2011-03-17 18:32:33 +0000
@@ -67,6 +67,8 @@
67 temporarily_overwrite_file_on_dir,67 temporarily_overwrite_file_on_dir,
68 )68 )
69from linaro_media_create.partitions import (69from linaro_media_create.partitions import (
70 HEADS,
71 SECTORS,
70 calculate_partition_size_and_offset,72 calculate_partition_size_and_offset,
71 convert_size_to_bytes,73 convert_size_to_bytes,
72 create_partitions,74 create_partitions,
@@ -770,7 +772,7 @@
770 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())772 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
771 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())773 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
772774
773 create_partitions(boards.Mx5Config, self.media, 128, 32, '')775 create_partitions(boards.Mx5Config, self.media, HEADS, SECTORS, '')
774776
775 self.assertEqual(777 self.assertEqual(
776 ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path),778 ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path),
@@ -780,8 +782,8 @@
780 # every time we run sfdisk it actually repartitions the device,782 # every time we run sfdisk it actually repartitions the device,
781 # erasing any partitions created previously.783 # erasing any partitions created previously.
782 self.assertEqual(784 self.assertEqual(
783 [('1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', 128, 32, '',785 [('1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', HEADS, SECTORS,
784 self.media.path)],786 '', self.media.path)],
785 sfdisk_fixture.mock.calls)787 sfdisk_fixture.mock.calls)
786788
787 def test_create_partitions_for_smdkv310(self):789 def test_create_partitions_for_smdkv310(self):
@@ -790,7 +792,7 @@
790 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())792 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
791793
792 create_partitions(794 create_partitions(
793 board_configs['smdkv310'], self.media, 128, 32, '')795 board_configs['smdkv310'], self.media, HEADS, SECTORS, '')
794796
795 self.assertEqual(797 self.assertEqual(
796 ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path),798 ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path),
@@ -800,22 +802,23 @@
800 # every time we run sfdisk it actually repartitions the device,802 # every time we run sfdisk it actually repartitions the device,
801 # erasing any partitions created previously.803 # erasing any partitions created previously.
802 self.assertEqual(804 self.assertEqual(
803 [('1,221183,0xDA\n221184,106496,0x0C,*\n327680,,,-', 128, 32, '',805 [('1,221183,0xDA\n221184,106496,0x0C,*\n327680,,,-', HEADS,
804 self.media.path)], sfdisk_fixture.mock.calls)806 SECTORS, '', self.media.path)], sfdisk_fixture.mock.calls)
805807
806 def test_create_partitions_for_beagle(self):808 def test_create_partitions_for_beagle(self):
807 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())809 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
808 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())810 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
809811
810 create_partitions(812 create_partitions(
811 board_configs['beagle'], self.media, 128, 32, '')813 board_configs['beagle'], self.media, HEADS, SECTORS, '')
812814
813 self.assertEqual(815 self.assertEqual(
814 ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path),816 ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path),
815 'sync'],817 'sync'],
816 popen_fixture.mock.commands_executed)818 popen_fixture.mock.commands_executed)
817 self.assertEqual(819 self.assertEqual(
818 [('63,106432,0x0C,*\n106496,,,-', 128, 32, '', self.media.path)],820 [('63,106432,0x0C,*\n106496,,,-', HEADS, SECTORS, '',
821 self.media.path)],
819 sfdisk_fixture.mock.calls)822 sfdisk_fixture.mock.calls)
820823
821 def test_create_partitions_with_img_file(self):824 def test_create_partitions_with_img_file(self):
@@ -824,7 +827,7 @@
824827
825 tmpfile = self.createTempFileAsFixture()828 tmpfile = self.createTempFileAsFixture()
826 create_partitions(829 create_partitions(
827 board_configs['beagle'], Media(tmpfile), 128, 32, '')830 board_configs['beagle'], Media(tmpfile), HEADS, SECTORS, '')
828831
829 # Unlike the test for partitioning of a regular block device, in this832 # Unlike the test for partitioning of a regular block device, in this
830 # case parted was not called as there's no existing partition table833 # case parted was not called as there's no existing partition table
@@ -832,7 +835,7 @@
832 self.assertEqual(['sync'], popen_fixture.mock.commands_executed)835 self.assertEqual(['sync'], popen_fixture.mock.commands_executed)
833836
834 self.assertEqual(837 self.assertEqual(
835 [('63,106432,0x0C,*\n106496,,,-', 128, 32, '', tmpfile)],838 [('63,106432,0x0C,*\n106496,,,-', HEADS, SECTORS, '', tmpfile)],
836 sfdisk_fixture.mock.calls)839 sfdisk_fixture.mock.calls)
837840
838 def test_run_sfdisk_commands(self):841 def test_run_sfdisk_commands(self):
@@ -842,7 +845,7 @@
842 stdout=subprocess.PIPE)845 stdout=subprocess.PIPE)
843 proc.communicate()846 proc.communicate()
844 stdout, stderr = run_sfdisk_commands(847 stdout, stderr = run_sfdisk_commands(
845 '2,16063,0xDA', 128, 32, '', tmpfile, as_root=False,848 '2,16063,0xDA', HEADS, SECTORS, '', tmpfile, as_root=False,
846 stderr=subprocess.PIPE)849 stderr=subprocess.PIPE)
847 self.assertIn('Successfully wrote the new partition table', stdout)850 self.assertIn('Successfully wrote the new partition table', stdout)
848851
@@ -851,7 +854,7 @@
851 self.assertRaises(854 self.assertRaises(
852 cmd_runner.SubcommandNonZeroReturnValue,855 cmd_runner.SubcommandNonZeroReturnValue,
853 run_sfdisk_commands,856 run_sfdisk_commands,
854 ',1,0xDA', 128, 32, '', tmpfile, as_root=False,857 ',1,0xDA', HEADS, SECTORS, '', tmpfile, as_root=False,
855 stderr=subprocess.PIPE)858 stderr=subprocess.PIPE)
856859
857860
@@ -929,7 +932,7 @@
929 stdout=subprocess.PIPE)932 stdout=subprocess.PIPE)
930 proc.communicate()933 proc.communicate()
931 stdout, stderr = run_sfdisk_commands(934 stdout, stderr = run_sfdisk_commands(
932 sfdisk_commands, 128, 32, '', tmpfile, as_root=False,935 sfdisk_commands, HEADS, SECTORS, '', tmpfile, as_root=False,
933 # Throw away stderr as sfdisk complains a lot when operating on a936 # Throw away stderr as sfdisk complains a lot when operating on a
934 # qemu image.937 # qemu image.
935 stderr=subprocess.PIPE)938 stderr=subprocess.PIPE)
@@ -1009,8 +1012,8 @@
1009 # This is the call that would create a 2 GiB image file.1012 # This is the call that would create a 2 GiB image file.
1010 ['qemu-img create -f raw %s 2147483648' % tmpfile,1013 ['qemu-img create -f raw %s 2147483648' % tmpfile,
1011 # This call would partition the image file.1014 # This call would partition the image file.
1012 '%s sfdisk --force -D -uS -H 128 -S 32 -C 1024 %s' % (1015 '%s sfdisk --force -D -uS -H %s -S %s -C 1024 %s' % (
1013 sudo_args, tmpfile),1016 sudo_args, HEADS, SECTORS, tmpfile),
1014 # Make sure changes are written to disk.1017 # Make sure changes are written to disk.
1015 'sync',1018 'sync',
1016 '%s mkfs.vfat -F 32 %s -n boot' % (sudo_args, bootfs_dev),1019 '%s mkfs.vfat -F 32 %s -n boot' % (sudo_args, bootfs_dev),
@@ -1036,8 +1039,8 @@
1036 True, True, True)1039 True, True, True)
1037 self.assertEqual(1040 self.assertEqual(
1038 ['%s parted -s %s mklabel msdos' % (sudo_args, tmpfile),1041 ['%s parted -s %s mklabel msdos' % (sudo_args, tmpfile),
1039 '%s sfdisk --force -D -uS -H 128 -S 32 %s' % (1042 '%s sfdisk --force -D -uS -H %s -S %s %s' % (
1040 sudo_args, tmpfile),1043 sudo_args, HEADS, SECTORS, tmpfile),
1041 'sync',1044 'sync',
1042 # Since the partitions are mounted, setup_partitions will umount1045 # Since the partitions are mounted, setup_partitions will umount
1043 # them before running mkfs.1046 # them before running mkfs.

Subscribers

People subscribed via source and target branches