Skip to content

Commit 431970f

Browse files
authored
Merge pull request #546 from ocaml-multicore/lin-bytes-fixes
Lin bytes test fixes
2 parents 3a1d2d3 + 48099a0 commit 431970f

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- #540: Significantly increase the probability of context switching in `Lin_thread`
66
and `STM_thread` by utilizing `Gc.Memprof` callbacks. Avoid on 5.0-5.2
77
without `Gc.Memprof` support.
8+
- #546: Speed up `Lin`'s default `string` and `bytes` shrinkers.
89

910
## 0.7
1011

lib/lin.ml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,18 @@ let gen_deconstructible gen print eq = GenDeconstr (gen,print,eq)
159159

160160
let qcheck_nat64_small = QCheck.(map Int64.of_int small_nat)
161161

162-
let bytes_small_printable = QCheck.bytes_small_of QCheck.Gen.printable
162+
(* QCheck's string shrinker reduces each char repeatedly which is too excessive for Lin *)
163+
let shrink_char c = QCheck.(if c = 'a' then Iter.empty else Iter.return 'a')
164+
let shrink_string = QCheck.Shrink.string ~shrink:shrink_char
165+
let shrink_bytes = QCheck.Shrink.bytes ~shrink:shrink_char
166+
167+
let string = QCheck.(set_shrink shrink_string string)
168+
let string_small = QCheck.(set_shrink shrink_string small_string)
169+
let string_small_printable = QCheck.(set_shrink shrink_string small_printable_string)
170+
171+
let bytes = QCheck.(set_shrink shrink_bytes bytes)
172+
let bytes_small = QCheck.(set_shrink shrink_bytes bytes_small)
173+
let bytes_small_printable = QCheck.(set_shrink shrink_bytes (bytes_small_of Gen.printable))
163174

164175
let unit = GenDeconstr (QCheck.unit, QCheck.Print.unit, (=))
165176
let bool = GenDeconstr (QCheck.bool, QCheck.Print.bool, (=))
@@ -174,11 +185,11 @@ let int32 = GenDeconstr (QCheck.int32, Int32.to_string, Int3
174185
let int64 = GenDeconstr (QCheck.int64, Int64.to_string, Int64.equal)
175186
let nat64_small = GenDeconstr (qcheck_nat64_small, Int64.to_string, Int64.equal)
176187
let float = GenDeconstr (QCheck.float, QCheck.Print.float, Float.equal)
177-
let string = GenDeconstr (QCheck.string, QCheck.Print.string, String.equal)
178-
let string_small = GenDeconstr (QCheck.small_string, QCheck.Print.string, String.equal)
179-
let string_small_printable = GenDeconstr (QCheck.small_printable_string, QCheck.Print.string, String.equal)
180-
let bytes = GenDeconstr (QCheck.bytes, QCheck.Print.bytes, Bytes.equal)
181-
let bytes_small = GenDeconstr (QCheck.bytes_small, QCheck.Print.bytes, Bytes.equal)
188+
let string = GenDeconstr (string, QCheck.Print.string, String.equal)
189+
let string_small = GenDeconstr (string_small, QCheck.Print.string, String.equal)
190+
let string_small_printable = GenDeconstr (string_small_printable, QCheck.Print.string, String.equal)
191+
let bytes = GenDeconstr (bytes, QCheck.Print.bytes, Bytes.equal)
192+
let bytes_small = GenDeconstr (bytes_small, QCheck.Print.bytes, Bytes.equal)
182193
let bytes_small_printable = GenDeconstr (bytes_small_printable, QCheck.Print.bytes, Bytes.equal)
183194

184195
let option : type a c s. ?ratio:float -> (a, c, s, combinable) ty -> (a option, c, s, combinable) ty =

src/bytes/lin_tests.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module BConf = struct
66
let init () = Stdlib.Bytes.make 42 '0'
77
let cleanup _ = ()
88

9+
let bytes_to_seq b = List.to_seq (List.of_seq (Bytes.to_seq b)) (* eager version *)
910
open Lin
1011
let int,string = nat_small, string_small_printable
1112
let api = [
@@ -29,6 +30,7 @@ module BConf = struct
2930
val_ "Bytes.contains" Bytes.contains (t @-> char @-> returning_or_exc bool);
3031
val_ "Bytes.contains_from" Bytes.contains_from (t @-> int @-> char @-> returning_or_exc bool);
3132
val_ "Bytes.rcontains_from" Bytes.rcontains_from (t @-> int @-> char @-> returning_or_exc bool);
33+
val_ "Bytes.to_seq" bytes_to_seq (t @-> returning (seq char));
3234
(* UTF codecs and validations *)
3335
val_ "Bytes.is_valid_utf_8" Bytes.is_valid_utf_8 (t @-> returning bool);
3436
val_ "Bytes.is_valid_utf_16be" Bytes.is_valid_utf_16be (t @-> returning bool);
@@ -46,6 +48,6 @@ module BT_thread = Lin_thread.Make(BConf)
4648
;;
4749
QCheck_base_runner.run_tests_main [
4850
BT_domain.neg_lin_test ~count:5000 ~name:"Lin Bytes test with Domain";
49-
BT_thread.lin_test ~count:250 ~name:"Lin Bytes test with Thread";
51+
BT_thread.neg_lin_test ~count:5000 ~name:"Lin Bytes test with Thread";
5052
BT_domain.stress_test ~count:1000 ~name:"Lin Bytes stress test with Domain";
5153
]

0 commit comments

Comments
 (0)