blob: 79cc8a0f2e8934b62248739d8c8df6205da30f94 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import os
6
7from oeqa.selftest.case import OESelftestTestCase
8from oeqa.utils.commands import bitbake, get_bb_vars, runCmd
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009
10# This test builds an image with using the "container" IMAGE_FSTYPE, and
11# ensures that then files in the image are only the ones expected.
12#
13# The only package added to the image is container_image_testpkg, which
14# contains one file. However, due to some other things not cleaning up during
15# rootfs creation, there is some cruft. Ideally bugs will be filed and the
16# cruft removed, but for now we whitelist some known set.
17#
18# Also for performance reasons we're only checking the cruft when using ipk.
19# When using deb, and rpm it is a bit different and we could test all
20# of them, but this test is more to catch if other packages get added by
21# default other than what is in ROOTFS_BOOTSTRAP_INSTALL.
22#
23class ContainerImageTests(OESelftestTestCase):
24
25 # Verify that when specifying a IMAGE_TYPEDEP_ of the form "foo.bar" that
26 # the conversion type bar gets added as a dep as well
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027 def test_expected_files(self):
28
29 def get_each_path_part(path):
30 if path:
31 part = [ '.' + path + '/' ]
32 result = get_each_path_part(path.rsplit('/', 1)[0])
33 if result:
34 return part + result
35 else:
36 return part
37 else:
38 return None
39
40 self.write_config("""PREFERRED_PROVIDER_virtual/kernel = "linux-dummy"
41IMAGE_FSTYPES = "container"
42PACKAGE_CLASSES = "package_ipk"
43IMAGE_FEATURES = ""
Brad Bishopf86d0552018-12-04 14:18:15 -080044IMAGE_BUILDINFO_FILE = ""
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050045INIT_MANAGER = "sysvinit"
46IMAGE_INSTALL_remove = "ssh-pregen-hostkeys"
47
Brad Bishopd7bf8c12018-02-25 22:55:05 -050048""")
49
50 bbvars = get_bb_vars(['bindir', 'sysconfdir', 'localstatedir',
51 'DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'],
52 target='container-test-image')
53 expected_files = [
54 './',
55 '.{bindir}/theapp',
56 '.{sysconfdir}/default/',
57 '.{sysconfdir}/default/postinst',
58 '.{sysconfdir}/ld.so.cache',
59 '.{sysconfdir}/timestamp',
60 '.{sysconfdir}/version',
61 './run/',
62 '.{localstatedir}/cache/',
Andrew Geissler09209ee2020-12-13 08:44:15 -060063 '.{localstatedir}/lib/'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064 ]
65
66 expected_files = [ x.format(bindir=bbvars['bindir'],
67 sysconfdir=bbvars['sysconfdir'],
68 localstatedir=bbvars['localstatedir'])
69 for x in expected_files ]
70
71 # Since tar lists all directories individually, make sure each element
72 # from bindir, sysconfdir, etc is added
73 expected_files += get_each_path_part(bbvars['bindir'])
74 expected_files += get_each_path_part(bbvars['sysconfdir'])
75 expected_files += get_each_path_part(bbvars['localstatedir'])
76
77 expected_files = sorted(expected_files)
78
79 # Build the image of course
80 bitbake('container-test-image')
81
82 image = os.path.join(bbvars['DEPLOY_DIR_IMAGE'],
83 bbvars['IMAGE_LINK_NAME'] + '.tar.bz2')
84
85 # Ensure the files in the image are what we expect
86 result = runCmd("tar tf {} | sort".format(image), shell=True)
87 self.assertEqual(result.output.split('\n'), expected_files)