Mercurial > hg
annotate contrib/python-zstandard/tests/test_data_structures_fuzzing.py @ 47859:155a2ec8a9dc
merge with stable
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 22 Aug 2021 16:32:06 -0400 |
parents | 5e84a96d865b |
children |
rev | line source |
---|---|
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 import io |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 import os |
37495
b1fb341d8a61
zstandard: vendor python-zstandard 0.9.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31796
diff
changeset
|
3 import sys |
b1fb341d8a61
zstandard: vendor python-zstandard 0.9.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31796
diff
changeset
|
4 import unittest |
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 try: |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 import hypothesis |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 import hypothesis.strategies as strategies |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 except ImportError: |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
10 raise unittest.SkipTest("hypothesis not available") |
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 |
37495
b1fb341d8a61
zstandard: vendor python-zstandard 0.9.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31796
diff
changeset
|
12 import zstandard as zstd |
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 from .common import ( |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 make_cffi, |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
16 TestCase, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
17 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
18 |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
19 |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
20 s_windowlog = strategies.integers( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
21 min_value=zstd.WINDOWLOG_MIN, max_value=zstd.WINDOWLOG_MAX |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
22 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
23 s_chainlog = strategies.integers( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
24 min_value=zstd.CHAINLOG_MIN, max_value=zstd.CHAINLOG_MAX |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
25 ) |
44147
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
26 s_hashlog = strategies.integers( |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
27 min_value=zstd.HASHLOG_MIN, max_value=zstd.HASHLOG_MAX |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
28 ) |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
29 s_searchlog = strategies.integers( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
30 min_value=zstd.SEARCHLOG_MIN, max_value=zstd.SEARCHLOG_MAX |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
31 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
32 s_minmatch = strategies.integers( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
33 min_value=zstd.MINMATCH_MIN, max_value=zstd.MINMATCH_MAX |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
34 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
35 s_targetlength = strategies.integers( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
36 min_value=zstd.TARGETLENGTH_MIN, max_value=zstd.TARGETLENGTH_MAX |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
37 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
38 s_strategy = strategies.sampled_from( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
39 ( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
40 zstd.STRATEGY_FAST, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
41 zstd.STRATEGY_DFAST, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
42 zstd.STRATEGY_GREEDY, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
43 zstd.STRATEGY_LAZY, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
44 zstd.STRATEGY_LAZY2, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
45 zstd.STRATEGY_BTLAZY2, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
46 zstd.STRATEGY_BTOPT, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
47 zstd.STRATEGY_BTULTRA, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
48 zstd.STRATEGY_BTULTRA2, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
49 ) |
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 ) |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
53 @make_cffi |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
54 @unittest.skipUnless("ZSTD_SLOW_TESTS" in os.environ, "ZSTD_SLOW_TESTS not set") |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
55 class TestCompressionParametersHypothesis(TestCase): |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
56 @hypothesis.given( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
57 s_windowlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
58 s_chainlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
59 s_hashlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
60 s_searchlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
61 s_minmatch, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
62 s_targetlength, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
63 s_strategy, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
64 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
65 def test_valid_init( |
44147
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
66 self, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
67 windowlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
68 chainlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
69 hashlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
70 searchlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
71 minmatch, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
72 targetlength, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
73 strategy, |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
74 ): |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
75 zstd.ZstdCompressionParameters( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
76 window_log=windowlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
77 chain_log=chainlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
78 hash_log=hashlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
79 search_log=searchlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
80 min_match=minmatch, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
81 target_length=targetlength, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
82 strategy=strategy, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
83 ) |
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
85 @hypothesis.given( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
86 s_windowlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
87 s_chainlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
88 s_hashlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
89 s_searchlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
90 s_minmatch, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
91 s_targetlength, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
92 s_strategy, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
93 ) |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
94 def test_estimated_compression_context_size( |
44147
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
95 self, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
96 windowlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
97 chainlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
98 hashlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
99 searchlog, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
100 minmatch, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
101 targetlength, |
5e84a96d865b
python-zstandard: blacken at 80 characters
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43994
diff
changeset
|
102 strategy, |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
103 ): |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
104 if minmatch == zstd.MINMATCH_MIN and strategy in ( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
105 zstd.STRATEGY_FAST, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
106 zstd.STRATEGY_GREEDY, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
107 ): |
42070
675775c33ab6
zstandard: vendor python-zstandard 0.11
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40121
diff
changeset
|
108 minmatch += 1 |
675775c33ab6
zstandard: vendor python-zstandard 0.11
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40121
diff
changeset
|
109 elif minmatch == zstd.MINMATCH_MAX and strategy != zstd.STRATEGY_FAST: |
675775c33ab6
zstandard: vendor python-zstandard 0.11
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40121
diff
changeset
|
110 minmatch -= 1 |
31796
e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 |
43994
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
112 p = zstd.ZstdCompressionParameters( |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
113 window_log=windowlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
114 chain_log=chainlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
115 hash_log=hashlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
116 search_log=searchlog, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
117 min_match=minmatch, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
118 target_length=targetlength, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
119 strategy=strategy, |
de7838053207
zstandard: vendor python-zstandard 0.13.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42070
diff
changeset
|
120 ) |
37495
b1fb341d8a61
zstandard: vendor python-zstandard 0.9.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31796
diff
changeset
|
121 size = p.estimated_compression_context_size() |