subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1606743 - in /subversion/trunk/subversion/tests/cmdline: svnadmin_tests.py svntest/main.py
Date Mon, 30 Jun 2014 13:57:53 GMT
Author: stefan2
Date: Mon Jun 30 13:57:52 2014
New Revision: 1606743

URL: http://svn.apache.org/r1606743
Log:
Instead of manually fiddling with FSFS index data in our test suite,
use the svnfsfs tool to read and rewrite the indexes after we manipulated
the revision contents.

* subversion/tests/cmdline/svnadmin_tests.py
  (FSFS_Index): New utility class handling all the index access.
  (read_l2p): Drop obsolete utility.
  (set_changed_path_list): Use the new class to read the index data and
                           to keep it consistent with our manipulated
                           rev content.
  (verify_invalid_path_changes): Update expected errors as we don't get
                                 low-level checksum mismatches anymore.

* subversion/tests/cmdline/svntest/main.py
  (svnfsfs_binary): New tool constant similar to svnauthz-binary.
  (run_svnfsfs): New runner utility for the new binary.

Modified:
    subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py
    subversion/trunk/subversion/tests/cmdline/svntest/main.py

Modified: subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py?rev=1606743&r1=1606742&r2=1606743&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py Mon Jun 30 13:57:52 2014
@@ -262,40 +262,76 @@ def load_dumpstream(sbox, dump, *varargs
   return load_and_verify_dumpstream(sbox, None, None, None, False, dump,
                                     *varargs)
 
-def read_l2p(contents, item):
-  """ For the format 7+ revision file CONTENTS, return the physical offset
-      of ITEM.  This code supports only small, nonpacked revs. """
-
-  # decode numbers
-  numbers = []
-  value = 0
-  shift = 0
-  for c in contents:
-    char = ord(c)
-    value += (char & 127) << shift
-    if char < 128:
-      numbers.append(value)
-      shift = 0
-      value = 0
-    else:
-      shift += 7
-
-  # decode offsets
-  numbers[7] = -1
-  for i in range(8, len(numbers)):
-    if numbers[i] & 1 == 1:
-      numbers[i] = - (numbers[i] + 1) / 2
-    else:
-      numbers[i] = numbers[i] / 2
-    numbers[i] += numbers[i-1]
+class FSFS_Index:
+  """Manages indexes of a rev file in a FSFS format 7 repository.
+  The interface returns P2L information and allows for item offsets
+  and lengths to be modified. """
+
+  by_item = { }
+  revision = -1
+  repo_dir = None
+
+  def __init__(self, sbox, revision):
+    self.revision = revision
+    self.repo_dir = sbox.repo_dir
+
+    self._read()
+
+  def _read(self):
+    """ Read P2L index using svnfsfs. """
+    exit_code, output, errput = svntest.main.run_svnfsfs('dump-index',
+                                                  '-r' + str(self.revision),
+                                                  self.repo_dir)
+    svntest.verify.verify_outputs("Error while dumping index",
+                                  [], errput, [], [])
+    svntest.verify.verify_exit_code(None, exit_code, 0)
+
+    self.by_item.clear()
+    for line in output:
+      values = line.split()
+      if len(values) >= 4 and values[0] != 'Start':
+        item = long(values[4])
+        self.by_item[item] = values
+
+  def _write(self):
+    """ Rewrite indexes using svnfsfs. """
+    by_offset = {}
+    for values in self.by_item.itervalues():
+      by_offset[long(values[0], 16)] = values
+
+    lines = []
+    for (offset, values) in sorted(by_offset.items()):
+      values = by_offset[offset]
+      line = values[0] + ' ' + values[1] + ' ' + values[2] + ' ' + \
+             values[3] + ' ' + values[4] + '\n';
+      lines.append(line)
+
+    exit_code, output, errput = svntest.main.run_command_stdin(
+      svntest.main.svnfsfs_binary, 0, 0, True, lines,
+      'load-index', self.repo_dir)
+
+    svntest.verify.verify_outputs("Error while rewriting index",
+                                  output, errput, [], [])
+    svntest.verify.verify_exit_code(None, exit_code, 0)
+
+  def get_item(self, item):
+    """ Return offset, length and type of ITEM. """
+    values = self.by_item[item]
+
+    offset = long(values[0], 16)
+    len = long(values[1], 16)
+    type = values[2]
+
+    return (offset, len, type)
+
+  def modify_item(self, item, offset, len):
+    """ Modify offset and length of ITEM. """
+    values = self.by_item[item]
 
-  # we support only small, unpacked rev files
-  if numbers[1] < len(numbers) or numbers[3] != 1 :
-    raise svntest.Failure("More than 1 page in %s" % filename)
-  if numbers[2] != 1:
-    raise svntest.Failure("More than 1 rev in %s" % filename)
+    values[0] = format(offset, 'x')
+    values[1] = format(len, 'x')
 
-  return numbers[item + 7]
+    self._write()
 
 def repo_format(sbox):
   """ Return the repository format number for SBOX."""
@@ -310,6 +346,8 @@ def set_changed_path_list(sbox, revision
   """ Replace the changed paths list in the revision file REVISION in SBOX
       with the text CHANGES."""
 
+  idx = None
+
   # read full file
   fp = open(fsfs_file(sbox.repo_dir, 'revs', str(revision)), 'r+b')
   contents = fp.read()
@@ -331,8 +369,11 @@ def set_changed_path_list(sbox, revision
     l2p_offset = long(footer.split(' ')[0])
     p2l_offset = long(footer.split(' ')[1])
 
+    idx = FSFS_Index(sbox, revision)
+    (offset, item_len, item_type) = idx.get_item(1)
+
     # split file contents
-    body_len = read_l2p(contents[l2p_offset:], 1)
+    body_len = offset
     indexes = contents[l2p_offset:length - footer_length - 1]
 
     # construct new footer, include indexes as are
@@ -351,6 +392,9 @@ def set_changed_path_list(sbox, revision
   fp.truncate()
   fp.close()
 
+  if repo_format(sbox) >= 7:
+    idx.modify_item(1, offset, len(changes) + 1)
+
 ######################################################################
 # Tests
 
@@ -2186,6 +2230,8 @@ def verify_invalid_path_changes(sbox):
                                            ".*r18: E160013:.*"])
   if (svntest.main.fs_has_rep_sharing()):
     exp_out.insert(0, ".*Verifying.*metadata.*")
+    if svntest.main.is_fs_log_addressing():
+      exp_out.insert(1, ".*Verifying.*metadata.*")
 
   exp_err = svntest.verify.RegexListOutput(["svnadmin: E160020:.*",
                                             "svnadmin: E145001:.*",
@@ -2199,19 +2245,16 @@ def verify_invalid_path_changes(sbox):
   exit_code, output, errput = svntest.main.run_svnadmin("verify",
                                                         sbox.repo_dir)
 
-  if svntest.main.is_fs_log_addressing():
-    exp_out = svntest.verify.RegexListOutput([])
-    exp_err = svntest.verify.RegexListOutput(["svnadmin: E160058:.*",
-                                              "svnadmin: E165011:.*"], False)
-  else:
-    exp_out = svntest.verify.RegexListOutput([".*Verified revision 0.",
-                                              ".*Verified revision 1.",
-                                              ".*Error verifying revision 2."])
-    exp_err = svntest.verify.RegexListOutput(["svnadmin: E160020:.*",
-                                              "svnadmin: E165011:.*"], False)
+  exp_out = svntest.verify.RegexListOutput([".*Verified revision 0.",
+                                            ".*Verified revision 1.",
+                                            ".*Error verifying revision 2."])
+  exp_err = svntest.verify.RegexListOutput(["svnadmin: E160020:.*",
+                                            "svnadmin: E165011:.*"], False)
 
   if (svntest.main.fs_has_rep_sharing()):
     exp_out.insert(0, ".*Verifying.*metadata.*")
+    if svntest.main.is_fs_log_addressing():
+      exp_out.insert(1, ".*Verifying.*metadata.*")
   if svntest.verify.verify_outputs("Unexpected error while running 'svnadmin verify'.",
                                    output, errput, exp_out, exp_err):
     raise svntest.Failure

Modified: subversion/trunk/subversion/tests/cmdline/svntest/main.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/main.py?rev=1606743&r1=1606742&r2=1606743&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/main.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/main.py Mon Jun 30 13:57:52 2014
@@ -171,6 +171,14 @@ svnauthz_validate_binary = os.path.abspa
     '../../../tools/server-side/svnauthz-validate' + _exe
 )
 
+######################################################################
+# The location of svnfsfs binary, relative to the only scripts that
+# import this file right now (they live in ../).
+# Use --tools to overide these defaults.
+svnfsfs_binary = os.path.abspath(
+    '../../../tools/server-side/svnfsfs/svnfsfs' + _exe
+)
+
 # Location to the pristine repository, will be calculated from test_area_url
 # when we know what the user specified for --url.
 pristine_greek_repos_url = None
@@ -759,6 +767,11 @@ def run_svnauthz_validate(*varargs):
   stderr as list of lines (including line terminators)."""
   return run_command(svnauthz_validate_binary, 1, False, *varargs)
 
+def run_svnfsfs(*varargs):
+  """Run svnfsfs with VARARGS, returns exit code as int; stdout, stderr
+  as list of lines (including line terminators)."""
+  return run_command(svnfsfs_binary, 1, False, *varargs)
+
 def run_lock_helper(repo, path, user, seconds):
   """Run lock-helper to lock path in repo by username for seconds"""
 



Mime
View raw message