From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C996BA04C0; Mon, 28 Sep 2020 23:51:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 96D4A1D6C6; Mon, 28 Sep 2020 23:51:37 +0200 (CEST) Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by dpdk.org (Postfix) with ESMTP id 419E71BDDF for ; Mon, 28 Sep 2020 23:51:34 +0200 (CEST) Received: by mail-lf1-f67.google.com with SMTP id u8so3111550lff.1 for ; Mon, 28 Sep 2020 14:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=izn5ojfvd3xrmNkBs/FoETtcPitzg7i9lCk0A4ZR9vI=; b=N8bvDdFqd/YKoyIOsI6oBuDhvrVXqYPAvcZt0UA/hHrxlWDx+4uZhaJHRDBRZ2TiVe SLpZ+0Wltjjsvu8TGVvIZrSs1InvUfitgx3875dvMOvvhqcfnOrBjbs1IUi6A4pTuahU nWZDJlCJSaVddVwK/sfgUFBcAOgWAsnCF5bY2ub2zx/e7buYWnknXkf89Hk6XDX9xzr1 nbz5f4Cl2Tdw3mAWDDoROWtP+JD8xLQkXDZ3V0arZ9u/hgC2ppqmMtHuw4HRLmEp5spR XL2bT9PQfdtRvQxIfkZuE1JybZ7Kc/1kShLxBuE0idxy1ozR+d3UHjS5NhI7YO2PMyex G7Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=izn5ojfvd3xrmNkBs/FoETtcPitzg7i9lCk0A4ZR9vI=; b=B6ETTz/L42fkclchOHzbHBN6/IG/MYn/DBegU3wKu6XKU7Ub9MWK5R5+CxW7g3Kz9d r0+pJ+pR4B6+a6Zj9w8o9Y6i9B2SDpytn3PzKYi+ZSgfLfic3UsOAG/ghDaxCZSigl2M Xa2+czJoV6frqDdqH3ytqoYMUuDfdsPIMbsNuLNNUqt3kB0O9EZcHAOPUUpYdmvGXjSp mLBbje4JCiKXcBJB6y4crWkwx37kGCrHSKa/yQRDsNE3SmTyC3tdH3sguSNpfpCWqAjl /We/6fU7N6cRjD0oD2C9c794HMpYO29PTgIsFXgMIA2Xu0apzWx0O482TbRupgbUoXx5 QWQg== X-Gm-Message-State: AOAM533EsFxG9yzrEskrKto39X0wW0Bx4nAlSXCtWoQejDt8LjPS9P2Y C9zLnLR2YpyznPDWrNQP2qGBKnTWHtocE880 X-Google-Smtp-Source: ABdhPJyHS5s2PQrhoLy/pye0kiNi4zdSJLq78Rboj9SVBpqMbZyxwe+tXYru6DmzoBs+or+vjNZLZQ== X-Received: by 2002:ac2:5627:: with SMTP id b7mr90783lff.27.1601329892491; Mon, 28 Sep 2020 14:51:32 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id l11sm2954893lfk.113.2020.09.28.14.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 14:51:31 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: "Kinsella, Ray" , Khoa To , Stephen Hemminger , Ferruh Yigit , Dmitry Kozlyuk , Olivier Matz , Neil Horman Date: Tue, 29 Sep 2020 00:50:46 +0300 Message-Id: <20200928215052.23627-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928215052.23627-1-dmitry.kozliuk@gmail.com> References: <20200730210652.14568-1-dmitry.kozliuk@gmail.com> <20200928215052.23627-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 1/7] cmdline: make implementation logically opaque 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" struct cmdline exposes platform-specific members it contains, most notably struct termios that is only available on Unix. While ABI considerations prevent from hinding the definition on already supported platforms, struct cmdline is considered logically opaque from now on. Add a deprecation notice targeted at 20.11. * Remove tests checking struct cmdline content as meaningless. * Fix missing cmdline_free() in unit test. * Add cmdline_get_rdline() to access history buffer indirectly. The new function is currently used only in tests. Signed-off-by: Dmitry Kozlyuk Suggested-by: Olivier Matz --- app/test-cmdline/commands.c | 8 +++- app/test/test_cmdline_lib.c | 44 +++++++++------------- doc/guides/rel_notes/deprecation.rst | 4 ++ lib/librte_cmdline/cmdline.c | 9 +++-- lib/librte_cmdline/cmdline.h | 18 ++++++++- lib/librte_cmdline/cmdline_parse.c | 3 -- lib/librte_cmdline/cmdline_socket.c | 5 +-- lib/librte_cmdline/rte_cmdline_version.map | 8 ++++ 8 files changed, 60 insertions(+), 39 deletions(-) diff --git a/app/test-cmdline/commands.c b/app/test-cmdline/commands.c index d67c0ca6a..ff7ac973e 100644 --- a/app/test-cmdline/commands.c +++ b/app/test-cmdline/commands.c @@ -294,8 +294,10 @@ cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { + struct rdline *rdl = cmdline_get_rdline(cl); + cmdline_printf(cl, "History buffer size: %zu\n", - sizeof(cl->rdl.history_buf)); + sizeof(rdl->history_buf)); } cmdline_parse_token_string_t cmd_get_history_bufsize_tok = @@ -326,7 +328,9 @@ cmd_clear_history_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { - rdline_clear_history(&cl->rdl); + struct rdline *rdl = cmdline_get_rdline(cl); + + rdline_clear_history(rdl); } cmdline_parse_token_string_t cmd_clear_history_tok = diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c index dec465da5..bd72df0da 100644 --- a/app/test/test_cmdline_lib.c +++ b/app/test/test_cmdline_lib.c @@ -46,22 +46,29 @@ complete_buffer(__rte_unused struct rdline *rdl, static int test_cmdline_parse_fns(void) { - struct cmdline cl; + struct cmdline *cl; + cmdline_parse_ctx_t ctx; int i = 0; char dst[CMDLINE_TEST_BUFSIZE]; + cl = cmdline_new(&ctx, "prompt", -1, -1); + if (cl == NULL) { + printf("Error: cannot create cmdline to test parse fns!\n"); + return -1; + } + if (cmdline_parse(NULL, "buffer") >= 0) goto error; - if (cmdline_parse(&cl, NULL) >= 0) + if (cmdline_parse(cl, NULL) >= 0) goto error; if (cmdline_complete(NULL, "buffer", &i, dst, sizeof(dst)) >= 0) goto error; - if (cmdline_complete(&cl, NULL, &i, dst, sizeof(dst)) >= 0) + if (cmdline_complete(cl, NULL, &i, dst, sizeof(dst)) >= 0) goto error; - if (cmdline_complete(&cl, "buffer", NULL, dst, sizeof(dst)) >= 0) + if (cmdline_complete(cl, "buffer", NULL, dst, sizeof(dst)) >= 0) goto error; - if (cmdline_complete(&cl, "buffer", &i, NULL, sizeof(dst)) >= 0) + if (cmdline_complete(cl, "buffer", &i, NULL, sizeof(dst)) >= 0) goto error; return 0; @@ -166,11 +173,11 @@ static int test_cmdline_fns(void) { cmdline_parse_ctx_t ctx; - struct cmdline cl, *tmp; + struct cmdline *cl; memset(&ctx, 0, sizeof(ctx)); - tmp = cmdline_new(&ctx, "test", -1, -1); - if (tmp == NULL) + cl = cmdline_new(&ctx, "test", -1, -1); + if (cl == NULL) goto error; if (cmdline_new(NULL, "prompt", 0, 0) != NULL) @@ -179,7 +186,7 @@ test_cmdline_fns(void) goto error; if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >= 0) goto error; - if (cmdline_in(&cl, NULL, CMDLINE_TEST_BUFSIZE) >= 0) + if (cmdline_in(cl, NULL, CMDLINE_TEST_BUFSIZE) >= 0) goto error; if (cmdline_write_char(NULL, 0) >= 0) goto error; @@ -188,30 +195,15 @@ test_cmdline_fns(void) cmdline_set_prompt(NULL, "prompt"); cmdline_free(NULL); cmdline_printf(NULL, "format"); - /* this should fail as stream handles are invalid */ - cmdline_printf(tmp, "format"); cmdline_interact(NULL); cmdline_quit(NULL); - /* check if void calls change anything when they should fail */ - cl = *tmp; - - cmdline_printf(&cl, NULL); - if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; - cmdline_set_prompt(&cl, NULL); - if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; - cmdline_in(&cl, NULL, CMDLINE_TEST_BUFSIZE); - if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; - - cmdline_free(tmp); - return 0; error: printf("Error: function accepted null parameter!\n"); - return -1; -mismatch: - printf("Error: data changed!\n"); + if (cl != NULL) + cmdline_free(cl); return -1; } diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 9691f2c57..7ae013c27 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -255,3 +255,7 @@ Deprecation Notices ``make``. Given environments are too much variables for such a simple script, it will be removed in DPDK 20.11. Some useful parts may be converted into specific scripts. + +* cmdline: ``cmdline`` structure will be made opaque to hide platform-specific + content. On Linux and FreeBSD, supported prior to DPDK 20.11, + original structure will be kept until DPDK 21.11. \ No newline at end of file diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index cfd703e5b..41f50cc56 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -13,13 +13,10 @@ #include #include #include -#include #include #include -#include "cmdline_parse.h" -#include "cmdline_rdline.h" #include "cmdline.h" static void @@ -103,6 +100,12 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) return cl; } +struct rdline* +cmdline_get_rdline(struct cmdline *cl) +{ + return &cl->rdl; +} + void cmdline_free(struct cmdline *cl) { diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h index 243f99d20..c29762dda 100644 --- a/lib/librte_cmdline/cmdline.h +++ b/lib/librte_cmdline/cmdline.h @@ -7,9 +7,13 @@ #ifndef _CMDLINE_H_ #define _CMDLINE_H_ +#ifndef RTE_EXEC_ENV_WINDOWS +#include +#endif + #include +#include -#include #include #include @@ -23,6 +27,8 @@ extern "C" { #endif +#ifndef RTE_EXEC_ENV_WINDOWS + struct cmdline { int s_in; int s_out; @@ -32,6 +38,12 @@ struct cmdline { struct termios oldterm; }; +#else + +struct cmdline; + +#endif /* RTE_EXEC_ENV_WINDOWS */ + struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out); void cmdline_set_prompt(struct cmdline *cl, const char *prompt); void cmdline_free(struct cmdline *cl); @@ -40,6 +52,10 @@ void cmdline_printf(const struct cmdline *cl, const char *fmt, ...) int cmdline_in(struct cmdline *cl, const char *buf, int size); int cmdline_write_char(struct rdline *rdl, char c); +__rte_experimental +struct rdline * +cmdline_get_rdline(struct cmdline *cl); + /** * This function is nonblocking equivalent of ``cmdline_interact()``. It polls * *cl* for one character and interpret it. If return value is *RDLINE_EXITED* diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c index b57b30e8f..f120f19dd 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -10,14 +10,11 @@ #include #include #include -#include #include #include -#include "cmdline_rdline.h" -#include "cmdline_parse.h" #include "cmdline.h" #ifdef RTE_LIBRTE_CMDLINE_DEBUG diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c index ecb3d82b6..6c89d2171 100644 --- a/lib/librte_cmdline/cmdline_socket.c +++ b/lib/librte_cmdline/cmdline_socket.c @@ -11,12 +11,9 @@ #include #include #include -#include -#include "cmdline_parse.h" -#include "cmdline_rdline.h" -#include "cmdline_socket.h" #include "cmdline.h" +#include "cmdline_socket.h" struct cmdline * cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path) diff --git a/lib/librte_cmdline/rte_cmdline_version.map b/lib/librte_cmdline/rte_cmdline_version.map index a99104457..9df027215 100644 --- a/lib/librte_cmdline/rte_cmdline_version.map +++ b/lib/librte_cmdline/rte_cmdline_version.map @@ -69,3 +69,11 @@ DPDK_21 { local: *; }; + +EXPERIMENTAL { + global: + + cmdline_get_rdline; + + local: *; +}; -- 2.28.0