Revision 509809db
b/htools/Ganeti/HTools/CLI.hs | ||
---|---|---|
67 | 67 |
, oPrintNodes |
68 | 68 |
, oQuiet |
69 | 69 |
, oRapiMaster |
70 |
, oReplay |
|
70 | 71 |
, oSaveCluster |
71 | 72 |
, oShowHelp |
72 | 73 |
, oShowVer |
... | ... | |
126 | 127 |
, optShowNodes :: Maybe [String] -- ^ Whether to show node status |
127 | 128 |
, optShowVer :: Bool -- ^ Just show the program version |
128 | 129 |
, optTieredSpec :: Maybe RSpec -- ^ Requested specs for tiered mode |
130 |
, optReplay :: Maybe String -- ^ Unittests: RNG state |
|
129 | 131 |
, optVerbose :: Int -- ^ Verbosity level |
130 | 132 |
} deriving Show |
131 | 133 |
|
... | ... | |
164 | 166 |
, optShowNodes = Nothing |
165 | 167 |
, optShowVer = False |
166 | 168 |
, optTieredSpec = Nothing |
169 |
, optReplay = Nothing |
|
167 | 170 |
, optVerbose = 1 |
168 | 171 |
} |
169 | 172 |
|
... | ... | |
381 | 384 |
"TSPEC") |
382 | 385 |
"enable tiered specs allocation, given as 'disk,ram,cpu'" |
383 | 386 |
|
387 |
oReplay :: OptType |
|
388 |
oReplay = Option "" ["replay"] |
|
389 |
(ReqArg (\ stat opts -> Ok opts { optReplay = Just stat } ) "STATE") |
|
390 |
"Pre-seed the random number generator with STATE" |
|
391 |
|
|
384 | 392 |
oVerbose :: OptType |
385 | 393 |
oVerbose = Option "v" ["verbose"] |
386 | 394 |
(NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 })) |
b/htools/test.hs | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import Data.IORef |
29 | 29 |
import Test.QuickCheck |
30 |
import System.Console.GetOpt |
|
30 | 31 |
import System.IO |
31 | 32 |
import System.Exit |
32 | 33 |
import System (getArgs) |
33 | 34 |
import Text.Printf |
34 | 35 |
|
35 | 36 |
import Ganeti.HTools.QC |
37 |
import Ganeti.HTools.CLI |
|
38 |
import Ganeti.HTools.Utils (sepSplit) |
|
39 |
|
|
40 |
-- | Options list and functions |
|
41 |
options :: [OptType] |
|
42 |
options = |
|
43 |
[ oReplay |
|
44 |
, oVerbose |
|
45 |
, oShowVer |
|
46 |
, oShowHelp |
|
47 |
] |
|
36 | 48 |
|
37 | 49 |
fast :: Args |
38 | 50 |
fast = stdArgs |
... | ... | |
101 | 113 |
, ("Cluster", slow, testCluster) |
102 | 114 |
] |
103 | 115 |
|
116 |
transformTestOpts :: Args -> Options -> IO Args |
|
117 |
transformTestOpts args opts = do |
|
118 |
r <- case optReplay opts of |
|
119 |
Nothing -> return Nothing |
|
120 |
Just str -> do |
|
121 |
let vs = sepSplit ',' str |
|
122 |
(case vs of |
|
123 |
[rng, size] -> return $ Just (read rng, read size) |
|
124 |
_ -> fail "Invalid state given") |
|
125 |
return args { chatty = optVerbose opts > 1, |
|
126 |
replay = r |
|
127 |
} |
|
128 |
|
|
104 | 129 |
main :: IO () |
105 | 130 |
main = do |
106 | 131 |
errs <- newIORef 0 |
107 | 132 |
let wrap = map (wrapTest errs) |
108 |
args <- getArgs |
|
133 |
cmd_args <- System.getArgs |
|
134 |
(opts, args) <- parseOpts cmd_args "test" options |
|
109 | 135 |
let tests = if null args |
110 | 136 |
then allTests |
111 | 137 |
else filter (\(name, _, _) -> name `elem` args) allTests |
112 | 138 |
max_count = maximum $ map (\(_, _, t) -> length t) tests |
113 |
mapM_ (\(name, opts, tl) -> runTests name opts (wrap tl) max_count) tests |
|
139 |
mapM_ (\(name, targs, tl) -> |
|
140 |
transformTestOpts targs opts >>= \newargs -> |
|
141 |
runTests name newargs (wrap tl) max_count) tests |
|
114 | 142 |
terr <- readIORef errs |
115 | 143 |
(if terr > 0 |
116 | 144 |
then do |
Also available in: Unified diff