File: test_data_structures_fuzzing.py

package info (click to toggle)
mercurial 5.6.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 38,792 kB
  • sloc: python: 196,559; ansic: 45,504; tcl: 3,715; lisp: 1,483; sh: 1,475; cpp: 864; javascript: 649; makefile: 581; xml: 36; sql: 30
file content (121 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import io
import os
import sys
import unittest

try:
    import hypothesis
    import hypothesis.strategies as strategies
except ImportError:
    raise unittest.SkipTest("hypothesis not available")

import zstandard as zstd

from .common import (
    make_cffi,
    TestCase,
)


s_windowlog = strategies.integers(
    min_value=zstd.WINDOWLOG_MIN, max_value=zstd.WINDOWLOG_MAX
)
s_chainlog = strategies.integers(
    min_value=zstd.CHAINLOG_MIN, max_value=zstd.CHAINLOG_MAX
)
s_hashlog = strategies.integers(
    min_value=zstd.HASHLOG_MIN, max_value=zstd.HASHLOG_MAX
)
s_searchlog = strategies.integers(
    min_value=zstd.SEARCHLOG_MIN, max_value=zstd.SEARCHLOG_MAX
)
s_minmatch = strategies.integers(
    min_value=zstd.MINMATCH_MIN, max_value=zstd.MINMATCH_MAX
)
s_targetlength = strategies.integers(
    min_value=zstd.TARGETLENGTH_MIN, max_value=zstd.TARGETLENGTH_MAX
)
s_strategy = strategies.sampled_from(
    (
        zstd.STRATEGY_FAST,
        zstd.STRATEGY_DFAST,
        zstd.STRATEGY_GREEDY,
        zstd.STRATEGY_LAZY,
        zstd.STRATEGY_LAZY2,
        zstd.STRATEGY_BTLAZY2,
        zstd.STRATEGY_BTOPT,
        zstd.STRATEGY_BTULTRA,
        zstd.STRATEGY_BTULTRA2,
    )
)


@make_cffi
@unittest.skipUnless("ZSTD_SLOW_TESTS" in os.environ, "ZSTD_SLOW_TESTS not set")
class TestCompressionParametersHypothesis(TestCase):
    @hypothesis.given(
        s_windowlog,
        s_chainlog,
        s_hashlog,
        s_searchlog,
        s_minmatch,
        s_targetlength,
        s_strategy,
    )
    def test_valid_init(
        self,
        windowlog,
        chainlog,
        hashlog,
        searchlog,
        minmatch,
        targetlength,
        strategy,
    ):
        zstd.ZstdCompressionParameters(
            window_log=windowlog,
            chain_log=chainlog,
            hash_log=hashlog,
            search_log=searchlog,
            min_match=minmatch,
            target_length=targetlength,
            strategy=strategy,
        )

    @hypothesis.given(
        s_windowlog,
        s_chainlog,
        s_hashlog,
        s_searchlog,
        s_minmatch,
        s_targetlength,
        s_strategy,
    )
    def test_estimated_compression_context_size(
        self,
        windowlog,
        chainlog,
        hashlog,
        searchlog,
        minmatch,
        targetlength,
        strategy,
    ):
        if minmatch == zstd.MINMATCH_MIN and strategy in (
            zstd.STRATEGY_FAST,
            zstd.STRATEGY_GREEDY,
        ):
            minmatch += 1
        elif minmatch == zstd.MINMATCH_MAX and strategy != zstd.STRATEGY_FAST:
            minmatch -= 1

        p = zstd.ZstdCompressionParameters(
            window_log=windowlog,
            chain_log=chainlog,
            hash_log=hashlog,
            search_log=searchlog,
            min_match=minmatch,
            target_length=targetlength,
            strategy=strategy,
        )
        size = p.estimated_compression_context_size()