{-# LANGUAGE CPP #-}

{- FOURMOLU_DISABLE -}
module Main (main) where

import qualified Test.Crypto.DSIGN
import qualified Test.Crypto.Hash
import qualified Test.Crypto.KES
import qualified Test.Crypto.VRF
import qualified Test.Crypto.Regressions
#ifdef SECP256K1_ENABLED
import qualified Test.Crypto.Vector.Secp256k1DSIGN
#endif
import qualified Test.Crypto.EllipticCurve
import Test.Tasty (TestTree, adjustOption, testGroup, defaultMain)
import Test.Tasty.QuickCheck (QuickCheckTests (QuickCheckTests))
import Cardano.Crypto.Libsodium (sodiumInit)
import Test.Crypto.Util (Lock, mkLock)

main :: IO ()
IO ()
main = do
  IO ()
sodiumInit

  -- This lock is used to prevent tests that use mlocking from running
  -- concurrently. Concurrent execution of these tests can cause the testsuite
  -- to exhaust mlock quota; but each individual test on its own should be
  -- fine.
  Lock
mlockLock <- IO Lock
mkLock

  TestTree -> IO ()
defaultMain (Lock -> TestTree
tests Lock
mlockLock)

tests :: Lock -> TestTree
tests :: Lock -> TestTree
tests Lock
mlockLock =
  -- The default QuickCheck test count is 100. This is too few to catch
  -- anything, so we set a minimum of 1000.
  (QuickCheckTests -> QuickCheckTests) -> TestTree -> TestTree
forall v. IsOption v => (v -> v) -> TestTree -> TestTree
adjustOption (\(QuickCheckTests Int
i) -> Int -> QuickCheckTests
QuickCheckTests (Int -> QuickCheckTests) -> Int -> QuickCheckTests
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
i Int
1000) (TestTree -> TestTree)
-> ([TestTree] -> TestTree) -> [TestTree] -> TestTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    TestName -> [TestTree] -> TestTree
testGroup TestName
"cardano-crypto-class" ([TestTree] -> TestTree) -> [TestTree] -> TestTree
forall a b. (a -> b) -> a -> b
$
      [ Lock -> TestTree
Test.Crypto.DSIGN.tests Lock
mlockLock
      , Lock -> TestTree
Test.Crypto.Hash.tests Lock
mlockLock
      , Lock -> TestTree
Test.Crypto.KES.tests Lock
mlockLock
      , TestTree
Test.Crypto.VRF.tests
      , TestTree
Test.Crypto.Regressions.tests
#ifdef SECP256K1_ENABLED
      , TestTree
Test.Crypto.Vector.Secp256k1DSIGN.tests
#endif
      , TestTree
Test.Crypto.EllipticCurve.tests
      ]