diff options
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 118 |
1 files changed, 93 insertions, 25 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index c8765e5330..9e7be6168e 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
@@ -790,41 +790,50 @@ class Wic2(WicTestCase): | |||
790 | tempf.write("part " \ | 790 | tempf.write("part " \ |
791 | "--source rootfs --ondisk hda --align 4 --fixed-size %d " | 791 | "--source rootfs --ondisk hda --align 4 --fixed-size %d " |
792 | "--fstype=ext4\n" % size) | 792 | "--fstype=ext4\n" % size) |
793 | wksname = os.path.splitext(os.path.basename(wkspath))[0] | ||
794 | 793 | ||
795 | return wkspath, wksname | 794 | return wkspath |
796 | 795 | ||
797 | def test_fixed_size(self): | 796 | def _get_wic_partitions(self, wkspath, native_sysroot=None, ignore_status=False): |
798 | """ | 797 | p = runCmd("wic create %s -e core-image-minimal -o %s" % (wkspath, self.resultdir), |
799 | Test creation of a simple image with partition size controlled through | 798 | ignore_status=ignore_status) |
800 | --fixed-size flag | 799 | |
801 | """ | 800 | if p.status: |
802 | wkspath, wksname = Wic2._make_fixed_size_wks(200) | 801 | return (p, None) |
802 | |||
803 | wksname = os.path.splitext(os.path.basename(wkspath))[0] | ||
803 | 804 | ||
804 | runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
805 | % (wkspath, self.resultdir)) | ||
806 | os.remove(wkspath) | ||
807 | wicout = glob(self.resultdir + "%s-*direct" % wksname) | 805 | wicout = glob(self.resultdir + "%s-*direct" % wksname) |
808 | self.assertEqual(1, len(wicout)) | 806 | |
807 | if not wicout: | ||
808 | return (p, None) | ||
809 | 809 | ||
810 | wicimg = wicout[0] | 810 | wicimg = wicout[0] |
811 | 811 | ||
812 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | 812 | if not native_sysroot: |
813 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | ||
813 | 814 | ||
814 | # verify partition size with wic | 815 | # verify partition size with wic |
815 | res = runCmd("parted -m %s unit mib p 2>/dev/null" % wicimg, | 816 | res = runCmd("parted -m %s unit kib p 2>/dev/null" % wicimg, |
816 | native_sysroot=native_sysroot) | 817 | native_sysroot=native_sysroot) |
817 | 818 | ||
818 | # parse parted output which looks like this: | 819 | # parse parted output which looks like this: |
819 | # BYT;\n | 820 | # BYT;\n |
820 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n | 821 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n |
821 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n | 822 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n |
822 | partlns = res.output.splitlines()[2:] | 823 | return (p, res.output.splitlines()[2:]) |
823 | 824 | ||
824 | self.assertEqual(1, len(partlns), | 825 | def test_fixed_size(self): |
825 | msg="Partition list '%s'" % res.output) | 826 | """ |
826 | self.assertEqual("1:0.00MiB:200MiB:200MiB:ext4::;", partlns[0], | 827 | Test creation of a simple image with partition size controlled through |
827 | msg="Partition list '%s'" % res.output) | 828 | --fixed-size flag |
829 | """ | ||
830 | wkspath = Wic2._make_fixed_size_wks(200) | ||
831 | _, partlns = self._get_wic_partitions(wkspath) | ||
832 | os.remove(wkspath) | ||
833 | |||
834 | self.assertEqual(partlns, [ | ||
835 | "1:4.00kiB:204804kiB:204800kiB:ext4::;", | ||
836 | ]) | ||
828 | 837 | ||
829 | def test_fixed_size_error(self): | 838 | def test_fixed_size_error(self): |
830 | """ | 839 | """ |
@@ -832,13 +841,72 @@ class Wic2(WicTestCase): | |||
832 | --fixed-size flag. The size of partition is intentionally set to 1MiB | 841 | --fixed-size flag. The size of partition is intentionally set to 1MiB |
833 | in order to trigger an error in wic. | 842 | in order to trigger an error in wic. |
834 | """ | 843 | """ |
835 | wkspath, wksname = Wic2._make_fixed_size_wks(1) | 844 | wkspath = Wic2._make_fixed_size_wks(1) |
836 | 845 | p, _ = self._get_wic_partitions(wkspath, ignore_status=True) | |
837 | self.assertEqual(1, runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
838 | % (wkspath, self.resultdir), ignore_status=True).status) | ||
839 | os.remove(wkspath) | 846 | os.remove(wkspath) |
840 | wicout = glob(self.resultdir + "%s-*direct" % wksname) | 847 | |
841 | self.assertEqual(0, len(wicout)) | 848 | self.assertNotEqual(p.status, 0, "wic exited successfully when an error was expected:\n%s" % p.output) |
849 | |||
850 | def test_offset(self): | ||
851 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | ||
852 | |||
853 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
854 | # Test that partitions are placed at the correct offsets, default KB | ||
855 | tempf.write("bootloader --ptable gpt\n" \ | ||
856 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | ||
857 | "part /bar --ondisk hda --offset 102432 --fixed-size 100M --fstype=ext4\n") | ||
858 | tempf.flush() | ||
859 | |||
860 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
861 | self.assertEqual(partlns, [ | ||
862 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | ||
863 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | ||
864 | ]) | ||
865 | |||
866 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
867 | # Test that partitions are placed at the correct offsets, same with explicit KB | ||
868 | tempf.write("bootloader --ptable gpt\n" \ | ||
869 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 100M --fstype=ext4\n" \ | ||
870 | "part /bar --ondisk hda --offset 102432K --fixed-size 100M --fstype=ext4\n") | ||
871 | tempf.flush() | ||
872 | |||
873 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
874 | self.assertEqual(partlns, [ | ||
875 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | ||
876 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | ||
877 | ]) | ||
878 | |||
879 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
880 | # Test that partitions are placed at the correct offsets using MB | ||
881 | tempf.write("bootloader --ptable gpt\n" \ | ||
882 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 100M --fstype=ext4\n" \ | ||
883 | "part /bar --ondisk hda --offset 101M --fixed-size 100M --fstype=ext4\n") | ||
884 | tempf.flush() | ||
885 | |||
886 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
887 | self.assertEqual(partlns, [ | ||
888 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | ||
889 | "2:103424kiB:205824kiB:102400kiB:ext4:primary:;", | ||
890 | ]) | ||
891 | |||
892 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
893 | # Test that image creation fails if the partitions would overlap | ||
894 | tempf.write("bootloader --ptable gpt\n" \ | ||
895 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | ||
896 | "part /bar --ondisk hda --offset 102431 --fixed-size 100M --fstype=ext4\n") | ||
897 | tempf.flush() | ||
898 | |||
899 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) | ||
900 | self.assertNotEqual(p.status, 0, "wic exited successfully when an error was expected:\n%s" % p.output) | ||
901 | |||
902 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
903 | # Test that partitions are not allowed to overlap with the booloader | ||
904 | tempf.write("bootloader --ptable gpt\n" \ | ||
905 | "part / --source rootfs --ondisk hda --offset 8 --fixed-size 100M --fstype=ext4\n") | ||
906 | tempf.flush() | ||
907 | |||
908 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) | ||
909 | self.assertNotEqual(p.status, 0, "wic exited successfully when an error was expected:\n%s" % p.output) | ||
842 | 910 | ||
843 | @only_for_arch(['i586', 'i686', 'x86_64']) | 911 | @only_for_arch(['i586', 'i686', 'x86_64']) |
844 | def test_rawcopy_plugin_qemu(self): | 912 | def test_rawcopy_plugin_qemu(self): |