-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The runtime reimplement the QCheckSTM.Sequential.Make functor to use new postcond function. It also implement how the failure message is printed and the append function for postcond.
- Loading branch information
Showing
23 changed files
with
225 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,24 @@ | |
ortac-core | ||
(ortac-qcheck-stm :with-test))) | ||
|
||
(package | ||
(name ortac-runtime-qcheck-stm) | ||
(synopsis "Runtime support library for Ortac/QCheck-STM-generated code") | ||
(description | ||
"\> The ortac-runtime-qcheck-stm library provides support for the code | ||
"\> generated by the Ortac/QCheck-STM plugin (provided by the | ||
"\> ortac-qcheck-stm package). | ||
"\> | ||
"\> Ortac (OCaml Runtime Assertion Checking) is a tool to turn | ||
"\> executable Gospel specifications into code to test they hold. | ||
) | ||
(authors "Nicolas Osborne <[email protected]>") | ||
(maintainers "Nicolas Osborne <[email protected]>") | ||
(depends | ||
(ocaml (>= 4.11.0)) | ||
qcheck-stm | ||
ortac-runtime)) | ||
|
||
(package | ||
(name ortac-examples) | ||
(synopsis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
synopsis: "Runtime support library for Ortac/QCheck-STM-generated code" | ||
description: """ | ||
The ortac-runtime-qcheck-stm library provides support for the code | ||
generated by the Ortac/QCheck-STM plugin (provided by the | ||
ortac-qcheck-stm package). | ||
|
||
Ortac (OCaml Runtime Assertion Checking) is a tool to turn | ||
executable Gospel specifications into code to test they hold. | ||
""" | ||
maintainer: ["Nicolas Osborne <[email protected]>"] | ||
authors: ["Nicolas Osborne <[email protected]>"] | ||
license: "MIT" | ||
homepage: "https://github.com/ocaml-gospel/ortac" | ||
bug-reports: "https://github.com/ocaml-gospel/ortac/issues" | ||
depends: [ | ||
"dune" {>= "3.8"} | ||
"ocaml" {>= "4.11.0"} | ||
"qcheck-stm" | ||
"ortac-runtime" | ||
"odoc" {with-doc} | ||
] | ||
build: [ | ||
["dune" "subst"] {dev} | ||
[ | ||
"dune" | ||
"build" | ||
"-p" | ||
name | ||
"-j" | ||
jobs | ||
"--promote-install-files=false" | ||
"@install" | ||
"@runtest" {with-test} | ||
"@doc" {with-doc} | ||
] | ||
["dune" "install" "-p" name "--create-install-files" name] | ||
] | ||
dev-repo: "git+https://github.com/ocaml-gospel/ortac.git" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(library | ||
(name ortac_runtime_qcheck_stm) | ||
(public_name ortac-runtime-qcheck-stm) | ||
(libraries | ||
qcheck-core | ||
qcheck-core.runner | ||
qcheck-stm.stm | ||
qcheck-stm.sequential | ||
qcheck-multicoretests-util | ||
ortac-runtime)) |
74 changes: 74 additions & 0 deletions
74
plugins/qcheck-stm/src/runtime/ortac_runtime_qcheck_stm.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
open STM | ||
include Ortac_runtime | ||
|
||
let ( ++ ) a b = | ||
match (a, b) with | ||
| None, None -> None | ||
| Some (_, _), None -> a | ||
| None, Some (_, _) -> b | ||
| Some (cmd0, terms0), Some (cmd1, terms1) -> | ||
assert (cmd0 = cmd1); | ||
Some (cmd0, terms0 @ terms1) | ||
|
||
module Make (Spec : Spec) = struct | ||
open QCheck | ||
module Internal = Internal.Make (Spec) [@alert "-internal"] | ||
|
||
let pp_trace ppf trace = | ||
let open Fmt in | ||
let pp_aux ppf (c, r) = pf ppf "%s : %s" (Spec.show_cmd c) (show_res r) in | ||
pf ppf "@[%a@]" (list ~sep:(any "@\n") pp_aux) trace | ||
|
||
let pp_terms ppf err = | ||
let open Fmt in | ||
let pp_aux ppf (term, l) = pf ppf "@[%a@\n @[%s@]@]@\n" pp_loc l term in | ||
pf ppf "%a" (list ~sep:(any "@\n") pp_aux) err | ||
|
||
let message trace cmd terms = | ||
Test.fail_reportf | ||
"Gospel specification violation in function %s\n\ | ||
@;\ | ||
\ @[%a@]@\n\ | ||
when executing the following sequence of operations:@\n\ | ||
@;\ | ||
\ @[%a@]@." cmd pp_terms terms pp_trace trace | ||
|
||
let rec check_disagree postcond s sut cs = | ||
match cs with | ||
| [] -> None | ||
| c :: cs -> ( | ||
let res = Spec.run c sut in | ||
(* This functor will be called after a modified postcond has been | ||
defined, returning a list of 3-plets containing the command, the | ||
term and the location *) | ||
match postcond c s res with | ||
| None -> ( | ||
let s' = Spec.next_state c s in | ||
match check_disagree postcond s' sut cs with | ||
| None -> None | ||
| Some (rest, cmd, terms) -> Some ((c, res) :: rest, cmd, terms)) | ||
| Some (cmd, terms) -> Some ([ (c, res) ], cmd, terms)) | ||
|
||
let agree_prop wrapped_init_state postcond cs = | ||
let _ = wrapped_init_state () in | ||
assume (Internal.cmds_ok Spec.init_state cs); | ||
let sut = Spec.init_sut () in | ||
(* reset system's state *) | ||
let res = | ||
try Ok (check_disagree postcond Spec.init_state sut cs) | ||
with exn -> Error exn | ||
in | ||
let () = Spec.cleanup sut in | ||
let res = match res with Ok res -> res | Error exn -> raise exn in | ||
match res with | ||
| None -> true | ||
| Some (trace, cmd, terms) -> message trace cmd terms | ||
(* Test.fail_reportf *) | ||
(* "%a@\n@[@, when executing this sequence of operations:@]@\n@\n%a@." *) | ||
(* pp_err err pp_trace trace *) | ||
|
||
let agree_test ~count ~name wrapped_init_state postcond = | ||
Test.make ~name ~count | ||
(Internal.arb_cmds Spec.init_state) | ||
(agree_prop wrapped_init_state postcond) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.