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 340F3A052B; Thu, 30 Jul 2020 23:07:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 232041BFFA; Thu, 30 Jul 2020 23:07:27 +0200 (CEST) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by dpdk.org (Postfix) with ESMTP id E4E3B37B7 for ; Thu, 30 Jul 2020 23:07:23 +0200 (CEST) Received: by mail-lf1-f68.google.com with SMTP id m15so15053150lfp.7 for ; Thu, 30 Jul 2020 14:07:23 -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=ENUhdIfK4CmepfQyGTyZI9cxe4Jmh3NvhWeWsAAo2iA=; b=kbx25d5EpO/l5Pf7nfZhBzfSqsnlqTHuiKgnbolzB6TQXNhTFAd6RaAxqSiVG/ncie 8TrMHQOeSvEo3xz+qa4ilxb5hvKR3W40SWDWeTJ01o4XU+MrWO23h5MoVG0RJU0cGRHr 4aF02j3qA2I7AykRGHdlvO6TIO2jnrTNDgFC5cTU+5zKfp1GeoaexsM8xVHQFcV5RU5v Vr1DAnFKxFBObiok22vc3cDxDJ0zpJHsIpaNNhT3QxB3/mME3biz8qWmiRGJ8ttmBJG+ EFQUPETOFdXcblsNtef7slSCOPIP9v++ox7i9Q6Y/9CNenQumPBA3INxdyADfOBiJ2UZ NNVQ== 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=ENUhdIfK4CmepfQyGTyZI9cxe4Jmh3NvhWeWsAAo2iA=; b=Sz4skIZNb87HqQFaIiF5Sqe19WNUnzARfOjX9b6OFTE8fXdbfT60zPyw7/vPS1Xfvl YJJzvEipPR86LpKkGxZbqy9ZZ2f+mBoMvxrdtQ1SHZTuIJR7+fJ1Gx4f+NZ7TLFlnDd7 GGru8lPosy/LLrvNAuQl8PsPuOmxgCxGiDrbjlF0lREZ/6lf9IEkUB4UsEDeTaCdFXtK 5Gf9NEmbISU05oA7KdNcflnMZUSK8nvfI4Gt3wVI3DMxEeAe063aonGh7Ct7h4XUw843 IRhyJOw0MQ39fIiYdwz2s7tzTADb89RJylysWZyM/4TJrdChe1LehskIukq+N59xGiau 53Gw== X-Gm-Message-State: AOAM530YeZF+/fipY91KWVo79Y+9iq6RFlpB8qYOoqhLvpCWXA2+heew ZB2OOy1lQjkpaTS0LvelJ4b6O0qwGUQjSw== X-Google-Smtp-Source: ABdhPJz/DZGTv7JE2ko59CEx7O2yvLNsbqc2qfKk7vdswYyKQZECr9+lnvc7kUSe4F5XfjoT0wmVjw== X-Received: by 2002:ac2:5335:: with SMTP id f21mr256839lfh.114.1596143242973; Thu, 30 Jul 2020 14:07:22 -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 y9sm1257763lji.49.2020.07.30.14.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 14:07:22 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Malloy , Narcisa Ana Maria Vasile , Fady Bader , Tal Shnaiderman , "Kadam, Pallavi" , Dmitry Kozlyuk , Olivier Matz , Ray Kinsella , Neil Horman Date: Fri, 31 Jul 2020 00:06:45 +0300 Message-Id: <20200730210652.14568-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200730210652.14568-1-dmitry.kozliuk@gmail.com> References: <20200620210511.13134-1-dmitry.kozliuk@gmail.com> <20200730210652.14568-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/7] cmdline: make implementation 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. Make the structure opaque. Remove tests checking struct cmdline content as meaningless. Add cmdline_get_rdline() to access history buffer. The new function is currently used only in tests. Signed-off-by: Dmitry Kozlyuk --- app/test-cmdline/commands.c | 8 +++-- app/test/test_cmdline_lib.c | 42 +++++++++------------- lib/librte_cmdline/cmdline.c | 10 ++++-- lib/librte_cmdline/cmdline.h | 15 ++++---- lib/librte_cmdline/cmdline_parse.c | 4 +-- lib/librte_cmdline/cmdline_private.h | 22 ++++++++++++ lib/librte_cmdline/cmdline_socket.c | 6 ++-- lib/librte_cmdline/rte_cmdline_version.map | 8 +++++ 8 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 lib/librte_cmdline/cmdline_private.h 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..a7f5a7f7f 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,31 +195,14 @@ 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"); - return -1; } /* test library functions. the point of these tests is not so much to test diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index cfd703e5b..6f3fdd598 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -13,14 +13,12 @@ #include #include #include -#include #include #include -#include "cmdline_parse.h" -#include "cmdline_rdline.h" #include "cmdline.h" +#include "cmdline_private.h" static void cmdline_valid_buffer(struct rdline *rdl, const char *buf, @@ -103,6 +101,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..96674dfda 100644 --- a/lib/librte_cmdline/cmdline.h +++ b/lib/librte_cmdline/cmdline.h @@ -8,8 +8,8 @@ #define _CMDLINE_H_ #include +#include -#include #include #include @@ -23,14 +23,7 @@ extern "C" { #endif -struct cmdline { - int s_in; - int s_out; - cmdline_parse_ctx_t *ctx; - struct rdline rdl; - char prompt[RDLINE_PROMPT_SIZE]; - struct termios oldterm; -}; +struct cmdline; 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); @@ -40,6 +33,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..ea0979158 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -10,15 +10,13 @@ #include #include #include -#include #include #include -#include "cmdline_rdline.h" -#include "cmdline_parse.h" #include "cmdline.h" +#include "cmdline_private.h" #ifdef RTE_LIBRTE_CMDLINE_DEBUG #define debug_printf printf diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h new file mode 100644 index 000000000..3b1c70e9f --- /dev/null +++ b/lib/librte_cmdline/cmdline_private.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2020 Dmitry Kozlyuk + */ + +#ifndef _CMDLINE_PRIVATE_H_ +#define _CMDLINE_PRIVATE_H_ + +#include + +#include +#include + +struct cmdline { + int s_in; + int s_out; + cmdline_parse_ctx_t *ctx; + struct rdline rdl; + char prompt[RDLINE_PROMPT_SIZE]; + struct termios oldterm; +}; + +#endif diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c index ecb3d82b6..5e4b734d6 100644 --- a/lib/librte_cmdline/cmdline_socket.c +++ b/lib/librte_cmdline/cmdline_socket.c @@ -11,12 +11,10 @@ #include #include #include -#include -#include "cmdline_parse.h" -#include "cmdline_rdline.h" -#include "cmdline_socket.h" #include "cmdline.h" +#include "cmdline_private.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 95fce812f..135ecc71f 100644 --- a/lib/librte_cmdline/rte_cmdline_version.map +++ b/lib/librte_cmdline/rte_cmdline_version.map @@ -69,3 +69,11 @@ DPDK_20.0 { local: *; }; + +EXPERIMENTAL { + global: + + cmdline_get_rdline; + + local: *; +}; -- 2.25.4