Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make write-merge test buildable #28

Merged
merged 1 commit into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/GHC/RTS/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module GHC.RTS.Events (
readEventLogFromFile,
writeEventLogToFile,

serialiseEventLog,

-- * Utilities
CapEvent(..), sortEvents,
buildEventTypeMap,
Expand Down
49 changes: 21 additions & 28 deletions test/WriteMerge.hs
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
{-
This test checks the functionality of `ghc-events merge` and writeEventLogToFile
-}

import Control.Monad
import qualified Data.ByteString.Lazy as BL
import Data.List (( \\ ))
import Data.Maybe (fromJust)
import System.Exit (exitFailure)

import GHC.RTS.Events
import GHC.RTS.EventsIncremental
import GHC.RTS.Events.Incremental (readEventLog)
import Utils (files, diffLines)


-- Failing test cases due to changes introduced some time in the past but
-- went unnoticed. Needs fixing. TODO
failingCases :: [FilePath]
failingCases = map ("test/"++)
[ "queens-ghc-6.12.1.eventlog"
, "queens-ghc-7.0.2.eventlog"
, "mandelbrot-mmc-2011-06-14.eventlog"
, "782stop.eventlog"]

-- Returns a pretty printed version of the log and one that's been reserialised
-- and reparsed, which should yield the same result
rewriteLog :: EventLog -> (String, String)
rewriteLog oldLog =
(ppEventLog oldLog, ppEventLog newLog)
where
logBytestring = serialiseEventLog oldLog
eps = newParserState `pushBytes` (BL.toStrict logBytestring)
(newEvts, finalState, _) = readRemainingEvents eps
newHdr = fromJust $ readHeader finalState
newLog = (EventLog newHdr (Data newEvts))
rewriteLog :: EventLog -> EventLog
rewriteLog oldLog = case readEventLog (serialiseEventLog oldLog) of
Left reason -> error reason
Right (newLog, _) -> newLog

testFile :: FilePath -> IO Bool
testFile f = do
e <- readEventLogFromFile f
let oops s = putStrLn (f ++ ": failure " ++ s) >> return False
case e of
Left m -> oops m
Right log -> do
let (old, new) = rewriteLog log
if old == new
then putStrLn (f ++ ": success") >> return True
else do putStrLn $ diffLines old new
oops "re-written file does not match the original"
e <- readEventLogFromFile f
let oops s = putStrLn (f ++ ": failure " ++ s) >> return False
case e of
Left m -> oops m
Right log -> do
let old = ppEventLog log
let new = ppEventLog $ rewriteLog log
if old == new
then putStrLn (f ++ ": success") >> return True
else do
putStrLn $ diffLines old new
oops "re-written file does not match the original"

main :: IO ()
main = do
successes <- mapM testFile files
if and successes
then return ()
else exitFailure
successes <- mapM testFile files
unless (and successes) exitFailure