You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2012/06/10 07:39:22 UTC

svn commit: r1348531 - /subversion/trunk/subversion/tests/libsvn_delta/vdelta-test.c

Author: brane
Date: Sun Jun 10 05:39:22 2012
New Revision: 1348531

URL: http://svn.apache.org/viewvc?rev=1348531&view=rev
Log:
Teach vdelta-test to optionally repeat the test cycle,
making it easier to profile the deltifier.

* subversion/tests/libsvn_delta/vdelta-test.c: Include svn_ctypes.h.
  (do_one_test_cycle): New. Factor the actual test out of main.
  (main): Parse an optional parameter giving the number of test repetitions.
  Call do_one_test_cycle for the number of repetitions, rewinding the
  input files between cycles.

Modified:
    subversion/trunk/subversion/tests/libsvn_delta/vdelta-test.c

Modified: subversion/trunk/subversion/tests/libsvn_delta/vdelta-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_delta/vdelta-test.c?rev=1348531&r1=1348530&r2=1348531&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_delta/vdelta-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_delta/vdelta-test.c Sun Jun 10 05:39:22 2012
@@ -28,6 +28,7 @@
 
 #include "../svn_test.h"
 
+#include "svn_ctype.h"
 #include "svn_delta.h"
 #include "svn_error.h"
 #include "svn_pools.h"
@@ -82,75 +83,17 @@ do_one_diff(apr_file_t *source_file, apr
 }
 
 
-static apr_file_t *
-open_binary_read(const char *path, apr_pool_t *pool)
-{
-  apr_status_t apr_err;
-  apr_file_t *fp;
-
-  apr_err = apr_file_open(&fp, path, (APR_READ | APR_BINARY),
-                          APR_OS_DEFAULT, pool);
-
-  if (apr_err)
-    {
-      fprintf(stderr, "unable to open \"%s\" for reading\n", path);
-      exit(1);
-    }
-
-  return fp;
-}
-
-
-int
-main(int argc, char **argv)
+static void
+do_one_test_cycle(apr_file_t *source_file_A, apr_file_t *target_file_A,
+                  apr_file_t *source_file_B, apr_file_t *target_file_B,
+                  int quiet, apr_pool_t *pool)
 {
-  apr_file_t *source_file_A = NULL;
-  apr_file_t *target_file_A = NULL;
   int count_A = 0;
   apr_off_t len_A = 0;
 
-  apr_file_t *source_file_B = NULL;
-  apr_file_t *target_file_B = NULL;
   int count_B = 0;
   apr_off_t len_B = 0;
 
-  apr_pool_t *pool;
-  int quiet = 0;
-
-  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'q')
-    {
-      quiet = 1;
-      --argc; ++argv;
-    }
-
-  apr_initialize();
-  pool = svn_pool_create(NULL);
-
-  if (argc == 2)
-    {
-      target_file_A = open_binary_read(argv[1], pool);
-    }
-  else if (argc == 3)
-    {
-      source_file_A = open_binary_read(argv[1], pool);
-      target_file_A = open_binary_read(argv[2], pool);
-    }
-  else if (argc == 4)
-    {
-      source_file_A = open_binary_read(argv[1], pool);
-      target_file_A = open_binary_read(argv[2], pool);
-      source_file_B = open_binary_read(argv[2], pool);
-      target_file_B = open_binary_read(argv[3], pool);
-    }
-  else
-    {
-      fprintf(stderr,
-              "Usage: vdelta-test [-q] <target>\n"
-              "   or: vdelta-test [-q] <source> <target>\n"
-              "   or: vdelta-test [-q] <source> <intermediate> <target>\n");
-      exit(1);
-    }
-
   do_one_diff(source_file_A, target_file_A,
               &count_A, &len_A, quiet, pool, "A ", stdout);
 
@@ -219,6 +162,98 @@ main(int argc, char **argv)
       fprintf(stdout, "AB: (LENGTH %" APR_OFF_T_FMT " +%d)\n",
               len_AB, count_AB);
     }
+}
+
+
+static apr_file_t *
+open_binary_read(const char *path, apr_pool_t *pool)
+{
+  apr_status_t apr_err;
+  apr_file_t *fp;
+
+  apr_err = apr_file_open(&fp, path, (APR_READ | APR_BINARY),
+                          APR_OS_DEFAULT, pool);
+
+  if (apr_err)
+    {
+      fprintf(stderr, "unable to open \"%s\" for reading\n", path);
+      exit(1);
+    }
+
+  return fp;
+}
+
+
+int
+main(int argc, char **argv)
+{
+  apr_file_t *source_file_A = NULL;
+  apr_file_t *target_file_A = NULL;
+
+  apr_file_t *source_file_B = NULL;
+  apr_file_t *target_file_B = NULL;
+
+  apr_pool_t *pool;
+  int quiet = 0;
+  int repeat = 1;
+
+  while (argc > 1)
+    {
+      const char *const arg = argv[1];
+      if (arg[0] != '-')
+        break;
+
+      if (arg[1] == 'q')
+        quiet = 1;
+      else if (svn_ctype_isdigit(arg[1]))
+        repeat = atoi(arg + 1);
+      else
+        break;
+      --argc; ++argv;
+    }
+
+  apr_initialize();
+  pool = svn_pool_create(NULL);
+
+  if (argc == 2)
+    {
+      target_file_A = open_binary_read(argv[1], pool);
+    }
+  else if (argc == 3)
+    {
+      source_file_A = open_binary_read(argv[1], pool);
+      target_file_A = open_binary_read(argv[2], pool);
+    }
+  else if (argc == 4)
+    {
+      source_file_A = open_binary_read(argv[1], pool);
+      target_file_A = open_binary_read(argv[2], pool);
+      source_file_B = open_binary_read(argv[2], pool);
+      target_file_B = open_binary_read(argv[3], pool);
+    }
+  else
+    {
+      fprintf(stderr,
+              "Usage: vdelta-test [-q] [-<repeat>] <target>\n"
+              "   or: vdelta-test [-q] [-<repeat>] <source> <target>\n"
+              "   or: vdelta-test [-q] [-<repeat>] "
+              "<source> <intermediate> <target>\n");
+      exit(1);
+    }
+
+  while (0 < repeat--)
+    {
+      apr_off_t offset = 0;
+
+      do_one_test_cycle(source_file_A, target_file_A,
+                        source_file_B, target_file_B,
+                        quiet, pool);
+
+      if (source_file_A) apr_file_seek(source_file_A, APR_SET, &offset);
+      if (target_file_A) apr_file_seek(target_file_A, APR_SET, &offset);
+      if (source_file_B) apr_file_seek(source_file_B, APR_SET, &offset);
+      if (target_file_B) apr_file_seek(target_file_B, APR_SET, &offset);
+    }
 
   if (source_file_A) apr_file_close(source_file_A);
   if (target_file_A) apr_file_close(target_file_A);