aboutsummaryrefslogtreecommitdiff
path: root/cli/lib/core/image_build_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lib/core/image_build_unittest.py')
-rw-r--r--cli/lib/core/image_build_unittest.py139
1 files changed, 75 insertions, 64 deletions
diff --git a/cli/lib/core/image_build_unittest.py b/cli/lib/core/image_build_unittest.py
index 09bdb8d..1807520 100644
--- a/cli/lib/core/image_build_unittest.py
+++ b/cli/lib/core/image_build_unittest.py
@@ -25,6 +25,7 @@ from bsp import device_stub
from core import image_build
from core import util_stub
from environment import sysroot_stub
+from project import config_stub
from project import dependency
from project import pack
from project import packmap_stub
@@ -40,7 +41,8 @@ class TestData(object):
_BSP_VERSION = '0.1'
_BUILD_TYPE = 'user'
_BRILLO_VERSION = '9.9'
- _CACHE_DIR = '/product/artifacts'
+ _ARTIFACT_CACHE_DIR = '/product/artifacts'
+ _METADATA_CACHE_DIR = '/product/metadata'
_OS_DIR = '/bing/bong'
_PLATFORM_DIR = '/foo/bar'
_PRODUCT_DIR = '/bip/boop'
@@ -57,7 +59,6 @@ class BuildImageBase(TestData):
def setUp(self):
self.stub_os = stubs.StubOs()
- self.stub_fileinput = stubs.StubFileinput()
self.stub_open = stubs.StubOpen(self.stub_os)
self.stub_selinux = policy_stub.StubPolicy()
self.stub_shutil = stubs.StubShutil(self.stub_os)
@@ -65,7 +66,6 @@ class BuildImageBase(TestData):
self.stub_sysroot_generator = sysroot_stub.StubSysrootGenerator()
self.stub_util = util_stub.StubUtil(os_version=self._BRILLO_VERSION)
- image_build.fileinput = self.stub_fileinput
image_build.os = self.stub_os
image_build.open = self.stub_open.open
image_build.policy = self.stub_selinux
@@ -82,6 +82,10 @@ class BuildImageBase(TestData):
product_out_cache=self._PRODUCT_DIR,
os_dir=self._OS_DIR)
self.target = target_stub.StubTarget(platform=self.platform)
+ self.config = config_stub.StubConfig(
+ artifact_cache=self._ARTIFACT_CACHE_DIR,
+ metadata_cache=self._METADATA_CACHE_DIR,
+ output_dir=self._IMAGE_OUT_DIR)
self.product_out_dir = None
self.image_type = None
@@ -103,7 +107,8 @@ class BuildImageBase(TestData):
product_out_dir = self.platform.product_out_cache
self.product_out_dir = product_out_dir
self.stub_os.path.should_be_dir = [
- product_out_dir, self._IMAGE_OUT_DIR, self._CACHE_DIR,
+ product_out_dir, self._IMAGE_OUT_DIR, self._ARTIFACT_CACHE_DIR,
+ self._METADATA_CACHE_DIR,
self.stub_os.path.join(platform_dir, 'host',
self.stub_util.GetHostArch(),
'bin'),
@@ -112,18 +117,20 @@ class BuildImageBase(TestData):
self.stub_os.path.should_be_dir)
# Willing to make an image_build root in the cache dir.
- self.stub_os.should_makedirs = [self._CACHE_DIR]
- # Image_Build root should get system_image_info.txt, and modify it.
- self.stub_fileinput.should_touch = [self.stub_os.path.join(
- self._CACHE_DIR, 'image_info.txt')]
+ self.stub_os.should_makedirs = [] # [self._CACHE_DIR]
+ prebuilt_intermediates = self.stub_os.path.join(
+ self._PRODUCT_DIR, 'obj', 'PACKAGING', 'systemimage_intermediates',
+ 'system_image_info.txt')
+ self.stub_os.path.should_exist.append(prebuilt_intermediates)
+ self.stub_open.files[prebuilt_intermediates] = stubs.StubFile()
expected_call = [
'build_image.py',
- self.stub_os.path.join(self._CACHE_DIR, 'root', image_type),
- self.stub_os.path.join(self._CACHE_DIR, 'image_info.txt'),
+ self.stub_os.path.join(self._ARTIFACT_CACHE_DIR, image_type),
+ self.stub_os.path.join(self._METADATA_CACHE_DIR, 'image_info.txt'),
self.stub_os.path.join(
self._IMAGE_OUT_DIR, '{}.img'.format(image_type)),
- self._CACHE_DIR]
+ self._METADATA_CACHE_DIR]
return expected_call
@@ -143,8 +150,8 @@ class BaseTests(object):
command = self.stub_subprocess.AddCommand()
self.assertEqual(
0,
- image_build.BuildImage(self.image_type, self.platform,
- self._CACHE_DIR, self._IMAGE_OUT_DIR))
+ image_build.BuildImage(self.image_type, self.target,
+ self.config))
command.AssertCallWas(expected_call)
@@ -152,10 +159,8 @@ class BaseTests(object):
"""Tests that the make exit code is returned."""
self.stub_subprocess.AddCommand(ret_code=1)
self.SetupForImageImage_Build()
- self.assertEqual(
- 1,
- image_build.BuildImage(self.image_type, self.platform,
- self._CACHE_DIR, self._IMAGE_OUT_DIR))
+ self.assertEqual(1, image_build.BuildImage(
+ self.image_type, self.target, self.config))
def test_image_missing_paths(self):
self.SetupForImageImage_Build()
@@ -169,15 +174,13 @@ class BaseTests(object):
if directory != self._IMAGE_OUT_DIR:
with self.assertRaises(image_build.PathError):
image_build.BuildImage(
- self.image_type, self.platform,
- self._CACHE_DIR, self._IMAGE_OUT_DIR)
+ self.image_type, self.target, self.config)
else:
self.stub_os.should_makedirs.append(self._IMAGE_OUT_DIR)
self.assertEqual(
0,
- image_build.BuildImage(self.image_type, self.platform,
- self._CACHE_DIR,
- self._IMAGE_OUT_DIR))
+ image_build.BuildImage(self.image_type, self.target,
+ self.config))
# Put it back in.
self.stub_os.path.should_be_dir.append(directory)
@@ -188,8 +191,8 @@ class BaseTests(object):
# Shouldn't reach the linking point.
self.device.should_link_version = None
with self.assertRaises(self.stub_util.HostUnsupportedArchError):
- image_build.BuildImage(self.image_type, self.platform,
- self._CACHE_DIR, self._IMAGE_OUT_DIR)
+ image_build.BuildImage(self.image_type, self.target,
+ self.config)
class BuildUnsupportedImageTest(unittest.TestCase):
@@ -200,7 +203,7 @@ class BuildUnsupportedImageTest(unittest.TestCase):
with self.assertRaises(image_build.ImageTypeError):
# pylint: disable=protected-access
image_build.BuildImage(bt.image_type, bt.target,
- bt._CACHE_DIR, bt._IMAGE_OUT_DIR)
+ bt.config)
class BuildOdmImageTest(BaseTests.BuildImageBaseTest):
@@ -241,9 +244,13 @@ class BuildSystemImageTest(BaseTests.BuildImageBaseTest):
class CreateTargetCacheTest(TestData, unittest.TestCase):
def setUp(self):
- self.spec = project_spec_stub.StubProjectSpec()
+ self.artifact_cache_dir = '/base/path/build_root'
+ self.metadata_cache_dir = '/base/path/metadata'
+ self.config = config_stub.StubConfig(
+ artifact_cache=self.artifact_cache_dir,
+ metadata_cache=self.metadata_cache_dir)
+ self.spec = project_spec_stub.StubProjectSpec(config=self.config)
self.target = None
- self.cache_dir = '/base/path'
p = pack.Pack('my_project', 'main')
self.copy = pack.Copy(p)
@@ -260,18 +267,25 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
image_build.open = self.stub_open.open
image_build.sysroot = self.stub_sysroot_generator
+ metadata_split = self.metadata_cache_dir.split('/')
self.metadata_files = [
- self.stub_os.path.join(self.cache_dir, 'etc'),
- self.cache_dir,
- self.stub_os.path.sep +
- self.cache_dir.split(self.stub_os.path.sep)[1],
- self.stub_os.path.join(self.cache_dir, 'etc', 'fs_config_dirs'),
- self.stub_os.path.join(self.cache_dir, 'etc', 'fs_config_files'),
- self.stub_os.path.join(self.cache_dir, 'file_contexts'),
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc')]
+ # mkdirs will recursively create the rest of the dir.
+ while len(metadata_split) > 1:
+ self.metadata_files.append('/'.join(metadata_split))
+ metadata_split.pop()
+ self.metadata_files += ['/'.join(metadata_split[:i+2]) for i in
+ reversed(range(len(metadata_split)-1))]
+ self.metadata_files += [
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc',
+ 'fs_config_dirs'),
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc',
+ 'fs_config_files'),
+ self.stub_os.path.join(self.metadata_cache_dir, 'file_contexts'),
]
# This always happens unless it fails early.
self.stub_os.should_makedirs += [
- self.stub_os.path.join(self.cache_dir, 'etc')]
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc')]
def tearDown(self):
# Make sure all files are copied.
@@ -284,7 +298,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
target = target_stub.StubTarget(
submap_raises=dependency.Error('dep error'))
with self.assertRaises(dependency.Error):
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
def test_skip_os(self):
p = pack.Pack('brillo.{}'.format(self._BRILLO_VERSION), 'some_os_stuff')
@@ -292,8 +306,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
destinations={'/system/bin/servicemanager': [pack.Copy(p)]})
target = target_stub.StubTarget(submaps=[simple_map])
# sysroot stub will not be touched because the OS will be under /system.
- image_build.CreateTargetCache(self.spec, target, self.cache_dir,
- mountpoint='/odm')
+ image_build.CreateTargetCache(self.spec, target, mountpoint='/odm')
def test_with_os(self):
p = pack.Pack('brillo.{}'.format(self._BRILLO_VERSION), 'some_os_stuff')
@@ -308,8 +321,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(cpy.dst)[1:]]
self.stub_sysroot_generator.should_add_file = [(cpy.src,
cpy.dst.lstrip('/'))]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir,
- mountpoint='/')
+ image_build.CreateTargetCache(self.spec, target, mountpoint='/')
def test_skip_nonmountpoint(self):
self.copy.dst = '/system/bin/xyzzy.txt'
@@ -326,8 +338,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(odm_copy.dst)[1:]]
self.stub_sysroot_generator.should_add_file = [(odm_copy.src,
'odm/bin/xyzzy.txt')]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir,
- mountpoint='/odm')
+ image_build.CreateTargetCache(self.spec, target, mountpoint='/odm')
def test_copy_file_src_file_dst(self):
self.copy.dst = '/system/bin/xyzzy.txt'
@@ -340,16 +351,17 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(self.copy.dst)[1:]]
self.stub_sysroot_generator.should_add_file = [(self.copy.src,
'system/bin/xyzzy.txt')]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
# Ensure the selabel was copied.
file_contexts = self.stub_open.files[
- self.stub_os.path.join(self.cache_dir, 'file_contexts')].contents
+ self.stub_os.path.join(self.metadata_cache_dir,
+ 'file_contexts')].contents
self.assertRegexpMatches(
'\n'.join(file_contexts),
'{}($|\n)'.format(self.copy.acl.file_context()))
# Ensure the ACLs were copied too.
fs_config_files = self.stub_open.files[
- self.stub_os.path.join(self.cache_dir, 'etc',
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc',
'fs_config_files')].contents
self.assertRegexpMatches(
'\n'.join(fs_config_files),
@@ -397,24 +409,23 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
]
# Needed for ensuring fs_config_files appending works.
- existing = self.stub_os.path.join(self.cache_dir, 'root', 'system',
+ existing = self.stub_os.path.join(self.artifact_cache_dir, 'system',
'etc', 'fs_config_files')
self.stub_os.path.should_exist.append(existing)
system_fs_config_files = 'abc123'
self.stub_open.files[existing] = stubs.StubFile(system_fs_config_files)
- existing = self.stub_os.path.join(self.cache_dir, 'root', 'system',
+ existing = self.stub_os.path.join(self.artifact_cache_dir, 'system',
'etc', 'fs_config_dirs')
self.stub_os.path.should_exist.append(existing)
system_fs_config_dirs = '321bca'
self.stub_open.files[existing] = stubs.StubFile(system_fs_config_dirs)
- image_build.CreateTargetCache(self.spec, target, self.cache_dir,
- mountpoint='/')
+ image_build.CreateTargetCache(self.spec, target, mountpoint='/')
# Ensure the ACLs were copied and the system fs_config_* are appended
# to the build-specific changes.
fs_config_files = self.stub_open.files[
- self.stub_os.path.join(self.cache_dir, 'etc',
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc',
'fs_config_files')].contents
self.assertEqual(
['%\x00\x00\x01\xd2\x04\xe1\x10\x00\x00\x00\x00\x00\x00\x00\x00'
@@ -424,7 +435,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
# Ensure that no directory ACLs were implicitly placed on
# system or system/bin/.
fs_config_dirs = self.stub_open.files[
- self.stub_os.path.join(self.cache_dir, 'etc',
+ self.stub_os.path.join(self.metadata_cache_dir, 'etc',
'fs_config_dirs')].contents
self.assertEqual(fs_config_dirs, ['', system_fs_config_dirs])
@@ -441,7 +452,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(self.copy.dst)[1:]]
self.stub_sysroot_generator.should_add_glob = [
(self.copy.src, 'system/bin/', False)]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
def test_copy_glob_recursive(self):
self.copy.src = '/my/bins/*'
@@ -456,7 +467,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(self.copy.dst)[1:]]
self.stub_sysroot_generator.should_add_glob = [
(self.copy.src, 'system/bin/', True)]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
def test_copy_dir(self):
self.copy.src = '/my/etc/'
@@ -471,7 +482,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(self.copy.dst)[1:]]
self.stub_sysroot_generator.should_add_dir = [
(self.copy.src, 'system/etc/', False)]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
def test_copy_dir_recurse(self):
self.copy.src = '/my/etc/'
@@ -486,7 +497,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_os.path.dirname(self.copy.dst)[1:]]
self.stub_sysroot_generator.should_add_dir = [
(self.copy.src, 'system/etc/', True)]
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
def test_copy_invalid_combos(self):
@@ -506,7 +517,7 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
destinations={self.copy.dst: [self.copy]})
target = target_stub.StubTarget(submaps=[simple_map])
with self.assertRaises(image_build.PathError):
- image_build.CreateTargetCache(self.spec, target, self.cache_dir)
+ image_build.CreateTargetCache(self.spec, target)
def test_unmanaged_file(self):
self.copy.dst = '/system/bin/xyzzy.txt'
@@ -519,9 +530,9 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
self.stub_sysroot_generator.should_add_file = [(self.copy.src,
'system/bin/xyzzy.txt')]
self.stub_os.path.should_exist.append(
- '/base/path/root/system/foozle/blag')
- image_build.CreateTargetCache(self.spec, target, self.cache_dir,
- verbose=False)
+ self.stub_os.path.join(self.artifact_cache_dir, 'system', 'foozle',
+ 'blag'))
+ image_build.CreateTargetCache(self.spec, target, verbose=False)
# The metadata files should've been created.
expect_files = self.metadata_files
self.assertEqual(self.stub_os.path.should_exist, expect_files)
@@ -534,11 +545,11 @@ class CreateTargetCacheTest(TestData, unittest.TestCase):
target = target_stub.StubTarget(submaps=[simple_map])
self.stub_sysroot_generator.should_makedirs = [
self.stub_os.path.dirname(self.copy.dst)[1:]]
- self.stub_sysroot_generator.should_add_file = [(self.copy.src,
- 'system/bin/xyzzy.txt')]
+ self.stub_sysroot_generator.should_add_file = [
+ (self.copy.src, 'system/bin/xyzzy.txt')]
self.stub_os.path.should_exist.append(
- '/base/path/root/system/foozle/barzle/blag.mal')
- image_build.CreateTargetCache(self.spec, target, self.cache_dir,
- verbose=False)
+ self.stub_os.path.join(self.artifact_cache_dir, 'system',
+ 'foozle', 'barzle', 'blag.mal'))
+ image_build.CreateTargetCache(self.spec, target, verbose=False)
expect_files = self.metadata_files
self.assertEqual(self.stub_os.path.should_exist, expect_files)