2018-05-22 00:32:29 +03:00
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
2017-11-10 04:18:20 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2017-11-15 06:00:01 +03:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2019-07-12 00:25:13 +03:00
|
|
|
|
2017-11-10 04:18:20 +03:00
|
|
|
module PPC64InstructionCoverage (
|
|
|
|
ppc64InstructionCoverageTests
|
2019-07-12 00:25:13 +03:00
|
|
|
)
|
|
|
|
where
|
2017-11-10 04:18:20 +03:00
|
|
|
|
|
|
|
import Control.Lens ( (^.) )
|
2019-07-12 00:25:13 +03:00
|
|
|
import Control.Monad ( when )
|
2018-05-22 00:32:29 +03:00
|
|
|
import qualified Data.Foldable as F
|
2017-11-10 04:18:20 +03:00
|
|
|
import qualified Data.Map as M
|
2018-05-22 00:32:29 +03:00
|
|
|
import Data.Maybe ( fromJust )
|
2017-11-10 04:18:20 +03:00
|
|
|
import qualified Data.Set as S
|
|
|
|
import Data.Word ( Word64 )
|
2019-07-12 00:25:13 +03:00
|
|
|
import qualified System.FilePath as FP
|
2017-11-10 04:18:20 +03:00
|
|
|
import qualified Test.Tasty as T
|
|
|
|
import qualified Test.Tasty.HUnit as T
|
|
|
|
|
|
|
|
import qualified Data.ElfEdit as E
|
|
|
|
|
2018-05-22 00:32:29 +03:00
|
|
|
import qualified Data.Macaw.BinaryLoader as MBL
|
2018-10-30 01:28:44 +03:00
|
|
|
import Data.Macaw.BinaryLoader.PPC ()
|
|
|
|
import qualified Data.Macaw.Discovery as MD
|
2017-11-10 04:18:20 +03:00
|
|
|
import qualified Data.Macaw.Memory as MM
|
2018-05-22 00:32:29 +03:00
|
|
|
import qualified Data.Macaw.Memory.ElfLoader as MM
|
2017-11-10 04:18:20 +03:00
|
|
|
import qualified Data.Macaw.PPC as RO
|
2018-10-30 01:28:44 +03:00
|
|
|
import qualified Data.Parameterized.Some as PU
|
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
|
2019-07-12 00:25:13 +03:00
|
|
|
mkTest fp = T.testCase fp (withELF fp (testMacaw fp))
|
2017-11-10 04:18:20 +03:00
|
|
|
|
2019-07-12 00:25:13 +03:00
|
|
|
testMacaw :: FilePath -> E.Elf 64 -> IO ()
|
|
|
|
testMacaw fpath elf = do
|
2018-05-22 00:32:29 +03:00
|
|
|
let loadCfg = MM.defaultLoadOptions { MM.loadRegionIndex = Just 0 }
|
|
|
|
loadedBinary :: MBL.LoadedBinary PPC64.PPC (E.Elf 64)
|
|
|
|
<- MBL.loadBinary loadCfg elf
|
|
|
|
entries <- MBL.entryPoints loadedBinary
|
2018-10-30 01:28:44 +03:00
|
|
|
let cfg = RO.ppc64_linux_info loadedBinary
|
2018-05-22 00:32:29 +03:00
|
|
|
let mem = MBL.memoryImage loadedBinary
|
|
|
|
let di = MD.cfgFromAddrs cfg mem M.empty (F.toList entries) []
|
|
|
|
let allFoundBlockAddrs :: S.Set Word64
|
|
|
|
allFoundBlockAddrs =
|
2018-10-30 01:55:41 +03:00
|
|
|
S.fromList [ fromIntegral (fromJust (MM.asAbsoluteAddr (MM.segoffAddr (MD.pblockAddr pbr))))
|
2018-05-22 00:32:29 +03:00
|
|
|
| PU.Some dfi <- M.elems (di ^. MD.funInfo)
|
|
|
|
, pbr <- M.elems (dfi ^. MD.parsedBlocks)
|
|
|
|
]
|
|
|
|
T.assertBool "No blocks found" (not (S.null allFoundBlockAddrs))
|
2019-07-12 00:25:13 +03:00
|
|
|
when (FP.takeFileName fpath == "gzip") $
|
|
|
|
-- This is pretty specific, and mostly just designed to notify us
|
|
|
|
-- when there has been a change
|
2019-08-10 02:11:59 +03:00
|
|
|
T.assertEqual "number of found blocks" 37218 (length allFoundBlockAddrs)
|