Statistics
| Branch: | Tag: | Revision:

root / htest / test.hs @ 51000365

History | View | Annotate | Download (4.5 kB)

1
{-| Unittest runner for ganeti-htools.
2

    
3
-}
4

    
5
{-
6

    
7
Copyright (C) 2009, 2011, 2012 Google Inc.
8

    
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.
13

    
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.
18

    
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
22
02110-1301, USA.
23

    
24
-}
25

    
26
module Main(main) where
27

    
28
import Data.Monoid (mappend)
29
import Test.Framework
30
import System.Environment (getArgs)
31

    
32
import Test.Ganeti.TestImports ()
33
import Test.Ganeti.BasicTypes
34
import Test.Ganeti.Confd.Utils
35
import Test.Ganeti.Common
36
import Test.Ganeti.Daemon
37
import Test.Ganeti.HTools.CLI
38
import Test.Ganeti.HTools.Cluster
39
import Test.Ganeti.HTools.Container
40
import Test.Ganeti.HTools.Loader
41
import Test.Ganeti.HTools.Instance
42
import Test.Ganeti.HTools.Node
43
import Test.Ganeti.HTools.PeerMap
44
import Test.Ganeti.HTools.Simu
45
import Test.Ganeti.HTools.Text
46
import Test.Ganeti.HTools.Types
47
import Test.Ganeti.HTools.Utils
48
import Test.Ganeti.Jobs
49
import Test.Ganeti.JSON
50
import Test.Ganeti.Luxi
51
import Test.Ganeti.Objects
52
import Test.Ganeti.OpCodes
53
import Test.Ganeti.Query.Filter
54
import Test.Ganeti.Query.Language
55
import Test.Ganeti.Query.Query
56
import Test.Ganeti.Rpc
57
import Test.Ganeti.Ssconf
58

    
59
-- | Our default test options, overring the built-in test-framework
60
-- ones.
61
fast :: TestOptions
62
fast = TestOptions
63
       { topt_seed                               = Nothing
64
       , topt_maximum_generated_tests            = Just 500
65
       , topt_maximum_unsuitable_generated_tests = Just 5000
66
       , topt_maximum_test_size                  = Nothing
67
       , topt_maximum_test_depth                 = Nothing
68
       , topt_timeout                            = Nothing
69
       }
70

    
71
-- | Our slow test options.
72
slow :: TestOptions
73
slow = fast
74
       { topt_maximum_generated_tests            = Just 50
75
       , topt_maximum_unsuitable_generated_tests = Just 500
76
       }
77

    
78
-- | All our defined tests.
79
allTests :: [(Bool, (String, [Test]))]
80
allTests =
81
  [ (True, testBasicTypes)
82
  , (True, testConfd_Utils)
83
  , (True, testCommon)
84
  , (True, testDaemon)
85
  , (True, testHTools_CLI)
86
  , (True, testHTools_Container)
87
  , (True, testHTools_Instance)
88
  , (True, testHTools_Loader)
89
  , (True, testHTools_Node)
90
  , (True, testHTools_PeerMap)
91
  , (True, testHTools_Simu)
92
  , (True, testHTools_Text)
93
  , (True, testHTools_Types)
94
  , (True, testHTools_Utils)
95
  , (True, testJSON)
96
  , (True, testJobs)
97
  , (True, testLuxi)
98
  , (True, testObjects)
99
  , (True, testOpCodes)
100
  , (True, testQuery_Filter)
101
  , (True, testQuery_Language)
102
  , (True, testQuery_Query)
103
  , (True, testRpc)
104
  , (True, testSsconf)
105
  , (False, testHTools_Cluster)
106
  , (False, testSlowObjects)
107
  ]
108

    
109
-- | Slow a test's max tests, if provided as such.
110
makeSlowOrFast :: Bool -> TestOptions -> TestOptions
111
makeSlowOrFast is_fast opts =
112
  let template = if is_fast then fast else slow
113
      fn_val v = if is_fast then v else v `div` 10
114
  in case topt_maximum_generated_tests opts of
115
       -- user didn't override the max_tests, so we'll do it here
116
       Nothing -> opts `mappend` template
117
       -- user did override, so we ignore the template and just directly
118
       -- decrease the max_tests, if needed
119
       Just max_tests -> opts { topt_maximum_generated_tests =
120
                                  Just (fn_val max_tests)
121
                              }
122

    
123
-- | Main function. Note we don't use defaultMain since we want to
124
-- control explicitly our test sizes (and override the default).
125
main :: IO ()
126
main = do
127
  ropts <- getArgs >>= interpretArgsOrExit
128
  -- note: we do this overriding here since we need some groups to
129
  -- have a smaller test count; so in effect we're basically
130
  -- overriding t-f's inheritance here, but only for max_tests
131
  let (act_fast, act_slow) =
132
       case ropt_test_options ropts of
133
         Nothing -> (fast, slow)
134
         Just topts -> (makeSlowOrFast True topts, makeSlowOrFast False topts)
135
      actual_opts is_fast = if is_fast then act_fast else act_slow
136
  let tests = map (\(is_fast, (group_name, group_tests)) ->
137
                     plusTestOptions (actual_opts is_fast) $
138
                     testGroup group_name group_tests) allTests
139
  defaultMainWithOpts tests ropts