Hi!
> diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
> index f3983d4..64751fd 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)
> @@ -712,3 +712,82 @@ void check_ksm_options(int *size, int *num, int *unit)
>                               "process number cannot be less 3.");
>       }
>  }
> +
> +void set_sys_tune(char *sys_file, long long tune)
> +{
> +     int fd;
> +     char buf[BUFSIZ];
> +
> +     tst_resm(TINFO, "set %s to %lld", sys_file, tune);
> +
> +     fd = open(sys_file, O_WRONLY);
> +     if (fd == -1)
> +             tst_brkm(TBROK|TERRNO, cleanup, "open %s", sys_file);
> +     if (snprintf(buf, BUFSIZ, "%lld", tune) < 0)
> +             tst_brkm(TBROK|TERRNO, cleanup, "snprintf");
> +     if (write(fd, buf, strlen(buf)) == -1)
> +             tst_brkm(TBROK|TERRNO, cleanup, "write");

Please add the filename into the message that gets printed when write
has failed too. And possibly enclose the %s with ' eg. 
tst_brkm(... "open '%s'", sys_file).

> +     close(fd);
> +}
> +
> +long long get_sys_tune(char *sys_file)
> +{
> +     int fd;
> +     long long tune;
> +     char buf[BUFSIZ], *endptr;
> +
> +     fd = open(sys_file, O_RDONLY);
> +     if (fd == -1)
> +             tst_brkm(TBROK|TERRNO, cleanup, "open %s", sys_file);
> +     if (read(fd, buf, BUFSIZ) < 0)
> +             tst_brkm(TBROK|TERRNO, cleanup, "read");

And here into the read branch too.

> +     close(fd);
> +
> +     tune = strtoll(buf, &endptr, 10);
> +     if (tune == LLONG_MAX || tune == LLONG_MIN)
> +             tst_brkm(TBROK|TERRNO, cleanup, "strtoll");
> +     if (endptr == buf || (*endptr != '\0' && *endptr != '\n'))
> +             tst_brkm(TBROK, cleanup, "Invalid tunable: %s", buf);
> +
> +     return tune;
> +}
> +
> +/*
> + * the function is designed to make sure the value we get from
> + * sys_file is equal to what we set last.
> + */
> +void check_sys_tune(char *sys_file, long long tune)
> +{
> +     long long val;
> +
> +     val = get_sys_tune(sys_file);
> +     if (val == tune)
> +             tst_resm(TINFO, "confirmed %s = %lld", sys_file, tune);
> +     else
> +             tst_brkm(TBROK, cleanup, "%s = %lld, is not %lld",
> +                             sys_file, val, tune);
> +}
> +
> +long long read_meminfo(char *item)
> +{
> +     FILE *fp;
> +     char line[BUFSIZ], buf[BUFSIZ];
> +     long 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, "%s %lld ", 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);
> +}


-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Why Cloud-Based Security and Archiving Make Sense
Osterman Research conducted this study that outlines how and why cloud
computing security and archiving is rapidly being adopted across the IT 
space for its ease of implementation, lower cost, and increased 
reliability. Learn more. http://www.accelacomm.com/jaw/sfnl/114/51425301/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to