[dpdk-dev] [RFC v1 5/9] app/testpmd: add python command
Xueming Li
xuemingl at mellanox.com
Fri Dec 8 09:22:21 CET 2017
py shell: invoke python shell, Ctrl+d to quit
py <any>: run python clause
Signed-off-by: Xueming Li <xuemingl at mellanox.com>
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 <rte_pmd_i40e.h>
#endif
+#ifdef RTE_LIBRTE_PYTHON
+#include <rte_python.h>
+#endif
#ifdef RTE_LIBRTE_BNXT_PMD
#include <rte_pmd_bnxt.h>
#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
More information about the dev
mailing list