Skip to content

Commit

Permalink
Make continuous fuzzing default
Browse files Browse the repository at this point in the history
Fixes #477
  • Loading branch information
siraben committed Jun 2, 2023
1 parent 70a1c6c commit ce18f0d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 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
5 changes: 1 addition & 4 deletions 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 Expand Up @@ -116,9 +116,6 @@ initialWorkerState =
, ncalls = 0
}

defaultTestLimit :: Int
defaultTestLimit = 50000

defaultSequenceLength :: Int
defaultSequenceLength = 100

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
4 changes: 2 additions & 2 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ options = Options
<> help "Timeout given in seconds.")
<*> optional (option auto $ long "test-limit"
<> metavar "INTEGER"
<> help ("Number of sequences of transactions to generate during testing. Default is " ++ show defaultTestLimit))
<> help ("Number of sequences of transactions to generate during testing. Default is unbounded."))
<*> optional (option auto $ long "shrink-limit"
<> metavar "INTEGER"
<> help ("Number of tries to attempt to shrink a failing sequence of transactions. Default is " ++ show defaultShrinkLimit))
Expand Down 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
2 changes: 1 addition & 1 deletion src/test/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ overrideQuiet conf =

overrideLimits :: EConfig -> EConfig
overrideLimits conf =
conf { campaignConf = conf.campaignConf { testLimit = 10000
conf { campaignConf = conf.campaignConf { testLimit = Just 10000
, shrinkLimit = 4000 }}

type SolcVersion = Version
Expand Down
2 changes: 1 addition & 1 deletion src/test/Tests/Seed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ seedTests =
where
cfg s = defaultConfig
{ campaignConf = CampaignConf
{ testLimit = 600
{ testLimit = Just 600
, stopOnFail = False
, estimateGas = False
, seqLen = 20
Expand Down

0 comments on commit ce18f0d

Please sign in to comment.