linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] libtracefs: Fix tracefs_tracing_dir() mount test
Date: Sat, 10 Dec 2022 19:10:34 -0500	[thread overview]
Message-ID: <20221210191034.26a1b156@gandalf.local.home> (raw)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The tracefs_tracing_dir() test was broken. The pre-test setup already
called tracing_tracing_dir() and cached the value. When the mounting test
ran, it unmounted the tracefs directory, and then called the
tracefs_tracing_dir() again, which just returned the cached value, leaving
the tracefs file system unmounted. This had the test incorrectly pass, but
then broke the tests after that.

Add a check to make sure that the content in both the mounted tracefs
directory and the debugfs directory exists.

Fixes: e6daa60cca ("libtracefs: Add unit test to test mounting of tracefs_{tracing,debug}_dir()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 utest/tracefs-utest.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index d1789a3d87f9..a5666e40cac4 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -751,8 +751,10 @@ static void test_mounting(void)
 {
 	const char *tracing_dir;
 	const char *debug_dir;
+	struct stat st;
 	char *save_tracing = NULL;
 	char *save_debug = NULL;
+	char *path;
 	char *dir;
 	int ret;
 
@@ -797,6 +799,11 @@ static void test_mounting(void)
 		if (strncmp(tracing_dir, "/sys/kernel/", 12) != 0)
 			printf("Tracing directory mounted at '%s'\n",
 			       tracing_dir);
+
+		/* Make sure the directory has content.*/
+		asprintf(&path, "%s/trace", tracing_dir);
+		CU_TEST(stat(path, &st) == 0);
+		free(path);
 	}
 
 	/* Now mount debugfs dir, which should mount at /sys/kernel/debug */
@@ -807,6 +814,11 @@ static void test_mounting(void)
 		if (strcmp(debug_dir, DEBUGFS_DEFAULT_PATH) != 0)
 			printf("debug directory mounted at '%s'\n",
 			       debug_dir);
+
+		/* Make sure the directory has content.*/
+		asprintf(&path, "%s/tracing", debug_dir);
+		CU_TEST(stat(path, &st) == 0);
+		free(path);
 	}
 
 	if (save_debug)
@@ -2329,9 +2341,7 @@ void test_tracefs_lib(void)
 		return;
 	}
 
-	/* Must be first test */
 	CU_add_test(suite, "Test tracefs/debugfs mounting", test_mounting);
-
 	CU_add_test(suite, "Follow events", test_follow_events);
 	CU_add_test(suite, "trace cpu read",
 		    test_trace_cpu_read);
-- 
2.35.1


                 reply	other threads:[~2022-12-11  0:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221210191034.26a1b156@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /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).