linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brendan Higgins <brendanhiggins@google.com>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: shuah@kernel.org, pmladek@suse.com, sergey.senozhatsky@gmail.com,
	rostedt@goodmis.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	frowand.list@gmail.com, sboyd@kernel.org,
	Randy Dunlap <rdunlap@infradead.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>
Subject: Re: [PATCH v1] printk: add dummy vprintk_emit for when CONFIG_PRINTK=n
Date: Tue, 27 Aug 2019 21:45:29 -0700	[thread overview]
Message-ID: <20190828044529.GA30152@google.com> (raw)
In-Reply-To: <20190828030231.GA24069@jagdpanzerIV>

On Wed, Aug 28, 2019 at 12:02:31PM +0900, Sergey Senozhatsky wrote:
> On (08/27/19 16:48), Brendan Higgins wrote:
> > Previously vprintk_emit was only defined when CONFIG_PRINTK=y, this
> > caused a build failure in kunit/test.c when CONFIG_PRINTK was not set.
> > Add a no-op dummy so that callers don't have to ifdef around this.
> > 
> > Note: It has been suggested that this go in through the kselftest tree
> > along with the KUnit patches, because KUnit depends on this. See the
> > second link for the discussion on this.
> 
> Is there any reason for kunit to use vprintk_emit()? Can you switch
> to pr_err()/pr_info()/pr_foo()?
> 
> vprintk_emit() function is pretty internal. It's not static because
> drivers/base/core.c wants to add some extra payload to printk()
> messages (extended headers, etc).

I actually use it in a very similar way as dev_printk() does. I am using
it to define an equivalent kunit_printk(), which takes a log level, and
adds its own test information to the log.

What I have now is:

static int kunit_vprintk_emit(int level, const char *fmt, va_list args)
{
	return vprintk_emit(0, level, NULL, 0, fmt, args);
}

static int kunit_printk_emit(int level, const char *fmt, ...)
{
	va_list args;
	int ret;

	va_start(args, fmt);
	ret = kunit_vprintk_emit(level, fmt, args);
	va_end(args);

	return ret;
}

static void kunit_vprintk(const struct kunit *test,
			  const char *level,
			  struct va_format *vaf)
{
	kunit_printk_emit(level[1] - '0', "\t# %s: %pV", test->name, vaf);
}

The closest thing I can do without vprintk_emit is:

static void kunit_vprintk(const struct kunit *test,
			  const char *level,
			  struct va_format *vaf)
{
	printk("%s\t# %s: %pV", level, test->name, vaf);
}

But checkpatch complains:

WARNING: printk() should include KERN_<LEVEL> facility level

Based on the printk() implementation, it looks like it should be fine to
provide the level via format string since the formatting is performed
before the log level is checked; nevertheless, it seemed to me like
vprintk_emit was closer to what I wanted (again, it's what dev_printk
uses). Shuah and Tim seemed to agree with me:

https://lore.kernel.org/linux-kselftest/ECADFF3FD767C149AD96A924E7EA6EAF977A5D82@USCULXMSG01.am.sony.com/

Nevertheless, I probably don't want add any custom dict entries.

Really, what I think I want is a printk_level().

Thoughts?

  reply	other threads:[~2019-08-28  4:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27 23:48 [PATCH v1] printk: add dummy vprintk_emit for when CONFIG_PRINTK=n Brendan Higgins
2019-08-28  0:45 ` Randy Dunlap
2019-08-28  3:02 ` Sergey Senozhatsky
2019-08-28  4:45   ` Brendan Higgins [this message]
2019-08-28  5:24     ` Sergey Senozhatsky
2019-08-28  9:28       ` Brendan Higgins

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=20190828044529.GA30152@google.com \
    --to=brendanhiggins@google.com \
    --cc=frowand.list@gmail.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sboyd@kernel.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=sfr@canb.auug.org.au \
    --cc=shuah@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).