File: WriteMerge.hs

package info (click to toggle)
haskell-ghc-events 0.19.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,396 kB
  • sloc: haskell: 3,552; ansic: 146; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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.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"]

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 = 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
  unless (and successes) exitFailure