From 9e59a0d5d9e6feeacb6b83a704a5ce78e4148904 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Tue, 14 Jan 2025 11:46:08 +0100 Subject: [PATCH] Simplify the test suite * The tasty stuff results in a more complicated eventlog, which is distracting. * Used `unsafe` rather than `safe` calls, to avoid GC interference. * Use only two capabilities. * Explore both `a+b` and `b+a` (slowAdd is slow in the _second_ arg) --- trace-foreign-calls/test/Main.hs | 39 ++++++------------- .../test/Test/TraceForeignCalls/UsePlugin.hs | 8 ++-- trace-foreign-calls/trace-foreign-calls.cabal | 4 +- 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/trace-foreign-calls/test/Main.hs b/trace-foreign-calls/test/Main.hs index 0dc059d..5eaec93 100644 --- a/trace-foreign-calls/test/Main.hs +++ b/trace-foreign-calls/test/Main.hs @@ -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 diff --git a/trace-foreign-calls/test/Test/TraceForeignCalls/UsePlugin.hs b/trace-foreign-calls/test/Test/TraceForeignCalls/UsePlugin.hs index 50b956f..f351383 100644 --- a/trace-foreign-calls/test/Test/TraceForeignCalls/UsePlugin.hs +++ b/trace-foreign-calls/test/Test/TraceForeignCalls/UsePlugin.hs @@ -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 diff --git a/trace-foreign-calls/trace-foreign-calls.cabal b/trace-foreign-calls/trace-foreign-calls.cabal index 2f8a4a9..5caf117 100644 --- a/trace-foreign-calls/trace-foreign-calls.cabal +++ b/trace-foreign-calls/trace-foreign-calls.cabal @@ -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: @@ -81,7 +81,5 @@ test-suite test-trace-foreign-calls build-depends: -- external dependencies , async - , tasty - , tasty-hunit