1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* test-main.c main() for the OOM check of the launch helper
4 * Copyright (C) 2007 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "activation-helper.h"
30 #include <dbus/dbus-internals.h>
31 #include <dbus/dbus-misc.h>
33 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
35 die (const char *failure)
37 fprintf (stderr, "Unit test failed: %s\n", failure);
42 check_memleaks (const char *name)
46 printf ("%s: checking for memleaks\n", name);
47 if (_dbus_get_malloc_blocks_outstanding () != 0)
49 _dbus_warn ("%d dbus_malloc blocks were not freed\n",
50 _dbus_get_malloc_blocks_outstanding ());
56 test_post_hook (const char *name)
58 check_memleaks (name);
60 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
63 #ifdef ACTIVATION_LAUNCHER_DO_OOM
65 /* returns true if good things happen, or if we get OOM */
67 bus_activation_helper_oom_test (void *data)
73 service = (const char *) data;
76 dbus_error_init (&error);
77 if (!run_launch_helper (service, &error))
79 _DBUS_ASSERT_ERROR_IS_SET (&error);
80 /* we failed, but a OOM is good */
81 if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
83 _dbus_warn ("FAILED SELF TEST: Error: %s\n", error.message);
86 dbus_error_free (&error);
90 /* we succeeded, yay! */
91 _DBUS_ASSERT_ERROR_IS_CLEAR (&error);
99 main (int argc, char **argv)
101 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
103 DBusString config_file;
108 dir = _dbus_getenv ("DBUS_TEST_DATA");
112 fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n");
116 printf ("%s: Running launch helper OOM checks\n", argv[0]);
118 if (!_dbus_string_init (&config_file))
120 if (!_dbus_string_append (&config_file, dir))
122 if (!_dbus_string_append (&config_file, "/valid-config-files-system/debug-allow-all-pass.conf"))
125 /* use a config file that will actually work... */
126 dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG",
127 _dbus_string_get_const_data (&config_file));
129 _dbus_string_free (&config_file);
131 if (!_dbus_test_oom_handling ("dbus-daemon-launch-helper",
132 bus_activation_helper_oom_test,
133 "org.freedesktop.DBus.TestSuiteEchoService"))
136 test_post_hook (argv[0]);
138 printf ("%s: Success\n", argv[0]);
141 #else /* DBUS_ENABLE_EMBEDDED_TESTS */
143 printf ("Not compiled with test support\n");