tests/test-revlog-raw.py
author Boris Feld <boris.feld@octobus.net>
Thu, 20 Dec 2018 12:17:15 +0100
changeset 41037 cca12a31ede5
parent 39260 0a5b20c107a6
child 41038 15f78383d3c8
permissions -rw-r--r--
revlog: add some direct testing of the slicing logic This test check slicing backed by an actual revlog. It will test the C version of slicing (if the test are run with the C extensions).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     1
# test revlog interaction about raw data (flagprocessor)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     2
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     3
from __future__ import absolute_import, print_function
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     4
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     5
import sys
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     6
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     7
from mercurial import (
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
    encoding,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
    node,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
    revlog,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    11
    transaction,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    12
    vfs,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    14
41037
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
    15
from mercurial.revlogutils import (
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
    16
    deltas,
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
    17
)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
    18
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    19
# TESTTMP is optional. This makes it convenient to run without run-tests.py
37940
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
    20
tvfs = vfs.vfs(encoding.environ.get(b'TESTTMP', b'/tmp'))
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    21
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    22
# Enable generaldelta otherwise revlog won't use delta as expected by the test
41037
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
    23
tvfs.options = {b'generaldelta': True, b'revlogv1': True,
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
    24
                b'sparse-revlog': True}
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    25
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    26
# The test wants to control whether to use delta explicitly, based on
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    27
# "storedeltachains".
39260
0a5b20c107a6 repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37940
diff changeset
    28
revlog.revlog._isgooddeltainfo = lambda self, d, textlen: self._storedeltachains
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    29
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    30
def abort(msg):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    31
    print('abort: %s' % msg)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    32
    # Return 0 so run-tests.py could compare the output.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    33
    sys.exit()
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    34
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    35
# Register a revlog processor for flag EXTSTORED.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    36
#
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    37
# It simply prepends a fixed header, and replaces '1' to 'i'. So it has
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    38
# insertion and replacement, and may be interesting to test revlog's line-based
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    39
# deltas.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    40
_extheader = b'E\n'
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    41
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    42
def readprocessor(self, rawtext):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    43
    # True: the returned text could be used to verify hash
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    44
    text = rawtext[len(_extheader):].replace(b'i', b'1')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    45
    return text, True
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    46
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    47
def writeprocessor(self, text):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    48
    # False: the returned rawtext shouldn't be used to verify hash
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    49
    rawtext = _extheader + text.replace(b'1', b'i')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    50
    return rawtext, False
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    51
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    52
def rawprocessor(self, rawtext):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    53
    # False: do not verify hash. Only the content returned by "readprocessor"
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    54
    # can be used to verify hash.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    55
    return False
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    56
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    57
revlog.addflagprocessor(revlog.REVIDX_EXTSTORED,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    58
                        (readprocessor, writeprocessor, rawprocessor))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    59
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    60
# Utilities about reading and appending revlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    61
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    62
def newtransaction():
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    63
    # A transaction is required to write revlogs
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    64
    report = lambda msg: None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    65
    return transaction.transaction(report, tvfs, {'plain': tvfs}, b'journal')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    66
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    67
def newrevlog(name=b'_testrevlog.i', recreate=False):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    68
    if recreate:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    69
        tvfs.tryunlink(name)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    70
    rlog = revlog.revlog(tvfs, name)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    71
    return rlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    72
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    73
def appendrev(rlog, text, tr, isext=False, isdelta=True):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    74
    '''Append a revision. If isext is True, set the EXTSTORED flag so flag
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    75
    processor will be used (and rawtext is different from text). If isdelta is
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    76
    True, force the revision to be a delta, otherwise it's full text.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    77
    '''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    78
    nextrev = len(rlog)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    79
    p1 = rlog.node(nextrev - 1)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    80
    p2 = node.nullid
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    81
    if isext:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    82
        flags = revlog.REVIDX_EXTSTORED
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    83
    else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    84
        flags = revlog.REVIDX_DEFAULT_FLAGS
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    85
    # Change storedeltachains temporarily, to override revlog's delta decision
39260
0a5b20c107a6 repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37940
diff changeset
    86
    rlog._storedeltachains = isdelta
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    87
    try:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    88
        rlog.addrevision(text, tr, nextrev, p1, p2, flags=flags)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    89
        return nextrev
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    90
    except Exception as ex:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    91
        abort('rev %d: failed to append: %s' % (nextrev, ex))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    92
    finally:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    93
        # Restore storedeltachains. It is always True, see revlog.__init__
39260
0a5b20c107a6 repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37940
diff changeset
    94
        rlog._storedeltachains = True
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    95
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    96
def addgroupcopy(rlog, tr, destname=b'_destrevlog.i', optimaldelta=True):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    97
    '''Copy revlog to destname using revlog.addgroup. Return the copied revlog.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    98
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
    99
    This emulates push or pull. They use changegroup. Changegroup requires
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   100
    repo to work. We don't have a repo, so a dummy changegroup is used.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   101
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   102
    If optimaldelta is True, use optimized delta parent, so the destination
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   103
    revlog could probably reuse it. Otherwise it builds sub-optimal delta, and
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   104
    the destination revlog needs more work to use it.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   105
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   106
    This exercises some revlog.addgroup (and revlog._addrevision(text=None))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   107
    code path, which is not covered by "appendrev" alone.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   108
    '''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   109
    class dummychangegroup(object):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   110
        @staticmethod
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   111
        def deltachunk(pnode):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   112
            pnode = pnode or node.nullid
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   113
            parentrev = rlog.rev(pnode)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   114
            r = parentrev + 1
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   115
            if r >= len(rlog):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   116
                return {}
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   117
            if optimaldelta:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   118
                deltaparent = parentrev
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   119
            else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   120
                # suboptimal deltaparent
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   121
                deltaparent = min(0, parentrev)
35840
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   122
            if not rlog.candelta(deltaparent, r):
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   123
                deltaparent = -1
37940
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   124
            return {b'node': rlog.node(r), b'p1': pnode, b'p2': node.nullid,
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   125
                    b'cs': rlog.node(rlog.linkrev(r)), b'flags': rlog.flags(r),
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   126
                    b'deltabase': rlog.node(deltaparent),
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   127
                    b'delta': rlog.revdiff(deltaparent, r)}
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   128
34298
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34160
diff changeset
   129
        def deltaiter(self):
34160
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33623
diff changeset
   130
            chain = None
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33623
diff changeset
   131
            for chunkdata in iter(lambda: self.deltachunk(chain), {}):
37940
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   132
                node = chunkdata[b'node']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   133
                p1 = chunkdata[b'p1']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   134
                p2 = chunkdata[b'p2']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   135
                cs = chunkdata[b'cs']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   136
                deltabase = chunkdata[b'deltabase']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   137
                delta = chunkdata[b'delta']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   138
                flags = chunkdata[b'flags']
34160
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33623
diff changeset
   139
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33623
diff changeset
   140
                chain = node
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33623
diff changeset
   141
34298
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34160
diff changeset
   142
                yield (node, p1, p2, cs, deltabase, delta, flags)
34160
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33623
diff changeset
   143
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   144
    def linkmap(lnode):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   145
        return rlog.rev(lnode)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   146
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   147
    dlog = newrevlog(destname, recreate=True)
34298
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34160
diff changeset
   148
    dummydeltas = dummychangegroup().deltaiter()
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34160
diff changeset
   149
    dlog.addgroup(dummydeltas, linkmap, tr)
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   150
    return dlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   151
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   152
def lowlevelcopy(rlog, tr, destname=b'_destrevlog.i'):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   153
    '''Like addgroupcopy, but use the low level revlog._addrevision directly.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   154
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   155
    It exercises some code paths that are hard to reach easily otherwise.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   156
    '''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   157
    dlog = newrevlog(destname, recreate=True)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   158
    for r in rlog:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   159
        p1 = rlog.node(r - 1)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   160
        p2 = node.nullid
35840
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   161
        if r == 0 or (rlog.flags(r) & revlog.REVIDX_EXTSTORED):
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   162
            text = rlog.revision(r, raw=True)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   163
            cachedelta = None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   164
        else:
35840
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   165
            # deltaparent cannot have EXTSTORED flag.
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   166
            deltaparent = max([-1] +
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   167
                              [p for p in range(r)
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   168
                               if rlog.flags(p) & revlog.REVIDX_EXTSTORED == 0])
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   169
            text = None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   170
            cachedelta = (deltaparent, rlog.revdiff(deltaparent, r))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   171
        flags = rlog.flags(r)
33623
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   172
        ifh = dfh = None
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   173
        try:
37940
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   174
            ifh = dlog.opener(dlog.indexfile, b'a+')
33623
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   175
            if not dlog._inline:
37940
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   176
                dfh = dlog.opener(dlog.datafile, b'a+')
33623
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   177
            dlog._addrevision(rlog.node(r), text, tr, r, p1, p2, flags,
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   178
                              cachedelta, ifh, dfh)
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   179
        finally:
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   180
            if dfh is not None:
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   181
                dfh.close()
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   182
            if ifh is not None:
6788e648efcf test-revlog-raw: close file handles explicitly (issue5644)
Yuya Nishihara <yuya@tcha.org>
parents: 31767
diff changeset
   183
                ifh.close()
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   184
    return dlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   185
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   186
# Utilities to generate revisions for testing
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   187
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   188
def genbits(n):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   189
    '''Given a number n, generate (2 ** (n * 2) + 1) numbers in range(2 ** n).
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   190
    i.e. the generated numbers have a width of n bits.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   191
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   192
    The combination of two adjacent numbers will cover all possible cases.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   193
    That is to say, given any x, y where both x, and y are in range(2 ** n),
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   194
    there is an x followed immediately by y in the generated sequence.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   195
    '''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   196
    m = 2 ** n
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   197
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   198
    # Gray Code. See https://en.wikipedia.org/wiki/Gray_code
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   199
    gray = lambda x: x ^ (x >> 1)
31766
8a0c47982ade test-revlog-raw: fix "genbits" implementation
Jun Wu <quark@fb.com>
parents: 31753
diff changeset
   200
    reversegray = dict((gray(i), i) for i in range(m))
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   201
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   202
    # Generate (n * 2) bit gray code, yield lower n bits as X, and look for
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   203
    # the next unused gray code where higher n bits equal to X.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   204
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   205
    # For gray codes whose higher bits are X, a[X] of them have been used.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   206
    a = [0] * m
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   207
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   208
    # Iterate from 0.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   209
    x = 0
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   210
    yield x
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   211
    for i in range(m * m):
31766
8a0c47982ade test-revlog-raw: fix "genbits" implementation
Jun Wu <quark@fb.com>
parents: 31753
diff changeset
   212
        x = reversegray[x]
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   213
        y = gray(a[x] + x * m) & (m - 1)
31766
8a0c47982ade test-revlog-raw: fix "genbits" implementation
Jun Wu <quark@fb.com>
parents: 31753
diff changeset
   214
        assert a[x] < m
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   215
        a[x] += 1
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   216
        x = y
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   217
        yield x
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   218
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   219
def gentext(rev):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   220
    '''Given a revision number, generate dummy text'''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   221
    return b''.join(b'%d\n' % j for j in range(-1, rev % 5))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   222
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   223
def writecases(rlog, tr):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   224
    '''Write some revisions interested to the test.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   225
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   226
    The test is interested in 3 properties of a revision:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   227
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   228
        - Is it a delta or a full text? (isdelta)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   229
          This is to catch some delta application issues.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   230
        - Does it have a flag of EXTSTORED? (isext)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   231
          This is to catch some flag processor issues. Especially when
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   232
          interacted with revlog deltas.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   233
        - Is its text empty? (isempty)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   234
          This is less important. It is intended to try to catch some careless
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   235
          checks like "if text" instead of "if text is None". Note: if flag
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   236
          processor is involved, raw text may be not empty.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   237
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   238
    Write 65 revisions. So that all combinations of the above flags for
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   239
    adjacent revisions are covered. That is to say,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   240
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   241
        len(set(
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   242
            (r.delta, r.ext, r.empty, (r+1).delta, (r+1).ext, (r+1).empty)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   243
            for r in range(len(rlog) - 1)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   244
           )) is 64.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   245
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   246
    Where "r.delta", "r.ext", and "r.empty" are booleans matching properties
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   247
    mentioned above.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   248
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   249
    Return expected [(text, rawtext)].
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   250
    '''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   251
    result = []
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   252
    for i, x in enumerate(genbits(3)):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   253
        isdelta, isext, isempty = bool(x & 1), bool(x & 2), bool(x & 4)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   254
        if isempty:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   255
            text = b''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   256
        else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   257
            text = gentext(i)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   258
        rev = appendrev(rlog, text, tr, isext=isext, isdelta=isdelta)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   259
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   260
        # Verify text, rawtext, and rawsize
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   261
        if isext:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   262
            rawtext = writeprocessor(None, text)[0]
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   263
        else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   264
            rawtext = text
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   265
        if rlog.rawsize(rev) != len(rawtext):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   266
            abort('rev %d: wrong rawsize' % rev)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   267
        if rlog.revision(rev, raw=False) != text:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   268
            abort('rev %d: wrong text' % rev)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   269
        if rlog.revision(rev, raw=True) != rawtext:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   270
            abort('rev %d: wrong rawtext' % rev)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   271
        result.append((text, rawtext))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   272
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   273
        # Verify flags like isdelta, isext work as expected
35840
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   274
        # isdelta can be overridden to False if this or p1 has isext set
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   275
        if bool(rlog.deltaparent(rev) > -1) and not isdelta:
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
   276
            abort('rev %d: isdelta is unexpected' % rev)
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   277
        if bool(rlog.flags(rev)) != isext:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   278
            abort('rev %d: isext is ineffective' % rev)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   279
    return result
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   280
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   281
# Main test and checking
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   282
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   283
def checkrevlog(rlog, expected):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   284
    '''Check if revlog has expected contents. expected is [(text, rawtext)]'''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   285
    # Test using different access orders. This could expose some issues
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   286
    # depending on revlog caching (see revlog._cache).
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   287
    for r0 in range(len(rlog) - 1):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   288
        r1 = r0 + 1
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   289
        for revorder in [[r0, r1], [r1, r0]]:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   290
            for raworder in [[True], [False], [True, False], [False, True]]:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   291
                nlog = newrevlog()
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   292
                for rev in revorder:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   293
                    for raw in raworder:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   294
                        t = nlog.revision(rev, raw=raw)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   295
                        if t != expected[rev][int(raw)]:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   296
                            abort('rev %d: corrupted %stext'
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   297
                                  % (rev, raw and 'raw' or ''))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   298
41037
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   299
slicingdata = [
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   300
    ([0, 1, 2, 3, 55, 56, 58, 59, 60],
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   301
     [[0, 1], [2], [58], [59, 60]],
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   302
     10),
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   303
    ([0, 1, 2, 3, 55, 56, 58, 59, 60],
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   304
     [[0, 1], [2], [58], [59, 60]],
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   305
     10),
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   306
    ([-1, 0, 1, 2, 3, 55, 56, 58, 59, 60],
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   307
     [[-1, 0, 1], [2], [58], [59, 60]],
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   308
     10),
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   309
]
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   310
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   311
def slicingtest(rlog):
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   312
    oldmin = rlog._srmingapsize
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   313
    try:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   314
        # the test revlog is small, we remove the floor under which we
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   315
        # slicing is diregarded.
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   316
        rlog._srmingapsize = 0
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   317
        for item in slicingdata:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   318
            chain, expected, target = item
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   319
            result = deltas.slicechunk(rlog, chain, targetsize=target)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   320
            result = list(result)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   321
            if result != expected:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   322
                print('slicing differ:')
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   323
                print('  chain: %s' % chain)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   324
                print('  target: %s' % target)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   325
                print('  expected: %s' % expected)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   326
                print('  result:   %s' % result)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   327
    finally:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   328
        rlog._srmingapsize = oldmin
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   329
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   330
def maintest():
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   331
    expected = rl = None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   332
    with newtransaction() as tr:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   333
        rl = newrevlog(recreate=True)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   334
        expected = writecases(rl, tr)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   335
        checkrevlog(rl, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   336
        print('local test passed')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   337
        # Copy via revlog.addgroup
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   338
        rl1 = addgroupcopy(rl, tr)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   339
        checkrevlog(rl1, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   340
        rl2 = addgroupcopy(rl, tr, optimaldelta=False)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   341
        checkrevlog(rl2, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   342
        print('addgroupcopy test passed')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   343
        # Copy via revlog.clone
37940
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 35840
diff changeset
   344
        rl3 = newrevlog(name=b'_destrevlog3.i', recreate=True)
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   345
        rl.clone(tr, rl3)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   346
        checkrevlog(rl3, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   347
        print('clone test passed')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   348
        # Copy via low-level revlog._addrevision
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   349
        rl4 = lowlevelcopy(rl, tr)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   350
        checkrevlog(rl4, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   351
        print('lowlevelcopy test passed')
41037
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   352
        slicingtest(rl)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39260
diff changeset
   353
        print('slicing test passed')
31753
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   354
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   355
try:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   356
    maintest()
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   357
except Exception as ex:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
   358
    abort('crashed: %s' % ex)