Current efi capsule python tests have much code duplication.
This commit creates the common function
in test/py/tests/test_efi_capsule/capsule_common.py,
aim to reduce the code size and improve maintainability.
Signed-off-by: Masahisa Kojima
---
Newly created in v7
.../tests/test_efi_capsule/capsule_common.py | 86 +++
.../test_capsule_firmware_fit.py | 151 +++-
.../test_capsule_firmware_raw.py | 224 +++---
.../test_capsule_firmware_signed_fit.py | 198 +++-
.../test_capsule_firmware_signed_raw.py | 210 +++-
5 files changed, 231 insertions(+), 638 deletions(-)
create mode 100644 test/py/tests/test_efi_capsule/capsule_common.py
diff --git a/test/py/tests/test_efi_capsule/capsule_common.py
b/test/py/tests/test_efi_capsule/capsule_common.py
new file mode 100644
index 00..a460cfd4c2
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/capsule_common.py
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2023, Linaro Limited
+
+
+"""Common function for UEFI capsule test."""
+
+from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+
+def setup(u_boot_console, disk_img, osindications):
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'printenv -e PlatformLangCodes', # workaround for terminal size
determination
+'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
+'efidebug boot order 1',
+'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x10
0x5;u-boot-env raw 0x15 0x20"'])
+
+if osindications is None:
+output = u_boot_console.run_command('env set -e OsIndications')
+else:
+output = u_boot_console.run_command('env set -e -nv -bs -rt
OsIndications =%s' % osindications)
+
+output = u_boot_console.run_command('env save')
+
+def init_content(u_boot_console, target, filename, expected):
+output = u_boot_console.run_command_list([
+'sf probe 0:0',
+'fatload host 0:1 400 %s/%s'
+% (CAPSULE_DATA_DIR, filename),
+'sf write 400 %s 10' % target,
+'sf read 500 10 10',
+'md.b 500 10'])
+assert expected in ''.join(output)
+
+def place_capsule_file(u_boot_console, filenames):
+for name in filenames:
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 %s/%s' % (CAPSULE_DATA_DIR, name),
+'fatwrite host 0:1 400 %s/%s $filesize'
+% (CAPSULE_INSTALL_DIR, name)])
+
+output = u_boot_console.run_command('fatls host 0:1 %s' %
CAPSULE_INSTALL_DIR)
+for name in filenames:
+assert name in ''.join(output)
+
+def exec_manual_update(u_boot_console, disk_img, filenames, need_reboot =
True):
+# make sure that dfu_alt_info exists even persistent variables
+# are not available.
+output = u_boot_console.run_command_list([
+'env set dfu_alt_info '
+'"sf 0:0=u-boot-bin raw 0x10 0x5;'
+'u-boot-env raw 0x15 0x20"',
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+for name in filenames:
+assert name in ''.join(output)
+
+# need to run uefi command to initiate capsule handling
+output = u_boot_console.run_command(
+'env print -e Capsule', wait_for_reboot = need_reboot)
+
+def check_file_removed(u_boot_console, disk_img, filenames):
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+for name in filenames:
+assert name not in ''.join(output)
+
+def check_file_exist(u_boot_console, disk_img, filenames):
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+for name in filenames:
+assert name in ''.join(output)
+
+def verify_content(u_boot_console, target, expected):
+output = u_boot_console.run_command_list([
+'sf probe 0:0',
+'sf read 400 %s 10' % target,
+'md.b 400 10'])
+assert expected in ''.join(output)
+
+def do_reboot_dtb_specified(u_boot_config, u_boot_console, dtb_filename):
+mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
+u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
++ '/%s' % dtb_filename
+u_boot_console.restart_uboot()
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
index 9ee152818d..fccf1f3fc1 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
@@ -8,7 +8,14 @@ This test verifies capsule-on-disk firmware update for FIT
images
import pytest
from capsule_defs import CAPSULE_DATA_DIR, CAPSUL