1 /*
2 * Author: Karl MacMillan <kmacmillan@tresys.com>
3 *
4 * Copyright (C) 2006 Tresys Technology, LLC
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "test-cond.h"
22 #include "test-linker.h"
23 #include "test-expander.h"
24 #include "test-deps.h"
25 #include "test-downgrade.h"
26
27 #include <CUnit/Basic.h>
28 #include <CUnit/Console.h>
29 #include <CUnit/TestDB.h>
30
31 #include <stdbool.h>
32 #include <stdio.h>
33 #include <getopt.h>
34 #include <stdlib.h>
35
36 int mls;
37
38 #define DECLARE_SUITE(name) \
39 do { \
40 suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \
41 if (NULL == suite) { \
42 CU_cleanup_registry(); \
43 return CU_get_error(); \
44 } \
45 if (name##_add_tests(suite)) { \
46 CU_cleanup_registry(); \
47 return CU_get_error(); \
48 } \
49 } while (0)
50
usage(char * progname)51 static void usage(char *progname)
52 {
53 printf("usage: %s [options]\n", progname);
54 printf("options:\n");
55 printf("\t-v, --verbose\t\t\tverbose output\n");
56 printf("\t-i, --interactive\t\tinteractive console\n");
57 }
58
do_tests(int interactive,int verbose)59 static bool do_tests(int interactive, int verbose)
60 {
61 CU_pSuite suite = NULL;
62 unsigned int num_failures;
63
64 if (CUE_SUCCESS != CU_initialize_registry())
65 return CU_get_error();
66
67 DECLARE_SUITE(cond);
68 DECLARE_SUITE(linker);
69 DECLARE_SUITE(expander);
70 DECLARE_SUITE(deps);
71 DECLARE_SUITE(downgrade);
72
73 if (verbose)
74 CU_basic_set_mode(CU_BRM_VERBOSE);
75 else
76 CU_basic_set_mode(CU_BRM_NORMAL);
77
78 if (interactive)
79 CU_console_run_tests();
80 else
81 CU_basic_run_tests();
82 num_failures = CU_get_number_of_tests_failed();
83 CU_cleanup_registry();
84 return CU_get_error() == CUE_SUCCESS && num_failures == 0;
85
86 }
87
main(int argc,char ** argv)88 int main(int argc, char **argv)
89 {
90 int i, verbose = 1, interactive = 0;
91
92 struct option opts[] = {
93 {"verbose", 0, NULL, 'v'},
94 {"interactive", 0, NULL, 'i'},
95 {NULL, 0, NULL, 0}
96 };
97
98 while ((i = getopt_long(argc, argv, "vi", opts, NULL)) != -1) {
99 switch (i) {
100 case 'v':
101 verbose = 1;
102 break;
103 case 'i':
104 interactive = 1;
105 break;
106 case 'h':
107 default:{
108 usage(argv[0]);
109 exit(1);
110 }
111 }
112 }
113
114 /* first do the non-mls tests */
115 mls = 0;
116 if (!do_tests(interactive, verbose))
117 return -1;
118
119 /* then with mls */
120 mls = 1;
121 if (!do_tests(interactive, verbose))
122 return -1;
123
124 return 0;
125 }
126