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

parent 569787a0
......@@ -28,6 +28,7 @@
extern const char *test_domain;
extern const char *auth_domain;
static char* all_leaks_buffer = NULL;
static const char *belle_sip_tester_root_ca_path = NULL;
static FILE * log_file = NULL;
......@@ -109,6 +110,13 @@ void belle_sip_tester_init(void(*ftester_printf)(int level, const char *fmt, va_
void belle_sip_tester_uninit(void) {
belle_sip_object_unref(pool);
belle_sip_uninit_sockets();
// show all leaks that happened during the test
if (all_leaks_buffer) {
bc_tester_printf(bc_printf_verbosity_info, all_leaks_buffer);
belle_sip_free(all_leaks_buffer);
}
bc_tester_uninit();
}
......@@ -119,11 +127,16 @@ void belle_sip_tester_before_each() {
void belle_sip_tester_after_each() {
int leaked_objects = belle_sip_object_get_object_count() - leaked_objects_count;
BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
if (leaked_objects > 0) {
char* format = belle_sip_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();
belle_sip_error("%d objects were leaked in latest test, please fix that!\n", leaked_objects);
bc_tester_printf(bc_printf_verbosity_info, format);
belle_sip_error("%s", format);
all_leaks_buffer = belle_sip_strcat_printf(all_leaks_buffer, "\n%s", format);
}
}
......
......@@ -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;
}
......@@ -92,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, ...);
......
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