tester: do not use BC_ASSERT_EQUAL macro to check leaks to avoid false positive in CUnit report

parent 6cc4570e
mediastreamer2 @ 3fca3ee2
Subproject commit d6c107053b8dc55c754e2f01155d447adad60151
Subproject commit 3fca3ee284a5fe92fd0eb080bfb2f969ef35bcdb
......@@ -55,6 +55,9 @@ static char *bc_tester_resource_dir_prefix = NULL;
// by default writable will always write near the executable
static char *bc_tester_writable_dir_prefix = NULL;
static char *bc_current_suite_name = NULL;
static char *bc_current_test_name = NULL;
int bc_printf_verbosity_info;
int bc_printf_verbosity_error;
......@@ -165,6 +168,7 @@ static time_t suite_start_time = 0;
static void suite_start_message_handler(const CU_pSuite pSuite) {
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] started\n", pSuite->pName);
suite_start_time = time(NULL);
bc_current_suite_name = pSuite->pName;
}
static void suite_complete_message_handler(const CU_pSuite pSuite, const CU_pFailureRecord pFailure) {
bc_tester_printf(bc_printf_verbosity_info, "Suite [%s] ended in %lu sec\n", pSuite->pName,
......@@ -179,6 +183,7 @@ static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSu
}
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] Test [%s] started", pSuite->pName,pTest->pName);
test_start_time = time(NULL);
bc_current_test_name = pTest->pName;
}
/*derivated from cunit*/
......@@ -641,3 +646,11 @@ char* bc_sprintf(const char* format, ...) {
va_end (args);
return res;
}
const char * bc_tester_current_suite_name() {
return bc_current_suite_name;
}
const char * bc_tester_current_test_name() {
return bc_current_test_name;
}
......@@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TESTER_UTILS_H
#define TESTER_UTILS_H
......@@ -93,6 +92,8 @@ const char * bc_tester_test_name(const char *suite_name, int test_index);
int bc_tester_run_suite(test_suite_t *suite);
int bc_tester_run_tests(const char *suite_name, const char *test_name);
int bc_tester_suite_index(const char *suite_name);
const char * bc_tester_current_suite_name();
const char * bc_tester_current_test_name();
char* bc_sprintfva(const char* format, va_list args);
char* bc_sprintf(const char* format, ...);
......
......@@ -156,10 +156,6 @@ void liblinphone_tester_init(void(*ftester_printf)(int level, const char *fmt, v
liblinphone_tester_add_suites();
}
void liblinphone_tester_uninit(void) {
bc_tester_uninit();
}
int liblinphone_tester_set_log_file(const char *filename) {
if (log_file) {
fclose(log_file);
......
......@@ -505,15 +505,21 @@ void liblinphone_tester_before_each(void) {
}
}
static char* all_leaks_buffer = NULL;
void liblinphone_tester_after_each(void) {
if (!liblinphone_tester_leak_detector_disabled){
int leaked_objects = belle_sip_object_get_object_count() - leaked_objects_count;
// this will NOT be counted in tests fail but at least it will be shown
BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
if (leaked_objects > 0) {
char* format = ms_strdup_printf("%d object%s leaked in suite [%s] test [%s], please fix that!",
leaked_objects, leaked_objects>1?"s were":"was",
bc_tester_current_suite_name(), bc_tester_current_test_name());
belle_sip_object_dump_active_objects();
belle_sip_object_flush_active_objects();
ms_error("%d object%s leaked in latest test, please fix that!", leaked_objects, leaked_objects>1?"s were":"was");
bc_tester_printf(bc_printf_verbosity_info, format);
ms_error("%s", format);
all_leaks_buffer = ms_strcat_printf(all_leaks_buffer, "\n%s", format);
}
}
......@@ -522,3 +528,11 @@ void liblinphone_tester_after_each(void) {
}
}
void liblinphone_tester_uninit(void) {
// show all leaks that happened during the test
if (all_leaks_buffer) {
bc_tester_printf(bc_printf_verbosity_info, all_leaks_buffer);
ms_free(all_leaks_buffer);
}
bc_tester_uninit();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment