summaryrefslogtreecommitdiff
path: root/testsuite/tests/concurrent/should_run/allocLimit4.hs
blob: b589ffa4afed5dce10e106f65d10207a2a64906c (plain)
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
module Main (main) where

import GHC.Conc
import Control.Concurrent
import Control.Exception
import System.Exit
import Control.Monad

-- check that +RTS -xq is doing the right thing: the test requires
-- +RTS -xq300k

main = do
  m <- newEmptyMVar
  let action = do
         e <- try $ do
          setAllocationCounter (10*1024)
          enableAllocationLimit
          print (length [1..])
         case e of
           Left AllocationLimitExceeded{} -> do
             c <- getAllocationCounter
             when (c < 250*1024 || c > 350*1024) $ fail "wrong limit grace"
             print (length [2..])
           Right _ ->
             fail "didn't catch AllocationLimitExceeded"

  forkFinally action (putMVar m)
  r <- takeMVar m
  case r of
    Left e | Just AllocationLimitExceeded <- fromException e -> return ()
    _ -> print r >> exitFailure