@@ -29,7 +29,7 @@ import EVM.Solidity (SourceCache(..), SrcMap, SolcContract(..))
2929
3030import Echidna.Types.Campaign (CampaignConf (.. ))
3131import Echidna.Types.Config (Env (.. ), EConfig (.. ))
32- import Echidna.Types.Coverage (OpIx , unpackTxResults , CoverageMap , CoverageFileType (.. ))
32+ import Echidna.Types.Coverage (OpIx , unpackTxResults , CoverageMap , CoverageFileType (.. ), ExecQty )
3333import Echidna.Types.Tx (TxResult (.. ))
3434
3535saveCoverages
@@ -103,7 +103,7 @@ ppCoveredCode fileType sc cs s | null s = pure "Coverage map is empty"
103103 pure $ topHeader <> T. unlines (map ppFile allFiles)
104104
105105-- | Mark one particular line, from a list of lines, keeping the order of them
106- markLines :: CoverageFileType -> V. Vector Text -> S. Set Int -> Map Int [TxResult ] -> V. Vector Text
106+ markLines :: CoverageFileType -> V. Vector Text -> S. Set Int -> Map Int ( [TxResult ], ExecQty ) -> V. Vector Text
107107markLines fileType codeLines runtimeLines resultMap =
108108 V. map markLine . V. filter shouldUseLine $ V. indexed codeLines
109109 where
@@ -112,7 +112,7 @@ markLines fileType codeLines runtimeLines resultMap =
112112 _ -> True
113113 markLine (i, codeLine) =
114114 let n = i + 1
115- results = fromMaybe [] (Map. lookup n resultMap)
115+ ( results, execs) = fromMaybe ( [] , 0 ) (Map. lookup n resultMap)
116116 markers = sort $ nub $ getMarker <$> results
117117 wrapLine :: Text -> Text
118118 wrapLine line = case fileType of
@@ -123,11 +123,16 @@ markLines fileType codeLines runtimeLines resultMap =
123123 where
124124 cssClass = if n `elem` runtimeLines then getCSSClass markers else " neutral"
125125 result = case fileType of
126- Lcov -> pack $ printf " DA:%d,%d" n (length results)
127- _ -> pack $ printf " %*d | %-4s| %s" lineNrSpan n markers (wrapLine codeLine)
126+ Lcov -> pack $ printf " DA:%d,%d" n execs
127+ Html -> pack $ printf " %*d | %4s | %-4s| %s" lineNrSpan n (prettyExecs execs) markers (wrapLine codeLine)
128+ _ -> pack $ printf " %*d | %-4s| %s" lineNrSpan n markers (wrapLine codeLine)
128129
129130 in result
130131 lineNrSpan = length . show $ V. length codeLines + 1
132+ prettyExecs x = prettyExecs' x 0
133+ prettyExecs' x n | x >= 1000 = prettyExecs' (x `div` 1000 ) (n + 1 )
134+ | x < 1000 && n == 0 = show x
135+ | otherwise = show x <> [" kMGTPEZY" !! n]
131136
132137getCSSClass :: String -> Text
133138getCSSClass markers =
@@ -146,16 +151,16 @@ getMarker ErrorOutOfGas = 'o'
146151getMarker _ = ' e'
147152
148153-- | Given a source cache, a coverage map, a contract returns a list of covered lines
149- srcMapCov :: SourceCache -> CoverageMap -> [SolcContract ] -> IO (Map FilePath (Map Int [TxResult ]))
154+ srcMapCov :: SourceCache -> CoverageMap -> [SolcContract ] -> IO (Map FilePath (Map Int ( [TxResult ], ExecQty ) ))
150155srcMapCov sc covMap contracts = do
151156 Map. unionsWith Map. union <$> mapM linesCovered contracts
152157 where
153- linesCovered :: SolcContract -> IO (Map FilePath (Map Int [TxResult ]))
158+ linesCovered :: SolcContract -> IO (Map FilePath (Map Int ( [TxResult ], ExecQty ) ))
154159 linesCovered c =
155160 case Map. lookup c. runtimeCodehash covMap of
156161 Just vec -> VU. foldl' (\ acc covInfo -> case covInfo of
157- (- 1 , _, _) -> acc -- not covered
158- (opIx, _stackDepths, txResults) ->
162+ (- 1 , _, _, _ ) -> acc -- not covered
163+ (opIx, _stackDepths, txResults, execQty ) ->
159164 case srcMapForOpLocation c opIx of
160165 Just srcMap ->
161166 case srcMapCodePos sc srcMap of
@@ -167,8 +172,10 @@ srcMapCov sc covMap contracts = do
167172 where
168173 innerUpdate =
169174 Map. alter
170- ( Just . ( <> unpackTxResults txResults) . fromMaybe mempty )
175+ updateLine
171176 line
177+ updateLine (Just (r, q)) = Just ((<> unpackTxResults txResults) r, max q execQty)
178+ updateLine Nothing = Just (unpackTxResults txResults, execQty)
172179 Nothing -> acc
173180 Nothing -> acc
174181 ) mempty vec
0 commit comments