Skip to content
Snippets Groups Projects
Commit 509809db authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: allow unittest to be replayed


This just adds glue to allow replaying of tests using a given RNG state
and test size (both are needed for exact replayability).

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent a1cd7c1e
No related merge requests found
...@@ -67,6 +67,7 @@ module Ganeti.HTools.CLI ...@@ -67,6 +67,7 @@ module Ganeti.HTools.CLI
, oPrintNodes , oPrintNodes
, oQuiet , oQuiet
, oRapiMaster , oRapiMaster
, oReplay
, oSaveCluster , oSaveCluster
, oShowHelp , oShowHelp
, oShowVer , oShowVer
...@@ -126,6 +127,7 @@ data Options = Options ...@@ -126,6 +127,7 @@ data Options = Options
, optShowNodes :: Maybe [String] -- ^ Whether to show node status , optShowNodes :: Maybe [String] -- ^ Whether to show node status
, optShowVer :: Bool -- ^ Just show the program version , optShowVer :: Bool -- ^ Just show the program version
, optTieredSpec :: Maybe RSpec -- ^ Requested specs for tiered mode , optTieredSpec :: Maybe RSpec -- ^ Requested specs for tiered mode
, optReplay :: Maybe String -- ^ Unittests: RNG state
, optVerbose :: Int -- ^ Verbosity level , optVerbose :: Int -- ^ Verbosity level
} deriving Show } deriving Show
...@@ -164,6 +166,7 @@ defaultOptions = Options ...@@ -164,6 +166,7 @@ defaultOptions = Options
, optShowNodes = Nothing , optShowNodes = Nothing
, optShowVer = False , optShowVer = False
, optTieredSpec = Nothing , optTieredSpec = Nothing
, optReplay = Nothing
, optVerbose = 1 , optVerbose = 1
} }
...@@ -381,6 +384,11 @@ oTieredSpec = Option "" ["tiered-alloc"] ...@@ -381,6 +384,11 @@ oTieredSpec = Option "" ["tiered-alloc"]
"TSPEC") "TSPEC")
"enable tiered specs allocation, given as 'disk,ram,cpu'" "enable tiered specs allocation, given as 'disk,ram,cpu'"
oReplay :: OptType
oReplay = Option "" ["replay"]
(ReqArg (\ stat opts -> Ok opts { optReplay = Just stat } ) "STATE")
"Pre-seed the random number generator with STATE"
oVerbose :: OptType oVerbose :: OptType
oVerbose = Option "v" ["verbose"] oVerbose = Option "v" ["verbose"]
(NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 })) (NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 }))
......
...@@ -27,12 +27,24 @@ module Main(main) where ...@@ -27,12 +27,24 @@ module Main(main) where
import Data.IORef import Data.IORef
import Test.QuickCheck import Test.QuickCheck
import System.Console.GetOpt
import System.IO import System.IO
import System.Exit import System.Exit
import System (getArgs) import System (getArgs)
import Text.Printf import Text.Printf
import Ganeti.HTools.QC import Ganeti.HTools.QC
import Ganeti.HTools.CLI
import Ganeti.HTools.Utils (sepSplit)
-- | Options list and functions
options :: [OptType]
options =
[ oReplay
, oVerbose
, oShowVer
, oShowHelp
]
fast :: Args fast :: Args
fast = stdArgs fast = stdArgs
...@@ -101,16 +113,32 @@ allTests = ...@@ -101,16 +113,32 @@ allTests =
, ("Cluster", slow, testCluster) , ("Cluster", slow, testCluster)
] ]
transformTestOpts :: Args -> Options -> IO Args
transformTestOpts args opts = do
r <- case optReplay opts of
Nothing -> return Nothing
Just str -> do
let vs = sepSplit ',' str
(case vs of
[rng, size] -> return $ Just (read rng, read size)
_ -> fail "Invalid state given")
return args { chatty = optVerbose opts > 1,
replay = r
}
main :: IO () main :: IO ()
main = do main = do
errs <- newIORef 0 errs <- newIORef 0
let wrap = map (wrapTest errs) let wrap = map (wrapTest errs)
args <- getArgs cmd_args <- System.getArgs
(opts, args) <- parseOpts cmd_args "test" options
let tests = if null args let tests = if null args
then allTests then allTests
else filter (\(name, _, _) -> name `elem` args) allTests else filter (\(name, _, _) -> name `elem` args) allTests
max_count = maximum $ map (\(_, _, t) -> length t) tests max_count = maximum $ map (\(_, _, t) -> length t) tests
mapM_ (\(name, opts, tl) -> runTests name opts (wrap tl) max_count) tests mapM_ (\(name, targs, tl) ->
transformTestOpts targs opts >>= \newargs ->
runTests name newargs (wrap tl) max_count) tests
terr <- readIORef errs terr <- readIORef errs
(if terr > 0 (if terr > 0
then do then do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment