invoke spin from racket

This commit is contained in:
Sam Caldwell 2021-01-06 11:19:42 -05:00
parent 5a5c651321
commit d0f00779cd
1 changed files with 26 additions and 0 deletions

View File

@ -4,6 +4,7 @@
(require "proto.rkt") (require "proto.rkt")
(require "ltl.rkt") (require "ltl.rkt")
(require racket/runtime-path)
(module+ test (module+ test
(require rackunit) (require rackunit)
@ -573,6 +574,31 @@
(indent) (displayln "true")) (indent) (displayln "true"))
(indent) (displayln ")")))) (indent) (displayln ")"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Invoking Spin
(define-runtime-path RUN-SPIN.EXE "run-spin.sh")
;; SpinThang String -> Bool
(define (run-spin spin [spec-name "spec"])
(define tmp (make-temporary-file "typed-syndicate-spin~a.pml"))
(gen-spin/to-file spin tmp)
(define out (with-output-to-string
(thunk (system* RUN-SPIN.EXE tmp spec-name))))
(delete-file tmp)
(analyze-spin-output out))
(define SPIN-REPORT-RX #px"(?m:^State-vector \\d+ byte, depth reached \\d+, errors: (\\d+)$)")
;; String -> Bool
;; True if the model satisfies the spec, false otherwise
(define (analyze-spin-output out)
(define rxmatch (regexp-match SPIN-REPORT-RX out))
(unless rxmatch
(error 'analyze-spin-output "unable to parse spin output"))
(define num-errors (string->number (second rxmatch)))
(zero? num-errors))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Misc Utils ;; Misc Utils