From patchwork Wed Apr 29 05:51:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 465902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3F0A3140332 for ; Wed, 29 Apr 2015 15:55:49 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 80D314BBC8; Wed, 29 Apr 2015 07:54:51 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u9ukP9CeYp2l; Wed, 29 Apr 2015 07:54:51 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF9D84BA83; Wed, 29 Apr 2015 07:53:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9B56C4BA89 for ; Wed, 29 Apr 2015 07:53:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LpazXg-1BcKc for ; Wed, 29 Apr 2015 07:53:33 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by theia.denx.de (Postfix) with ESMTPS id E025E4BA8B for ; Wed, 29 Apr 2015 07:53:25 +0200 (CEST) Received: from us-aus-mgwout1.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod3.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t3T5rFqC004350; Wed, 29 Apr 2015 00:53:15 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout1.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015042900531603-380900 ; Wed, 29 Apr 2015 00:53:16 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Wed, 29 Apr 2015 00:51:02 -0500 Message-Id: <1430286666-392-16-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1430286666-392-1-git-send-email-joe.hershberger@ni.com> References: <1429653771-11676-1-git-send-email-joe.hershberger@ni.com> <1430286666-392-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/29/2015 12:53:16 AM, Serialize by Router on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/29/2015 12:53:16 AM, Serialize complete at 04/29/2015 12:53:16 AM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-04-29_01:, , signatures=0 Cc: Marek Vasut , Tom Rini , Jeroen Hofstee , Stefan Roese , Joe Hershberger , Alexander Holler Subject: [U-Boot] [PATCH v2 15/19] test: env: Add test framework for env X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Reviewed-by: Simon Glass --- 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 #include #include +#include #include #include #include @@ -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.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __ENV_TEST_H__ +#define __ENV_TEST_H__ + +#include + +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.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include + +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; +}