From ea29bad9cff2fd88d172276b58859f01649fe444 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 7 Feb 2025 11:30:39 -0700 Subject: test: Tweak FDT-overlay tests Use fdt_overlay consistently in the identifiers and file/dir names. Signed-off-by: Simon Glass --- Makefile | 2 +- include/test/fdt_overlay.h | 15 ++ include/test/overlay.h | 15 -- include/test/suites.h | 4 +- test/Kconfig | 2 +- test/cmd_ut.c | 8 +- test/fdt_overlay/Kconfig | 10 + test/fdt_overlay/Makefile | 14 ++ test/fdt_overlay/cmd_ut_fdt_overlay.c | 281 +++++++++++++++++++++++++ test/fdt_overlay/test-fdt-base.dts | 20 ++ test/fdt_overlay/test-fdt-overlay-stacked.dtso | 20 ++ test/fdt_overlay/test-fdt-overlay.dtso | 95 +++++++++ test/overlay/Kconfig | 10 - test/overlay/Makefile | 14 -- test/overlay/cmd_ut_overlay.c | 280 ------------------------ test/overlay/test-fdt-base.dts | 20 -- test/overlay/test-fdt-overlay-stacked.dtso | 20 -- test/overlay/test-fdt-overlay.dtso | 95 --------- test/py/tests/test_suite.py | 4 +- 19 files changed, 465 insertions(+), 464 deletions(-) create mode 100644 include/test/fdt_overlay.h delete mode 100644 include/test/overlay.h create mode 100644 test/fdt_overlay/Kconfig create mode 100644 test/fdt_overlay/Makefile create mode 100644 test/fdt_overlay/cmd_ut_fdt_overlay.c create mode 100644 test/fdt_overlay/test-fdt-base.dts create mode 100644 test/fdt_overlay/test-fdt-overlay-stacked.dtso create mode 100644 test/fdt_overlay/test-fdt-overlay.dtso delete mode 100644 test/overlay/Kconfig delete mode 100644 test/overlay/Makefile delete mode 100644 test/overlay/cmd_ut_overlay.c delete mode 100644 test/overlay/test-fdt-base.dts delete mode 100644 test/overlay/test-fdt-overlay-stacked.dtso delete mode 100644 test/overlay/test-fdt-overlay.dtso diff --git a/Makefile b/Makefile index b32606b69f5..a9cc235b6da 100644 --- a/Makefile +++ b/Makefile @@ -895,7 +895,7 @@ endif libs-$(CONFIG_$(PHASE_)UNIT_TEST) += test/ libs-$(CONFIG_UT_ENV) += test/env/ libs-$(CONFIG_UT_OPTEE) += test/optee/ -libs-$(CONFIG_UT_OVERLAY) += test/overlay/ +libs-$(CONFIG_UT_FDT_OVERLAY) += test/fdt_overlay/ libs-y += $(if $(wildcard $(srctree)/board/$(BOARDDIR)/Makefile),board/$(BOARDDIR)/) diff --git a/include/test/fdt_overlay.h b/include/test/fdt_overlay.h new file mode 100644 index 00000000000..34e8020a496 --- /dev/null +++ b/include/test/fdt_overlay.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + */ + +#ifndef __TEST_OVERLAY_H__ +#define __TEST_OVERLAY_H__ + +#include + +/* Declare a new FDT-overlay test */ +#define FDT_OVERLAY_TEST(_name, _flags) UNIT_TEST(_name, _flags, fdt_overlay) + +#endif /* __TEST_OVERLAY_H__ */ diff --git a/include/test/overlay.h b/include/test/overlay.h deleted file mode 100644 index 5dc98399ce7..00000000000 --- a/include/test/overlay.h +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2016 NextThing Co - * Copyright (c) 2016 Free Electrons - */ - -#ifndef __TEST_OVERLAY_H__ -#define __TEST_OVERLAY_H__ - -#include - -/* Declare a new environment test */ -#define OVERLAY_TEST(_name, _flags) UNIT_TEST(_name, _flags, overlay) - -#endif /* __TEST_OVERLAY_H__ */ diff --git a/include/test/suites.h b/include/test/suites.h index 774dd893378..dce720b4e78 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -36,8 +36,8 @@ int cmd_ut_category(struct unit_test_state *uts, const char *name, int do_ut_bootstd(struct unit_test_state *uts, struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_fdt_overlay(struct unit_test_state *uts, struct cmd_tbl *cmdtp, + int flag, int argc, char *const argv[]); int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); -int do_ut_overlay(struct unit_test_state *uts, struct cmd_tbl *cmdtp, int flag, - int argc, char *const argv[]); #endif /* __TEST_SUITES_H__ */ diff --git a/test/Kconfig b/test/Kconfig index 1c8e3d16300..01d64642fdb 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -120,7 +120,7 @@ source "test/env/Kconfig" source "test/image/Kconfig" source "test/lib/Kconfig" source "test/optee/Kconfig" -source "test/overlay/Kconfig" +source "test/fdt_overlay/Kconfig" config POST bool "Power On Self Test support" diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 0b923ee7e2e..958b591c605 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -105,6 +105,7 @@ SUITE_DECL(dm); SUITE_DECL(env); SUITE_DECL(exit); SUITE_DECL(fdt); +SUITE_DECL(fdt_overlay); SUITE_DECL(font); SUITE_DECL(hush); SUITE_DECL(lib); @@ -114,7 +115,6 @@ SUITE_DECL(mbr); SUITE_DECL(measurement); SUITE_DECL(mem); SUITE_DECL(optee); -SUITE_DECL(overlay); SUITE_DECL(pci_mps); SUITE_DECL(seama); SUITE_DECL(setexpr); @@ -134,6 +134,9 @@ static struct suite suites[] = { SUITE(env, "environment"), SUITE(exit, "shell exit and variables"), SUITE(fdt, "fdt command"), +#ifdef CONFIG_UT_FDT_OVERLAY + SUITE_CMD(fdt_overlay, do_ut_fdt_overlay, "device tree overlays"), +#endif SUITE(font, "font command"), SUITE(hush, "hush behaviour"), SUITE(lib, "library functions"), @@ -144,9 +147,6 @@ static struct suite suites[] = { SUITE(mem, "memory-related commands"), #ifdef CONFIG_UT_OPTEE SUITE_CMD(optee, do_ut_optee, "OP-TEE"), -#endif -#ifdef CONFIG_UT_OVERLAY - SUITE_CMD(overlay, do_ut_overlay, "device tree overlays"), #endif SUITE(pci_mps, "PCI Express Maximum Payload Size"), SUITE(seama, "seama command parameters loading and decoding"), diff --git a/test/fdt_overlay/Kconfig b/test/fdt_overlay/Kconfig new file mode 100644 index 00000000000..c2bb70fc970 --- /dev/null +++ b/test/fdt_overlay/Kconfig @@ -0,0 +1,10 @@ +config UT_FDT_OVERLAY + bool "Enable Device Tree Overlays Unit Tests" + depends on UNIT_TEST && OF_CONTROL && SANDBOX + default y + select OF_LIBFDT_OVERLAY + help + This enables the 'ut overlay' command which runs a series of unit + tests on the fdt overlay code. + If all is well then all tests pass although there will be a few + messages printed along the way. diff --git a/test/fdt_overlay/Makefile b/test/fdt_overlay/Makefile new file mode 100644 index 00000000000..5625c0d8885 --- /dev/null +++ b/test/fdt_overlay/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2016 NextThing Co +# Copyright (c) 2016 Free Electrons + +# Test files +obj-y += cmd_ut_fdt_overlay.o + +DTC_FLAGS += -@ + +# DT overlays +obj-y += test-fdt-base.dtb.o +obj-y += test-fdt-overlay.dtbo.o +obj-y += test-fdt-overlay-stacked.dtbo.o diff --git a/test/fdt_overlay/cmd_ut_fdt_overlay.c b/test/fdt_overlay/cmd_ut_fdt_overlay.c new file mode 100644 index 00000000000..9fe18b60aca --- /dev/null +++ b/test/fdt_overlay/cmd_ut_fdt_overlay.c @@ -0,0 +1,281 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +/* 4k ought to be enough for anybody */ +#define FDT_COPY_SIZE (4 * SZ_1K) + +extern u32 __dtb_test_fdt_base_begin; +extern u32 __dtbo_test_fdt_overlay_begin; +extern u32 __dtbo_test_fdt_overlay_stacked_begin; + +static void *fdt; + +static int ut_fdt_getprop_u32_by_index(void *fdt, const char *path, + const char *name, int index, + u32 *out) +{ + const fdt32_t *val; + int node_off; + int len; + + node_off = fdt_path_offset(fdt, path); + if (node_off < 0) + return node_off; + + val = fdt_getprop(fdt, node_off, name, &len); + if (!val || (len < (sizeof(uint32_t) * (index + 1)))) + return -FDT_ERR_NOTFOUND; + + *out = fdt32_to_cpu(*(val + index)); + + return 0; +} + +static int ut_fdt_getprop_u32(void *fdt, const char *path, const char *name, + u32 *out) +{ + return ut_fdt_getprop_u32_by_index(fdt, path, name, 0, out); +} + +static int fdt_getprop_str(void *fdt, const char *path, const char *name, + const char **out) +{ + int node_off; + int len; + + node_off = fdt_path_offset(fdt, path); + if (node_off < 0) + return node_off; + + *out = fdt_stringlist_get(fdt, node_off, name, 0, &len); + + return len < 0 ? len : 0; +} + +static int fdt_overlay_test_change_int_property(struct unit_test_state *uts) +{ + u32 val = 0; + + ut_assertok(ut_fdt_getprop_u32(fdt, "/test-node", "test-int-property", + &val)); + ut_asserteq(43, val); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_change_int_property, 0); + +static int fdt_overlay_test_change_str_property(struct unit_test_state *uts) +{ + const char *val = NULL; + + ut_assertok(fdt_getprop_str(fdt, "/test-node", "test-str-property", + &val)); + ut_asserteq_str("foobar", val); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_change_str_property, 0); + +static int fdt_overlay_test_add_str_property(struct unit_test_state *uts) +{ + const char *val = NULL; + + ut_assertok(fdt_getprop_str(fdt, "/test-node", "test-str-property-2", + &val)); + ut_asserteq_str("foobar2", val); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_add_str_property, 0); + +static int fdt_overlay_test_add_node_by_phandle(struct unit_test_state *uts) +{ + int off; + + off = fdt_path_offset(fdt, "/test-node/new-node"); + ut_assert(off >= 0); + + ut_assertnonnull(fdt_getprop(fdt, off, "new-property", NULL)); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_add_node_by_phandle, 0); + +static int fdt_overlay_test_add_node_by_path(struct unit_test_state *uts) +{ + int off; + + off = fdt_path_offset(fdt, "/new-node"); + ut_assert(off >= 0); + + ut_assertnonnull(fdt_getprop(fdt, off, "new-property", NULL)); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_add_node_by_path, 0); + +static int fdt_overlay_test_add_subnode_property(struct unit_test_state *uts) +{ + int off; + + off = fdt_path_offset(fdt, "/test-node/sub-test-node"); + ut_assert(off >= 0); + + ut_assertnonnull(fdt_getprop(fdt, off, "sub-test-property", NULL)); + ut_assertnonnull(fdt_getprop(fdt, off, "new-sub-test-property", NULL)); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_add_subnode_property, 0); + +static int fdt_overlay_test_local_phandle(struct unit_test_state *uts) +{ + uint32_t local_phandle; + u32 val = 0; + int off; + + off = fdt_path_offset(fdt, "/new-local-node"); + ut_assert(off >= 0); + + local_phandle = fdt_get_phandle(fdt, off); + ut_assert(local_phandle); + + ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-several-phandle", + 0, &val)); + ut_asserteq(local_phandle, val); + + ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-several-phandle", + 1, &val)); + ut_asserteq(local_phandle, val); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_local_phandle, 0); + +static int fdt_overlay_test_local_phandles(struct unit_test_state *uts) +{ + uint32_t local_phandle, test_phandle; + u32 val = 0; + int off; + + off = fdt_path_offset(fdt, "/new-local-node"); + ut_assert(off >= 0); + + local_phandle = fdt_get_phandle(fdt, off); + ut_assert(local_phandle); + + off = fdt_path_offset(fdt, "/test-node"); + ut_assert(off >= 0); + + test_phandle = fdt_get_phandle(fdt, off); + ut_assert(test_phandle); + + ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-phandle", 0, + &val)); + ut_asserteq(test_phandle, val); + + ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-phandle", 1, + &val)); + ut_asserteq(local_phandle, val); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_local_phandles, 0); + +static int fdt_overlay_test_stacked(struct unit_test_state *uts) +{ + u32 val = 0; + + ut_assertok(ut_fdt_getprop_u32(fdt, "/new-local-node", + "stacked-test-int-property", &val)); + ut_asserteq(43, val); + + return CMD_RET_SUCCESS; +} +FDT_OVERLAY_TEST(fdt_overlay_test_stacked, 0); + +int do_ut_fdt_overlay(struct unit_test_state *uts, struct cmd_tbl *cmdtp, + int flag, int argc, char *const argv[]) +{ + struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_overlay); + const int n_ents = UNIT_TEST_SUITE_COUNT(fdt_overlay); + void *fdt_base = &__dtb_test_fdt_base_begin; + void *fdt_overlay = &__dtbo_test_fdt_overlay_begin; + void *fdt_overlay_stacked = &__dtbo_test_fdt_overlay_stacked_begin; + void *fdt_overlay_copy, *fdt_overlay_stacked_copy; + int ret = -ENOMEM; + + ut_assertok(fdt_check_header(fdt_base)); + ut_assertok(fdt_check_header(fdt_overlay)); + + fdt = malloc(FDT_COPY_SIZE); + if (!fdt) + goto err1; + + fdt_overlay_copy = malloc(FDT_COPY_SIZE); + if (!fdt_overlay_copy) + goto err2; + + fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE); + if (!fdt_overlay_stacked_copy) + goto err3; + + /* + * Resize the FDT to 4k so that we have room to operate on + * + * (and relocate it since the memory might be mapped + * read-only) + */ + ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE)); + + /* + * Resize the overlay to 4k so that we have room to operate on + * + * (and relocate it since the memory might be mapped + * read-only) + */ + ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy, + FDT_COPY_SIZE)); + + /* + * Resize the stacked overlay to 4k so that we have room to operate on + * + * (and relocate it since the memory might be mapped + * read-only) + */ + ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy, + FDT_COPY_SIZE)); + + /* Apply the overlay */ + ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_copy)); + + /* Apply the stacked overlay */ + ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_stacked_copy)); + + ret = cmd_ut_category(uts, "fdt_overlay", "fdt_overlay_test_", tests, + n_ents, argc, argv); + + free(fdt_overlay_stacked_copy); +err3: + free(fdt_overlay_copy); +err2: + free(fdt); +err1: + return ret; +} diff --git a/test/fdt_overlay/test-fdt-base.dts b/test/fdt_overlay/test-fdt-base.dts new file mode 100644 index 00000000000..38278334e4d --- /dev/null +++ b/test/fdt_overlay/test-fdt-base.dts @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + */ + +/dts-v1/; + +/ { + test: test-node { + test-int-property = <42>; + test-str-property = "foo"; + + subtest: sub-test-node { + sub-test-property; + }; + }; +}; + + diff --git a/test/fdt_overlay/test-fdt-overlay-stacked.dtso b/test/fdt_overlay/test-fdt-overlay-stacked.dtso new file mode 100644 index 00000000000..6411adec539 --- /dev/null +++ b/test/fdt_overlay/test-fdt-overlay-stacked.dtso @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * Copyright (c) 2018 Konsulko Group + */ + +/dts-v1/; +/plugin/; + +/ { + /* Test that we can reference an overlay symbol */ + fragment@0 { + target = <&local>; + + __overlay__ { + stacked-test-int-property = <43>; + }; + }; +}; diff --git a/test/fdt_overlay/test-fdt-overlay.dtso b/test/fdt_overlay/test-fdt-overlay.dtso new file mode 100644 index 00000000000..5a21b346d07 --- /dev/null +++ b/test/fdt_overlay/test-fdt-overlay.dtso @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + */ + +/dts-v1/; +/plugin/; + +/ { + /* Test that we can change an int by another */ + fragment@0 { + target = <&test>; + + __overlay__ { + test-int-property = <43>; + }; + }; + + /* Test that we can replace a string by a longer one */ + fragment@1 { + target = <&test>; + + __overlay__ { + test-str-property = "foobar"; + }; + }; + + /* Test that we add a new property */ + fragment@2 { + target = <&test>; + + __overlay__ { + test-str-property-2 = "foobar2"; + }; + }; + + /* Test that we add a new node (by phandle) */ + fragment@3 { + target = <&test>; + + __overlay__ { + new-node { + new-property; + }; + }; + }; + + /* Test that we add a new node (by path) */ + fragment@4 { + target-path = "/"; + + __overlay__ { + new-node { + new-property; + }; + }; + }; + + fragment@5 { + target-path = "/"; + + __overlay__ { + local: new-local-node { + new-property; + }; + }; + }; + + fragment@6 { + target-path = "/"; + + __overlay__ { + test-phandle = <&test>, <&local>; + }; + }; + + fragment@7 { + target-path = "/"; + + __overlay__ { + test-several-phandle = <&local>, <&local>; + }; + }; + + fragment@8 { + target = <&test>; + + __overlay__ { + sub-test-node { + new-sub-test-property; + }; + }; + }; +}; diff --git a/test/overlay/Kconfig b/test/overlay/Kconfig deleted file mode 100644 index 881848968bb..00000000000 --- a/test/overlay/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -config UT_OVERLAY - bool "Enable Device Tree Overlays Unit Tests" - depends on UNIT_TEST && OF_CONTROL && SANDBOX - default y - select OF_LIBFDT_OVERLAY - help - This enables the 'ut overlay' command which runs a series of unit - tests on the fdt overlay code. - If all is well then all tests pass although there will be a few - messages printed along the way. diff --git a/test/overlay/Makefile b/test/overlay/Makefile deleted file mode 100644 index 47937e3c108..00000000000 --- a/test/overlay/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ -# -# Copyright (c) 2016 NextThing Co -# Copyright (c) 2016 Free Electrons - -# Test files -obj-y += cmd_ut_overlay.o - -DTC_FLAGS += -@ - -# DT overlays -obj-y += test-fdt-base.dtb.o -obj-y += test-fdt-overlay.dtbo.o -obj-y += test-fdt-overlay-stacked.dtbo.o diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c deleted file mode 100644 index aefa147ec04..00000000000 --- a/test/overlay/cmd_ut_overlay.c +++ /dev/null @@ -1,280 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2016 NextThing Co - * Copyright (c) 2016 Free Electrons - */ - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -/* 4k ought to be enough for anybody */ -#define FDT_COPY_SIZE (4 * SZ_1K) - -extern u32 __dtb_test_fdt_base_begin; -extern u32 __dtbo_test_fdt_overlay_begin; -extern u32 __dtbo_test_fdt_overlay_stacked_begin; - -static void *fdt; - -static int ut_fdt_getprop_u32_by_index(void *fdt, const char *path, - const char *name, int index, - u32 *out) -{ - const fdt32_t *val; - int node_off; - int len; - - node_off = fdt_path_offset(fdt, path); - if (node_off < 0) - return node_off; - - val = fdt_getprop(fdt, node_off, name, &len); - if (!val || (len < (sizeof(uint32_t) * (index + 1)))) - return -FDT_ERR_NOTFOUND; - - *out = fdt32_to_cpu(*(val + index)); - - return 0; -} - -static int ut_fdt_getprop_u32(void *fdt, const char *path, const char *name, - u32 *out) -{ - return ut_fdt_getprop_u32_by_index(fdt, path, name, 0, out); -} - -static int fdt_getprop_str(void *fdt, const char *path, const char *name, - const char **out) -{ - int node_off; - int len; - - node_off = fdt_path_offset(fdt, path); - if (node_off < 0) - return node_off; - - *out = fdt_stringlist_get(fdt, node_off, name, 0, &len); - - return len < 0 ? len : 0; -} - -static int fdt_overlay_change_int_property(struct unit_test_state *uts) -{ - u32 val = 0; - - ut_assertok(ut_fdt_getprop_u32(fdt, "/test-node", "test-int-property", - &val)); - ut_asserteq(43, val); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_change_int_property, 0); - -static int fdt_overlay_change_str_property(struct unit_test_state *uts) -{ - const char *val = NULL; - - ut_assertok(fdt_getprop_str(fdt, "/test-node", "test-str-property", - &val)); - ut_asserteq_str("foobar", val); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_change_str_property, 0); - -static int fdt_overlay_add_str_property(struct unit_test_state *uts) -{ - const char *val = NULL; - - ut_assertok(fdt_getprop_str(fdt, "/test-node", "test-str-property-2", - &val)); - ut_asserteq_str("foobar2", val); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_add_str_property, 0); - -static int fdt_overlay_add_node_by_phandle(struct unit_test_state *uts) -{ - int off; - - off = fdt_path_offset(fdt, "/test-node/new-node"); - ut_assert(off >= 0); - - ut_assertnonnull(fdt_getprop(fdt, off, "new-property", NULL)); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_add_node_by_phandle, 0); - -static int fdt_overlay_add_node_by_path(struct unit_test_state *uts) -{ - int off; - - off = fdt_path_offset(fdt, "/new-node"); - ut_assert(off >= 0); - - ut_assertnonnull(fdt_getprop(fdt, off, "new-property", NULL)); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_add_node_by_path, 0); - -static int fdt_overlay_add_subnode_property(struct unit_test_state *uts) -{ - int off; - - off = fdt_path_offset(fdt, "/test-node/sub-test-node"); - ut_assert(off >= 0); - - ut_assertnonnull(fdt_getprop(fdt, off, "sub-test-property", NULL)); - ut_assertnonnull(fdt_getprop(fdt, off, "new-sub-test-property", NULL)); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_add_subnode_property, 0); - -static int fdt_overlay_local_phandle(struct unit_test_state *uts) -{ - uint32_t local_phandle; - u32 val = 0; - int off; - - off = fdt_path_offset(fdt, "/new-local-node"); - ut_assert(off >= 0); - - local_phandle = fdt_get_phandle(fdt, off); - ut_assert(local_phandle); - - ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-several-phandle", - 0, &val)); - ut_asserteq(local_phandle, val); - - ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-several-phandle", - 1, &val)); - ut_asserteq(local_phandle, val); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_local_phandle, 0); - -static int fdt_overlay_local_phandles(struct unit_test_state *uts) -{ - uint32_t local_phandle, test_phandle; - u32 val = 0; - int off; - - off = fdt_path_offset(fdt, "/new-local-node"); - ut_assert(off >= 0); - - local_phandle = fdt_get_phandle(fdt, off); - ut_assert(local_phandle); - - off = fdt_path_offset(fdt, "/test-node"); - ut_assert(off >= 0); - - test_phandle = fdt_get_phandle(fdt, off); - ut_assert(test_phandle); - - ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-phandle", 0, - &val)); - ut_asserteq(test_phandle, val); - - ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-phandle", 1, - &val)); - ut_asserteq(local_phandle, val); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_local_phandles, 0); - -static int fdt_overlay_stacked(struct unit_test_state *uts) -{ - u32 val = 0; - - ut_assertok(ut_fdt_getprop_u32(fdt, "/new-local-node", - "stacked-test-int-property", &val)); - ut_asserteq(43, val); - - return CMD_RET_SUCCESS; -} -OVERLAY_TEST(fdt_overlay_stacked, 0); - -int do_ut_overlay(struct unit_test_state *uts, struct cmd_tbl *cmdtp, int flag, - int argc, char *const argv[]) -{ - struct unit_test *tests = UNIT_TEST_SUITE_START(overlay); - const int n_ents = UNIT_TEST_SUITE_COUNT(overlay); - void *fdt_base = &__dtb_test_fdt_base_begin; - void *fdt_overlay = &__dtbo_test_fdt_overlay_begin; - void *fdt_overlay_stacked = &__dtbo_test_fdt_overlay_stacked_begin; - void *fdt_overlay_copy, *fdt_overlay_stacked_copy; - int ret = -ENOMEM; - - ut_assertok(fdt_check_header(fdt_base)); - ut_assertok(fdt_check_header(fdt_overlay)); - - fdt = malloc(FDT_COPY_SIZE); - if (!fdt) - goto err1; - - fdt_overlay_copy = malloc(FDT_COPY_SIZE); - if (!fdt_overlay_copy) - goto err2; - - fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE); - if (!fdt_overlay_stacked_copy) - goto err3; - - /* - * Resize the FDT to 4k so that we have room to operate on - * - * (and relocate it since the memory might be mapped - * read-only) - */ - ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE)); - - /* - * Resize the overlay to 4k so that we have room to operate on - * - * (and relocate it since the memory might be mapped - * read-only) - */ - ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy, - FDT_COPY_SIZE)); - - /* - * Resize the stacked overlay to 4k so that we have room to operate on - * - * (and relocate it since the memory might be mapped - * read-only) - */ - ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy, - FDT_COPY_SIZE)); - - /* Apply the overlay */ - ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_copy)); - - /* Apply the stacked overlay */ - ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_stacked_copy)); - - ret = cmd_ut_category(uts, "overlay", "", tests, n_ents, argc, argv); - - free(fdt_overlay_stacked_copy); -err3: - free(fdt_overlay_copy); -err2: - free(fdt); -err1: - return ret; -} diff --git a/test/overlay/test-fdt-base.dts b/test/overlay/test-fdt-base.dts deleted file mode 100644 index 38278334e4d..00000000000 --- a/test/overlay/test-fdt-base.dts +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2016 NextThing Co - * Copyright (c) 2016 Free Electrons - */ - -/dts-v1/; - -/ { - test: test-node { - test-int-property = <42>; - test-str-property = "foo"; - - subtest: sub-test-node { - sub-test-property; - }; - }; -}; - - diff --git a/test/overlay/test-fdt-overlay-stacked.dtso b/test/overlay/test-fdt-overlay-stacked.dtso deleted file mode 100644 index 6411adec539..00000000000 --- a/test/overlay/test-fdt-overlay-stacked.dtso +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2016 NextThing Co - * Copyright (c) 2016 Free Electrons - * Copyright (c) 2018 Konsulko Group - */ - -/dts-v1/; -/plugin/; - -/ { - /* Test that we can reference an overlay symbol */ - fragment@0 { - target = <&local>; - - __overlay__ { - stacked-test-int-property = <43>; - }; - }; -}; diff --git a/test/overlay/test-fdt-overlay.dtso b/test/overlay/test-fdt-overlay.dtso deleted file mode 100644 index 5a21b346d07..00000000000 --- a/test/overlay/test-fdt-overlay.dtso +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2016 NextThing Co - * Copyright (c) 2016 Free Electrons - */ - -/dts-v1/; -/plugin/; - -/ { - /* Test that we can change an int by another */ - fragment@0 { - target = <&test>; - - __overlay__ { - test-int-property = <43>; - }; - }; - - /* Test that we can replace a string by a longer one */ - fragment@1 { - target = <&test>; - - __overlay__ { - test-str-property = "foobar"; - }; - }; - - /* Test that we add a new property */ - fragment@2 { - target = <&test>; - - __overlay__ { - test-str-property-2 = "foobar2"; - }; - }; - - /* Test that we add a new node (by phandle) */ - fragment@3 { - target = <&test>; - - __overlay__ { - new-node { - new-property; - }; - }; - }; - - /* Test that we add a new node (by path) */ - fragment@4 { - target-path = "/"; - - __overlay__ { - new-node { - new-property; - }; - }; - }; - - fragment@5 { - target-path = "/"; - - __overlay__ { - local: new-local-node { - new-property; - }; - }; - }; - - fragment@6 { - target-path = "/"; - - __overlay__ { - test-phandle = <&test>, <&local>; - }; - }; - - fragment@7 { - target-path = "/"; - - __overlay__ { - test-several-phandle = <&local>, <&local>; - }; - }; - - fragment@8 { - target = <&test>; - - __overlay__ { - sub-test-node { - new-sub-test-property; - }; - }; - }; -}; diff --git a/test/py/tests/test_suite.py b/test/py/tests/test_suite.py index ae127301fd7..1e02d67efe2 100644 --- a/test/py/tests/test_suite.py +++ b/test/py/tests/test_suite.py @@ -7,10 +7,10 @@ import re # List of test suites we expect to find with 'ut info' and 'ut all' EXPECTED_SUITES = [ 'addrmap', 'bdinfo', 'bloblist', 'bootm', 'bootstd', - 'cmd', 'common', 'dm', 'env', 'exit', + 'cmd', 'common', 'dm', 'env', 'exit', 'fdt_overlay', 'fdt', 'font', 'hush', 'lib', 'loadm', 'log', 'mbr', 'measurement', 'mem', - 'overlay', 'pci_mps', 'setexpr', 'upl', + 'pci_mps', 'setexpr', 'upl', ] -- cgit v1.3.1