From a285dac7bc99f2ad4a8ff3debcdd0d48d4fc22f8 Mon Sep 17 00:00:00 2001 From: Adrian Freihofer Date: Thu, 4 Jul 2024 09:09:41 +0200 Subject: oe-selftest: fitimage fix test_initramfs_bundle It looks like most of the assertions of this tests were by-passed because of combinations of invalid regexes and inverted assert statement. Try to fix. Use the variables from the kernel recipe instead of potentially invalid values from get_bb_vars with undefined recipe. Use one get_bb_vars statement instead of many seaparate calls mainly to improve the duration of this test case. Make the test working for an its file with an absolute path to the kernel binary. This will be needed with one of the following commits and does not harm in general. (From OE-Core rev: 741f0cfa4f0025a2823581cab09e0bf14382e54d) Signed-off-by: Adrian Freihofer Signed-off-by: Richard Purdie --- meta/lib/oeqa/selftest/cases/fitimage.py | 57 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'meta/lib') diff --git a/meta/lib/oeqa/selftest/cases/fitimage.py b/meta/lib/oeqa/selftest/cases/fitimage.py index ee688c7909..0b5f4602fb 100644 --- a/meta/lib/oeqa/selftest/cases/fitimage.py +++ b/meta/lib/oeqa/selftest/cases/fitimage.py @@ -774,23 +774,25 @@ FIT_HASH_ALG = "sha256" # fitImage is created as part of linux recipe bitbake("virtual/kernel") - image_type = get_bb_var('INITRAMFS_IMAGE') - deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') - machine = get_bb_var('MACHINE') - fitimage_its_path = os.path.join(deploy_dir_image, - "fitImage-its-%s-%s-%s" % (image_type, machine, machine)) - fitimage_path = os.path.join(deploy_dir_image,"fitImage") + bb_vars = get_bb_vars([ + 'DEPLOY_DIR_IMAGE', + 'FIT_HASH_ALG', + 'FIT_KERNEL_COMP_ALG', + 'INITRAMFS_IMAGE', + 'MACHINE', + 'UBOOT_ARCH', + 'UBOOT_ENTRYPOINT', + 'UBOOT_LOADADDRESS', + 'UBOOT_MKIMAGE_KERNEL_TYPE' + ], + 'virtual/kernel') + fitimage_its_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], + "fitImage-its-%s-%s-%s" % (bb_vars['INITRAMFS_IMAGE'], bb_vars['MACHINE'], bb_vars['MACHINE'])) + fitimage_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'],"fitImage") self.assertExists(fitimage_its_path, "%s image tree source doesn't exist" % (fitimage_its_path)) self.assertExists(fitimage_path, "%s FIT image doesn't exist" % (fitimage_path)) - kernel_load = str(get_bb_var('UBOOT_LOADADDRESS')) - kernel_entry = str(get_bb_var('UBOOT_ENTRYPOINT')) - kernel_type = str(get_bb_var('UBOOT_MKIMAGE_KERNEL_TYPE')) - kernel_compression = str(get_bb_var('FIT_KERNEL_COMP_ALG')) - uboot_arch = str(get_bb_var('UBOOT_ARCH')) - fit_hash_alg = str(get_bb_var('FIT_HASH_ALG')) - its_file = open(fitimage_its_path) its_lines = [line.strip() for line in its_file.readlines()] @@ -799,14 +801,14 @@ FIT_HASH_ALG = "sha256" 'kernel-1 {', 'description = "Linux kernel";', 'data = /incbin/("linux.bin");', - 'type = "' + kernel_type + '";', - 'arch = "' + uboot_arch + '";', + 'type = "' + str(bb_vars['UBOOT_MKIMAGE_KERNEL_TYPE']) + '";', + 'arch = "' + str(bb_vars['UBOOT_ARCH']) + '";', 'os = "linux";', - 'compression = "' + kernel_compression + '";', - 'load = <' + kernel_load + '>;', - 'entry = <' + kernel_entry + '>;', + 'compression = "' + str(bb_vars['FIT_KERNEL_COMP_ALG']) + '";', + 'load = <' + str(bb_vars['UBOOT_LOADADDRESS']) + '>;', + 'entry = <' + str(bb_vars['UBOOT_ENTRYPOINT']) + '>;', 'hash-1 {', - 'algo = "' + fit_hash_alg +'";', + 'algo = "' + str(bb_vars['FIT_HASH_ALG']) +'";', '};', '};' ] @@ -818,6 +820,11 @@ FIT_HASH_ALG = "sha256" node_start_idx = its_lines.index(node_str) node = its_lines[node_start_idx:(node_start_idx + len(exp_node_lines))] + + # Remove the absolute path. This refers to WORKDIR which is not always predictable. + re_data = re.compile(r'^data = /incbin/\(.*/linux\.bin"\);$') + node = [re.sub(re_data, 'data = /incbin/("linux.bin");', cfg_str) for cfg_str in node] + self.assertEqual(node, exp_node_lines, "kernel node does not match expectation") rx_configs = re.compile("^conf-.*") @@ -834,14 +841,14 @@ FIT_HASH_ALG = "sha256" node = its_lines[cfg_start_idx:line_idx] print("checking configuration " + cfg_str.rstrip(" {")) - rx_desc_line = re.compile("^description.*1 Linux kernel.*") - self.assertNotEqual(len(list(filter(rx_desc_line.match, node))), 1, "kernel keyword not found in the description line") + rx_desc_line = re.compile(r'^description = ".*Linux kernel.*') + self.assertEqual(len(list(filter(rx_desc_line.match, node))), 1, "kernel keyword not found in the description line") - self.assertNotIn('kernel = "kernel-1";', node) + self.assertIn('kernel = "kernel-1";', node) - rx_sign_line = re.compile("^sign-images.*kernel.*") - self.assertNotEqual(len(list(filter(rx_sign_line.match, node))), 1, "kernel hash not signed") + rx_sign_line = re.compile(r'^sign-images = .*kernel.*') + self.assertEqual(len(list(filter(rx_sign_line.match, node))), 1, "kernel hash not signed") # Verify the signature uboot_tools_sysroot_native = self._setup_uboot_tools_native() - self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, os.path.join(deploy_dir_image, 'am335x-bone.dtb')) + self._verify_fit_image_signature(uboot_tools_sysroot_native, fitimage_path, os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], 'am335x-bone.dtb')) -- cgit v1.2.3-54-g00ecf