multicoretests icon indicating copy to clipboard operation
multicoretests copied to clipboard

Refine Out_channel string/bytes generator

Open jmid opened this issue 1 year ago • 1 comments

As part of carving a reproducer for #444, I realized that its string and bytes generators could be refined to have a bigger chance of producing strings stressing the channel boundary logic.

This quick little PR attempts such a refinement. It is based on a size_gen generator that produces numbers around powers of 2:

let size_gen =
      Gen.(map2 (fun pos size_adj ->
                   let res = 1 lsl (pos-1) in
                   if size_adj < res then res-size_adj else res) (int_bound 18) (int_bound 10));;
val size_gen : int QCheck.Gen.t = <fun>
Gen.generate ~n:10 size_gen;;
- : int list = [65531; 16378; 65535; 128; 8185; 0; 249; 4; 59; 28]
Gen.generate ~n:10 size_gen;;
- : int list = [65531; 126; 1; 512; 131066; 13; 252; 4087; 16380; 120]
Gen.generate ~n:10 size_gen;;
- : int list = [0; 65533; 15; 8190; 4089; 4094; 8; 65528; 2044; 65530]

jmid avatar Nov 01 '24 15:11 jmid