xfs
[Top] [All Lists]

[PATCH] xfstests: enhance ltp/fsx with a timeout option

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfstests: enhance ltp/fsx with a timeout option
From: David Sterba <dsterba@xxxxxxx>
Date: Wed, 23 Jan 2013 13:40:51 +0100
Cc: David Sterba <dsterba@xxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
New option T will let fsx run for a given amount of time (in seconds,
accepts d/h/m/s modifiers). This option is mutually exclusive with the
-N numops option.

This can be used in situations when guessing the right number of fsx
operations is tedious or just not that important. The test run time is
bounded and more suitable for automated testing.

Signed-off-by: David Sterba <dsterba@xxxxxxx>
---
 ltp/fsx.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/ltp/fsx.c b/ltp/fsx.c
index 2f1e3e8..94a8f8b 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -140,6 +140,7 @@ long        numops = -1;                    /* -N flag */
 int    randomoplen = 1;                /* -O flag disables it */
 int    seed = 1;                       /* -S flag */
 int     mapped_writes = 1;              /* -W flag disables */
+int     timeout = 0;                   /* -T flag */
 int     fallocate_calls = 1;            /* -F flag disables */
 int     punch_hole_calls = 1;           /* -H flag disables */
 int    mapped_reads = 1;               /* -R flag disables it */
@@ -1150,6 +1151,7 @@ usage(void)
        -O: use oplen (see -o flag) for every op (default random)\n\
        -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
        -S seed: for random # generator (default 1) 0 gets timestamp\n\
+       -T timespec: run for at most timespec (accepts d/h/m/s modifiers)\n\
        -W: mapped write operations DISabled\n\
         -R: read() system calls only (mapped reads disabled)\n\
         -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
@@ -1191,6 +1193,38 @@ getnum(char *s, char **e)
        return (ret);
 }
 
+int
+gettime(char *s, char **e)
+{
+       int num;
+
+       *e = (char *) 0;
+       num = strtol(s, e, 0);
+       if (*e)
+               switch (**e) {
+               case 'd':
+               case 'D':
+                       num *= 24*60*60;
+                       *e = *e + 1;
+                       break;
+               case 'h':
+               case 'H':
+                       num *= 60*60;
+                       *e = *e + 1;
+                       break;
+               case 'm':
+               case 'M':
+                       num *= 60;
+                       *e = *e + 1;
+                       break;
+               case 's':
+               case 'S':
+                       *e = *e + 1;
+                       break;
+               }
+       return (num);
+}
+
 #ifdef AIO
 
 #define QSZ     1024
@@ -1337,6 +1371,7 @@ main(int argc, char **argv)
        char    *endp;
        char goodfile[1024];
        char logfile[1024];
+       time_t start_time;
 
        goodfile[0] = 0;
        logfile[0] = 0;
@@ -1348,7 +1383,7 @@ main(int argc, char **argv)
 
        setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
 
-       while ((ch = getopt(argc, argv, 
"b:c:dfl:m:no:p:qr:s:t:w:xyAD:FHLN:OP:RS:WZ"))
+       while ((ch = getopt(argc, argv, 
"b:c:dfl:m:no:p:qr:s:t:w:xyAD:FHLN:OP:RS:T:WZ"))
               != EOF)
                switch (ch) {
                case 'b':
@@ -1455,6 +1490,10 @@ main(int argc, char **argv)
                        numops = getnum(optarg, &endp);
                        if (numops < 0)
                                usage();
+                       if (timeout > 0) {
+                               fprintf(stdout, "Numops and timeout cannot be 
used together\n");
+                               usage();
+                       }
                        break;
                case 'O':
                        randomoplen = 0;
@@ -1477,6 +1516,20 @@ main(int argc, char **argv)
                        if (seed < 0)
                                usage();
                        break;
+               case 'T':
+                       timeout = gettime(optarg, &endp);
+                       if (timeout < 0) {
+                               fprintf(stdout, "Timeout is negative.\n");
+                               usage();
+                       }
+                       if (numops > 0) {
+                               fprintf(stdout, "Timeout and numops cannot be 
used together\n");
+                               usage();
+                       }
+                       if (!quiet)
+                               fprintf(stdout, "timeout set to %d seconds\n",
+                                               timeout);
+                       break;
                case 'W':
                        mapped_writes = 0;
                        if (!quiet)
@@ -1596,8 +1649,12 @@ main(int argc, char **argv)
        test_fallocate();
        test_punch_hole();
 
-       while (numops == -1 || numops--)
+       start_time = time(NULL);
+       while (numops == -1 || numops--) {
                test();
+               if (timeout && time(NULL) - start_time > timeout)
+                       break;
+       }
 
        if (close(fd)) {
                prterr("close");
-- 
1.8.0.2

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH] xfstests: enhance ltp/fsx with a timeout option, David Sterba <=