debug PRINTF with open_memstream, cleanup

This commit is contained in:
2023-10-06 02:01:35 +02:00
parent caa0135e8a
commit 2e575317e2
5 changed files with 176 additions and 371 deletions
+16 -16
View File
@@ -182,11 +182,11 @@ __attribute__((destructor))
signal(SIGSEGV, SIG_DFL); /* restore default behaviour , */
//int kdefault=0, kgreen=1, kred=2, kyellow=3, kblue=4, knothing;
if(unicolour) {
kgreen=knothing; kred=knothing; kyellow=knothing; kblue=knothing;
//for(int i=0; i< Dknothing;++i) strcpy(colors_f[i]," ");
}
//int k_DEFAULT=0, k_GREEN=1, k_RED=2, k_YELLOW=3, k_BLUE=4, k_NOTHING;
//if(unicolour) {
//k_GREEN=k_NOTHING; k_RED=k_NOTHING; k_YELLOW=k_NOTHING; k_BLUE=k_NOTHING;
//for(int i=0; i< Dk_NOTHING;++i) strcpy(colors_f[i]," ");
//}
struct winsize w;
ioctl(1, TIOCGWINSZ, &w);
@@ -194,7 +194,7 @@ __attribute__((destructor))
char *reader=malloc(w.ws_col);
strcpy(reader,"STAT OF MOCK FUNCTIONS");
fprintf(F_OUT,"%s\n\n%0*d\n %*s \n%0*d %s\n\n", colors_f[kyellow] ,w.ws_col,0, (int)(w.ws_col+strlen(reader))/2, reader,w.ws_col,0, DEFAULT_K );
fprintf(F_OUT,"%s\n\n%0*d\n %*s \n%0*d %s\n\n", colors_f[k_YELLOW] ,w.ws_col,0, (int)(w.ws_col+strlen(reader))/2, reader,w.ws_col,0, DEFAULT_K );
is_parallel_nb = 0; /* no longer parallel here */
@@ -207,7 +207,7 @@ __attribute__((destructor))
PRINT_DEBUG("**** STAT mock function:%s, conditions:%s t_left:%ld, init_left:%ld, failed_call:%ld\n",tmock->str_namefunc, tmock->str_conditions, tmock->times_left,tmock->init_times_left, tmock->failed_call);
if((tmock->expect_call) && (tmock->init_times_left == tmock->times_left) || (tmock->failed_call)){
if(tmock->l_current_var){
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s\n",colors_f[kred],HK_FL,colors_f[kyellow],tmock->str_namefunc,DEFAULT_K,
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s\n",colors_f[k_RED],HK_FL,colors_f[k_YELLOW],tmock->str_namefunc,DEFAULT_K,
number_call_translate(tmock->init_times_left),
tmock->call/*tmock->failed_call + (tmock->init_times_left - tmock->times_left)*/,
tmock->failed_call,
@@ -216,7 +216,7 @@ __attribute__((destructor))
PRINT_VAR_CUR(tmock);
}
else
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s \n",colors_f[kred],HK_FL,colors_f[kyellow],tmock->str_namefunc,DEFAULT_K,
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s \n",colors_f[k_RED],HK_FL,colors_f[k_YELLOW],tmock->str_namefunc,DEFAULT_K,
number_call_translate(tmock->init_times_left),
tmock->call/*tmock->failed_call + (tmock->init_times_left - tmock->times_left)*/,
tmock->failed_call,
@@ -227,7 +227,7 @@ __attribute__((destructor))
//free(tfree);
}
PRINTF("\n%s%s STAT MOCK : there are %ld mock functions, %ld wished responses, %ld expected responses, which are:\n\n",colors_f[kgreen],HK_EQ,count_f_mock, count_f_mock_wished, count_expect_mock);
PRINTF("\n%s%s STAT MOCK : there are %ld mock functions, %ld wished responses, %ld expected responses, which are:\n\n",colors_f[k_GREEN],HK_EQ,count_f_mock, count_f_mock_wished, count_expect_mock);
struct list_base_fmock *tmp_list_fm = g_list_base_fmock;
struct func_mock_info_struct *tmp_inf_mock;
/* list each fmock an each calls */
@@ -251,7 +251,7 @@ __attribute__((destructor))
reader[bg_rd+len_nameff+len_by_+i]=caller[i];
PRINTF("%s%s%s\n\n",colors_f[kblue],reader,DEFAULT_K );
PRINTF("%s%s%s\n\n",colors_f[k_BLUE],reader,DEFAULT_K );
while(tmp_inf_mock){
if(0==strncmp(tmp_inf_mock->str_namefunc,nameff, len_nameff)){
if(tmp_inf_mock->expect_call==1){
@@ -259,37 +259,37 @@ __attribute__((destructor))
if(tmp_inf_mock->l_current_var){
PRINTF("%s%s%s %s\t expect %s,\t called %ld times and failed %ld times %s,\t with condition: %s%s\n" ,
colors_f[!unicolour*(kred - success)],tab_hk_f[hk_FL-success],colors_f[knothing * success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
colors_f[!unicolour*(k_RED - success)],tab_hk_f[hk_FL-success],colors_f[k_NOTHING * success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, strprint_caller_(tmp_inf_mock->str_caller), tmp_inf_mock->str_conditions, DEFAULT_K);
PRINT_VAR_CUR(tmp_inf_mock);
}else{
PRINTF("%s%s%s %s\t expect %s,\t called %ld times and failed %ld times %s,\t with condition: %s%s\n" ,
colors_f[!unicolour*(kred - success)],tab_hk_f[hk_FL-success],colors_f[knothing*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
colors_f[!unicolour*(k_RED - success)],tab_hk_f[hk_FL-success],colors_f[k_NOTHING*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, strprint_caller_(tmp_inf_mock->str_caller), tmp_inf_mock->str_conditions , DEFAULT_K);
}
}else if(tmp_inf_mock->expect_call==0) {/* will expect */
int success = !(tmp_inf_mock->failed_call);
if(tmp_inf_mock->l_current_var){
PRINTF("%s%s%s %s\t will %s,\t called %ld times and failed %ld times %s,\t with condition: %s,%s\n" ,
colors_f[!unicolour*(kred + success)],tab_hk_f[hk_FL-success],colors_f[knothing*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
colors_f[!unicolour*(k_RED + success)],tab_hk_f[hk_FL-success],colors_f[k_NOTHING*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, strprint_caller_(tmp_inf_mock->str_caller), tmp_inf_mock->str_conditions , DEFAULT_K);
PRINT_VAR_CUR(tmp_inf_mock);
}else{
PRINTF("%s%s%s %s\t will %s,\t called %ld times and failed %ld times %s,\t with condition: %s %s\n" ,
colors_f[!unicolour*(kred + success)],tab_hk_f[hk_FL-success],colors_f[knothing*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
colors_f[!unicolour*(k_RED + success)],tab_hk_f[hk_FL-success],colors_f[k_NOTHING*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, strprint_caller_(tmp_inf_mock->str_caller), tmp_inf_mock->str_conditions , DEFAULT_K);
}
}
else if(tmp_inf_mock->expect_call==-1){
if(tmp_inf_mock->l_current_var){
PRINTF("%s%s%s %s\t %s,\t called %ld times, %s\n" ,
colors_f[!unicolour*(kred)],tab_hk_f[hk_FL],colors_f[kdefault],tmp_inf_mock->str_namefunc,
colors_f[!unicolour*(k_RED)],tab_hk_f[hk_FL],colors_f[k_DEFAULT],tmp_inf_mock->str_namefunc,
number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
strprint_caller_(tmp_inf_mock->str_caller) );
PRINT_VAR_CUR(tmp_inf_mock);
}else{
PRINTF("%s%s%s %s\t %s,\t called %ld times, %s\n" ,
colors_f[!unicolour*(kred)],tab_hk_f[hk_FL],colors_f[kdefault],tmp_inf_mock->str_namefunc,
colors_f[!unicolour*(k_RED)],tab_hk_f[hk_FL],colors_f[k_DEFAULT],tmp_inf_mock->str_namefunc,
number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
strprint_caller_(tmp_inf_mock->str_caller));
}
+29 -12
View File
@@ -92,7 +92,6 @@ extern struct list_base_fmock *g_list_base_fmock;
returntype (*run) args_prototype_with_parenthesis;\
int (*call_mock_condition) args_prototype_with_parenthesis ;/* to store condition */\
char* (*str_print_current_variables) args_prototype_with_parenthesis ;/* to store current variables CREATE by macro STR_PRINT_CUR_VAR same arguments as MOCK_FUNC without returntype whoch is always char * */\
/*int arg_count;*/\
struct func_mock_info_struct *info_mock;\
struct list_mock_return_ ## namefunction *next;\
} list_mo_ ## namefunction;\
@@ -109,22 +108,36 @@ extern struct list_base_fmock *g_list_base_fmock;
PRINT_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>count call of %s: %ld\n",#namefunction,count_call_f);\
struct list_mock_return_ ## namefunction *tmp_mock = &list_mo_ ## namefunction;\
if( (tmp_mock->info_mock)->times_left == INITSTATE ){\
PRINT_HK_C(YELLOW_K, HK_TR," WARNING, %s, no EXPECT_MOCK_CALL or WILL_MOCK_CALL, but called %ld times.\n",#namefunction, count_call_f);\
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," WARNING, %s, no EXPECT_MOCK_CALL or WILL_MOCK_CALL, but called %ld times.\n",#namefunction, count_call_f);\
if(count_call_f==1){\
PRINT_HK_C(YELLOW_K,HK_TR," For instance:\n%s EXPECT_MOCK_CALL(%s,%s,%s,true,1){\n%s\t %s ret;\n%s \t ...do something with %s;\n%s\t return ret;\n%s }\n%s if call once and accept all args, the same args with WILL_MOCK_CALL \n",\
HK_TR, #returntype, #namefunction,#args_prototype_with_parenthesis, HK_TR,#returntype, HK_TR, #args_call_with_parenthesis, HK_TR, HK_TR, HK_TR ); \
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," For instance:\n"\
"%s EXPECT_MOCK_CALL(%s,%s,%s,true,1){\n"\
"%s\t %s ret;\n%s \t ...do something with %s;\n"\
"%s\t return ret;\n"\
"%s }\n"\
"%s if call once and accept all args, the same args with WILL_MOCK_CALL \n\n",\
HK_TR, #returntype, #namefunction,#args_prototype_with_parenthesis, HK_TR,#returntype, \
HK_TR, #args_call_with_parenthesis, HK_TR, HK_TR, HK_TR ); \
/*return (returntype)0;*/ \
INIT_MOCK_INFO_IF_NO_(tmp_mock,namefunction, PRE_ID);\
}/* to have log */\
if(list_mo_ ## namefunction.next ) PRINT_ERROR(" %s .next SHOULD BE NULL\n",STRFY(list_mo_ ## namefunction));\
/*if(list_mo_ ## namefunction.next ) PRINT_ERROR(" %s .next SHOULD BE NULL\n",STRFY(list_mo_ ## namefunction));*/\
}\
while(tmp_mock->next && (tmp_mock->info_mock)->times_left == 0) tmp_mock = tmp_mock->next ;\
while(tmp_mock->next && (tmp_mock->info_mock)->times_left == 0) {tmp_mock = tmp_mock->next ;}\
++((tmp_mock->info_mock)->call);\
if(tmp_mock->str_print_current_variables)\
if(tmp_mock->str_print_current_variables){\
append_variable_current(&((tmp_mock->info_mock)->l_current_var), tmp_mock->str_print_current_variables args_call_with_parenthesis);\
}\
else if(count_call_f == 1){\
PRINT_HK_C(YELLOW_K,HK_TR," no printer variable defined, to define it:\n%s STR_PRINT_CUR_VAR(%s,%s,%s){\n%s\t char* ret=malloc(256);/*for instance*/;\n%s \t ... sprintf(ret,...., %s);/*for instance*/ \n%s\t return ret;\n%s }\n%s same prototype as MOCK_FUNC whithout returntype which always char* \n",\
HK_TR, #namefunction,#args_prototype_with_parenthesis, #args_call_with_parenthesis, HK_TR, HK_TR, #args_call_with_parenthesis, HK_TR, HK_TR, HK_TR ); \
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," no printer variable function defined, to define it:\n"\
"%s STR_PRINT_CUR_VAR(%s,%s,%s){\n"\
"%s\t char* ret=malloc(256);/*for instance*/;\n"\
"%s\t ... sprintf(ret,...., %s);/*for instance*/ \n"\
"%s\t return ret;\n"\
"%s }\n"\
"%s same prototype as MOCK_FUNC whithout returntype which always char* i\n\n",\
HK_TR, #namefunction,#args_prototype_with_parenthesis, #args_call_with_parenthesis, \
HK_TR, HK_TR, #args_call_with_parenthesis, HK_TR, HK_TR, HK_TR ); \
}\
/*LOG("condition_func:%d\n", tmp_mock->call_mock_condition args_call_with_parenthesis);*/ /*LOG("%s\n","failure condition");*/\
/*EXPECT_EQ_TYPE_INT(1, tmp_mock->call_mock_condition args_call_with_parenthesis);*/ /*LOG("%s\n","failure condition");*/\
@@ -132,9 +145,13 @@ extern struct list_base_fmock *g_list_base_fmock;
/*return (returntype)0;*//* default return */\
if( (tmp_mock->info_mock)->str_caller == NULL){ \
if(count_call_f == 1){\
PRINT_HK_C(YELLOW_K,HK_TR," WARNING, no INIT_CALLER_MOCK; you can put it like this: \n%s TEST(nametest){\n%s\t INIT_CALLER_MOCK(%s); \n%s\t %s%s; \n%s }\n%s i.e before calling %s in this TEST, to have explicit logs\n",\
HK_TR, HK_TR, #namefunction, HK_TR,#namefunction,#args_call_with_parenthesis, HK_TR, HK_TR, #namefunction);\
} \
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," WARNING, no INIT_CALLER_MOCK; you can put it like this: \n"\
"%s TEST(nametest){\n"\
"%s\t INIT_CALLER_MOCK(%s); \n"\
"%s\t %s%s; \n"\
"%s }\n"\
"%s i.e before calling %s in this TEST, to have explicit logs\n",\
HK_TR, HK_TR, #namefunction, HK_TR,#namefunction,#args_call_with_parenthesis, HK_TR, HK_TR, #namefunction);} \
/*return (returntype)0;*/ \
}\
else if (((tmp_mock->info_mock)->times_left != 0) && ((tmp_mock->info_mock)->times_left != INITSTATE )) {\
+45 -34
View File
@@ -94,11 +94,13 @@ char *default_bar_progress=" c";
//size_t width = 80;
char *colors_f[]={DEFAULT_K, GREEN_K, RED_K, YELLOW_K, BLUE_K, ""};
int kdefault=0, kgreen=1, kred=2, kyellow=3, kblue=4 , knothing= Dknothing;
int k_DEFAULT=0, k_GREEN=1, k_RED=2, k_YELLOW=3, k_BLUE=4, k_NOTHING=Dknothing;
char *tab_hk_f[]={ HK_EQ, HK_TR, HK_RN, HK_DN, HK_OK, HK_FL, HK_PS, HK_SK };
int hk_EQ=0, hk_TR=1, hk_RN=2, hk_DN=3, hk_OK=4, hk_FL=5, hk_PS=6, hk_SK=7 ;
char *varHK_EQ=HK_EQ, *varHK_TR=HK_TR, *varHK_RN=HK_RN, *varHK_DN=HK_DN, *varHK_OK=HK_OK, *varHK_FL=HK_FL, *varHK_PS=HK_PS, *varHK_SK=HK_SK;
bool some_tests_selected=0;
size_t *array_TYPE_SIZE_T=NULL; /* if active, size = count_tests */
@@ -185,10 +187,12 @@ pthread_mutex_t mut_count_pass_global;
pthread_mutex_t mut_count_fail_global;
pthread_mutex_t mut_count_pass_local;
pthread_mutex_t mut_count_fail_local;
/*
* end of the global variables of test_t.c
*/
/*
*
*/
@@ -273,6 +277,12 @@ char* extract_func_edited_TEST_from_exec_func_name(char* func_name){
// ========================== =================================
void setup_variables_before_exec(){
if(unicolour){
k_DEFAULT=k_NOTHING;
k_GREEN=k_NOTHING;
k_RED=k_NOTHING;
k_YELLOW=k_NOTHING;
k_BLUE=k_NOTHING;
size_t len_bp = strlen(bar_progress);
size_t len_db = strlen(default_bar_progress);
if( len_bp >= len_db ){
@@ -601,7 +611,7 @@ void parse_options(int argc, char **argv){
#define LISTE_ALL_FAILED_TEST_IN_F_OUT\
while(failed_lst){\
PRINT_HK_C(RED_K, HK_FL," %s\n",failed_lst->name);\
PRINT_HK_C(colors_f[k_RED], HK_FL," %s\n",failed_lst->name);\
failed_lst = failed_lst->next;\
}
@@ -614,7 +624,7 @@ void list_failed_test(struct failed_lists *test_failed){
LISTE_ALL_FAILED_TEST_IN_F_OUT
}else{
while(failed_lst){
PRINT_HK_C(RED_K, HK_FL," %s, on thread[%ld]\n",failed_lst->name,id_thrd);
PRINT_HK_C(colors_f[k_RED], HK_FL," %s, on thread[%ld]\n",failed_lst->name,id_thrd);
failed_lst = failed_lst->next;
}
}
@@ -622,7 +632,7 @@ void list_failed_test(struct failed_lists *test_failed){
else{
LISTE_ALL_FAILED_TEST_IN_F_OUT
}
PRINT_HK_C(DEFAULT_K, HK_EQ,"%s\n","");
PRINT_HK_C(colors_f[k_DEFAULT], HK_EQ,"%s\n","");
}
@@ -894,7 +904,7 @@ append_func(void (*run)(void), char *name){
void begin_execute_func(char *fun_ame, struct timespec *start_t){
clock_gettime(CLOCK_REALTIME, start_t);
PRINT_HK_C(GREEN_K,HK_RN," %s\n", fun_ame);
PRINT_HK_C(colors_f[k_GREEN],HK_RN," %s\n", fun_ame);
count_pass_local = 0;
count_fail_local = 0;
}
@@ -909,13 +919,13 @@ void end_execute_func(char *fun_ame, struct timespec start_t){
if(count_fail_local){
INCREMENT(count_fail_global); /*++count_fail_global*/
append_failed_list(&failed_l, fun_ame);
PRINT_HK_C(RED_K, HK_FL, " %lu tests failed from %s\n",count_fail_local,fun_ame);
PRINT_TIMESTAMP_STAT(RED_K);
PRINT_HK_C(colors_f[k_RED], HK_FL, " %lu tests failed from %s\n",count_fail_local,fun_ame);
PRINT_TIMESTAMP_STAT(colors_f[k_RED]);
}
else
{
INCREMENT(count_pass_global); /*++count_pass_global*/
PRINT_TIMESTAMP_STAT(GREEN_K);
PRINT_TIMESTAMP_STAT(colors_f[k_GREEN]);
}
}
/*
@@ -923,8 +933,8 @@ void end_execute_func(char *fun_ame, struct timespec start_t){
*/
void head_run(size_t nbtest, struct timespec *start_t){
clock_gettime(CLOCK_REALTIME, start_t);
if(cur_array_TYPE_SIZE_T || cur_array_TYPE_STRING) PRINT_HK_C(GREEN_K, HK_EQ," Running tests.\n");
else PRINT_HK_C(GREEN_K, HK_EQ," Running %lu tests.\n",nbtest);
if(cur_array_TYPE_SIZE_T || cur_array_TYPE_STRING) PRINT_HK_C(colors_f[k_GREEN], HK_EQ,"%s"," Running tests.\n");
else PRINT_HK_C(colors_f[k_GREEN], HK_EQ," Running %lu tests.\n",nbtest);
}
/*
@@ -934,13 +944,13 @@ void
stat_end_run(size_t ntst, struct timespec start_t){
struct timespec end_t; clock_gettime(CLOCK_REALTIME, &end_t);
if(SECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran. (%lf s total)\n",ntst, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran. (%ld ns total)\n",ntst, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran. (%lf ms total)\n",ntst, diff_timespec_milliseconds(end_t, start_t));
if(SECOND) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran. (%lf s total)\n",ntst, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran. (%ld ns total)\n",ntst, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran. (%lf ms total)\n",ntst, diff_timespec_milliseconds(end_t, start_t));
PRINT_HK_C(GREEN_K, HK_PS," %lu tests\n", count_pass_global);
PRINT_HK_C(colors_f[k_GREEN], HK_PS," %lu tests\n", count_pass_global);
if(failed_l != NULL){
PRINT_HK_C(RED_K, HK_FL," %lu tests, listed below:\n",count_fail_global);
PRINT_HK_C(colors_f[k_RED], HK_FL," %lu tests, listed below:\n",count_fail_global);
list_failed_test(failed_l);
PRINT_HK_C("","","\n%ld FAILED TESTS \n",count_fail_global);
}
@@ -1031,7 +1041,7 @@ void execute_all(struct func *fun){
size_t num_f;
char *name_test=NULL;
bool exec_test=0;
//PRINT_HK_C(GREEN_K, HK_EQ," Running %lu tests.\n",count_tests);
//PRINT_HK_C(colors_f[k_GREEN], HK_EQ," Running %lu tests.\n",count_tests);
while(tmp){
current_fn = tmp;
CHECK_IF_SELECTED_TEST(tmp->name)
@@ -1074,8 +1084,8 @@ run_all_tests()
*/
void head_all_parallel_run(struct timespec *start_t){
clock_gettime(CLOCK_REALTIME, start_t);
if (cur_array_TYPE_SIZE_T || cur_array_TYPE_STRING) PRINT_HK_C(GREEN_K, HK_EQ," Running tests on %ld threads\n", parallel_nb);
else PRINT_HK_C(GREEN_K, HK_EQ," Running %ld tests on %ld threads\n",count_tests, parallel_nb);
if (cur_array_TYPE_SIZE_T || cur_array_TYPE_STRING) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," Running tests on %ld threads\n", parallel_nb);
else PRINT_HK_C(colors_f[k_GREEN], HK_EQ," Running %ld tests on %ld threads\n",count_tests, parallel_nb);
}
/*
@@ -1085,7 +1095,7 @@ void head_parallel_run(struct timespec *start_t, size_t id_thrd){
sprintf(log_name_file_thrd[id_thrd],"log_thread_%ld_id_%ld",id_thrd,pthread_self());
f_ou_th[id_thrd] = fopen(log_name_file_thrd[id_thrd], "w+");
clock_gettime(CLOCK_REALTIME, start_t);
PRINT_HK_C(GREEN_K, HK_EQ," Running tests on thread[%ld] ========== ==threadID== %ld \n", id_thrd,pthread_self());
PRINT_HK_C(colors_f[k_GREEN], HK_EQ," Running tests on thread[%ld] ========== ==threadID== %ld \n", id_thrd,pthread_self());
}
/*
@@ -1095,13 +1105,13 @@ void
stat_end_parallel_run(size_t ntst, struct timespec start_t, size_t id_thrd){
struct timespec end_t; clock_gettime(CLOCK_REALTIME, &end_t);
if(SECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran on thread[%ld]. (%lf s total) \n",ntst, id_thrd, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran on thread[%ld]. (%ld ns total)\n",ntst, id_thrd, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran on thread[%ld]. (%lf ms total)\n",ntst, id_thrd, diff_timespec_milliseconds(end_t, start_t));
if(SECOND) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran on thread[%ld]. (%lf s total) \n",ntst, id_thrd, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran on thread[%ld]. (%ld ns total)\n",ntst, id_thrd, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran on thread[%ld]. (%lf ms total)\n",ntst, id_thrd, diff_timespec_milliseconds(end_t, start_t));
PRINT_HK_C(GREEN_K, HK_PS," %lu tests passed on thread[%ld]\n", count_pass_thread[id_thrd], id_thrd);
PRINT_HK_C(colors_f[k_GREEN], HK_PS," %lu tests passed on thread[%ld]\n", count_pass_thread[id_thrd], id_thrd);
if(thread_test_failed_l[id_thrd] != NULL){
PRINT_HK_C(RED_K, HK_FL," %lu tests failed on thread[%ld], listed below:\n",count_fail_thread[id_thrd],id_thrd);
PRINT_HK_C(colors_f[k_RED], HK_FL," %lu tests failed on thread[%ld], listed below:\n",count_fail_thread[id_thrd],id_thrd);
list_failed_test(thread_test_failed_l[id_thrd]);
}
}
@@ -1113,15 +1123,15 @@ void
stat_end_all_parallel_run(size_t ntst, struct timespec start_t){
struct timespec end_t; clock_gettime(CLOCK_REALTIME, &end_t);
//PRINT_HK_C(DEFAULT_K, HK_EQ," %s: all parallel tests done\n\n",__FILE__);
//PRINT_HK_C(colors_f[k_DEFAULT], HK_EQ," %s: all parallel tests done\n\n",__FILE__);
if(SECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran on %ld threads. (%lf s total) \n",ntst, parallel_nb, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran on %ld threads. (%ld ns total)\n",ntst, parallel_nb, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran on %ld threads. (%lf ms total)\n",ntst, parallel_nb, diff_timespec_milliseconds(end_t, start_t));
if(SECOND) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran on %ld threads. (%lf s total) \n",ntst, parallel_nb, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran on %ld threads. (%ld ns total)\n",ntst, parallel_nb, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(colors_f[k_GREEN], HK_EQ," %lu tests ran on %ld threads. (%lf ms total)\n",ntst, parallel_nb, diff_timespec_milliseconds(end_t, start_t));
PRINT_HK_C(GREEN_K, HK_PS," %lu tests\n", count_pass_global);
PRINT_HK_C(colors_f[k_GREEN], HK_PS," %lu tests\n", count_pass_global);
if(failed_l != NULL){
PRINT_HK_C(RED_K, HK_FL," %lu tests, listed below:\n",count_fail_global);
PRINT_HK_C(colors_f[k_RED], HK_FL," %lu tests, listed below:\n",count_fail_global);
list_failed_test(failed_l);
PRINT_HK_C("","","\n%ld FAILED TESTS \n",count_fail_global);
}
@@ -1131,7 +1141,7 @@ stat_end_all_parallel_run(size_t ntst, struct timespec start_t){
void begin_execute_func_parallel(char *fun_ame, struct timespec *start_t, size_t id_thrd){
clock_gettime(CLOCK_REALTIME, start_t);
PRINT_HK_C(GREEN_K,HK_RN," %s on thread[%ld]\n", fun_ame, id_thrd);
PRINT_HK_C(colors_f[k_GREEN],HK_RN," %s on thread[%ld]\n", fun_ame, id_thrd);
}
#define PRINT_TIMESTAMP_STAT_PARALLEL(color)\
@@ -1150,14 +1160,14 @@ void end_execute_func_parallel(char *fun_ame, struct timespec start_t, size_t id
LOCK(mut_global_list_fail);
append_failed_list(&failed_l, fun_ame);
UNLOCK(mut_global_list_fail);
PRINT_HK_C(RED_K, HK_FL, " %lu tests failed from %s on thread[%ld], %ld tests failed on thread[%ld]\n",count_fail_test[num_test],fun_ame, id_thrd,count_fail_thread[id_thrd],id_thrd);
PRINT_TIMESTAMP_STAT_PARALLEL(RED_K);
PRINT_HK_C(colors_f[k_RED], HK_FL, " %lu tests failed from %s on thread[%ld], %ld tests failed on thread[%ld]\n",count_fail_test[num_test],fun_ame, id_thrd,count_fail_thread[id_thrd],id_thrd);
PRINT_TIMESTAMP_STAT_PARALLEL(colors_f[k_RED]);
}
else
{
++(count_pass_thread[id_thrd]);
INCREMENT(count_pass_global); /*++count_pass_global*/
PRINT_TIMESTAMP_STAT_PARALLEL(GREEN_K);
PRINT_TIMESTAMP_STAT_PARALLEL(colors_f[k_GREEN]);
}
}
@@ -1404,5 +1414,6 @@ purge_tests()
struct func *tmp = f_beging;
clear_all_func(&tmp);
PRINT_DEBUG("%s\n","purge done");
}
+66 -291
View File
@@ -13,12 +13,12 @@
#include "tools_t/tools_t.h"
#include "bar_progress/bar_progress.h"
#define DEFAULT_K "\033[0m" //Resets the text to default color
#define DEFAULT_K "\033[0m" /*Resets the text to default color*/
#define GREEN_K "\033[0;32m"
#define RED_K "\033[0;31m"
#define YELLOW_K "\033[0;33m"
#define BLUE_K "\033[0;34m"
#define NOTHING_K ""
#define COLOR_SZ 6
@@ -67,306 +67,81 @@ extern char *savelog;
extern char *colors_f[];
extern char *tab_hk_f[];
extern int kdefault, kgreen, kred, kyellow, kblue, knothing;
extern int k_DEFAULT, k_GREEN, k_RED, k_YELLOW, k_BLUE, k_NOTHING;
extern int hk_EQ, hk_TR, hk_RN, hk_DN, hk_OK, hk_FL, hk_PS, hk_SK;
#ifndef SAVE_LOG
#define SAVE_LOG 0
#else
#ifndef ORDER_LOG
#define ORDER_LOG 1
#endif
#endif
extern char *varHK_EQ, *varHK_TR, *varHK_RN, *varHK_DN, *varHK_OK, *varHK_FL, *varHK_PS, *varHK_SK;
/*
* */
#define BUF_SIZE 256
#define INIT_STREAM_(stream,buf,len)\
FILE *stream;\
char *buf;\
size_t len;\
stream = open_memstream (&buf, &len);\
if (stream == NULL) { fprintf(stderr," error open_memstream %s:%d:%s \n",__FILE__,__LINE__,__func__); exit(0); }
#define CLOSE_STREAM_(stream, buf)\
fclose (stream);\
free (buf);
#define directory_in_memory "/dev/shm"
#define BUILD_PATH_ID_FILE(dir,id) STRFY(dir/id)
#define INIT_STREAM_MEM(stream, buf)\
char *buf = malloc(BUF_SIZE);\
char *filename=malloc(strlen(directory_in_memory) + strlen("tmp_")+32) ;\
sprintf(filename,"%s/tmp_%ld",directory_in_memory,pthread_self());\
FILE *stream = fopen(filename,"w+");\
if (stream == NULL) { fprintf(stderr," error open stream on \'tmp\' %s:%d:%s \n",__FILE__,__LINE__,__func__); exit(0); }
#define BEGIN_CPY_STREAM_MEM(stream, buf)\
rewind(stream);\
while(fgets(buf, BUF_SIZE, stream)){
#define END_CPY_STREAM_MEM(stream, buf)\
}\
fclose(stream);\
free(buf);\
remove(filename);\
#define CPY_STREAM_TO_OUT_THR(stream,msg)\
BEGIN_CPY_STREAM_MEM (stream, msg);\
fprintf(F_OUT, "%s",msg);\
if(id_thread >= 0){\
fprintf(f_ou_th[id_thread], "%s",msg);\
}\
END_CPY_STREAM_MEM (stream, msg);\
#define INIT_STREAM_MEM_SV_(stream, buf,savelog)\
char *buf = malloc(BUF_SIZE);\
char *filename=malloc(strlen(directory_in_memory) + strlen("tmp_")+32) ;\
sprintf(filename,"%s/tmp_%ld",directory_in_memory,pthread_self());\
FILE *stream = fopen(filename,"w+");\
if (stream == NULL) { fprintf(stderr," error open stream on \'tmp\' %s:%d:%s \n",__FILE__,__LINE__,__func__); exit(0); }\
FILE *f_savelog = fopen(savelog,"w+");\
if (f_savelog == NULL) { fprintf(stderr," error open f_savelog on \'tmp\' %s:%d:%s \n",__FILE__,__LINE__,__func__); exit(0); }
#define _CPY_STREAM_OUT_AND_SV_(stream, f_savelog, msg)\
BEGIN_CPY_STREAM_MEM (stream, msg)\
fprintf(F_OUT,"%s",msg);\
fprintf(f_savelog,"%s",msg); \
END_CPY_STREAM_MEM (stream, msg);\
fclose(f_savelog);
#if 1
/*
* to execute once in print functions in the case of log_parallel (printing on screen and recording in file), we have to copy to string before copy it,
* I've tried open_memstream but it have some bugs.
* so I use normal fopen a file a memory location '/dev/shm', it is remove after use!
* to execute once in print functions in the case of log_parallel (printing on screen and recording in file), we have to copy to stream -> string before copy it,
* so I have tried using fopen a file in memory location '/dev/shm' and remove it after use!
* /dev/shm/tmp_PTHREAD_SELF() but it prints twice sometimes,
* here a solution with open_memstream which is better
*/
#define PRINTF( ...) \
do{ \
FILE *stream ;\
size_t len;\
char *buf ;\
stream = open_memstream (&buf, &len);\
if (stream == NULL) { fprintf(stderr," error open_memstream %s:%d:%s \n",__FILE__,__LINE__,__func__); exit(0); }\
fprintf(stream, __VA_ARGS__); \
fflush(stream);\
rewind(stream);\
if(is_parallel_nb){\
long int id_thread=id_of_thread_executed();\
if(log_parallel){\
INIT_STREAM_MEM (stream, msg);\
fprintf(stream, __VA_ARGS__);\
CPY_STREAM_TO_OUT_THR(stream, msg);\
fprintf(F_OUT, "%s",buf);\
if(id_thread >= 0){\
fprintf(f_ou_th[id_thread], "%s",buf);\
fflush(f_ou_th[id_thread]);\
}\
else{\
if(id_thread < 0){\
fprintf(F_OUT,__VA_ARGS__);\
}\
else{\
fprintf(f_ou_th[id_thread], __VA_ARGS__);\
if(id_thread >= 0){\
fprintf(f_ou_th[id_thread], "%s",buf);\
fflush(f_ou_th[id_thread]);\
}\
else {\
fprintf(F_OUT, "%s",buf);\
}\
}\
} \
else{\
if(savelog){\
INIT_STREAM_MEM_SV_(stream,msg,savelog);\
fprintf(stream, __VA_ARGS__);\
_CPY_STREAM_OUT_AND_SV_(stream, f_savelog, msg);\
FILE *f_savelog = fopen(savelog,"w+");\
fprintf(f_savelog, "%s",buf);\
fclose(f_savelog);\
}\
else\
fprintf(F_OUT, __VA_ARGS__);\
else{\
fprintf(F_OUT, "%s",buf);\
}\
}\
fclose(stream);\
free(buf);\
}while(0)
#define LOG(...) PRINTF(__VA_ARGS__)
#define PRINT_LOC(fmt, ...) \
PRINTF( "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, __VA_ARGS__)
/*
#define PRINT_HK_C(color,hk,...)\
PRINTF(color hk DEFAULT_K __VA_ARGS__)
*/
#define PRINT_HK_C(color,hk,...)\
do{ \
if(is_parallel_nb){\
long int id_thread=id_of_thread_executed();\
if(log_parallel){\
INIT_STREAM_MEM(stream, msg);\
if(!unicolour) fprintf(stream, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(stream, hk __VA_ARGS__); \
CPY_STREAM_TO_OUT_THR (stream, msg)\
fflush(f_ou_th[id_thread]);\
}\
else{\
if(id_thread < 0){\
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); \
}\
else{\
if(!unicolour) fprintf(f_ou_th[id_thread], color hk DEFAULT_K __VA_ARGS__); \
else fprintf(f_ou_th[id_thread], hk __VA_ARGS__); \
fflush(f_ou_th[id_thread]);\
}\
}\
} \
else{\
if(savelog){\
INIT_STREAM_MEM_SV_(stream, msg, savelog);\
if(!unicolour) fprintf(stream, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(stream, hk __VA_ARGS__);\
_CPY_STREAM_OUT_AND_SV_ (stream, f_savelog, msg);\
}\
else{\
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); \
}\
}\
}while(0)
#else
#define PRINT_HK_C(color,hk,fmt,...)\
PRINTF("%s%s%s" fmt, color,hk,colors_f[k_DEFAULT],__VA_ARGS__)
#define PRINT_LOC(fmt, ...) \
do{ \
/*if(ordered){*/\
if(is_parallel_nb){\
long int id_thread=id_of_thread_executed();\
if(log_parallel){\
INIT_STREAM_MEM (stream, msg);\
fprintf(stream, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, __VA_ARGS__);\
CPY_STREAM_TO_OUT_THR (stream, msg);\
fflush(f_ou_th[id_thread]);\
}\
else{\
if(id_thread < 0){\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
}\
else{\
fprintf(f_ou_th[id_thread], "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
fflush(f_ou_th[id_thread]);\
}\
}\
} \
else{\
if(savelog){\
INIT_STREAM_MEM_SV_(stream, msg,savelog);\
fprintf(stream, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, __VA_ARGS__);\
_CPY_STREAM_OUT_AND_SV_(stream, f_savelog, msg);\
}\
else\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, __VA_ARGS__);\
}\
}while(0)
#endif
#if 0
/* below old solution, but it execute twice functions called in print functions when log_parallel == 1 */
#define PRINT_LOC(fmt, ...) \
do{ \
/*if(ordered){*/\
if(is_parallel_nb){\
size_t id_thread=id_of_thread_executed();\
if(id_thread < 0){\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
}\
else{\
fprintf(f_ou_th[id_thread], "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
}\
} \
/*else{\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
}\
}\
else{*/if(log_parallel || !is_parallel_nb){\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
}\
}while(0)
#define PRINTF( ...) \
do{ \
printf("\n\n sizeof VARGS:%ld \n\n",sizeof(__VA_ARGS__));\
/*if(ordered){*/\
if(is_parallel_nb){\
size_t id_thread=id_of_thread_executed();\
if(id_thread < 0){\
fprintf(F_OUT,__VA_ARGS__);\
}\
else{\
fprintf(f_ou_th[id_thread], __VA_ARGS__);\
}\
} \
/*else{\
fprintf(F_OUT, __VA_ARGS__);\
}\
}\
else{*/if(log_parallel || !is_parallel_nb){\
fprintf(F_OUT, __VA_ARGS__);\
}\
}while(0)
#define LOG(...) PRINTF(__VA_ARGS__)
#define PRINT_HK_C(color,hk,...)\
do{ \
/*if(ordered){*/\
if(is_parallel_nb){\
size_t id_thread=id_of_thread_executed();\
if(id_thread < 0){\
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); \
}\
else{\
if(!unicolour) fprintf(f_ou_th[id_thread], color hk DEFAULT_K __VA_ARGS__); \
else fprintf(f_ou_th[id_thread], hk __VA_ARGS__); \
}\
} \
/*else{\
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); \
}*/\
/*}*/\
/*else{*/if(log_parallel || !is_parallel_nb){\
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); \
}\
}while(0)
#endif
#if 0
/*
* print [ HK_NAME ] with color
*/
#define PRINT_HK_C(color,hk,format,...)\
do{ if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K format, __VA_ARGS__); \
else fprintf(F_OUT, hk format, __VA_ARGS__); } while(0) \
#endif /* 0 */
/*
* to skip the bloc test function
*/
#define SKIP(...)\
PRINT_HK_C(GREEN_K, HK_SK __VA_ARGS__);\
#define SKIP(fmt,...)\
PRINT_HK_C(colors_f[k_GREEN], HK_SK, fmt, ## __VA_ARGS__);\
PRINT_LOC("%s\n\n" DEFAULT_K," Skiped "); return;
@@ -535,26 +310,26 @@ GEN_EXPECTED_OP_TYPE_FUNC(NE, TYPE_STRING)
do{ \
if(is_parallel_nb == 0){\
if(expected_##OP##_##type(var1, var2)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 %s passed from %s \n\n",name_f,msg_call); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 %s passed from %s \n\n",name_f,msg_call); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); */ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 %s failed from %s \n",name_f,msg_call); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 %s failed from %s \n",name_f,msg_call); \
} \
}else { \
if(expected_##OP##_name_##type(var1, var2, name_f)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 %s passed from %s \n\n",name_f,msg_call); \
/*PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",name_f);*/ \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 %s passed from %s \n\n",name_f,msg_call); \
/*PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",name_f);*/ \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP ,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2));*/ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 %s failed from %s \n",name_f,msg_call); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 %s failed from %s \n",name_f,msg_call); \
} \
}\
}while(0);
@@ -569,26 +344,26 @@ do{ \
do{ \
if(is_parallel_nb == 0){\
if(expected_##OP##_##type(var1, var2)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); */ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
if(is_assert) return; \
} \
}else { \
if(expected_##OP##_name_##type(var1, var2, __func__)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP ,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2));*/ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
if(is_assert) return; \
} \
}\
@@ -603,25 +378,25 @@ do{ \
do{ \
if(is_parallel_nb == 0){\
if(expected_##OP##_##type(var1, var2)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); */ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
} \
}else { \
if(expected_##OP##_name_##type(var1, var2, __func__)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP ,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2));*/ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
} \
}\
}while(0);
@@ -630,26 +405,26 @@ do{ \
do{ \
if(is_parallel_nb == 0){\
if(expected_##OP##_##type(var1, var2)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); */ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
return; \
} \
}else { \
if(expected_##OP##_name_##type(var1, var2, __func__)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
/*PRINT_LOC("Failure\nExpected %s of these values:\n %s\n\tWhich is: %s\n %s\n\tWhich is: %s\n\n"\
,DESCRIPTION_##OP ,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2));*/ \
PRINT_LOC("Failure\nExpected: (%s) %s (%s) :\n Value of %s: %s \n Value of %s: %s\n\n"\
,#var1,STRFY(OP),#var2,#var1, type##_TO_STR(var1), #var2, type##_TO_STR(var2)); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
return; \
} \
}\
@@ -895,21 +670,21 @@ do{ \
do{ \
if(is_parallel_nb==0){\
if(expected_##expect##_f(var1)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
PRINT_LOC("Failure\nValue of: %s\nActual: %s\nExpected: %s\n\n", #var1, #not_expect, #expect);\
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
if(is_assert) return; \
} \
}\
else{\
if(expected_##expect##_f_name(var1, __func__)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
PRINT_LOC("Failure\nValue of: %s\nActual: %s\nExpected: %s\n\n", #var1, #not_expect, #expect);\
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n",__func__); \
if(is_assert) return; \
} \
}\
@@ -923,21 +698,21 @@ do{
do{ \
if(is_parallel_nb==0){ \
if(expected_##expect##_f(var1)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
PRINT_LOC("Failure\nValue of: %s\nActual: %s\nExpected: %s\n", #var1, #not_expect, #expect); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n\n",__func__); \
} \
} \
else{ \
size_t id_thread=id_of_thread_executed(); \
if(expected_##expect##_f_name(var1, __func__)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s, on thread[%ld]\n\n",__func__,id_thread); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s, on thread[%ld]\n\n",__func__,id_thread); \
} \
else{ \
PRINT_LOC("Failure\nValue of: %s\nActual: %s\nExpected: %s\n", #var1, #not_expect, #expect); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s, on thread[%ld]\n\n",__func__,id_thread); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s, on thread[%ld]\n\n",__func__,id_thread); \
} \
} \
}while(0);
@@ -947,22 +722,22 @@ do{
do{ \
if(is_parallel_nb==0){ \
if(expected_##expect##_f(var1)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s \n\n",__func__); \
} \
else{ \
PRINT_LOC("Failure\nValue of: %s\nActual: %s\nExpected: %s\n", #var1, #not_expect, #expect); \
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s \n\n",__func__); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s \n\n",__func__); \
return; \
} \
}\
else{\
size_t id_thread=id_of_thread_executed(); \
if(expected_##expect##_f_name(var1, __func__)){ \
PRINT_HK_C(GREEN_K,HK_TR," 1 test passed from %s, on thread[%ld]\n\n",__func__,id_thread); \
PRINT_HK_C(colors_f[k_GREEN],HK_TR," 1 test passed from %s, on thread[%ld]\n\n",__func__,id_thread); \
} \
else{ \
PRINT_LOC("Failure\nValue of: %s\nActual: %s\nExpected: %s\n\n", #var1, #not_expect, #expect);\
PRINT_HK_C(RED_K,HK_TR," 1 test failed from %s, on thread[%ld]\n\n",__func__, id_thread); \
PRINT_HK_C(colors_f[k_RED],HK_TR," 1 test failed from %s, on thread[%ld]\n\n",__func__, id_thread); \
return; \
} \
}\
+7 -5
View File
@@ -14,7 +14,7 @@
#include "permutation_t/permutation_t.h"
#if 0
#if 1
TEST(size_permutation2){
PRINTF("another size_permutation2 again\n");
@@ -94,7 +94,7 @@ TEST(expect){
int b = 6;
EXPECT_EQ(a,b);
//SKIP();
SKIP("on skip eq string\n");
SKIP("%s\n","on skip eq string");
EXPECT_EQ_TYPE_STRING("hello","hello");
float f1 = 1.00019999, f2=1.00019999;
EXPECT_EQ_TYPE_FLOAT(f1,f2);
@@ -346,9 +346,11 @@ EXPECT_MOCK_CALL(int, f7_mock,(int a, int b),(a>b),2){
}
TEST(f4_mock_test){
PRINTF("f7 ret: %d\n",f7_mock(1,1));
PRINTF("second call f7 : %d\n",f7_mock(2,0));
TEST(f7_mock_test){
int v0=f7_mock(1,1);
PRINTF("f7 ret: %d\n",v0);
int v1=f7_mock(2,0);
PRINTF("second call f7 : %d\n",v1);
}