Thread (22 messages) 22 messages, 4 authors, 2021-06-15

RE: [PATCH RFCv3 3/3] lib/test_printf: add test cases for '%pD'

From: Justin He <hidden>
Date: 2021-06-15 07:07:27
Also in: linux-fsdevel, lkml

Hi Petr
-----Original Message-----
From: Petr Mladek <pmladek@suse.com>
Sent: Monday, June 14, 2021 11:44 PM
To: Justin He <redacted>
Cc: Steven Rostedt <rostedt@goodmis.org>; Sergey Senozhatsky
[off-list ref]; Andy Shevchenko
[off-list ref]; Rasmus Villemoes
[off-list ref]; Jonathan Corbet [off-list ref]; Alexander
Viro [off-list ref]; Linus Torvalds <torvalds@linux-
foundation.org>; Peter Zijlstra (Intel) [off-list ref]; Eric
Biggers [off-list ref]; Ahmed S. Darwish [off-list ref];
linux-doc@vger.kernel.org; linux-kernel@vger.kernel.org; linux-
fsdevel@vger.kernel.org
Subject: Re: [PATCH RFCv3 3/3] lib/test_printf: add test cases for '%pD'

On Fri 2021-06-11 23:59:53, Jia He wrote:
quoted
After the behaviour of specifier '%pD' is changed to print full path
of struct file, the related test cases are also updated.

Given the string is prepended from the end of the buffer, the check
of "wrote beyond the nul-terminator" should be skipped.

Signed-off-by: Jia He <redacted>
---
 lib/test_printf.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/lib/test_printf.c b/lib/test_printf.c
index ec0d5976bb69..3632bd6cf906 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -78,7 +80,7 @@ do_test(int bufsize, const char *expect, int elen,
            return 1;
    }

-   if (memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE +
PAD_SIZE - (written + 1))) {
quoted
+   if (!is_prepend_buf && memchr_inv(test_buffer + written + 1,
FILL_CHAR, BUF_SIZE + PAD_SIZE - (written + 1))) {
quoted
            pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-
terminator\n",
quoted
                    bufsize, fmt);
            return 1;
@@ -496,6 +498,27 @@ dentry(void)
    test("  bravo/alfa|  bravo/alfa", "%12pd2|%*pd2", &test_dentry[2],
12, &test_dentry[2]);
quoted
 }

+static struct vfsmount test_vfsmnt = {};
+
+static struct file test_file __initdata = {
+   .f_path = { .dentry = &test_dentry[2],
+               .mnt = &test_vfsmnt,
+   },
+};
+
+static void __init
+f_d_path(void)
+{
+   test("(null)", "%pD", NULL);
+   test("(efault)", "%pD", PTR_INVALID);
+
+   is_prepend_buf = true;
+   test("/bravo/alfa   |/bravo/alfa   ", "%-14pD|%*pD", &test_file, -14,
&test_file);
quoted
+   test("   /bravo/alfa|   /bravo/alfa", "%14pD|%*pD", &test_file, 14,
&test_file);
quoted
+   test("   /bravo/alfa|/bravo/alfa   ", "%14pD|%-14pD", &test_file,
&test_file);

Please, add more test for scenarios when the path does not fit into
the buffer or when there are no limitations, ...
Indeed, thanks


--
Cheers,
Justin (Jia He)



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help