Skip to content

Commit 6562689

Browse files
readme
1 parent 796469d commit 6562689

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# `dscheck` — tool for testing concurrent OCaml programs
2+
--------------------------------------------------------
3+
4+
Experimental model checker for testing concurrent algorithms based on [Dynamic Partial-Order Reduction for Model Checking Software](https://users.soe.ucsc.edu/~cormac/papers/popl05.pdf). At the core, `dscheck` runs each test numerous times, exhaustively trying every single interleaving of atomic operations. User-provided assertions are run at the end of every execution.
5+
6+
7+
# Usage
8+
9+
Lockfree can be installed from `opam`: `opam install dscheck`. Sample usage on a [naive counter](tests/test_naive_counter.ml) is shown below.
10+
11+
```ocaml
12+
module Atomic = Dscheck.TracedAtomic
13+
(* tested implementation needs to use dscheck's atomic module *)
14+
15+
let test_counter () =
16+
let counter = Atomic.make 0 in
17+
let incr () = Atomic.set counter (Atomic.get counter + 1) in
18+
Atomic.spawn incr;
19+
Atomic.spawn incr;
20+
Atomic.final (fun () -> Atomic.check (fun () -> Atomic.get counter == 2))
21+
```
22+
23+
This is a classic example of a race condition with two threads trying to increment a counter without synchronisation. When the race occurs, one of the updates is lost. `dscheck` finds the interleaving that leads to that:
24+
25+
```
26+
Found assertion violation at run 12:
27+
Process 0: start
28+
Process 0: get 1
29+
Process 1: start
30+
Process 1: get 1
31+
Process 0: set 1
32+
Process 1: set 1
33+
Fatal error: exception File "src/tracedAtomic.ml", line 266, characters 6-12: Assertion failed
34+
```
35+
36+
37+
# Contributions
38+
39+
Contributions are appreciated! Please create issues/PRs to this repo.
40+

tests/dune

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(executable
2-
(name test_list)
3-
(modules test_list)
1+
(executables
2+
(names test_list test_naive_counter)
3+
(modules test_list test_naive_counter)
44
(libraries dscheck))

tests/test_naive_counter.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Atomic = Dscheck.TracedAtomic
2+
3+
let test_counter () =
4+
let counter = Atomic.make 0 in
5+
let incr () = Atomic.set counter (Atomic.get counter + 1) in
6+
Atomic.spawn incr;
7+
Atomic.spawn incr;
8+
Atomic.final (fun () -> Atomic.check (fun () -> Atomic.get counter == 2))
9+
10+
let () = Atomic.trace test_counter

0 commit comments

Comments
 (0)