Hi!
>  testcases/kernel/syscalls/swapon/swapon01.c |   19 +++++-
>  testcases/kernel/syscalls/swapon/swapon02.c |   84 
> ++++++++++++---------------
>  testcases/kernel/syscalls/swapon/swapon03.c |   17 +-----
>  3 files changed, 55 insertions(+), 65 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c 
> b/testcases/kernel/syscalls/swapon/swapon01.c
> index 11a49f9..05f1579 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -132,6 +132,10 @@ int main(int ac, char **av)
>  /* setup() - performs all ONE TIME setup for this test */
>  void setup()
>  {
> +     char cmd_buffer[256];
> +
> +     long bs = sysconf(_SC_PAGESIZE);
> +     int count = 10;
>  
>       tst_sig(FORK, DEF_HANDLER, cleanup);
>  
> @@ -154,15 +158,22 @@ void setup()
>                        "Cannot do swapon on a file located on a nfs 
> filesystem");
>       }
>  
> -     if (!tst_cwd_has_free(65536)) {
> +     if (!tst_cwd_has_free(bs*count)) {
>               tst_brkm(TBROK, cleanup,
>                        "Insufficient disk space to create swap file");
>       }
>  
>       /*create file */
> -     if (system("dd if=/dev/zero of=swapfile01 bs=1024 count=65536 >"
> -                " tmpfile 2>&1") != 0) {
> -             tst_brkm(TBROK, cleanup, "Failed to create file for swap");
> +     if (snprintf(cmd_buffer, sizeof(cmd_buffer),
> +                     "dd if=/dev/zero of=swapfile01 bs=%li "
> +                     "count=%i > /tmp/file 2>&1", bs, count) < 0) {
> +             tst_brkm(TBROK, cleanup, 
> +                     "sprintf() failed to create command string");
> +     }
> +
> +     if (system(cmd_buffer) != 0) {
> +             tst_brkm(TBROK, cleanup, "dd command failed to create file via "
> +                     "command: %s", cmd_buffer);

This part of the code seems to be repeated several times. What about
making it into library code in lib/tst_fill_file.c instead?

Something like:

tst_fill_file(const char *path, char pattern, size_t bs, size_t count);

And I would open the and write the file directly rather than doing
system("dd ...");

-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to