diff --git a/blockio-uring.cabal b/blockio-uring.cabal index 8f4c4a5..c82bacc 100644 --- a/blockio-uring.cabal +++ b/blockio-uring.cabal @@ -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 @@ -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 @@ -61,8 +62,8 @@ benchmark bench , primitive , random , time - , vector , unix + , vector pkgconfig-depends: liburing other-modules: @@ -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: diff --git a/System/IO/BlockIO.hs b/src/System/IO/BlockIO.hs similarity index 100% rename from System/IO/BlockIO.hs rename to src/System/IO/BlockIO.hs diff --git a/System/IO/BlockIO/URing.hs b/src/System/IO/BlockIO/URing.hs similarity index 100% rename from System/IO/BlockIO/URing.hs rename to src/System/IO/BlockIO/URing.hs diff --git a/System/IO/BlockIO/URingFFI.hsc b/src/System/IO/BlockIO/URingFFI.hsc similarity index 100% rename from System/IO/BlockIO/URingFFI.hsc rename to src/System/IO/BlockIO/URingFFI.hsc diff --git a/test/Main.hs b/test/test-internals.hs similarity index 55% rename from test/Main.hs rename to test/test-internals.hs index aed0182..9edc445 100644 --- a/test/Main.hs +++ b/test/test-internals.hs @@ -10,8 +10,7 @@ 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 @@ -19,37 +18,19 @@ 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 () diff --git a/test/test.hs b/test/test.hs new file mode 100644 index 0000000..5d25b59 --- /dev/null +++ b/test/test.hs @@ -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 ()