Messages in this thread Patch in this message | | | From | Rasmus Villemoes <> | Subject | [RFC 6/6] lib/test_printf.c: add a few fmtcheck() test cases | Date | Wed, 8 Nov 2017 23:30:20 +0100 |
| |
It should be trivial to add more test cases, once we figure out the exact rules for being compatible or not. Perhaps we'll have to extend the struct test with a flags element if we add flags that affect the return value.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> --- lib/test_printf.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
diff --git a/lib/test_printf.c b/lib/test_printf.c index 563f10e6876a..0c8490f3a9b3 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -483,6 +483,45 @@ test_pointer(void) flags(); } +static void __init +test_fmtcheck(void) +{ + struct test { const char *fmt; const char *tmpl; }; + static const struct test compatible[] __initconst = { + {"", ""}, + {"wlan%d", "%d"}, + {"aa%llxbb", "cc%Lxdd%%"}, + }; + static const struct test incompatible[] __initconst = { + {"a %d b %lx", "%d %x"}, + {"%llo", "%Lx"}, + }; + unsigned i; + const struct test *t; + const char *ret; + + for (i = 0; i < ARRAY_SIZE(compatible); ++i) { + total_tests++; + t = &compatible[i]; + ret = _fmtcheck(t->fmt, t->tmpl, FMTCHECK_SILENT); + if (ret != t->fmt) { + failed_tests++; + pr_warn("'%s' and '%s' deemed incompatible by fmtcheck()", + t->fmt, t->tmpl); + } + } + for (i = 0; i < ARRAY_SIZE(incompatible); ++i) { + total_tests++; + t = &incompatible[i]; + ret = _fmtcheck(t->fmt, t->tmpl, FMTCHECK_SILENT); + if (ret != t->tmpl) { + failed_tests++; + pr_warn("'%s' and '%s' deemed compatible by fmtcheck()", + t->fmt, t->tmpl); + } + } +} + static int __init test_printf_init(void) { @@ -496,6 +535,8 @@ test_printf_init(void) test_string(); test_pointer(); + test_fmtcheck(); + kfree(alloced_buffer); if (failed_tests == 0) -- 2.11.0
| |