@@ -29,7 +29,7 @@ import EVM.Solidity (SourceCache(..), SrcMap, SolcContract(..))
29
29
30
30
import Echidna.Types.Campaign (CampaignConf (.. ))
31
31
import Echidna.Types.Config (Env (.. ), EConfig (.. ))
32
- import Echidna.Types.Coverage (OpIx , unpackTxResults , CoverageMap , CoverageFileType (.. ))
32
+ import Echidna.Types.Coverage (OpIx , unpackTxResults , CoverageMap , CoverageFileType (.. ), ExecQty )
33
33
import Echidna.Types.Tx (TxResult (.. ))
34
34
35
35
saveCoverages
@@ -103,7 +103,7 @@ ppCoveredCode fileType sc cs s | null s = pure "Coverage map is empty"
103
103
pure $ topHeader <> T. unlines (map ppFile allFiles)
104
104
105
105
-- | 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
107
107
markLines fileType codeLines runtimeLines resultMap =
108
108
V. map markLine . V. filter shouldUseLine $ V. indexed codeLines
109
109
where
@@ -112,7 +112,7 @@ markLines fileType codeLines runtimeLines resultMap =
112
112
_ -> True
113
113
markLine (i, codeLine) =
114
114
let n = i + 1
115
- results = fromMaybe [] (Map. lookup n resultMap)
115
+ ( results, execs) = fromMaybe ( [] , 0 ) (Map. lookup n resultMap)
116
116
markers = sort $ nub $ getMarker <$> results
117
117
wrapLine :: Text -> Text
118
118
wrapLine line = case fileType of
@@ -123,11 +123,16 @@ markLines fileType codeLines runtimeLines resultMap =
123
123
where
124
124
cssClass = if n `elem` runtimeLines then getCSSClass markers else " neutral"
125
125
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)
128
129
129
130
in result
130
131
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]
131
136
132
137
getCSSClass :: String -> Text
133
138
getCSSClass markers =
@@ -146,16 +151,16 @@ getMarker ErrorOutOfGas = 'o'
146
151
getMarker _ = ' e'
147
152
148
153
-- | 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 ) ))
150
155
srcMapCov sc covMap contracts = do
151
156
Map. unionsWith Map. union <$> mapM linesCovered contracts
152
157
where
153
- linesCovered :: SolcContract -> IO (Map FilePath (Map Int [TxResult ]))
158
+ linesCovered :: SolcContract -> IO (Map FilePath (Map Int ( [TxResult ], ExecQty ) ))
154
159
linesCovered c =
155
160
case Map. lookup c. runtimeCodehash covMap of
156
161
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 ) ->
159
164
case srcMapForOpLocation c opIx of
160
165
Just srcMap ->
161
166
case srcMapCodePos sc srcMap of
@@ -167,8 +172,10 @@ srcMapCov sc covMap contracts = do
167
172
where
168
173
innerUpdate =
169
174
Map. alter
170
- ( Just . ( <> unpackTxResults txResults) . fromMaybe mempty )
175
+ updateLine
171
176
line
177
+ updateLine (Just (r, q)) = Just ((<> unpackTxResults txResults) r, max q execQty)
178
+ updateLine Nothing = Just (unpackTxResults txResults, execQty)
172
179
Nothing -> acc
173
180
Nothing -> acc
174
181
) mempty vec
0 commit comments