Skip to content

Commit 90cc0c2

Browse files
committed
Add simulation mode to model validation
Signed-off-by: Joshua Zhang <joshuazh@microsoft.com>
1 parent 4d429be commit 90cc0c2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

tla/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ The TLA+ spec defines the desired behaviors of the model. To validate the correc
7272
./validate-model.sh -s ./MCetcdraft.tla -c ./MCetcdraft.cfg
7373
```
7474

75+
You can also add `-m` option to run model checking in simulation mode, which will randomly walk in the state machine and is helpful for finding issues quickly.
76+
77+
```console
78+
./validate-model.sh -m -s ./MCetcdraft.tla -c ./MCetcdraft.cfg
79+
```
7580

7681
## Validate Collected Traces
7782
With above example trace logger, validate.sh can be used to validate traces parallelly.

tla/validate-model.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22

3-
WORKDIR="$(mktemp -d)"
3+
WORKDIR="${WORKDIR:-$(mktemp -d)}"
44
TOOLDIR="${WORKDIR}/tool"
55
STATEDIR="${WORKDIR}/state"
6-
FAILFAST=false
76
PARALLEL=$(nproc)
7+
SIMULATE=false
88

99
function show_usage {
10-
echo "usage: validate-model.sh -s <spec> -c <config>">&2
10+
echo "usage: validate-model.sh [-m] -s <spec> -c <config>">&2
1111
}
1212

1313
function install_tlaplus {
@@ -22,16 +22,23 @@ function validate {
2222
local config=${2}
2323
local tooldir=${3}
2424
local statedir=${4}
25+
local sim=${5:-false}
2526

2627
set -o pipefail
27-
java -XX:+UseParallelGC -cp ${tooldir}/tla2tools.jar:${tooldir}/CommunityModules-deps.jar tlc2.TLC -config "${config}" "${spec}" -lncheck final -metadir "${statedir}" -fpmem 0.9
28+
if [ "$sim" = true ]; then
29+
java -XX:+UseParallelGC -cp ${tooldir}/tla2tools.jar:${tooldir}/CommunityModules-deps.jar tlc2.TLC -config "${config}" "${spec}" -lncheck final -metadir "${statedir}" -fpmem 0.9 -workers auto -simulate
30+
else
31+
java -XX:+UseParallelGC -cp ${tooldir}/tla2tools.jar:${tooldir}/CommunityModules-deps.jar tlc2.TLC -config "${config}" "${spec}" -lncheck final -metadir "${statedir}" -fpmem 0.9 -workers auto
32+
fi
33+
2834
}
2935

30-
while getopts :hs:c:p: flag
36+
while getopts :hms:c: flag
3137
do
3238
case "${flag}" in
3339
s) SPEC=${OPTARG};;
3440
c) CONFIG=${OPTARG};;
41+
m) SIMULATE=true;;
3542
h|*) show_usage; exit 1;;
3643
esac
3744
done
@@ -47,5 +54,5 @@ echo "config: ${CONFIG}"
4754

4855
install_tlaplus
4956

50-
validate $SPEC $CONFIG $TOOLDIR $STATEDIR
57+
validate $SPEC $CONFIG $TOOLDIR $STATEDIR $SIMULATE
5158

0 commit comments

Comments
 (0)