From 71a432ed18f0008a5743434f1b2193dc50c57ecf Mon Sep 17 00:00:00 2001 From: Tristan Ravitch Date: Tue, 7 Nov 2017 20:50:33 -0800 Subject: [PATCH] Improve the test suite Don't just ensure that found blocks are expected: also ensure that all expected blocks are found. --- macaw-ppc/tests/PPC64Tests.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/macaw-ppc/tests/PPC64Tests.hs b/macaw-ppc/tests/PPC64Tests.hs index e2f70f30..69a7fea6 100644 --- a/macaw-ppc/tests/PPC64Tests.hs +++ b/macaw-ppc/tests/PPC64Tests.hs @@ -98,7 +98,12 @@ testDiscovery expectedFilename elf = -- expectedEntries maps function entry points to the set of block starts -- within the function. ignoredBlocks = S.fromList (ignoreBlocks er) - -- ignoredBlocks :: S.Set Word64 + 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) + ] F.forM_ (M.elems (di ^. MD.funInfo)) $ \(PU.Some dfi) -> do let actualEntry = fromIntegral (fromJust (MM.asAbsoluteAddr (MM.relativeSegmentAddr (MD.discoveredFunAddr dfi)))) actualBlockStarts = S.fromList [ (baddr, bsize) @@ -112,6 +117,9 @@ testDiscovery expectedFilename elf = (_, Nothing) -> T.assertFailure (printf "Unexpected block start: 0x%x" actualEntry) (_, Just expectedBlockStarts) -> T.assertEqual (printf "Block starts for 0x%x" actualEntry) expectedBlockStarts (actualBlockStarts `removeIgnored` ignoredBlocks) + F.forM_ (funcs er) $ \(_funcAddr, blockAddrs) -> + F.forM_ blockAddrs $ \(blockAddr@(Hex addr), _) -> do + T.assertBool ("Missing block address: " ++ show blockAddr) (S.member addr allFoundBlockAddrs) removeIgnored :: (Ord b, Ord a) => S.Set (a, b) -> S.Set a -> S.Set (a, b) removeIgnored actualBlockStarts ignoredBlocks =