mirror of
https://github.com/torvalds/linux.git
synced 2024-12-03 17:41:22 +00:00
77f18153c0
With gcc 8 we get new set of snprintf() warnings that breaks the compilation, one example: tests/mem.c: In function ‘check’: tests/mem.c:19:48: error: ‘%s’ directive output may be truncated writing \ up to 99 bytes into a region of size 89 [-Werror=format-truncation=] snprintf(failure, sizeof failure, "unexpected %s", out); The gcc docs says: To avoid the warning either use a bigger buffer or handle the function's return value which indicates whether or not its output has been truncated. Given that all these warnings are harmless, because the code either properly fails due to uncomplete file path or we don't care for truncated output at all, I'm changing all those snprintf() calls to scnprintf(), which actually 'checks' for the snprint return value so the gcc stays silent. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> Link: http://lkml.kernel.org/r/20180319082902.4518-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
#include "util/mem-events.h"
|
|
#include "util/symbol.h"
|
|
#include "linux/perf_event.h"
|
|
#include "util/debug.h"
|
|
#include "tests.h"
|
|
#include <string.h>
|
|
|
|
static int check(union perf_mem_data_src data_src,
|
|
const char *string)
|
|
{
|
|
char out[100];
|
|
char failure[100];
|
|
struct mem_info mi = { .data_src = data_src };
|
|
|
|
int n;
|
|
|
|
n = perf_mem__snp_scnprintf(out, sizeof out, &mi);
|
|
n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi);
|
|
scnprintf(failure, sizeof failure, "unexpected %s", out);
|
|
TEST_ASSERT_VAL(failure, !strcmp(string, out));
|
|
return 0;
|
|
}
|
|
|
|
int test__mem(struct test *text __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
int ret = 0;
|
|
union perf_mem_data_src src;
|
|
|
|
memset(&src, 0, sizeof(src));
|
|
|
|
src.mem_lvl = PERF_MEM_LVL_HIT;
|
|
src.mem_lvl_num = 4;
|
|
|
|
ret |= check(src, "N/AL4 hit");
|
|
|
|
src.mem_remote = 1;
|
|
|
|
ret |= check(src, "N/ARemote L4 hit");
|
|
|
|
src.mem_lvl = PERF_MEM_LVL_MISS;
|
|
src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
|
|
src.mem_remote = 0;
|
|
|
|
ret |= check(src, "N/APMEM miss");
|
|
|
|
src.mem_remote = 1;
|
|
|
|
ret |= check(src, "N/ARemote PMEM miss");
|
|
|
|
src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
|
|
src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;
|
|
|
|
ret |= check(src , "FwdRemote RAM miss");
|
|
|
|
return ret;
|
|
}
|