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 <stdio.h>
32#include <getopt.h>
33#include <stdlib.h>
34
35int mls;
36
37#define DECLARE_SUITE(name) \
38	suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \
39	if (NULL == suite) { \
40		CU_cleanup_registry(); \
41		return CU_get_error(); } \
42	if (name##_add_tests(suite)) { \
43		CU_cleanup_registry(); \
44		return CU_get_error(); }
45
46static void usage(char *progname)
47{
48	printf("usage:  %s [options]\n", progname);
49	printf("options:\n");
50	printf("\t-v, --verbose\t\t\tverbose output\n");
51	printf("\t-i, --interactive\t\tinteractive console\n");
52}
53
54static int do_tests(int interactive, int verbose)
55{
56	CU_pSuite suite = NULL;
57
58	if (CUE_SUCCESS != CU_initialize_registry())
59		return CU_get_error();
60
61	DECLARE_SUITE(cond);
62	DECLARE_SUITE(linker);
63	DECLARE_SUITE(expander);
64	DECLARE_SUITE(deps);
65	DECLARE_SUITE(downgrade);
66
67	if (verbose)
68		CU_basic_set_mode(CU_BRM_VERBOSE);
69	else
70		CU_basic_set_mode(CU_BRM_NORMAL);
71
72	if (interactive)
73		CU_console_run_tests();
74	else
75		CU_basic_run_tests();
76	CU_cleanup_registry();
77	return CU_get_error();
78
79}
80
81int main(int argc, char **argv)
82{
83	int i, verbose = 1, interactive = 0;
84
85	struct option opts[] = {
86		{"verbose", 0, NULL, 'v'},
87		{"interactive", 0, NULL, 'i'},
88		{NULL, 0, NULL, 0}
89	};
90
91	while ((i = getopt_long(argc, argv, "vi", opts, NULL)) != -1) {
92		switch (i) {
93		case 'v':
94			verbose = 1;
95			break;
96		case 'i':
97			interactive = 1;
98			break;
99		case 'h':
100		default:{
101				usage(argv[0]);
102				exit(1);
103			}
104		}
105	}
106
107	/* first do the non-mls tests */
108	mls = 0;
109	if (do_tests(interactive, verbose))
110		return -1;
111
112	/* then with mls */
113	mls = 1;
114	if (do_tests(interactive, verbose))
115		return -1;
116
117	return 0;
118}
119