1 /* -*- mode: C; c-file-style: "gnu" -*- */ 2 /* test-main.c main() for make check 3 * 4 * Copyright (C) 2003 Red Hat, Inc. 5 * 6 * Licensed under the Academic Free License version 2.1 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 */ 23 24 #include "test.h" 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <dbus/dbus-string.h> 28 #include <dbus/dbus-sysdeps.h> 29 #include <dbus/dbus-internals.h> 30 #include "selinux.h" 31 32 #ifdef DBUS_BUILD_TESTS 33 static void 34 die (const char *failure) 35 { 36 fprintf (stderr, "Unit test failed: %s\n", failure); 37 exit (1); 38 } 39 40 static void 41 check_memleaks (const char *name) 42 { 43 dbus_shutdown (); 44 45 printf ("%s: checking for memleaks\n", name); 46 if (_dbus_get_malloc_blocks_outstanding () != 0) 47 { 48 _dbus_warn ("%d dbus_malloc blocks were not freed\n", 49 _dbus_get_malloc_blocks_outstanding ()); 50 die ("memleaks"); 51 } 52 } 53 #endif /* DBUS_BUILD_TESTS */ 54 55 static void 56 test_pre_hook (void) 57 { 58 59 if (_dbus_getenv ("DBUS_TEST_SELINUX") 60 && (!bus_selinux_pre_init () 61 || !bus_selinux_full_init ())) 62 die ("could not init selinux support"); 63 } 64 65 static char *progname = ""; 66 static void 67 test_post_hook (void) 68 { 69 if (_dbus_getenv ("DBUS_TEST_SELINUX")) 70 bus_selinux_shutdown (); 71 check_memleaks (progname); 72 } 73 74 int 75 main (int argc, char **argv) 76 { 77 #ifdef DBUS_BUILD_TESTS 78 const char *dir; 79 DBusString test_data_dir; 80 81 progname = argv[0]; 82 83 if (argc > 1) 84 dir = argv[1]; 85 else 86 dir = _dbus_getenv ("DBUS_TEST_DATA"); 87 88 if (dir == NULL) 89 { 90 fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); 91 return 1; 92 } 93 94 _dbus_string_init_const (&test_data_dir, dir); 95 96 if (!_dbus_threads_init_debug ()) 97 die ("initializing debug threads"); 98 99 test_pre_hook (); 100 printf ("%s: Running expire list test\n", argv[0]); 101 if (!bus_expire_list_test (&test_data_dir)) 102 die ("expire list"); 103 test_post_hook (); 104 105 test_pre_hook (); 106 printf ("%s: Running config file parser test\n", argv[0]); 107 if (!bus_config_parser_test (&test_data_dir)) 108 die ("parser"); 109 test_post_hook (); 110 111 test_pre_hook (); 112 printf ("%s: Running policy test\n", argv[0]); 113 if (!bus_policy_test (&test_data_dir)) 114 die ("policy"); 115 test_post_hook (); 116 117 test_pre_hook (); 118 printf ("%s: Running signals test\n", argv[0]); 119 if (!bus_signals_test (&test_data_dir)) 120 die ("signals"); 121 test_post_hook (); 122 123 test_pre_hook (); 124 printf ("%s: Running SHA1 connection test\n", argv[0]); 125 if (!bus_dispatch_sha1_test (&test_data_dir)) 126 die ("sha1"); 127 test_post_hook (); 128 129 test_pre_hook (); 130 printf ("%s: Running message dispatch test\n", argv[0]); 131 if (!bus_dispatch_test (&test_data_dir)) 132 die ("dispatch"); 133 test_post_hook (); 134 135 test_pre_hook (); 136 printf ("%s: Running service files reloading test\n", argv[0]); 137 if (!bus_activation_service_reload_test (&test_data_dir)) 138 die ("service reload"); 139 test_post_hook (); 140 141 printf ("%s: Success\n", argv[0]); 142 143 144 return 0; 145 #else /* DBUS_BUILD_TESTS */ 146 147 printf ("Not compiled with test support\n"); 148 149 return 0; 150 #endif 151 } 152