
From: Simon Glass <sjg@chromium.org> Pass in the two fixtures this function actually requires, rather than ubman, which is a function-scoped fixture. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/py/tests/test_android/test_abootimg.py | 37 +++++++------- test/py/tests/test_ut.py | 54 ++++++++++++--------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py index 2aadb692b30..750fa12c56b 100644 --- a/test/py/tests/test_android/test_abootimg.py +++ b/test/py/tests/test_android/test_abootimg.py @@ -102,43 +102,43 @@ dtb1_addr = loadaddr + dtb1_offset # DTB #2 start address in RAM dtb2_addr = vloadaddr + dtb2_offset -class AbootimgTestDiskImage(object): +class AbootimgTestDiskImage(): """Disk image used by abootimg tests.""" - def __init__(self, ubman, image_name, hex_img): + def __init__(self, config, log, image_name, hex_img): """Initialize a new AbootimgDiskImage object. Args: - ubman: A U-Boot console. + config (ArbitraryAttributeContainer): Configuration Returns: Nothing. """ - gz_hex = ubman.config.persistent_data_dir + '/' + image_name + '.gz.hex' - gz = ubman.config.persistent_data_dir + '/' + image_name + '.gz' + gz_hex = config.persistent_data_dir + '/' + image_name + '.gz.hex' + gz = config.persistent_data_dir + '/' + image_name + '.gz' filename = image_name - persistent = ubman.config.persistent_data_dir + '/' + filename - self.path = ubman.config.result_dir + '/' + filename - ubman.log.action('persistent is ' + persistent) - with utils.persistent_file_helper(ubman.log, persistent): + persistent = config.persistent_data_dir + '/' + filename + self.path = config.result_dir + '/' + filename + log.action('persistent is ' + persistent) + with utils.persistent_file_helper(log, persistent): if os.path.exists(persistent): - ubman.log.action('Disk image file ' + persistent + + log.action('Disk image file ' + persistent + ' already exists') else: - ubman.log.action('Generating ' + persistent) + log.action('Generating ' + persistent) f = open(gz_hex, "w") f.write(hex_img) f.close() cmd = ('xxd', '-r', '-p', gz_hex, gz) - utils.run_and_log(ubman, cmd) + utils.run_and_log_no_ubman(log, cmd) cmd = ('gunzip', '-9', gz) - utils.run_and_log(ubman, cmd) + utils.run_and_log_no_ubman(log, cmd) cmd = ('cp', persistent, self.path) - utils.run_and_log(ubman, cmd) + utils.run_and_log_no_ubman(log, cmd) gtdi1 = None @pytest.fixture(scope='function') @@ -150,7 +150,8 @@ def abootimg_disk_image(ubman): global gtdi1 if not gtdi1: - gtdi1 = AbootimgTestDiskImage(ubman, 'boot.img', img_hex) + gtdi1 = AbootimgTestDiskImage(ubman.config, ubman.log, 'boot.img', + img_hex) return gtdi1 gtdi2 = None @@ -163,7 +164,8 @@ def abootimgv4_disk_image_vboot(ubman): global gtdi2 if not gtdi2: - gtdi2 = AbootimgTestDiskImage(ubman, 'vendor_boot.img', vboot_img_hex) + gtdi2 = AbootimgTestDiskImage(ubman.config, ubman.log, + 'vendor_boot.img', vboot_img_hex) return gtdi2 gtdi3 = None @@ -176,7 +178,8 @@ def abootimgv4_disk_image_boot(ubman): global gtdi3 if not gtdi3: - gtdi3 = AbootimgTestDiskImage(ubman, 'bootv4.img', boot_img_hex) + gtdi3 = AbootimgTestDiskImage(ubman.config, ubman.log, 'bootv4.img', + boot_img_hex) return gtdi3 @pytest.mark.boardspec('sandbox') diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 186cb9f864c..e93f1cbf123 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -427,8 +427,13 @@ def setup_cros_image(config, log): return fname -def setup_android_image(ubman): - """Create a 20MB disk image with Android partitions""" +def setup_android_image(config, log): + """Create a 20MB disk image with Android partitions + + Args: + config (ArbitraryAttributeContainer): Configuration + log (multiplexed_log.Logfile): Log to write to + """ Partition = collections.namedtuple('part', 'start,size,name') parts = {} disk_data = None @@ -448,9 +453,9 @@ def setup_android_image(ubman): disk_data = disk_data[:start] + data + disk_data[start + len(data):] mmc_dev = 7 - fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') - utils.run_and_log(ubman, f'qemu-img create {fname} 20M') - utils.run_and_log(ubman, f'cgpt create {fname}') + fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') + utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') + utils.run_and_log_no_ubman(log, f'cgpt create {fname}') ptr = 40 @@ -472,13 +477,13 @@ def setup_android_image(ubman): size = int(size_str[:-1]) * sect_1mb else: size = int(size_str) - utils.run_and_log( - ubman, + utils.run_and_log_no_ubman( + log, f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") ptr += size - utils.run_and_log(ubman, f'cgpt boot -p {fname}') - out = utils.run_and_log(ubman, f'cgpt show -q {fname}') + utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') + out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') # Create a dict (indexed by partition number) containing the above info for line in out.splitlines(): @@ -488,13 +493,15 @@ def setup_android_image(ubman): with open(fname, 'rb') as inf: disk_data = inf.read() - test_abootimg.AbootimgTestDiskImage(ubman, 'bootv4.img', test_abootimg.boot_img_hex) - boot_img = os.path.join(ubman.config.result_dir, 'bootv4.img') + test_abootimg.AbootimgTestDiskImage(config, log, 'bootv4.img', + test_abootimg.boot_img_hex) + boot_img = os.path.join(config.result_dir, 'bootv4.img') with open(boot_img, 'rb') as inf: set_part_data(2, inf.read()) - test_abootimg.AbootimgTestDiskImage(ubman, 'vendor_boot.img', test_abootimg.vboot_img_hex) - vendor_boot_img = os.path.join(ubman.config.result_dir, 'vendor_boot.img') + test_abootimg.AbootimgTestDiskImage(config, log, 'vendor_boot.img', + test_abootimg.vboot_img_hex) + vendor_boot_img = os.path.join(config.result_dir, 'vendor_boot.img') with open(vendor_boot_img, 'rb') as inf: set_part_data(4, inf.read()) @@ -504,9 +511,9 @@ def setup_android_image(ubman): print(f'wrote to {fname}') mmc_dev = 8 - fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') - utils.run_and_log(ubman, f'qemu-img create {fname} 20M') - utils.run_and_log(ubman, f'cgpt create {fname}') + fname = os.path.join(config.source_dir, f'mmc{mmc_dev}.img') + utils.run_and_log_no_ubman(log, f'qemu-img create {fname} 20M') + utils.run_and_log_no_ubman(log, f'cgpt create {fname}') ptr = 40 @@ -526,13 +533,13 @@ def setup_android_image(ubman): size = int(size_str[:-1]) * sect_1mb else: size = int(size_str) - utils.run_and_log( - ubman, + utils.run_and_log_no_ubman( + log, f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") ptr += size - utils.run_and_log(ubman, f'cgpt boot -p {fname}') - out = utils.run_and_log(ubman, f'cgpt show -q {fname}') + utils.run_and_log_no_ubman(log, f'cgpt boot -p {fname}') + out = utils.run_and_log_no_ubman(log, f'cgpt show -q {fname}') # Create a dict (indexed by partition number) containing the above info for line in out.splitlines(): @@ -542,8 +549,9 @@ def setup_android_image(ubman): with open(fname, 'rb') as inf: disk_data = inf.read() - test_abootimg.AbootimgTestDiskImage(ubman, 'boot.img', test_abootimg.img_hex) - boot_img = os.path.join(ubman.config.result_dir, 'boot.img') + test_abootimg.AbootimgTestDiskImage(config, log, 'boot.img', + test_abootimg.img_hex) + boot_img = os.path.join(config.result_dir, 'boot.img') with open(boot_img, 'rb') as inf: set_part_data(2, inf.read()) @@ -650,7 +658,7 @@ def test_ut_dm_init_bootstd(ubman): setup_bootmenu_image(ubman.config, ubman.log) setup_cedit_file(ubman) setup_cros_image(ubman.config, ubman.log) - setup_android_image(ubman) + setup_android_image(ubman.config, ubman.log) setup_efi_image(ubman) setup_ubuntu_image(ubman.config, ubman.log, 3, 'flash') setup_localboot_image(ubman) -- 2.43.0