[LTP] [PATCH] madvise06: Allow for kmem and memsw counters being disabled
Richard Palethorpe
rpalethorpe@suse.com
Mon Nov 16 11:52:09 CET 2020
These may be missing and we only access them for printing diagnostic
info.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
testcases/kernel/syscalls/madvise/madvise06.c | 22 ++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/testcases/kernel/syscalls/madvise/madvise06.c b/testcases/kernel/syscalls/madvise/madvise06.c
index 2ba2bac6f..dc515d528 100644
--- a/testcases/kernel/syscalls/madvise/madvise06.c
+++ b/testcases/kernel/syscalls/madvise/madvise06.c
@@ -64,14 +64,16 @@ static void check_path(const char *path)
}
#define READ_CGMEM(item) \
- ({long tst_rval; \
- SAFE_FILE_LINES_SCANF(MNT_NAME"/"GROUP_NAME"/memory."item, \
- "%ld", \
- &tst_rval); \
+ ({long tst_rval = 0; \
+ const char *cgpath = MNT_NAME"/"GROUP_NAME"/memory."item; \
+ if (!access(cgpath, R_OK)) \
+ SAFE_FILE_LINES_SCANF(cgpath, "%ld", &tst_rval); \
tst_rval;})
static void meminfo_diag(const char *point)
{
+ long rval;
+
FILE_PRINTF("/proc/sys/vm/stat_refresh", "1");
tst_res(TINFO, "%s", point);
tst_res(TINFO, "\tSwap: %ld Kb",
@@ -82,10 +84,14 @@ static void meminfo_diag(const char *point)
SAFE_READ_MEMINFO("Cached:") - init_cached);
tst_res(TINFO, "\tcgmem.usage_in_bytes: %ld Kb",
READ_CGMEM("usage_in_bytes") / 1024);
- tst_res(TINFO, "\tcgmem.memsw.usage_in_bytes: %ld Kb",
- READ_CGMEM("memsw.usage_in_bytes") / 1024);
- tst_res(TINFO, "\tcgmem.kmem.usage_in_bytes: %ld Kb",
- READ_CGMEM("kmem.usage_in_bytes") / 1024);
+
+ rval = READ_CGMEM("memsw.usage_in_bytes") / 1024;
+ if (rval)
+ tst_res(TINFO, "\tcgmem.memsw.usage_in_bytes: %ld Kb", rval);
+
+ rval = READ_CGMEM("kmem.usage_in_bytes") / 1024;
+ if (rval)
+ tst_res(TINFO, "\tcgmem.kmem.usage_in_bytes: %ld Kb", rval);
}
static void setup(void)
--
2.29.1
More information about the ltp
mailing list