From patchwork Wed Oct 7 07:20:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1377807 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=JQgGW/lc; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C5m3X12Qzz9s0b for ; Wed, 7 Oct 2020 18:21:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D704C823C9; Wed, 7 Oct 2020 09:21:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="JQgGW/lc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5120B823CF; Wed, 7 Oct 2020 09:21:11 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0713.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::713]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4FE74823A1 for ; Wed, 7 Oct 2020 09:21:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FTg6OLMRh2ogL7Z7mN7Jy9oKxDF3dxO1fkbwCKCN1NuFxt00U1tpgb5OhPaYWiEBKZwSRvOCOf7ysDE/2oRsbWBKKBMkZMt5d+Tu7lCZ4cbMkOHnSkHXLqfsBVWtS8hH5QbQ+zU0KGZKE1HG5Xm0IAxNNwcJnwEWGseALgAIy03xExw95wJ+lbYgUpt/zGFKjXq2zaDjS/NBpuCuoE+yDZ0oI6rqydb4ovqyR6SpcZEUCwTno1fmYeqzbHH6wAA/0kIIJYtsGx08NxuwyqFH1kM1wMN8f8Ieq0vl7OPAUnlMpW5a6BEBxg2p5V9yiJn/7xY+R+tUJ3q0vBzx25TRrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BBP2JoQF4zP2NirhLtPS3/og8iocgamSPas8S0h47Lk=; b=fY3fdbhtzhXcyl7ehkvIRYQPuc8WOMEIaspddqCu5m/Jj/hdwSY9S6Onz9QB/eQradPY93Fj2SrH1yTJdq0y0nbvQsZuiqx8gSKiaJss+OGUPr02mfYaLI/hkdDWKaasTLMSh9wQy/XtKy45AeomZhDRsl9MTn3aE6p3X+91OveCHG+HSkohAusheB7tZKF5ReyfOzp7WusXLK6cysVpIo4p5htlZr5VU8SEIz3zfxd6R56sOy9Fa9fHkaU48TcG1Gtvww4KT0da1aCin1mH4Qsxd5+x2lVQYpwlSkHLINlnZIIGZWpyJILvLKWtOVbXpbBYDrhX3EZHMkJjU6TRYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BBP2JoQF4zP2NirhLtPS3/og8iocgamSPas8S0h47Lk=; b=JQgGW/lcJ+lHRoe2LDs2tLapvwA+MM2g6CskNBF3dnAP9TCTX35Azdnos7/VTq7J8JySTrHBc3DsIK4xKHO6ytPz26ByI3ekxOehyK6pWusAAInISR0OquykMx7uiGb4YqLR63SNixfL9NAXQPcSdDk0QhfaeS/ZjTMQOS2fffk= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:2f::12) by AM7PR10MB3333.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:10c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.22; Wed, 7 Oct 2020 07:21:05 +0000 Received: from AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc8a:f8d9:a15f:44ce]) by AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc8a:f8d9:a15f:44ce%7]) with mapi id 15.20.3433.045; Wed, 7 Oct 2020 07:21:05 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Wolfgang Denk , Tom Rini , Rasmus Villemoes Subject: [PATCH v2 1/3] cli_hush.c: refactor handle_dollar() to prepare for "run with arguments" Date: Wed, 7 Oct 2020 09:20:50 +0200 Message-Id: <20201007072052.28200-2-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201007072052.28200-1-rasmus.villemoes@prevas.dk> References: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> <20201007072052.28200-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [81.216.59.226] X-ClientProxiedBy: AM0PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:208:122::18) To AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:2f::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (81.216.59.226) by AM0PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:208:122::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21 via Frontend Transport; Wed, 7 Oct 2020 07:21:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76032785-32bc-4f1f-2638-08d86a918d8f X-MS-TrafficTypeDiagnostic: AM7PR10MB3333: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cumy2NJGFeZKN+bCM5PTD8cxqeOyw1c9ScFvyl5SJBjaa1qlDT0EVZgOPmJ5Wi37fnHq5kj8Yi+oIOVJwmVUV4oOngcmgM84PqblJ2q1vqZKRoWhKi6QEuRnRiJj8/VDAZHkB13acs27ZMrwgQIK2H9h/g8g+MHJnjXYMZt5udsDB9sLSgEqleXwRmDEMy+68OosLExBQ3NTFJnez0wZbX0y2GbkjgPryIm5iOennNoLxEpjzLRuFYWYgbnReICrBXsOMdI2R31enftFpVBdvgrBQzs4dF//tHSKR+uzcOEucqRbFPDbg1FbT2B3HqUrSw7S5y25wo2rKkymmZ9kiw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(396003)(346002)(136003)(39840400004)(366004)(376002)(107886003)(66476007)(66556008)(8676002)(36756003)(66946007)(26005)(16526019)(8976002)(8936002)(186003)(6512007)(478600001)(2616005)(956004)(6506007)(6486002)(5660300002)(1076003)(52116002)(83380400001)(54906003)(4326008)(6666004)(86362001)(316002)(44832011)(2906002)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 3ymxLSRmPAxWkJ2KT5pobq8GlddqeJRiQ4X9otn5m7sljP3hugD5nXTzEKTc1WFTrvixs1Z2vWjmXwfIWP7+d4rq8y0DIUd8R6mtPfpshQt45fgAberJ3WjT6tj6Ped4G48NNzcW9xO3nVIjqz1S0NU7+148/8/vPmI+pbuoQwTwuHRA4xblz5m5eNdVkf++Is4+iwp3Ul0O3m/w1HwrHMvTwAl2sndXoKqkMBmjJUwWhNL8m48EMHkI5eIFknB2LnVFmxrvRYi6z1/LooNcwsKq2zWftPecH9N7SmtbeFMy5XBNbK7fnU6qZCuSP4tFo6tNxrC4xCsZUI39HWXdTMGSWQPIRDT1YmlAvTIEnuEMPaQWyxrUm5/Ck1mpG6VzdY8E8sctDXIsPcK0uzfWt/bmaIz/qKdzux2sph9Ys/+ygbYoGaPaiXS8u4N7nPUJR9EF4JLKNyAMHQgZh1xzQjXAnDi/Wj1M7DBikUqDcX2buTNAv0O+eq/c3xxm4bH7M+wV+1guNoIjdQeHNg6vxLtgonDW60n020wHhqgjcrOiKArEBTxPytCtIkmVZa4my0ArTZXA175DtVOsr4XM9UD03Aybv3RIL8Z0Qm5/GkYlLh0eRePNIm9n8uu1YJ856wX86gtbdGoAhqbqwkU7+Q== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 76032785-32bc-4f1f-2638-08d86a918d8f X-MS-Exchange-CrossTenant-AuthSource: AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2020 07:21:05.3154 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jThxU+Wibg8STxOi+XY9OloBnmcIZGyLZJTJ5zf4rhY6gSpjBRnTkqN3ujNm1UiFIygXlaDoRbes9c0RY1eCHK/23BEDxyGbVCWorW8UBrw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR10MB3333 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean A later patch will add handling of $1 through $9 as well as $#, using the same SPECIAL_VAR_SYMBOL handling as is currently used for $?. So move that case to an explicit #ifdef __U_BOOT__ branch, and consolidate a few of the #ifndef __U_BOOT__ cases, making it easier to see the original hush code. No functional change. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- common/cli_hush.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/common/cli_hush.c b/common/cli_hush.c index 5b1f119074..072b871f1e 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -2863,6 +2863,16 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i advance = 1; #endif } else switch (ch) { +#ifdef __U_BOOT__ + case '?': + ctx->child->sp++; + b_addchr(dest, SPECIAL_VAR_SYMBOL); + b_addchr(dest, '$'); + b_addchr(dest, '?'); + b_addchr(dest, SPECIAL_VAR_SYMBOL); + advance = 1; + break; +#endif #ifndef __U_BOOT__ case '$': b_adduint(dest,getpid()); @@ -2872,20 +2882,10 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i if (last_bg_pid > 0) b_adduint(dest, last_bg_pid); advance = 1; break; -#endif case '?': -#ifndef __U_BOOT__ b_adduint(dest,last_return_code); -#else - ctx->child->sp++; - b_addchr(dest, SPECIAL_VAR_SYMBOL); - b_addchr(dest, '$'); - b_addchr(dest, '?'); - b_addchr(dest, SPECIAL_VAR_SYMBOL); -#endif advance = 1; break; -#ifndef __U_BOOT__ case '#': b_adduint(dest,global_argc ? global_argc-1 : 0); advance = 1; From patchwork Wed Oct 7 07:20:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1377808 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=LKmoHCGx; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C5m3l552Mz9s0b for ; Wed, 7 Oct 2020 18:21:39 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3EF4F823DF; Wed, 7 Oct 2020 09:21:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="LKmoHCGx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D05A3823AF; Wed, 7 Oct 2020 09:21:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0713.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::713]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AEAE5823AF for ; Wed, 7 Oct 2020 09:21:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TtcoEj9989HenuZ2HgIC+gNK/VjCnpY7KoQ05TCZui3OGljnqcrjNOeUE+wxALk3hviNj0w7vtt2y2CZq8QiK1nr+f80aBGdz+saKZkqO39Xt6OCzGaffekAdj3WdF1yqNjpHtVmPnXUFJmUzeuDwXzWPnnhW3LyxGsy2MUIGdGP0QTfbfh9cPhWtdz5A+U3M02wPOUTVkYpwglUoe21AXLuKXfWtdEQ1D8FbONNsUzQqQpnD+Q87brMMa2uygBAObfYo9l0uhN80TKnrpNJTGJHvDLMJJr1ndH9yCKQi71AUuLLWH7llHSyv26aFO6DdVKh0f7ajLlxgls03WVPhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=src1T/B6clzMPILNab6hhAjMq+ay44v0sRrFYlv5Xgg=; b=LxkZGWw+eK4bLOkx1o+IjvfurCY2E0VQ6RCh6V+NUA1KA+817E1BlMIL+eb7H1W4qPhdRvKxy1HuHQmOVdbRIfXYVC+2z99FRk8wunyFgVI6UionU45cBaQXhZVvLHqVDTViR5N4plGQv+cLkakyP7krwjPgKdX2zOpI/+idS0+eydqPiR9D9GRoQuH3W1DoDfEoM9zjozXi2NHgul34/RpAwDqWsoTEzAmepVX6N3gn1xNQLkEFg49FYffQJPe7P59Xh/qh+nALpb1m6Vly/QKLDuALVAEBHfGUm8hbJRxbpkGQs4BiK6tQtctBeVsgTpy4LBFVyafQYc0cm0JwSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=src1T/B6clzMPILNab6hhAjMq+ay44v0sRrFYlv5Xgg=; b=LKmoHCGxyX8q+QDVOi7Zz3ffX5ra4tQIOJMxHv1lJxejMTBOl7AyzFiuQjXvONDcvYYBuMHhzhWKQ0BFdSjI8zSpKpbyp158/BOcx3C3Ml4G/Akl6145zvk7JLr2P25WaE8nv9JPdmxBnotXJ4FFnXug75L2adavrCt50neBEgk= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:2f::12) by AM7PR10MB3333.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:10c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.22; Wed, 7 Oct 2020 07:21:06 +0000 Received: from AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc8a:f8d9:a15f:44ce]) by AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc8a:f8d9:a15f:44ce%7]) with mapi id 15.20.3433.045; Wed, 7 Oct 2020 07:21:06 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Wolfgang Denk , Tom Rini , Rasmus Villemoes Subject: [PATCH v2 2/3] allow positional arguments with "run" command Date: Wed, 7 Oct 2020 09:20:51 +0200 Message-Id: <20201007072052.28200-3-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201007072052.28200-1-rasmus.villemoes@prevas.dk> References: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> <20201007072052.28200-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [81.216.59.226] X-ClientProxiedBy: AM0PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:208:122::18) To AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:2f::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (81.216.59.226) by AM0PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:208:122::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21 via Frontend Transport; Wed, 7 Oct 2020 07:21:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3f79f89-6915-4f76-dfe1-08d86a918e16 X-MS-TrafficTypeDiagnostic: AM7PR10MB3333: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ACY/phS39X3FK+2sFAtY6FTrxd9zNZepH7oUbVSLoDc4nDHOT5FNpVkwyGKqxaHk1L6OmRSZpANOLq7NCjBl7rE4CXtlv9NEUQnnwQQVlSUANgy5/vNzSuvnfITF0nGiT9x7Y0N+zoml+wuVMVjhy/fQojaCGbNqwsjp6z7KGmQRUP2Ez4xBDJv5lO1F4hbPmIiypTumPAm1R33r2KrfmyVGwqmbA5igaEfAJEuAEPERnpI/Cy2pybHrtTJbE/NfS7VbwnZexDoDyCtBgy2yHKcGQheP9BC3bqMC9TNp21qRRHyQlKvDLrulkHit3STKrP4Fx5ejDsTPNA0gRKoufw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(396003)(346002)(136003)(39840400004)(366004)(376002)(107886003)(66476007)(66556008)(8676002)(36756003)(66946007)(26005)(16526019)(8976002)(8936002)(186003)(6512007)(478600001)(2616005)(956004)(6506007)(6486002)(5660300002)(1076003)(52116002)(83380400001)(54906003)(4326008)(6666004)(86362001)(316002)(44832011)(2906002)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: pVqmlDLfT2rt6vgipE+NsIEV/L1Jx9XHHMg0ZUcXoR9w4mPc1nVbxqIn0VIE8AZbssyhp/FSPS06tFbDj2fsYfSOOPa1ATI2ODg8ChWH6tXUz5bZ35fhF8jkSIq1DvvAQXLJZuKAMP+9tYlKFuJaiGr6ObvxP5eG7OPdhl0fN2KOkpCOLPm56INFIO7B0644jlnFuAf9Qtm4gLWa44695YvlnjcEp3QFet8ccJXnKeYEUhFqKKaQDMC0Lz6MwoZdviNM52dXkoUGKpkvb44kBTukjdJElBW7/ljodztPal56SGkJSa/vyyMkLlAYCLcYbAoosVgZLxiMh54d3aKKEE8PT+d5799v64UzjQUxPFLT2kFS2PMO7qXIiQ2UNUIDlb2ud6ow1TUIvOevs5+egf0/wjBK7kYRSxBHkNxc/cnkJM1PzY0BXFfes2uF19jl0MGpx1VDkLYZeV5W83WIOV0v4sm/prDfj/pVuwfSKDdO4tQ8kPqWxRqL0ethezPqcwMHFrictbX74xlppK3nugCPGGPpARuVafIWKdTFHGBkW7vWze6hw7d4BaI+kEbYklNYZ7XULZhIO/iIYF9MmIFGbrbExIMJV0Y70cOEavWBEnHstlwwb7fFkyULb73fhcahOs6gIR/7vKOwkHeqmA== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: d3f79f89-6915-4f76-dfe1-08d86a918e16 X-MS-Exchange-CrossTenant-AuthSource: AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2020 07:21:06.1969 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JP9p7SJpD7DtQvCMZaBKNlY9CSJ0P1xtSmmcfOCYw3/LwhNgh+rlm+w2Ea0ORKAWb8sBpT93oiPs0g585/ta/tmCWBIycn2Bp6cOXK958nA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR10MB3333 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Currently, the only way to emulate functions with arguments in the U-Boot shell is by doing "foo=arg1; bar=arg2; run func" and having "func" refer to $foo and $bar. That works, but is a bit clunky, and also suffers from foo and bar being set globally - if func itself wants to run other "functions" defined in the environment, those other functions better not use the same parameter names: setenv g 'do_g_stuff $foo' setenv f 'do_f_stuff $foo $bar; foo=123; run g; do_more_f_stuff $foo $bar' foo=arg1; bar=arg2; run f Sure, f could do a "saved_foo=$foo; .... foo=$saved_foo" dance, but that makes everything even more clunky. In order to increase readability, allow passing positional arguments to the functions invoked via run: When invoked with a -- separator, the remaining arguments are use to set the local shell variables $1 through $9 (and $#). As in a "real" shell, they are local to the current function, so if f is called with two arguments, and f calls g with one argument, g sees $2 as unset. Then the above can be written setenv g 'do_g_stuff $1' setenv f 'do_f_stuff $1 $2; run g -- 123; do_more_f_stuff $1 $2' run f -- arg1 arg2 Everything except - b_addchr(dest, '?'); + b_addchr(dest, ch); is under CONFIG_CMD_RUN_ARGS, and when CONFIG_CMD_RUN_ARGS=n, the ch there can only be '?'. So no functional change when CONFIG_CMD_RUN_ARGS is not selected. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- cmd/Kconfig | 10 ++++++++++ cmd/nvedit.c | 7 ++++++- common/cli.c | 44 ++++++++++++++++++++++++++++++++++++++------ common/cli_hush.c | 32 +++++++++++++++++++++++++++++++- include/cli_hush.h | 9 +++++++++ 5 files changed, 94 insertions(+), 8 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 0c984d735d..b8426d19d7 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -443,6 +443,16 @@ config CMD_RUN help Run the command in the given environment variable. +config CMD_RUN_ARGS + bool "allow positional arguments with run command" + depends on HUSH_PARSER + depends on CMD_RUN + help + Allow invoking 'run' as 'run f g -- arg1 arg2 ...', which + will run the commands defined in the environment variables f + and g with positional arguments $1..$9 set to the arguments + following the -- separator. + config CMD_IMI bool "iminfo" default y diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 7fce723800..202139bfb9 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -1575,7 +1575,12 @@ U_BOOT_CMD_COMPLETE( run, CONFIG_SYS_MAXARGS, 1, do_run, "run commands in an environment variable", "var [...]\n" - " - run the commands in the environment variable(s) 'var'", + " - run the commands in the environment variable(s) 'var'\n" + CONFIG_IS_ENABLED(CMD_RUN_ARGS, ( + "run var [...] -- arg1 arg2 [...]\n" + " - run the commands in the environment variable(s) 'var',\n" + " with shell variables $1, $2, ... set to arg1, arg2, ...\n" + )), var_complete ); #endif diff --git a/common/cli.c b/common/cli.c index 6635ab2bcf..f970bd1eae 100644 --- a/common/cli.c +++ b/common/cli.c @@ -131,24 +131,56 @@ int run_command_list(const char *cmd, int len, int flag) #if defined(CONFIG_CMD_RUN) int do_run(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int i; + struct run_args ra; + int i, j; + int ret = 0; + int cmds = argc; if (argc < 2) return CMD_RET_USAGE; - for (i = 1; i < argc; ++i) { + if (CONFIG_IS_ENABLED(CMD_RUN_ARGS)) { + for (i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "--")) { + cmds = i; + ++i; + break; + } + } + ra.count = argc - i; + if (ra.count > MAX_RUN_ARGS) { + printf("## Error: At most %d positional arguments allowed\n", + MAX_RUN_ARGS); + return 1; + } + for (j = i; j < argc; ++j) + ra.args[j - i] = argv[j]; + + ra.prev = current_run_args; + current_run_args = &ra; + } + + for (i = 1; i < cmds; ++i) { char *arg; arg = env_get(argv[i]); if (arg == NULL) { printf("## Error: \"%s\" not defined\n", argv[i]); - return 1; + ret = 1; + goto out; } - if (run_command(arg, flag | CMD_FLAG_ENV) != 0) - return 1; + if (run_command(arg, flag | CMD_FLAG_ENV) != 0) { + ret = 1; + goto out; + } } - return 0; + +out: + if (CONFIG_IS_ENABLED(CMD_RUN_ARGS)) + current_run_args = ra.prev; + + return ret; } #endif diff --git a/common/cli_hush.c b/common/cli_hush.c index 072b871f1e..df35c9c8d2 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -135,6 +135,11 @@ DECLARE_GLOBAL_DATA_PTR; #define syntax() syntax_err() #define xstrdup strdup #define error_msg printf + +#ifdef CONFIG_CMD_RUN_ARGS +struct run_args *current_run_args; +#endif + #else typedef enum { REDIRECT_INPUT = 1, @@ -2144,6 +2149,10 @@ char *get_local_var(const char *s) #ifdef __U_BOOT__ if (*s == '$') return get_dollar_var(s[1]); + /* To make ${1:-default} work: */ + if (IS_ENABLED(CONFIG_CMD_RUN_ARGS) && + '1' <= s[0] && s[0] <= '9' && !s[1]) + return get_dollar_var(s[0]); #endif for (cur = top_vars; cur; cur=cur->next) @@ -2826,6 +2835,23 @@ static char *get_dollar_var(char ch) case '?': sprintf(buf, "%u", (unsigned int)last_return_code); break; +#ifdef CONFIG_CMD_RUN_ARGS + case '#': + if (!current_run_args) + return NULL; + sprintf(buf, "%u", current_run_args->count); + break; + case '1' ... '9': { + const struct run_args *ra = current_run_args; + int i = ch - '1'; + + if (!ra) + return NULL; + if (i >= ra->count) + return NULL; + return ra->args[i]; + } +#endif default: return NULL; } @@ -2865,10 +2891,14 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i } else switch (ch) { #ifdef __U_BOOT__ case '?': +#ifdef CONFIG_CMD_RUN_ARGS + case '1' ... '9': + case '#': +#endif ctx->child->sp++; b_addchr(dest, SPECIAL_VAR_SYMBOL); b_addchr(dest, '$'); - b_addchr(dest, '?'); + b_addchr(dest, ch); b_addchr(dest, SPECIAL_VAR_SYMBOL); advance = 1; break; diff --git a/include/cli_hush.h b/include/cli_hush.h index 2bd35670c7..d6eb7e908d 100644 --- a/include/cli_hush.h +++ b/include/cli_hush.h @@ -23,4 +23,13 @@ char *get_local_var(const char *s); #if defined(CONFIG_HUSH_INIT_VAR) extern int hush_init_var (void); #endif + +#define MAX_RUN_ARGS 9 +struct run_args { + struct run_args *prev; + int count; + char *args[MAX_RUN_ARGS]; /* [0] holds $1 etc. */ +}; +extern struct run_args *current_run_args; + #endif From patchwork Wed Oct 7 07:20:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1377809 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=jcFMeqyP; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C5m3y6LlTz9s0b for ; Wed, 7 Oct 2020 18:21:50 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 97E83823E6; Wed, 7 Oct 2020 09:21:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="jcFMeqyP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D3D7D823DD; Wed, 7 Oct 2020 09:21:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0713.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::713]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1A253823C9 for ; Wed, 7 Oct 2020 09:21:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=je3prtq2NfxcOZTC8QGQ31j3knx1ZMkFq0q9VsfEwZRIJfKZ/rEPEOYHSpt994wYI1w4YP6XJVoFoWU3WK7jfEbgRHxFndvfhmyhjJIeZqVZH8t8H9nAVMCIR7d40G3fVYDtYVtu7H3ZZdv6z2BjXrMTaHbJRSDP4jHmaiB0iKXrM39vGvJo7Y308i6No87DK6SsIrkcyWxv7JGRdURvSEmlnUIyrm2dTs9Va/rO0uAj/fuVxZFAgOQV5NUei9n/hqu9q0ij3rgqwa+jq7OUAB8a6JHobDyp/NCm24jpFRz2b1goCZe5ltCTWWaue6j/zUylEab5TawYkJyGaZfOOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KY/iCot4pc2tHXcFyMA7n0aRtm75/c6zZ9X4FJwldVY=; b=l+IOpgk9POHXnXCh8Q8JFs71wpz+wkjXdlAFzMyzDvi5TfD3j1xBB98Ip6FqO3g52om83CU5ZMmHxprctGUHjjF+LxxxJkKlT/RX6kXs+yg0XAV9jdSFOVVtY5QF1n8IS0tLj2pmn7qoA1w4RwmtDOo14Q/QC4udylsfG3x4Jjlee9CGuWKZrc51Bqhv0e5IMsxKfrT5q3gHnNFov1iDaXtACG3T1pgXWoQhknF318g8p2JsCNJtwYRwxuoWh3Nh6dHfwI+TvctNkxuYXDSc84XoOHROH8WgsA/+kFrz2vnKZa8fXASB6KEte2UY7mqSoLijYSxbpDDhjcugUmh2rQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KY/iCot4pc2tHXcFyMA7n0aRtm75/c6zZ9X4FJwldVY=; b=jcFMeqyPV/1cYCMw+Vl4ZmxYrP2m2PPweaElr5PwIykli3tLhf/SOEamVsA8gRTIENifFYx4u9qfPDYOFurrbqqpoNAXxQcBflYu/AcfsH+ENchYRq0muBudm56EXuPFEZgrdwa/PUHBApR39c29Er6VxzjnaB4f4CDt0bDmZso= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:2f::12) by AM7PR10MB3333.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:10c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.22; Wed, 7 Oct 2020 07:21:07 +0000 Received: from AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc8a:f8d9:a15f:44ce]) by AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc8a:f8d9:a15f:44ce%7]) with mapi id 15.20.3433.045; Wed, 7 Oct 2020 07:21:07 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Wolfgang Denk , Tom Rini , Rasmus Villemoes Subject: [PATCH v2 3/3] ut: add small hush tests Date: Wed, 7 Oct 2020 09:20:52 +0200 Message-Id: <20201007072052.28200-4-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201007072052.28200-1-rasmus.villemoes@prevas.dk> References: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> <20201007072052.28200-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [81.216.59.226] X-ClientProxiedBy: AM0PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:208:122::18) To AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:2f::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (81.216.59.226) by AM0PR04CA0005.eurprd04.prod.outlook.com (2603:10a6:208:122::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21 via Frontend Transport; Wed, 7 Oct 2020 07:21:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ce9e5ae-6365-490d-3ace-08d86a918e94 X-MS-TrafficTypeDiagnostic: AM7PR10MB3333: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:31; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sLVLh4Nejh7N9IATQT2SfAXtSRetmhwz6For2wYEpj08L9kPrXwymSHwYcDvaODJlAbkC1iI/v9BKGNwshAYa64rHqaSr+46rM7K2ajXY9x+MZUr/GrCnFOFlQhUUVYTm4meqqQTJWJwnO/Waoosn4B7JzyccFo7JzeknBr79s+yD0YgOeTUh3X3xRuRebiF9HYf0F/Zqa8YSGoQ/tYc3purN2qcRifEdZekGN/axT2REW7XqnC8apYE0BL16xLjKMuHIqumKGw0lbpFK+T4zry96yprWxUaN6KBfbJT/CzxZPnYnDHv5mTqrdQzUFe8A5pEXdsN7EQbTyf0SHxjxg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(396003)(346002)(136003)(39840400004)(366004)(376002)(107886003)(66476007)(66556008)(8676002)(36756003)(66946007)(26005)(16526019)(8976002)(8936002)(186003)(6512007)(478600001)(2616005)(956004)(6506007)(6486002)(5660300002)(1076003)(52116002)(54906003)(4326008)(6666004)(86362001)(316002)(44832011)(2906002)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Ek9hcVWEBtw5sz+AqdhZ6vmDqjSmIy1pjokrFs2Eiur4EhUg7B+3I2Qz2YbebU52E+08JYNtZQg4rRhWx3ZsgwdrOFisIFWKlP60EsxrO4igOyLDzU11YCfNsuM5HMDbuUZPTgG6SSoh/iJI70GUatGpl6KmXmoXo3UxH1nXqVvQiIlkeFkzKmk+UuJIkMih7Ae/5XyP/x6g80MJoyqb88lOvhSh49Avb3UHoWMTEL07/S8BL0LNvQkIPAqVx7vfRz+1/ZJuRbkS2INKeI9aPdKp4rWZBcFbi5jvNfHIfWvz417FUjpPVFeBw1TD9P/JhD836FwdrkDVKDrnFqxGiwcrGU3iAwixUdQAtxd/t4arFBjHI6G3sF06rL2m6CQYOhmFqvlWp10xXuprtHR+u6TEBRtO7rhmmGPKnyzAz4xGrYLZUkwqhynPoGv+kLQ1Y4CdQXA+xyc/2vHrvKMSuHXEQ9gV1MgDPLj94JKouOfhpkWuLcpxi0t7/MJ5jTCGEqf5FQtTfnA7eXPw+YLXrx343HY48DHerds99yuZBII3KIZeaNNI8Na4gLuFlfCSZUfEBcRKnu0TvtFEFBnZTL7KnWTsbC1KJTqplNW7EG4yFhlpyL9y8WBX1HsvxK2b+Lyu1E+kvhBJuhDDOghZ/Q== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 8ce9e5ae-6365-490d-3ace-08d86a918e94 X-MS-Exchange-CrossTenant-AuthSource: AM6PR10MB1880.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2020 07:21:07.0524 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8PyTW+kKkgkrs/hY/jRF+gzmCI1lsO/jd8iEOsr0yyZP2r4jvo1R72qjPE6wNv5bzNGZx6DQLij/R2Zs+haZ0IGz9NfPAeTK2l4miaODgjk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR10MB3333 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean This is primarily to add a test of the new "call" command, but we might as well add some very basic tests as well. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + include/test/suites.h | 1 + test/cmd/Makefile | 1 + test/cmd/hush.c | 91 +++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 6 +++ 6 files changed, 101 insertions(+) create mode 100644 test/cmd/hush.c diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index c3ca796d51..96e5a37627 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -25,6 +25,7 @@ CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y # CONFIG_CMD_ELF is not set +CONFIG_CMD_RUN_ARGS=y CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y CONFIG_CMD_ERASEENV=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 6e9f029cc9..94c8376837 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -30,6 +30,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_ELF is not set +CONFIG_CMD_RUN_ARGS=y CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y CONFIG_CMD_ERASEENV=y diff --git a/include/test/suites.h b/include/test/suites.h index ab7b3bd9ca..082b87ce52 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -32,6 +32,7 @@ int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_hush(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 859dcda239..adc5ba0307 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -4,3 +4,4 @@ obj-y += mem.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o +obj-$(CONFIG_HUSH_PARSER) += hush.o diff --git a/test/cmd/hush.c b/test/cmd/hush.c new file mode 100644 index 0000000000..1f5e8afdf2 --- /dev/null +++ b/test/cmd/hush.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include + +#define HUSH_TEST(_name, _flags) UNIT_TEST(_name, _flags, hush_test) + +int do_ut_hush(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + struct unit_test *tests = ll_entry_start(struct unit_test, hush_test); + const int n_ents = ll_entry_count(struct unit_test, hush_test); + + return cmd_ut_category("cmd_hush", "cmd_hush_", tests, n_ents, argc, + argv); +} + +static int hush_test_basic(struct unit_test_state *uts) +{ + run_command("true", 0); + ut_assert_console_end(); + + run_command("echo $?", 0); + ut_assert_nextline("0"); + ut_assert_console_end(); + + run_command("false", 0); + ut_assert_console_end(); + + run_command("echo $?", 0); + ut_assert_nextline("1"); + ut_assert_console_end(); + + return 0; +} +HUSH_TEST(hush_test_basic, UT_TESTF_CONSOLE_REC); + +static int hush_test_cond(struct unit_test_state *uts) +{ + run_command("if true ; then echo yay ; else echo nay ; fi", 0); + ut_assert_nextline("yay"); + ut_assert_console_end(); + + run_command("if false ; then echo yay ; else echo nay ; fi", 0); + ut_assert_nextline("nay"); + ut_assert_console_end(); + + /* Short-circuiting */ + run_command("if true || echo x ; then echo yay; else echo nay ; fi", 0); + ut_assert_nextline("yay"); + ut_assert_console_end(); + + run_command("if false || echo x ; then echo yay; else echo nay ; fi", 0); + ut_assert_nextline("x"); + ut_assert_nextline("yay"); + ut_assert_console_end(); + + run_command("if true && echo x ; then echo yay; else echo nay ; fi", 0); + ut_assert_nextline("x"); + ut_assert_nextline("yay"); + ut_assert_console_end(); + + run_command("if false && echo x ; then echo yay; else echo nay ; fi", 0); + ut_assert_nextline("nay"); + ut_assert_console_end(); + + return 0; +} +HUSH_TEST(hush_test_cond, UT_TESTF_CONSOLE_REC); + +#ifdef CONFIG_CMD_RUN_ARGS +static int hush_test_call(struct unit_test_state *uts) +{ + run_command("env set f 'echo f: argc=$#, [$1] [${2}] [${3:-z}]; run g -- $2; echo f: [$1] [${2}]'", 0); + ut_assert_console_end(); + + run_command("env set g 'echo g: argc=$#, [$1] [$2] [${2:-y}]'", 0); + ut_assert_console_end(); + + run_command("run f g -- 11 22", 0); + ut_assert_nextline("f: argc=2, [11] [22] [z]"); + ut_assert_nextline("g: argc=1, [22] [] [y]"); + ut_assert_nextline("f: [11] [22]"); + ut_assert_nextline("g: argc=2, [11] [22] [22]"); + ut_assert_console_end(); + + return 0; +} +HUSH_TEST(hush_test_call, UT_TESTF_CONSOLE_REC); +#endif diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 8f0bc688a2..cd903186b9 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -81,6 +81,9 @@ static struct cmd_tbl cmd_ut_sub[] = { #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD) U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""), #endif +#ifdef CONFIG_HUSH_PARSER + U_BOOT_CMD_MKENT(hush, CONFIG_SYS_MAXARGS, 1, do_ut_hush, "", ""), +#endif #ifdef CONFIG_SANDBOX U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression, "", ""), @@ -140,6 +143,9 @@ static char ut_help_text[] = #ifdef CONFIG_UT_ENV "ut env [test-name]\n" #endif +#ifdef CONFIG_HUSH_PARSER + "ut hush - test (hush) shell functionality\n" +#endif #ifdef CONFIG_UT_LIB "ut lib [test-name] - test library functions\n" #endif