;; Fault injection into the existing executor, in a disposable fresh process.
;; These reports are controls, never additional corpus results.
(require :asdf)
(assert (string= "2.5.4" (lisp-implementation-version)))
(setf *compile-verbose* nil *load-verbose* nil)
(asdf:load-asd (merge-pathnames "../../topic-maps.asd" *load-truename*))
(asdf:load-system "topic-maps/xtm/tests")
(let ((mode (uiop:getenv "TOPIC_MAPS_21B_FAULT")))
(if (string= mode "mismatch")
(let ((original (symbol-function 'topic-maps.cxtm:canonicalize-octets)))
(setf (symbol-function 'topic-maps.cxtm:canonicalize-octets)
(lambda (&rest args)
(let ((actual (copy-seq (apply original args))))
(setf (aref actual 0) (logxor 1 (aref actual 0))) actual))))
(let* ((original (symbol-function 'topic-maps.xtm:deserialize-octets))
(source (cond ((string= mode "xml") "")
((string= mode "xtm") (topic-maps.xtm.tests::document ""))
((string= mode "tmdm") (topic-maps.xtm.tests::document ""))
((string= mode "unsupported") (topic-maps.xtm.tests::document "N"))
(t (error "Unknown fault control ~S" mode)))))
(setf (symbol-function 'topic-maps.xtm:deserialize-octets)
(lambda (bytes &rest args) (declare (ignore bytes))
(apply original (topic-maps.xtm.tests::bytes source) args)))))
(asdf:test-system "topic-maps/xtm"))
(error "Fault control unexpectedly completed without ASDF failure.")