Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export ingredients provided by library #6

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Changes in 0.1.2.0

- `benchIngredients`, `consoleBenchReporter`, `csvReporter` are exported.


* Changes in 0.1.1.0

- Human readable error messages not just bare error codes
Expand Down
36 changes: 27 additions & 9 deletions Test/Tasty/PAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ looks similar to one using @criterion@, @gauge@ or @tasty-bench@:

> module Main where
> import Test.Tasty.PAPI
>
>
> main :: IO ()
> main = defaultMain
> [ bench "6" $ whnf fib 6
> , bench "7" $ whnf fib 7
> , bench "8" $ whnf fib 8
> ]
>
>
> fib :: Integer -> Integer
> fib 0 = 0
> fib 1 = 1
Expand Down Expand Up @@ -72,7 +72,7 @@ provided by this package:
-}
module Test.Tasty.PAPI
( -- * Running benchmarks
Test.Tasty.PAPI.defaultMain
defaultMain
, Benchmark
, Benchmarkable(..)
, bench
Expand All @@ -82,6 +82,10 @@ module Test.Tasty.PAPI
, whnf
, nfIO
, whnfIO
-- * Ingredients
, benchIngredients
, consoleBenchReporter
, csvReporter
-- * Data types
, Counter(..)
) where
Expand All @@ -104,7 +108,7 @@ import System.Exit
import System.IO
import Text.Printf

import Test.Tasty
import Test.Tasty hiding (defaultMain)
import Test.Tasty.Ingredients
import Test.Tasty.Ingredients.ConsoleReporter
import Test.Tasty.Options
Expand All @@ -123,7 +127,7 @@ newtype EventSet = EventSet CInt
foreign import capi "papi.h value PAPI_OK" papi_OK :: CInt
foreign import capi "papi.h value PAPI_NULL" papi_NULL :: CInt
foreign import capi "papi.h value PAPI_VER_CURRENT" papi_VER_CURRENT :: CInt

foreign import capi "papi.h value PAPI_L1_DCM" papi_L1_DCM :: CInt
foreign import capi "papi.h value PAPI_L1_ICM" papi_L1_ICM :: CInt
foreign import capi "papi.h value PAPI_L2_DCM" papi_L2_DCM :: CInt
Expand Down Expand Up @@ -281,7 +285,7 @@ withPapiEventSet action = do
call "Failed to destroy eventset" $ papi_destroy_eventset p_evt

-- | Supported hardware counters
--
--
-- Documentation is taken from rather outdated manual:
-- https://icl.utk.edu/projects/papi/files/documentation/PAPI_USER_GUIDE_23.htm
data Counter
Expand Down Expand Up @@ -662,22 +666,36 @@ nfIO io = Benchmarkable $ do a <- io
-- @since 0.1
defaultMain :: [TestTree] -> IO ()
defaultMain
= defaultMainWithIngredients [ listingTests
, consoleBenchReporter `composeReporters` csvReporter
]
= defaultMainWithIngredients benchIngredients
. testGroup "All"


----------------------------------------------------------------
-- Reporters
----------------------------------------------------------------

-- | Standard set of ingredients which are used by 'defaultMain'
--
-- @since 0.1.2.0
benchIngredients :: [Ingredient]
benchIngredients =
[ listingTests
, consoleBenchReporter `composeReporters` csvReporter
]

-- | Reporter which prints results on benchmarks to stdout.
--
-- @since 0.1.2.0
consoleBenchReporter :: Ingredient
consoleBenchReporter = consoleTestReporterWithHook $ \_ r -> do
case reads @[CLLong] $ resultDescription r of
[(_,s)] -> pure r { resultDescription = s }
_ -> pure r

-- | Run benchmarks and save results in CSV format. It activates when
-- @--csv@ FILE command line option is specified.
--
-- @since 0.1.2.0
csvReporter :: Ingredient
csvReporter = TestReporter [Option (Proxy @(Maybe CsvPath)), Option (Proxy @CounterSet)] $
\opts tree -> do
Expand Down
4 changes: 2 additions & 2 deletions tasty-papi.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tasty-papi
version: 0.1.1.0
version: 0.1.2.0
cabal-version: 1.18
license: BSD3
license-file: LICENSE
Expand Down Expand Up @@ -51,4 +51,4 @@ test-suite tasty-papi-run
--
Build-Depends: base -any
, tasty -any
, tasty-papi -any
, tasty-papi -any