diff options
| -rw-r--r-- | meta/lib/oeqa/selftest/wic.py | 29 | ||||
| -rw-r--r-- | scripts/lib/wic/filemap.py | 6 |
2 files changed, 33 insertions, 2 deletions
diff --git a/meta/lib/oeqa/selftest/wic.py b/meta/lib/oeqa/selftest/wic.py index 8030c35117..c1ff512f81 100644 --- a/meta/lib/oeqa/selftest/wic.py +++ b/meta/lib/oeqa/selftest/wic.py | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | """Test cases for wic.""" | 24 | """Test cases for wic.""" |
| 25 | 25 | ||
| 26 | import os | 26 | import os |
| 27 | import sys | ||
| 27 | import unittest | 28 | import unittest |
| 28 | 29 | ||
| 29 | from glob import glob | 30 | from glob import glob |
| @@ -761,3 +762,31 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r | |||
| 761 | self.assertEqual(0, runCmd(cmd).status) | 762 | self.assertEqual(0, runCmd(cmd).status) |
| 762 | self.remove_config(config) | 763 | self.remove_config(config) |
| 763 | self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct"))) | 764 | self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct"))) |
| 765 | |||
| 766 | def test_sparse_copy(self): | ||
| 767 | """Test sparse_copy with FIEMAP and SEEK_HOLE filemap APIs""" | ||
| 768 | libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'wic') | ||
| 769 | sys.path.insert(0, libpath) | ||
| 770 | from filemap import FilemapFiemap, FilemapSeek, sparse_copy, ErrorNotSupp | ||
| 771 | with NamedTemporaryFile("w", suffix=".wic-sparse") as sparse: | ||
| 772 | src_name = sparse.name | ||
| 773 | src_size = 1024 * 10 | ||
| 774 | sparse.truncate(src_size) | ||
| 775 | # write one byte to the file | ||
| 776 | with open(src_name, 'r+b') as sfile: | ||
| 777 | sfile.seek(1024 * 4) | ||
| 778 | sfile.write(b'\x00') | ||
| 779 | dest = sparse.name + '.out' | ||
| 780 | # copy src file to dest using different filemap APIs | ||
| 781 | for api in (FilemapFiemap, FilemapSeek, None): | ||
| 782 | if os.path.exists(dest): | ||
| 783 | os.unlink(dest) | ||
| 784 | try: | ||
| 785 | sparse_copy(sparse.name, dest, api=api) | ||
| 786 | except ErrorNotSupp: | ||
| 787 | continue # skip unsupported API | ||
| 788 | dest_stat = os.stat(dest) | ||
| 789 | self.assertEqual(dest_stat.st_size, src_size) | ||
| 790 | # 8 blocks is 4K (physical sector size) | ||
| 791 | self.assertEqual(dest_stat.st_blocks, 8) | ||
| 792 | os.unlink(dest) | ||
diff --git a/scripts/lib/wic/filemap.py b/scripts/lib/wic/filemap.py index 080668e7c2..1f1aacc522 100644 --- a/scripts/lib/wic/filemap.py +++ b/scripts/lib/wic/filemap.py | |||
| @@ -530,9 +530,11 @@ def filemap(image, log=None): | |||
| 530 | except ErrorNotSupp: | 530 | except ErrorNotSupp: |
| 531 | return FilemapSeek(image, log) | 531 | return FilemapSeek(image, log) |
| 532 | 532 | ||
| 533 | def sparse_copy(src_fname, dst_fname, offset=0, skip=0): | 533 | def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None): |
| 534 | """Efficiently copy sparse file to or into another file.""" | 534 | """Efficiently copy sparse file to or into another file.""" |
| 535 | fmap = filemap(src_fname) | 535 | if not api: |
| 536 | api = filemap | ||
| 537 | fmap = api(src_fname) | ||
| 536 | try: | 538 | try: |
| 537 | dst_file = open(dst_fname, 'r+b') | 539 | dst_file = open(dst_fname, 'r+b') |
| 538 | except IOError: | 540 | except IOError: |
