Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_mi.py: 53%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12#!/usr/bin/python3
13# Copyright 2023 Google LLC
14#
15# Licensed under the Apache License, Version 2.0 (the "License");
16# you may not use this file except in compliance with the License.
17# You may obtain a copy of the License at
18#
19# http://www.apache.org/licenses/LICENSE-2.0
20#
21# Unless required by applicable law or agreed to in writing, software
22# distributed under the License is distributed on an "AS IS" BASIS,
23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24# See the License for the specific language governing permissions and
25# limitations under the License.
26"""Calls the APIs of more_itertools with random settings"""
27import sys
28import atheris
29import more_itertools
32def get_random_list(fdp, min_len=5, max_len=100):
33 return fdp.ConsumeIntList(fdp.ConsumeIntInRange(min_len, max_len), 4)
36def check_sliced(fdp):
37 seq2 = [x for x in fdp.ConsumeUnicodeNoSurrogates(1024)]
38 try:
39 l1 = list(more_itertools.sliced(seq2, 3, strict=fdp.ConsumeBool()))
40 except ValueError:
41 pass
44def check_windowed(fdp):
45 idxs = get_random_list(fdp)
46 try:
47 l2 = list(more_itertools.windowed(idxs, fdp.ConsumeIntInRange(1, 100)))
48 l2 = list(more_itertools.windowed(idxs, fdp.ConsumeIntInRange(-10, 100)))
49 except ValueError:
50 pass
53def check_distinct_combinations(fdp):
54 idxs = get_random_list(fdp)
55 try:
56 l3 = list(more_itertools.distinct_combinations(
57 idxs, fdp.ConsumeIntInRange(5, 10)))
58 l3 = list(more_itertools.distinct_combinations(
59 idxs, fdp.ConsumeIntInRange(-10, 10)))
60 except ValueError:
61 pass
64def check_substrings(fdp):
65 c3 = [''.join(s) for s in more_itertools.substrings(fdp.ConsumeUnicodeNoSurrogates(24))]
68def check_substrings_indexes(fdp):
69 l1 = get_random_list(fdp)
70 try:
71 list(more_itertools.substrings_indexes(l1))
72 except ValueError:
73 pass
76def check_locate(fdp):
77 l1 = get_random_list(fdp)
78 try:
79 list(more_itertools.locate(l1))
80 except ValueError:
81 pass
84def check_islice_extended(fdp):
85 l1 = get_random_list(fdp)
86 try:
87 list(more_itertools.islice_extended(l1, 3, 10))
88 except ValueError:
89 pass
92def check_interleave_evenly(fdp):
93 l1 = get_random_list(fdp)
94 l2 = get_random_list(fdp)
95 try:
96 list(more_itertools.interleave_evenly([l1, l2]))
97 except ValueError:
98 pass
101def check_collapse(fdp):
102 l1 = get_random_list(fdp)
103 try:
104 list(more_itertools.collapse(l1))
105 except ValueError:
106 pass
109def check_chunked(fdp):
110 l1 = get_random_list(fdp)
111 try:
112 list(more_itertools.chunked(l1, n=fdp.ConsumeIntInRange(-10, 100)))
113 except ValueError:
114 pass
117def check_intersperse(fdp):
118 l1 = get_random_list(fdp)
119 try:
120 list(more_itertools.intersperse('a', l1))
121 except ValueError:
122 pass
125def TestOneInput(data):
126 fdp = atheris.FuzzedDataProvider(data)
127 targets = [
128 check_sliced,
129 check_windowed,
130 check_distinct_combinations,
131 check_substrings,
132 check_interleave_evenly,
133 check_chunked,
134 check_intersperse,
135 check_substrings_indexes,
136 check_locate,
137 check_islice_extended,
138 ]
140 target = fdp.PickValueInList(targets)
141 target(fdp)
144def main():
145 atheris.instrument_all()
146 atheris.Setup(sys.argv, TestOneInput)
147 atheris.Fuzz()
150if __name__ == "__main__":
151 main()