hsmt-0.1.0.0: test-common/HSMT/Benchmarks.hs
-- | The SMT-LIB benchmarks in @bench/smtlib@, shared by the test suite and
-- the benchmark program.
--
-- Each file states the expected answer of each check with
-- @(set-info :status ...)@ before it, as the SMT-LIB benchmark library
-- does; Z3 checks these annotations as well.
module HSMT.Benchmarks
( benchmarkDir
, benchmarkFiles
, expectedStatuses
, knownLimitations
, answerText
) where
import Control.Monad (filterM)
import Data.List (isSuffixOf, sort)
import Data.Text (Text)
import System.Directory (doesDirectoryExist, doesFileExist, listDirectory)
import System.FilePath (makeRelative, (</>))
import HSMT.SMT.Engine (EngineResult (..))
import HSMT.SMTLib.Parser (SExpr (..), parseSExprsPartial)
benchmarkDir :: FilePath
benchmarkDir = "bench" </> "smtlib"
-- | Every @.smt2@ file under 'benchmarkDir', relative to it, in order.
benchmarkFiles :: IO [FilePath]
benchmarkFiles = do
exists <- doesDirectoryExist benchmarkDir
if exists then sort . map (makeRelative benchmarkDir) <$> walk benchmarkDir else pure []
where
walk dir = do
entries <- map (dir </>) <$> listDirectory dir
files <- filterM doesFileExist entries
dirs <- filterM doesDirectoryExist entries
((filter (".smt2" `isSuffixOf`) files) <>) . concat <$> mapM walk dirs
-- | The status in effect at each @check-sat@ and @check-sat-assuming@ of a
-- script, in order (@unknown@ when none was given).
expectedStatuses :: Text -> [Text]
expectedStatuses txt = go "unknown" (fst (parseSExprsPartial txt))
where
go st = \case
[] -> []
SList [SSym "set-info", SKey "status", SSym s] : rest -> go s rest
SList (SSym c : _) : rest | c `elem` ["check-sat", "check-sat-assuming"] -> st : go st rest
_ : rest -> go st rest
-- | Benchmarks hsmt answers with @unknown@ (or not in reasonable time), and
-- why. The test suite accepts @unknown@ from these, and only from these.
knownLimitations :: [(FilePath, Text)]
knownLimitations =
[ ("QF_S" </> "no_conjugate.smt2", "unsatisfiable for every length; the string encoding is bounded")
, ("QF_S" </> "replace_contains.smt2", "unsatisfiable for every length; the string encoding is bounded")
, ("QF_SLIA" </> "from_int_roundtrip.smt2", "str.from_int over unbounded integers")
, ("QF_BV" </> "mul_commutes16.smt2", "equivalence of multipliers; bit-blasting has no word-level rewriting")
]
answerText :: EngineResult -> Text
answerText = \case
ESat _ -> "sat"
EUnsat _ -> "unsat"
EUnknown _ -> "unknown"