diff options
author | Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com> | 2013-10-10 13:16:36 +0300 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-05-02 10:58:10 +0200 |
commit | dab43bc463a25109f6d86d64722f5e9c60d465e5 (patch) | |
tree | d10a2b1d3816e080ecb37bee4562f0017ccc1fd5 /src/tests | |
parent | 0a3246795b7ec49d6a2de4bebd82810b9b0cd08e (diff) | |
download | sssd-dab43bc463a25109f6d86d64722f5e9c60d465e5.tar.gz sssd-dab43bc463a25109f6d86d64722f5e9c60d465e5.tar.xz sssd-dab43bc463a25109f6d86d64722f5e9c60d465e5.zip |
Move DEBUG macro body to debug_fn
Move DEBUG macro body to the debug_fn function, adding "function"
argument to the latter.
Rename "debug_fn" in sssd_krb5_locator_plugin.c to "plugin_debug_fn" to
remove conflict with the sssd debug_fn.
Replace DEBUG_MSG macro usage with debug_fn function usage.
Remove DEBUG_MSG macro along with tests.
The above makes the total size of binaries drop by 20% for the standard
Fedora build and by 44% for a build configured according to Debian
packaging script.
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Stephen Gallagher <sgallagh@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
(cherry picked from commit fb0332565892bc10998ca98b567d4dde2213844d)
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/debug-tests.c | 299 |
1 files changed, 10 insertions, 289 deletions
diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c index f73f9bd7e..0902005af 100644 --- a/src/tests/debug-tests.c +++ b/src/tests/debug-tests.c @@ -179,7 +179,7 @@ START_TEST(test_debug_get_level_new_format) } END_TEST -int test_helper_debug_check_message(int level, int msgmode) +int test_helper_debug_check_message(int level) { TALLOC_CTX *ctx = talloc_new(NULL); char filename[24] = {'\0'}; @@ -221,11 +221,7 @@ int test_helper_debug_check_message(int level, int msgmode) goto done; } - if (msgmode == 0) { - DEBUG(level, ("%s", body)); - } else { - DEBUG_MSG(level, __FUNCTION__, "some error"); - } + DEBUG(level, ("%s", body)); ret = fseek(file, 0, SEEK_END); if (ret == -1) { @@ -329,7 +325,7 @@ done: return ret; } -int test_helper_debug_is_empty_message(int level, int msgmode) +int test_helper_debug_is_empty_message(int level) { char filename[24] = {'\0'}; int fd; @@ -362,11 +358,7 @@ int test_helper_debug_is_empty_message(int level, int msgmode) goto done; } - if (msgmode == 0) { - DEBUG(level, ("some error\n")); - } else { - DEBUG_MSG(level, __FUNCTION__, "some error"); - } + DEBUG(level, ("some error\n")); ret = fseek(file, 0, SEEK_END); if (ret == -1) { @@ -420,7 +412,7 @@ START_TEST(test_debug_is_set_single_no_timestamp) debug_level = levels[i]; errno = 0; - result = test_helper_debug_check_message(levels[i], 0); + result = test_helper_debug_check_message(levels[i]); if (result == DEBUG_TEST_ERROR) { error_msg = strerror(errno); @@ -462,7 +454,7 @@ START_TEST(test_debug_is_set_single_timestamp) debug_level = levels[i]; errno = 0; - result = test_helper_debug_check_message(levels[i], 0); + result = test_helper_debug_check_message(levels[i]); if (result == DEBUG_TEST_ERROR) { error_msg = strerror(errno); @@ -509,7 +501,7 @@ START_TEST(test_debug_is_set_single_timestamp_microseconds) debug_level = levels[i]; errno = 0; - result = test_helper_debug_check_message(levels[i], 0); + result = test_helper_debug_check_message(levels[i]); if (result == DEBUG_TEST_ERROR) { error_msg = strerror(errno); @@ -557,7 +549,7 @@ START_TEST(test_debug_is_notset_no_timestamp) debug_level = all_set & ~levels[i]; errno = 0; - result = test_helper_debug_is_empty_message(levels[i], 0); + result = test_helper_debug_is_empty_message(levels[i]); if (result == DEBUG_TEST_ERROR) { error_msg = strerror(errno); @@ -602,7 +594,7 @@ START_TEST(test_debug_is_notset_timestamp) debug_level = all_set & ~levels[i]; errno = 0; - result = test_helper_debug_is_empty_message(levels[i], 0); + result = test_helper_debug_is_empty_message(levels[i]); if (result == DEBUG_TEST_ERROR) { error_msg = strerror(errno); @@ -647,7 +639,7 @@ START_TEST(test_debug_is_notset_timestamp_microseconds) debug_level = all_set & ~levels[i]; errno = 0; - result = test_helper_debug_is_empty_message(levels[i], 0); + result = test_helper_debug_is_empty_message(levels[i]); if (result == DEBUG_TEST_ERROR) { error_msg = strerror(errno); @@ -664,271 +656,6 @@ START_TEST(test_debug_is_notset_timestamp_microseconds) } END_TEST -START_TEST(test_debug_msg_is_set_single_no_timestamp) -{ - int i; - int result; - int levels[] = { - SSSDBG_FATAL_FAILURE, - SSSDBG_CRIT_FAILURE, - SSSDBG_OP_FAILURE, - SSSDBG_MINOR_FAILURE, - SSSDBG_CONF_SETTINGS, - SSSDBG_FUNC_DATA, - SSSDBG_TRACE_FUNC, - SSSDBG_TRACE_LIBS, - SSSDBG_TRACE_INTERNAL, - SSSDBG_TRACE_ALL - }; - char *error_msg; - - debug_timestamps = 0; - debug_microseconds = 0; - debug_to_file = 1; - debug_prg_name = "sssd"; - - for (i = 0; i <= 9; i++) { - debug_level = levels[i]; - - errno = 0; - result = test_helper_debug_check_message(levels[i], 1); - - if (result == DEBUG_TEST_ERROR) { - error_msg = strerror(errno); - fail(error_msg); - } - - char *msg = NULL; - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]); - fail_unless(result == EOK, msg); - talloc_free(msg); - } -} -END_TEST - -START_TEST(test_debug_msg_is_set_single_timestamp) -{ - int i; - int result; - int levels[] = { - SSSDBG_FATAL_FAILURE, - SSSDBG_CRIT_FAILURE, - SSSDBG_OP_FAILURE, - SSSDBG_MINOR_FAILURE, - SSSDBG_CONF_SETTINGS, - SSSDBG_FUNC_DATA, - SSSDBG_TRACE_FUNC, - SSSDBG_TRACE_LIBS, - SSSDBG_TRACE_INTERNAL, - SSSDBG_TRACE_ALL - }; - char *error_msg; - - debug_timestamps = 1; - debug_microseconds = 0; - debug_to_file = 1; - debug_prg_name = "sssd"; - - for (i = 0; i <= 9; i++) { - debug_level = levels[i]; - - errno = 0; - result = test_helper_debug_check_message(levels[i], 1); - - if (result == DEBUG_TEST_ERROR) { - error_msg = strerror(errno); - fail(error_msg); - } - - char *msg = NULL; - - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - invalid timestamp", levels[i]); - fail_if(result == DEBUG_TEST_NOK_TS, msg); - talloc_free(msg); - - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]); - fail_unless(result == EOK, msg); - talloc_free(msg); - } -} -END_TEST - -START_TEST(test_debug_msg_is_set_single_timestamp_microseconds) -{ - int i; - int result; - int levels[] = { - SSSDBG_FATAL_FAILURE, - SSSDBG_CRIT_FAILURE, - SSSDBG_OP_FAILURE, - SSSDBG_MINOR_FAILURE, - SSSDBG_CONF_SETTINGS, - SSSDBG_FUNC_DATA, - SSSDBG_TRACE_FUNC, - SSSDBG_TRACE_LIBS, - SSSDBG_TRACE_INTERNAL, - SSSDBG_TRACE_ALL - }; - char *error_msg; - - debug_timestamps = 1; - debug_microseconds = 1; - debug_to_file = 1; - debug_prg_name = "sssd"; - - for (i = 0; i <= 9; i++) { - debug_level = levels[i]; - - errno = 0; - result = test_helper_debug_check_message(levels[i], 1); - - if (result == DEBUG_TEST_ERROR) { - error_msg = strerror(errno); - fail(error_msg); - } - - char *msg = NULL; - - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - invalid timestamp", levels[i]); - fail_if(result == DEBUG_TEST_NOK_TS, msg); - talloc_free(msg); - - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message don't match", levels[i]); - fail_unless(result == EOK, msg); - talloc_free(msg); - } -} -END_TEST - -START_TEST(test_debug_msg_is_notset_no_timestamp) -{ - int i; - int result; - int all_set = SSSDBG_MASK_ALL; - int levels[] = { - SSSDBG_FATAL_FAILURE, - SSSDBG_CRIT_FAILURE, - SSSDBG_OP_FAILURE, - SSSDBG_MINOR_FAILURE, - SSSDBG_CONF_SETTINGS, - SSSDBG_FUNC_DATA, - SSSDBG_TRACE_FUNC, - SSSDBG_TRACE_LIBS, - SSSDBG_TRACE_INTERNAL, - SSSDBG_TRACE_ALL - }; - char *error_msg; - - debug_timestamps = 0; - debug_microseconds = 0; - debug_to_file = 1; - debug_prg_name = "sssd"; - - for (i = 0; i <= 9; i++) { - debug_level = all_set & ~levels[i]; - - errno = 0; - result = test_helper_debug_is_empty_message(levels[i], 1); - - if (result == DEBUG_TEST_ERROR) { - error_msg = strerror(errno); - fail(error_msg); - } - - char *msg = NULL; - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message has been written", levels[i]); - fail_unless(result == EOK, msg); - talloc_free(msg); - } -} -END_TEST - -START_TEST(test_debug_msg_is_notset_timestamp) -{ - int i; - int result; - int all_set = SSSDBG_MASK_ALL; - int levels[] = { - SSSDBG_FATAL_FAILURE, - SSSDBG_CRIT_FAILURE, - SSSDBG_OP_FAILURE, - SSSDBG_MINOR_FAILURE, - SSSDBG_CONF_SETTINGS, - SSSDBG_FUNC_DATA, - SSSDBG_TRACE_FUNC, - SSSDBG_TRACE_LIBS, - SSSDBG_TRACE_INTERNAL, - SSSDBG_TRACE_ALL - }; - char *error_msg; - - debug_timestamps = 0; - debug_microseconds = 0; - debug_to_file = 1; - debug_prg_name = "sssd"; - - for (i = 0; i <= 9; i++) { - debug_level = all_set & ~levels[i]; - - errno = 0; - result = test_helper_debug_is_empty_message(levels[i], 1); - - if (result == DEBUG_TEST_ERROR) { - error_msg = strerror(errno); - fail(error_msg); - } - - char *msg = NULL; - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message has been written", levels[i]); - fail_unless(result == EOK, msg); - talloc_free(msg); - } -} -END_TEST - -START_TEST(test_debug_msg_is_notset_timestamp_microseconds) -{ - int i; - int result; - int all_set = SSSDBG_MASK_ALL; - int levels[] = { - SSSDBG_FATAL_FAILURE, - SSSDBG_CRIT_FAILURE, - SSSDBG_OP_FAILURE, - SSSDBG_MINOR_FAILURE, - SSSDBG_CONF_SETTINGS, - SSSDBG_FUNC_DATA, - SSSDBG_TRACE_FUNC, - SSSDBG_TRACE_LIBS, - SSSDBG_TRACE_INTERNAL, - SSSDBG_TRACE_ALL - }; - char *error_msg; - - debug_timestamps = 0; - debug_microseconds = 1; - debug_to_file = 1; - debug_prg_name = "sssd"; - - for (i = 0; i <= 9; i++) { - debug_level = all_set & ~levels[i]; - - errno = 0; - result = test_helper_debug_is_empty_message(levels[i], 1); - - if (result == DEBUG_TEST_ERROR) { - error_msg = strerror(errno); - fail(error_msg); - } - - char *msg = NULL; - msg = talloc_asprintf(NULL, "Test of level %#.4x failed - message has been written", levels[i]); - fail_unless(result == EOK, msg); - talloc_free(msg); - } -} -END_TEST - START_TEST(test_debug_is_set_true) { int i; @@ -1004,12 +731,6 @@ Suite *debug_suite(void) tcase_add_test(tc_debug, test_debug_is_notset_no_timestamp); tcase_add_test(tc_debug, test_debug_is_notset_timestamp); tcase_add_test(tc_debug, test_debug_is_notset_timestamp_microseconds); - tcase_add_test(tc_debug, test_debug_msg_is_set_single_no_timestamp); - tcase_add_test(tc_debug, test_debug_msg_is_set_single_timestamp); - tcase_add_test(tc_debug, test_debug_msg_is_set_single_timestamp_microseconds); - tcase_add_test(tc_debug, test_debug_msg_is_notset_no_timestamp); - tcase_add_test(tc_debug, test_debug_msg_is_notset_timestamp); - tcase_add_test(tc_debug, test_debug_msg_is_notset_timestamp_microseconds); tcase_add_test(tc_debug, test_debug_is_set_true); tcase_add_test(tc_debug, test_debug_is_set_false); tcase_set_timeout(tc_debug, 60); |