| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \ |
| 40 |
if (NULL == suite) { \ |
| 41 |
CU_cleanup_registry(); \ |
| 42 |
return CU_get_error(); } \ |
| 43 |
if (name##_add_tests(suite)) { \ |
| 44 |
CU_cleanup_registry(); \ |
| 45 |
return CU_get_error(); } |
| 46 |
|
| 47 |
static void usage(char *progname) |
| 48 |
{ |
| 49 |
printf("usage: %s [options]\n", progname); |
| 50 |
printf("options:\n"); |
| 51 |
printf("\t-v, --verbose\t\t\tverbose output\n"); |
| 52 |
printf("\t-i, --interactive\t\tinteractive console\n"); |
| 53 |
} |
| 54 |
|
| 55 |
static bool do_tests(int interactive, int verbose) |
| 56 |
{ |
| 57 |
CU_pSuite suite = NULL; |
| 58 |
unsigned int num_failures; |
| 59 |
|
| 60 |
if (CUE_SUCCESS != CU_initialize_registry()) |
| 61 |
return CU_get_error(); |
| 62 |
|
| 63 |
DECLARE_SUITE(cond); |
| 64 |
DECLARE_SUITE(linker); |
| 65 |
DECLARE_SUITE(expander); |
| 66 |
DECLARE_SUITE(deps); |
| 67 |
DECLARE_SUITE(downgrade); |
| 68 |
|
| 69 |
if (verbose) |
| 70 |
CU_basic_set_mode(CU_BRM_VERBOSE); |
| 71 |
else |
| 72 |
CU_basic_set_mode(CU_BRM_NORMAL); |
| 73 |
|
| 74 |
if (interactive) |
| 75 |
CU_console_run_tests(); |
| 76 |
else |
| 77 |
CU_basic_run_tests(); |
| 78 |
num_failures = CU_get_number_of_tests_failed(); |
| 79 |
CU_cleanup_registry(); |
| 80 |
return CU_get_error() == CUE_SUCCESS && num_failures == 0; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
int main(int argc, char **argv) |
| 85 |
{ |
| 86 |
int i, verbose = 1, interactive = 0; |
| 87 |
|
| 88 |
struct option opts[] = { |
| 89 |
{"verbose", 0, NULL, 'v'}, |
| 90 |
{"interactive", 0, NULL, 'i'}, |
| 91 |
{NULL, 0, NULL, 0} |
| 92 |
}; |
| 93 |
|
| 94 |
while ((i = getopt_long(argc, argv, "vi", opts, NULL)) != -1) { |
| 95 |
switch (i) { |
| 96 |
case 'v': |
| 97 |
verbose = 1; |
| 98 |
break; |
| 99 |
case 'i': |
| 100 |
interactive = 1; |
| 101 |
break; |
| 102 |
case 'h': |
| 103 |
default:{ |
| 104 |
usage(argv[0]); |
| 105 |
exit(1); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
mls = 0; |
| 112 |
if (!do_tests(interactive, verbose)) |
| 113 |
return -1; |
| 114 |
|
| 115 |
|
| 116 |
mls = 1; |
| 117 |
if (!do_tests(interactive, verbose)) |
| 118 |
return -1; |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |