-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save corpus while fuzzing; add TestSimplified event; change event system
- Loading branch information
1 parent
31c187b
commit e3b86cd
Showing
11 changed files
with
134 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Echidna.Async where | ||
|
||
import Control.Concurrent.Thread.Group (forkIO) | ||
import Control.Monad (void) | ||
import Control.Monad.Reader (MonadReader, asks, ask) | ||
import Control.Monad.State.Strict (MonadState, gets) | ||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
import Data.IORef (atomicModifyIORef', readIORef) | ||
import Data.Time (LocalTime) | ||
|
||
import Echidna.Types.Campaign (CampaignEvent, WorkerState(..)) | ||
import Echidna.Types.Config (Env(..)) | ||
import Echidna.Utility (getTimestamp) | ||
|
||
spawnThread :: Env -> IO a -> IO () | ||
spawnThread env io = void $ forkIO env.threadGroup io | ||
|
||
addEventHandler | ||
:: (MonadReader Env m, MonadIO m) | ||
=> ((Int, LocalTime, CampaignEvent) -> IO ()) | ||
-> m () | ||
addEventHandler f = do | ||
handlersRef <- asks (.eventHandlers) | ||
liftIO $ atomicModifyIORef' handlersRef (\l -> (f:l, ())) | ||
|
||
pushEvent | ||
:: (MonadReader Env m, MonadState WorkerState m, MonadIO m) | ||
=> CampaignEvent | ||
-> m () | ||
pushEvent event = do | ||
workerId <- gets (.workerId) | ||
env <- ask | ||
liftIO $ pushEventIO env workerId event | ||
|
||
pushEventIO :: Env -> Int -> CampaignEvent -> IO () | ||
pushEventIO env workerId event = do | ||
time <- liftIO getTimestamp | ||
handlers <- readIORef env.eventHandlers | ||
mapM_ (\f -> spawnThread env $ f (workerId, time, event)) handlers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ dependencies: | |
- semver | ||
- split | ||
- text | ||
- threads | ||
- transformers | ||
- time | ||
- unliftio | ||
|
Oops, something went wrong.