test.hs 4.15 KB
Newer Older
1
{-| Unittest runner for ganeti-htools.
2
3
4

-}

Iustin Pop's avatar
Iustin Pop committed
5
6
{-

7
Copyright (C) 2009, 2011, 2012 Google Inc.
Iustin Pop's avatar
Iustin Pop committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

-}

26
27
module Main(main) where

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

32
import Test.Ganeti.TestImports ()
33
import Test.Ganeti.Confd.Utils
34
35
36
37
38
39
40
41
42
43
44
import Test.Ganeti.HTools.CLI
import Test.Ganeti.HTools.Cluster
import Test.Ganeti.HTools.Container
import Test.Ganeti.HTools.Loader
import Test.Ganeti.HTools.Instance
import Test.Ganeti.HTools.Node
import Test.Ganeti.HTools.PeerMap
import Test.Ganeti.HTools.Simu
import Test.Ganeti.HTools.Text
import Test.Ganeti.HTools.Types
import Test.Ganeti.HTools.Utils
45
46
import Test.Ganeti.Jobs
import Test.Ganeti.JSON
47
import Test.Ganeti.Luxi
Iustin Pop's avatar
Iustin Pop committed
48
import Test.Ganeti.Objects
49
50
import Test.Ganeti.OpCodes
import Test.Ganeti.Query.Language
Iustin Pop's avatar
Iustin Pop committed
51
import Test.Ganeti.Rpc
52
import Test.Ganeti.Ssconf
53

54
55
56
57
58
59
60
61
62
63
-- | Our default test options, overring the built-in test-framework
-- ones.
fast :: TestOptions
fast = TestOptions
       { topt_seed                               = Nothing
       , topt_maximum_generated_tests            = Just 500
       , topt_maximum_unsuitable_generated_tests = Just 5000
       , topt_maximum_test_size                  = Nothing
       , topt_maximum_test_depth                 = Nothing
       , topt_timeout                            = Nothing
Iustin Pop's avatar
Iustin Pop committed
64
       }
65

66
67
68
69
70
-- | Our slow test options.
slow :: TestOptions
slow = fast
       { topt_maximum_generated_tests            = Just 50
       , topt_maximum_unsuitable_generated_tests = Just 500
Iustin Pop's avatar
Iustin Pop committed
71
       }
72

73
74
-- | All our defined tests.
allTests :: [(Bool, (String, [Test]))]
Iustin Pop's avatar
Iustin Pop committed
75
allTests =
76
77
78
79
80
81
82
83
84
85
86
87
88
  [ (True, testUtils)
  , (True, testPeerMap)
  , (True, testContainer)
  , (True, testInstance)
  , (True, testNode)
  , (True, testText)
  , (True, testSimu)
  , (True, testOpCodes)
  , (True, testJobs)
  , (True, testLoader)
  , (True, testTypes)
  , (True, testCLI)
  , (True, testJSON)
89
  , (True, testLuxi)
90
91
92
  , (True, testSsconf)
  , (True, testQlang)
  , (True, testRpc)
93
  , (True, testConfdUtils)
Iustin Pop's avatar
Iustin Pop committed
94
  , (True, testObjects)
95
  , (False, testCluster)
Iustin Pop's avatar
Iustin Pop committed
96
97
  ]

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-- | Slow a test's max tests, if provided as such.
makeSlowOrFast :: Bool -> TestOptions -> TestOptions
makeSlowOrFast is_fast opts =
  let template = if is_fast then fast else slow
      fn_val v = if is_fast then v else v `div` 10
  in case topt_maximum_generated_tests opts of
       -- user didn't override the max_tests, so we'll do it here
       Nothing -> opts `mappend` template
       -- user did override, so we ignore the template and just directly
       -- decrease the max_tests, if needed
       Just max_tests -> opts { topt_maximum_generated_tests =
                                  Just (fn_val max_tests)
                              }

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