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