linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Jia He <justin.he@arm.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Jonathan Corbet <corbet@lwn.net>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Eric Biggers <ebiggers@google.com>,
	"Ahmed S. Darwish" <a.darwish@linutronix.de>,
	Linux Documentation List <linux-doc@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux FS Devel <linux-fsdevel@vger.kernel.org>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH RFCv4 4/4] lib/test_printf.c: add test cases for '%pD'
Date: Tue, 15 Jun 2021 23:47:29 +0300	[thread overview]
Message-ID: <CAHp75VeB68UUfz=6dO31zf59p6_5wGBX7etWJEV_xtLYsy=hBQ@mail.gmail.com> (raw)
In-Reply-To: <20210615154952.2744-5-justin.he@arm.com>

On Tue, Jun 15, 2021 at 6:55 PM Jia He <justin.he@arm.com> wrote:
>
> 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 of '%pD' is prepended from the end of the buffer, the
> check of "wrote beyond the nul-terminator" should be skipped.
>
> Signed-off-by: Jia He <justin.he@arm.com>
> ---
>  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 d1d2f898ebae..9f851a82b3af 100644
> --- a/lib/test_printf.c
> +++ b/lib/test_printf.c
> @@ -16,6 +16,7 @@
>
>  #include <linux/bitmap.h>
>  #include <linux/dcache.h>
> +#include <linux/fs.h>
>  #include <linux/socket.h>
>  #include <linux/in.h>
>
> @@ -34,6 +35,7 @@ KSTM_MODULE_GLOBALS();
>
>  static char *test_buffer __initdata;
>  static char *alloced_buffer __initdata;
> +static bool is_prepended_buf __initdata;
>
>  extern bool no_hash_pointers;
>
> @@ -78,7 +80,7 @@ do_test(int bufsize, const char *expect, int elen,
>                 return 1;
>         }
>
> -       if (memchr_inv(test_buffer + written + 1, FILL_CHAR, bufsize - (written + 1))) {

> +       if (!is_prepended_buf && memchr_inv(test_buffer + written + 1, FILL_CHAR, bufsize - (written + 1))) {

Can it be parametrized? I don't like the custom test case being
involved here like this.

>                 pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n",
>                         bufsize, fmt);
>                 return 1;
> @@ -501,6 +503,27 @@ dentry(void)
>         test("  bravo/alfa|  bravo/alfa", "%12pd2|%*pd2", &test_dentry[2], 12, &test_dentry[2]);
>  }
>
> +static struct vfsmount test_vfsmnt __initdata = {};
> +
> +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_prepended_buf = true;
> +       test("/bravo/alfa   |/bravo/alfa   ", "%-14pD|%*pD", &test_file, -14, &test_file);
> +       test("   /bravo/alfa|   /bravo/alfa", "%14pD|%*pD", &test_file, 14, &test_file);
> +       test("   /bravo/alfa|/bravo/alfa   ", "%14pD|%-14pD", &test_file, &test_file);
> +       is_prepended_buf = false;
> +}
> +
>  static void __init
>  struct_va_format(void)
>  {
> @@ -784,6 +807,7 @@ test_pointer(void)
>         ip();
>         uuid();
>         dentry();
> +       f_d_path();
>         struct_va_format();
>         time_and_date();
>         struct_clk();
> --
> 2.17.1
>


-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2021-06-15 20:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15 15:49 [PATCH RFCv4 0/4] make '%pD' print full path for file Jia He
2021-06-15 15:49 ` [PATCH RFCv4 1/4] fs: introduce helper d_path_unsafe() Jia He
2021-06-15 20:40   ` Andy Shevchenko
2021-06-16  0:54     ` Justin He
2021-06-15 15:49 ` [PATCH RFCv4 2/4] lib/vsprintf.c: make '%pD' print full path for file Jia He
2021-06-15 20:44   ` Andy Shevchenko
2021-06-17 14:09   ` Petr Mladek
2021-06-22  2:20     ` Justin He
2021-06-15 15:49 ` [PATCH RFCv4 3/4] lib/test_printf.c: split write-beyond-buffer check in two Jia He
2021-06-17 14:17   ` Petr Mladek
2021-06-15 15:49 ` [PATCH RFCv4 4/4] lib/test_printf.c: add test cases for '%pD' Jia He
2021-06-15 20:47   ` Andy Shevchenko [this message]
2021-06-17 14:52     ` Petr Mladek
2021-06-22  2:21       ` Justin He
2021-06-15 20:42 ` [PATCH RFCv4 0/4] make '%pD' print full path for file Andy Shevchenko
2021-06-16  5:09 ` Christoph Hellwig
2021-06-16  5:16   ` Justin He

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='CAHp75VeB68UUfz=6dO31zf59p6_5wGBX7etWJEV_xtLYsy=hBQ@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=a.darwish@linutronix.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=ebiggers@google.com \
    --cc=justin.he@arm.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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).