From patchwork Sun May 3 20:12:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 467424 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 863E0140285 for ; Mon, 4 May 2015 06:17:41 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D706A4B93E; Sun, 3 May 2015 22:16:44 +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 g8GN57QIfcJU; Sun, 3 May 2015 22:16:44 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DBBB04B989; Sun, 3 May 2015 22:15:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2744D4B892 for ; Sun, 3 May 2015 22:15:13 +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 juHyb0Fk1Zda for ; Sun, 3 May 2015 22:15:13 +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 (skprod2.natinst.com [130.164.80.23]) by theia.denx.de (Postfix) with ESMTPS id 8B4B04B8C6 for ; Sun, 3 May 2015 22:15:08 +0200 (CEST) Received: from us-aus-mgwout2.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod2.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t43KF6nF025385; Sun, 3 May 2015 15:15:06 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout2.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015050315150692-652385 ; Sun, 3 May 2015 15:15:06 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Sun, 3 May 2015 15:12:58 -0500 Message-Id: <1430683982-9832-23-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1430683982-9832-1-git-send-email-joe.hershberger@ni.com> References: <1430286666-392-1-git-send-email-joe.hershberger@ni.com> <1430683982-9832-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 05/03/2015 03:15:06 PM, Serialize by Router on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 05/03/2015 03:15:07 PM, Serialize complete at 05/03/2015 03:15:07 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-05-03_03:, , signatures=0 Cc: Tom Rini , Joe Hershberger Subject: [U-Boot] [PATCH v3 22/26] test: env: Add test for verifying env attrs 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 test of the env_attr_lookup() function. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: -New for version 2 test/env/Makefile | 1 + test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/env/attr.c diff --git a/test/env/Makefile b/test/env/Makefile index 59b38e9..5168bcb 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ # obj-y += cmd_ut_env.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000..d9be825 --- /dev/null +++ b/test/env/attr.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include +#include + +static int env_test_attrs_lookup(struct unit_test_state *uts) +{ + char attrs[32]; + + ut_assertok(env_attr_lookup("foo:bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(" foo:bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup("foo : bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(" foo: bar ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup("foo:bar ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); + + ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); + + ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); + ut_asserteq_str("baz", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , foot : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); + ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); + + return 0; +} +ENV_TEST(env_test_attrs_lookup, 0);