[LTP] [PATCH v4 1/2] tst_memutils.c: Add tst_print_meminfo function

Wei Gao wegao@suse.com
Mon Dec 18 13:22:35 CET 2023


Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/tst_memutils.h    |  2 ++
 include/tst_safe_macros.h |  3 +++
 lib/tst_safe_macros.c     | 13 +++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 19b593430..0dd941ced 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -58,4 +58,6 @@ void tst_enable_oom_protection(pid_t pid);
  */
 void tst_disable_oom_protection(pid_t pid);
 
+#define TST_PRINT_MEMINFO() safe_print_file(__FILE__, __LINE__, "/proc/meminfo")
+
 #endif /* TST_MEMUTILS_H__ */
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index c899c4f2c..f2ce8919b 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -21,6 +21,7 @@
 #include <dirent.h>
 #include <grp.h>
 
+#include "safe_stdio_fn.h"
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
 
@@ -671,4 +672,6 @@ int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info);
 #define SAFE_SYSINFO(info) \
 	safe_sysinfo(__FILE__, __LINE__, (info))
 
+void safe_print_file(const char *file, const int lineno, char *path);
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 7f28d43e5..024963bab 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -610,3 +610,16 @@ int safe_msync(const char *file, const int lineno, void *addr,
 
 	return rval;
 }
+
+void safe_print_file(const char *file, const int lineno, char *path)
+{
+	FILE *pfile;
+	char line[PATH_MAX];
+
+	pfile = safe_fopen(file, lineno, NULL, path, "r");
+
+	while (fgets(line, sizeof(line), pfile))
+		tst_resm_(file, lineno, TINFO, "%s", line);
+
+	safe_fclose(file, lineno, NULL, pfile);
+}
-- 
2.35.3



More information about the ltp mailing list