diff options
author | Sean Anderson <seanga2@gmail.com> | 2023-10-14 16:47:57 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-10-17 20:50:52 -0400 |
commit | c56468a60d503aee45bc39542307a9d8e6cf5a40 (patch) | |
tree | a153960c49310a594b603969a18ffb4c58e19cb8 | |
parent | a24be84df9d8e31de40de0d2270470e19c784bd4 (diff) | |
download | u-boot-c56468a60d503aee45bc39542307a9d8e6cf5a40.zip u-boot-c56468a60d503aee45bc39542307a9d8e6cf5a40.tar.gz u-boot-c56468a60d503aee45bc39542307a9d8e6cf5a40.tar.bz2 |
test: spl: Split tests up and use some configs
In order to make adding new spl unit tests easier, especially when they may
have many dependencies, add some Kconfigs for the existing image test.
Split it into the parts which are generic (such as callbacks) and the
test-specific parts.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | test/Kconfig | 1 | ||||
-rw-r--r-- | test/Makefile | 5 | ||||
-rw-r--r-- | test/image/Kconfig | 20 | ||||
-rw-r--r-- | test/image/Makefile | 3 | ||||
-rw-r--r-- | test/image/spl_load.c | 76 | ||||
-rw-r--r-- | test/image/spl_load_os.c | 80 |
6 files changed, 106 insertions, 79 deletions
diff --git a/test/Kconfig b/test/Kconfig index 830245b..ca648d2 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -101,6 +101,7 @@ config UT_UNICODE source "test/dm/Kconfig" source "test/env/Kconfig" +source "test/image/Kconfig" source "test/lib/Kconfig" source "test/optee/Kconfig" source "test/overlay/Kconfig" diff --git a/test/Makefile b/test/Makefile index 1787736..8e1fed2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,9 +3,6 @@ # (C) Copyright 2012 The Chromium Authors obj-y += test-main.o -ifdef CONFIG_SPL_LOAD_FIT -obj-$(CONFIG_SANDBOX) += image/ -endif ifneq ($(CONFIG_$(SPL_)BLOBLIST),) obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o @@ -30,4 +27,6 @@ obj-$(CONFIG_UNIT_TEST) += boot/ obj-$(CONFIG_UNIT_TEST) += common/ obj-y += log/ obj-$(CONFIG_$(SPL_)UT_UNICODE) += unicode_ut.o +else +obj-$(CONFIG_SPL_UT_LOAD) += image/ endif diff --git a/test/image/Kconfig b/test/image/Kconfig new file mode 100644 index 0000000..70ffe0f --- /dev/null +++ b/test/image/Kconfig @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2023 Sean Anderson <seanga2@gmail.com> + +config SPL_UT_LOAD + bool "Unit tests for SPL load methods" + depends on SPL_UNIT_TEST + default y if SANDBOX + help + Test various SPL load methods. + +if SPL_UT_LOAD + +config SPL_UT_LOAD_OS + bool "Test loading from the host OS" + depends on SANDBOX && SPL_LOAD_FIT + default y + help + Smoke test to ensure that loading U-boot works in sandbox. + +endif diff --git a/test/image/Makefile b/test/image/Makefile index c4039df..f7ae996 100644 --- a/test/image/Makefile +++ b/test/image/Makefile @@ -2,4 +2,5 @@ # # Copyright 2021 Google LLC -obj-$(CONFIG_SPL_BUILD) += spl_load.o +obj-y += spl_load.o +obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o diff --git a/test/image/spl_load.c b/test/image/spl_load.c index 4e27ff4..1a57bf8 100644 --- a/test/image/spl_load.c +++ b/test/image/spl_load.c @@ -1,48 +1,10 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright 2021 Google LLC - * Written by Simon Glass <sjg@chromium.org> + * Copyright (C) 2023 Sean Anderson <seanga2@gmail.com> */ #include <common.h> -#include <image.h> #include <mapmem.h> -#include <os.h> -#include <spl.h> -#include <test/ut.h> - -/* Declare a new SPL test */ -#define SPL_TEST(_name, _flags) UNIT_TEST(_name, _flags, spl_test) - -/* Context used for this test */ -struct text_ctx { - int fd; -}; - -static ulong read_fit_image(struct spl_load_info *load, ulong sector, - ulong count, void *buf) -{ - struct text_ctx *text_ctx = load->priv; - off_t offset, ret; - ssize_t res; - - offset = sector * load->bl_len; - ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET); - if (ret != offset) { - printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset, - ret, errno); - return 0; - } - - res = os_read(text_ctx->fd, buf, count * load->bl_len); - if (res == -1) { - printf("Failed to read %lx bytes, got %ld (errno=%d)\n", - count * load->bl_len, res, errno); - return 0; - } - - return count; -} int board_fit_config_name_match(const char *name) { @@ -53,39 +15,3 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size) { return map_sysmem(0x100000, 0); } - -static int spl_test_load(struct unit_test_state *uts) -{ - struct spl_image_info image; - struct legacy_img_hdr *header; - struct text_ctx text_ctx; - struct spl_load_info load; - char fname[256]; - int ret; - int fd; - - memset(&load, '\0', sizeof(load)); - load.bl_len = 512; - load.read = read_fit_image; - - ret = sandbox_find_next_phase(fname, sizeof(fname), true); - if (ret) { - printf("(%s not found, error %d)\n", fname, ret); - return ret; - } - load.filename = fname; - - header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); - - fd = os_open(fname, OS_O_RDONLY); - ut_assert(fd >= 0); - ut_asserteq(512, os_read(fd, header, 512)); - text_ctx.fd = fd; - - load.priv = &text_ctx; - - ut_assertok(spl_load_simple_fit(&image, &load, 0, header)); - - return 0; -} -SPL_TEST(spl_test_load, 0); diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c new file mode 100644 index 0000000..bf374f2 --- /dev/null +++ b/test/image/spl_load_os.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 Google LLC + * Written by Simon Glass <sjg@chromium.org> + */ + +#include <common.h> +#include <image.h> +#include <os.h> +#include <spl.h> +#include <test/ut.h> + +/* Declare a new SPL test */ +#define SPL_TEST(_name, _flags) UNIT_TEST(_name, _flags, spl_test) + +/* Context used for this test */ +struct text_ctx { + int fd; +}; + +static ulong read_fit_image(struct spl_load_info *load, ulong sector, + ulong count, void *buf) +{ + struct text_ctx *text_ctx = load->priv; + off_t offset, ret; + ssize_t res; + + offset = sector * load->bl_len; + ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET); + if (ret != offset) { + printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset, + ret, errno); + return 0; + } + + res = os_read(text_ctx->fd, buf, count * load->bl_len); + if (res == -1) { + printf("Failed to read %lx bytes, got %ld (errno=%d)\n", + count * load->bl_len, res, errno); + return 0; + } + + return count; +} + +static int spl_test_load(struct unit_test_state *uts) +{ + struct spl_image_info image; + struct legacy_img_hdr *header; + struct text_ctx text_ctx; + struct spl_load_info load; + char fname[256]; + int ret; + int fd; + + memset(&load, '\0', sizeof(load)); + load.bl_len = 512; + load.read = read_fit_image; + + ret = sandbox_find_next_phase(fname, sizeof(fname), true); + if (ret) { + printf("(%s not found, error %d)\n", fname, ret); + return ret; + } + load.filename = fname; + + header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + + fd = os_open(fname, OS_O_RDONLY); + ut_assert(fd >= 0); + ut_asserteq(512, os_read(fd, header, 512)); + text_ctx.fd = fd; + + load.priv = &text_ctx; + + ut_assertok(spl_load_simple_fit(&image, &load, 0, header)); + + return 0; +} +SPL_TEST(spl_test_load, 0); |