2017-11-10 04:18:20 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2017-11-15 06:00:01 +03:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2017-11-10 04:18:20 +03:00
|
|
|
module PPC64InstructionCoverage (
|
|
|
|
ppc64InstructionCoverageTests
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Control.Lens ( (^.) )
|
|
|
|
import qualified Data.Map as M
|
2017-11-22 01:10:47 +03:00
|
|
|
import Data.Maybe ( fromJust, mapMaybe )
|
2017-11-15 06:00:01 +03:00
|
|
|
import Data.Proxy ( Proxy(..) )
|
2017-11-10 04:18:20 +03:00
|
|
|
import qualified Data.Set as S
|
|
|
|
import Data.Word ( Word64 )
|
|
|
|
import qualified Test.Tasty as T
|
|
|
|
import qualified Test.Tasty.HUnit as T
|
|
|
|
|
|
|
|
import qualified Data.ElfEdit as E
|
|
|
|
|
|
|
|
import qualified Data.Parameterized.Some as PU
|
|
|
|
import qualified Data.Macaw.Memory as MM
|
|
|
|
import qualified Data.Macaw.Discovery as MD
|
|
|
|
import qualified Data.Macaw.PPC as RO
|
2017-11-22 01:10:47 +03:00
|
|
|
import qualified Data.Macaw.PPC.BinaryFormat.ELF as E
|
2017-11-15 06:00:01 +03:00
|
|
|
import qualified SemMC.Architecture.PPC64 as PPC64
|
2017-11-10 04:18:20 +03:00
|
|
|
|
|
|
|
import Shared
|
|
|
|
|
|
|
|
ppc64InstructionCoverageTests :: [FilePath] -> T.TestTree
|
|
|
|
ppc64InstructionCoverageTests = T.testGroup "PPCCoverage" . map mkTest
|
|
|
|
|
|
|
|
mkTest :: FilePath -> T.TestTree
|
|
|
|
mkTest fp = T.testCase fp (withELF fp testMacaw)
|
|
|
|
|
|
|
|
testMacaw :: E.Elf 64 -> IO ()
|
|
|
|
testMacaw elf =
|
|
|
|
withMemory MM.Addr64 elf $ \mem -> do
|
|
|
|
let Just entryPoint = MM.asSegmentOff mem (findEntryPoint64 elf mem)
|
2018-05-18 18:33:58 +03:00
|
|
|
-- let tocBase = E.parseTOC elf
|
|
|
|
-- let otherEntryAddrs :: [MM.MemAddr 64]
|
|
|
|
di <- E.parseTOC elf
|
|
|
|
-- let otherEntries = mapMaybe (MM.asSegmentOff mem) otherEntryAddrs
|
|
|
|
-- let di = MD.cfgFromAddrs (RO.ppc64_linux_info tocBase) mem M.empty (entryPoint:otherEntries) []
|
2017-11-10 04:18:20 +03:00
|
|
|
let allFoundBlockAddrs :: S.Set Word64
|
|
|
|
allFoundBlockAddrs =
|
|
|
|
S.fromList [ fromIntegral (fromJust (MM.asAbsoluteAddr (MM.relativeSegmentAddr (MD.pblockAddr pbr))))
|
|
|
|
| PU.Some dfi <- M.elems (di ^. MD.funInfo)
|
|
|
|
, pbr <- M.elems (dfi ^. MD.parsedBlocks)
|
|
|
|
]
|
|
|
|
T.assertBool "No blocks found" (not (S.null allFoundBlockAddrs))
|
|
|
|
|
|
|
|
|