From patchwork Fri Mar 31 19:13:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allain Legacy X-Patchwork-Id: 23047 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 5AFDD2B98; Fri, 31 Mar 2017 21:13:43 +0200 (CEST) Received: from mail5.wrs.com (mail5.windriver.com [192.103.53.11]) by dpdk.org (Postfix) with ESMTP id C56CFFE5 for ; Fri, 31 Mar 2017 21:13:34 +0200 (CEST) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id v2VJDX8X018411 (version=TLSv1 cipher=AES128-SHA bits=128 verify=OK); Fri, 31 Mar 2017 12:13:33 -0700 Received: from yow-cgts4-lx.wrs.com (128.224.145.137) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 31 Mar 2017 12:13:32 -0700 From: Allain Legacy To: CC: Date: Fri, 31 Mar 2017 15:13:19 -0400 Message-ID: <20170331191320.143047-2-allain.legacy@windriver.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170331191320.143047-1-allain.legacy@windriver.com> References: <20170331191320.143047-1-allain.legacy@windriver.com> MIME-Version: 1.0 X-Originating-IP: [128.224.145.137] Subject: [dpdk-dev] [PATCH 1/2] app/testpmd: load cmdline commands from file at startup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adds support to testpmd to load a set of cmdline CLI commands at startup. This can be helpful when needing to cut-n-paste many commands each time testpmd is restarted. This option will work in both interactive and non-interactive modes. ./testpmd -n4 -c3 ... -- --cmdline-file=/home/ubuntu/somefile.txt Signed-off-by: Allain Legacy Acked-by: Jingjing Wu --- app/test-pmd/cmdline.c | 21 ++++++++++++++++ app/test-pmd/parameters.c | 10 ++++++++ app/test-pmd/testpmd.c | 4 +++ app/test-pmd/testpmd.h | 2 ++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 39 +++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 47f935d20..3d7f90360 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -12579,6 +12579,27 @@ cmdline_parse_ctx_t main_ctx[] = { NULL, }; +/* read cmdline commands from file */ +void +cmdline_read_from_file(const char *filename) +{ + struct cmdline *cl; + + cl = cmdline_file_new(main_ctx, "testpmd> ", filename); + if (cl == NULL) { + printf("Failed to create file based cmdline context: %s\n", + filename); + return; + } + + cmdline_interact(cl); + cmdline_quit(cl); + + cmdline_free(cl); + + printf("Read CLI commands from %s\n", filename); +} + /* prompt function, called from main on MASTER lcore */ void prompt(void) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 28db8cdd3..085b6fc73 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -86,6 +86,7 @@ usage(char* progname) printf("usage: %s " #ifdef RTE_LIBRTE_CMDLINE "[--interactive|-i] " + "[--cmdline-file=FILENAME] " #endif "[--help|-h] | [--auto-start|-a] | [" "--coremask=COREMASK --portmask=PORTMASK --numa " @@ -103,6 +104,7 @@ usage(char* progname) progname); #ifdef RTE_LIBRTE_CMDLINE printf(" --interactive: run in interactive mode.\n"); + printf(" --cmdline-file: execute cli commands before startup.\n"); #endif printf(" --auto-start: start forwarding on init " "[always when non-interactive].\n"); @@ -505,6 +507,7 @@ launch_args_parse(int argc, char** argv) { "help", 0, 0, 0 }, #ifdef RTE_LIBRTE_CMDLINE { "interactive", 0, 0, 0 }, + { "cmdline-file", 1, 0, 0 }, { "auto-start", 0, 0, 0 }, { "eth-peers-configfile", 1, 0, 0 }, { "eth-peer", 1, 0, 0 }, @@ -595,6 +598,13 @@ launch_args_parse(int argc, char** argv) printf("Interactive-mode selected\n"); interactive = 1; } + if (!strcmp(lgopts[opt_idx].name, "cmdline-file")) { + printf("CLI commands to be read from %s\n", + optarg); + snprintf(cmdline_filename, + sizeof(cmdline_filename), "%s", + optarg); + } if (!strcmp(lgopts[opt_idx].name, "auto-start")) { printf("Auto-start selected\n"); auto_start = 1; diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index e04e215ba..f7722d91f 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -87,6 +87,7 @@ uint16_t verbose_level = 0; /**< Silent by default. */ /* use master core for command line ? */ uint8_t interactive = 0; uint8_t auto_start = 0; +char cmdline_filename[PATH_MAX] = {0}; /* * NUMA support configuration. @@ -2140,6 +2141,9 @@ main(int argc, char** argv) rte_eth_promiscuous_enable(port_id); #ifdef RTE_LIBRTE_CMDLINE + if (strlen(cmdline_filename) != 0) + cmdline_read_from_file(cmdline_filename); + if (interactive == 1) { if (auto_start) { printf("Start automatic packet forwarding\n"); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 8cf286052..554896dc6 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -308,6 +308,7 @@ extern uint16_t nb_rx_queue_stats_mappings; extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */ extern uint8_t interactive; extern uint8_t auto_start; +extern char cmdline_filename[PATH_MAX]; /**< offline commands file */ extern uint8_t numa_support; /**< set by "--numa" parameter */ extern uint16_t port_topology; /**< set by "--port-topology" parameter */ extern uint8_t no_flush_rx; /** + + +In all cases output from any included command will be displayed as standard output. +Execution will continue until the end of the file is reached regardless of +whether any errors occur. The end user must examine the output to determine if +any failures occurred. + + Control Functions -----------------