Skip to contentSkip to conversation

kunit: fix failure to build without printk

PATCH New Brendan Higgins 1 participant 1 message Sep 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 kunit: fix failure to build without printk

Previously KUnit assumed that printk would always be present, which is not a valid assumption to make. Fix that by removing call to vprintk_emit, and calling printk directly.

This fixes a build error[1] reported by Randy.

For context this change comes after much discussion. My first stab[2] at this was just to make the KUnit logging code compile out; however, it was agreed that if we were going to use vprintk_emit, then vprintk_emit should provide a no-op stub, which lead to my second attempt[3]. In response to me trying to stub out vprintk_emit, Sergey Senozhatsky suggested a way for me to remove our usage of vprintk_emit, which led to my third attempt at solving this[4].

In my third version of this patch[4], I completely removed vprintk_emit, as suggested by Sergey; however, there was a bit of debate over whether Sergey's solution was the best. The debate arose due to Sergey's version resulting in a checkpatch warning, which resulted in a debate over correct printk usage. Joe Perches offered an alternative fix which was somewhat less far reaching than what Sergey had suggested and importantly relied on continuing to use %pV. Much of the debated centered around whether %pV should be widely used, and whether Sergey's version would result in object size bloat. Ultimately, we decided to go with Sergey's version.

Link[1]: https://lore.kernel.org/linux-kselftest/[email protected]/
Link[2]: https://lore.kernel.org/linux-kselftest/[email protected]/
Link[3]: https://lore.kernel.org/linux-kselftest/[email protected]/
Link[4]: https://lore.kernel.org/linux-kselftest/[email protected]/

---

Sorry for the long commit message, but given the long discussion (and some of the confusion that occurred in the discussion), it seemed appropriate to summarize the discussion around this patch up to this point (especially since one of the proposed patches was under a separate patch subject).

Changes Since v3:

Renamed kunit_print_level to kunit_printk, and changed the KERN_LEVEL macro parameter (in kunit_printk) to lvl, as suggested by Joe.

---
 include/kunit/test.h |  5 ++--
 kunit/test.c         | 57 +++++---------------------------------------
 2 files changed, 8 insertions(+), 54 deletions(-)
include/kunit/test.h +2 -3
index 8b7eb03d4971..dba48304b3bd 100644
@@ -339,9 +339,8 @@ static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
 
 void kunit_cleanup(struct kunit *test);
 
-void __printf(3, 4) kunit_printk(const char *level,
-				 const struct kunit *test,
-				 const char *fmt, ...);
+#define kunit_printk(lvl, test, fmt, ...) \
+	printk(lvl "\t# %s: " fmt, (test)->name, ##__VA_ARGS__)
 
 /**
  * kunit_info() - Prints an INFO level message associated with @test.
kunit/test.c +6 -51

92 lines not on this page · raw message

Signature · 1 line
2.23.0.187.g17f5b7556c-goog