Skip to content

Commit

Permalink
Merge pull request #17 from well-typed/edsko/simplify-test-suite
Browse files Browse the repository at this point in the history
Simplify the test suite
  • Loading branch information
edsko authored Jan 14, 2025
2 parents e6b2dee + 9e59a0d commit 1e12b1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
39 changes: 12 additions & 27 deletions trace-foreign-calls/test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
module Main (main) where

import Control.Concurrent.Async (concurrently)
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.Runners (NumThreads(..))

import Test.TraceForeignCalls.UsePlugin

main :: IO ()
main = defaultMain $ localOption (NumThreads 1) $
testGroup "trace-foreign-calls" [
testCase "answerIO" $ do
answer <- answerIO
assertEqual "" 42 $ answer
, testCase "answerPure" $ do
let answer = answerPure
assertEqual "" 42 $ answer
, testCase "slowAddIO" $ do
let a = 1_000_000_000
b = 2_000_000_000
result <- slowAddIO a b
assertEqual "" (a + b) $ result
, testCase "slowAddPure" $ do
let a = 1_000_000_000
b = 2_000_000_000
let result = slowAddPure a b
assertEqual "" (a + b) $ result
, testCase "slowAddConcurrent" $ do
let a = 1_000_000_000
b = 2_000_000_000
(ab, ba) <- concurrently (slowAddIO a b) (slowAddIO b a)
assertEqual "" ab ba
]
main = do
print =<< answerIO
print $ answerPure
print =<< slowAddIO a b
print =<< slowAddIO b a
print $ slowAddPure a b
print $ slowAddPure b a
print =<< concurrently (slowAddIO a b) (slowAddIO b a)
print =<< concurrently (slowAddIO b a) (slowAddIO a b)
where
a = 1_000_000_000
b = 2_000_000_000
8 changes: 4 additions & 4 deletions trace-foreign-calls/test/Test/TraceForeignCalls/UsePlugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ module Test.TraceForeignCalls.UsePlugin (

import Foreign.C

foreign import capi "test_cbits.h answer" c_answerIO :: IO CInt
foreign import capi "test_cbits.h answer" c_answerPure :: CInt
foreign import capi unsafe "test_cbits.h answer" c_answerIO :: IO CInt
foreign import capi unsafe "test_cbits.h answer" c_answerPure :: CInt

foreign import capi "test_cbits.h slow_add" c_slowAddIO :: CLong -> CLong -> IO CLong
foreign import capi "test_cbits.h slow_add" c_slowAddPure :: CLong -> CLong -> CLong
foreign import capi unsafe "test_cbits.h slow_add" c_slowAddIO :: CLong -> CLong -> IO CLong
foreign import capi unsafe "test_cbits.h slow_add" c_slowAddPure :: CLong -> CLong -> CLong

answerIO :: IO Int
answerIO = fromIntegral <$> c_answerIO
Expand Down
4 changes: 1 addition & 3 deletions trace-foreign-calls/trace-foreign-calls.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test-suite test-trace-foreign-calls
exitcode-stdio-1.0
ghc-options:
-threaded
"-with-rtsopts -l -N"
"-with-rtsopts -l -N2"
cc-options:
-O0
hs-source-dirs:
Expand All @@ -81,7 +81,5 @@ test-suite test-trace-foreign-calls
build-depends:
-- external dependencies
, async
, tasty
, tasty-hunit


0 comments on commit 1e12b1b

Please sign in to comment.