From: Caspar Z. <su...@li...> - 2011-12-23 08:58:18
|
The branch, master, has been updated via 233e122774264d73767ce217494f2798e0f450ba (commit) from 052a43404c013399d79fa136f2aef698a0bd999c (commit) - Log ----------------------------------------------------------------- commit 233e122774264d73767ce217494f2798e0f450ba Author: Caspar Zhang <ca...@ca...> Date: Fri Dec 23 13:02:56 2011 +0800 mem/lib: add read_meminfo() function adds a read_meminfo() function. @params: meminfo item to be searched (should include colon) @return: a long int value for this item Signed-off-by: Caspar Zhang <ca...@ca...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/mem/include/mem.h | 2 ++ testcases/kernel/mem/lib/mem.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletions(-) diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h index 9e6b72c..7659236 100644 --- a/testcases/kernel/mem/include/mem.h +++ b/testcases/kernel/mem/include/mem.h @@ -19,6 +19,7 @@ #define MB (1UL<<20) #define PATH_SYS_SYSTEM "/sys/devices/system" #define PATH_KSM "/sys/kernel/mm/ksm/" +#define PATH_MEMINFO "/proc/meminfo" char overcommit[BUFSIZ]; int opt_num, opt_size, opt_unit; @@ -48,4 +49,5 @@ void create_same_memory(int size, int num, int unit); void check_ksm_options(int *size, int *num, int *unit); void write_cpusets(void); void write_memcg(void); +long read_meminfo(char *item); #endif diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c index 98fe5cc..2be3744 100644 --- a/testcases/kernel/mem/lib/mem.c +++ b/testcases/kernel/mem/lib/mem.c @@ -77,7 +77,7 @@ void write_memcg(void) snprintf(buf, BUFSIZ, "%d", getpid()); if (write(fd, buf, strlen(buf)) != strlen(buf)) tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf); - close(fd); + close(fd); } void write_cpusets(void) @@ -715,3 +715,27 @@ void check_ksm_options(int *size, int *num, int *unit) "process number cannot be less 3."); } } + +long read_meminfo(char *item) +{ + FILE *fp; + char line[BUFSIZ], buf[BUFSIZ]; + long val; + + fp = fopen(PATH_MEMINFO, "r"); + if (fp == NULL) + tst_brkm(TBROK|TERRNO, cleanup, "fopen %s", PATH_MEMINFO); + + while (fgets(line, BUFSIZ, fp) != NULL) { + if (sscanf(line, "%64s %ld", buf, &val) == 2) + if (strcmp(buf, item) == 0) { + fclose(fp); + return val; + } + continue; + } + fclose(fp); + + tst_brkm(TBROK, cleanup, "cannot find \"%s\" in %s", + item, PATH_MEMINFO); +} hooks/post-receive -- ltp |