aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-04-06 14:58:49 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-11 18:10:49 +0100
commit88701cef6ba399e82f96ed1b0eef9a44ed8c1687 (patch)
tree564b54f67f21930cdf9627f9a1366028f7fad330
parent3f1f42984021d87ac43aaa16f38b706c2c965e02 (diff)
downloadopenembedded-core-contrib-88701cef6ba399e82f96ed1b0eef9a44ed8c1687.tar.gz
openembedded-core-contrib-88701cef6ba399e82f96ed1b0eef9a44ed8c1687.tar.bz2
openembedded-core-contrib-88701cef6ba399e82f96ed1b0eef9a44ed8c1687.zip
oe-selftest: test wic sparse_copy API
Added new parameter 'api' to sparse_copy function to specify underlying filemap API to use. By default sparse_copy will try both available APIs. Added test case for sparse_copy to wic test suite. Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/wic.py29
-rw-r--r--scripts/lib/wic/filemap.py6
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 @@
"""Test cases for wic."""
import os
+import sys
import unittest
from glob import glob
@@ -761,3 +762,31 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
self.assertEqual(0, runCmd(cmd).status)
self.remove_config(config)
self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct")))
+
+ def test_sparse_copy(self):
+ """Test sparse_copy with FIEMAP and SEEK_HOLE filemap APIs"""
+ libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'wic')
+ sys.path.insert(0, libpath)
+ from filemap import FilemapFiemap, FilemapSeek, sparse_copy, ErrorNotSupp
+ with NamedTemporaryFile("w", suffix=".wic-sparse") as sparse:
+ src_name = sparse.name
+ src_size = 1024 * 10
+ sparse.truncate(src_size)
+ # write one byte to the file
+ with open(src_name, 'r+b') as sfile:
+ sfile.seek(1024 * 4)
+ sfile.write(b'\x00')
+ dest = sparse.name + '.out'
+ # copy src file to dest using different filemap APIs
+ for api in (FilemapFiemap, FilemapSeek, None):
+ if os.path.exists(dest):
+ os.unlink(dest)
+ try:
+ sparse_copy(sparse.name, dest, api=api)
+ except ErrorNotSupp:
+ continue # skip unsupported API
+ dest_stat = os.stat(dest)
+ self.assertEqual(dest_stat.st_size, src_size)
+ # 8 blocks is 4K (physical sector size)
+ self.assertEqual(dest_stat.st_blocks, 8)
+ 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):
except ErrorNotSupp:
return FilemapSeek(image, log)
-def sparse_copy(src_fname, dst_fname, offset=0, skip=0):
+def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None):
"""Efficiently copy sparse file to or into another file."""
- fmap = filemap(src_fname)
+ if not api:
+ api = filemap
+ fmap = api(src_fname)
try:
dst_file = open(dst_fname, 'r+b')
except IOError: