Skip to content

Commit 7953bd7

Browse files
authored
emit saved reproducer log message as event rather than putstrln (#1274)
1 parent bd90027 commit 7953bd7

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

lib/Echidna/Output/Corpus.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import Echidna.Types.Test (EchidnaTest(..))
1818
import Echidna.Types.Tx (Tx)
1919
import Echidna.Utility (listDirectory, withCurrentDirectory)
2020

21-
saveTxs :: FilePath -> [[Tx]] -> IO ()
22-
saveTxs dir = mapM_ saveTxSeq where
21+
saveTxs :: Env -> FilePath -> [[Tx]] -> IO ()
22+
saveTxs env dir = mapM_ saveTxSeq where
2323
saveTxSeq txSeq = do
2424
createDirectoryIfMissing True dir
2525
let file = dir </> (show . abs . hash . show) txSeq <.> "txt"
26-
putStrLn ("Saving reproducer to " ++ file)
2726
unlessM (doesFileExist file) $ encodeFile file (toJSON txSeq)
27+
pushCampaignEvent env (ReproducerSaved file)
2828

2929
loadTxs :: FilePath -> IO [(FilePath, [Tx])]
3030
loadTxs dir = do
@@ -59,7 +59,7 @@ saveCorpusEvent env (_time, campaignEvent) = do
5959

6060
saveFile dir (subdir, txs) =
6161
unless (null txs) $
62-
handle exceptionHandler $ saveTxs (dir </> subdir) [txs]
62+
handle exceptionHandler $ saveTxs env (dir </> subdir) [txs]
6363

6464
exceptionHandler (e :: IOException) =
6565
pushCampaignEvent env (Failure $ "Problem while writing to file: " ++ show e)

lib/Echidna/Server.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ instance ToJSON SSE where
3030
object [ "timestamp" .= time
3131
, "data" .= reason
3232
]
33+
toJSON (SSE (time, ReproducerSaved filename)) =
34+
object [ "timestamp" .= time
35+
, "filename" .= filename
36+
]
3337

3438
runSSEServer :: MVar () -> Env -> Word16 -> Int -> IO ()
3539
runSSEServer serverStopVar env port nworkers = do
@@ -53,6 +57,7 @@ runSSEServer serverStopVar env port nworkers = do
5357
TxSequenceReplayFailed {} -> "tx_sequence_replay_failed"
5458
WorkerStopped _ -> "worker_stopped"
5559
Failure _err -> "failure"
60+
ReproducerSaved _ -> "saved_reproducer"
5661
case campaignEvent of
5762
WorkerEvent _ _ (WorkerStopped _) -> do
5863
aliveAfter <- atomicModifyIORef' aliveRef (\n -> (n-1, n-1))

lib/Echidna/Types/Campaign.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type WorkerId = Int
7272
data CampaignEvent
7373
= WorkerEvent WorkerId WorkerType WorkerEvent
7474
| Failure String
75+
| ReproducerSaved String -- filename
7576

7677
data WorkerEvent
7778
= TestFalsified !EchidnaTest
@@ -111,6 +112,7 @@ ppCampaignEvent :: CampaignEvent -> String
111112
ppCampaignEvent = \case
112113
WorkerEvent _ _ e -> ppWorkerEvent e
113114
Failure err -> err
115+
ReproducerSaved f -> "Saved reproducer to " <> f
114116

115117
ppWorkerEvent :: WorkerEvent -> String
116118
ppWorkerEvent = \case

src/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ main = withUtf8 $ withCP65001 $ do
8181
Nothing -> pure ()
8282
Just dir -> do
8383
measureIO cfg.solConf.quiet "Saving test reproducers" $
84-
saveTxs (dir </> "reproducers") (filter (not . null) $ (.reproducer) <$> tests)
84+
saveTxs env (dir </> "reproducers") (filter (not . null) $ (.reproducer) <$> tests)
8585

8686
saveTracesEnabled <- lookupEnv "ECHIDNA_SAVE_TRACES"
8787
when (isJust saveTracesEnabled) $ do
@@ -98,7 +98,7 @@ main = withUtf8 $ withCP65001 $ do
9898

9999
measureIO cfg.solConf.quiet "Saving corpus" $ do
100100
corpus <- readIORef env.corpusRef
101-
saveTxs (dir </> "coverage") (snd <$> Set.toList corpus)
101+
saveTxs env (dir </> "coverage") (snd <$> Set.toList corpus)
102102

103103
-- TODO: We use the corpus dir to save coverage reports which is confusing.
104104
-- Add config option to pass dir for saving coverage report and decouple it

0 commit comments

Comments
 (0)