|
|
@ -1,8 +1,11 @@ |
|
|
|
{-# LANGUAGE CPP #-} |
|
|
|
{-# LANGUAGE CPP #-} |
|
|
|
|
|
|
|
{-# LANGUAGE TemplateHaskell #-} |
|
|
|
{-# OPTIONS_GHC -Wno-unused-imports #-} |
|
|
|
{-# OPTIONS_GHC -Wno-unused-imports #-} |
|
|
|
|
|
|
|
|
|
|
|
module Echidna.UI where |
|
|
|
module Echidna.UI where |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Echidna.CatchMVar |
|
|
|
|
|
|
|
|
|
|
|
#ifdef INTERACTIVE_UI |
|
|
|
#ifdef INTERACTIVE_UI |
|
|
|
import Brick |
|
|
|
import Brick |
|
|
|
import Brick.BChan |
|
|
|
import Brick.BChan |
|
|
@ -97,7 +100,7 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
Interactive -> do |
|
|
|
Interactive -> do |
|
|
|
-- Channel to push events to update UI |
|
|
|
-- Channel to push events to update UI |
|
|
|
uiChannel <- liftIO $ newBChan 1000 |
|
|
|
uiChannel <- liftIO $ newBChan 1000 |
|
|
|
let forwardEvent = void . writeBChanNonBlocking uiChannel . EventReceived |
|
|
|
let forwardEvent = void . $writeBChanNonBlocking_ uiChannel . EventReceived |
|
|
|
uiEventsForwarderStopVar <- spawnListener forwardEvent |
|
|
|
uiEventsForwarderStopVar <- spawnListener forwardEvent |
|
|
|
|
|
|
|
|
|
|
|
ticker <- liftIO . forkIO . forever $ do |
|
|
|
ticker <- liftIO . forkIO . forever $ do |
|
|
@ -106,12 +109,12 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
now <- getTimestamp |
|
|
|
now <- getTimestamp |
|
|
|
tests <- traverse readIORef env.testRefs |
|
|
|
tests <- traverse readIORef env.testRefs |
|
|
|
states <- workerStates workers |
|
|
|
states <- workerStates workers |
|
|
|
writeBChan uiChannel (CampaignUpdated now tests states) |
|
|
|
$writeBChan_ uiChannel (CampaignUpdated now tests states) |
|
|
|
|
|
|
|
|
|
|
|
-- TODO: remove and use events for this |
|
|
|
-- TODO: remove and use events for this |
|
|
|
c <- readIORef env.fetchContractCache |
|
|
|
c <- readIORef env.fetchContractCache |
|
|
|
s <- readIORef env.fetchSlotCache |
|
|
|
s <- readIORef env.fetchSlotCache |
|
|
|
writeBChan uiChannel (FetchCacheUpdated c s) |
|
|
|
$writeBChan_ uiChannel (FetchCacheUpdated c s) |
|
|
|
|
|
|
|
|
|
|
|
-- UI initialization |
|
|
|
-- UI initialization |
|
|
|
let buildVty = do |
|
|
|
let buildVty = do |
|
|
@ -149,7 +152,7 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
stopWorkers workers |
|
|
|
stopWorkers workers |
|
|
|
|
|
|
|
|
|
|
|
-- wait for all events to be processed |
|
|
|
-- wait for all events to be processed |
|
|
|
forM_ [uiEventsForwarderStopVar, corpusSaverStopVar] takeMVar |
|
|
|
liftIO $ forM_ [uiEventsForwarderStopVar, corpusSaverStopVar] $takeMVar_ |
|
|
|
|
|
|
|
|
|
|
|
liftIO $ killThread ticker |
|
|
|
liftIO $ killThread ticker |
|
|
|
|
|
|
|
|
|
|
@ -168,7 +171,7 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
liftIO $ forM_ [sigINT, sigTERM] $ \sig -> |
|
|
|
liftIO $ forM_ [sigINT, sigTERM] $ \sig -> |
|
|
|
let handler = Catch $ do |
|
|
|
let handler = Catch $ do |
|
|
|
stopWorkers workers |
|
|
|
stopWorkers workers |
|
|
|
void $ tryPutMVar serverStopVar () |
|
|
|
void $ $tryPutMVar_ serverStopVar () |
|
|
|
in installHandler sig handler Nothing |
|
|
|
in installHandler sig handler Nothing |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
let forwardEvent ev = putStrLn =<< runReaderT (ppLogLine vm ev) env |
|
|
|
let forwardEvent ev = putStrLn =<< runReaderT (ppLogLine vm ev) env |
|
|
@ -190,7 +193,7 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
printStatus |
|
|
|
printStatus |
|
|
|
|
|
|
|
|
|
|
|
-- wait for all events to be processed |
|
|
|
-- wait for all events to be processed |
|
|
|
forM_ [uiEventsForwarderStopVar, corpusSaverStopVar] takeMVar |
|
|
|
liftIO $ forM_ [uiEventsForwarderStopVar, corpusSaverStopVar] $takeMVar_ |
|
|
|
|
|
|
|
|
|
|
|
liftIO $ killThread ticker |
|
|
|
liftIO $ killThread ticker |
|
|
|
|
|
|
|
|
|
|
@ -200,7 +203,7 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
when (isJust conf.campaignConf.serverPort) $ do |
|
|
|
when (isJust conf.campaignConf.serverPort) $ do |
|
|
|
-- wait until we send all SSE events |
|
|
|
-- wait until we send all SSE events |
|
|
|
liftIO $ putStrLn "Waiting until all SSE are received..." |
|
|
|
liftIO $ putStrLn "Waiting until all SSE are received..." |
|
|
|
readMVar serverStopVar |
|
|
|
liftIO $ $readMVar_ serverStopVar |
|
|
|
|
|
|
|
|
|
|
|
states <- liftIO $ workerStates workers |
|
|
|
states <- liftIO $ workerStates workers |
|
|
|
|
|
|
|
|
|
|
@ -237,7 +240,7 @@ ui vm dict initialCorpus cliSelectedContract = do |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
time <- liftIO getTimestamp |
|
|
|
time <- liftIO getTimestamp |
|
|
|
writeChan env.eventQueue (time, WorkerEvent workerId workerType (WorkerStopped stopReason)) |
|
|
|
liftIO $ $writeChan_ env.eventQueue (time, WorkerEvent workerId workerType (WorkerStopped stopReason)) |
|
|
|
|
|
|
|
|
|
|
|
pure (threadId, stateRef) |
|
|
|
pure (threadId, stateRef) |
|
|
|
|
|
|
|
|
|
|
|