]> granicus.if.org Git - check/commitdiff
* Measure test duration correctly. Fixes SF bug #3575451.
authorhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Thu, 11 Oct 2012 08:53:08 +0000 (08:53 +0000)
committerhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Thu, 11 Oct 2012 08:53:08 +0000 (08:53 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@622 64e312b2-a51f-0410-8e61-82d0ca0eb02a

src/check_log.c

index bec5aa4b2ef435921ec7463a932b3f7d4f3743c3..7be1b42fb065cacfd61c56abfd5a273f5364a9f1 100644 (file)
@@ -222,7 +222,7 @@ void xml_lfun (SRunner *sr CK_ATTRIBUTE_UNUSED, FILE *file, enum print_output pr
 {
   TestResult *tr;
   Suite *s;
-  static struct timeval inittv, endtv;
+  static struct timeval inittv;
   static char t[sizeof "yyyy-mm-dd hh:mm:ss"] = {0};
 
   if (t[0] == 0)
@@ -241,11 +241,17 @@ void xml_lfun (SRunner *sr CK_ATTRIBUTE_UNUSED, FILE *file, enum print_output pr
     fprintf(file, "  <datetime>%s</datetime>\n", t);
     break;
   case CLENDLOG_SR:
-    gettimeofday(&endtv, NULL);
-    fprintf(file, "  <duration>%f</duration>\n",
-        (endtv.tv_sec + (float)(endtv.tv_usec)/1000000) - \
-        (inittv.tv_sec + (float)(inittv.tv_usec/1000000)));
-    fprintf(file, "</testsuites>\n");
+    {
+      struct timeval now;
+
+      /* calculate time the test were running */
+      gettimeofday(&now, NULL);
+      timersub(&now, &inittv, &now);
+
+      fprintf(file, "  <duration>%d.%06d</duration>\n",
+              now.tv_sec, now.tv_usec);
+      fprintf(file, "</testsuites>\n");
+    }
     break;
   case CLSTART_SR:
     break;