Skip to content

Commit 5b984c4

Browse files
committed
Make maximum buffer size of TestCase configurable
This removes the global variable `BUFFER_SIZE` in favor of a new field in `CheckConfig`. Closes #17
1 parent 3264df2 commit 5b984c4

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/teststate.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,6 @@ function target!(ts::TestState)
261261
end
262262
end
263263

264-
"""
265-
BUFFER_SIZE
266-
267-
The default maximum buffer size to use for a test case.
268-
"""
269-
const BUFFER_SIZE = Ref((100 * 1024) % UInt)
270-
271264
"""
272265
generate(ts::TestState)
273266
@@ -288,7 +281,7 @@ function generate!(ts::TestState)
288281
(isnothing(ts.best_scoring) || # no score
289282
(ts.valid_test_cases <= ts.config.max_examples÷2))
290283
# +1, since we this test case is for the *next* call
291-
tc = TestCase(UInt64[], ts.rng, ts.calls+1, ts.config.max_examples, BUFFER_SIZE[])
284+
tc = TestCase(UInt64[], ts.rng, ts.calls+1, ts.config.max_examples, ts.config.buffer_size*8)
292285
test_function(ts, tc)
293286
end
294287
end

src/types.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ Fields:
7575
* `record`: Whether the result should be recorded in the parent testset, if there is one
7676
* `verbose`: Whether the printing should be verbose, i.e. print even if it's a `Pass`
7777
* `broken`: Whether the invocation is expected to fail
78+
* `buffer_size`: The default maximum buffer size to use for a test case. Defaults to `100_000`.
79+
80+
!!! warn "Buffer Size"
81+
At any one point, there may be more than one active buffer being worked on.
82+
You can try to increase this value when you encounter a lot of `Overrun`.
83+
Do not set this too large, or you're very likely to run out of memory; the default
84+
results in ~800kB worth of choices being possible, which should be plenty for most fuzzing
85+
tasks. It's generally unlikely that failures only occur with very large values here, and not with
86+
smaller ones.
7887
"""
7988
struct CheckConfig
8089
rng::Random.AbstractRNG
@@ -83,8 +92,9 @@ struct CheckConfig
8392
verbose::Bool
8493
broken::Bool
8594
db::ExampleDB
95+
buffer_size::UInt
8696
function CheckConfig(; rng::Random.AbstractRNG, max_examples::Int, record=true,
87-
verbose=false, broken=false, db::Union{Bool,ExampleDB}=true, kws...)
97+
verbose=false, broken=false, db::Union{Bool,ExampleDB}=true, buffer_size=100_000, kws...)
8898
!isempty(kws) && @warn "Got unsupported keyword arguments to CheckConfig! Ignoring:" Keywords=keys(kws)
8999
database::ExampleDB = if db isa Bool
90100
if db
@@ -100,7 +110,8 @@ struct CheckConfig
100110
record,
101111
verbose,
102112
broken,
103-
database)
113+
database,
114+
buffer_size)
104115
end
105116
end
106117

test/runtests.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,12 +811,19 @@ const verb = VERSION.major == 1 && VERSION.minor < 11
811811
end
812812

813813
@testset "Partially overwrite given Config" begin
814-
cntr = Ref(0)
815-
@check config=conf max_examples=100 function passConfFailTestFailTest(i=intgen)
816-
cntr[] += 1
814+
res = @check config=conf max_examples=100 function passConfFailTestFailTest(i=intgen)
817815
true
818816
end
819-
@test cntr[] == 100
817+
@test @something(res.final_state).calls == 100
818+
end
819+
820+
@testset "Buffer Size" begin
821+
vecgen = Data.Vectors(Data.Integers{UInt8}(); min_size=10)
822+
res = @check buffer_size=1 record=false function passConfFailTestFailTest(v=vecgen)
823+
isempty(v)
824+
end
825+
# all of these must have been rejected as an Overrun, so no call should ever take place
826+
@test iszero(@something(res.final_state).valid_test_cases)
820827
end
821828
end
822829

0 commit comments

Comments
 (0)