##// END OF EJS Templates
test: deal with changed error message on python 3.10...
Julien Cristau -
r49928:34cdad07 default
parent child Browse files
Show More
@@ -1,220 +1,220 b''
1 revlog.parseindex must be able to parse the index file even if
1 revlog.parseindex must be able to parse the index file even if
2 an index entry is split between two 64k blocks. The ideal test
2 an index entry is split between two 64k blocks. The ideal test
3 would be to create an index file with inline data where
3 would be to create an index file with inline data where
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
5 the size of an index entry) and with an index entry starting right
5 the size of an index entry) and with an index entry starting right
6 before the 64k block boundary, and try to read it.
6 before the 64k block boundary, and try to read it.
7 We approximate that by reducing the read buffer to 1 byte.
7 We approximate that by reducing the read buffer to 1 byte.
8
8
9 $ hg init a
9 $ hg init a
10 $ cd a
10 $ cd a
11 $ echo abc > foo
11 $ echo abc > foo
12 $ hg add foo
12 $ hg add foo
13 $ hg commit -m 'add foo'
13 $ hg commit -m 'add foo'
14 $ echo >> foo
14 $ echo >> foo
15 $ hg commit -m 'change foo'
15 $ hg commit -m 'change foo'
16 $ hg log -r 0:
16 $ hg log -r 0:
17 changeset: 0:7c31755bf9b5
17 changeset: 0:7c31755bf9b5
18 user: test
18 user: test
19 date: Thu Jan 01 00:00:00 1970 +0000
19 date: Thu Jan 01 00:00:00 1970 +0000
20 summary: add foo
20 summary: add foo
21
21
22 changeset: 1:26333235a41c
22 changeset: 1:26333235a41c
23 tag: tip
23 tag: tip
24 user: test
24 user: test
25 date: Thu Jan 01 00:00:00 1970 +0000
25 date: Thu Jan 01 00:00:00 1970 +0000
26 summary: change foo
26 summary: change foo
27
27
28 $ cat >> test.py << EOF
28 $ cat >> test.py << EOF
29 > from mercurial import changelog, node, pycompat, vfs
29 > from mercurial import changelog, node, pycompat, vfs
30 >
30 >
31 > class singlebyteread(object):
31 > class singlebyteread(object):
32 > def __init__(self, real):
32 > def __init__(self, real):
33 > self.real = real
33 > self.real = real
34 >
34 >
35 > def read(self, size=-1):
35 > def read(self, size=-1):
36 > if size == 65536:
36 > if size == 65536:
37 > size = 1
37 > size = 1
38 > return self.real.read(size)
38 > return self.real.read(size)
39 >
39 >
40 > def __getattr__(self, key):
40 > def __getattr__(self, key):
41 > return getattr(self.real, key)
41 > return getattr(self.real, key)
42 >
42 >
43 > def __enter__(self):
43 > def __enter__(self):
44 > self.real.__enter__()
44 > self.real.__enter__()
45 > return self
45 > return self
46 >
46 >
47 > def __exit__(self, *args, **kwargs):
47 > def __exit__(self, *args, **kwargs):
48 > return self.real.__exit__(*args, **kwargs)
48 > return self.real.__exit__(*args, **kwargs)
49 >
49 >
50 > def opener(*args):
50 > def opener(*args):
51 > o = vfs.vfs(*args)
51 > o = vfs.vfs(*args)
52 > def wrapper(*a, **kwargs):
52 > def wrapper(*a, **kwargs):
53 > f = o(*a, **kwargs)
53 > f = o(*a, **kwargs)
54 > return singlebyteread(f)
54 > return singlebyteread(f)
55 > wrapper.options = o.options
55 > wrapper.options = o.options
56 > return wrapper
56 > return wrapper
57 >
57 >
58 > cl = changelog.changelog(opener(b'.hg/store'))
58 > cl = changelog.changelog(opener(b'.hg/store'))
59 > print(len(cl), 'revisions:')
59 > print(len(cl), 'revisions:')
60 > for r in cl:
60 > for r in cl:
61 > print(pycompat.sysstr(node.short(cl.node(r))))
61 > print(pycompat.sysstr(node.short(cl.node(r))))
62 > EOF
62 > EOF
63 $ "$PYTHON" test.py
63 $ "$PYTHON" test.py
64 2 revisions:
64 2 revisions:
65 7c31755bf9b5
65 7c31755bf9b5
66 26333235a41c
66 26333235a41c
67
67
68 $ cd ..
68 $ cd ..
69
69
70 #if no-pure
70 #if no-pure
71
71
72 Test SEGV caused by bad revision passed to reachableroots() (issue4775):
72 Test SEGV caused by bad revision passed to reachableroots() (issue4775):
73
73
74 $ cd a
74 $ cd a
75
75
76 $ "$PYTHON" <<EOF
76 $ "$PYTHON" <<EOF
77 > from mercurial import changelog, vfs
77 > from mercurial import changelog, vfs
78 > cl = changelog.changelog(vfs.vfs(b'.hg/store'))
78 > cl = changelog.changelog(vfs.vfs(b'.hg/store'))
79 > print('good heads:')
79 > print('good heads:')
80 > for head in [0, len(cl) - 1, -1]:
80 > for head in [0, len(cl) - 1, -1]:
81 > print('%s: %r' % (head, cl.reachableroots(0, [head], [0])))
81 > print('%s: %r' % (head, cl.reachableroots(0, [head], [0])))
82 > print('bad heads:')
82 > print('bad heads:')
83 > for head in [len(cl), 10000, -2, -10000, None]:
83 > for head in [len(cl), 10000, -2, -10000, None]:
84 > print('%s:' % head, end=' ')
84 > print('%s:' % head, end=' ')
85 > try:
85 > try:
86 > cl.reachableroots(0, [head], [0])
86 > cl.reachableroots(0, [head], [0])
87 > print('uncaught buffer overflow?')
87 > print('uncaught buffer overflow?')
88 > except (IndexError, TypeError) as inst:
88 > except (IndexError, TypeError) as inst:
89 > print(inst)
89 > print(inst)
90 > print('good roots:')
90 > print('good roots:')
91 > for root in [0, len(cl) - 1, -1]:
91 > for root in [0, len(cl) - 1, -1]:
92 > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
92 > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
93 > print('out-of-range roots are ignored:')
93 > print('out-of-range roots are ignored:')
94 > for root in [len(cl), 10000, -2, -10000]:
94 > for root in [len(cl), 10000, -2, -10000]:
95 > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
95 > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
96 > print('bad roots:')
96 > print('bad roots:')
97 > for root in [None]:
97 > for root in [None]:
98 > print('%s:' % root, end=' ')
98 > print('%s:' % root, end=' ')
99 > try:
99 > try:
100 > cl.reachableroots(root, [len(cl) - 1], [root])
100 > cl.reachableroots(root, [len(cl) - 1], [root])
101 > print('uncaught error?')
101 > print('uncaught error?')
102 > except TypeError as inst:
102 > except TypeError as inst:
103 > print(inst)
103 > print(inst)
104 > EOF
104 > EOF
105 good heads:
105 good heads:
106 0: [0]
106 0: [0]
107 1: [0]
107 1: [0]
108 -1: []
108 -1: []
109 bad heads:
109 bad heads:
110 2: head out of range
110 2: head out of range
111 10000: head out of range
111 10000: head out of range
112 -2: head out of range
112 -2: head out of range
113 -10000: head out of range
113 -10000: head out of range
114 None: an integer is required( .got type NoneType.)? (re)
114 None: (an integer is required( .got type NoneType.)?|'NoneType' object cannot be interpreted as an integer) (re)
115 good roots:
115 good roots:
116 0: [0]
116 0: [0]
117 1: [1]
117 1: [1]
118 -1: [-1]
118 -1: [-1]
119 out-of-range roots are ignored:
119 out-of-range roots are ignored:
120 2: []
120 2: []
121 10000: []
121 10000: []
122 -2: []
122 -2: []
123 -10000: []
123 -10000: []
124 bad roots:
124 bad roots:
125 None: an integer is required( .got type NoneType.)? (re)
125 None: (an integer is required( .got type NoneType.)?|'NoneType' object cannot be interpreted as an integer) (re)
126
126
127 $ cd ..
127 $ cd ..
128
128
129 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
129 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
130
130
131 $ mkdir invalidparent
131 $ mkdir invalidparent
132 $ cd invalidparent
132 $ cd invalidparent
133
133
134 $ hg clone --pull -q --config phases.publish=False ../a limit --config format.sparse-revlog=no
134 $ hg clone --pull -q --config phases.publish=False ../a limit --config format.sparse-revlog=no
135 $ hg clone --pull -q --config phases.publish=False ../a neglimit --config format.sparse-revlog=no
135 $ hg clone --pull -q --config phases.publish=False ../a neglimit --config format.sparse-revlog=no
136 $ hg clone --pull -q --config phases.publish=False ../a segv --config format.sparse-revlog=no
136 $ hg clone --pull -q --config phases.publish=False ../a segv --config format.sparse-revlog=no
137 $ rm -R limit/.hg/cache neglimit/.hg/cache segv/.hg/cache
137 $ rm -R limit/.hg/cache neglimit/.hg/cache segv/.hg/cache
138
138
139 $ "$PYTHON" <<EOF
139 $ "$PYTHON" <<EOF
140 > data = open("limit/.hg/store/00changelog.i", "rb").read()
140 > data = open("limit/.hg/store/00changelog.i", "rb").read()
141 > poisons = [
141 > poisons = [
142 > (b'limit', b'\0\0\0\x02'),
142 > (b'limit', b'\0\0\0\x02'),
143 > (b'neglimit', b'\xff\xff\xff\xfe'),
143 > (b'neglimit', b'\xff\xff\xff\xfe'),
144 > (b'segv', b'\0\x01\0\0'),
144 > (b'segv', b'\0\x01\0\0'),
145 > ]
145 > ]
146 > for n, p in poisons:
146 > for n, p in poisons:
147 > # corrupt p1 at rev0 and p2 at rev1
147 > # corrupt p1 at rev0 and p2 at rev1
148 > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
148 > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
149 > open(n + b"/.hg/store/00changelog.i", "wb").write(d)
149 > open(n + b"/.hg/store/00changelog.i", "wb").write(d)
150 > EOF
150 > EOF
151
151
152 $ hg -R limit debugrevlogindex -f1 -c
152 $ hg -R limit debugrevlogindex -f1 -c
153 rev flag size link p1 p2 nodeid
153 rev flag size link p1 p2 nodeid
154 0 0000 62 0 2 -1 7c31755bf9b5
154 0 0000 62 0 2 -1 7c31755bf9b5
155 1 0000 65 1 0 2 26333235a41c
155 1 0000 65 1 0 2 26333235a41c
156
156
157 $ hg -R limit debugdeltachain -c
157 $ hg -R limit debugdeltachain -c
158 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
158 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
159 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
159 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
160 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
160 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
161
161
162 $ hg -R neglimit debugrevlogindex -f1 -c
162 $ hg -R neglimit debugrevlogindex -f1 -c
163 rev flag size link p1 p2 nodeid
163 rev flag size link p1 p2 nodeid
164 0 0000 62 0 -2 -1 7c31755bf9b5
164 0 0000 62 0 -2 -1 7c31755bf9b5
165 1 0000 65 1 0 -2 26333235a41c
165 1 0000 65 1 0 -2 26333235a41c
166
166
167 $ hg -R segv debugrevlogindex -f1 -c
167 $ hg -R segv debugrevlogindex -f1 -c
168 rev flag size link p1 p2 nodeid
168 rev flag size link p1 p2 nodeid
169 0 0000 62 0 65536 -1 7c31755bf9b5
169 0 0000 62 0 65536 -1 7c31755bf9b5
170 1 0000 65 1 0 65536 26333235a41c
170 1 0000 65 1 0 65536 26333235a41c
171
171
172 $ hg -R segv debugdeltachain -c
172 $ hg -R segv debugdeltachain -c
173 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
173 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
174 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
174 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
175 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
175 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
176
176
177 $ cat <<EOF > test.py
177 $ cat <<EOF > test.py
178 > import sys
178 > import sys
179 > from mercurial import changelog, pycompat, vfs
179 > from mercurial import changelog, pycompat, vfs
180 > cl = changelog.changelog(vfs.vfs(pycompat.fsencode(sys.argv[1])))
180 > cl = changelog.changelog(vfs.vfs(pycompat.fsencode(sys.argv[1])))
181 > n0, n1 = cl.node(0), cl.node(1)
181 > n0, n1 = cl.node(0), cl.node(1)
182 > ops = [
182 > ops = [
183 > ('reachableroots',
183 > ('reachableroots',
184 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
184 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
185 > ('compute_phases_map_sets', lambda: cl.computephases({1: {cl.node(0)}})),
185 > ('compute_phases_map_sets', lambda: cl.computephases({1: {cl.node(0)}})),
186 > ('index_headrevs', lambda: cl.headrevs()),
186 > ('index_headrevs', lambda: cl.headrevs()),
187 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
187 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
188 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
188 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
189 > ]
189 > ]
190 > for l, f in ops:
190 > for l, f in ops:
191 > print(l + ':', end=' ')
191 > print(l + ':', end=' ')
192 > try:
192 > try:
193 > f()
193 > f()
194 > print('uncaught buffer overflow?')
194 > print('uncaught buffer overflow?')
195 > except ValueError as inst:
195 > except ValueError as inst:
196 > print(inst)
196 > print(inst)
197 > EOF
197 > EOF
198
198
199 $ "$PYTHON" test.py limit/.hg/store
199 $ "$PYTHON" test.py limit/.hg/store
200 reachableroots: parent out of range
200 reachableroots: parent out of range
201 compute_phases_map_sets: parent out of range
201 compute_phases_map_sets: parent out of range
202 index_headrevs: parent out of range
202 index_headrevs: parent out of range
203 find_gca_candidates: parent out of range
203 find_gca_candidates: parent out of range
204 find_deepest: parent out of range
204 find_deepest: parent out of range
205 $ "$PYTHON" test.py neglimit/.hg/store
205 $ "$PYTHON" test.py neglimit/.hg/store
206 reachableroots: parent out of range
206 reachableroots: parent out of range
207 compute_phases_map_sets: parent out of range
207 compute_phases_map_sets: parent out of range
208 index_headrevs: parent out of range
208 index_headrevs: parent out of range
209 find_gca_candidates: parent out of range
209 find_gca_candidates: parent out of range
210 find_deepest: parent out of range
210 find_deepest: parent out of range
211 $ "$PYTHON" test.py segv/.hg/store
211 $ "$PYTHON" test.py segv/.hg/store
212 reachableroots: parent out of range
212 reachableroots: parent out of range
213 compute_phases_map_sets: parent out of range
213 compute_phases_map_sets: parent out of range
214 index_headrevs: parent out of range
214 index_headrevs: parent out of range
215 find_gca_candidates: parent out of range
215 find_gca_candidates: parent out of range
216 find_deepest: parent out of range
216 find_deepest: parent out of range
217
217
218 $ cd ..
218 $ cd ..
219
219
220 #endif
220 #endif
General Comments 0
You need to be logged in to leave comments. Login now