]> sourceware.org Git - lvm2.git/commitdiff
Display duration of tests when it passed.
authorZdenek Kabelac <zkabelac@redhat.com>
Fri, 28 Jan 2011 16:05:38 +0000 (16:05 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 28 Jan 2011 16:05:38 +0000 (16:05 +0000)
Enhance output with info about the test duration.
Cleanup few declarations in the code.

test/lib/harness.c

index f07d2edf74e7e67c5f01ff373ed9ecf990063a7d..ae6c3449c70375a4e9e0dee03f3a255779449bce 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <time.h>
 
 static pid_t pid;
 static int fds[2];
@@ -82,9 +83,9 @@ static int outline(char *buf, int start, int force) {
                 char *line = strndup(from, next - from);
                 char *a = line, *b;
                 do {
-                        b = line + strlen(line);
                         int idx = -1;
                         int i;
+                        b = line + strlen(line);
                         for ( i = 0; i < 2; ++i ) {
                                 if (subst[i].key) {
                                         // printf("trying: %s -> %s\n", subst[i].value, subst[i].key);
@@ -145,15 +146,24 @@ static void drain(void) {
        }
 }
 
-static void passed(int i, char *f) {
+static const char *duration(time_t start)
+{
+       static char buf[16];
+       int t = (int)(time(NULL) - start);
+
+       sprintf(buf, "%2d:%02d", t / 60, t % 60);
+       return buf;
+}
+
+static void passed(int i, char *f, time_t t) {
        if (strstr(readbuf, "TEST WARNING")) {
                ++s.nwarned;
                s.status[i] = WARNED;
-               printf("warnings\n");
+               printf("warnings  %s\n", duration(t));
        } else {
                ++ s.npassed;
                s.status[i] = PASSED;
-               printf("passed.\n");
+               printf("passed.   %s\n", duration(t));
        }
 }
 
@@ -192,12 +202,13 @@ static void run(int i, char *f) {
                fflush(stderr);
                _exit(202);
        } else {
+               int st, w;
+               time_t start = time(NULL);
                char buf[128];
                snprintf(buf, 128, "%s ...", f);
                buf[127] = 0;
                printf("Running %-40s ", buf);
                fflush(stdout);
-               int st, w;
                while ((w = waitpid(pid, &st, WNOHANG)) == 0) {
                        drain();
                        usleep(20000);
@@ -209,7 +220,7 @@ static void run(int i, char *f) {
                drain();
                if (WIFEXITED(st)) {
                        if (WEXITSTATUS(st) == 0) {
-                               passed(i, f);
+                               passed(i, f, start);
                        } else if (WEXITSTATUS(st) == 200) {
                                skipped(i, f);
                        } else {
@@ -223,6 +234,8 @@ static void run(int i, char *f) {
 }
 
 int main(int argc, char **argv) {
+       const char *be_verbose = getenv("VERBOSE");
+       time_t start = time(NULL);
        int i;
 
        if (argc >= MAX) {
@@ -230,9 +243,6 @@ int main(int argc, char **argv) {
                exit(1);
        }
 
-       s.nwarned = s.nfailed = s.npassed = s.nskipped = 0;
-
-       char *be_verbose = getenv("VERBOSE");
        if (be_verbose && atoi(be_verbose))
                verbose = 1; // XXX
 
@@ -260,8 +270,9 @@ int main(int argc, char **argv) {
                        break;
        }
 
-       printf("\n## %d tests: %d OK, %d warnings, %d failures; %d skipped\n",
+       printf("\n## %d tests %s : %d OK, %d warnings, %d failures; %d skipped\n",
               s.nwarned + s.npassed + s.nfailed + s.nskipped,
+              duration(start),
               s.npassed, s.nwarned, s.nfailed, s.nskipped);
 
        /* print out a summary */
@@ -279,5 +290,6 @@ int main(int argc, char **argv) {
                printf("\n");
                return s.nfailed > 0 || die;
        }
+
        return die;
 }
This page took 0.039568 seconds and 5 git commands to generate.