mirror of
https://github.com/GaloisInc/macaw.git
synced 2024-12-29 00:59:09 +03:00
give an expected block size in x86_64 tests
This commit is contained in:
parent
54662612ea
commit
d61e6d4a7f
@ -27,6 +27,7 @@ import qualified Data.Parameterized.Some as PU
|
||||
import qualified Data.Macaw.Memory as MM
|
||||
import qualified Data.Macaw.Memory.ElfLoader as MM
|
||||
import qualified Data.Macaw.Discovery as MD
|
||||
import qualified Data.Macaw.Discovery.State as MD
|
||||
import qualified Data.Macaw.X86 as RO
|
||||
|
||||
elfX64LinuxTests :: [FilePath] -> T.TestTree
|
||||
@ -34,7 +35,7 @@ elfX64LinuxTests = T.testGroup "ELF x64 Linux" . map mkTest
|
||||
|
||||
-- | The type of expected results for test cases
|
||||
data ExpectedResult =
|
||||
R { funcs :: [(Word64, [Word64])]
|
||||
R { funcs :: [(Word64, [(Word64, Integer)])]
|
||||
-- ^ The first element of the pair is the address of entry point
|
||||
-- of the function. The list is a list of the addresses of the
|
||||
-- basic blocks in the function (including the first block).
|
||||
@ -68,14 +69,18 @@ testDiscovery expectedFilename elf =
|
||||
F.forM_ (M.elems (di ^. MD.funInfo)) $ \(PU.Some dfi) -> do
|
||||
let actualEntry = fromIntegral (fromJust (MM.asAbsoluteAddr (MM.relativeSegmentAddr (MD.discoveredFunAddr dfi))))
|
||||
-- actualEntry = fromIntegral (MM.addrValue (MD.discoveredFunAddr dfi))
|
||||
actualBlockStarts = S.fromList [ fromIntegral (fromJust (MM.asAbsoluteAddr (MM.relativeSegmentAddr (MD.pblockAddr pbr))))
|
||||
actualBlockStarts = S.fromList [ ( addr
|
||||
, toInteger (MD.blockSize pbr)
|
||||
)
|
||||
| pbr <- M.elems (dfi ^. MD.parsedBlocks)
|
||||
, let addr = fromIntegral (fromJust (MM.asAbsoluteAddr (MM.relativeSegmentAddr (MD.pblockAddr pbr))))
|
||||
, addr `S.notMember` ignoredBlocks
|
||||
]
|
||||
case (S.member actualEntry ignoredBlocks, M.lookup actualEntry expectedEntries) of
|
||||
(True, _) -> return ()
|
||||
(_, Nothing) -> T.assertFailure (printf "Unexpected entry point: 0x%x" actualEntry)
|
||||
(_, Just expectedBlockStarts) ->
|
||||
T.assertEqual (printf "Block starts for 0x%x" actualEntry) expectedBlockStarts (actualBlockStarts `S.difference` ignoredBlocks)
|
||||
T.assertEqual (printf "Block starts for 0x%x" actualEntry) expectedBlockStarts actualBlockStarts
|
||||
|
||||
withELF :: FilePath -> (E.Elf 64 -> IO ()) -> IO ()
|
||||
withELF fp k = do
|
||||
|
@ -1,3 +1,3 @@
|
||||
R { funcs = [(0x2b1, [0x2b1, 0x2ce, 0x2bf])]
|
||||
R { funcs = [(0x2b1, [(0x2b1, 14), (0x2ce, 16), (0x2bf, 31)])]
|
||||
, ignoreBlocks = [0x2de]
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
R { funcs = [ (0x336, [0x336, 0x376])
|
||||
, (0x2be, [0x2be, 0x318])
|
||||
, (0x2b1, [0x2b1])
|
||||
R { funcs = [ (0x336, [(0x336, 64), (0x376, 22)])
|
||||
, (0x2be, [(0x2be, 90), (0x318, 30)])
|
||||
, (0x2b1, [(0x2b1, 13)])
|
||||
]
|
||||
, ignoreBlocks = [0x38c]
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
R { funcs = [ (0x2b1, [0x2b1])
|
||||
, (0x2bf, [0x2bf, 0x2e2])
|
||||
R { funcs = [ (0x2b1, [(0x2b1, 14)])
|
||||
, (0x2bf, [(0x2bf, 35), (0x2e2, 22)])
|
||||
]
|
||||
, ignoreBlocks = [0x2f8]
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
R { funcs = [(0x2b1, [0x2b1])]
|
||||
R { funcs = [(0x2b1, [(0x2b1, 20)])]
|
||||
, ignoreBlocks = [0x2c5]
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
R { funcs = [ (0x2c0, [0x2c0])
|
||||
, (0x2d0, [0x2d0, 0x2c0])
|
||||
, (0x2e0, [0x2e0, 0x2eb])
|
||||
R { funcs = [ (0x2c0, [(0x2c0, 0)])
|
||||
, (0x2d0, [(0x2d0, 11), (0x2c0, 7)])
|
||||
, (0x2e0, [(0x2e0, 11), (0x2eb, 16)])
|
||||
]
|
||||
, ignoreBlocks = [0x2fb]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user