1 {-| Unittest runner for ganeti-htools.
7 Copyright (C) 2009, 2011, 2012 Google Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 module Main(main) where
28 import Data.Monoid (mappend)
30 import System.Environment (getArgs)
32 import Test.Ganeti.TestImports ()
33 import Test.Ganeti.BasicTypes
34 import Test.Ganeti.Confd.Utils
35 import Test.Ganeti.HTools.CLI
36 import Test.Ganeti.HTools.Cluster
37 import Test.Ganeti.HTools.Container
38 import Test.Ganeti.HTools.Loader
39 import Test.Ganeti.HTools.Instance
40 import Test.Ganeti.HTools.Node
41 import Test.Ganeti.HTools.PeerMap
42 import Test.Ganeti.HTools.Simu
43 import Test.Ganeti.HTools.Text
44 import Test.Ganeti.HTools.Types
45 import Test.Ganeti.HTools.Utils
46 import Test.Ganeti.Jobs
47 import Test.Ganeti.JSON
48 import Test.Ganeti.Luxi
49 import Test.Ganeti.Objects
50 import Test.Ganeti.OpCodes
51 import Test.Ganeti.Query.Language
52 import Test.Ganeti.Query.Query
53 import Test.Ganeti.Rpc
54 import Test.Ganeti.Ssconf
56 -- | Our default test options, overring the built-in test-framework
61 , topt_maximum_generated_tests = Just 500
62 , topt_maximum_unsuitable_generated_tests = Just 5000
63 , topt_maximum_test_size = Nothing
64 , topt_maximum_test_depth = Nothing
65 , topt_timeout = Nothing
68 -- | Our slow test options.
71 { topt_maximum_generated_tests = Just 50
72 , topt_maximum_unsuitable_generated_tests = Just 500
75 -- | All our defined tests.
76 allTests :: [(Bool, (String, [Test]))]
78 [ (True, testBasicTypes)
79 , (True, testConfd_Utils)
80 , (True, testHTools_CLI)
81 , (True, testHTools_Container)
82 , (True, testHTools_Instance)
83 , (True, testHTools_Loader)
84 , (True, testHTools_Node)
85 , (True, testHTools_PeerMap)
86 , (True, testHTools_Simu)
87 , (True, testHTools_Text)
88 , (True, testHTools_Types)
89 , (True, testHTools_Utils)
95 , (True, testQuery_Language)
96 , (True, testQuery_Query)
99 , (False, testHTools_Cluster)
100 , (False, testSlowObjects)
103 -- | Slow a test's max tests, if provided as such.
104 makeSlowOrFast :: Bool -> TestOptions -> TestOptions
105 makeSlowOrFast is_fast opts =
106 let template = if is_fast then fast else slow
107 fn_val v = if is_fast then v else v `div` 10
108 in case topt_maximum_generated_tests opts of
109 -- user didn't override the max_tests, so we'll do it here
110 Nothing -> opts `mappend` template
111 -- user did override, so we ignore the template and just directly
112 -- decrease the max_tests, if needed
113 Just max_tests -> opts { topt_maximum_generated_tests =
114 Just (fn_val max_tests)
117 -- | Main function. Note we don't use defaultMain since we want to
118 -- control explicitly our test sizes (and override the default).
121 ropts <- getArgs >>= interpretArgsOrExit
122 -- note: we do this overriding here since we need some groups to
123 -- have a smaller test count; so in effect we're basically
124 -- overriding t-f's inheritance here, but only for max_tests
125 let (act_fast, act_slow) =
126 case ropt_test_options ropts of
127 Nothing -> (fast, slow)
128 Just topts -> (makeSlowOrFast True topts, makeSlowOrFast False topts)
129 actual_opts is_fast = if is_fast then act_fast else act_slow
130 let tests = map (\(is_fast, (group_name, group_tests)) ->
131 plusTestOptions (actual_opts is_fast) $
132 testGroup group_name group_tests) allTests
133 defaultMainWithOpts tests ropts