blob: c0998e319e0eb40b4515c41a22a2c3d946d4f0e4 [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 = ""
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045""")
46
47 bbvars = get_bb_vars(['bindir', 'sysconfdir', 'localstatedir',
48 'DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'],
49 target='container-test-image')
50 expected_files = [
51 './',
52 '.{bindir}/theapp',
53 '.{sysconfdir}/default/',
54 '.{sysconfdir}/default/postinst',
55 '.{sysconfdir}/ld.so.cache',
56 '.{sysconfdir}/timestamp',
57 '.{sysconfdir}/version',
58 './run/',
59 '.{localstatedir}/cache/',
60 '.{localstatedir}/cache/ldconfig/',
61 '.{localstatedir}/cache/ldconfig/aux-cache',
62 '.{localstatedir}/cache/opkg/',
63 '.{localstatedir}/lib/',
64 '.{localstatedir}/lib/opkg/'
65 ]
66
67 expected_files = [ x.format(bindir=bbvars['bindir'],
68 sysconfdir=bbvars['sysconfdir'],
69 localstatedir=bbvars['localstatedir'])
70 for x in expected_files ]
71
72 # Since tar lists all directories individually, make sure each element
73 # from bindir, sysconfdir, etc is added
74 expected_files += get_each_path_part(bbvars['bindir'])
75 expected_files += get_each_path_part(bbvars['sysconfdir'])
76 expected_files += get_each_path_part(bbvars['localstatedir'])
77
78 expected_files = sorted(expected_files)
79
80 # Build the image of course
81 bitbake('container-test-image')
82
83 image = os.path.join(bbvars['DEPLOY_DIR_IMAGE'],
84 bbvars['IMAGE_LINK_NAME'] + '.tar.bz2')
85
86 # Ensure the files in the image are what we expect
87 result = runCmd("tar tf {} | sort".format(image), shell=True)
88 self.assertEqual(result.output.split('\n'), expected_files)