From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Igor Opaniuk <igor.opaniuk@gmail.com>, u-boot@lists.u-boot-project.org
Cc: Jan Kehren <jan.kehren@emteria.com>,
Guillaume La Roque <glaroque@baylibre.com>,
Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Mattijs Korpershoek <mkorpershoek@kernel.org>,
Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Subject: [PATCH v2 02/10] test/py: android: Move android image creation to a dedicated file
Date: Tue, 20 Oct 2026 11:25:51 +0200 [thread overview]
Message-ID: <20261020-test-avb-fixes-v2-2-997f8f04fd3f@kernel.org> (raw)
In-Reply-To: <20261020-test-avb-fixes-v2-0-997f8f04fd3f@kernel.org>
The image creation code in test_ut is huge and difficult to follow.
The android part contain code duplications when making mmc7.img/mmc8.img.
To prepare some code refactoring, move the Android specific bits into a
dedicated file under test_android/.
No functional change.
Reviewed-by: Guillaume La Roque <glaroque@baylibre.com>
Reviewed-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Tested-by: Guillaume La Roque <glaroque@baylibre.com>
Tested-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
---
test/py/tests/test_android/android_image.py | 135 ++++++++++++++++++++++++++++
test/py/tests/test_ut.py | 129 +-------------------------
2 files changed, 136 insertions(+), 128 deletions(-)
diff --git a/test/py/tests/test_android/android_image.py b/test/py/tests/test_android/android_image.py
new file mode 100644
index 000000000000..3bea311586bf
--- /dev/null
+++ b/test/py/tests/test_android/android_image.py
@@ -0,0 +1,135 @@
+# SPDX-License-Identifier: GPL-2.0
+"""Helpers to create Android disk images for sandbox testing."""
+
+import collections
+import os
+
+import utils
+from test_android import test_abootimg
+
+def setup_android_image(ubman):
+ """Create a 20MB disk image with Android partitions"""
+ Partition = collections.namedtuple('part', 'start,size,name')
+ parts = {}
+ disk_data = None
+
+ def set_part_data(partnum, data):
+ """Set the contents of a disk partition
+
+ This updates disk_data by putting data in the right place
+
+ Args:
+ partnum (int): Partition number to set
+ data (bytes): Data for that partition
+ """
+ nonlocal disk_data
+
+ start = parts[partnum].start * sect_size
+ 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}')
+
+ ptr = 40
+
+ # Number of sectors in 1MB
+ sect_size = 512
+ sect_1mb = (1 << 20) // sect_size
+
+ required_parts = [
+ {'num': 1, 'label':'misc', 'size': '1M'},
+ {'num': 2, 'label':'boot_a', 'size': '4M'},
+ {'num': 3, 'label':'boot_b', 'size': '4M'},
+ {'num': 4, 'label':'vendor_boot_a', 'size': '4M'},
+ {'num': 5, 'label':'vendor_boot_b', 'size': '4M'},
+ ]
+
+ for part in required_parts:
+ size_str = part['size']
+ if 'M' in size_str:
+ size = int(size_str[:-1]) * sect_1mb
+ else:
+ size = int(size_str)
+ utils.run_and_log(
+ ubman,
+ 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}')
+
+ # Create a dict (indexed by partition number) containing the above info
+ for line in out.splitlines():
+ start, size, num, name = line.split(maxsplit=3)
+ parts[int(num)] = Partition(int(start), int(size), name)
+
+ 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')
+ 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')
+ with open(vendor_boot_img, 'rb') as inf:
+ set_part_data(4, inf.read())
+
+ with open(fname, 'wb') as outf:
+ outf.write(disk_data)
+
+ 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}')
+
+ ptr = 40
+
+ # Number of sectors in 1MB
+ sect_size = 512
+ sect_1mb = (1 << 20) // sect_size
+
+ required_parts = [
+ {'num': 1, 'label':'misc', 'size': '1M'},
+ {'num': 2, 'label':'boot_a', 'size': '4M'},
+ {'num': 3, 'label':'boot_b', 'size': '4M'},
+ ]
+
+ for part in required_parts:
+ size_str = part['size']
+ if 'M' in size_str:
+ size = int(size_str[:-1]) * sect_1mb
+ else:
+ size = int(size_str)
+ utils.run_and_log(
+ ubman,
+ 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}')
+
+ # Create a dict (indexed by partition number) containing the above info
+ for line in out.splitlines():
+ start, size, num, name = line.split(maxsplit=3)
+ parts[int(num)] = Partition(int(start), int(size), name)
+
+ 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')
+ with open(boot_img, 'rb') as inf:
+ set_part_data(2, inf.read())
+
+ with open(fname, 'wb') as outf:
+ outf.write(disk_data)
+
+ print(f'wrote to {fname}')
+
+ return fname
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 2a5acc18c612..c1b5bc056023 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -19,7 +19,7 @@ import utils
# pylint: disable=E0611
from tests import fs_helper
from fs_helper import DiskHelper, FsHelper
-from test_android import test_abootimg
+from test_android.android_image import setup_android_image
def mkdir_cond(dirname):
"""Create a directory if it doesn't already exist
@@ -506,133 +506,6 @@ def setup_cros_image(ubman):
return fname
-def setup_android_image(ubman):
- """Create a 20MB disk image with Android partitions"""
- Partition = collections.namedtuple('part', 'start,size,name')
- parts = {}
- disk_data = None
-
- def set_part_data(partnum, data):
- """Set the contents of a disk partition
-
- This updates disk_data by putting data in the right place
-
- Args:
- partnum (int): Partition number to set
- data (bytes): Data for that partition
- """
- nonlocal disk_data
-
- start = parts[partnum].start * sect_size
- 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}')
-
- ptr = 40
-
- # Number of sectors in 1MB
- sect_size = 512
- sect_1mb = (1 << 20) // sect_size
-
- required_parts = [
- {'num': 1, 'label':'misc', 'size': '1M'},
- {'num': 2, 'label':'boot_a', 'size': '4M'},
- {'num': 3, 'label':'boot_b', 'size': '4M'},
- {'num': 4, 'label':'vendor_boot_a', 'size': '4M'},
- {'num': 5, 'label':'vendor_boot_b', 'size': '4M'},
- ]
-
- for part in required_parts:
- size_str = part['size']
- if 'M' in size_str:
- size = int(size_str[:-1]) * sect_1mb
- else:
- size = int(size_str)
- utils.run_and_log(
- ubman,
- 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}')
-
- # Create a dict (indexed by partition number) containing the above info
- for line in out.splitlines():
- start, size, num, name = line.split(maxsplit=3)
- parts[int(num)] = Partition(int(start), int(size), name)
-
- 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')
- 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')
- with open(vendor_boot_img, 'rb') as inf:
- set_part_data(4, inf.read())
-
- with open(fname, 'wb') as outf:
- outf.write(disk_data)
-
- 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}')
-
- ptr = 40
-
- # Number of sectors in 1MB
- sect_size = 512
- sect_1mb = (1 << 20) // sect_size
-
- required_parts = [
- {'num': 1, 'label':'misc', 'size': '1M'},
- {'num': 2, 'label':'boot_a', 'size': '4M'},
- {'num': 3, 'label':'boot_b', 'size': '4M'},
- ]
-
- for part in required_parts:
- size_str = part['size']
- if 'M' in size_str:
- size = int(size_str[:-1]) * sect_1mb
- else:
- size = int(size_str)
- utils.run_and_log(
- ubman,
- 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}')
-
- # Create a dict (indexed by partition number) containing the above info
- for line in out.splitlines():
- start, size, num, name = line.split(maxsplit=3)
- parts[int(num)] = Partition(int(start), int(size), name)
-
- 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')
- with open(boot_img, 'rb') as inf:
- set_part_data(2, inf.read())
-
- with open(fname, 'wb') as outf:
- outf.write(disk_data)
-
- print(f'wrote to {fname}')
-
- return fname
-
def setup_cedit_file(ubman):
"""Set up a .dtb file for use with testing expo and configuration editor"""
infname = os.path.join(ubman.config.source_dir,
--
2.56.0
next prev parent reply other threads:[~2026-10-20 9:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 9:25 [PATCH v2 00/10] Fix AVB pytest suite for sandbox Mattijs Korpershoek
2026-10-20 9:25 ` [PATCH v2 01/10] avb: Use map_to_sysmem() for flush_cache() address Mattijs Korpershoek
2026-10-22 8:25 ` Simon Glass
2026-10-20 9:25 ` Mattijs Korpershoek [this message]
2026-10-22 8:25 ` [PATCH v2 02/10] test/py: android: Move android image creation to a dedicated file Simon Glass
2026-10-20 9:25 ` [PATCH v2 03/10] test/py: android: Drop verbose printing and unused return Mattijs Korpershoek
2026-10-22 8:25 ` Simon Glass
2026-10-20 9:25 ` [PATCH v2 04/10] test/py: android: Use for loop to create the images / update disks Mattijs Korpershoek
2026-10-22 8:25 ` Simon Glass
2026-10-20 9:25 ` [PATCH v2 05/10] test/py: android: Add create_gpt_image() for image creation Mattijs Korpershoek
2026-10-20 15:07 ` Guillaume La Roque
2026-10-22 8:26 ` Simon Glass
2026-10-22 13:24 ` Mattijs Korpershoek
2026-10-20 9:25 ` [PATCH v2 06/10] test/py: android: Add setup_android_v{4,2}_image subfunctions Mattijs Korpershoek
2026-10-22 8:26 ` [PATCH v2 06/10] test/py: android: Add setup_android_v{4, 2}_image subfunctions Simon Glass
2026-10-20 9:25 ` [PATCH v2 07/10] test/py: avb: Use format specifiers instead of str() for mmc_dev Mattijs Korpershoek
2026-10-22 8:59 ` Simon Glass
2026-10-20 9:25 ` [PATCH v2 08/10] test/py: avb: Move mmc device number to a pytest fixture Mattijs Korpershoek
2026-10-22 8:26 ` Simon Glass
2026-10-20 9:25 ` [PATCH v2 09/10] test/py: avb: Add sandbox AVB testing with dedicated mmc12 device Mattijs Korpershoek
2026-10-22 8:26 ` Simon Glass
2026-10-22 12:53 ` Mattijs Korpershoek
2026-10-20 9:25 ` [PATCH v2 10/10] test/py: avb: Fix find() logic when matching response strings Mattijs Korpershoek
2026-10-20 15:07 ` Guillaume La Roque
2026-10-22 8:26 ` Simon Glass
2026-10-22 12:22 ` Mattijs Korpershoek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020-test-avb-fixes-v2-2-997f8f04fd3f@kernel.org \
--to=mkorpershoek@kernel.org \
--cc=glaroque@baylibre.com \
--cc=igor.opaniuk@gmail.com \
--cc=igor.opaniuk@oss.qualcomm.com \
--cc=jan.kehren@emteria.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.