x86-cli: Test suite

This commit is contained in:
Langston Barrett 2024-08-20 13:43:39 -04:00
parent f5c451021a
commit dcb4ec1c6a
4 changed files with 65 additions and 3 deletions

View File

@ -120,18 +120,19 @@ test-suite macaw-x86-syntax-tests
base,
containers,
crucible >= 0.1,
crucible-syntax,
crucible-llvm-syntax,
crucible-cli,
filepath,
macaw-symbolic,
macaw-symbolic-syntax,
macaw-x86,
macaw-x86-cli,
macaw-x86-symbolic,
macaw-x86-syntax,
parameterized-utils >= 0.1.7,
tasty,
tasty-golden,
text,
what4,
executable macaw-x86
import: shared

View File

@ -0,0 +1,10 @@
(defun @byte_id ((x (Bitvector 8))) (Bitvector 8)
(start start:
(return x)))
(defun @main () Unit
(start start:
(let input (fresh (Bitvector 8)))
(let input_back (funcall @byte_id input))
(assert! (equal? input input_back) "byte_id test")
(return ())))

View File

@ -0,0 +1,4 @@
==== Begin Simulation ====
==== Finish Simulation ====
==== No proof obligations ====

View File

@ -1,4 +1,51 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Data.List (sort)
import Data.Text.IO qualified as T
import System.FilePath
import System.IO
import Test.Tasty (defaultMain, TestTree, testGroup)
import Test.Tasty.Golden
import What4.Solver.Z3 (z3Options)
import Lang.Crucible.CLI (simulateProgramWithExtension)
import Data.Macaw.X86.Symbolic.CLI (withX86Hooks)
main :: IO ()
main = pure ()
main = do
simTests <- findTests "x86 simulation" "test-data" testSimulator
defaultMain simTests
findTests :: String -> FilePath -> (FilePath -> FilePath -> IO ()) -> IO TestTree
findTests groupName testDir testAction =
do inputs <- findByExtension [".cbl"] testDir
return $ testGroup groupName
[ goldenFileTestCase input testAction
| input <- sort inputs
]
goldenFileTestCase :: FilePath -> (FilePath -> FilePath -> IO ()) -> TestTree
goldenFileTestCase input testAction =
goldenVsFileDiff
(takeBaseName input) -- test name
(\x y -> ["diff", "-u", x, y])
goodFile -- golden file path
outFile
(testAction input outFile) -- action whose result is tested
where
outFile = replaceExtension input ".out"
goodFile = replaceExtension input ".out.good"
testSimulator :: FilePath -> FilePath -> IO ()
testSimulator inFile outFile =
do contents <- T.readFile inFile
withFile outFile WriteMode $ \outh ->
withX86Hooks $ \ext hooks ->
simulateProgramWithExtension ext inFile contents outh Nothing z3Options hooks