Skip to content

Commit

Permalink
Make continuous fuzzing default
Browse files Browse the repository at this point in the history
  • Loading branch information
siraben committed Jun 2, 2023
1 parent 70a1c6c commit bc6cee9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/Echidna/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ runWorker
-> GenDict -- ^ Generation dictionary
-> Int -- ^ Worker id starting from 0
-> [[Tx]] -- ^ Initial corpus of transactions
-> Int -- ^ Test limit for this worker
-> Maybe Int -- ^ Test limit for this worker
-> m (WorkerStopReason, WorkerState)
runWorker callback vm world dict workerId initialCorpus testLimit = do
metaCacheRef <- asks (.metadataCache)
Expand Down Expand Up @@ -135,10 +135,10 @@ runWorker callback vm world dict workerId initialCorpus testLimit = do
if | stopOnFail && any final tests ->
lift callback >> pure FastFailed

| (null tests || any isOpen tests) && ncalls < testLimit ->
| (null tests || any isOpen tests) && maybe True (ncalls <) testLimit ->
fuzz >> continue

| ncalls >= testLimit && any (\t -> isOpen t && isOptimizationTest t) tests -> do
| maybe False (ncalls >=) testLimit && any (\t -> isOpen t && isOptimizationTest t) tests -> do
liftIO $ atomicModifyIORef' testsRef $ \sharedTests ->
(closeOptimizationTest <$> sharedTests, ())
continue
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ instance FromJSON EConfigWithUsage where
pure $ TestConf classify (const psender)

campaignConfParser = CampaignConf
<$> v ..:? "testLimit" ..!= defaultTestLimit
<$> v ..:? "testLimit"
<*> v ..:? "stopOnFail" ..!= False
<*> v ..:? "estimateGas" ..!= False
<*> v ..:? "seqLen" ..!= defaultSequenceLength
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/Types/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Echidna.Types.Tx (Tx)

-- | Configuration for running an Echidna 'Campaign'.
data CampaignConf = CampaignConf
{ testLimit :: Int
{ testLimit :: Maybe Int
-- ^ Maximum number of function calls to execute while fuzzing
, stopOnFail :: Bool
-- ^ Whether to stop the campaign immediately if any property fails
Expand Down
6 changes: 4 additions & 2 deletions lib/Echidna/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ ui vm world dict initialCorpus = do

-- Distribute over all workers, could be slightly bigger overall due to
-- ceiling but this doesn't matter
perWorkerTestLimit = ceiling
(fromIntegral conf.campaignConf.testLimit / fromIntegral nworkers :: Double)
perWorkerTestLimit =
case conf.campaignConf.testLimit of
Nothing -> Nothing
Just t -> Just $ ceiling (fromIntegral t / fromIntegral nworkers :: Double)

chunkSize = ceiling
(fromIntegral (length initialCorpus) / fromIntegral nworkers :: Double)
Expand Down
4 changes: 2 additions & 2 deletions lib/Echidna/UI/Widgets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ summaryWidget env uiState =
<=>
perfWidget uiState
<=>
str ("Total calls: " <> progress (sum $ (.ncalls) <$> uiState.campaigns)
env.cfg.campaignConf.testLimit)
str ("Total calls: " <> maybe (show totalCalls) (progress totalCalls) env.cfg.campaignConf.testLimit)
totalCalls = (sum $ (.ncalls) <$> uiState.campaigns)
middle =
padLeft (Pad 1) $
str ("Unique instructions: " <> show uiState.coverage)
Expand Down
2 changes: 1 addition & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ overrideConfig config Options{..} = do

overrideCampaignConf campaignConf = campaignConf
{ corpusDir = cliCorpusDir <|> campaignConf.corpusDir
, testLimit = fromMaybe campaignConf.testLimit cliTestLimit
, testLimit = cliTestLimit <|> campaignConf.testLimit
, shrinkLimit = fromMaybe campaignConf.shrinkLimit cliShrinkLimit
, seqLen = fromMaybe campaignConf.seqLen cliSeqLen
, seed = cliSeed <|> campaignConf.seed
Expand Down

0 comments on commit bc6cee9

Please sign in to comment.