Skip to content

Commit 300f6b4

Browse files
committed
Add test to verify round-trip-ability
1 parent ded621b commit 300f6b4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ghc-events.cabal

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,11 @@ test-suite write-merge
126126
build-depends: ghc-events, base, bytestring
127127
extensions: RecordWildCards, NamedFieldPuns, BangPatterns, PatternGuards
128128
buildable: False
129+
130+
test-suite roundtrip
131+
type: exitcode-stdio-1.0
132+
main-is: Roundtrip.hs
133+
other-modules: Utils
134+
hs-source-dirs: ., test
135+
build-depends: ghc-events, base
136+
extensions: RecordWildCards, NamedFieldPuns, BangPatterns, PatternGuards

test/Roundtrip.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Control.Monad
2+
import System.Exit
3+
4+
import GHC.RTS.Events
5+
import GHC.RTS.Events.Incremental
6+
import Utils (files, diffLines)
7+
8+
-- | Check that an eventlog round-trips through encoding/decoding.
9+
checkRoundtrip :: FilePath -> IO Bool
10+
checkRoundtrip logFile = do
11+
putStrLn logFile
12+
Right eventlog <- readEventLogFromFile logFile
13+
let Right (roundtripped, _) = readEventLog $ serialiseEventLog eventlog
14+
let getEvents = sortEvents . events . dat
15+
if show roundtripped == show eventlog
16+
then return True
17+
else putStrLn "bad" >> return False
18+
19+
main :: IO ()
20+
main = do
21+
successes <- mapM checkRoundtrip files
22+
unless (and successes) exitFailure

0 commit comments

Comments
 (0)