DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Olivier Matz <olivier.matz@6wind.com>,
	Bruce Richardson <bruce.richardson@intel.com>
Subject: [RFC PATCH v2 5/5] examples/bond: auto-generate cmdline boilerplate
Date: Mon, 18 Sep 2023 14:03:52 +0100	[thread overview]
Message-ID: <20230918130352.379478-6-bruce.richardson@intel.com> (raw)
In-Reply-To: <20230918130352.379478-1-bruce.richardson@intel.com>

Use the dpdk-cmdline-gen script to autogenerate all the boilerplate
structs and defines for the commandline part of the app.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 examples/bond/Makefile      |  10 ++-
 examples/bond/commands.list |   6 ++
 examples/bond/main.c        | 161 ++++--------------------------------
 examples/bond/main.h        |  10 ---
 examples/bond/meson.build   |   8 ++
 5 files changed, 36 insertions(+), 159 deletions(-)
 create mode 100644 examples/bond/commands.list
 delete mode 100644 examples/bond/main.h

diff --git a/examples/bond/Makefile b/examples/bond/Makefile
index ad711a5bee..0a559ad82b 100644
--- a/examples/bond/Makefile
+++ b/examples/bond/Makefile
@@ -6,6 +6,7 @@ APP = bond_app
 
 # all source are stored in SRCS-y
 SRCS-y := main.c
+SRC-DEPS := build/commands.h
 
 PKGCONF ?= pkg-config
 
@@ -24,10 +25,13 @@ static: build/$(APP)-static
 LDFLAGS += -lrte_net_bond
 
 PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
-CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
+CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) -I build/
 LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
 LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
 
+build/commands.h: commands.list Makefile
+	dpdk-cmdline-gen.py -o $@ --context-name=main_ctx $<
+
 ifeq ($(MAKECMDGOALS),static)
 # check for broken pkg-config
 ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),)
@@ -38,10 +42,10 @@ endif
 
 CFLAGS += -DALLOW_EXPERIMENTAL_API
 
-build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
+build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(SRC-DEPS)
 	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
 
-build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
+build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build  $(SRC-DEPS)
 	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
 
 build:
diff --git a/examples/bond/commands.list b/examples/bond/commands.list
new file mode 100644
index 0000000000..08e1a3fea8
--- /dev/null
+++ b/examples/bond/commands.list
@@ -0,0 +1,6 @@
+send <IP>ip
+start
+stop
+show
+help
+quit
\ No newline at end of file
diff --git a/examples/bond/main.c b/examples/bond/main.c
index 9b076bb39f..e893005701 100644
--- a/examples/bond/main.c
+++ b/examples/bond/main.c
@@ -45,16 +45,8 @@
 #include <rte_cpuflags.h>
 #include <rte_eth_bond.h>
 
-#include <cmdline_rdline.h>
-#include <cmdline_parse.h>
-#include <cmdline_parse_num.h>
-#include <cmdline_parse_string.h>
-#include <cmdline_parse_ipaddr.h>
-#include <cmdline_parse_etheraddr.h>
 #include <cmdline_socket.h>
-#include <cmdline.h>
-
-#include "main.h"
+#include "commands.h"
 
 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
 
@@ -462,11 +454,7 @@ static int lcore_main(__rte_unused void *arg1)
 	return 0;
 }
 
-struct cmd_obj_send_result {
-	cmdline_fixed_string_t action;
-	cmdline_ipaddr_t ip;
-};
-static inline void get_string(struct cmd_obj_send_result *res, char *buf, uint8_t size)
+static inline void get_string(struct cmd_send_result *res, char *buf, uint8_t size)
 {
 	snprintf(buf, size, NIPQUAD_FMT,
 		((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[0]),
@@ -475,12 +463,11 @@ static inline void get_string(struct cmd_obj_send_result *res, char *buf, uint8_
 		((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[3])
 		);
 }
-static void cmd_obj_send_parsed(void *parsed_result,
-		__rte_unused struct cmdline *cl,
-			       __rte_unused void *data)
+void
+cmd_send_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data)
 {
 
-	struct cmd_obj_send_result *res = parsed_result;
+	struct cmd_send_result *res = parsed_result;
 	char ip_str[INET6_ADDRSTRLEN];
 
 	struct rte_ether_addr bond_mac_addr;
@@ -544,29 +531,8 @@ static void cmd_obj_send_parsed(void *parsed_result,
 	cmdline_printf(cl, "\n");
 }
 
-cmdline_parse_token_string_t cmd_obj_action_send =
-	TOKEN_STRING_INITIALIZER(struct cmd_obj_send_result, action, "send");
-cmdline_parse_token_ipaddr_t cmd_obj_ip =
-	TOKEN_IPV4_INITIALIZER(struct cmd_obj_send_result, ip);
-
-cmdline_parse_inst_t cmd_obj_send = {
-	.f = cmd_obj_send_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "send client_ip",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_obj_action_send,
-		(void *)&cmd_obj_ip,
-		NULL,
-	},
-};
-
-struct cmd_start_result {
-	cmdline_fixed_string_t start;
-};
-
-static void cmd_start_parsed(__rte_unused void *parsed_result,
-			       struct cmdline *cl,
-			       __rte_unused void *data)
+void
+cmd_start_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data)
 {
 	int worker_core_id = rte_lcore_id();
 
@@ -605,26 +571,8 @@ static void cmd_start_parsed(__rte_unused void *parsed_result,
 		);
 }
 
-cmdline_parse_token_string_t cmd_start_start =
-	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
-
-cmdline_parse_inst_t cmd_start = {
-	.f = cmd_start_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "starts listening if not started at startup",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_start_start,
-		NULL,
-	},
-};
-
-struct cmd_help_result {
-	cmdline_fixed_string_t help;
-};
-
-static void cmd_help_parsed(__rte_unused void *parsed_result,
-			    struct cmdline *cl,
-			    __rte_unused void *data)
+void
+cmd_help_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data)
 {
 	cmdline_printf(cl,
 			"ALB - link bonding mode 6 example\n"
@@ -637,26 +585,8 @@ static void cmd_help_parsed(__rte_unused void *parsed_result,
 		       );
 }
 
-cmdline_parse_token_string_t cmd_help_help =
-	TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
-
-cmdline_parse_inst_t cmd_help = {
-	.f = cmd_help_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "show help",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_help_help,
-		NULL,
-	},
-};
-
-struct cmd_stop_result {
-	cmdline_fixed_string_t stop;
-};
-
-static void cmd_stop_parsed(__rte_unused void *parsed_result,
-			    struct cmdline *cl,
-			    __rte_unused void *data)
+void
+cmd_stop_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data)
 {
 	rte_spinlock_lock(&global_flag_stru_p->lock);
 	if (global_flag_stru_p->LcoreMainIsRunning == 0)	{
@@ -678,26 +608,8 @@ static void cmd_stop_parsed(__rte_unused void *parsed_result,
 	rte_spinlock_unlock(&global_flag_stru_p->lock);
 }
 
-cmdline_parse_token_string_t cmd_stop_stop =
-	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
-
-cmdline_parse_inst_t cmd_stop = {
-	.f = cmd_stop_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "this command do not handle any arguments",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_stop_stop,
-		NULL,
-	},
-};
-
-struct cmd_quit_result {
-	cmdline_fixed_string_t quit;
-};
-
-static void cmd_quit_parsed(__rte_unused void *parsed_result,
-			    struct cmdline *cl,
-			    __rte_unused void *data)
+void
+cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data)
 {
 	rte_spinlock_lock(&global_flag_stru_p->lock);
 	if (global_flag_stru_p->LcoreMainIsRunning == 0)	{
@@ -721,26 +633,8 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,
 	cmdline_quit(cl);
 }
 
-cmdline_parse_token_string_t cmd_quit_quit =
-	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
-
-cmdline_parse_inst_t cmd_quit = {
-	.f = cmd_quit_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "this command do not handle any arguments",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_quit_quit,
-		NULL,
-	},
-};
-
-struct cmd_show_result {
-	cmdline_fixed_string_t show;
-};
-
-static void cmd_show_parsed(__rte_unused void *parsed_result,
-			    struct cmdline *cl,
-			    __rte_unused void *data)
+void
+cmd_show_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data)
 {
 	uint16_t slaves[16] = {0};
 	uint8_t len = 16;
@@ -772,31 +666,6 @@ static void cmd_show_parsed(__rte_unused void *parsed_result,
 	rte_spinlock_unlock(&global_flag_stru_p->lock);
 }
 
-cmdline_parse_token_string_t cmd_show_show =
-	TOKEN_STRING_INITIALIZER(struct cmd_show_result, show, "show");
-
-cmdline_parse_inst_t cmd_show = {
-	.f = cmd_show_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "this command do not handle any arguments",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_show_show,
-		NULL,
-	},
-};
-
-/****** CONTEXT (list of instruction) */
-
-cmdline_parse_ctx_t main_ctx[] = {
-	(cmdline_parse_inst_t *)&cmd_start,
-	(cmdline_parse_inst_t *)&cmd_obj_send,
-	(cmdline_parse_inst_t *)&cmd_stop,
-	(cmdline_parse_inst_t *)&cmd_show,
-	(cmdline_parse_inst_t *)&cmd_quit,
-	(cmdline_parse_inst_t *)&cmd_help,
-	NULL,
-};
-
 /* prompt function, called from main on MAIN lcore */
 static void prompt(__rte_unused void *arg1)
 {
diff --git a/examples/bond/main.h b/examples/bond/main.h
deleted file mode 100644
index f91ed9c885..0000000000
--- a/examples/bond/main.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2010-2015 Intel Corporation
- */
-
-#ifndef _MAIN_H_
-#define _MAIN_H_
-
-int main(int argc, char *argv[]);
-
-#endif /* ifndef _MAIN_H_ */
diff --git a/examples/bond/meson.build b/examples/bond/meson.build
index ed22b7887d..bfbec04ecd 100644
--- a/examples/bond/meson.build
+++ b/examples/bond/meson.build
@@ -11,3 +11,11 @@ allow_experimental_apis = true
 sources = files(
         'main.c',
 )
+
+cmd_h = custom_target('commands_hdr',
+	output: 'commands.h',
+	input: files('commands.list'),
+	capture: true,
+	command: [cmdline_gen_cmd, '--context-name=main_ctx', '@INPUT@']
+)
+sources += cmd_h
-- 
2.39.2


  parent reply	other threads:[~2023-09-18 13:04 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02 17:00 [RFC PATCH 0/1] make cmdline library easier to use Bruce Richardson
2023-08-02 17:00 ` [RFC PATCH 1/1] cmdline/dpdk-cmdline-gen: generate boilerplate for simple cmds Bruce Richardson
2023-08-02 18:05 ` [RFC PATCH 0/1] make cmdline library easier to use Stephen Hemminger
2023-08-03  8:11   ` Bruce Richardson
2023-09-18 13:03 ` [RFC PATCH v2 0/5] use script to simplify use of cmdline lib Bruce Richardson
2023-09-18 13:03   ` [RFC PATCH v2 1/5] buildtools/dpdk-cmdline-gen: generate boilerplate for simple cmds Bruce Richardson
2023-09-18 13:03   ` [RFC PATCH v2 2/5] examples/simple_mp: auto-generate cmdline boilerplate Bruce Richardson
2023-09-18 13:03   ` [RFC PATCH v2 3/5] examples/hotplug_mp: " Bruce Richardson
2023-09-18 13:03   ` [RFC PATCH v2 4/5] buildtools/dpdk-cmdline-gen: add IP address support Bruce Richardson
2023-09-18 13:03   ` Bruce Richardson [this message]
2023-10-11 13:33 ` [PATCH v3 0/5] document and simplify use of cmdline Bruce Richardson
2023-10-11 13:33   ` [PATCH v3 1/5] doc/prog_guide: new chapter on cmdline library Bruce Richardson
2023-10-11 13:33   ` [PATCH v3 2/5] buildtools: script to generate cmdline boilerplate Bruce Richardson
2023-10-13 12:23     ` Robin Jarry
2023-10-13 12:43       ` Bruce Richardson
2023-10-11 13:33   ` [PATCH v3 3/5] examples/simple_mp: auto-generate " Bruce Richardson
2023-10-11 13:33   ` [PATCH v3 4/5] examples/hotplug_mp: " Bruce Richardson
2023-10-11 13:33   ` [PATCH v3 5/5] examples/bond: " Bruce Richardson
2023-10-12 13:21   ` [PATCH v3 0/5] document and simplify use of cmdline David Marchand
2023-10-12 13:47     ` Bruce Richardson
2023-10-12 13:51     ` Bruce Richardson
2023-10-16 14:06 ` [PATCH v4 0/7] " Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 1/7] doc/prog_guide: new chapter on cmdline library Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 2/7] buildtools: script to generate cmdline boilerplate Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 3/7] ci: allow use of DPDK tools when building examples Bruce Richardson
2023-10-17 12:24     ` Aaron Conole
2023-10-17 12:28       ` Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 4/7] examples/simple_mp: auto-generate cmdline boilerplate Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 5/7] examples/hotplug_mp: " Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 6/7] examples/bond: " Bruce Richardson
2023-10-16 14:06   ` [PATCH v4 7/7] examples/vdpa: " Bruce Richardson
2023-10-17  7:10   ` [PATCH v4 0/7] document and simplify use of cmdline David Marchand
2023-10-17  8:29     ` Bruce Richardson
2023-10-17 12:16       ` Bruce Richardson
2023-10-17 16:23       ` David Marchand
2023-10-17 17:02         ` Bruce Richardson
2023-10-17 17:08         ` Bruce Richardson
2023-10-18 11:21           ` David Marchand
2023-10-18 11:37             ` Bruce Richardson
2023-10-17 12:13 ` [PATCH v5 0/9] " Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 1/9] doc/prog_guide: new chapter on cmdline library Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 2/9] buildtools: script to generate cmdline boilerplate Bruce Richardson
2023-10-25 13:04     ` Robin Jarry
2023-10-25 13:33       ` Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 3/9] ci: allow use of DPDK tools when building examples Bruce Richardson
2023-10-17 14:08     ` Aaron Conole
2023-10-17 12:13   ` [PATCH v5 4/9] examples/simple_mp: auto-generate cmdline boilerplate Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 5/9] examples/hotplug_mp: " Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 6/9] examples/bond: " Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 7/9] examples/vdpa: " Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 8/9] buildtools/dpdk-cmdline-gen: support option strings Bruce Richardson
2023-10-17 12:13   ` [PATCH v5 9/9] examples/ntb: auto-generate cmdline boilerplate Bruce Richardson
2023-10-23 13:15 ` [PATCH v6 0/9] document and simplify use of cmdline Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 1/9] doc/prog_guide: new chapter on cmdline library Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 2/9] buildtools: script to generate cmdline boilerplate Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 3/9] ci: allow use of DPDK tools when building examples Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 4/9] examples/simple_mp: auto-generate cmdline boilerplate Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 5/9] examples/hotplug_mp: " Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 6/9] examples/bond: " Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 7/9] examples/vdpa: " Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 8/9] buildtools/dpdk-cmdline-gen: support option strings Bruce Richardson
2023-10-23 13:15   ` [PATCH v6 9/9] examples/ntb: auto-generate cmdline boilerplate Bruce Richardson
2023-10-27 11:01 ` [PATCH v7 0/9] document and simplify use of cmdline Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 1/9] doc/prog_guide: new chapter on cmdline library Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 2/9] buildtools: script to generate cmdline boilerplate Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 3/9] ci: allow use of DPDK tools when building examples Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 4/9] examples/simple_mp: auto-generate cmdline boilerplate Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 5/9] examples/hotplug_mp: " Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 6/9] examples/bond: " Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 7/9] examples/vdpa: " Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 8/9] buildtools/dpdk-cmdline-gen: support option strings Bruce Richardson
2023-10-27 11:01   ` [PATCH v7 9/9] examples/ntb: auto-generate cmdline boilerplate Bruce Richardson
2023-11-10 14:16   ` [PATCH v7 0/9] document and simplify use of cmdline David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230918130352.379478-6-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).