diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/wic.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 384 |
1 files changed, 315 insertions, 69 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index b616759209..680f99d381 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
@@ -12,6 +12,7 @@ import os | |||
12 | import sys | 12 | import sys |
13 | import unittest | 13 | import unittest |
14 | import hashlib | 14 | import hashlib |
15 | import subprocess | ||
15 | 16 | ||
16 | from glob import glob | 17 | from glob import glob |
17 | from shutil import rmtree, copy | 18 | from shutil import rmtree, copy |
@@ -152,7 +153,7 @@ class Wic(WicTestCase): | |||
152 | # create a temporary file for the WKS content | 153 | # create a temporary file for the WKS content |
153 | with NamedTemporaryFile("w", suffix=".wks") as wks: | 154 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
154 | wks.write( | 155 | wks.write( |
155 | 'part --source bootimg-efi ' | 156 | 'part --source bootimg_efi ' |
156 | '--sourceparams="loader=grub-efi,install-kernel-into-boot-dir=false" ' | 157 | '--sourceparams="loader=grub-efi,install-kernel-into-boot-dir=false" ' |
157 | '--label boot --active\n' | 158 | '--label boot --active\n' |
158 | ) | 159 | ) |
@@ -185,7 +186,7 @@ class Wic(WicTestCase): | |||
185 | # create a temporary file for the WKS content | 186 | # create a temporary file for the WKS content |
186 | with NamedTemporaryFile("w", suffix=".wks") as wks: | 187 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
187 | wks.write( | 188 | wks.write( |
188 | 'part --source bootimg-efi ' | 189 | 'part --source bootimg_efi ' |
189 | '--sourceparams="loader=grub-efi,install-kernel-into-boot-dir=true" ' | 190 | '--sourceparams="loader=grub-efi,install-kernel-into-boot-dir=true" ' |
190 | '--label boot --active\n' | 191 | '--label boot --active\n' |
191 | ) | 192 | ) |
@@ -445,8 +446,9 @@ class Wic(WicTestCase): | |||
445 | wks.write(""" | 446 | wks.write(""" |
446 | part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path usr | 447 | part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path usr |
447 | part /usr --source rootfs --ondisk mmcblk0 --fstype=ext4 --rootfs-dir %s/usr | 448 | part /usr --source rootfs --ondisk mmcblk0 --fstype=ext4 --rootfs-dir %s/usr |
448 | part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --rootfs-dir %s/usr""" | 449 | part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --rootfs-dir %s/usr |
449 | % (rootfs_dir, rootfs_dir)) | 450 | part /mnt --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/whoami --rootfs-dir %s/usr""" |
451 | % (rootfs_dir, rootfs_dir, rootfs_dir)) | ||
450 | runCmd("wic create %s -e core-image-minimal -o %s" \ | 452 | runCmd("wic create %s -e core-image-minimal -o %s" \ |
451 | % (wks_file, self.resultdir)) | 453 | % (wks_file, self.resultdir)) |
452 | 454 | ||
@@ -457,7 +459,7 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r | |||
457 | wicimg = wicout[0] | 459 | wicimg = wicout[0] |
458 | 460 | ||
459 | # verify partition size with wic | 461 | # verify partition size with wic |
460 | res = runCmd("parted -m %s unit b p 2>/dev/null" % wicimg) | 462 | res = runCmd("parted -m %s unit b p" % wicimg, stderr=subprocess.PIPE) |
461 | 463 | ||
462 | # parse parted output which looks like this: | 464 | # parse parted output which looks like this: |
463 | # BYT;\n | 465 | # BYT;\n |
@@ -465,9 +467,9 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r | |||
465 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n | 467 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n |
466 | partlns = res.output.splitlines()[2:] | 468 | partlns = res.output.splitlines()[2:] |
467 | 469 | ||
468 | self.assertEqual(3, len(partlns)) | 470 | self.assertEqual(4, len(partlns)) |
469 | 471 | ||
470 | for part in [1, 2, 3]: | 472 | for part in [1, 2, 3, 4]: |
471 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % part) | 473 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % part) |
472 | partln = partlns[part-1].split(":") | 474 | partln = partlns[part-1].split(":") |
473 | self.assertEqual(7, len(partln)) | 475 | self.assertEqual(7, len(partln)) |
@@ -478,16 +480,16 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r | |||
478 | 480 | ||
479 | # Test partition 1, should contain the normal root directories, except | 481 | # Test partition 1, should contain the normal root directories, except |
480 | # /usr. | 482 | # /usr. |
481 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ | 483 | res = runCmd("debugfs -R 'ls -p' %s" % \ |
482 | os.path.join(self.resultdir, "selftest_img.part1")) | 484 | os.path.join(self.resultdir, "selftest_img.part1"), stderr=subprocess.PIPE) |
483 | files = extract_files(res.output) | 485 | files = extract_files(res.output) |
484 | self.assertIn("etc", files) | 486 | self.assertIn("etc", files) |
485 | self.assertNotIn("usr", files) | 487 | self.assertNotIn("usr", files) |
486 | 488 | ||
487 | # Partition 2, should contain common directories for /usr, not root | 489 | # Partition 2, should contain common directories for /usr, not root |
488 | # directories. | 490 | # directories. |
489 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ | 491 | res = runCmd("debugfs -R 'ls -p' %s" % \ |
490 | os.path.join(self.resultdir, "selftest_img.part2")) | 492 | os.path.join(self.resultdir, "selftest_img.part2"), stderr=subprocess.PIPE) |
491 | files = extract_files(res.output) | 493 | files = extract_files(res.output) |
492 | self.assertNotIn("etc", files) | 494 | self.assertNotIn("etc", files) |
493 | self.assertNotIn("usr", files) | 495 | self.assertNotIn("usr", files) |
@@ -495,27 +497,78 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r | |||
495 | 497 | ||
496 | # Partition 3, should contain the same as partition 2, including the bin | 498 | # Partition 3, should contain the same as partition 2, including the bin |
497 | # directory, but not the files inside it. | 499 | # directory, but not the files inside it. |
498 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ | 500 | res = runCmd("debugfs -R 'ls -p' %s" % \ |
499 | os.path.join(self.resultdir, "selftest_img.part3")) | 501 | os.path.join(self.resultdir, "selftest_img.part3"), stderr=subprocess.PIPE) |
500 | files = extract_files(res.output) | 502 | files = extract_files(res.output) |
501 | self.assertNotIn("etc", files) | 503 | self.assertNotIn("etc", files) |
502 | self.assertNotIn("usr", files) | 504 | self.assertNotIn("usr", files) |
503 | self.assertIn("share", files) | 505 | self.assertIn("share", files) |
504 | self.assertIn("bin", files) | 506 | self.assertIn("bin", files) |
505 | res = runCmd("debugfs -R 'ls -p bin' %s 2>/dev/null" % \ | 507 | res = runCmd("debugfs -R 'ls -p bin' %s" % \ |
506 | os.path.join(self.resultdir, "selftest_img.part3")) | 508 | os.path.join(self.resultdir, "selftest_img.part3"), stderr=subprocess.PIPE) |
507 | files = extract_files(res.output) | 509 | files = extract_files(res.output) |
508 | self.assertIn(".", files) | 510 | self.assertIn(".", files) |
509 | self.assertIn("..", files) | 511 | self.assertIn("..", files) |
510 | self.assertEqual(2, len(files)) | 512 | self.assertEqual(2, len(files)) |
511 | 513 | ||
512 | for part in [1, 2, 3]: | 514 | # Partition 4, should contain the same as partition 2, including the bin |
515 | # directory, but not whoami (a symlink to busybox.nosuid) inside it. | ||
516 | res = runCmd("debugfs -R 'ls -p' %s" % \ | ||
517 | os.path.join(self.resultdir, "selftest_img.part4"), stderr=subprocess.PIPE) | ||
518 | files = extract_files(res.output) | ||
519 | self.assertNotIn("etc", files) | ||
520 | self.assertNotIn("usr", files) | ||
521 | self.assertIn("share", files) | ||
522 | self.assertIn("bin", files) | ||
523 | res = runCmd("debugfs -R 'ls -p bin' %s" % \ | ||
524 | os.path.join(self.resultdir, "selftest_img.part4"), stderr=subprocess.PIPE) | ||
525 | files = extract_files(res.output) | ||
526 | self.assertIn(".", files) | ||
527 | self.assertIn("..", files) | ||
528 | self.assertIn("who", files) | ||
529 | self.assertNotIn("whoami", files) | ||
530 | |||
531 | for part in [1, 2, 3, 4]: | ||
513 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % part) | 532 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % part) |
514 | os.remove(part_file) | 533 | os.remove(part_file) |
515 | 534 | ||
516 | finally: | 535 | finally: |
517 | os.environ['PATH'] = oldpath | 536 | os.environ['PATH'] = oldpath |
518 | 537 | ||
538 | def test_exclude_path_with_extra_space(self): | ||
539 | """Test having --exclude-path with IMAGE_ROOTFS_EXTRA_SPACE. [Yocto #15555]""" | ||
540 | |||
541 | with NamedTemporaryFile("w", suffix=".wks") as wks: | ||
542 | wks.writelines( | ||
543 | ['bootloader --ptable gpt\n', | ||
544 | 'part /boot --size=100M --active --fstype=ext4 --label boot\n', | ||
545 | 'part / --source rootfs --fstype=ext4 --label root --exclude-path boot/\n']) | ||
546 | wks.flush() | ||
547 | config = 'IMAGE_ROOTFS_EXTRA_SPACE = "500000"\n'\ | ||
548 | 'DEPENDS:pn-core-image-minimal += "wic-tools"\n'\ | ||
549 | 'IMAGE_FSTYPES += "wic ext4"\n'\ | ||
550 | 'WKS_FILE = "%s"\n' % wks.name | ||
551 | self.append_config(config) | ||
552 | bitbake('core-image-minimal') | ||
553 | |||
554 | """ | ||
555 | the output of "wic ls <image>.wic" will look something like: | ||
556 | Num Start End Size Fstype | ||
557 | 1 17408 136332287 136314880 ext4 | ||
558 | 2 136332288 171464703 35132416 ext4 | ||
559 | we are looking for the size of partition 2 | ||
560 | i.e. in this case the number 35,132,416 | ||
561 | without the fix the size will be around 85,403,648 | ||
562 | with the fix the size should be around 799,960,064 | ||
563 | """ | ||
564 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE'], 'core-image-minimal') | ||
565 | deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] | ||
566 | machine = bb_vars['MACHINE'] | ||
567 | nativesysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') | ||
568 | wicout = glob(os.path.join(deploy_dir, "core-image-minimal-%s.rootfs-*.wic" % machine))[0] | ||
569 | size_of_root_partition = int(runCmd("wic ls %s --native-sysroot %s" % (wicout, nativesysroot)).output.split('\n')[2].split()[3]) | ||
570 | self.assertGreater(size_of_root_partition, 500000000) | ||
571 | |||
519 | def test_include_path(self): | 572 | def test_include_path(self): |
520 | """Test --include-path wks option.""" | 573 | """Test --include-path wks option.""" |
521 | 574 | ||
@@ -541,13 +594,13 @@ part /part2 --source rootfs --ondisk mmcblk0 --fstype=ext4 --include-path %s""" | |||
541 | part2 = glob(os.path.join(self.resultdir, 'temp-*.direct.p2'))[0] | 594 | part2 = glob(os.path.join(self.resultdir, 'temp-*.direct.p2'))[0] |
542 | 595 | ||
543 | # Test partition 1, should not contain 'test-file' | 596 | # Test partition 1, should not contain 'test-file' |
544 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) | 597 | res = runCmd("debugfs -R 'ls -p' %s" % (part1), stderr=subprocess.PIPE) |
545 | files = extract_files(res.output) | 598 | files = extract_files(res.output) |
546 | self.assertNotIn('test-file', files) | 599 | self.assertNotIn('test-file', files) |
547 | self.assertEqual(True, files_own_by_root(res.output)) | 600 | self.assertEqual(True, files_own_by_root(res.output)) |
548 | 601 | ||
549 | # Test partition 2, should contain 'test-file' | 602 | # Test partition 2, should contain 'test-file' |
550 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part2)) | 603 | res = runCmd("debugfs -R 'ls -p' %s" % (part2), stderr=subprocess.PIPE) |
551 | files = extract_files(res.output) | 604 | files = extract_files(res.output) |
552 | self.assertIn('test-file', files) | 605 | self.assertIn('test-file', files) |
553 | self.assertEqual(True, files_own_by_root(res.output)) | 606 | self.assertEqual(True, files_own_by_root(res.output)) |
@@ -576,12 +629,12 @@ part / --source rootfs --fstype=ext4 --include-path %s --include-path core-imag | |||
576 | 629 | ||
577 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] | 630 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] |
578 | 631 | ||
579 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) | 632 | res = runCmd("debugfs -R 'ls -p' %s" % (part1), stderr=subprocess.PIPE) |
580 | files = extract_files(res.output) | 633 | files = extract_files(res.output) |
581 | self.assertIn('test-file', files) | 634 | self.assertIn('test-file', files) |
582 | self.assertEqual(True, files_own_by_root(res.output)) | 635 | self.assertEqual(True, files_own_by_root(res.output)) |
583 | 636 | ||
584 | res = runCmd("debugfs -R 'ls -p /export/etc/' %s 2>/dev/null" % (part1)) | 637 | res = runCmd("debugfs -R 'ls -p /export/etc/' %s" % (part1), stderr=subprocess.PIPE) |
585 | files = extract_files(res.output) | 638 | files = extract_files(res.output) |
586 | self.assertIn('passwd', files) | 639 | self.assertIn('passwd', files) |
587 | self.assertEqual(True, files_own_by_root(res.output)) | 640 | self.assertEqual(True, files_own_by_root(res.output)) |
@@ -668,7 +721,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc | |||
668 | % (wks_file, self.resultdir)) | 721 | % (wks_file, self.resultdir)) |
669 | 722 | ||
670 | for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')): | 723 | for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')): |
671 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) | 724 | res = runCmd("debugfs -R 'ls -p' %s" % (part), stderr=subprocess.PIPE) |
672 | self.assertEqual(True, files_own_by_root(res.output)) | 725 | self.assertEqual(True, files_own_by_root(res.output)) |
673 | 726 | ||
674 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "%s"\n' % wks_file | 727 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "%s"\n' % wks_file |
@@ -678,7 +731,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc | |||
678 | 731 | ||
679 | # check each partition for permission | 732 | # check each partition for permission |
680 | for part in glob(os.path.join(tmpdir, 'temp-*.direct.p*')): | 733 | for part in glob(os.path.join(tmpdir, 'temp-*.direct.p*')): |
681 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) | 734 | res = runCmd("debugfs -R 'ls -p' %s" % (part), stderr=subprocess.PIPE) |
682 | self.assertTrue(files_own_by_root(res.output) | 735 | self.assertTrue(files_own_by_root(res.output) |
683 | ,msg='Files permission incorrect using wks set "%s"' % test) | 736 | ,msg='Files permission incorrect using wks set "%s"' % test) |
684 | 737 | ||
@@ -706,7 +759,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc | |||
706 | 759 | ||
707 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] | 760 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] |
708 | 761 | ||
709 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) | 762 | res = runCmd("debugfs -R 'ls -p' %s" % (part1), stderr=subprocess.PIPE) |
710 | files = extract_files(res.output) | 763 | files = extract_files(res.output) |
711 | self.assertIn('passwd', files) | 764 | self.assertIn('passwd', files) |
712 | 765 | ||
@@ -741,7 +794,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc | |||
741 | bitbake('base-files -c do_install') | 794 | bitbake('base-files -c do_install') |
742 | bf_fstab = os.path.join(get_bb_var('D', 'base-files'), 'etc', 'fstab') | 795 | bf_fstab = os.path.join(get_bb_var('D', 'base-files'), 'etc', 'fstab') |
743 | self.assertEqual(True, os.path.exists(bf_fstab)) | 796 | self.assertEqual(True, os.path.exists(bf_fstab)) |
744 | bf_fstab_md5sum = runCmd('md5sum %s 2>/dev/null' % bf_fstab).output.split(" ")[0] | 797 | bf_fstab_md5sum = runCmd('md5sum %s ' % bf_fstab).output.split(" ")[0] |
745 | 798 | ||
746 | try: | 799 | try: |
747 | no_fstab_update_path = os.path.join(self.resultdir, 'test-no-fstab-update') | 800 | no_fstab_update_path = os.path.join(self.resultdir, 'test-no-fstab-update') |
@@ -757,7 +810,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc | |||
757 | part_fstab_md5sum = [] | 810 | part_fstab_md5sum = [] |
758 | for i in range(1, 3): | 811 | for i in range(1, 3): |
759 | part = glob(os.path.join(self.resultdir, 'temp-*.direct.p') + str(i))[0] | 812 | part = glob(os.path.join(self.resultdir, 'temp-*.direct.p') + str(i))[0] |
760 | part_fstab = runCmd("debugfs -R 'cat etc/fstab' %s 2>/dev/null" % (part)) | 813 | part_fstab = runCmd("debugfs -R 'cat etc/fstab' %s" % (part), stderr=subprocess.PIPE) |
761 | part_fstab_md5sum.append(hashlib.md5((part_fstab.output + "\n\n").encode('utf-8')).hexdigest()) | 814 | part_fstab_md5sum.append(hashlib.md5((part_fstab.output + "\n\n").encode('utf-8')).hexdigest()) |
762 | 815 | ||
763 | # '/etc/fstab' in partition 2 should contain the same stock fstab file | 816 | # '/etc/fstab' in partition 2 should contain the same stock fstab file |
@@ -839,6 +892,61 @@ bootloader --ptable gpt""") | |||
839 | finally: | 892 | finally: |
840 | os.remove(wks_file) | 893 | os.remove(wks_file) |
841 | 894 | ||
895 | def test_wic_sector_size(self): | ||
896 | """Test generation image sector size""" | ||
897 | |||
898 | oldpath = os.environ['PATH'] | ||
899 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") | ||
900 | |||
901 | try: | ||
902 | # Add WIC_SECTOR_SIZE into config | ||
903 | config = 'WIC_SECTOR_SIZE = "4096"\n'\ | ||
904 | 'WICVARS:append = " WIC_SECTOR_SIZE"\n' | ||
905 | self.append_config(config) | ||
906 | bitbake('core-image-minimal') | ||
907 | |||
908 | # Check WIC_SECTOR_SIZE apply to bitbake variable | ||
909 | wic_sector_size_str = get_bb_var('WIC_SECTOR_SIZE', 'core-image-minimal') | ||
910 | wic_sector_size = int(wic_sector_size_str) | ||
911 | self.assertEqual(4096, wic_sector_size) | ||
912 | |||
913 | self.logger.info("Test wic_sector_size: %d \n" % wic_sector_size) | ||
914 | |||
915 | with NamedTemporaryFile("w", suffix=".wks") as wks: | ||
916 | wks.writelines( | ||
917 | ['bootloader --ptable gpt\n', | ||
918 | 'part --fstype ext4 --source rootfs --label rofs-a --mkfs-extraopts "-b 4096"\n', | ||
919 | 'part --fstype ext4 --source rootfs --use-uuid --mkfs-extraopts "-b 4096"\n']) | ||
920 | wks.flush() | ||
921 | cmd = "wic create %s -e core-image-minimal -o %s" % (wks.name, self.resultdir) | ||
922 | runCmd(cmd) | ||
923 | wksname = os.path.splitext(os.path.basename(wks.name))[0] | ||
924 | images = glob(os.path.join(self.resultdir, "%s-*direct" % wksname)) | ||
925 | self.assertEqual(1, len(images)) | ||
926 | |||
927 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') | ||
928 | # list partitions | ||
929 | result = runCmd("wic ls %s -n %s" % (images[0], sysroot)) | ||
930 | self.assertEqual(3, len(result.output.split('\n'))) | ||
931 | |||
932 | # verify partition size with wic | ||
933 | res = runCmd("export PARTED_SECTOR_SIZE=%d; parted -m %s unit b p" % (wic_sector_size, images[0]), | ||
934 | stderr=subprocess.PIPE) | ||
935 | |||
936 | # parse parted output which looks like this: | ||
937 | # BYT;\n | ||
938 | # /var/tmp/wic/build/tmpgjzzefdd-202410281021-sda.direct:78569472B:file:4096:4096:gpt::;\n | ||
939 | # 1:139264B:39284735B:39145472B:ext4:rofs-a:;\n | ||
940 | # 2:39284736B:78430207B:39145472B:ext4:primary:;\n | ||
941 | disk_info = res.output.splitlines()[1] | ||
942 | # Check sector sizes | ||
943 | sector_size_logical = int(disk_info.split(":")[3]) | ||
944 | sector_size_physical = int(disk_info.split(":")[4]) | ||
945 | self.assertEqual(wic_sector_size, sector_size_logical, "Logical sector size is not %d." % wic_sector_size) | ||
946 | self.assertEqual(wic_sector_size, sector_size_physical, "Physical sector size is not %d." % wic_sector_size) | ||
947 | |||
948 | finally: | ||
949 | os.environ['PATH'] = oldpath | ||
842 | 950 | ||
843 | class Wic2(WicTestCase): | 951 | class Wic2(WicTestCase): |
844 | 952 | ||
@@ -913,6 +1021,18 @@ class Wic2(WicTestCase): | |||
913 | """Test building wic images by bitbake""" | 1021 | """Test building wic images by bitbake""" |
914 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ | 1022 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ |
915 | 'MACHINE_FEATURES:append = " efi"\n' | 1023 | 'MACHINE_FEATURES:append = " efi"\n' |
1024 | image_recipe_append = """ | ||
1025 | do_image_wic[postfuncs] += "run_wic_cmd" | ||
1026 | run_wic_cmd() { | ||
1027 | echo "test" >> ${WORKDIR}/test.wic-cp | ||
1028 | wic cp --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${WORKDIR}/test.wic-cp ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/ | ||
1029 | wic ls --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/ | ||
1030 | wic rm --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/test.wic-cp | ||
1031 | wic cp --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${WORKDIR}/test.wic-cp ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/ | ||
1032 | } | ||
1033 | """ | ||
1034 | self.write_recipeinc('images', image_recipe_append) | ||
1035 | |||
916 | self.append_config(config) | 1036 | self.append_config(config) |
917 | image = 'wic-image-minimal' | 1037 | image = 'wic-image-minimal' |
918 | bitbake(image) | 1038 | bitbake(image) |
@@ -921,6 +1041,11 @@ class Wic2(WicTestCase): | |||
921 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image) | 1041 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image) |
922 | prefix = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.' % bb_vars['IMAGE_LINK_NAME']) | 1042 | prefix = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.' % bb_vars['IMAGE_LINK_NAME']) |
923 | 1043 | ||
1044 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') | ||
1045 | # check if file is there | ||
1046 | result = runCmd("wic ls %s:1/ -n %s" % (prefix+"wic", sysroot)) | ||
1047 | self.assertIn("test.wic-cp", result.output) | ||
1048 | |||
924 | # check if we have result image and manifests symlinks | 1049 | # check if we have result image and manifests symlinks |
925 | # pointing to existing files | 1050 | # pointing to existing files |
926 | for suffix in ('wic', 'manifest'): | 1051 | for suffix in ('wic', 'manifest'): |
@@ -936,10 +1061,29 @@ class Wic2(WicTestCase): | |||
936 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ | 1061 | config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ |
937 | 'MACHINE_FEATURES:append = " efi"\n' | 1062 | 'MACHINE_FEATURES:append = " efi"\n' |
938 | self.append_config(config) | 1063 | self.append_config(config) |
1064 | image_recipe_append = """ | ||
1065 | do_image_wic[postfuncs] += "run_wic_cmd" | ||
1066 | run_wic_cmd() { | ||
1067 | echo "test" >> ${WORKDIR}/test.wic-cp | ||
1068 | wic cp --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${WORKDIR}/test.wic-cp ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/ | ||
1069 | wic ls --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/ | ||
1070 | wic rm --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/test.wic-cp | ||
1071 | wic cp --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" ${WORKDIR}/test.wic-cp ${IMGDEPLOYDIR}/${IMAGE_NAME}.wic:1/ | ||
1072 | } | ||
1073 | """ | ||
1074 | self.write_recipeinc('images', image_recipe_append) | ||
939 | bitbake('wic-image-minimal') | 1075 | bitbake('wic-image-minimal') |
1076 | |||
1077 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') | ||
1078 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], "wic-image-minimal") | ||
1079 | image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], bb_vars['IMAGE_LINK_NAME']) | ||
1080 | # check if file is there | ||
1081 | result = runCmd("wic ls %s:1/ -n %s" % (image_path+".wic", sysroot)) | ||
1082 | self.assertIn("test.wic-cp", result.output) | ||
940 | self.remove_config(config) | 1083 | self.remove_config(config) |
941 | 1084 | ||
942 | with runqemu('wic-image-minimal', ssh=False, runqemuparams='nographic') as qemu: | 1085 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'wic-image-minimal') or "" |
1086 | with runqemu('wic-image-minimal', ssh=False, runqemuparams='%s nographic' % (runqemu_params)) as qemu: | ||
943 | cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' " \ | 1087 | cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' " \ |
944 | "-e '/dev/root /|/dev/sda2 /' -e '/dev/sda3 /media' -e '/dev/sda4 /mnt'" | 1088 | "-e '/dev/root /|/dev/sda2 /' -e '/dev/sda3 /media' -e '/dev/sda4 /mnt'" |
945 | status, output = qemu.run_serial(cmd) | 1089 | status, output = qemu.run_serial(cmd) |
@@ -959,8 +1103,9 @@ class Wic2(WicTestCase): | |||
959 | bitbake('core-image-minimal ovmf') | 1103 | bitbake('core-image-minimal ovmf') |
960 | self.remove_config(config) | 1104 | self.remove_config(config) |
961 | 1105 | ||
1106 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-minimal') or "" | ||
962 | with runqemu('core-image-minimal', ssh=False, | 1107 | with runqemu('core-image-minimal', ssh=False, |
963 | runqemuparams='nographic ovmf', image_fstype='wic') as qemu: | 1108 | runqemuparams='%s nographic ovmf' % (runqemu_params), image_fstype='wic') as qemu: |
964 | cmd = "grep sda. /proc/partitions |wc -l" | 1109 | cmd = "grep sda. /proc/partitions |wc -l" |
965 | status, output = qemu.run_serial(cmd) | 1110 | status, output = qemu.run_serial(cmd) |
966 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1111 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
@@ -1000,8 +1145,8 @@ class Wic2(WicTestCase): | |||
1000 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | 1145 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
1001 | 1146 | ||
1002 | # verify partition size with wic | 1147 | # verify partition size with wic |
1003 | res = runCmd("parted -m %s unit kib p 2>/dev/null" % wicimg, | 1148 | res = runCmd("parted -m %s unit kib p" % wicimg, |
1004 | native_sysroot=native_sysroot) | 1149 | native_sysroot=native_sysroot, stderr=subprocess.PIPE) |
1005 | 1150 | ||
1006 | # parse parted output which looks like this: | 1151 | # parse parted output which looks like this: |
1007 | # BYT;\n | 1152 | # BYT;\n |
@@ -1040,71 +1185,71 @@ class Wic2(WicTestCase): | |||
1040 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1185 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1041 | # Test that partitions are placed at the correct offsets, default KB | 1186 | # Test that partitions are placed at the correct offsets, default KB |
1042 | tempf.write("bootloader --ptable gpt\n" \ | 1187 | tempf.write("bootloader --ptable gpt\n" \ |
1043 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | 1188 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 200M --fstype=ext4\n" \ |
1044 | "part /bar --ondisk hda --offset 102432 --fixed-size 100M --fstype=ext4\n") | 1189 | "part /bar --ondisk hda --offset 204832 --fixed-size 100M --fstype=ext4\n") |
1045 | tempf.flush() | 1190 | tempf.flush() |
1046 | 1191 | ||
1047 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | 1192 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) |
1048 | self.assertEqual(partlns, [ | 1193 | self.assertEqual(partlns, [ |
1049 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | 1194 | "1:32.0kiB:204832kiB:204800kiB:ext4:primary:;", |
1050 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | 1195 | "2:204832kiB:307232kiB:102400kiB:ext4:primary:;", |
1051 | ]) | 1196 | ]) |
1052 | 1197 | ||
1053 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1198 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1054 | # Test that partitions are placed at the correct offsets, same with explicit KB | 1199 | # Test that partitions are placed at the correct offsets, same with explicit KB |
1055 | tempf.write("bootloader --ptable gpt\n" \ | 1200 | tempf.write("bootloader --ptable gpt\n" \ |
1056 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 100M --fstype=ext4\n" \ | 1201 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 200M --fstype=ext4\n" \ |
1057 | "part /bar --ondisk hda --offset 102432K --fixed-size 100M --fstype=ext4\n") | 1202 | "part /bar --ondisk hda --offset 204832K --fixed-size 100M --fstype=ext4\n") |
1058 | tempf.flush() | 1203 | tempf.flush() |
1059 | 1204 | ||
1060 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | 1205 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) |
1061 | self.assertEqual(partlns, [ | 1206 | self.assertEqual(partlns, [ |
1062 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | 1207 | "1:32.0kiB:204832kiB:204800kiB:ext4:primary:;", |
1063 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | 1208 | "2:204832kiB:307232kiB:102400kiB:ext4:primary:;", |
1064 | ]) | 1209 | ]) |
1065 | 1210 | ||
1066 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1211 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1067 | # Test that partitions are placed at the correct offsets using MB | 1212 | # Test that partitions are placed at the correct offsets using MB |
1068 | tempf.write("bootloader --ptable gpt\n" \ | 1213 | tempf.write("bootloader --ptable gpt\n" \ |
1069 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 100M --fstype=ext4\n" \ | 1214 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 200M --fstype=ext4\n" \ |
1070 | "part /bar --ondisk hda --offset 101M --fixed-size 100M --fstype=ext4\n") | 1215 | "part /bar --ondisk hda --offset 201M --fixed-size 100M --fstype=ext4\n") |
1071 | tempf.flush() | 1216 | tempf.flush() |
1072 | 1217 | ||
1073 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | 1218 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) |
1074 | self.assertEqual(partlns, [ | 1219 | self.assertEqual(partlns, [ |
1075 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | 1220 | "1:32.0kiB:204832kiB:204800kiB:ext4:primary:;", |
1076 | "2:103424kiB:205824kiB:102400kiB:ext4:primary:;", | 1221 | "2:205824kiB:308224kiB:102400kiB:ext4:primary:;", |
1077 | ]) | 1222 | ]) |
1078 | 1223 | ||
1079 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1224 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1080 | # Test that partitions can be placed on a 512 byte sector boundary | 1225 | # Test that partitions can be placed on a 512 byte sector boundary |
1081 | tempf.write("bootloader --ptable gpt\n" \ | 1226 | tempf.write("bootloader --ptable gpt\n" \ |
1082 | "part / --source rootfs --ondisk hda --offset 65s --fixed-size 99M --fstype=ext4\n" \ | 1227 | "part / --source rootfs --ondisk hda --offset 65s --fixed-size 199M --fstype=ext4\n" \ |
1083 | "part /bar --ondisk hda --offset 102432 --fixed-size 100M --fstype=ext4\n") | 1228 | "part /bar --ondisk hda --offset 204832 --fixed-size 100M --fstype=ext4\n") |
1084 | tempf.flush() | 1229 | tempf.flush() |
1085 | 1230 | ||
1086 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | 1231 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) |
1087 | self.assertEqual(partlns, [ | 1232 | self.assertEqual(partlns, [ |
1088 | "1:32.5kiB:101408kiB:101376kiB:ext4:primary:;", | 1233 | "1:32.5kiB:203808kiB:203776kiB:ext4:primary:;", |
1089 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | 1234 | "2:204832kiB:307232kiB:102400kiB:ext4:primary:;", |
1090 | ]) | 1235 | ]) |
1091 | 1236 | ||
1092 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1237 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1093 | # Test that a partition can be placed immediately after a MSDOS partition table | 1238 | # Test that a partition can be placed immediately after a MSDOS partition table |
1094 | tempf.write("bootloader --ptable msdos\n" \ | 1239 | tempf.write("bootloader --ptable msdos\n" \ |
1095 | "part / --source rootfs --ondisk hda --offset 1s --fixed-size 100M --fstype=ext4\n") | 1240 | "part / --source rootfs --ondisk hda --offset 1s --fixed-size 200M --fstype=ext4\n") |
1096 | tempf.flush() | 1241 | tempf.flush() |
1097 | 1242 | ||
1098 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | 1243 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) |
1099 | self.assertEqual(partlns, [ | 1244 | self.assertEqual(partlns, [ |
1100 | "1:0.50kiB:102400kiB:102400kiB:ext4::;", | 1245 | "1:0.50kiB:204800kiB:204800kiB:ext4::;", |
1101 | ]) | 1246 | ]) |
1102 | 1247 | ||
1103 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1248 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1104 | # Test that image creation fails if the partitions would overlap | 1249 | # Test that image creation fails if the partitions would overlap |
1105 | tempf.write("bootloader --ptable gpt\n" \ | 1250 | tempf.write("bootloader --ptable gpt\n" \ |
1106 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | 1251 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 200M --fstype=ext4\n" \ |
1107 | "part /bar --ondisk hda --offset 102431 --fixed-size 100M --fstype=ext4\n") | 1252 | "part /bar --ondisk hda --offset 204831 --fixed-size 100M --fstype=ext4\n") |
1108 | tempf.flush() | 1253 | tempf.flush() |
1109 | 1254 | ||
1110 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) | 1255 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) |
@@ -1113,7 +1258,7 @@ class Wic2(WicTestCase): | |||
1113 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1258 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1114 | # Test that partitions are not allowed to overlap with the booloader | 1259 | # Test that partitions are not allowed to overlap with the booloader |
1115 | tempf.write("bootloader --ptable gpt\n" \ | 1260 | tempf.write("bootloader --ptable gpt\n" \ |
1116 | "part / --source rootfs --ondisk hda --offset 8 --fixed-size 100M --fstype=ext4\n") | 1261 | "part / --source rootfs --ondisk hda --offset 8 --fixed-size 200M --fstype=ext4\n") |
1117 | tempf.flush() | 1262 | tempf.flush() |
1118 | 1263 | ||
1119 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) | 1264 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) |
@@ -1154,8 +1299,9 @@ class Wic2(WicTestCase): | |||
1154 | bitbake('core-image-minimal-mtdutils') | 1299 | bitbake('core-image-minimal-mtdutils') |
1155 | self.remove_config(config) | 1300 | self.remove_config(config) |
1156 | 1301 | ||
1302 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-minimal-mtdutils') or "" | ||
1157 | with runqemu('core-image-minimal-mtdutils', ssh=False, | 1303 | with runqemu('core-image-minimal-mtdutils', ssh=False, |
1158 | runqemuparams='nographic', image_fstype='wic') as qemu: | 1304 | runqemuparams='%s nographic' % (runqemu_params), image_fstype='wic') as qemu: |
1159 | cmd = "grep sda. /proc/partitions |wc -l" | 1305 | cmd = "grep sda. /proc/partitions |wc -l" |
1160 | status, output = qemu.run_serial(cmd) | 1306 | status, output = qemu.run_serial(cmd) |
1161 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1307 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
@@ -1177,6 +1323,10 @@ class Wic2(WicTestCase): | |||
1177 | self.assertEqual(1, len(out)) | 1323 | self.assertEqual(1, len(out)) |
1178 | 1324 | ||
1179 | def test_rawcopy_plugin(self): | 1325 | def test_rawcopy_plugin(self): |
1326 | config = 'IMAGE_FSTYPES = "ext4"\n' | ||
1327 | self.append_config(config) | ||
1328 | self.assertEqual(0, bitbake('core-image-minimal').status) | ||
1329 | self.remove_config(config) | ||
1180 | self._rawcopy_plugin('ext4') | 1330 | self._rawcopy_plugin('ext4') |
1181 | 1331 | ||
1182 | def test_rawcopy_plugin_unpack(self): | 1332 | def test_rawcopy_plugin_unpack(self): |
@@ -1214,8 +1364,9 @@ class Wic2(WicTestCase): | |||
1214 | bitbake('core-image-minimal') | 1364 | bitbake('core-image-minimal') |
1215 | self.remove_config(config) | 1365 | self.remove_config(config) |
1216 | 1366 | ||
1367 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-minimal') or "" | ||
1217 | with runqemu('core-image-minimal', ssh=False, | 1368 | with runqemu('core-image-minimal', ssh=False, |
1218 | runqemuparams='nographic', image_fstype='wic') as qemu: | 1369 | runqemuparams='%s nographic' % (runqemu_params), image_fstype='wic') as qemu: |
1219 | # Check that we have ONLY two /dev/sda* partitions (/boot and /) | 1370 | # Check that we have ONLY two /dev/sda* partitions (/boot and /) |
1220 | cmd = "grep sda. /proc/partitions | wc -l" | 1371 | cmd = "grep sda. /proc/partitions | wc -l" |
1221 | status, output = qemu.run_serial(cmd) | 1372 | status, output = qemu.run_serial(cmd) |
@@ -1242,7 +1393,7 @@ class Wic2(WicTestCase): | |||
1242 | def test_biosplusefi_plugin(self): | 1393 | def test_biosplusefi_plugin(self): |
1243 | """Test biosplusefi plugin""" | 1394 | """Test biosplusefi plugin""" |
1244 | # Wic generation below may fail depending on the order of the unittests | 1395 | # Wic generation below may fail depending on the order of the unittests |
1245 | # This is because bootimg-pcbios (that bootimg-biosplusefi uses) generate its MBR inside STAGING_DATADIR directory | 1396 | # This is because bootimg_pcbios (that bootimg_biosplusefi uses) generate its MBR inside STAGING_DATADIR directory |
1246 | # which may or may not exists depending on what was built already | 1397 | # which may or may not exists depending on what was built already |
1247 | # If an image hasn't been built yet, directory ${STAGING_DATADIR}/syslinux won't exists and _get_bootimg_dir() | 1398 | # If an image hasn't been built yet, directory ${STAGING_DATADIR}/syslinux won't exists and _get_bootimg_dir() |
1248 | # will raise with "Couldn't find correct bootimg_dir" | 1399 | # will raise with "Couldn't find correct bootimg_dir" |
@@ -1254,7 +1405,7 @@ class Wic2(WicTestCase): | |||
1254 | 1405 | ||
1255 | img = 'core-image-minimal' | 1406 | img = 'core-image-minimal' |
1256 | with NamedTemporaryFile("w", suffix=".wks") as wks: | 1407 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
1257 | wks.writelines(['part /boot --active --source bootimg-biosplusefi --sourceparams="loader=grub-efi"\n', | 1408 | wks.writelines(['part /boot --active --source bootimg_biosplusefi --sourceparams="loader=grub-efi"\n', |
1258 | 'part / --source rootfs --fstype=ext4 --align 1024 --use-uuid\n'\ | 1409 | 'part / --source rootfs --fstype=ext4 --align 1024 --use-uuid\n'\ |
1259 | 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n']) | 1410 | 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n']) |
1260 | wks.flush() | 1411 | wks.flush() |
@@ -1274,7 +1425,7 @@ class Wic2(WicTestCase): | |||
1274 | 1425 | ||
1275 | img = 'core-image-minimal' | 1426 | img = 'core-image-minimal' |
1276 | with NamedTemporaryFile("w", suffix=".wks") as wks: | 1427 | with NamedTemporaryFile("w", suffix=".wks") as wks: |
1277 | wks.writelines(['part /boot --source bootimg-efi --sourceparams="loader=uefi-kernel"\n' | 1428 | wks.writelines(['part /boot --source bootimg_efi --sourceparams="loader=uefi-kernel"\n' |
1278 | 'part / --source rootfs --fstype=ext4 --align 1024 --use-uuid\n'\ | 1429 | 'part / --source rootfs --fstype=ext4 --align 1024 --use-uuid\n'\ |
1279 | 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n']) | 1430 | 'bootloader --timeout=0 --append="console=ttyS0,115200n8"\n']) |
1280 | wks.flush() | 1431 | wks.flush() |
@@ -1288,24 +1439,45 @@ class Wic2(WicTestCase): | |||
1288 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | 1439 | @skipIfNotArch(['i586', 'i686', 'x86_64']) |
1289 | @OETestTag("runqemu") | 1440 | @OETestTag("runqemu") |
1290 | def test_efi_plugin_unified_kernel_image_qemu(self): | 1441 | def test_efi_plugin_unified_kernel_image_qemu(self): |
1291 | """Test efi plugin's Unified Kernel Image feature in qemu""" | 1442 | """Test Unified Kernel Image feature in qemu without systemd in initramfs or rootfs""" |
1292 | config = 'IMAGE_FSTYPES = "wic"\n'\ | 1443 | config = """ |
1293 | 'INITRAMFS_IMAGE = "core-image-minimal-initramfs"\n'\ | 1444 | # efi firmware must load systemd-boot, not grub |
1294 | 'WKS_FILE = "test_efi_plugin.wks"\n'\ | 1445 | EFI_PROVIDER = "systemd-boot" |
1295 | 'MACHINE_FEATURES:append = " efi"\n' | 1446 | |
1447 | # image format must be wic, needs esp partition for firmware etc | ||
1448 | IMAGE_FSTYPES:pn-core-image-base:append = " wic" | ||
1449 | WKS_FILE = "test_efi_plugin.wks" | ||
1450 | |||
1451 | # efi, uki and systemd features must be enabled | ||
1452 | MACHINE_FEATURES:append = " efi" | ||
1453 | IMAGE_CLASSES:append:pn-core-image-base = " uki" | ||
1454 | |||
1455 | # uki embeds also an initrd, no systemd or udev | ||
1456 | INITRAMFS_IMAGE = "core-image-initramfs-boot" | ||
1457 | |||
1458 | # runqemu must not load kernel separately, it's in the uki | ||
1459 | QB_KERNEL_ROOT = "" | ||
1460 | QB_DEFAULT_KERNEL = "none" | ||
1461 | |||
1462 | # boot command line provided via uki, not via bootloader | ||
1463 | UKI_CMDLINE = "rootwait root=LABEL=root console=${KERNEL_CONSOLE}" | ||
1464 | |||
1465 | """ | ||
1296 | self.append_config(config) | 1466 | self.append_config(config) |
1297 | bitbake('core-image-minimal core-image-minimal-initramfs ovmf') | 1467 | bitbake('core-image-base ovmf') |
1468 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-base') or "" | ||
1469 | uki_filename = get_bb_var('UKI_FILENAME', 'core-image-base') | ||
1298 | self.remove_config(config) | 1470 | self.remove_config(config) |
1299 | 1471 | ||
1300 | with runqemu('core-image-minimal', ssh=False, | 1472 | with runqemu('core-image-base', ssh=False, |
1301 | runqemuparams='nographic ovmf', image_fstype='wic') as qemu: | 1473 | runqemuparams='%s nographic ovmf' % (runqemu_params), image_fstype='wic') as qemu: |
1302 | # Check that /boot has EFI bootx64.efi (required for EFI) | 1474 | # Check that /boot has EFI boot*.efi (required for EFI) |
1303 | cmd = "ls /boot/EFI/BOOT/bootx64.efi | wc -l" | 1475 | cmd = "ls /boot/EFI/BOOT/boot*.efi | wc -l" |
1304 | status, output = qemu.run_serial(cmd) | 1476 | status, output = qemu.run_serial(cmd) |
1305 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1477 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
1306 | self.assertEqual(output, '1') | 1478 | self.assertEqual(output, '1') |
1307 | # Check that /boot has EFI/Linux/linux.efi (required for Unified Kernel Images auto detection) | 1479 | # Check that /boot has EFI/Linux/${UKI_FILENAME} (required for Unified Kernel Images auto detection) |
1308 | cmd = "ls /boot/EFI/Linux/linux.efi | wc -l" | 1480 | cmd = "ls /boot/EFI/Linux/%s | wc -l" % (uki_filename) |
1309 | status, output = qemu.run_serial(cmd) | 1481 | status, output = qemu.run_serial(cmd) |
1310 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1482 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
1311 | self.assertEqual(output, '1') | 1483 | self.assertEqual(output, '1') |
@@ -1315,6 +1487,80 @@ class Wic2(WicTestCase): | |||
1315 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1487 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
1316 | self.assertEqual(output, '0') | 1488 | self.assertEqual(output, '0') |
1317 | 1489 | ||
1490 | @skipIfNotArch(['aarch64']) | ||
1491 | @OETestTag("runqemu") | ||
1492 | def test_efi_plugin_plain_systemd_boot_qemu_aarch64(self): | ||
1493 | """Test plain systemd-boot in qemu with systemd""" | ||
1494 | config = """ | ||
1495 | INIT_MANAGER = "systemd" | ||
1496 | EFI_PROVIDER = "systemd-boot" | ||
1497 | |||
1498 | # image format must be wic, needs esp partition for firmware etc | ||
1499 | IMAGE_FSTYPES:pn-core-image-base:append = " wic" | ||
1500 | WKS_FILE = "test_efi_plugin_plain_systemd-boot.wks" | ||
1501 | |||
1502 | INITRAMFS_IMAGE = "core-image-initramfs-boot" | ||
1503 | |||
1504 | # to configure runqemu | ||
1505 | IMAGE_CLASSES += "qemuboot" | ||
1506 | # u-boot efi firmware | ||
1507 | QB_DEFAULT_BIOS = "u-boot.bin" | ||
1508 | # need to use virtio, scsi not supported by u-boot by default | ||
1509 | QB_DRIVE_TYPE = "/dev/vd" | ||
1510 | |||
1511 | # disable kvm, breaks boot | ||
1512 | QEMU_USE_KVM = "" | ||
1513 | |||
1514 | IMAGE_CLASSES:remove = 'testimage' | ||
1515 | """ | ||
1516 | self.append_config(config) | ||
1517 | bitbake('core-image-base u-boot') | ||
1518 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-base') or "" | ||
1519 | |||
1520 | with runqemu('core-image-base', ssh=False, | ||
1521 | runqemuparams='%s nographic' % (runqemu_params), image_fstype='wic') as qemu: | ||
1522 | # Check that /boot has EFI boot*.efi (required for EFI) | ||
1523 | cmd = "ls /boot/EFI/BOOT/boot*.efi | wc -l" | ||
1524 | status, output = qemu.run_serial(cmd) | ||
1525 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
1526 | self.assertEqual(output, '1') | ||
1527 | # Check that boot.conf exists | ||
1528 | cmd = "cat /boot/loader/entries/boot.conf" | ||
1529 | status, output = qemu.run_serial(cmd) | ||
1530 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
1531 | self.remove_config(config) | ||
1532 | |||
1533 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | ||
1534 | @OETestTag("runqemu") | ||
1535 | def test_efi_plugin_plain_systemd_boot_qemu_x86(self): | ||
1536 | """Test plain systemd-boot to systemd in qemu""" | ||
1537 | config = """ | ||
1538 | INIT_MANAGER = "systemd" | ||
1539 | EFI_PROVIDER = "systemd-boot" | ||
1540 | |||
1541 | # image format must be wic, needs esp partition for firmware etc | ||
1542 | IMAGE_FSTYPES:pn-core-image-base:append = " wic" | ||
1543 | WKS_FILE = "test_efi_plugin_plain_systemd-boot.wks" | ||
1544 | |||
1545 | INITRAMFS_IMAGE = "core-image-initramfs-boot" | ||
1546 | """ | ||
1547 | self.append_config(config) | ||
1548 | bitbake('core-image-base ovmf') | ||
1549 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-base') or "" | ||
1550 | self.remove_config(config) | ||
1551 | |||
1552 | with runqemu('core-image-base', ssh=False, | ||
1553 | runqemuparams='%s nographic ovmf' % (runqemu_params), image_fstype='wic') as qemu: | ||
1554 | # Check that /boot has EFI boot*.efi (required for EFI) | ||
1555 | cmd = "ls /boot/EFI/BOOT/boot*.efi | wc -l" | ||
1556 | status, output = qemu.run_serial(cmd) | ||
1557 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
1558 | self.assertEqual(output, '1') | ||
1559 | # Check that boot.conf exists | ||
1560 | cmd = "cat /boot/loader/entries/boot.conf" | ||
1561 | status, output = qemu.run_serial(cmd) | ||
1562 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
1563 | |||
1318 | def test_fs_types(self): | 1564 | def test_fs_types(self): |
1319 | """Test filesystem types for empty and not empty partitions""" | 1565 | """Test filesystem types for empty and not empty partitions""" |
1320 | img = 'core-image-minimal' | 1566 | img = 'core-image-minimal' |
@@ -1446,8 +1692,8 @@ class Wic2(WicTestCase): | |||
1446 | os.rename(image_path, image_path + '.bak') | 1692 | os.rename(image_path, image_path + '.bak') |
1447 | os.rename(new_image_path, image_path) | 1693 | os.rename(new_image_path, image_path) |
1448 | 1694 | ||
1449 | # Check if it boots in qemu | 1695 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-minimal') or "" |
1450 | with runqemu('core-image-minimal', ssh=False, runqemuparams='nographic') as qemu: | 1696 | with runqemu('core-image-minimal', ssh=False, runqemuparams='%s nographic' % (runqemu_params)) as qemu: |
1451 | cmd = "ls /etc/" | 1697 | cmd = "ls /etc/" |
1452 | status, output = qemu.run_serial('true') | 1698 | status, output = qemu.run_serial('true') |
1453 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1699 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |