2016-05-07 04:14:27 +03:00
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module ProfileTests where
|
|
|
|
|
|
|
|
import Haxl.Prelude
|
|
|
|
import Data.List
|
|
|
|
|
|
|
|
import Haxl.Core
|
|
|
|
|
|
|
|
import Test.HUnit
|
|
|
|
|
|
|
|
import Data.IORef
|
|
|
|
import qualified Data.HashMap.Strict as HashMap
|
|
|
|
import qualified Data.HashSet as HashSet
|
|
|
|
|
|
|
|
import TestUtils
|
|
|
|
|
|
|
|
mkProfilingEnv = do
|
|
|
|
env <- makeTestEnv
|
|
|
|
return env { flags = (flags env) { report = 4 } }
|
|
|
|
|
|
|
|
collectsdata :: Assertion
|
|
|
|
collectsdata = do
|
|
|
|
env <- mkProfilingEnv
|
|
|
|
_x <- runHaxl env $
|
|
|
|
withLabel "bar" $
|
|
|
|
withLabel "foo" $
|
|
|
|
if length (intersect ["a"::Text, "b"] ["c"]) > 1
|
|
|
|
then return 5
|
|
|
|
else return (4::Int)
|
2016-06-04 01:23:22 +03:00
|
|
|
profData <- profile <$> readIORef (profRef env)
|
2016-05-07 04:14:27 +03:00
|
|
|
assertEqual "has data" 3 $ HashMap.size profData
|
2016-05-17 14:01:41 +03:00
|
|
|
assertBool "foo allocates" $
|
|
|
|
case profileAllocs <$> HashMap.lookup "foo" profData of
|
|
|
|
Just x -> x > 0
|
|
|
|
Nothing -> False
|
2016-05-07 04:14:27 +03:00
|
|
|
assertEqual "bar does not allocate" (Just 0) $
|
|
|
|
profileAllocs <$> HashMap.lookup "bar" profData
|
|
|
|
assertEqual "foo's parent" (Just ["bar"]) $
|
|
|
|
HashSet.toList . profileDeps <$> HashMap.lookup "foo" profData
|
|
|
|
|
|
|
|
tests = TestList
|
|
|
|
[ TestLabel "collectsdata" $ TestCase collectsdata
|
|
|
|
]
|