mirror of
https://github.com/GaloisInc/macaw.git
synced 2024-11-25 21:54:51 +03:00
x86-cli: Test suite
This commit is contained in:
parent
f5c451021a
commit
dcb4ec1c6a
@ -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
|
||||
|
10
macaw-x86-cli/test-data/byte-id.cbl
Normal file
10
macaw-x86-cli/test-data/byte-id.cbl
Normal 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 ())))
|
4
macaw-x86-cli/test-data/byte-id.out.good
Normal file
4
macaw-x86-cli/test-data/byte-id.out.good
Normal file
@ -0,0 +1,4 @@
|
||||
==== Begin Simulation ====
|
||||
|
||||
==== Finish Simulation ====
|
||||
==== No proof obligations ====
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user