diff options
| author | Tom Rini <[email protected]> | 2026-04-06 12:16:57 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-04-06 12:16:57 -0600 |
| commit | 93f84ee022a8401421cdaab84fe7d106d83fdb4a (patch) | |
| tree | fb15a4af876e8faf9893fd86c1c0e127265dbe9a /test | |
| parent | 88dc2788777babfd6322fa655df549a019aa1e69 (diff) | |
| parent | e2138cf1e6088f12ffa874e87cc8f4b198378635 (diff) | |
Merge branch 'next'
Diffstat (limited to 'test')
| -rw-r--r-- | test/Kconfig | 1 | ||||
| -rw-r--r-- | test/boot/bootflow.c | 57 | ||||
| -rw-r--r-- | test/cmd/exit.c | 3 | ||||
| -rw-r--r-- | test/cmd/test_echo.c | 3 | ||||
| -rw-r--r-- | test/cmd/test_pause.c | 3 | ||||
| -rw-r--r-- | test/dm/blk.c | 3 | ||||
| -rw-r--r-- | test/dm/i3c.c | 2 | ||||
| -rw-r--r-- | test/dm/virtio_device.c | 1 | ||||
| -rw-r--r-- | test/dm/virtio_rng.c | 14 | ||||
| -rw-r--r-- | test/hush/if.c | 81 | ||||
| -rw-r--r-- | test/lib/test_print.c | 3 | ||||
| -rw-r--r-- | test/log/log_filter.c | 4 | ||||
| -rw-r--r-- | test/py/tests/fs_helper.py | 111 | ||||
| -rw-r--r-- | test/py/tests/test_efi_ecpt.py | 42 | ||||
| -rw-r--r-- | test/py/tests/test_gpio.py | 36 | ||||
| -rw-r--r-- | test/py/tests/test_ut.py | 47 |
16 files changed, 368 insertions, 43 deletions
diff --git a/test/Kconfig b/test/Kconfig index 24105c13304..14b5b0e2a9a 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -15,6 +15,7 @@ config SPL_UNIT_TEST bool "Unit tests in SPL" depends on SPL # We need to be able to unbind devices for tests to work + select SPL_DM select SPL_DM_DEVICE_REMOVE help Select this to enable unit tests in SPL. Most test are designed for diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index a56435d053f..56ee1952357 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -31,6 +31,7 @@ DECLARE_GLOBAL_DATA_PTR; extern U_BOOT_DRIVER(bootmeth_android); extern U_BOOT_DRIVER(bootmeth_cros); +extern U_BOOT_DRIVER(bootmeth_rauc); extern U_BOOT_DRIVER(bootmeth_2script); /* Use this as the vendor for EFI to tell the app to exit boot services */ @@ -1392,6 +1393,62 @@ static int bootflow_efi(struct unit_test_state *uts) } BOOTSTD_TEST(bootflow_efi, UTF_CONSOLE); +/* Test RAUC bootmeth */ +static int bootflow_rauc(struct unit_test_state *uts) +{ + const char *mmc_dev = "mmc10"; + struct bootstd_priv *std; + struct udevice *bootstd; + static const char *order[] = {NULL, NULL}; + const char **old_order; + ofnode root; + ofnode node; + + order[0] = mmc_dev; + + if (!CONFIG_IS_ENABLED(BOOTMETH_RAUC)) + return -EAGAIN; + + /* Enable the requested mmc node since we need a different bootflow */ + root = oftree_root(oftree_default()); + node = ofnode_find_subnode(root, mmc_dev); + ut_assert(ofnode_valid(node)); + ut_assertok(lists_bind_fdt(gd->dm_root, node, NULL, NULL, false)); + + /* Enable the rauc bootmeth */ + ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); + ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_rauc), + "rauc", 0, ofnode_null(), NULL)); + + /* Change the device and bootmeth order */ + std = dev_get_priv(bootstd); + old_order = std->bootdev_order; + std->bootdev_order = order; + + ut_assertok(bootmeth_set_order("rauc")); + + /* Run scan and list */ + ut_assertok(run_command("bootflow scan", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("bootflow list", 0)); + + ut_assert_nextlinen("Showing all"); + ut_assert_nextlinen("Seq"); + ut_assert_nextlinen("---"); + ut_assert_nextlinen(" 0 rauc ready mmc 0 mmc10.bootdev.whole "); + ut_assert_nextlinen("---"); + ut_assert_skip_to_line("(1 bootflow, 1 valid)"); + + ut_assert_console_end(); + + /* Restore the order used by the device tree */ + std->bootdev_order = old_order; + + return 0; +} +BOOTSTD_TEST(bootflow_rauc, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); + /* Check 'bootflow scan' provides a list of images */ static int bootstd_images(struct unit_test_state *uts) { diff --git a/test/cmd/exit.c b/test/cmd/exit.c index fdde054b928..e20bc5f7b98 100644 --- a/test/cmd/exit.c +++ b/test/cmd/exit.c @@ -7,11 +7,8 @@ #include <console.h> #include <mapmem.h> -#include <asm/global_data.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - /* Declare a new exit test */ #define EXIT_TEST(_name, _flags) UNIT_TEST(_name, _flags, exit) diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c index 8b306cc907f..7ed534742f7 100644 --- a/test/cmd/test_echo.c +++ b/test/cmd/test_echo.c @@ -6,14 +6,11 @@ */ #include <command.h> -#include <asm/global_data.h> #include <display_options.h> #include <test/lib.h> #include <test/test.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - struct test_data { char *cmd; char *expected; diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c index 174c31a3852..b2cf60d3e74 100644 --- a/test/cmd/test_pause.c +++ b/test/cmd/test_pause.c @@ -5,12 +5,9 @@ * Copyright 2022, Samuel Dionne-Riel <[email protected]> */ -#include <asm/global_data.h> #include <test/lib.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - static int lib_test_hush_pause(struct unit_test_state *uts) { /* Test default message */ diff --git a/test/dm/blk.c b/test/dm/blk.c index 1b928b27d9c..f67869107da 100644 --- a/test/dm/blk.c +++ b/test/dm/blk.c @@ -8,14 +8,11 @@ #include <part.h> #include <sandbox_host.h> #include <usb.h> -#include <asm/global_data.h> #include <asm/state.h> #include <dm/test.h> #include <test/test.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - /* Test that block devices can be created */ static int dm_test_blk_base(struct unit_test_state *uts) { diff --git a/test/dm/i3c.c b/test/dm/i3c.c index 81336e67555..816ecabd722 100644 --- a/test/dm/i3c.c +++ b/test/dm/i3c.c @@ -8,8 +8,6 @@ #include <dm/test.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - /* Basic test of the i3c uclass */ static int dm_test_i3c_base(struct unit_test_state *uts) { diff --git a/test/dm/virtio_device.c b/test/dm/virtio_device.c index 53414e4d3a4..c2cd0630d97 100644 --- a/test/dm/virtio_device.c +++ b/test/dm/virtio_device.c @@ -40,6 +40,7 @@ static int dm_test_virtio_base(struct unit_test_state *uts) ut_assertok(virtio_get_status(dev, &status)); ut_asserteq(VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK | + VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_FEATURES_OK, status); return 0; diff --git a/test/dm/virtio_rng.c b/test/dm/virtio_rng.c index e404b08484e..5fd56ade586 100644 --- a/test/dm/virtio_rng.c +++ b/test/dm/virtio_rng.c @@ -19,12 +19,19 @@ struct virtio_rng_priv { struct virtqueue *rng_vq; }; +#define BUFFER_SIZE 16 +#define CANARY "CANARYCANARYCANARYCANARY" + /* Test the virtio-rng driver validates the used size */ static int dm_test_virtio_rng_check_len(struct unit_test_state *uts) { struct udevice *bus, *dev; struct virtio_rng_priv *priv; - u8 buffer[16]; + u8 buffer[BUFFER_SIZE + sizeof(CANARY)]; + + /* write known data to buffer */ + memset(buffer, 0xaa, BUFFER_SIZE); + memcpy(buffer + BUFFER_SIZE, CANARY, sizeof(CANARY)); /* check probe success */ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus)); @@ -44,7 +51,10 @@ static int dm_test_virtio_rng_check_len(struct unit_test_state *uts) priv->rng_vq->vring.used->ring[0].len = U32_MAX; /* check the driver gracefully handles the error */ - ut_asserteq(-EIO, dm_rng_read(dev, buffer, sizeof(buffer))); + dm_rng_read(dev, buffer, BUFFER_SIZE); + + /* check for the canary bytes behind the real buffer */ + ut_asserteq_mem(buffer + BUFFER_SIZE, CANARY, sizeof(CANARY)); return 0; } diff --git a/test/hush/if.c b/test/hush/if.c index ea615b246a9..6117c37e53c 100644 --- a/test/hush/if.c +++ b/test/hush/if.c @@ -32,6 +32,19 @@ static int hush_test_if_base(struct unit_test_state *uts) sprintf(if_formatted, if_format, "false"); ut_asserteq(1, run_command(if_formatted, 0)); + sprintf(if_formatted, if_format, "test"); + ut_asserteq(1, run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "test ''"); + ut_asserteq(1, run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "test 'abc'"); + ut_assertok(run_command(if_formatted, 0)); + + /* Special case: 'test -n' interpreted as 'test -n ""'. */ + sprintf(if_formatted, if_format, "test '-n'"); + ut_asserteq(1, run_command(if_formatted, 0)); + return 0; } HUSH_TEST(hush_test_if_base, 0); @@ -315,3 +328,71 @@ static int hush_test_if_z_operator(struct unit_test_state *uts) return 0; } HUSH_TEST(hush_test_if_z_operator, 0); + +static int hush_test_lbracket_alias(struct unit_test_state *uts) +{ + char if_formatted[128]; + const char *missing_rbracket_error = "[: missing terminating ]"; + + sprintf(if_formatted, if_format, "[ aaa = aaa ]"); + ut_assertok(run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ aaa = bbb ]"); + ut_asserteq(1, run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ aaa = aaa"); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + sprintf(if_formatted, if_format, "[ aaa = bbb"); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + sprintf(if_formatted, if_format, "[ aaa = aaa]"); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + sprintf(if_formatted, if_format, "[ aaa = bbb]"); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + sprintf(if_formatted, if_format, "[ aaa != aaa -o bbb != bbb ]"); + ut_asserteq(1, run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ aaa != aaa -o bbb = bbb ]"); + ut_assertok(run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ ! aaa != aaa -o ! bbb != bbb ]"); + ut_assertok(run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ ! aaa != aaa -o ! bbb = bbb ]"); + ut_assertok(run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ ]"); + ut_asserteq(1, run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "["); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + sprintf(if_formatted, if_format, "[ '' ]"); + ut_asserteq(1, run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ ''"); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + sprintf(if_formatted, if_format, "[ 'abc' ]"); + ut_assertok(run_command(if_formatted, 0)); + + sprintf(if_formatted, if_format, "[ 'abc'"); + ut_asserteq(1, run_command(if_formatted, 0)); + ut_assert_nextline(missing_rbracket_error); + + /* Special case: '[ -n ]' interpreted as '[ -n "" ]'. */ + sprintf(if_formatted, if_format, "[ -n ]"); + ut_asserteq(1, run_command(if_formatted, 0)); + + return 0; +} +HUSH_TEST(hush_test_lbracket_alias, UTF_CONSOLE); diff --git a/test/lib/test_print.c b/test/lib/test_print.c index cd7f3f85769..2aeb034b121 100644 --- a/test/lib/test_print.c +++ b/test/lib/test_print.c @@ -7,13 +7,10 @@ #include <command.h> #include <display_options.h> -#include <asm/global_data.h> #include <test/lib.h> #include <test/test.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - static int test_print_freq(struct unit_test_state *uts, uint64_t freq, char *expected) { diff --git a/test/log/log_filter.c b/test/log/log_filter.c index 8622dcf2913..147b83980cf 100644 --- a/test/log/log_filter.c +++ b/test/log/log_filter.c @@ -5,12 +5,10 @@ #include <console.h> #include <log.h> -#include <asm/global_data.h> +#include <vsprintf.h> #include <test/log.h> #include <test/ut.h> -DECLARE_GLOBAL_DATA_PTR; - /* Test invalid options */ static int log_test_filter_invalid(struct unit_test_state *uts) { diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index b8a22b22806..800376b1e7d 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -7,9 +7,97 @@ import re import os +import shutil from subprocess import call, check_call, check_output, CalledProcessError +from subprocess import DEVNULL +import tempfile -def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): +# size_gran (int): Size granularity of file system image in bytes +SIZE_GRAN = 1 << 20 + + +class FsHelper: + """Creating a filesystem containing test files + + Usage: + with FsHelper(ubman.config, 'ext4', 10, 'mmc1') as fsh: + # create files in the self.srcdir directory + fsh.mk_fs() + # Now use the filesystem + + # The filesystem and srcdir are erased after the 'with' statement. + + It is also possible to use an existing srcdir: + + with FsHelper(ubman.config, 'fat32', 10, 'usb2') as fsh: + fsh.srcdir = src_dir + fsh.mk_fs() + ... + + Properties: + fs_img (str): Filename for the filesystem image + """ + def __init__(self, config, fs_type, size_mb, prefix): + """Set up a new object + + Args: + config (u_boot_config): U-Boot configuration + fs_type (str): File system type: one of ext2, ext3, ext4, vfat, + fat12, fat16, fat32, exfat, fs_generic (which means vfat) + size_mb (int): Size of file system in MB + prefix (str): Prefix string of volume's file name + """ + if fs_type not in ['fat12', 'fat16', 'fat32', 'vfat', + 'ext2', 'ext3', 'ext4', + 'exfat', 'fs_generic']: + raise ValueError(f"Unsupported filesystem type '{fs_type}'") + + self.config = config + self.fs_type = fs_type + self.size_mb = size_mb + self.prefix = prefix + self.quiet = True + self.fs_img = None + self.tmpdir = None + self.srcdir = None + self._do_cleanup = False + + def mk_fs(self): + """Make a new filesystem and copy in the files""" + self.setup() + self._do_cleanup = True + self.fs_img = mk_fs(self.config, self.fs_type, self.size_mb << 20, + self.prefix, self.srcdir, quiet=self.quiet) + + def setup(self): + """Set up the srcdir ready to receive files""" + if not self.srcdir: + if self.config: + self.srcdir = os.path.join(self.config.persistent_data_dir, + f'{self.prefix}.{self.fs_type}.tmp') + if os.path.exists(self.srcdir): + shutil.rmtree(self.srcdir) + os.mkdir(self.srcdir) + else: + self.tmpdir = tempfile.TemporaryDirectory('fs_helper') + self.srcdir = self.tmpdir.name + + def cleanup(self): + """Remove created image""" + if self.tmpdir: + self.tmpdir.cleanup() + if self._do_cleanup: + os.remove(self.fs_img) + + def __enter__(self): + self.setup() + return self + + def __exit__(self, extype, value, traceback): + self.cleanup() + + +def mk_fs(config, fs_type, size, prefix, src_dir=None, fs_img=None, quiet=False): """Create a file system volume Args: @@ -18,12 +106,16 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): size (int): Size of file system in bytes prefix (str): Prefix string of volume's file name src_dir (str): Root directory to use, or None for none - size_gran (int): Size granularity of file system image in bytes + fs_img (str or None): Leaf filename for image, or None to use a + default name. The image is always placed under + persistent_data_dir. + quiet (bool): Suppress non-error output Raises: CalledProcessError: if any error occurs when creating the filesystem """ - fs_img = f'{prefix}.{fs_type}.img' + if not fs_img: + fs_img = f'{prefix}.{fs_type}.img' fs_img = os.path.join(config.persistent_data_dir, fs_img) if fs_type == 'fat12': @@ -48,7 +140,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): elif fs_lnxtype != 'vfat' and fs_lnxtype != 'exfat': raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}') - count = (size + size_gran - 1) // size_gran + count = (size + SIZE_GRAN - 1) // SIZE_GRAN # Some distributions do not add /sbin to the default PATH, where mkfs lives if '/sbin' not in os.environ["PATH"].split(os.pathsep): @@ -56,16 +148,19 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): try: check_call(f'rm -f {fs_img}', shell=True) - check_call(f'truncate -s $(( {size_gran} * {count} )) {fs_img}', + check_call(f'truncate -s $(( {SIZE_GRAN} * {count} )) {fs_img}', shell=True) - check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True) + check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True, + stdout=DEVNULL if quiet else None) if fs_type == 'ext4': sb_content = check_output(f'tune2fs -l {fs_img}', shell=True).decode() if 'metadata_csum' in sb_content: check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) elif fs_lnxtype == 'vfat' and src_dir: - check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True) + flags = f"-smpQ{'' if quiet else 'v'}" + check_call(f'mcopy -i {fs_img} {flags} {src_dir}/* ::/', + shell=True) elif fs_lnxtype == 'exfat' and src_dir: check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True) return fs_img @@ -75,7 +170,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): def setup_image(ubman, devnum, part_type, img_size=20, second_part=False, basename='mmc'): - """Create a disk image with a single partition + """Create a disk image with one or two partitions Args: ubman (ConsoleBase): Console to use diff --git a/test/py/tests/test_efi_ecpt.py b/test/py/tests/test_efi_ecpt.py new file mode 100644 index 00000000000..632a6b90bad --- /dev/null +++ b/test/py/tests/test_efi_ecpt.py @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +""" Unit test for the EFI Conformance Profiles Table (ECPT) +""" + +import pytest + + [email protected]('cmd_efidebug') [email protected]('efi_ecpt') +def test_efi_ecpt(ubman) -> None: + """ Unit test for the ECPT + This test assumes nothing about the ECPT contents, it just checks that the + ECPT table is there and that the efidebug ecpt command does not fail. + + Args: + ubman -- U-Boot console + """ + response = ubman.run_command('efidebug tables') + assert ('36122546-f7e7-4c8f-bd9b-eb8525b50c0b ' + 'EFI Conformance Profiles Table') in response + + response = ubman.run_command('efidebug ecpt') + assert 'Unknown command' not in response + assert 'Configure UEFI environment' not in response + assert 'Usage:' not in response + assert 'table missing' not in response + + [email protected]('cmd_efidebug') [email protected]('efi_ecpt') [email protected]('efi_ebbr_2_1_conformance') +def test_efi_ecpt_ebbr_2_1(ubman) -> None: + """ Unit test for the ECPT, with EBBR 2.1 profile + This test uses the efidebug ecpt command to dump the ECPT and check that + the EBBR 2.1 conformance profile is there. + + Args: + ubman -- U-Boot console + """ + response = ubman.run_command('efidebug ecpt') + assert ('cce33c35-74ac-4087-bce7-8b29b02eeb27 ' + 'EFI EBBR 2.1 Conformance Profile') in response diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py index 46b674b7653..eba7bab7589 100644 --- a/test/py/tests/test_gpio.py +++ b/test/py/tests/test_gpio.py @@ -4,8 +4,6 @@ # Copyright (c) 2020 Alex Kiernan <[email protected]> import pytest -import time -import utils """ test_gpio_input is intended to test the fix 4dbc107f4683. @@ -136,8 +134,12 @@ def test_gpio_set_generic(ubman): if not f: pytest.skip("gpio not configured") - gpio_pin_adr = f['gpio_op_pin']; - gpio_set_value = f['gpio_set_value']; + gpio_pin_adr = f.get('gpio_op_pin') + + if gpio_pin_adr is None: + pytest.skip("gpio_op_pin is not configured") + + gpio_set_value = f['gpio_set_value'] cmd = 'gpio set ' + gpio_pin_adr @@ -160,8 +162,12 @@ def test_gpio_clear_generic(ubman): if not f: pytest.skip("gpio not configured") - gpio_pin_adr = f['gpio_op_pin']; - gpio_clear_value = f['gpio_clear_value']; + gpio_pin_adr = f.get('gpio_op_pin') + + if gpio_pin_adr is None: + pytest.skip("gpio_op_pin is not configured") + + gpio_clear_value = f['gpio_clear_value'] cmd = 'gpio clear ' + gpio_pin_adr @@ -184,9 +190,13 @@ def test_gpio_toggle_generic(ubman): if not f: pytest.skip("gpio not configured") - gpio_pin_adr = f['gpio_op_pin']; - gpio_set_value = f['gpio_set_value']; - gpio_clear_value = f['gpio_clear_value']; + gpio_pin_adr = f.get('gpio_op_pin') + + if gpio_pin_adr is None: + pytest.skip("gpio_op_pin is not configured") + + gpio_set_value = f['gpio_set_value'] + gpio_clear_value = f['gpio_clear_value'] cmd = 'gpio set ' + gpio_pin_adr response = ubman.run_command(cmd) @@ -212,8 +222,8 @@ def test_gpio_input_generic(ubman): if not f: pytest.skip("gpio not configured") - gpio_pin_adr = f['gpio_ip_pin_clear']; - gpio_clear_value = f['gpio_clear_value']; + gpio_pin_adr = f['gpio_ip_pin_clear'] + gpio_clear_value = f['gpio_clear_value'] cmd = 'gpio input ' + gpio_pin_adr @@ -222,8 +232,8 @@ def test_gpio_input_generic(ubman): assert good_response in response - gpio_pin_adr = f['gpio_ip_pin_set']; - gpio_set_value = f['gpio_set_value']; + gpio_pin_adr = f['gpio_ip_pin_set'] + gpio_set_value = f['gpio_set_value'] cmd = 'gpio input ' + gpio_pin_adr diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index b7166d59943..98641a46c1d 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -554,6 +554,52 @@ def setup_efi_image(ubman): utils.run_and_log(ubman, f'rm -rf {mnt}') utils.run_and_log(ubman, f'rm -f {fsfile}') +def setup_rauc_image(ubman): + """Create a 40MB disk image with an A/B RAUC system on it""" + mmc_dev = 10 + fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') + mnt = ubman.config.persistent_data_dir + + spec = 'type=c, size=8M, start=1M, bootable\n' \ + 'type=83, size=10M\n' \ + 'type=c, size=8M, bootable\n' \ + 'type=83, size=10M' + + utils.run_and_log(ubman, f'qemu-img create {fname} 40M') + utils.run_and_log(ubman, ['sh', '-c', f'printf "{spec}" | sfdisk {fname}']) + + # Generate boot script + script = '# dummy boot script' + bootdir = os.path.join(mnt, 'boot') + utils.run_and_log(ubman, f'mkdir -p {bootdir}') + cmd_fname = os.path.join(bootdir, 'boot.cmd') + scr_fname = os.path.join(bootdir, 'boot.scr') + with open(cmd_fname, 'w', encoding='ascii') as outf: + print(script, file=outf) + + mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') + utils.run_and_log( + ubman, f'{mkimage} -C none -A arm -T script -d {cmd_fname} {scr_fname}') + utils.run_and_log(ubman, f'rm -f {cmd_fname}') + + # Generate empty rootfs + rootdir = os.path.join(mnt, 'root') + utils.run_and_log(ubman, f'mkdir -p {rootdir}') + + # Create boot filesystem image with boot script in it and copy to disk image + fsfile = f'rauc_boot.fat32.img' + fs_helper.mk_fs(ubman.config, 'fat32', 0x800000, fsfile.split('.')[0], bootdir) + utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=1 conv=notrunc') + utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=19 conv=notrunc') + utils.run_and_log(ubman, f'rm -f {scr_fname}') + + # Create empty root filesystem image and copy to disk image + fsfile = f'rauc_root.ext4.img' + fs_helper.mk_fs(ubman.config, 'ext4', 0xa00000, fsfile.split('.')[0], rootdir) + utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=9 conv=notrunc') + utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=27 conv=notrunc') + utils.run_and_log(ubman, f'rm -f {fsfile}') + @pytest.mark.buildconfigspec('cmd_bootflow') @pytest.mark.buildconfigspec('sandbox') def test_ut_dm_init_bootstd(ubman): @@ -565,6 +611,7 @@ def test_ut_dm_init_bootstd(ubman): setup_cros_image(ubman) setup_android_image(ubman) setup_efi_image(ubman) + setup_rauc_image(ubman) # Restart so that the new mmc1.img is picked up ubman.restart_uboot() |
