Skip to content

Commit

Permalink
tst_memutils.c: Add tst_print_meminfo()
Browse files Browse the repository at this point in the history
Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Wei Gao <[email protected]>
[ pvorel: use fprintf(), add TINFO message ]
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
coolgw authored and pevik committed Dec 18, 2023
1 parent d6340f0 commit dddc06b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/tst_memutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
3 changes: 3 additions & 0 deletions include/tst_safe_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <dirent.h>
#include <grp.h>

#include "safe_stdio_fn.h"
#include "safe_macros_fn.h"
#include "tst_cmd.h"

Expand Down Expand Up @@ -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__ */
15 changes: 15 additions & 0 deletions lib/tst_safe_macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,18 @@ 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];

tst_res(TINFO, "=== %s ===", path);

pfile = safe_fopen(file, lineno, NULL, path, "r");

while (fgets(line, sizeof(line), pfile))
fprintf(stderr, "%s", line);

safe_fclose(file, lineno, NULL, pfile);
}

0 comments on commit dddc06b

Please sign in to comment.