Skip to content

Commit e8489d5

Browse files
committed
Add stress test using Xt
1 parent ed5ff97 commit e8489d5

File tree

1 file changed

+67
-23
lines changed

1 file changed

+67
-23
lines changed

test/kcas/test.ml

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -386,29 +386,68 @@ let test_get_seq_xt () =
386386
(* *)
387387

388388
let test_stress n nb_loop =
389-
let make_loc n =
390-
let rec loop n out =
391-
if n > 0 then loop (n - 1) (Loc.make 0 :: out) else out
392-
in
393-
loop n []
394-
and make_kcas0 r_l =
395-
let rec loop r_l out =
396-
match r_l with h :: t -> loop t (Op.make_cas h 0 1 :: out) | [] -> out
397-
in
398-
loop r_l []
399-
and make_kcas1 r_l =
400-
let rec loop r_l out =
401-
match r_l with h :: t -> loop t (Op.make_cas h 1 0 :: out) | [] -> out
402-
in
403-
loop r_l []
404-
in
405-
let r_l = make_loc n in
406-
let kcas0 = make_kcas0 r_l in
407-
let kcas1 = make_kcas1 r_l in
408-
for _ = 1 to nb_loop do
409-
assert (Op.atomically kcas0);
410-
assert (Op.atomically kcas1)
411-
done
389+
[ Mode.obstruction_free; Mode.lock_free ]
390+
|> List.iter @@ fun mode ->
391+
let make_loc n =
392+
let rec loop n out =
393+
if n > 0 then loop (n - 1) (Loc.make ~mode 0 :: out) else out
394+
in
395+
loop n []
396+
and make_kcas0 r_l =
397+
let rec loop r_l out =
398+
match r_l with
399+
| h :: t -> loop t (Op.make_cas h 0 1 :: out)
400+
| [] -> out
401+
in
402+
loop r_l []
403+
and make_kcas1 r_l =
404+
let rec loop r_l out =
405+
match r_l with
406+
| h :: t -> loop t (Op.make_cas h 1 0 :: out)
407+
| [] -> out
408+
in
409+
loop r_l []
410+
in
411+
let r_l = make_loc n in
412+
let kcas0 = make_kcas0 r_l in
413+
let kcas1 = make_kcas1 r_l in
414+
for _ = 1 to nb_loop do
415+
assert (Op.atomically kcas0);
416+
assert (Op.atomically kcas1)
417+
done
418+
419+
(* *)
420+
421+
let test_stress_xt n nb_loop =
422+
[ Mode.obstruction_free; Mode.lock_free ]
423+
|> List.iter @@ fun mode ->
424+
let make_loc n =
425+
let rec loop n out =
426+
if n > 0 then loop (n - 1) (Loc.make ~mode 0 :: out) else out
427+
in
428+
loop n []
429+
and make_kcas0 ~xt r_l =
430+
let rec loop ~xt r_l =
431+
match r_l with
432+
| h :: t -> Xt.compare_and_set ~xt h 0 1 && loop ~xt t
433+
| [] -> true
434+
in
435+
loop ~xt r_l
436+
and make_kcas1 ~xt r_l =
437+
let rec loop ~xt r_l =
438+
match r_l with
439+
| h :: t -> Xt.compare_and_set ~xt h 1 0 && loop ~xt t
440+
| [] -> true
441+
in
442+
loop ~xt r_l
443+
in
444+
let r_l = make_loc n in
445+
let kcas0 ~xt = make_kcas0 ~xt r_l in
446+
let kcas1 ~xt = make_kcas1 ~xt r_l in
447+
for _ = 1 to nb_loop do
448+
assert (Xt.commit { tx = kcas0 });
449+
assert (Xt.commit { tx = kcas1 })
450+
done
412451

413452
(* *)
414453

@@ -840,6 +879,11 @@ let () =
840879
Alcotest.test_case "" `Quick (fun () ->
841880
test_stress (10 * Util.iter_factor) 1_0);
842881
] );
882+
( "stress xt",
883+
[
884+
Alcotest.test_case "" `Quick (fun () ->
885+
test_stress_xt (10 * Util.iter_factor) 1_0);
886+
] );
843887
("presort", [ Alcotest.test_case "" `Quick test_presort ]);
844888
( "is_in_log",
845889
[ Alcotest.test_case "" `Quick test_presort_and_is_in_log_xt ] );

0 commit comments

Comments
 (0)