perf vendor events: Update events and metrics for cascadelakex
[linux-2.6-microblaze.git] / lib / test_printf.c
index 07309c4..4bd15a5 100644 (file)
 #define PAD_SIZE 16
 #define FILL_CHAR '$'
 
+#define NOWARN(option, comment, block) \
+       __diag_push(); \
+       __diag_ignore_all(#option, comment); \
+       block \
+       __diag_pop();
+
 KSTM_MODULE_GLOBALS();
 
 static char *test_buffer __initdata;
@@ -78,12 +84,17 @@ 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))) {
+       if (memchr_inv(test_buffer + written + 1, FILL_CHAR, bufsize - (written + 1))) {
                pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n",
                        bufsize, fmt);
                return 1;
        }
 
+       if (memchr_inv(test_buffer + bufsize, FILL_CHAR, BUF_SIZE + PAD_SIZE - bufsize)) {
+               pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond buffer\n", bufsize, fmt);
+               return 1;
+       }
+
        if (memcmp(test_buffer, expect, written)) {
                pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n",
                        bufsize, fmt, test_buffer, written, expect);
@@ -154,9 +165,11 @@ test_number(void)
        test("0x1234abcd  ", "%#-12x", 0x1234abcd);
        test("  0x1234abcd", "%#12x", 0x1234abcd);
        test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0, 1, 12, 123, 1234, -123, -1234);
-       test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1);
-       test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1);
-       test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627);
+       NOWARN(-Wformat, "Intentionally test narrowing conversion specifiers.", {
+               test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1);
+               test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1);
+               test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627);
+       })
        /*
         * POSIX/C99: »The result of converting zero with an explicit
         * precision of zero shall be no characters.« Hence the output