From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 58CFC1AEEB for ; Fri, 8 Dec 2017 09:23:11 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from xuemingl@mellanox.com) with ESMTPS (AES256-SHA encrypted); 8 Dec 2017 10:23:07 +0200 Received: from dev-r630-06.mtbc.labs.mlnx (dev-r630-06.mtbc.labs.mlnx [10.12.205.180]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id vB88N6jN001032; Fri, 8 Dec 2017 10:23:07 +0200 Received: from dev-r630-06.mtbc.labs.mlnx (localhost [127.0.0.1]) by dev-r630-06.mtbc.labs.mlnx (8.14.7/8.14.7) with ESMTP id vB88N6SE045192; Fri, 8 Dec 2017 16:23:06 +0800 Received: (from xuemingl@localhost) by dev-r630-06.mtbc.labs.mlnx (8.14.7/8.14.7/Submit) id vB88N6g5045191; Fri, 8 Dec 2017 16:23:06 +0800 From: Xueming Li To: Wu Jingjing , Harry van Haaren Cc: Xueming Li , dev@dpdk.org Date: Fri, 8 Dec 2017 16:22:21 +0800 Message-Id: <20171208082225.44913-6-xuemingl@mellanox.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171208082225.44913-1-xuemingl@mellanox.com> References: <20171208082225.44913-1-xuemingl@mellanox.com> In-Reply-To: <20171019140649.26668-2-xuemingl@mellanox.com> References: <20171019140649.26668-2-xuemingl@mellanox.com> Subject: [dpdk-dev] [RFC v1 5/9] app/testpmd: add python command 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: , X-List-Received-Date: Fri, 08 Dec 2017 08:23:11 -0000 py shell: invoke python shell, Ctrl+d to quit py : run python clause Signed-off-by: Xueming Li Conflicts: app/test-pmd/cmdline.c --- app/test-pmd/cmdline.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 4acce9f07..6654a62cb 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -95,6 +95,9 @@ #ifdef RTE_LIBRTE_I40E_PMD #include #endif +#ifdef RTE_LIBRTE_PYTHON +#include +#endif #ifdef RTE_LIBRTE_BNXT_PMD #include #endif @@ -150,6 +153,8 @@ struct cmd_help_long_result { cmdline_fixed_string_t section; }; +extern cmdline_parse_ctx_t main_ctx[]; + static void cmd_help_long_parsed(void *parsed_result, struct cmdline *cl, __attribute__((unused)) void *data) @@ -15535,6 +15540,58 @@ cmdline_parse_inst_t cmd_load_from_file = { }, }; +#ifdef RTE_LIBRTE_PYTHON + +/* "py" command */ +struct cmd_py_run_result { + cmdline_fixed_string_t py; + cmdline_fixed_string_t code; +}; + +cmdline_parse_token_string_t cmd_py_run_py = + TOKEN_STRING_INITIALIZER(struct cmd_py_run_result, py, "py"); +cmdline_parse_token_string_t cmd_py_run_code = + TOKEN_STRING_INITIALIZER(struct cmd_py_run_result, code, ""); + +static void +cmd_py_run_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_py_run_result *res = parsed_result; + + if (rte_python_init()) + return; + if (!strcmp("shell", res->code)) { + cmdline_stdin_exit(testpmd_cl); + if (rte_python_shell()) + printf("Failed to open python shell!\n"); + testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); + + } else if (!strcmp("debug", res->code)) { + rte_python_debug = 1; + rte_log_set_level(RTE_LOGTYPE_PYTHON, RTE_LOG_DEBUG); + } else if (!strcmp("nodebug", res->code)) + rte_python_debug = 0; + else + rte_python_run(res->code); +} + +cmdline_parse_inst_t cmd_py_run = { + .f = cmd_py_run_parsed, + .data = NULL, + .help_str = "run python code like: hex(123)\n" + "\t'py shell' to enter shell (ctrl + d to quit)\n" + "\t'py debug|nodebug' to toggle debug output, --log-level=9", + .tokens = { + (void *)&cmd_py_run_py, + (void *)&cmd_py_run_code, + NULL, + }, +}; +#endif + /* ******************************************************************************** */ /* list of instructions */ @@ -15543,6 +15600,9 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_help_long, (cmdline_parse_inst_t *)&cmd_quit, (cmdline_parse_inst_t *)&cmd_load_from_file, +#ifdef RTE_LIBRTE_PYTHON + (cmdline_parse_inst_t *)&cmd_py_run, +#endif (cmdline_parse_inst_t *)&cmd_showport, (cmdline_parse_inst_t *)&cmd_showqueue, (cmdline_parse_inst_t *)&cmd_showportall, -- 2.13.3