From e428bf42b88e192fdcc4fee116da6d512ec7aee0 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 24 Mar 2015 17:23:05 +0100 Subject: [PATCH] tester: fix crash when using both --verbose and --log-file --- mediastreamer2 | 2 +- tester/common/bc_tester_utils.c | 18 +++++++++--------- tester/liblinphone_tester.c | 27 +++++++++++++++++---------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/mediastreamer2 b/mediastreamer2 index 8b1481dfe..160ed0a5c 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 8b1481dfe5d5faede84598e977ec62afd943bd2f +Subproject commit 160ed0a5c49e9067eda87544523a8d1bdb2b5155 diff --git a/tester/common/bc_tester_utils.c b/tester/common/bc_tester_utils.c index 2b6ff009d..077ec0569 100644 --- a/tester/common/bc_tester_utils.c +++ b/tester/common/bc_tester_utils.c @@ -115,7 +115,7 @@ int bc_tester_nb_tests(const char *suite_name) { void bc_tester_list_suites() { int j; for(j=0;jpName); + tester_printf(verbosity_error,"Suite initialization failed for [%s]", pSuite->pName); } static void suite_cleanup_failure_message_handler(const CU_pSuite pSuite) { - tester_printf(verbosity_error,"Suite cleanup failed for [%s].", pSuite->pName); + tester_printf(verbosity_error,"Suite cleanup failed for [%s]", pSuite->pName); } #ifdef HAVE_CU_GET_SUITE static void suite_start_message_handler(const CU_pSuite pSuite) { - tester_printf(verbosity_info,"Suite [%s] started\n", pSuite->pName); + tester_printf(verbosity_info,"Suite [%s] started", pSuite->pName); } static void suite_complete_message_handler(const CU_pSuite pSuite, const CU_pFailureRecord pFailure) { - tester_printf(verbosity_info,"Suite [%s] ended\n", pSuite->pName); + tester_printf(verbosity_info,"Suite [%s] ended", pSuite->pName); } static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) { @@ -163,11 +163,11 @@ static void test_complete_message_handler(const CU_pTest pTest, char result[2048]; char buffer[2048]; CU_pFailureRecord pFailure = pFailureList; - snprintf(result, 2048, "Suite [%s] Test [%s]", pSuite->pName, pTest->pName); + snprintf(result, sizeof(result), "Suite [%s] Test [%s]", pSuite->pName, pTest->pName); if (pFailure) { strncat(result, " failed:", strlen(" failed:")); for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) { - snprintf(buffer, 2048, "\n %d. %s:%u - %s", i, + snprintf(buffer, sizeof(buffer), "\n %d. %s:%u - %s", i, (NULL != pFailure->strFileName) ? pFailure->strFileName : "", pFailure->uiLineNumber, (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); @@ -346,7 +346,7 @@ void bc_tester_uninit() { } CU_cleanup_registry(); /*add missing final newline*/ - tester_printf(verbosity_info,"\n"); + tester_printf(verbosity_info,""); if( xml_enabled ){ /*create real xml file only if tester did not crash*/ diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 35bf35eab..0469b3675 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -30,7 +30,6 @@ static FILE * log_file = NULL; -static OrtpLogFunc ortp_log_handler; #ifdef ANDROID @@ -132,28 +131,35 @@ static void liblinphone_tester_qnx_log_handler(OrtpLogLevel lev, const char *fmt #endif /* __QNX__ */ static void log_handler(int lev, const char *fmt, va_list args) { +#ifdef WIN32 + vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, args); + fprintf(lev == ORTP_ERROR ? stderr : stdout, "\n"); +#else + va_list cap; + va_copy(cap,args); #ifdef ANDROID /* IMPORTANT: needed by liblinphone tester to retrieve suite list...*/ - cunit_android_trace_handler(lev == ORTP_ERROR, fmt, args); + cunit_android_trace_handler(lev == ORTP_ERROR, fmt, cap); #else /* Otherwise, we must use stdio to avoid log formatting (for autocompletion etc.) */ - vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, args); + vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, cap); + fprintf(lev == ORTP_ERROR ? stderr : stdout, "\n"); +#endif + va_end(cap); #endif if (log_file){ - ortp_set_log_file(log_file); - ortp_log_handler(lev, fmt, args); + ortp_logv_out(lev, fmt, args); } } void liblinphone_tester_init(void) { + if (! log_file) { #if defined(ANDROID) - linphone_core_set_log_handler(liblinphone_android_ortp_log_handler); + linphone_core_set_log_handler(liblinphone_android_ortp_log_handler); #elif defined(__QNX__) - linphone_core_set_log_handler(liblinphone_tester_qnx_log_handler); -#else - linphone_core_set_log_handler(ortp_logv_out); + linphone_core_set_log_handler(liblinphone_tester_qnx_log_handler); #endif - ortp_log_handler = ortp_get_log_handler(); + } bc_tester_init(log_handler, ORTP_MESSAGE, ORTP_ERROR); liblinphone_tester_add_suites(); @@ -202,6 +208,7 @@ int main (int argc, char *argv[]) return -2; } else { ms_message("Redirecting traces to file [%s]",argv[i]); + ortp_set_log_file(log_file); } } else if (strcmp(argv[i],"--domain")==0){ CHECK_ARG("--domain", ++i, argc);