Skip to content

Commit 3f7eca6

Browse files
committed
Add testcase for merge sort
1 parent fcc02be commit 3f7eca6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ghc-events.cabal

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ test-suite roundtrip
137137
hs-source-dirs: ., test
138138
build-depends: ghc-events, base
139139
extensions: RecordWildCards, NamedFieldPuns, BangPatterns, PatternGuards
140+
141+
test-suite merge-sort
142+
type: exitcode-stdio-1.0
143+
main-is: Sort.hs
144+
other-modules: Utils
145+
hs-source-dirs: ., test
146+
build-depends: ghc-events, base, bytestring, filepath, temporary
147+
extensions: RecordWildCards, NamedFieldPuns, BangPatterns, PatternGuards

test/Sort.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Control.Monad
2+
import System.Exit
3+
import System.FilePath
4+
import System.IO.Temp
5+
6+
import GHC.RTS.Events
7+
import qualified GHC.RTS.Events.Sort as Sort
8+
import Utils (files, diffLines)
9+
10+
-- | This is chosen to be small to ensure that we tickle the merge sort path.
11+
sortParams :: Sort.SortParams
12+
sortParams = Sort.SortParams { chunkSize = 1000, maxFanIn = 10 }
13+
14+
-- | Check that merge sort computes the same result as in-memory sort.
15+
checkSort :: FilePath -> IO Bool
16+
checkSort logFile = withSystemTempDirectory "check-sort" $ \tmpDir -> do
17+
Right eventlog <- readEventLogFromFile logFile
18+
Sort.sortEvents' sortParams tmpDir (tmpDir </> "out") eventlog
19+
let inMem = sortEvents $ events $ dat eventlog
20+
Right merged <- readEventLogFromFile (tmpDir </> "out")
21+
if show (events $ dat merged) == show inMem
22+
then return True
23+
else putStrLn "bad" >> return False
24+
25+
main :: IO ()
26+
main = do
27+
successes <- mapM checkSort files
28+
unless (and successes) exitFailure

0 commit comments

Comments
 (0)