From patchwork Fri Sep 25 11:19:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1371177 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=none (p=none 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=JFbnGCsl; 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 4ByTxW0Vbkz9sSJ for ; Fri, 25 Sep 2020 21:21:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0D78C826DB; Fri, 25 Sep 2020 13:20:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none 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="JFbnGCsl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4FB2C826C8; Fri, 25 Sep 2020 13:20:40 +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 EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0709.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe02::709]) (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 CC9A38253F for ; Fri, 25 Sep 2020 13:20:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none 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=PXFHOMqUBgurMm2iKxJIWPaQBsRl7bvB2imto+YchJ6PmL5Sxc6p7Xr81VHFAM9PdxqTGOdJWWqacZGARTSsllXBPxwVYIpsuoLrMsfbwhs+SjOELu3U/iAjT+XUrSxrsJlGH69dgZgbxQ3l9V7PGCAKMUfOnQOfcKf5XxnVovl2SSQBTXrpVeGqK1aJYKMZJsIqKicUdC9g0e+DBWw6qiALsC00fU8StENeamu+dssD6vPp7GDKjhaYA+VLktbBKkwph3isp1VcAO0b0q2QfLm8JmuLlGEi568BvP/FyqM8mxca4wkJvwP+5s4PN4G9bZd6H8U+Lpx9LPnTtlbl8Q== 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=WW02C5fYqRh5Qz3T7KSVeVirXIBAYroPItP1iieLBBzwtVNq8b/fR/5BZmR7t6P/VSP3AEz8iGZY42DdcRFHmyyAV44oKbQ0nIq83jTtSh55xwswayn03UNpPAYXPARKlhZEi38jOS2pTcDJFykhzxbV3DXAUXxdjoEJ//6npDbrLe+gTVTOrJvnKmGYie3p6kJhNCFIsZVeW0aJKhEVhZQEVecHbmLRjJmh0FJXMLvs6X/IAQsN9NV5D2efyDN5VkcyqLVIvVwBG+0+Z/TBpkkMdfi2tLk7SlOlAIyiZkuinAVO7e9TbIRxu+qY+gdmmY0Wel6mImEbxM7XB0/0Kg== 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=JFbnGCslFOqNtjmB0KYB/N8GFDVM/1ajV3cHsHQSQAWHK0qf8POlObOu2sbL76HpEiKiHI6aK4aUUH7JM46v7k92fLFOY43qe7g5h6vbEbXPXjYIjLXhmjYor+f6e+ksDTioIl2XBhJI0FvwN3a59bHiv8vqJjTRCCMUWgzx6cg= 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 AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM4PR1001MB1252.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:200:90::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Fri, 25 Sep 2020 11:20:34 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::acf4:4f51:6c3a:8cbc]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::acf4:4f51:6c3a:8cbc%5]) with mapi id 15.20.3412.020; Fri, 25 Sep 2020 11:20:34 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Rasmus Villemoes Subject: [PATCH 1/3] cli_hush.c: refactor handle_dollar() to prepare for cmd_call Date: Fri, 25 Sep 2020 13:19:40 +0200 Message-Id: <20200925111942.4629-2-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> References: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM6P193CA0065.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::42) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.115.188) by AM6P193CA0065.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.22 via Frontend Transport; Fri, 25 Sep 2020 11:20:33 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.115.188] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e56da64-3392-4ccd-2129-08d86145050e X-MS-TrafficTypeDiagnostic: AM4PR1001MB1252: 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: Gt/iMlcgfctMJG+QJEPCdaEHaK+w57SBZiGR1m8SZD1XGDGcKiu7zkajEdW3coFW7B+Y8K867f5lyZlnxZ3SoTa2NYZRBcMXIIQ0oewLy15TN4uLGDQrgtag05y5JiKMncmfZvqTaLlrwKI03io4qF4RjRPExPuo0k1Fon3zXmhdAcdZ4pboaFHn23kW7EmBxMGE0rjGbnhbrRnQuaFHBLIFd59+jbiLu2WGqqS+SgpQFJ+5u2DZUzF31VIFInIdNAWiHmEgki7C9YsdS6SuaPnjZF4XXrfit4B8Y2hOBo2Cwy1/DWKA3X9qcTNP0N/Lx7wM/GgVMSRU+XhDx/wD2NKc45w6qJunwlQdC7q9fEkEN+qP3ts8GNzZZjHg04UB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(396003)(39830400003)(136003)(366004)(346002)(376002)(83380400001)(26005)(66556008)(66946007)(36756003)(8676002)(6512007)(107886003)(2616005)(66476007)(8936002)(6486002)(8976002)(4326008)(16526019)(6506007)(54906003)(5660300002)(2906002)(6916009)(86362001)(44832011)(1076003)(6666004)(478600001)(52116002)(186003)(316002)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: v3ICHkPSzBTFJDGi7mTtbBBMNfBA8xFc77u1ebvbCiWsvFYN8XDKJa2JmuhRfIjCdWALsPgGD7uh3CDvqGQqWSwy9l72sG0dCc1bfnTmH5rGUN0ivLcS8fbUPlHG7zU5ye4FZ7s4OBg0N3bJSHydJUqwTt3176S/01vAFG+uiTK8/1QpgQlDqRLoNx2dj3m/Ib3coWO7xmP6+CsE1nkOkeDfgwwvOn4liGvgYIRlKYl/NWfykhzuxnBEAE2kAhT9cmru/fHPllraz3pcNir4iVHtDgzJ66HQVLC5+ioWwJNTPgMWknOcC+fmkSEr0+eS9GNMqDYkuxB0oHkeCXnbRI2AEI60H3tl8CTZFEA9Pxhpq3fe7H4BVZEFHb0zUFcjU5prL/BY+0PjA303MrZ9KJ3y7pf28syRur4lTvsyLg9Tksn+62+N6KHtxS3AwOvyHgqZgzjUklbLlQw7DTfEM2q0HaYxZvS1x6CssZNwjwwvNmfXhf2ZIE7pjP9NjF1PsGrTsw41QIlVcBZXnB5QW1HbaKfbDfi8vLIw5UhkMNIdHdycR6xmklwHt4Jdm0O0Tfxr2bOISlRLq1cnm2Nb3UsFBMtO2FzSTlxX0ef58DR/58Js42X7+qoYzv1vdKbxtK+YmdScJQfWhOCQQgzVwA== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 0e56da64-3392-4ccd-2129-08d86145050e X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2020 11:20:34.1043 (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: ciOEHm2AM6v+R5RVu+sUmP5IiOWuGdxs3CEKvb1jgt31UA9sjjKK0sVmQ8RfcEeQ4j1EMVri612+f3nQ6q0UhX87BvaURc5ErRxsnXKsxW0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR1001MB1252 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 --- 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 Fri Sep 25 11:19:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1371176 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=none (p=none 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=C2tCWwsc; 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 4ByTxJ4ySPz9sSf for ; Fri, 25 Sep 2020 21:20:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88A65826CD; Fri, 25 Sep 2020 13:20:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none 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="C2tCWwsc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A49CC826A5; Fri, 25 Sep 2020 13:20:38 +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 EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on070b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::70b]) (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 ED29782684 for ; Fri, 25 Sep 2020 13:20:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none 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=KQOLYQXDsLqJtnR/Qy3/dSJWXTq/UP9F4gEYeCYcKqkmura+V9cKz7yBsAW+NaE5lGXDE+YoUhW+M3YlAo5kkHs/FLXvDr+NHfrH88UwsATppDwoqVwSvz33y18Xcou3UUG6sXWnu6eEOuyI+GbTFAjvMeubAFFJ0a2aHk5+jVs5OBH4GLJ7GxXkbtZGVYhagvQqdiiBIORiYKIXH1r65nRzuFl54kvquMkYMF47nsM/ROmsDegvGIlFDkMtIWic24QcXOLRUv0LL0VSNVn6voZDueAJ+P2XpuYsJmvYVsw8P/XFO0vt8H5S0bUDHIjBnRUfA9Ov+0jiyBbSufvMQg== 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=4aotYPPmrwe1cIQue+EcM496A7n2Om7lw+V5FHiXFwI=; b=Kcd+nvhhE6b68hev1pXzBXZgTH34e3mrIhVqEhY4kF3mpg94x7MT4lWEXftQpHMkSc70x4UuIFZM6G8vdyAIz/X5m7EUyfmXyZ+daT+RLSpZIA7IXcmvpr67b+lKRZoU24G5r75BGx6/J8Ar/2d6btAtisoLgl8julGSUCSKT01X4uFPmnPVq5iF+L0bAyxvTLC4NWb5sJI7Amm1K50K4h6da5UMbzGP1jF8gLfe4VT8At7WFHIhSBLSxKTQkd7T4SOOm+QMNUTPALyvQ7IeQORMQqDAYj/pXg7l/wRyv+D6gpjK/cVRVztpbooX5yzRIU5OHhz04amgyH/YGcIqDQ== 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=4aotYPPmrwe1cIQue+EcM496A7n2Om7lw+V5FHiXFwI=; b=C2tCWwsckQIwmTouJoKGOvoZrGfkd+V/eElmFgzdgwmHH/d3w9emVn/2xd7o+OaoW6JnMwAHguxr+pyr0aS84jnMAFlXFCsj/Ig27V2mPn8ynM3WXC9aSCJe8C7rP7GQKe9rkWgQfG/Llny/dKrP+53FWcqBD6s++9ikzqQlq8o= 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 AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM0PR10MB2276.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:dd::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Fri, 25 Sep 2020 11:20:34 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::acf4:4f51:6c3a:8cbc]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::acf4:4f51:6c3a:8cbc%5]) with mapi id 15.20.3412.020; Fri, 25 Sep 2020 11:20:34 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Rasmus Villemoes Subject: [PATCH 2/3] cli_hush.c: add "call" command Date: Fri, 25 Sep 2020 13:19:41 +0200 Message-Id: <20200925111942.4629-3-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> References: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM6P193CA0065.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::42) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.115.188) by AM6P193CA0065.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.22 via Frontend Transport; Fri, 25 Sep 2020 11:20:34 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.115.188] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b805b87-cfbb-4d8d-ae25-08d86145056c X-MS-TrafficTypeDiagnostic: AM0PR10MB2276: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZOvuzkk7lr2TTp7O/dpH+wxWEKGWZ8r97Jif+MLxvC/JgK9dm+J1qS7B+4+fqgxsjgyH0JA5aiB4dbVTGa9iTrTYJKeOck29CLAzFEieOm68FjjY9G4nIq36P0286zhK8ZTvjRlGrouH8r8HiRoFbX2GFWHllJkvQVYDMhj7Mgb84yqqc/uInkAWES6h+grWDum+0+BY68ecJ4eqoSK/Yg+ev2UI1vfaT0Q383Q2551mCSoR9B6frg3G/3OFNB38nc7NxROfvxpVqkrh76oKgv0skFf+1vneivIFcAKyw0npuWuL4lrEZVXgmbHpEUJqxAr3QqUpb0OtlIYvzqO2dA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(136003)(376002)(39840400004)(8976002)(956004)(52116002)(186003)(2616005)(6512007)(6486002)(36756003)(6916009)(1076003)(478600001)(6506007)(8676002)(316002)(16526019)(107886003)(2906002)(66476007)(66946007)(66556008)(44832011)(4326008)(83380400001)(54906003)(6666004)(86362001)(8936002)(26005)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 5NauQormD9yqm0Rv2lPjSs/M/raXx9m2QIFkrUxasAcjX9k/E1MTDD3g0YPCoSmFThxt5BmIlQn4ATZ9yQ4kJpHTfoBjqvcI1cuv9qj2/a45MMoZ0Ug2caLPiSvTy+kz5QATRUlN9aL7VAILodZZfodxlXMwTHizkSXghzY+hzVHIOlFH7OZDfvjeKkngYiS17BBanGscCeYuDoGwonm2ix9v1mMLLi3T5FYwAqzzpUEpIo8ktrQvYD+jgCnOQyMPoB/JJoO7Ab08qk3HQl7KaWTkmVp65TxFgj8niywA3cNA544uu5zYuepdZeTd1nja4V+jfpIjqry2apzrV9WuDfOaXGjA7sgUwOhPmpzK5vlwnVs2+ut3aXC/LRhtnsJlzKDLS5ag9VqTGrpdhpRXn7rrWOZoO5gAk7wC5Y1Gr9oRXZB7RXlt3CmNPKXCpcLSg/qIZZ2dwwIef4d6PSpuTjDZxk8qHAUfjfp1w1OqtMsjSUKv/qqit24FHmu+1YUJLn5VOXAmkKGZPcNMhMTGAKqk6raG4lYxiOPhL8Ru90hJqmpXuiZXYU0vSZFR2CF3o/Ew0LDhMBkX/7iC3Fj3d4gXofiSJ/Y2Rmzbnv1UZEPRiyLsWNiEj4HNctrB3A/Kdd9bh1u27GLfyghl52lKQ== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 3b805b87-cfbb-4d8d-ae25-08d86145056c X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2020 11:20:34.7169 (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: eiK/S1ddjjkjFMm1hEo3/AEcJqPJmF4mdTcfYMTBhBqVhSd3mrxy7R6lCrSP39zII1UIzhQNwcCQ/b4XonSX7LoVDUuLPE39tDzVyIpJsac= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB2276 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 busybox 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' Sure, f could do a "saved_foo=$foo; .... foo=$saved_foo" dance, but that makes everything even more clunky. In order to increase readability, add a little helper "call" that is like "run", but which sets 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; call g 123; do_more_f_stuff $1 $2' Everything except - b_addchr(dest, '?'); + b_addchr(dest, ch); is under CONFIG_CMD_CALL, and when CONFIG_CMD_CALL=n, the ch there can only be '?'. So no functional change when CONFIG_CMD_CALL is not selected. "Real shells" have special syntax for defining a function, but calling a function is the same as calling builtins or external commands. So the "call" may admittedly be seen as a bit of a kludge. It should be rather easy to make custom (i.e., defined in the environment) functions "transparently callable" on top of this infrastructure, i.e. so one could just say f a b c instead of call f a b c However, that behaviour should be controlled by a separate config knob, and can be added later if anyone actually wants it. Signed-off-by: Rasmus Villemoes --- cmd/Kconfig | 8 +++++ common/cli_hush.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 0c984d735d..306f115c32 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -443,6 +443,14 @@ config CMD_RUN help Run the command in the given environment variable. +config CMD_CALL + bool "call" + depends on HUSH_PARSER + depends on CMD_RUN + help + Call function defined in environment variable, setting + positional arguments $1..$9. + config CMD_IMI bool "iminfo" default y diff --git a/common/cli_hush.c b/common/cli_hush.c index 072b871f1e..e17fba99ee 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -135,6 +135,17 @@ DECLARE_GLOBAL_DATA_PTR; #define syntax() syntax_err() #define xstrdup strdup #define error_msg printf + +#ifdef CONFIG_CMD_CALL +#define MAX_CALL_ARGS 9 +struct call_args { + struct call_args *prev; + int count; + char *args[MAX_CALL_ARGS]; /* [0] holds $1 etc. */ +}; +static struct call_args *current_call_args; +#endif + #else typedef enum { REDIRECT_INPUT = 1, @@ -2144,6 +2155,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_CALL) && + '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 +2841,23 @@ static char *get_dollar_var(char ch) case '?': sprintf(buf, "%u", (unsigned int)last_return_code); break; +#ifdef CONFIG_CMD_CALL + case '#': + if (!current_call_args) + return NULL; + sprintf(buf, "%u", current_call_args->count); + break; + case '1' ... '9': { + const struct call_args *ca = current_call_args; + int i = ch - '1'; + + if (!ca) + return NULL; + if (i >= ca->count) + return NULL; + return ca->args[i]; + } +#endif default: return NULL; } @@ -2865,10 +2897,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_CALL + 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; @@ -3711,5 +3747,42 @@ U_BOOT_CMD( " - print value of hushshell variable 'name'" ); +#ifdef CONFIG_CMD_CALL +static int do_cmd_call(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct call_args ca; + char *run_args[2]; + int i, ret; + + if (argc < 2) + return CMD_RET_USAGE; + + ca.count = argc - 2; + for (i = 2; i < argc; ++i) + ca.args[i - 2] = argv[i]; + ca.prev = current_call_args; + current_call_args = &ca; + + run_args[0] = "run"; + run_args[1] = argv[1]; + ret = do_run(cmdtp, flag, 2, run_args); + + current_call_args = ca.prev; + + return ret; +} + +U_BOOT_CMD_COMPLETE( + call, 1 + 1 + MAX_CALL_ARGS, 0, do_cmd_call, + "call command in environment variable, setting positional arguments $1..$9", + "var [args...]\n" + " - run the command(s) in the environment variable 'var',\n" + " with $1..$9 set to the positional arguments", + var_complete +); + +#endif + #endif /****************************************************************************/ From patchwork Fri Sep 25 11:19:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1371178 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=none (p=none 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=g6R21876; 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 4ByTxk1lgrz9sSJ for ; Fri, 25 Sep 2020 21:21:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 62100826CA; Fri, 25 Sep 2020 13:20:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none 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="g6R21876"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B0F86826BF; Fri, 25 Sep 2020 13:20:40 +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 EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on070b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::70b]) (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 34EE68269B for ; Fri, 25 Sep 2020 13:20:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none 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=dI+MpQA+CUPqQkzrkMJajVBB+Wc5EyZcAE32WO3hI9j8xhGuqewb0NUvZz48c6blTEWroYjSvUIlY6OweqMsDcIf1u0N3oBO56CZ3QRwZL1xYp9e2mZShkcMFsaPjnfJWQ0/ACkosFoBEB2hdEDBpcr0VfI8jhOqZda99pNaZ1+SdhRxiGlob2zvNJe/j4ahZX065iow/CeYY2+yvGQNOcDRdXjAZ5qE97K1wXQIMz8ICJq+S2ZDbIzrqb/xTuXcvfBGzoQ2Cfv1IBFUlxWziH5AslCOFQi/0byqY0A0Ev39eMpRAhuQzp2t4dQKT1Uw8ZZVs6Tzpz4jgcrMI6v/eg== 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=3yDUtkmFrL466Jrc7ixAP6/00y5zthwy297PtOXqQns=; b=YqqXiKWJnpxW3fGkmUzC/wW6iFB3CV2cokh4GM6h08GOpBaacgyDiffJpG83Z+s6VvGa/eTRruiLklbg1IP2duK+/rxEn4rclsba7JXChv68JLmslkpFpbO3zNZrfB8uUjNSWXLg4X2eU+b0t0tjWXdCKr71bL6ZmhQ1p8EefaIWKsKY09fnA0R7FYwC9FtJ5tlV7A6okpqRMSaDGL5xf9SIUGZLnlybYEYIggYHbCxmD5+RMw58dvfTtSr/gDEMLiRDz8BZMdxb8CGj4Gkny9mbjabaNdrUMuJ7bkTr55Si5EAB3TUvmdYfB3fXZQgGjx1X5YSpJNSYQdoD+YbMmQ== 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=3yDUtkmFrL466Jrc7ixAP6/00y5zthwy297PtOXqQns=; b=g6R21876Kz9kIeynz3qZ5jUcNOkmHYMuTSlBl5U241Ni0tHYO4aBtdiE6A4zrrMNR+NNCH7ZeFXQ1m3T0hfcMbhPdyjRX8IttuL5jnb7aeEpJDX8UMIc25zGYoyszZ/Zg7Irn6c8RH28yIOW7mWNuOMDvcYVEdFF7XpwF4jz4Fo= 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 AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM0PR10MB2276.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:dd::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Fri, 25 Sep 2020 11:20:35 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::acf4:4f51:6c3a:8cbc]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::acf4:4f51:6c3a:8cbc%5]) with mapi id 15.20.3412.020; Fri, 25 Sep 2020 11:20:35 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Rasmus Villemoes Subject: [PATCH 3/3] ut: add small hush tests Date: Fri, 25 Sep 2020 13:19:42 +0200 Message-Id: <20200925111942.4629-4-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> References: <20200925111942.4629-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM6P193CA0065.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::42) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.115.188) by AM6P193CA0065.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.22 via Frontend Transport; Fri, 25 Sep 2020 11:20:34 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.115.188] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3a004b3-f8fd-4335-6ef6-08d8614505ce X-MS-TrafficTypeDiagnostic: AM0PR10MB2276: 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: t+mBCLcKx2kR1+1hfSgcr/zzp+j0BONH1O7CFml4MYkeUHWCBIOG0WV5sp5ynYKqhytvimTANYQLSCBGLwac+BJOcFNkrGBfqAsF/OxskiS3uToptoFAbAk8QDYlFk/IPWnXIacEa9w9A4T+VBSeEF5FfvO7n6+RpXCRF4wNNC1Pa6nPZAIoz0YGawrbVbl1tzOwxK3Uh4ZUTJ7NyzkJRochvznyLhVszA+JIf6Hm9aiLAAqSupSCsL0kY3QNGnLAGXu5+f8mpQAn4ob6Vgu3GmBMzivaimiyGILGqdEx85aD4z1nEyEwDEIc0cb5YhI7A7BK8qRr7iB0DgJUblukw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(366004)(396003)(346002)(136003)(376002)(39840400004)(8976002)(956004)(52116002)(186003)(2616005)(6512007)(6486002)(36756003)(6916009)(1076003)(478600001)(6506007)(8676002)(316002)(16526019)(107886003)(2906002)(66476007)(66946007)(66556008)(44832011)(4326008)(54906003)(6666004)(86362001)(8936002)(26005)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: p0bCOi8ozpDfPWx0QGuxwZRmg3eNtFWZWEixunEbo0jK4+K9kb04PSqrJedHd2yPat2Gx4ISWOuDE5P06DULnXUXdiTqB00LvS1ka9vVMZ6keAnffb5UmegvzDLBbG73hwCPPPEzmLWzv9P9ZN7eTI8XoJAIJjAIsEDMhPfAXNWx+vQxLMsjPuCaus4cjQGWMqHbxqWZUSEkWifu07ULzbgFFcDwwW5KyCvGu42NNS4d9W3ZihNOO86Aem0tn/1ZfB24+sFRe6p02CRLP+CwlFqWjU/zlWSG3PjzJPs0aMzn8wHRax0pquoFyc7LDHoafBkn5f1f2pAN5RxJQzH69iJC4rYE03kRjyFAGGgsKgep3a+S9WfMRvT5kGQpOvvTHhWup2nm2Q0AnpNOtHSaje0Nr1sn+IRWy9kwJge5CtSt3vqrzJqRnKc2X1WIBSN5bqDyMH4XPAw00zflmTrMq4AquheFHYemTuS7YNn89/cMwVhTDE4+nsTI3ThYQkQ9v10/MMgQNRRwTLcZavEpb6K44Vh6kSk1CNhouR1OTEUxszf9vjXuyQLe8hJed+cgfJGvN4bN0qdq21UFot33ycGO0tLNuI4pAsQ/HI6LIAN79QUAT/vqlct3IIdsd0CZVnoUNlaah9CW6h+gYWCLhw== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: d3a004b3-f8fd-4335-6ef6-08d8614505ce X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2020 11:20:35.2446 (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: CTO/Yyv2wIaYBdixnkrDiDmSJVSJiBq4iIo7vum4bTWJizFt3mJ6+OMf3w7fjHhbujcusTMSKmen0KVmMhL3cpSaV2HiVO3vrNxF/bE1i2c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB2276 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 --- configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + include/test/suites.h | 1 + test/cmd/Makefile | 1 + test/cmd/hush.c | 90 +++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 6 +++ 6 files changed, 100 insertions(+) create mode 100644 test/cmd/hush.c diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index c3ca796d51..7e156e9813 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_CALL=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..ac06a8dc67 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_CALL=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..c4ad7b5e94 --- /dev/null +++ b/test/cmd/hush.c @@ -0,0 +1,90 @@ +// 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_CALL +static int hush_test_call(struct unit_test_state *uts) +{ + run_command("env set f 'echo f: argc=$#, [$1] [${2}] [${3:-z}]; call 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("call f 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_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