From patchwork Tue Nov 15 20:53:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13044177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F858C4332F for ; Tue, 15 Nov 2022 20:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238559AbiKOUxi (ORCPT ); Tue, 15 Nov 2022 15:53:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238570AbiKOUxQ (ORCPT ); Tue, 15 Nov 2022 15:53:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 995FE2CE32 for ; Tue, 15 Nov 2022 12:53:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 44B32B81A1C for ; Tue, 15 Nov 2022 20:53:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00FE9C433D6; Tue, 15 Nov 2022 20:53:12 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1ov2wO-00ApFR-0I; Tue, 15 Nov 2022 15:53:56 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 1/4] trace-cmd: Make the unit test depend on the static library Date: Tue, 15 Nov 2022 15:53:52 -0500 Message-Id: <20221115205355.2580214-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221115205355.2580214-1-rostedt@goodmis.org> References: <20221115205355.2580214-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" Several times I've been confused that the unit test was not working after I had fixed some of the library code. The reason is that the unit test binary does not have a dependency on the static library. Even though the library is updated, the unit test will not reflect the changes because it was not rebuilt against the updated static library. Add a dependency to the static library to the unit test binary. Signed-off-by: Steven Rostedt (Google) --- utest/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utest/Makefile b/utest/Makefile index d475bad5a0f9..337db9bf24a1 100644 --- a/utest/Makefile +++ b/utest/Makefile @@ -23,7 +23,7 @@ $(bdir): $(OBJS): | $(bdir) $(DEPS): | $(bdir) -$(bdir)/trace-utest: $(OBJS) +$(bdir)/trace-utest: $(OBJS) $(LIBTRACECMD_STATIC) $(Q)$(do_app_build) $(bdir)/%.o: %.c From patchwork Tue Nov 15 20:53:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13044174 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A630C4332F for ; Tue, 15 Nov 2022 20:53:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238654AbiKOUxc (ORCPT ); Tue, 15 Nov 2022 15:53:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238597AbiKOUxO (ORCPT ); Tue, 15 Nov 2022 15:53:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120963135C for ; Tue, 15 Nov 2022 12:53:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 91CFE61A2A for ; Tue, 15 Nov 2022 20:53:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0914CC433D7; Tue, 15 Nov 2022 20:53:12 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1ov2wO-00ApFU-0L; Tue, 15 Nov 2022 15:53:56 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 2/4] trace-cmd: Only show unit test output when -v is supplied Date: Tue, 15 Nov 2022 15:53:53 -0500 Message-Id: <20221115205355.2580214-3-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221115205355.2580214-1-rostedt@goodmis.org> References: <20221115205355.2580214-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" The "Use libraries to read file" test shows the output of the reading of the trace.dat file. That should only happen if the '-v' option is supplied, otherwise, it should be muted. Signed-off-by: Steven Rostedt (Google) --- utest/tracecmd-utest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c index e45b3537365c..2ec3f7118690 100644 --- a/utest/tracecmd-utest.c +++ b/utest/tracecmd-utest.c @@ -264,7 +264,8 @@ static int read_events(struct tracecmd_input *handle, struct tep_record *record, tep_print_event(tep, seq, record, "%s-%d %s %s\n", TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_NAME, TEP_PRINT_INFO); - trace_seq_do_printf(seq); + if (show_output) + trace_seq_do_printf(seq); return 0; } From patchwork Tue Nov 15 20:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13044176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0010BC4332F for ; Tue, 15 Nov 2022 20:53:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbiKOUxf (ORCPT ); Tue, 15 Nov 2022 15:53:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238529AbiKOUxQ (ORCPT ); Tue, 15 Nov 2022 15:53:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997253136D for ; Tue, 15 Nov 2022 12:53:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5B781B81B62 for ; Tue, 15 Nov 2022 20:53:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E32EC433B5; Tue, 15 Nov 2022 20:53:12 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1ov2wO-00ApFX-0Q; Tue, 15 Nov 2022 15:53:56 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 3/4] trace-cmd utest: Separate out the grep and pipes Date: Tue, 15 Nov 2022 15:53:54 -0500 Message-Id: <20221115205355.2580214-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221115205355.2580214-1-rostedt@goodmis.org> References: <20221115205355.2580214-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" To make the grep and pipe functions in the unit test more flexible, separate them out and instead of passing in the arguments and using va_list directly, pass in a void pointer and use as structure to pass in the arguments. This will allow for extending the grep and pipe functions to use different type of arguments as well as functionality. Signed-off-by: Steven Rostedt (Google) --- utest/tracecmd-utest.c | 112 ++++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 17 deletions(-) diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c index 2ec3f7118690..88d7217762d2 100644 --- a/utest/tracecmd-utest.c +++ b/utest/tracecmd-utest.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -111,9 +112,9 @@ static int run_trace(const char *cmd, ...) return ret; } -static int pipe_it(int *ofd, int *efd, const char *cmd, va_list ap) +static int pipe_it(int *ofd, int *efd, int (*func)(void *), + void *data) { - char **argv; int obrass[2]; int ebrass[2]; pid_t pid; @@ -130,9 +131,6 @@ static int pipe_it(int *ofd, int *efd, const char *cmd, va_list ap) goto fail; if (!pid) { - argv = get_args(cmd, ap); - if (!argv) - exit(-1); close(obrass[0]); close(STDOUT_FILENO); @@ -144,7 +142,7 @@ static int pipe_it(int *ofd, int *efd, const char *cmd, va_list ap) if (dup2(obrass[1], STDERR_FILENO) < 0) exit(-1); - ret = execvp(tracecmd_exec, argv); + ret = func(data); exit(ret); } @@ -165,26 +163,52 @@ static int pipe_it(int *ofd, int *efd, const char *cmd, va_list ap) return -1; } -static int grep_it(const char *match, const char *cmd, ...) +struct do_grep { + const char *cmd; + va_list *ap; +}; + +static int do_grep(void *data) +{ + struct do_grep *gdata = data; + char **argv; + int ret; + + argv = get_args(gdata->cmd, *gdata->ap); + if (!argv) + exit(-1); + + ret = execvp(tracecmd_exec, argv); + tracefs_list_free(argv); + return ret; +} + +struct do_grep_it { + const char *match; + const char *cmd; + va_list *ap; +}; + +static int do_grep_it(void *data) { + struct do_grep_it *dgdata = data; + struct do_grep gdata; FILE *fp; regex_t reg; - va_list ap; char *buf = NULL; ssize_t n; size_t l = 0; - bool found = false; int ofd; int efd; int pid; int ret; - if (regcomp(®, match, REG_ICASE|REG_NOSUB)) + if (regcomp(®, dgdata->match, REG_ICASE|REG_NOSUB)) return -1; - va_start(ap, cmd); - pid = pipe_it(&ofd, &efd, cmd, ap); - va_end(ap); + gdata.cmd = dgdata->cmd; + gdata.ap = dgdata->ap; + pid = pipe_it(&ofd, &efd, do_grep, &gdata); if (pid < 0) { regfree(®); @@ -197,10 +221,65 @@ static int grep_it(const char *match, const char *cmd, ...) do { n = getline(&buf, &l, fp); - if (show_output && n > 0) - printf("%s", buf); if (n > 0 && regexec(®, buf, 0, NULL, 0) == 0) + printf("%s", buf); + } while (n >= 0); + + free(buf); + out: + ret = wait_for_exec(pid); + if (fp) + fclose(fp); + else + perror("fp"); + close(ofd); + close(efd); + regfree(®); + + return ret > 0 ? 0 : ret; +} + +struct do_grep_match { + const char *match; + const char *cmd; + va_list *ap; +}; + +static int grep_match(const char *match, const char *cmd, ...) +{ + struct do_grep_it gdata; + FILE *fp; + va_list ap; + char *buf = NULL; + ssize_t n; + size_t l = 0; + bool found = false; + int ofd; + int efd; + int pid; + int ret; + + va_start(ap, cmd); + gdata.match = match; + gdata.cmd = cmd; + gdata.ap = ≈ + pid = pipe_it(&ofd, &efd, do_grep_it, &gdata); + va_end(ap); + + if (pid < 0) + return -1; + + fp = fdopen(ofd, "r"); + if (!fp) + goto out; + + do { + n = getline(&buf, &l, fp); + if (n > 0) { + if (show_output) + printf("%s", buf); found = true; + } } while (n >= 0); free(buf); @@ -215,7 +294,6 @@ static int grep_it(const char *match, const char *cmd, ...) close(ofd); } close(efd); - regfree(®); return found ? 0 : 1; } @@ -240,7 +318,7 @@ static void test_trace_convert6(void) ret = run_trace("record", TRACECMD_OUT, "-e", "sched", "sleep", "1", NULL); CU_TEST(ret == 0); } - ret = grep_it("[ \t]6[ \t]*\\[Version\\]", "dump", TRACECMD_IN2, NULL); + ret = grep_match("[ \t]6[ \t]*\\[Version\\]", "dump", TRACECMD_IN2, NULL); CU_TEST(ret == 0); } From patchwork Tue Nov 15 20:53:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13044175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDEEBC43217 for ; Tue, 15 Nov 2022 20:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238597AbiKOUxd (ORCPT ); Tue, 15 Nov 2022 15:53:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238600AbiKOUxP (ORCPT ); Tue, 15 Nov 2022 15:53:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F4831362 for ; Tue, 15 Nov 2022 12:53:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A25EF61987 for ; Tue, 15 Nov 2022 20:53:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 140A2C43470; Tue, 15 Nov 2022 20:53:12 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1ov2wO-00ApFd-0U; Tue, 15 Nov 2022 15:53:56 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 4/4] trace-cmd: Add test for max size option of record Date: Tue, 15 Nov 2022 15:53:55 -0500 Message-Id: <20221115205355.2580214-5-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221115205355.2580214-1-rostedt@goodmis.org> References: <20221115205355.2580214-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" Add a unit test to test the trace-cmd record -m X option. Signed-off-by: Steven Rostedt (Google) --- utest/tracecmd-utest.c | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c index 88d7217762d2..c72684ad53fc 100644 --- a/utest/tracecmd-utest.c +++ b/utest/tracecmd-utest.c @@ -308,6 +308,76 @@ static void test_trace_record_report(void) CU_TEST(ret == 0); } +static int read_stats(const char *out, const char *match, const char *cmd, ...) +{ + struct do_grep_it gdata; + FILE *fp; + va_list ap; + bool found = false; + char *buf = NULL; + char *p; + ssize_t n; + size_t l = 0; + int ofd; + int efd; + int pid; + int ret; + int val; + + va_start(ap, cmd); + gdata.match = match; + gdata.cmd = cmd; + gdata.ap = ≈ + pid = pipe_it(&ofd, &efd, do_grep_it, &gdata); + va_end(ap); + + if (pid < 0) + return -1; + + fp = fdopen(ofd, "r"); + if (!fp) + goto out; + + do { + n = getline(&buf, &l, fp); + if (n > 0) { + for (p = buf; isspace(*p); p++) + ; + val = atoi(p); + found = true; + if (show_output) + printf("%s", buf); + CU_TEST(val < 10000000); + } + } while (n >= 0); + + free(buf); + out: + ret = wait_for_exec(pid); + if (fp) + fclose(fp); + else { + perror("fp"); + } + if (!found) + ret = -1; + close(ofd); + close(efd); + return ret > 0 ? 0 : ret; +} + +static void test_trace_record_max(void) +{ + int ret; + + ret = run_trace("record", TRACECMD_OUT, "-p", "function", "-m", "5000", + "sleep", "10", NULL); + CU_TEST(ret == 0); + + ret = read_stats(TRACECMD_FILE, ".*bytes in size.*", "report", "--stat", NULL); + CU_TEST(ret == 0); +} + static void test_trace_convert6(void) { struct stat st; @@ -422,4 +492,6 @@ void test_tracecmd_lib(void) test_trace_convert6); CU_add_test(suite, "Use libraries to read file", test_trace_library_read); + CU_add_test(suite, "Test max length", + test_trace_record_max); }