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

Split tests into internal and external #12

Merged
merged 1 commit into from
Jun 14, 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
29 changes: 23 additions & 6 deletions blockio-uring.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ source-repository head

library
exposed-modules: System.IO.BlockIO
hs-source-dirs: src
other-modules:
System.IO.BlockIO.URing
System.IO.BlockIO.URingFFI

build-depends:
base >=4.12 && <4.20
, base >=4.12 && <4.20
, primitive ^>=0.9
, vector ^>=0.13

Expand All @@ -51,7 +52,7 @@ library
benchmark bench
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: benchmark .
hs-source-dirs: benchmark src
main-is: Bench.hs
build-depends:
, array
Expand All @@ -61,8 +62,8 @@ benchmark bench
, primitive
, random
, time
, vector
, unix
, vector

pkgconfig-depends: liburing
other-modules:
Expand All @@ -73,17 +74,33 @@ benchmark bench
ghc-options: -Wall -threaded

test-suite test
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: test.hs
build-depends:
, array
, base
, blockio-uring
, primitive
, tasty
, tasty-hunit
, vector

ghc-options: -threaded

test-suite test-internals
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test .
main-is: Main.hs
hs-source-dirs: test src
main-is: test-internals.hs
build-depends:
, array
, base
, primitive
, tasty
, vector
, tasty-hunit
, vector

pkgconfig-depends: liburing
other-modules:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 3 additions & 22 deletions test/Main.hs → test/test-internals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,27 @@ module Main (main) where

import Control.Exception (SomeException, try)
import Data.Word (Word64)
import System.IO.BlockIO
import System.IO.BlockIO.URing as URing
import System.IO.BlockIO.URing
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testGroup "test" [
tests = testGroup "test-internals" [
testCase "example_simpleNoop 1" $ example_simpleNoop 1
, testCase "example_simpleNoop maxBound" $ example_simpleNoop maxBound
, testCase "example_initClose" example_initClose
, testCase "example_closeIsIdempotent" example_closeIsIdempotent
]

example_simpleNoop :: Word64 -> Assertion
example_simpleNoop n = do
uring <- setupURing (URingParams 1)
prepareNop uring (IOOpId n)
URing.submitIO uring
submitIO uring
completion <- awaitIO uring
closeURing uring
IOCompletion (IOOpId n) (IOResult 0) @=? completion

deriving instance Eq IOCompletion
deriving instance Show IOCompletion

example_initClose :: Assertion
example_initClose = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx

example_closeIsIdempotent :: Assertion
example_closeIsIdempotent = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx
eith <- try @SomeException (closeIOCtx ctx)
case eith of
Left (e :: SomeException) ->
assertFailure ("Close on a closed context threw an error : " <> show e)
Right () ->
pure ()
31 changes: 31 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Main (main) where

import Control.Exception (SomeException, try)
import System.IO.BlockIO
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testGroup "test"
[ testCase "example_initClose" example_initClose
, testCase "example_closeIsIdempotent" example_closeIsIdempotent
]

example_initClose :: Assertion
example_initClose = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx

example_closeIsIdempotent :: Assertion
example_closeIsIdempotent = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx
eith <- try (closeIOCtx ctx)
case eith of
Left e ->
assertFailure ("Close on a closed context threw an error : " <> show (e :: SomeException))
Right () ->
pure ()
Loading