root / htools / test.hs @ adb77e3a
History | View | Annotate | Download (3.5 kB)
1 | 525bfb36 | Iustin Pop | {-| Unittest runner for ganeti-htools. |
---|---|---|---|
2 | 15f4c8ca | Iustin Pop | |
3 | 15f4c8ca | Iustin Pop | -} |
4 | 15f4c8ca | Iustin Pop | |
5 | e2fa2baf | Iustin Pop | {- |
6 | e2fa2baf | Iustin Pop | |
7 | e1dde6ad | Iustin Pop | Copyright (C) 2009, 2011, 2012 Google Inc. |
8 | e2fa2baf | Iustin Pop | |
9 | e2fa2baf | Iustin Pop | This program is free software; you can redistribute it and/or modify |
10 | e2fa2baf | Iustin Pop | it under the terms of the GNU General Public License as published by |
11 | e2fa2baf | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
12 | e2fa2baf | Iustin Pop | (at your option) any later version. |
13 | e2fa2baf | Iustin Pop | |
14 | e2fa2baf | Iustin Pop | This program is distributed in the hope that it will be useful, but |
15 | e2fa2baf | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | e2fa2baf | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | e2fa2baf | Iustin Pop | General Public License for more details. |
18 | e2fa2baf | Iustin Pop | |
19 | e2fa2baf | Iustin Pop | You should have received a copy of the GNU General Public License |
20 | e2fa2baf | Iustin Pop | along with this program; if not, write to the Free Software |
21 | e2fa2baf | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | e2fa2baf | Iustin Pop | 02110-1301, USA. |
23 | e2fa2baf | Iustin Pop | |
24 | e2fa2baf | Iustin Pop | -} |
25 | e2fa2baf | Iustin Pop | |
26 | 15f4c8ca | Iustin Pop | module Main(main) where |
27 | 15f4c8ca | Iustin Pop | |
28 | 95f6c931 | Iustin Pop | import Data.Monoid (mappend) |
29 | 95f6c931 | Iustin Pop | import Test.Framework |
30 | 7345b69b | Iustin Pop | import System.Environment (getArgs) |
31 | 38f536cb | Iustin Pop | |
32 | 15f4c8ca | Iustin Pop | import Ganeti.HTools.QC |
33 | 509809db | Iustin Pop | |
34 | 95f6c931 | Iustin Pop | -- | Our default test options, overring the built-in test-framework |
35 | 95f6c931 | Iustin Pop | -- ones. |
36 | 95f6c931 | Iustin Pop | fast :: TestOptions |
37 | 95f6c931 | Iustin Pop | fast = TestOptions |
38 | 95f6c931 | Iustin Pop | { topt_seed = Nothing |
39 | 95f6c931 | Iustin Pop | , topt_maximum_generated_tests = Just 500 |
40 | 95f6c931 | Iustin Pop | , topt_maximum_unsuitable_generated_tests = Just 5000 |
41 | 95f6c931 | Iustin Pop | , topt_maximum_test_size = Nothing |
42 | 95f6c931 | Iustin Pop | , topt_maximum_test_depth = Nothing |
43 | 95f6c931 | Iustin Pop | , topt_timeout = Nothing |
44 | 8e4f6d56 | Iustin Pop | } |
45 | 15f4c8ca | Iustin Pop | |
46 | 95f6c931 | Iustin Pop | -- | Our slow test options. |
47 | 95f6c931 | Iustin Pop | slow :: TestOptions |
48 | 95f6c931 | Iustin Pop | slow = fast |
49 | 95f6c931 | Iustin Pop | { topt_maximum_generated_tests = Just 50 |
50 | 95f6c931 | Iustin Pop | , topt_maximum_unsuitable_generated_tests = Just 500 |
51 | 8e4f6d56 | Iustin Pop | } |
52 | 38f536cb | Iustin Pop | |
53 | 95f6c931 | Iustin Pop | -- | All our defined tests. |
54 | 95f6c931 | Iustin Pop | allTests :: [(Bool, (String, [Test]))] |
55 | 06fe0cea | Iustin Pop | allTests = |
56 | 95f6c931 | Iustin Pop | [ (True, testUtils) |
57 | 95f6c931 | Iustin Pop | , (True, testPeerMap) |
58 | 95f6c931 | Iustin Pop | , (True, testContainer) |
59 | 95f6c931 | Iustin Pop | , (True, testInstance) |
60 | 95f6c931 | Iustin Pop | , (True, testNode) |
61 | 95f6c931 | Iustin Pop | , (True, testText) |
62 | 95f6c931 | Iustin Pop | , (True, testSimu) |
63 | 95f6c931 | Iustin Pop | , (True, testOpCodes) |
64 | 95f6c931 | Iustin Pop | , (True, testJobs) |
65 | 95f6c931 | Iustin Pop | , (True, testLoader) |
66 | 95f6c931 | Iustin Pop | , (True, testTypes) |
67 | 95f6c931 | Iustin Pop | , (True, testCLI) |
68 | 95f6c931 | Iustin Pop | , (True, testJSON) |
69 | 2c4eb054 | Iustin Pop | , (True, testLuxi) |
70 | 95f6c931 | Iustin Pop | , (True, testSsconf) |
71 | 95f6c931 | Iustin Pop | , (True, testQlang) |
72 | 95f6c931 | Iustin Pop | , (True, testRpc) |
73 | 998b6f8b | Iustin Pop | , (True, testConfd) |
74 | adb77e3a | Iustin Pop | , (True, testObjects) |
75 | 95f6c931 | Iustin Pop | , (False, testCluster) |
76 | 06fe0cea | Iustin Pop | ] |
77 | 06fe0cea | Iustin Pop | |
78 | 95f6c931 | Iustin Pop | -- | Slow a test's max tests, if provided as such. |
79 | 95f6c931 | Iustin Pop | makeSlowOrFast :: Bool -> TestOptions -> TestOptions |
80 | 95f6c931 | Iustin Pop | makeSlowOrFast is_fast opts = |
81 | 95f6c931 | Iustin Pop | let template = if is_fast then fast else slow |
82 | 95f6c931 | Iustin Pop | fn_val v = if is_fast then v else v `div` 10 |
83 | 95f6c931 | Iustin Pop | in case topt_maximum_generated_tests opts of |
84 | 95f6c931 | Iustin Pop | -- user didn't override the max_tests, so we'll do it here |
85 | 95f6c931 | Iustin Pop | Nothing -> opts `mappend` template |
86 | 95f6c931 | Iustin Pop | -- user did override, so we ignore the template and just directly |
87 | 95f6c931 | Iustin Pop | -- decrease the max_tests, if needed |
88 | 95f6c931 | Iustin Pop | Just max_tests -> opts { topt_maximum_generated_tests = |
89 | 95f6c931 | Iustin Pop | Just (fn_val max_tests) |
90 | 95f6c931 | Iustin Pop | } |
91 | 95f6c931 | Iustin Pop | |
92 | 95f6c931 | Iustin Pop | -- | Main function. Note we don't use defaultMain since we want to |
93 | 95f6c931 | Iustin Pop | -- control explicitly our test sizes (and override the default). |
94 | 38f536cb | Iustin Pop | main :: IO () |
95 | 15f4c8ca | Iustin Pop | main = do |
96 | 95f6c931 | Iustin Pop | ropts <- getArgs >>= interpretArgsOrExit |
97 | 95f6c931 | Iustin Pop | -- note: we do this overriding here since we need some groups to |
98 | 95f6c931 | Iustin Pop | -- have a smaller test count; so in effect we're basically |
99 | 95f6c931 | Iustin Pop | -- overriding t-f's inheritance here, but only for max_tests |
100 | 95f6c931 | Iustin Pop | let (act_fast, act_slow) = |
101 | 95f6c931 | Iustin Pop | case ropt_test_options ropts of |
102 | 95f6c931 | Iustin Pop | Nothing -> (fast, slow) |
103 | 95f6c931 | Iustin Pop | Just topts -> (makeSlowOrFast True topts, makeSlowOrFast False topts) |
104 | 95f6c931 | Iustin Pop | actual_opts is_fast = if is_fast then act_fast else act_slow |
105 | 95f6c931 | Iustin Pop | let tests = map (\(is_fast, (group_name, group_tests)) -> |
106 | 95f6c931 | Iustin Pop | plusTestOptions (actual_opts is_fast) $ |
107 | 95f6c931 | Iustin Pop | testGroup group_name group_tests) allTests |
108 | 95f6c931 | Iustin Pop | defaultMainWithOpts tests ropts |