Fix AVB pytest suite for sandbox
v2 cover Fix AVB pytest suite for sandbox
The AVB tests have the following limitations on sandbox:
* The mmc1.img required by sandbox is not created when the avb test runs
* mmc1.img contains a Fedora image, so avb verification cannot be done
* The tests silently pass due to bad usage of string.find()
This series improve the test suite to have more useful results on sandbox.
---
Changes in v2:
- Add missing find() return code check in test_avb_mmc_uuid (Guillaume)
- Skip avb tests when qemu-img or cgpt is not installed (Igor)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Mattijs Korpershoek (10):
avb: Use map_to_sysmem() for flush_cache() address test/py: android: Move android image creation to a dedicated file test/py: android: Drop verbose printing and unused return test/py: android: Use for loop to create the images / update disks test/py: android: Add create_gpt_image() for image creation test/py: android: Add setup_android_v{4,2}_image subfunctions test/py: avb: Use format specifiers instead of str() for mmc_dev test/py: avb: Move mmc device number to a pytest fixture test/py: avb: Add sandbox AVB testing with dedicated mmc12 device test/py: avb: Fix find() logic when matching response strings
arch/sandbox/dts/test.dts | 8 ++ common/avb_verify.c | 3 +- test/py/tests/test_android/android_image.py | 104 ++++++++++++++++++++++ test/py/tests/test_android/test_abootimg.py | 77 +++++++++++++++++ test/py/tests/test_android/test_avb.py | 78 +++++++++++------ test/py/tests/test_ut.py | 129 +--------------------------- 6 files changed, 246 insertions(+), 153 deletions(-)
---
base-commit: fed92546960a92177d67c0b8d7b22385f50fed29
change-id: 20261015-test-avb-fixes-9a4682e8057d
Best regards,
Signature · 1 line
Mattijs Korpershoek <[email protected]>
PATCH v2 1/10 avb: Use map_to_sysmem() for flush_cache() address
flush_cache() expects a U-Boot physical address, but avb_verify's mmc_read_and_flush() passes a raw pointer cast to ulong. On sandbox, host heap pointers (e.g. 0x1a27ee70) can be outside the emulated SDRAM region (0x0 to gd->ram_size), causing map_sysmem() inside flush_cache() to crash:
phys_to_virt: Cannot map sandbox address 1a27ee70
(SDRAM from 0 to 10000000)
Fix the crash by using map_to_sysmem() to convert the buffer pointer to a proper U-Boot address.
--- common/avb_verify.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
common/avb_verify.c +2 -1
@@ -7,6 +7,7 @@#include <blk.h> #include <cpu_func.h> #include <image.h> +#include <mapmem.h> #include <malloc.h> #include <part.h> #include <tee.h>
@@ -346,7 +347,7 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part, blks =blk_dread (part->mmc_blk, start, sectors, tmp_buf);/* flush cache after read */ -flush_cache ((ulong )tmp_buf, sectors * part->info.blksz); +flush_cache (map_to_sysmem (tmp_buf), sectors * part->info.blksz);if (unaligned)memcpy (buffer, tmp_buf, sectors * part->info.blksz);
Signature · 1 line
2.56.0
Re: [PATCH v2 01/10] avb: Use map_to_sysmem() for flush_cache() address
Quoted 14 lines · Mattijs Korpershoek
avb: Use
map_to_sysmem()forflush_cache()address
flush_cache()expects a U-Boot physical address, but avb_verify'smmc_read_and_flush()passes a raw pointer cast to ulong. On sandbox, host heap pointers (e.g.0x1a27ee70) can be outside the emulated SDRAM region (0x0togd->ram_size), causingmap_sysmem()insideflush_cache()to crash:
phys_to_virt: Cannot map sandbox address1a27ee70(SDRAM from 0 to 10000000)Fix the crash by using
map_to_sysmem()to convert the buffer pointer to a proper U-Boot address.
Quoted 8 lines
Reviewed-by Guillaume La Roque <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>common/avb_verify.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v2 2/10 test/py: android: Move android image creation to a dedicated file
In reply to Mattijs KorpershoekThe 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.
--- test/py/tests/test_android/android_image.py | 135 ++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 129 +------------------------- 2 files changed, 136 insertions(+), 128 deletions(-)
test/py/tests/test_android/android_image.py new file +135 -0
@@ -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
test/py/tests/test_ut.py +1 -128
141 lines not on this page · raw message
Signature · 1 line
2.56.0
Re: [PATCH v2 02/10] test/py: android: Move android image creation to a dedicated file
Quoted 16 lines · Mattijs Korpershoek
test/py: android: Move android image creation to a dedicated file
The image creation code in
test_utis 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 <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>
Quoted 3 lines
test/py/tests/test_android/android_image.py | 135 ++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 129 +------------------------- 2 files changed, 136 insertions(+), 128 deletions(-)
PATCH v2 3/10 test/py: android: Drop verbose printing and unused return
In reply to Mattijs KorpershoekThe setup_android_image() is only called once. The callers does not use the return value.
Drop the unused return. While at it, also remove the verbose printing.
--- test/py/tests/test_android/android_image.py | 6 ------ 1 file changed, 6 deletions(-)
test/py/tests/test_android/android_image.py +0 -6
@@ -81,8 +81,6 @@ def setup_android_image(ubman): 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')
@@ -129,7 +127,3 @@ def setup_android_image(ubman): with open(fname, 'wb') as outf: outf.write(disk_data) - - print(f'wrote to {fname}') - - return fname
Signature · 1 line
2.56.0
Re: [PATCH v2 03/10] test/py: android: Drop verbose printing and unused return
Quoted 7 lines · Mattijs Korpershoek
test/py: android: Drop verbose printing and unused return
The
setup_android_image()is only called once. The callers does not use the return value.Drop the unused return. While at it, also remove the verbose printing.
Quoted 8 lines
Reviewed-by Guillaume La Roque <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>test/py/tests/test_android/android_image.py | 6 ------ 1 file changed, 6 deletions(-)
PATCH v2 4/10 test/py: android: Use for loop to create the images / update disks
In reply to Mattijs Korpershoeksetup_android_image() creates 2 mmcX.img files:
* mmc7.img: For boot image v4 support
* mmc8.img: For boot image v2 support
There is quite some code that's common for both images. Currently, most code is duplicated.
To prepare a cleaner refactoring, move the image descriptions into an array and create each partition using a loop.
--- test/py/tests/test_android/android_image.py | 48 +++++++++++++---------------- 1 file changed, 21 insertions(+), 27 deletions(-)
test/py/tests/test_android/android_image.py +21 -27
@@ -13,20 +13,6 @@ def setup_android_image(ubman): 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')
@@ -68,15 +54,17 @@ 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') - 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()) + images = [ + (2, 'bootv4.img', test_abootimg.boot_img_hex), + (4, 'vendor_boot.img', test_abootimg.vboot_img_hex), + ] + for partnum, img_name, hex_data in images: + test_abootimg.AbootimgTestDiskImage(ubman, img_name, hex_data) + img_path = os.path.join(ubman.config.result_dir, img_name) + with open(img_path, 'rb') as inf: + data = inf.read() + start = parts[partnum].start * sect_size + disk_data = disk_data[:start] + data + disk_data[start + len(data):] with open(fname, 'wb') as outf: outf.write(disk_data)
@@ -120,10 +108,16 @@ 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') - with open(boot_img, 'rb') as inf: - set_part_data(2, inf.read()) + images = [ + (2, 'boot.img', test_abootimg.img_hex), + ] + for partnum, img_name, hex_data in images: + test_abootimg.AbootimgTestDiskImage(ubman, img_name, hex_data) + img_path = os.path.join(ubman.config.result_dir, img_name) + with open(img_path, 'rb') as inf: + data = inf.read() + start = parts[partnum].start * sect_size + disk_data = disk_data[:start] + data + disk_data[start + len(data):] with open(fname, 'wb') as outf: outf.write(disk_data)
Signature · 1 line
2.56.0
Re: [PATCH v2 04/10] test/py: android: Use for loop to create the images / update disks
Quoted 13 lines · Mattijs Korpershoek
test/py: android: Use for loop to create the images / update disks
setup_android_image()creates 2 mmcX.img files:* mmc7.img: For boot image v4 support
* mmc8.img: For boot image v2 supportThere is quite some code that's common for both images. Currently, most code is duplicated.
To prepare a cleaner refactoring, move the image descriptions into an array and create each partition using a loop.
Quoted 8 lines
Reviewed-by Guillaume La Roque <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>test/py/tests/test_android/android_image.py | 48 +++++++++++++---------------- 1 file changed, 21 insertions(+), 27 deletions(-)
PATCH v2 5/10 test/py: android: Add create_gpt_image() for image creation
In reply to Mattijs KorpershoekThere is quite some code duplication between the image creation for mmc7.img and mmc8.img. If we want to add more images, this will be even more duplication.
Add a common function, create_gpt_image() which removes all the code duplication.
--- test/py/tests/test_android/android_image.py | 78 +++++++---------------------- 1 file changed, 19 insertions(+), 59 deletions(-)
test/py/tests/test_android/android_image.py +19 -59
@@ -7,13 +7,12 @@ import os import utils from test_android import test_abootimg -def setup_android_image(ubman): +Partition = collections.namedtuple('part', 'start,size,name') + +def create_gpt_image(ubman, mmc_dev, required_parts, images): """Create a 20MB disk image with Android partitions""" - Partition = collections.namedtuple('part', 'start,size,name') parts = {} disk_data = None - - 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}')
@@ -24,14 +23,6 @@ def setup_android_image(ubman): 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:
@@ -54,10 +45,6 @@ def setup_android_image(ubman): with open(fname, 'rb') as inf: disk_data = inf.read() - images = [ - (2, 'bootv4.img', test_abootimg.boot_img_hex), - (4, 'vendor_boot.img', test_abootimg.vboot_img_hex), - ] for partnum, img_name, hex_data in images: test_abootimg.AbootimgTestDiskImage(ubman, img_name, hex_data) img_path = os.path.join(ubman.config.result_dir, img_name)
@@ -69,55 +56,28 @@ def setup_android_image(ubman): with open(fname, 'wb') as outf: outf.write(disk_data) - 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 - +def setup_android_image(ubman): + mmc_dev = 7 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'}, ] + images = [ + (2, 'bootv4.img', test_abootimg.boot_img_hex), + (4, 'vendor_boot.img', test_abootimg.vboot_img_hex), + ] + create_gpt_image(ubman, mmc_dev, required_parts, images) - 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() - + mmc_dev = 8 + required_parts = [ + {'num': 1, 'label':'misc', 'size': '1M'}, + {'num': 2, 'label':'boot_a', 'size': '4M'}, + {'num': 3, 'label':'boot_b', 'size': '4M'}, + ] images = [ (2, 'boot.img', test_abootimg.img_hex), ] - for partnum, img_name, hex_data in images: - test_abootimg.AbootimgTestDiskImage(ubman, img_name, hex_data) - img_path = os.path.join(ubman.config.result_dir, img_name) - with open(img_path, 'rb') as inf: - data = inf.read() - start = parts[partnum].start * sect_size - disk_data = disk_data[:start] + data + disk_data[start + len(data):] - - with open(fname, 'wb') as outf: - outf.write(disk_data) + create_gpt_image(ubman, mmc_dev, required_parts, images)
Signature · 1 line
2.56.0
Re: [PATCH v2 05/10] test/py: android: Add create_gpt_image() for image creation
Quoted 121 lines
There is quite some code duplication between the image creation for mmc7.img and mmc8.img. If we want to add more images, this will be even more duplication.
Add a common function,
create_gpt_image()which removes all the code duplication.Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>test/py/tests/test_android/android_image.py +18
-50@@ -7,13 +7,12 @@ import os import utils from test_android import test_abootimg -def setup_android_image(ubman): +Partition = collections.namedtuple('part', 'start,size,name') + +def create_gpt_image(ubman, mmc_dev, required_parts, images): """Create a 20MB disk image with Android partitions""" - Partition = collections.namedtuple('part', 'start,size,name') parts = {} disk_data = None - - 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}')@@ -24,14 +23,6 @@ def setup_android_image(ubman): 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:@@ -54,10 +45,6 @@ def setup_android_image(ubman): with open(fname, 'rb') as inf: disk_data = inf.read() - images = [ - (2, 'bootv4.img', test_abootimg.boot_img_hex), - (4, 'vendor_boot.img', test_abootimg.vboot_img_hex), - ] for partnum, img_name, hex_data in images: test_abootimg.AbootimgTestDiskImage(ubman, img_name, hex_data) img_path = os.path.join(ubman.config.result_dir, img_name)@@ -69,55 +56,28 @@ def setup_android_image(ubman): with open(fname, 'wb') as outf: outf.write(disk_data) - 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 - +def setup_android_image(ubman): + mmc_dev = 7 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'}, ] + images = [ + (2, 'bootv4.img', test_abootimg.boot_img_hex), + (4, 'vendor_boot.img', test_abootimg.vboot_img_hex), + ] + create_gpt_image(ubman, mmc_dev, required_parts, images) - 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() - + mmc_dev = 8 + required_parts = [ + {'num': 1, 'label':'misc', 'size': '1M'}, + {'num': 2, 'label':'boot_a', 'size': '4M'}, + {'num': 3, 'label':'boot_b', 'size': '4M'}, + ] images = [ (2, 'boot.img', test_abootimg.img_hex), ] - for partnum, img_name, hex_data in images:
test/py/tests/test_android/android_image.py def setup_android_image(ubman): · line 83
Quoted 10 lines
test/py/tests/test_android/android_image.py +1
-9- test_abootimg.AbootimgTestDiskImage(ubman, img_name, hex_data) - img_path = os.path.join(ubman.config.result_dir, img_name) - with open(img_path, 'rb') as inf: - data = inf.read() - start = parts[partnum].start * sect_size - disk_data = disk_data[:start] + data + disk_data[start + len(data):] - - with open(fname, 'wb') as outf: - outf.write(disk_data) + create_gpt_image(ubman, mmc_dev, required_parts, images)
Signature · 1 line
Guillaume La Roque <[email protected]>
Re: [PATCH v2 05/10] test/py: android: Add create_gpt_image() for image creation
In reply to Mattijs KorpershoekHi Mattijs,
Quoted 20 lines · Mattijs Korpershoek
test/py: android: Add
create_gpt_image()for image creationThere is quite some code duplication between the image creation for mmc7.img and mmc8.img. If we want to add more images, this will be even more duplication.
Add a common function,
create_gpt_image()which removes all the code duplication.Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>Reviewed-by Guillaume La Roque <[email protected]>test/py/tests/test_android/android_image.py | 78 +++++++---------------------- 1 file changed, 19 insertions(+), 59 deletions(-)
test/py/tests/test_android/android_image.py import os · line 12
Quoted 8 lines
test/py/tests/test_android/android_image.py +3
-2@@ -7,13 +7,12 @@ import os -def setup_android_image(ubman): +Partition = collections.namedtuple('part', 'start,size,name') + +def create_gpt_image(ubman, mmc_dev, required_parts, images): """Create a 20MB disk image with Android partitions""" - Partition = collections.namedtuple('part', 'start,size,name') parts = {} disk_data = None
This is now a general helper that callers have to fill in, but the format of 'required_parts' (a list of dicts with 'num', 'label' and 'size', where size is either a sector count or 'NM') and 'images' (tuples of partition number, file name and hex data) is only visible from reading the body. Please can you add an Args: section to the docstring describing each parameter, as set_part_data() has earlier in the series? Since the name now says GPT, the docstring could also say which mmc image it writes rather than 'Android partitions'.
Also, 'disk_data = None' is now redundant since the variable is only assigned once, further down. Moving Partition to module level seems unnecessary too, since only this function uses it.
test/py/tests/test_android/android_image.py def setup_android_image(ubman): · line 57
Quoted 4 lines
test/py/tests/test_android/android_image.py +2
-0@@ -69,55 +56,28 @@ def setup_android_image(ubman): +def setup_android_image(ubman): + mmc_dev = 7
This drops the docstring from setup_android_image(), so pylint complains at this patch. The next patch adds it back, but it would be better to keep it here so that each patch is clean on its own.
Regards,
Simon
Re: [PATCH v2 05/10] test/py: android: Add create_gpt_image() for image creation
Hi Simon,
Thank you for the review.
Quoted 32 lines · Simon Glass
Hi Mattijs,
Quoted 20 lines · Mattijs Korpershoek
test/py: android: Add
create_gpt_image()for image creationThere is quite some code duplication between the image creation for mmc7.img and mmc8.img. If we want to add more images, this will be even more duplication.
Add a common function,
create_gpt_image()which removes all the code duplication.Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>Reviewed-by Guillaume La Roque <[email protected]>test/py/tests/test_android/android_image.py | 78 +++++++---------------------- 1 file changed, 19 insertions(+), 59 deletions(-)test/py/tests/test_android/android_image.py import os · line 12
Quoted 8 lines
test/py/tests/test_android/android_image.py +3
-2@@ -7,13 +7,12 @@ import os -def setup_android_image(ubman): +Partition = collections.namedtuple('part', 'start,size,name') + +def create_gpt_image(ubman, mmc_dev, required_parts, images): """Create a 20MB disk image with Android partitions""" - Partition = collections.namedtuple('part', 'start,size,name') parts = {} disk_data = None
Quoted 8 lines
This is now a general helper that callers have to fill in, but the format of '
required_parts' (a list of dicts with 'num', 'label' and 'size', where size is either a sector count or 'NM') and 'images' (tuples of partition number, file name and hex data) is only visible from reading the body. Please can you add an Args: section to the docstring describing each parameter, asset_part_data()has earlier in the series? Since the name now says GPT, the docstring could also say which mmc image it writes rather than 'Android partitions'.
Ok, will do for v3.
Quoted 4 lines
Also, '
disk_data= None' is now redundant since the variable is only assigned once, further down. Moving Partition to module level seems unnecessary too, since only this function uses it.
Ok, dropped disk_data = None for v3.
Ok, put Partition back into the function for v3.
Quoted 9 lines
test/py/tests/test_android/android_image.py def setup_android_image(ubman): · line 57
Quoted 5 lines
test/py/tests/test_android/android_image.py +2
-0@@ -69,55 +56,28 @@ def setup_android_image(ubman): +def setup_android_image(ubman): + mmc_dev = 7This drops the docstring from
setup_android_image(), so pylint complains at this patch. The next patch adds it back, but it would be better to keep it here so that each patch is clean on its own.
Ok, will put the docstring back in in v3.
Quoted 3 lines
Regards,
Simon
PATCH v2 6/10 test/py: android: Add setup_android_v{4,2}_image subfunctions
In reply to Mattijs KorpershoekTo split out the logic even further, do each image creation in a separate function.
This will make it cleaner to add future images as well.
--- test/py/tests/test_android/android_image.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
test/py/tests/test_android/android_image.py +11 -5
@@ -56,8 +56,8 @@ def create_gpt_image(ubman, mmc_dev, required_parts, images): with open(fname, 'wb') as outf: outf.write(disk_data) -def setup_android_image(ubman): - mmc_dev = 7 +def setup_android_v4_image(ubman): + """Create mmc7.img: boot image v4 with vendor_boot partitions.""" required_parts = [ {'num': 1, 'label':'misc', 'size': '1M'}, {'num': 2, 'label':'boot_a', 'size': '4M'},
@@ -69,9 +69,10 @@ def setup_android_image(ubman): (2, 'bootv4.img', test_abootimg.boot_img_hex), (4, 'vendor_boot.img', test_abootimg.vboot_img_hex), ] - create_gpt_image(ubman, mmc_dev, required_parts, images) + create_gpt_image(ubman, 7, required_parts, images) - mmc_dev = 8 +def setup_android_v2_image(ubman): + """Create mmc8.img: boot image v2 without vendor_boot.""" required_parts = [ {'num': 1, 'label':'misc', 'size': '1M'}, {'num': 2, 'label':'boot_a', 'size': '4M'},
@@ -80,4 +81,9 @@ def setup_android_image(ubman): images = [ (2, 'boot.img', test_abootimg.img_hex), ] - create_gpt_image(ubman, mmc_dev, required_parts, images) + create_gpt_image(ubman, 8, required_parts, images) + +def setup_android_image(ubman): + """Create disk images with Android partitions.""" + setup_android_v4_image(ubman) + setup_android_v2_image(ubman)
Signature · 1 line
2.56.0
Re: [PATCH v2 06/10] test/py: android: Add setup_android_v{4, 2}_image subfunctions
Quoted 7 lines · Mattijs Korpershoek
test/py: android: Add setup_android_v{4,2}_image subfunctions
To split out the logic even further, do each image creation in a separate function.
This will make it cleaner to add future images as well.
Quoted 8 lines
Reviewed-by Guillaume La Roque <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>test/py/tests/test_android/android_image.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
PATCH v2 7/10 test/py: avb: Use format specifiers instead of str() for mmc_dev
In reply to Mattijs KorpershoekThe tests format mmc_dev using str() conversion, which produces a decimal string. This works when mmc_dev is 1, since "1" is valid in both decimal and hex, but breaks for other device numbers like 12 (0xc): str(12) produces "12", which avb init would interpret as 0x12.
Use %x for commands that parse hex (avb init) and %d for commands that parse decimal (mmc dev) to format device numbers correctly regardless of their value.
--- test/py/tests/test_android/test_avb.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
test/py/tests/test_android/test_avb.py +8 -10
@@ -29,7 +29,7 @@ def test_avb_verify(ubman): success_str = "Verification passed successfully" - response = ubman.run_command('avb init %s' %str(mmc_dev)) + response = ubman.run_command('avb init %x' % mmc_dev) assert response == '' response = ubman.run_command('avb verify') assert response.find(success_str)
@@ -43,11 +43,10 @@ def test_avb_mmc_uuid(ubman): 'part list mmc 1' output """ - response = ubman.run_command('avb init %s' % str(mmc_dev)) + response = ubman.run_command('avb init %x' % mmc_dev) assert response == '' - response = ubman.run_command('mmc rescan; mmc dev %s' % - str(mmc_dev)) + response = ubman.run_command('mmc rescan; mmc dev %d' % mmc_dev) assert response.find('is current device') part_lines = ubman.run_command('mmc part').splitlines()
@@ -75,7 +74,7 @@ def test_avb_read_rb(ubman): """Test reading rollback indexes """ - response = ubman.run_command('avb init %s' % str(mmc_dev)) + response = ubman.run_command('avb init %x' % mmc_dev) assert response == '' response = ubman.run_command('avb read_rb 1')
@@ -87,7 +86,7 @@ def test_avb_is_unlocked(ubman): """Test if device is in the unlocked state """ - response = ubman.run_command('avb init %s' % str(mmc_dev)) + response = ubman.run_command('avb init %x' % mmc_dev) assert response == '' response = ubman.run_command('avb is_unlocked')
@@ -101,14 +100,13 @@ def test_avb_mmc_read(ubman): """Test mmc read operation """ - response = ubman.run_command('mmc rescan; mmc dev %s 0' % - str(mmc_dev)) + response = ubman.run_command('mmc rescan; mmc dev %d 0' % mmc_dev) assert response.find('is current device') response = ubman.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) assert response.find('read: OK') - response = ubman.run_command('avb init %s' % str(mmc_dev)) + response = ubman.run_command('avb init %x' % mmc_dev) assert response == '' response = ubman.run_command('avb read_part xloader 0 100 0x%x' %
@@ -127,7 +125,7 @@ def test_avb_persistent_values(ubman): """Test reading/writing persistent storage to avb """ - response = ubman.run_command('avb init %s' % str(mmc_dev)) + response = ubman.run_command('avb init %x' % mmc_dev) assert response == '' response = ubman.run_command('avb write_pvalue test value_value')
Signature · 1 line
2.56.0
Re: [PATCH v2 07/10] test/py: avb: Use format specifiers instead of str() for mmc_dev
Quoted 11 lines · Mattijs Korpershoek
test/py: avb: Use format specifiers instead of
str()formmc_devThe tests format
mmc_devusingstr()conversion, which produces a decimal string. This works whenmmc_devis 1, since "1" is valid in both decimal and hex, but breaks for other device numbers like 12 (0xc): str(12) produces "12", which avb init would interpret as0x12.Use %x for commands that parse hex (avb init) and %d for commands that parse decimal (mmc dev) to format device numbers correctly regardless of their value.
Quoted 8 lines
Reviewed-by Guillaume La Roque <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>test/py/tests/test_android/test_avb.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
PATCH v2 8/10 test/py: avb: Move mmc device number to a pytest fixture
In reply to Mattijs KorpershoekThe AVB tests hardcode mmc device 1, which is usually correct on real hardware. On sandbox, this is not the case because mmc1.img contains a fedora image.
Replace the module-level mmc_dev constant with an avb_device_id fixture so that a subsequent commit can override the device number for sandbox.
--- test/py/tests/test_android/test_avb.py | 38 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-)
test/py/tests/test_android/test_avb.py +22 -16
@@ -16,20 +16,26 @@ For configuration verification: import pytest -# defauld mmc id -mmc_dev = 1 temp_addr = 0x90000000 temp_addr2 = 0x90002000 [email protected](scope='function') +def avb_device_id(ubman): + """Returns the device id number for AVB + """ + + # default mmc id + return 1 + @pytest.mark.buildconfigspec('cmd_avb') @pytest.mark.buildconfigspec('cmd_mmc') -def test_avb_verify(ubman): +def test_avb_verify(ubman, avb_device_id): """Run AVB 2.0 boot verification chain with avb subset of commands """ success_str = "Verification passed successfully" - response = ubman.run_command('avb init %x' % mmc_dev) + response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb verify') assert response.find(success_str)
@@ -38,15 +44,15 @@ def test_avb_verify(ubman): @pytest.mark.buildconfigspec('cmd_avb') @pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.notbuildconfigspec('sandbox') -def test_avb_mmc_uuid(ubman): +def test_avb_mmc_uuid(ubman, avb_device_id): """Check if 'avb get_uuid' works, compare results with 'part list mmc 1' output """ - response = ubman.run_command('avb init %x' % mmc_dev) + response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' - response = ubman.run_command('mmc rescan; mmc dev %d' % mmc_dev) + response = ubman.run_command('mmc rescan; mmc dev %d' % avb_device_id) assert response.find('is current device') part_lines = ubman.run_command('mmc part').splitlines()
@@ -70,11 +76,11 @@ def test_avb_mmc_uuid(ubman): @pytest.mark.buildconfigspec('cmd_avb') -def test_avb_read_rb(ubman): +def test_avb_read_rb(ubman, avb_device_id): """Test reading rollback indexes """ - response = ubman.run_command('avb init %x' % mmc_dev) + response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb read_rb 1')
@@ -82,11 +88,11 @@ def test_avb_read_rb(ubman): @pytest.mark.buildconfigspec('cmd_avb') -def test_avb_is_unlocked(ubman): +def test_avb_is_unlocked(ubman, avb_device_id): """Test if device is in the unlocked state """ - response = ubman.run_command('avb init %x' % mmc_dev) + response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb is_unlocked')
@@ -96,17 +102,17 @@ def test_avb_is_unlocked(ubman): @pytest.mark.buildconfigspec('cmd_avb') @pytest.mark.buildconfigspec('cmd_mmc') @pytest.mark.notbuildconfigspec('sandbox') -def test_avb_mmc_read(ubman): +def test_avb_mmc_read(ubman, avb_device_id): """Test mmc read operation """ - response = ubman.run_command('mmc rescan; mmc dev %d 0' % mmc_dev) + response = ubman.run_command('mmc rescan; mmc dev %d 0' % avb_device_id) assert response.find('is current device') response = ubman.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) assert response.find('read: OK') - response = ubman.run_command('avb init %x' % mmc_dev) + response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb read_part xloader 0 100 0x%x' %
@@ -121,11 +127,11 @@ def test_avb_mmc_read(ubman): @pytest.mark.buildconfigspec('cmd_avb') @pytest.mark.buildconfigspec('optee_ta_avb') -def test_avb_persistent_values(ubman): +def test_avb_persistent_values(ubman, avb_device_id): """Test reading/writing persistent storage to avb """ - response = ubman.run_command('avb init %x' % mmc_dev) + response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb write_pvalue test value_value')
Signature · 1 line
2.56.0
Re: [PATCH v2 08/10] test/py: avb: Move mmc device number to a pytest fixture
Quoted 10 lines · Mattijs Korpershoek
test/py: avb: Move mmc device number to a pytest fixture
The AVB tests hardcode mmc device 1, which is usually correct on real hardware. On sandbox, this is not the case because mmc1.img contains a fedora image.
Replace the module-level
mmc_devconstant with anavb_device_idfixture so that a subsequent commit can override the device number for sandbox.
Quoted 8 lines
Reviewed-by Guillaume La Roque <[email protected]>Reviewed-by Igor Opaniuk <[email protected]>Tested-by Guillaume La Roque <[email protected]>Tested-by Igor Opaniuk <[email protected]>Signed-off-by Mattijs Korpershoek <[email protected]>test/py/tests/test_android/test_avb.py | 38 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-)
PATCH v2 9/10 test/py: avb: Add sandbox AVB testing with dedicated mmc12 device
In reply to Mattijs KorpershoekRight now, sandbox runs the AVB tests using mmc1.img, which contains a fedora image.
This does not really make sense. We should test on an mmc device which has a proper vbmeta partition instead.
Add a new mmc12 in sandbox which contains all required partitions for proper AVB testing.
Use the mmc12 device in the avb tests only when running in sandbox. The mmc12 DT node gets enabled by the avb_device_id fixture if CMD_BIND is available.
Note: the vbmeta.img has been generated using:
$ ./avbtool.py add_hash_footer \
--image boot.img \
--partition_name boot \
--partition_size 4194304 $ ./avbtool.py make_vbmeta_image \
--key test/data/testkey_rsa4096.pem \
--algorithm SHA256_RSA4096 \
--include_descriptors_from_image boot.img \
--padding_size 4096 --flags 1 \
--output vbmeta.img $ gzip -9 vbmeta.img
$ xxd -p vbmeta.img.gz > vbmeta.img.gz.hex--- arch/sandbox/dts/test.dts | 8 +++ test/py/tests/test_android/android_image.py | 15 ++++++ test/py/tests/test_android/test_abootimg.py | 77 +++++++++++++++++++++++++++++ test/py/tests/test_android/test_avb.py | 26 ++++++++++ 4 files changed, 126 insertions(+)
arch/sandbox/dts/test.dts +8 -0
@@ -50,6 +50,7 @@ mmc9 = "/mmc9"; mmc10 = "/mmc10"; mmc11 = "/mmc11"; + mmc12 = "/mmc12"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2;
@@ -1398,6 +1399,13 @@ filename = "mmc11.img"; }; + /* This is used for Android AVB tests */ + mmc12 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "mmc12.img"; + }; + pch { compatible = "sandbox,pch"; };
test/py/tests/test_android/android_image.py +15 -0
@@ -83,7 +83,22 @@ def setup_android_v2_image(ubman): ] create_gpt_image(ubman, 8, required_parts, images) +def setup_android_avb_image(ubman): + """Create mmc12.img: boot image v2 with vbmeta.img.""" + + required_parts = [ + {'num': 1, 'label':'boot', 'size': '4M'}, + {'num': 2, 'label':'system', 'size': '4M'}, + {'num': 3, 'label':'vbmeta', 'size': '4M'}, + ] + images = [ + (1, 'boot.img', test_abootimg.img_hex), + (3, 'vbmeta.img', test_abootimg.vbmeta_img_hex), + ] + create_gpt_image(ubman, 12, required_parts, images) + def setup_android_image(ubman): """Create disk images with Android partitions.""" setup_android_v4_image(ubman) setup_android_v2_image(ubman) + setup_android_avb_image(ubman)
test/py/tests/test_android/test_abootimg.py +77 -0
89 lines not on this page · raw message
test/py/tests/test_android/test_avb.py +26 -0
@@ -13,8 +13,11 @@ For configuration verification: - Corrupt boot partition and check for failure - Corrupt vbmeta partition and check for failure """ +import os import pytest +import shutil +from android_image import setup_android_avb_image temp_addr = 0x90000000 temp_addr2 = 0x90002000
@@ -22,7 +25,30 @@ temp_addr2 = 0x90002000 @pytest.fixture(scope='function') def avb_device_id(ubman): """Returns the device id number for AVB + + On sandbox, creates mmc12.img and binds the disabled mmc12 DT node. + On other boards, defaults to device 1. """ + if ubman.config.buildconfig.get('config_sandbox'): + if not ubman.config.buildconfig.get('config_cmd_bind'): + pytest.skip('CMD_BIND required for AVB on sandbox') + + required_host_tools = ['qemu-img', 'cgpt'] + for tool in required_host_tools: + if shutil.which(tool) is None: + pytest.skip(f'tool "{tool}" not in $PATH') + + mmc_dev = 0xc + fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') + if not os.path.exists(fname): + setup_android_avb_image(ubman) + ubman.restart_uboot() + + ubman.run_command(f'bind /mmc{mmc_dev} mmc_sandbox') + # Run mmc list to ensure that mmc_sandbox driver is probed + ubman.run_command('mmc list') + + return mmc_dev # default mmc id return 1
Signature · 1 line
2.56.0
Re: [PATCH v2 09/10] test/py: avb: Add sandbox AVB testing with dedicated mmc12 device
Hi Mattijs,
Quoted 30 lines · Mattijs Korpershoek
test/py: avb: Add sandbox AVB testing with dedicated mmc12 device
Right now, sandbox runs the AVB tests using mmc1.img, which contains a fedora image.
This does not really make sense. We should test on an mmc device which has a proper vbmeta partition instead.Add a new mmc12 in sandbox which contains all required partitions for proper AVB testing.
Use the mmc12 device in the avb tests only when running in sandbox. The mmc12 DT node gets enabled by theavb_device_idfixture ifCMD_BINDis available.Note: the vbmeta.img has been generated using:
$ ./avbtool.py add_hash_footer \ --image boot.img \ --partition_name boot \ --partition_size 4194304[...]
arch/sandbox/dts/test.dts | 8 +++ test/py/tests/test_android/android_image.py | 15 ++++++ test/py/tests/test_android/test_abootimg.py | 77 +++++++++++++++++++++++++++++ test/py/tests/test_android/test_avb.py | 26 ++++++++++ 4 files changed, 126 insertions(+)
test/py/tests/test_android/test_avb.py temp_addr2 = 0x90002000 · line 29
Quoted 5 lines
test/py/tests/test_android/test_avb.py +5
-0@@ -22,7 +25,30 @@ temp_addr2 = 0x90002000 + mmc_dev = 0xc + fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') + if not os.path.exists(fname): + setup_android_avb_image(ubman) + ubman.restart_uboot()
Just to check, is the restart needed? The mmc12 node is disabled, so nothing probes it until the 'bind' below. Since sandbox_mmc_probe() is where the file gets mapped, the new image should be picked up without restarting U-Boot.
test/py/tests/test_android/test_avb.py temp_addr2 = 0x90002000 · line 27
Quoted 5 lines
test/py/tests/test_android/test_avb.py +3
-0@@ -22,7 +25,30 @@ temp_addr2 = 0x90002000 + ubman.run_command(f'bind /mmc{mmc_dev} mmc_sandbox') + # Run mmc list to ensure that mmc_sandbox driver is probed + ubman.run_command('mmc list')
The fixture has function scope, so this bind runs for each AVB test in the same U-Boot session. Since bind_by_node_path() doesn't check whether the node already has a device, each later test adds another mmc12 device with the same alias seq. The tests may still pass because the first device is found first, but it leaves junk in driver model. Please can you either unbind after the test (yield, then 'unbind /mmc12') or bind only if the device isn't already there? It would also be worth checking the bind output, so that a failure shows up here rather than later as a confusing 'avb verify' error.
I'm also wondering whether we lose something by not doing the disk-image setup upfront? Can we still run C tests on it?
Regards,
Simon
Re: [PATCH v2 09/10] test/py: avb: Add sandbox AVB testing with dedicated mmc12 device
Hi Simon,
Thank you for the review.
Quoted 31 lines · Simon Glass
Hi Mattijs,
Quoted 27 lines · Mattijs Korpershoek
test/py: avb: Add sandbox AVB testing with dedicated mmc12 device
Right now, sandbox runs the AVB tests using mmc1.img, which contains a fedora image.
This does not really make sense. We should test on an mmc device which has a proper vbmeta partition instead.Add a new mmc12 in sandbox which contains all required partitions for proper AVB testing.
Use the mmc12 device in the avb tests only when running in sandbox. The mmc12 DT node gets enabled by theavb_device_idfixture ifCMD_BINDis available.Note: the vbmeta.img has been generated using:
$ ./avbtool.py add_hash_footer \ --image boot.img \ --partition_name boot \ --partition_size 4194304[...]
arch/sandbox/dts/test.dts | 8 +++ test/py/tests/test_android/android_image.py | 15 ++++++ test/py/tests/test_android/test_abootimg.py | 77 +++++++++++++++++++++++++++++ test/py/tests/test_android/test_avb.py | 26 ++++++++++ 4 files changed, 126 insertions(+)
Quoted 12 lines
test/py/tests/test_android/test_avb.py temp_addr2 = 0x90002000 · line 29
Quoted 7 lines
test/py/tests/test_android/test_avb.py +5
-0@@ -22,7 +25,30 @@ temp_addr2 = 0x90002000 + mmc_dev = 0xc + fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') + if not os.path.exists(fname): + setup_android_avb_image(ubman) + ubman.restart_uboot()Just to check, is the restart needed? The mmc12 node is disabled, so nothing probes it until the 'bind' below. Since
sandbox_mmc_probe()is where the file gets mapped, the new image should be picked up without restarting U-Boot.
I did not give this enough thought and copied this from somewhere else. You are right, the restart is not needed. I will drop in in v3.
Quoted 12 lines
test/py/tests/test_android/test_avb.py temp_addr2 = 0x90002000 · line 27
Quoted 6 lines
test/py/tests/test_android/test_avb.py +3
-0@@ -22,7 +25,30 @@ temp_addr2 = 0x90002000 + ubman.run_command(f'bind /mmc{mmc_dev} mmc_sandbox') + # Run mmc list to ensure that mmc_sandbox driver is probed + ubman.run_command('mmc list')The fixture has function scope, so this bind runs for each AVB test in the same U-Boot session. Since
bind_by_node_path()doesn't check whether the node already has a device, each later test adds another mmc12 device with the same alias seq. The tests may still pass because the first device is found first, but it leaves junk in driver model.
Indeed:
=> dm tree mmc12
Class Seq Probed Driver Name
-----------------------------------------------------------
mmc 12 [ ] mmc_sandbox mmc12 blk 3 [ ] mmc_blk |-- mmc12.blk bootdev 14 [ ] mmc_bootdev `-- mmc12.bootdev
=> bind /mmc12 mmc_sandbox
=> dm tree mmc12
Class Seq Probed Driver Name
-----------------------------------------------------------
mmc 12 [ ] mmc_sandbox mmc12 blk 3 [ ] mmc_blk |-- mmc12.blk bootdev 14 [ ] mmc_bootdev |-- mmc12.bootdev mmc 12 [ ] mmc_sandbox `-- mmc12 blk 4 [ ] mmc_blk |-- mmc12.blk bootdev 15 [ ] mmc_bootdev `-- mmc12.bootdev
=>
Quoted 4 lines
please can you either unbind after the test (yield, then 'unbind /mmc12') or bind only if the device isn't already there? it would also be worth checking the bind output, so that a failure shows up here rather than later as a confusing 'avb verify' error.
I will check the bind output in v3.
I'l also do an unbind using yield followed by 'unbind /mmc12'
Quoted 3 lines
I'm also wondering whether we lose something by not doing the disk-image setup upfront? Can we still run C tests on it?
You mean doing the disk-image setup at the same time we create the other disk images in test_ut.py (test_ut_dm_init_bootstd) ?
I have considered this. I chose to create the image from the tests because it allows us to start from a clean state.
For example:
$ git clean -xdf $ ./test/py/test.py --bd sandbox --build -k test_avb_verify -s -v
If we create the images from another place (like test_ut.py) it means we have to run those first.
We could run C tests but mmc12.img has been made exclusively for the AVB tests for now.
If we need to access them from C we can revisit as of where to create the disk image.
Quoted 3 lines
Regards,
Simon
PATCH v2 10/10 test/py: avb: Fix find() logic when matching response strings
In reply to Mattijs KorpershoekThe AVB test suite runs some avb commands (such as "avb verify") and then parses the console output for success/failure.
It does so by using the string.find() function which returns:
* -1 when the subsystring does not exist
* 0/a positive number when the substring exists
For example, here is the output of:
$ ./test/py/test.py --bd sandbox --build -k test_avb_verify -s -v
Hit any key to stop autoboot: 0
=> => avb init 1
=> => avb verifyget_partition: no MMC device at slot 1get_partition: no MMC device at slot 1
avb_slot_verify.c:644: ERROR: boot: Error loading footer. Verification failed, reason: I/O error occurred while trying to load data => PASSED
Here, the test is marked as PASSED because assert(-1) will return success.
Fix the logic to fail these tests when the expected string is not found.
--- test/py/tests/test_android/test_avb.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
test/py/tests/test_android/test_avb.py +6 -6
@@ -64,7 +64,7 @@ def test_avb_verify(ubman, avb_device_id): response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb verify') - assert response.find(success_str) + assert response.find(success_str) != -1 @pytest.mark.buildconfigspec('cmd_avb')
@@ -79,7 +79,7 @@ def test_avb_mmc_uuid(ubman, avb_device_id): assert response == '' response = ubman.run_command('mmc rescan; mmc dev %d' % avb_device_id) - assert response.find('is current device') + assert response.find('is current device') != -1 part_lines = ubman.run_command('mmc part').splitlines() part_list = {}
@@ -133,22 +133,22 @@ def test_avb_mmc_read(ubman, avb_device_id): """ response = ubman.run_command('mmc rescan; mmc dev %d 0' % avb_device_id) - assert response.find('is current device') + assert response.find('is current device') != -1 response = ubman.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) - assert response.find('read: OK') + assert response.find('read: OK') != -1 response = ubman.run_command('avb init %x' % avb_device_id) assert response == '' response = ubman.run_command('avb read_part xloader 0 100 0x%x' % temp_addr2) - assert response.find('Read 512 bytes') + assert response.find('Read 512 bytes') != -1 # Now lets compare two buffers response = ubman.run_command('cmp 0x%x 0x%x 40' % (temp_addr, temp_addr2)) - assert response.find('64 word') + assert response.find('64 word') != -1 @pytest.mark.buildconfigspec('cmd_avb')
Signature · 1 line
2.56.0
Re: [PATCH v2 10/10] test/py: avb: Fix find() logic when matching response strings
Quoted 8 lines · Mattijs Korpershoek
The AVB test suite runs some avb commands (such as "avb verify") and then parses the console output for success/failure.
It does so by using the
string.find()function which returns:
* -1 when the subsystring does not exist
* 0/a positive number when the substring exists[...]
Signature · 1 line
Guillaume La Roque <[email protected]>
Re: [PATCH v2 10/10] test/py: avb: Fix find() logic when matching response strings
In reply to Mattijs KorpershoekHi Mattijs,
Quoted 7 lines · Mattijs Korpershoek
test/py: avb: Fix
find()logic when matching response stringsThe AVB test suite runs some avb commands (such as "avb verify") and then parses the console output for success/failure.
It does so by using the
string.find()function which returns:
* -1 when the subsystring does not exist
Typo: 'subsystring' should be 'substring'
Quoted 20 lines
* 0/a positive number when the substring exists
For example, here is the output of:
$ ./test/py/test.py --bd sandbox --build -k test_avb_verify -s -vHit any key to stop autoboot: 0
=> => avb init 1
=> => avb verifyget_partition: no MMC device at slot 1get_partition: no MMC device at slot 1
avb_slot_verify.c:644: ERROR: boot: Error loading footer. Verification failed, reason: I/O error occurred while trying to load data => PASSED
[...]test/py/tests/test_android/test_avb.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
test/py/tests/test_android/test_avb.py def test_avb_verify(ubman, avb_device_id): · line 64
Quoted 2 lines
test/py/tests/test_android/test_avb.py +1
-1@@ -64,7 +64,7 @@ def test_avb_verify(ubman, avb_device_id): - assert response.find(success_str) + assert response.find(success_str) != -1
It would be worth using the 'in' operator here and elsewhere, e.g. 'assert success_str in response', since that is the usual Python idiom. It also helps with debugging: pytest's assertion rewriting then shows both the expected string and the console output on failure, whereas '!= -1' just gives '-1 != -1'. What do you think?
Regards,
Simon
Re: [PATCH v2 10/10] test/py: avb: Fix find() logic when matching response strings
Hi Simon,
Thank you for the review.
Quoted 5 lines · Simon Glass
Hi Mattijs,
Quoted 2 lines · Mattijs Korpershoek
test/py: avb: Fix
find()logic when matching response strings
Quoted 7 lines
Quoted 5 lines
The AVB test suite runs some avb commands (such as "avb verify") and then parses the console output for success/failure.
It does so by using the
string.find()function which returns:
* -1 when the subsystring does not existTypo: 'subsystring' should be 'substring'
Will fix in v3.
Quoted 19 lines
Quoted 18 lines
* 0/a positive number when the substring exists
For example, here is the output of:
$ ./test/py/test.py --bd sandbox --build -k test_avb_verify -s -vHit any key to stop autoboot: 0
=> => avb init 1
=> => avb verifyget_partition: no MMC device at slot 1get_partition: no MMC device at slot 1
avb_slot_verify.c:644: ERROR: boot: Error loading footer. Verification failed, reason: I/O error occurred while trying to load data => PASSED
[...]test/py/tests/test_android/test_avb.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Quoted 10 lines
test/py/tests/test_android/test_avb.py def test_avb_verify(ubman, avb_device_id): · line 64
Quoted 4 lines
test/py/tests/test_android/test_avb.py +1
-1@@ -64,7 +64,7 @@ def test_avb_verify(ubman, avb_device_id): - assert response.find(success_str) + assert response.find(success_str) != -1It would be worth using the 'in' operator here and elsewhere, e.g. 'assert
success_strin response', since that is the usual Python idiom. It also helps with debugging: pytest's assertion rewriting then shows both the expected string and the console output on failure, whereas '!= -1' just gives '-1 != -1'. What do you think?
Indeed, that's a good suggestion, thank you. Will do in v3.
Quoted 3 lines
Regards,
Simon