test.hs 4.43 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.BasicTypes
34
import Test.Ganeti.Confd.Utils
35 36 37 38 39 40 41 42 43 44 45
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
46 47
import Test.Ganeti.Jobs
import Test.Ganeti.JSON
48
import Test.Ganeti.Luxi
Iustin Pop's avatar
Iustin Pop committed
49
import Test.Ganeti.Objects
50
import Test.Ganeti.OpCodes
Iustin Pop's avatar
Iustin Pop committed
51
import Test.Ganeti.Query.Filter
52
import Test.Ganeti.Query.Language
53
import Test.Ganeti.Query.Query
Iustin Pop's avatar
Iustin Pop committed
54
import Test.Ganeti.Rpc
55
import Test.Ganeti.Ssconf
56

57 58 59 60 61 62 63 64 65 66
-- | 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
67
       }
68

69 70 71 72 73
-- | 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
74
       }
75

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

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
-- | 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).
121
main :: IO ()
122
main = do
123 124 125 126 127 128 129 130 131 132 133 134 135
  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