aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-11-15 15:53:55 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-11-15 16:05:45 -0500
commit1f75010a25939c0c4e1d99df7c40e364e4206e9b (patch)
tree54408acd334a10726a9320aed2ef362a97499245
parent1b0c600e2bd8152c703a0c3262050e51be520ad2 (diff)
downloadtrace-cmd-1f75010a25939c0c4e1d99df7c40e364e4206e9b.tar.gz
trace-cmd: Add test for max size option of record
Add a unit test to test the trace-cmd record -m X option. Link: https://lore.kernel.org/linux-trace-devel/20221115205355.2580214-5-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--utest/tracecmd-utest.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c
index 88d72177..c72684ad 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 = &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);
}