1 /* 2 * Author: Karl MacMillan <kmacmillan (at) 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 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 /* first do the non-mls tests */ 111 mls = 0; 112 if (!do_tests(interactive, verbose)) 113 return -1; 114 115 /* then with mls */ 116 mls = 1; 117 if (!do_tests(interactive, verbose)) 118 return -1; 119 120 return 0; 121 } 122