Add a new "test" subcommand to the env command. This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.
Signed-off-by: Joe Hershberger <joe.hershber...@ni.com> --- Changes in v2: -New for version 2 Makefile | 1 + common/cmd_nvedit.c | 10 +++++++++- include/env_test.h | 18 ++++++++++++++++++ test/Kconfig | 1 + test/env/Kconfig | 8 ++++++++ test/env/Makefile | 7 +++++++ test/env/cmd_env_test.c | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/env_test.h create mode 100644 test/env/Kconfig create mode 100644 test/env/Makefile create mode 100644 test/env/cmd_env_test.c diff --git a/Makefile b/Makefile index 1e52008..c89d5db 100644 --- a/Makefile +++ b/Makefile @@ -665,6 +665,7 @@ libs-$(CONFIG_API) += api/ libs-$(CONFIG_HAS_POST) += post/ libs-y += test/ libs-y += test/dm/ +libs-$(CONFIG_ENV_TEST) += test/env/ libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index f4c2523..ce1b03b 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -28,6 +28,7 @@ #include <cli.h> #include <command.h> #include <environment.h> +#include <env_test.h> #include <search.h> #include <errno.h> #include <malloc.h> @@ -1147,6 +1148,9 @@ static cmd_tbl_t cmd_env_sub[] = { #if defined(CONFIG_CMD_ENV_EXISTS) U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""), #endif +#if defined(CONFIG_ENV_TEST) + U_BOOT_CMD_MKENT(test, 1, 0, do_env_test, "", ""), +#endif }; #if defined(CONFIG_NEEDS_MANUAL_RELOC) @@ -1215,7 +1219,11 @@ static char env_help_text[] = #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) "env save - save environment\n" #endif - "env set [-f] name [arg ...]\n"; + "env set [-f] name [arg ...]\n" +#if defined(CONFIG_ENV_TEST) + "env test - run unit tests on the env commands" +#endif + ; #endif U_BOOT_CMD( diff --git a/include/env_test.h b/include/env_test.h new file mode 100644 index 0000000..f9eb971 --- /dev/null +++ b/include/env_test.h @@ -0,0 +1,18 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershber...@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __ENV_TEST_H__ +#define __ENV_TEST_H__ + +#include <test/test.h> + +int do_env_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + +/* Declare a new environment test */ +#define ENV_TEST(_name, _flags) UNIT_TEST(_name, _flags, env_test) + +#endif /* __ENV_TEST_H__ */ diff --git a/test/Kconfig b/test/Kconfig index 706b01b..1f8e41c 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -2,3 +2,4 @@ config UNIT_TEST bool source "test/dm/Kconfig" +source "test/env/Kconfig" diff --git a/test/env/Kconfig b/test/env/Kconfig new file mode 100644 index 0000000..df65ac2 --- /dev/null +++ b/test/env/Kconfig @@ -0,0 +1,8 @@ +config ENV_TEST + bool "Enable env test command" + select UNIT_TEST + help + This enables the 'env test' command which runs a series of unit + tests on the env code. + If all is well then all tests pass although there will be a few + messages printed along the way. diff --git a/test/env/Makefile b/test/env/Makefile new file mode 100644 index 0000000..c35b18e --- /dev/null +++ b/test/env/Makefile @@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_env_test.o diff --git a/test/env/cmd_env_test.c b/test/env/cmd_env_test.c new file mode 100644 index 0000000..9643caa --- /dev/null +++ b/test/env/cmd_env_test.c @@ -0,0 +1,36 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershber...@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_test.h> +#include <test/ut.h> + +int do_env_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct unit_test *tests = ll_entry_start(struct unit_test, env_test); + const int n_ents = ll_entry_count(struct unit_test, env_test); + struct unit_test_state uts = { .fail_count = 0 }; + struct unit_test *test; + + if (argc == 1) + printf("Running %d environment tests\n", n_ents); + + for (test = tests; test < tests + n_ents; test++) { + if (argc > 1 && strcmp(argv[1], test->name)) + continue; + printf("Test: %s\n", test->name); + + uts.start = mallinfo(); + + test->func(&uts); + } + + printf("Failures: %d\n", uts.fail_count); + + return uts.fail_count ? CMD_RET_FAILURE : 0; +} -- 1.7.11.5 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot