debug PRINT macros, add some features fmocks
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
gcc test/is_good.c src/ftest/ftest.c src/fmock/fmock.c src/tools_t/tools_t.c \
|
||||
gcc test/is_good.c src/ftest/ftest.c src/fmock/fmock.c \
|
||||
src/tools_t/tools_t.c src/bar_progress/bar_progress.c \
|
||||
src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c \
|
||||
-I./src $1 -E > eEcomp
|
||||
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
gcc test/is_good.c src/ftest/ftest.c src/fmock/fmock.c src/tools_t/tools_t.c \
|
||||
gcc test/is_good.c src/ftest/ftest.c src/fmock/fmock.c \
|
||||
src/tools_t/tools_t.c src/bar_progress/bar_progress.c \
|
||||
src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c \
|
||||
-I./src $1 -o launch_is_good_c #&& ./launch_is_good_c -h -p
|
||||
-I./src $1 -o launch_is_good_c -lpthread #&& ./launch_is_good_c -h -p
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,167 @@
|
||||
|
||||
#include "bar_progress/bar_progress.h"
|
||||
|
||||
#define bg_red "\033[0;41m"
|
||||
#define bg_green "\033[0;42m"
|
||||
#define bg_yellow "\033[0;43m"
|
||||
#define bg_blue "\033[0;44m"
|
||||
#define bg_magenta "\033[0;45m"
|
||||
#define bg_cyan "\033[0;46m"
|
||||
#define bg_white "\033[30;47m"
|
||||
#define bg_gray "\033[37;40m"
|
||||
|
||||
#define BG_GREEN "\033[42;30m"
|
||||
#define BG_RED "\033[41m"
|
||||
|
||||
static struct winsize w;
|
||||
static int initialized = 0;
|
||||
|
||||
|
||||
static void set_window_height_for_bar_progress(int height)
|
||||
{
|
||||
fprintf(stdout, "\n\0337" // save cursor
|
||||
"\033[0;%dr" // set scroll region (this will place the cursor in the top left)
|
||||
"\0338\033[1A\033[J" // restore cursor but ensure its inside the scrolling area
|
||||
, height);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
static void init_progress_bar()
|
||||
{
|
||||
//ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
ioctl(1, TIOCGWINSZ, &w);
|
||||
set_window_height_for_bar_progress(w.ws_row - 1);
|
||||
}
|
||||
|
||||
|
||||
static void abort_progress_bar()
|
||||
{
|
||||
bar_progress_stop();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
void bar_progress_start()
|
||||
{
|
||||
signal(SIGWINCH, init_progress_bar);
|
||||
signal(SIGINT, abort_progress_bar);
|
||||
//signal(SIGSEGV, abort_progress_bar);
|
||||
init_progress_bar();
|
||||
initialized = 1;
|
||||
bar_progress_step(0);
|
||||
}
|
||||
|
||||
|
||||
void bar_progress_step_msg(int step_progress, int all_progress, char *msg, char fill_bar, char fill_dot, int colored /*bool */)
|
||||
{
|
||||
static int cur_round=0;
|
||||
char prgss[]="\\|/-";
|
||||
int len = strlen(prgss);
|
||||
|
||||
if (initialized == 0) {
|
||||
fprintf(stderr, "error: bar_progress_step() called before bar_progress_start().\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (step_progress < 0) {
|
||||
step_progress = 0;
|
||||
}
|
||||
else if (step_progress >= all_progress) {
|
||||
step_progress = all_progress -1;
|
||||
}
|
||||
int size_char_log= strlen(msg) + strlen("(-) Progress: [100a] [aaaa/bbbb] a");
|
||||
int width = (w.ws_col - size_char_log);
|
||||
int j;
|
||||
/*
|
||||
for(int j=0; j< width ; ++j)
|
||||
if (j<(int)(width * (step_progress / 100))) bar[j]='=';
|
||||
else bar[j]='.';
|
||||
bar[width] = 0;
|
||||
*/
|
||||
int status_percent = (step_progress+1) * 100 / all_progress;
|
||||
int status_progress = (step_progress+1) * width / all_progress;
|
||||
|
||||
char *bar = malloc(status_progress + 1); //w.ws_col);
|
||||
char *dot = malloc(width - status_progress +1 ); //w.ws_col);
|
||||
|
||||
/*for(j=0; j< status_progress ; ++j)
|
||||
bar[j]=fill_bar;//' ';//'#';//'=';
|
||||
*/
|
||||
memset(bar,fill_bar,status_progress);
|
||||
|
||||
bar[status_progress]='\0';
|
||||
|
||||
/*for(j=0;j<width - status_progress; ++j)
|
||||
dot[j]=fill_dot;//' ';//'-'; //'.';
|
||||
*/
|
||||
memset(dot,fill_dot, width-status_progress);
|
||||
dot[width - status_progress]='\0';
|
||||
|
||||
|
||||
if(colored)printf("\e[s\e[%d;0H(%c) "bg_white"Progress: [%3d%%]\e[0m ["bg_green"%s"bg_red"%s\e[0m] %s [%3d/%3d]\e[u", w.ws_row + 1, prgss[cur_round], status_percent, bar, dot, msg, step_progress + 1, all_progress);
|
||||
else printf("\e[s\e[%d;0H(%c) "bg_gray"Progress: [%3d%%]\e[0m ["bg_white"%s"bg_gray"%s\e[0m] %s [%3d/%3d]\e[u", w.ws_row + 1, prgss[cur_round], status_percent, bar, dot, msg, step_progress + 1, all_progress);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H(%c) "bg_green"Progress: [%3d%%]\e[0m ["bg_green"%s"bg_red"%s\e[0m] %s [%3d/%3d]\e[u", w.ws_row + 1,prgss[cur_round], status_percent, bar,dot,msg,step_progress,all_progress);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H(%c) "bg_green"Progress: [%3d%%]\e[0m ["BG_GREEN"%s"BG_RED"%s\e[0m] %s [%3d/%3d]\e[u", w.ws_row + 1,prgss[cur_round], status_percent, bar,dot,msg,step_progress,all_progress);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H(%c) \e[42;30mProgress: [%3d%%]\e[0m [%s%s%s%s\033[0m] %s [%3d/%3d]\e[u", w.ws_row + 1,prgss[cur_round], status_percent,BG_GREEN, bar, BG_RED,dot,msg,step_progress,all_progress);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [\033[42;30m%s\033[41m%s\033[0m]\e[u", w.ws_row + 1, (int) step_progress, bar,dot);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [%s]\e[u", w.ws_row + 1, (int) step_progress, bar);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [%s%s]\e[u", w.ws_row + 1, (int) step_progress, bar,dot);
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
if(cur_round<len-1) ++cur_round;
|
||||
else cur_round = 0;
|
||||
|
||||
free(bar);
|
||||
free(dot);
|
||||
}
|
||||
|
||||
void bar_progress_step(float step_progress)
|
||||
{
|
||||
if (initialized == 0) {
|
||||
fprintf(stderr, "error: bar_progress_step() called before bar_progress_start().\n");
|
||||
exit(1);
|
||||
}
|
||||
char *bar = malloc(w.ws_col);
|
||||
char *dot = malloc(w.ws_col);
|
||||
|
||||
if (step_progress < 0) {
|
||||
step_progress = 0;
|
||||
} else if (step_progress > 100) {
|
||||
step_progress = 100;
|
||||
}
|
||||
int width = (w.ws_col - 20);
|
||||
int j;
|
||||
/*
|
||||
for(int j=0; j< width ; ++j)
|
||||
if (j<(int)(width * (step_progress / 100))) bar[j]='=';
|
||||
else bar[j]='.';
|
||||
bar[width] = 0;
|
||||
*/
|
||||
int status = (int)(width * (step_progress / 100));
|
||||
for(j=0; j< status ; ++j)
|
||||
bar[j]='=';
|
||||
|
||||
bar[j]='\0';
|
||||
for(j=0;j<width-status; ++j)
|
||||
dot[j]='.';
|
||||
dot[j]='\0';
|
||||
|
||||
|
||||
fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [%s%s%s%s\033[0m]\e[u", w.ws_row + 1, (int) step_progress,BG_GREEN, bar, BG_RED,dot);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [\033[42;30m%s\033[41m%s\033[0m]\e[u", w.ws_row + 1, (int) step_progress, bar,dot);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [%s]\e[u", w.ws_row + 1, (int) step_progress, bar);
|
||||
//fprintf(stdout, "\e[s\e[%d;0H\e[42;30mProgress: [%3d%%]\e[0m [%s%s]\e[u", w.ws_row + 1, (int) step_progress, bar,dot);
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
free(bar);
|
||||
free(dot);
|
||||
}
|
||||
|
||||
|
||||
void bar_progress_stop()
|
||||
{
|
||||
set_window_height_for_bar_progress(w.ws_row);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef __BAR_PROGRESS_H__
|
||||
#define __BAR_PROGRESS_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Prepares screen for progress bar.
|
||||
*/
|
||||
void bar_progress_start(void);
|
||||
|
||||
void bar_progress_step_msg(int step_progress, int all_progress, char *msg, char fill_bar, char fill_dot, int colored);
|
||||
|
||||
/*
|
||||
* progress value 0 to 100
|
||||
*/
|
||||
void bar_progress_step(float step_percent);
|
||||
|
||||
/*
|
||||
* Removes progress bar and restores original screen size.
|
||||
*/
|
||||
void bar_progress_stop(void);
|
||||
|
||||
#endif /* __BAR_PROGRESS_H */
|
||||
+175
-1
@@ -1,5 +1,34 @@
|
||||
#include "fmock/fmock.h"
|
||||
|
||||
/*
|
||||
* global variables
|
||||
*/
|
||||
|
||||
//char *colors_f[]={DEFAULT_K, RED_K, GREEN_K, YELLOW_K, BLUE_K, ""};
|
||||
|
||||
size_t count_f_mock_wished=0;
|
||||
pthread_mutex_t mut_count_f_mock_wished;
|
||||
|
||||
size_t count_f_mock=0;
|
||||
pthread_mutex_t mut_count_f_mock;
|
||||
|
||||
size_t count_expect_mock=0;
|
||||
pthread_mutex_t mut_count_expect_mock;
|
||||
|
||||
struct list_base_fmock *g_list_base_fmock=NULL;
|
||||
|
||||
#define LOCK(mutex_var) pthread_mutex_lock(&mutex_var);
|
||||
#define UNLOCK(mutex_var) pthread_mutex_unlock(&mutex_var);
|
||||
|
||||
|
||||
#define INCREMENT_(variable)\
|
||||
do{\
|
||||
LOCK(mut_##variable); \
|
||||
++variable;\
|
||||
UNLOCK(mut_##variable);\
|
||||
}while(0);
|
||||
|
||||
|
||||
/*
|
||||
* return the numbers of comas (,) +1 in the input string
|
||||
*/
|
||||
@@ -13,19 +42,164 @@ int parse_count_args_(char *input){
|
||||
return val+1;
|
||||
}
|
||||
|
||||
/*
|
||||
* the begin only !
|
||||
*/
|
||||
void append_list_base_fmock(struct list_base_fmock **l_fmock, struct func_mock_info_struct *f_mock){
|
||||
INCREMENT_(count_f_mock);
|
||||
if(*l_fmock){
|
||||
struct list_base_fmock *tmp_l_n = *l_fmock;
|
||||
while(tmp_l_n->next) tmp_l_n = tmp_l_n->next;
|
||||
(tmp_l_n->next) = malloc(sizeof(struct list_base_fmock));
|
||||
(tmp_l_n->next)->info_mock = f_mock;
|
||||
}
|
||||
else{
|
||||
*l_fmock = malloc(sizeof(struct list_base_fmock));
|
||||
(*l_fmock)->info_mock = f_mock;
|
||||
}
|
||||
}
|
||||
|
||||
struct func_mock_info_struct *f_mock_glist;
|
||||
pthread_mutex_t mut_f_mock_glist;
|
||||
|
||||
void append_fmock_to_listmock(struct func_mock_info_struct **f_mock_list, struct func_mock_info_struct *f_mock){
|
||||
INCREMENT_(count_f_mock_wished);
|
||||
if(f_mock->expect_call) {
|
||||
INCREMENT_(count_expect_mock);
|
||||
}
|
||||
LOCK(mut_f_mock_glist);
|
||||
if(*f_mock_list){
|
||||
struct func_mock_info_struct *tmp_fmock_info = *f_mock_list;
|
||||
while(tmp_fmock_info->next) tmp_fmock_info = tmp_fmock_info->next;
|
||||
tmp_fmock_info->next = f_mock;
|
||||
}
|
||||
else{
|
||||
//*f_mock_global = malloc(sizeof(struct func_mock_info_struct));
|
||||
*f_mock_list = f_mock;
|
||||
}
|
||||
UNLOCK(mut_f_mock_glist);
|
||||
|
||||
}
|
||||
|
||||
char* extract_name_func_mock(char *input){
|
||||
char * ret=malloc(strlen(input));
|
||||
strcpy(ret,input);
|
||||
for(size_t i=0; i<strlen(ret)-6; ++i){
|
||||
if(strncmp(ret+i,"_line_",6) == 0){
|
||||
ret[i]='\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
void
|
||||
init_mock_c(){
|
||||
|
||||
pthread_mutex_init(&mut_f_mock_glist, NULL);
|
||||
pthread_mutex_init(&mut_count_f_mock_wished, NULL);
|
||||
pthread_mutex_init(&mut_count_f_mock, NULL);
|
||||
pthread_mutex_init(&mut_count_expect_mock, NULL);
|
||||
}
|
||||
|
||||
extern bool is_parallel_nb;
|
||||
|
||||
char * number_call_translate(long nb){
|
||||
char *ret=malloc(250);
|
||||
if(nb>0) sprintf(ret,"%ld",nb);
|
||||
else if(nb == 0 ) sprintf(ret,"zero");
|
||||
else if(nb==INFINITY) sprintf(ret,"INFINITY");
|
||||
else sprintf(ret,"negative");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
__attribute__((destructor))
|
||||
void
|
||||
check_mock_excpected(){
|
||||
|
||||
//int kdefault=0, kgreen=1, kred=2, kyellow=3, kblue=4, knothing=5;
|
||||
if(unicolour) {
|
||||
kgreen=5; kred=5; kyellow=5; kblue=5;
|
||||
}
|
||||
|
||||
struct winsize w;
|
||||
ioctl(1, TIOCGWINSZ, &w);
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
is_parallel_nb = 0; /* no longer parallel here */
|
||||
struct func_mock_info_struct *tmock = f_mock_glist, *tfree;
|
||||
|
||||
/* global order of fmock , order of expect and will */
|
||||
while(tmock){
|
||||
PRINT_DEBUG("check mock function: %s\n",tmock->str_namefunc);
|
||||
tfree=tmock;
|
||||
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)){
|
||||
PRINTF("%s%s %s %s expect to be called with condition %s, %s times, it was called %ld times and failed %ld times \n",colors_f[kred],HK_TR,tmock->str_namefunc,DEFAULT_K, tmock->str_conditions,
|
||||
number_call_translate(tmock->init_times_left),
|
||||
tmock->call/*tmock->failed_call + (tmock->init_times_left - tmock->times_left)*/,
|
||||
tmock->failed_call );
|
||||
}
|
||||
tmock=tmock->next;
|
||||
//free(tfree);
|
||||
}
|
||||
|
||||
PRINTF("\n%s%s STAT MOCK : there are %ld mock functions, %ld wished response, %ld expected response, which are:\n\n",colors_f[kgreen],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 */
|
||||
while(tmp_list_fm){
|
||||
tmp_inf_mock = tmp_list_fm->info_mock;
|
||||
memset(reader,'=',w.ws_col-1);
|
||||
char *nameff=extract_name_func_mock(tmp_inf_mock->str_namefunc);
|
||||
size_t len_nameff=strlen(nameff);
|
||||
size_t bg_rd=(w.ws_col - len_nameff)/2;
|
||||
for(size_t i=0; i<len_nameff; ++i)
|
||||
reader[bg_rd+i]=nameff[i];
|
||||
|
||||
PRINTF("%s%s%s\n\n",colors_f[kblue],reader,DEFAULT_K );
|
||||
while(tmp_inf_mock){
|
||||
if(0==strncmp(tmp_inf_mock->str_namefunc,nameff, len_nameff)){
|
||||
if(tmp_inf_mock->expect_call){
|
||||
if(tmp_inf_mock->init_times_left == tmp_inf_mock->times_left || tmp_inf_mock->failed_call){
|
||||
PRINTF("%s%s%s %s\t expect be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s \n" ,
|
||||
colors_f[kred],HK_EQ,DEFAULT_K,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
|
||||
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller);
|
||||
}else{
|
||||
PRINTF("%s%s %s\t expect be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s %s\n" ,
|
||||
colors_f[kgreen],HK_TR,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
|
||||
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller, DEFAULT_K);
|
||||
}
|
||||
}else{
|
||||
if(tmp_inf_mock->failed_call){
|
||||
PRINTF("%s%s%s %s\t will be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s \n" ,
|
||||
colors_f[kred],HK_EQ,DEFAULT_K,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
|
||||
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller);
|
||||
}else{
|
||||
PRINTF("%s%s %s\t will be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s %s\n" ,
|
||||
colors_f[kyellow],HK_TR,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
|
||||
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller, DEFAULT_K);
|
||||
}
|
||||
}
|
||||
}
|
||||
tmp_inf_mock = tmp_inf_mock->next;
|
||||
}
|
||||
tmp_list_fm = tmp_list_fm->next;
|
||||
}
|
||||
|
||||
PRINT_DEBUG("%s\n","check mock done!");
|
||||
|
||||
pthread_mutex_destroy(&mut_f_mock_glist);
|
||||
pthread_mutex_destroy(&mut_count_f_mock_wished);
|
||||
pthread_mutex_destroy(&mut_count_f_mock);
|
||||
pthread_mutex_destroy(&mut_count_expect_mock);
|
||||
}
|
||||
|
||||
|
||||
+71
-11
@@ -12,16 +12,27 @@ struct func_mock_info_struct{
|
||||
long id;
|
||||
char *str_namefunc;
|
||||
char *str_conditions;
|
||||
char *str_caller;
|
||||
int expect_call;/* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */
|
||||
long call;/* increment when call (try to executed) and 0 if not : init value */
|
||||
long failed_call;/* increment when condition not fill and 0 if not : init value */
|
||||
long init_times_left;/* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */
|
||||
long times_left;/* DONOTHING do nothing (pass to -> next), INFINITY every time; INITSTATE init; > 0 execute and decrement */
|
||||
struct func_mock_info_struct *next;
|
||||
};
|
||||
|
||||
struct list_base_fmock{
|
||||
struct func_mock_info_struct *info_mock;
|
||||
struct list_base_fmock *next;
|
||||
};
|
||||
|
||||
|
||||
int parse_count_args_(char *input);
|
||||
void append_fmock_to_listmock(struct func_mock_info_struct **f_mock_list, struct func_mock_info_struct *f_mock);
|
||||
void append_list_base_fmock(struct list_base_fmock **l_fmock, struct func_mock_info_struct *f_mock);
|
||||
|
||||
extern struct func_mock_info_struct *f_mock_glist;
|
||||
extern struct list_base_fmock *g_list_base_fmock;
|
||||
|
||||
#if 0
|
||||
int expect_call; /* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */\
|
||||
@@ -50,34 +61,66 @@ extern struct func_mock_info_struct *f_mock_glist;
|
||||
list_mo_ ## namefunction.next = NULL;\
|
||||
}\
|
||||
returntype namefunction args_prototype_with_parenthesis {\
|
||||
/*static size_t count_call_f=0;\
|
||||
PRINT_DEBUG(">>>>>>count call of %s: %ld\n",STRFY(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, no EXPECT or WILL CALL defined for the mock function %s.\n",#namefunction);\
|
||||
PRINT_HK_C(YELLOW_K,HK_TR," Can be defined by EXPECT_MOCK_CALL(%s,%s,%s,true,1) if call once and accept all args, the same args with WILL_MOCK_CALL \n",STRFY (returntype), STRFY(namefunction),STRFY (args_prototype_with_parenthesis) ); \
|
||||
return (returntype)0; \
|
||||
}\
|
||||
while(tmp_mock->next && (tmp_mock->info_mock)->times_left == 0) tmp_mock = tmp_mock->next ;\
|
||||
++((tmp_mock->info_mock)->call);\
|
||||
/*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");*/\
|
||||
if(0 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
||||
if ((tmp_mock->info_mock)->times_left == 0) /*no longer response, default return */ \
|
||||
return (returntype)0;/* default return */\
|
||||
if( (tmp_mock->info_mock)->str_caller == NULL){ \
|
||||
PRINT_HK_C(YELLOW_K,HK_TR," WARNING, MOCK need to be initialized in TEST env call by INIT_CALLER_MOCK(%s) if need to have stats\n",(tmp_mock->info_mock)->str_namefunc); \
|
||||
/*return (returntype)0;*/ \
|
||||
}\
|
||||
else{\
|
||||
size_t len0 = strlen((tmp_mock->info_mock)->str_conditions);\
|
||||
size_t len1 = strlen("call check condition: aa");\
|
||||
char *msg_call=malloc(len0 + len1);\
|
||||
sprintf(msg_call,"call check condition: %s",(tmp_mock->info_mock)->str_conditions);\
|
||||
HANDLE_OP_EXPECT_NAME(EQ,TYPE_INT,1, tmp_mock->call_mock_condition args_call_with_parenthesis, (tmp_mock->info_mock)->str_caller, msg_call); /*LOG("%s\n","failure condition");*/\
|
||||
free(msg_call);\
|
||||
}\
|
||||
/*if(0 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
||||
PRINT_LOC("Failure, arguments not expected\ncondition ( %s ) not verified\n\n", (tmp_mock->info_mock)->str_conditions);\
|
||||
PRINT_HK_C(RED_K,HK_TR," 1 argument check failed from %s \n",__func__); \
|
||||
}\
|
||||
}*/\
|
||||
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'^',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, STRFY(args_call_with_parenthesis));\
|
||||
if (((tmp_mock->info_mock)->times_left <= INFINITY) || ((tmp_mock->info_mock)->times_left > 0)){\
|
||||
--((tmp_mock->info_mock)->times_left);\
|
||||
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'v',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, STRFY(args_call_with_parenthesis));\
|
||||
if(1 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
|
||||
return tmp_mock->run args_call_with_parenthesis;\
|
||||
}\
|
||||
else return (returntype)0;/* default return */\
|
||||
else ++((tmp_mock->info_mock)->failed_call);\
|
||||
}\
|
||||
return (returntype)0;/* default return */\
|
||||
}
|
||||
|
||||
|
||||
char* extract_name_func_mock(char *input);
|
||||
|
||||
|
||||
#define EXPECT_EQ_IN_MOCKF(var1,var2, name_f_mocked)\
|
||||
do{ HANDLE_OP_EXPECT_NAME(EQ,TYPE_INT,var1,var2,(list_mo_ ## name_f_mocked.info_mock)->str_caller,"mock test")}while(0)
|
||||
|
||||
#if 0
|
||||
(tmp_mock->info_mock)->expect_call = f_expect_call;\
|
||||
(tmp_mock->info_mock)->init_times_left = repeat;\
|
||||
(tmp_mock->info_mock)->times_left = repeat;\
|
||||
(tmp_mock->info_mock)->next = NULL;\
|
||||
tmp_mock->call_mock_condition = CONCAT(namefunction ## _cond_, id);\
|
||||
tmp_mock->run = CONCAT(run_ ## namefunction ## _ID_, id);\
|
||||
tmp_mock->run = CONCAT(run_ ## namefunction ## _line_, id);\
|
||||
|
||||
|
||||
|
||||
(tmp_mock->next)->run = CONCAT(run_ ## namefunction ## _ID_, id);\
|
||||
(tmp_mock->next)->run = CONCAT(run_ ## namefunction ## _line_, id);\
|
||||
(tmp_mock->next)->call_mock_condition = CONCAT(namefunction ## _cond_, id);\
|
||||
(tmp_mock->next)->info_mock = malloc(sizeof(struct func_mock_info_struct));\
|
||||
((tmp_mock->next)->info_mock)->expect_call = f_expect_call;\
|
||||
@@ -92,40 +135,57 @@ extern struct func_mock_info_struct *f_mock_glist;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* to inject the name TEST in the mock attribute info
|
||||
*/
|
||||
#define INIT_CALLER_MOCK(namefunction)/* */\
|
||||
do{\
|
||||
struct list_mock_return_ ## namefunction *tmp_mock = &list_mo_ ## namefunction;\
|
||||
while(tmp_mock){\
|
||||
(tmp_mock->info_mock)->str_caller=malloc(strlen(__func__));\
|
||||
strcpy((tmp_mock->info_mock)->str_caller,__func__);\
|
||||
tmp_mock = tmp_mock->next;\
|
||||
}\
|
||||
}while(0);
|
||||
|
||||
#define FILL_MOCK_INFO(tmp_new_mock, namefunction, condition_on_args_expression , repeat, f_expect_call, id) \
|
||||
(tmp_new_mock)->run = CONCAT(run_ ## namefunction ## _ID_, id);\
|
||||
(tmp_new_mock)->run = CONCAT(run_ ## namefunction ## _line_, id);\
|
||||
(tmp_new_mock)->call_mock_condition = CONCAT(namefunction ## _cond_, id);\
|
||||
/*(tmp_new_mock)->info_mock = malloc(sizeof(struct func_mock_info_struct));*/\
|
||||
((tmp_new_mock)->info_mock)->expect_call = f_expect_call;\
|
||||
((tmp_new_mock)->info_mock)->call = 0;\
|
||||
((tmp_new_mock)->info_mock)->failed_call = 0;\
|
||||
((tmp_new_mock)->info_mock)->init_times_left = repeat;\
|
||||
((tmp_new_mock)->info_mock)->times_left = repeat;\
|
||||
((tmp_new_mock)->info_mock)->str_namefunc = malloc(strlen(#namefunction));\
|
||||
strcpy(((tmp_new_mock)->info_mock)->str_namefunc, #namefunction);\
|
||||
((tmp_new_mock)->info_mock)->str_namefunc = malloc(strlen(#namefunction) + 32 + strlen("_line_"));\
|
||||
sprintf(((tmp_new_mock)->info_mock)->str_namefunc,"%s_line_%d",#namefunction,id);\
|
||||
((tmp_new_mock)->info_mock)->str_conditions = malloc(strlen(#condition_on_args_expression));\
|
||||
strcpy(((tmp_new_mock)->info_mock)->str_conditions, #condition_on_args_expression);\
|
||||
((tmp_new_mock)->info_mock)->str_caller = NULL;\
|
||||
((tmp_new_mock)->info_mock)->next = NULL;\
|
||||
(tmp_new_mock)->next = NULL;\
|
||||
append_fmock_to_listmock(&f_mock_glist, (tmp_new_mock)->info_mock);
|
||||
|
||||
|
||||
#define ADD_RESPONSE(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression , repeat, f_expect_call, id)\
|
||||
/*FUNC_type_ ## namefunction CONCAT(run_ ## namefunction ## _ID_ , id);*/\
|
||||
returntype CONCAT(run_ ## namefunction ## _ID_ , id) args_prototype_with_parenthesis; \
|
||||
/*FUNC_type_ ## namefunction CONCAT(run_ ## namefunction ## _line_ , id);*/\
|
||||
returntype CONCAT(run_ ## namefunction ## _line_ , id) args_prototype_with_parenthesis; \
|
||||
int CONCAT(namefunction ## _cond_ , id) args_prototype_with_parenthesis {/*LOG("cond:%d\n",condition_on_args_expression);*/ return condition_on_args_expression;}\
|
||||
__attribute__((constructor)) void CONCAT(append_list_ ## namefunction , id)(void){\
|
||||
struct list_mock_return_ ## namefunction *tmp_mock = &list_mo_ ## namefunction;\
|
||||
if((tmp_mock->info_mock)->times_left == INITSTATE){/* init state */\
|
||||
FILL_MOCK_INFO(tmp_mock, namefunction, condition_on_args_expression , repeat, f_expect_call, id);\
|
||||
append_list_base_fmock( &g_list_base_fmock ,(tmp_mock->info_mock));\
|
||||
}\
|
||||
else{\
|
||||
while(tmp_mock->next) tmp_mock = tmp_mock->next;\
|
||||
tmp_mock->next = malloc(sizeof(list_mo_ ## namefunction));\
|
||||
(tmp_mock->next)->info_mock = malloc(sizeof(struct func_mock_info_struct));\
|
||||
FILL_MOCK_INFO(tmp_mock->next, namefunction, condition_on_args_expression , repeat, f_expect_call, id);\
|
||||
/*(tmp_mock->info_mock)->next = (tmp_mock->next)->info_mock ;*/\
|
||||
}\
|
||||
}\
|
||||
returntype CONCAT(run_ ## namefunction ## _ID_, id) args_prototype_with_parenthesis
|
||||
returntype CONCAT(run_ ## namefunction ## _line_, id) args_prototype_with_parenthesis
|
||||
|
||||
|
||||
|
||||
|
||||
+185
-186
@@ -94,9 +94,11 @@ struct failed_lists{
|
||||
/*
|
||||
* begin variable option
|
||||
*/
|
||||
|
||||
bool some_thing_wrong = 0;
|
||||
|
||||
bool help=0;
|
||||
bool only_usage=0;
|
||||
bool ordered= 0;
|
||||
bool unicolour = 0;
|
||||
bool removelog = 0;
|
||||
@@ -104,9 +106,13 @@ char *timeunit="ms";
|
||||
char *savelog=NULL;
|
||||
char *default_timeunit="ms";
|
||||
char *default_savelog="log_all_tests";
|
||||
char *default_bar_progress=" c";
|
||||
|
||||
//size_t width = 80;
|
||||
|
||||
char *colors_f[]={DEFAULT_K, GREEN_K, RED_K, YELLOW_K, BLUE_K, ""};
|
||||
int kdefaukt=0, kgreen=1, kred=2, kyellow=3, kblue=4, knothing=5;
|
||||
|
||||
bool some_tests_selected=0;
|
||||
|
||||
size_t *array_TYPE_SIZE_T=NULL; /* if active, size = count_tests */
|
||||
@@ -125,8 +131,11 @@ size_t parallel_nb = 0;
|
||||
*/
|
||||
|
||||
bool is_parallel_nb = 0;
|
||||
//bool is_width=0;
|
||||
bool progress = false;
|
||||
bool log_parallel = true;
|
||||
bool progress = true; // false;
|
||||
|
||||
char *bar_progress = " c"; /*{fill_bar,fill_dot,colored} */
|
||||
bool is_bar_progress = true;
|
||||
|
||||
FILE **f_ou_th;
|
||||
|
||||
@@ -268,14 +277,19 @@ void usage(int argc, char **argv){
|
||||
printf("\t -p <NB>, --parallel <NB>, -p=<NB>, --parallel=<NB>\n\t\tby default the program ran in sequantial all test, \n\t\tif this option is set, the program run tests on NB threads.\n\t\tEach thread pull up one test out the list of all test not yet executed,\n\t\tand execute it, until the list is empty \n\n");
|
||||
printf("\t -t <unit>, --time <unit>, -t=<unit>, --time=<unit> \n\t\tby default unit is millisecons ms, the other of unit are choices are second (or s), and nanosecond (or ns)\n\t\tex: -t ns or -t=nanosecond or --time=n to set nanosecond unit\n\n");
|
||||
printf("\t -u , --unicolour\n\t\tby default, the result is colored, if you choice this option, it prints with default color\n\n");
|
||||
printf("\t -o, --ordered\n\t\tthis option is usefull if you choose to use parallel tests,\n\t\tby default, each thread share the screen to print results,\n\t\tthis option create file to record log of each thread on file,\n\t\tand print on screen all results at the end of all tests\n\n");
|
||||
printf("\t -r , --remove\n\t\tif the option ordered is choosen if parallel tests,\n\t\tthis option remove the file logs of each thread after all tests.\n\n");
|
||||
// printf("\t -o, --ordered\n\t\tthis option is usefull if you choose to use parallel tests,\n\t\tby default, each thread share the screen to print results,\n\t\tthis option create file to record log of each thread on file,\n\t\tand print on screen all results at the end of all tests\n\n");
|
||||
printf("\t -r , --remove\n\t\tif the option parallel is choosen the result on each thread is record in separate files,\n\t\tthis option remove the file logs of each thread after all tests.\n\n");
|
||||
printf("\t -s <file>, --savelog <file>, -s=file, --savelog=file\n\t\tthis option save the global ordered result in 'file',\n\t\tthis option active the option -o or --ordered. \n\n");
|
||||
// printf("\t -w <WID>, --width <WID>, -w=WID, --savelog=WID\n\t\tthis option change the width of the progress bar to WID, by default, WID=80,\n\t\tex: -w100, or --width=100 or -wi 100\n\n");
|
||||
|
||||
printf("\t -n=<NUM1>,<NUM2> <NUM3>... ,--numtests=<NUM1>,<NUM2>...\n\t\tthis option allow to execute only the selected numbers of tests (in the order in file test)\n\t\tex: -n=0,6,3 8 to execute the tests 0,3,6,8 (if the number is less than the count of all tests)\n\n");
|
||||
printf("\t -l=<NAME1>,<NAME2> <NAME3>... ,--listests=<NAME1>,<NAME2>...<NAMEn>\n\t\tthis option allow to execute only the selected name of tests. It allows empty name by using '-l=,'\n\t\tex: -l=name0,,name2 : execute only (if they exist): TEST(name0),TEST(),TEST(name2)\n\n");
|
||||
|
||||
printf("\t -b <BPRGSS>, --bar_progress <BPRGSS>, -b=BPRGSS, --bar_progress=BPRGSS. Example: -b=\"#_c\"\n\t\tthis option change progression bar if it is active. The first character (\'#\') fills the bar\n\t\tthe second char (\'_\') fills the other part of bar. the bar is colored if the 3rd char is \'c\' and not if different.\n\t\tby default the progress bar is active and the option is -b=\" c\", if need not colored, we can put -b=\" n\" option.\n\n");
|
||||
printf("\t -z=<option> \n\t\tthis option is to set option=0,\n\t\tfor example, -z=progress is to not load progress bar, it is need if we want to redirect (pipe) the result to file.\n\t\tother option: -z=log_parallel (to avoid logs not ordered when parallel tests which is loged by default)\n\n");
|
||||
//printf(" log_parallel ={%d}\n\n",log_parallel);
|
||||
//printf(" progress ={%d}\n\n",progress);
|
||||
|
||||
if(array_TYPE_SIZE_T){
|
||||
for(int i=0; i< cur_array_TYPE_SIZE_T; ++i){
|
||||
PRINT_DEBUG("array_TYPE_SIZE_T[%d]=%ld\n",i,array_TYPE_SIZE_T[i]);
|
||||
@@ -290,6 +304,7 @@ void usage(int argc, char **argv){
|
||||
printf("invalid argument\n");
|
||||
exit(0);
|
||||
}
|
||||
if(only_usage) exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -385,6 +400,8 @@ long int extract_num_after_equal_symbole_in_string(char * in_str){
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* if the variable option is boolean
|
||||
*/
|
||||
@@ -395,10 +412,42 @@ long int extract_num_after_equal_symbole_in_string(char * in_str){
|
||||
while(argv[i][j]=='-') ++j;\
|
||||
if(argv[i][j] == #option[0]){\
|
||||
option=1;\
|
||||
if(0==strcmp(#option,"help")){ only_usage=1;break;}\
|
||||
continue;\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
#define IF_OPTION_TO_ZERO(option)\
|
||||
if(argv[i][0]=='-'){\
|
||||
j=1;\
|
||||
while(argv[i][j]=='-') ++j;/* to accept multiple -- */\
|
||||
if(argv[i][j] == 'z' ){\
|
||||
arg=argv[i];\
|
||||
char* ret_str=(char*)extract_string_after_equal_symbole_in_string(argv[i]);\
|
||||
PRINT_DEBUG("to zero option={%s}, ret_str = {%s}, argv[%d]={%s}\n",#option,ret_str,i,argv[i]);\
|
||||
if(ret_str == NULL || strlen(ret_str)==0){\
|
||||
if(i<argc-1){\
|
||||
if(argv[i+1][0]=='-')\
|
||||
help=1;\
|
||||
else if(0==strcmp(#option, argv[i+1])){ \
|
||||
option=0;\
|
||||
++i;\
|
||||
continue;\
|
||||
}\
|
||||
}\
|
||||
else{\
|
||||
help=1;\
|
||||
}\
|
||||
}\
|
||||
else if(0==strcmp(#option,ret_str)){ \
|
||||
option = 0;\
|
||||
continue;\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
void extract_to_array_TYPE_SIZE_T(char * in_str){
|
||||
size_t len=strlen(in_str);
|
||||
long int val=0, p=10;
|
||||
@@ -502,9 +551,12 @@ void parse_options(int argc, char **argv){
|
||||
//IF_OPTION_WITH_ARG_NUM(width)
|
||||
IF_OPTION_WITH_ARG_STR(savelog)
|
||||
IF_OPTION_WITH_ARG_STR(timeunit)
|
||||
IF_OPTION_WITH_ARG_STR(bar_progress)
|
||||
IF_OPTION_NO_ARG(ordered)
|
||||
IF_OPTION_NO_ARG(removelog)
|
||||
IF_OPTION_NO_ARG(unicolour)
|
||||
IF_OPTION_TO_ZERO(progress)
|
||||
IF_OPTION_TO_ZERO(log_parallel)
|
||||
IF_OPTION_WITH_MULTIPLE_ARG(numsuit,TYPE_SIZE_T)
|
||||
IF_OPTION_WITH_MULTIPLE_ARG(listsuite,TYPE_STRING)
|
||||
IF_NO_MATCH_DO_WRONG
|
||||
@@ -674,6 +726,115 @@ EXPECTED_OP_TYPE(NE,TYPE_DOUBLE)
|
||||
EXPECTED_OP_TYPE(NE,TYPE_L_DOUBLE)
|
||||
EXPECTED_OP_TYPE(NE,TYPE_STRING)
|
||||
|
||||
// ====================== progress bar =================
|
||||
|
||||
|
||||
unsigned sleep(unsigned x) { time_t t0=time(0); while (difftime(time(0),t0)<x); return 0; }
|
||||
unsigned nnsleep(long long x) {
|
||||
struct timespec time_stop;
|
||||
struct timespec time_start;
|
||||
clock_gettime(CLOCK_REALTIME, &time_start);
|
||||
|
||||
long long diff;
|
||||
do{
|
||||
clock_gettime(CLOCK_REALTIME, &time_stop);
|
||||
|
||||
diff = 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);
|
||||
}while(diff < x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void progress_test_(){
|
||||
struct func *tmp;
|
||||
size_t num_test=0;
|
||||
int cur = 0, len;
|
||||
//get_cursor_position(&col, &row);
|
||||
int width;
|
||||
long int chg=0;
|
||||
|
||||
char prgss[]="\\|/-";
|
||||
struct winsize w;
|
||||
//ioctl(1,TIOCGWINSZ, &w); // 1 =STDOUT_FILENO
|
||||
//printf ("lines %d\n", w.ws_row);
|
||||
//width = w.ws_col - 50;
|
||||
//printf ("columns %d vs width.choice: %d\n", w.ws_col, width);
|
||||
|
||||
len=strlen(prgss);
|
||||
|
||||
do{
|
||||
ioctl(1,TIOCGWINSZ, &w); // 1 =STDOUT_FILENO
|
||||
width = w.ws_col - 50;
|
||||
//LOCK(mut_current_test);
|
||||
tmp = current_fn;
|
||||
//UNLOCK(mut_current_test);
|
||||
if(tmp)
|
||||
num_test = extract_num__f(tmp->name);
|
||||
//gotoxy(13,0);
|
||||
printf("\r(%c)[",prgss[cur]);
|
||||
|
||||
for(int i=0; i< width; ++i) {
|
||||
if(i<=(num_test+1)*width/count_tests){
|
||||
//usleep(20000);
|
||||
printf("#");
|
||||
}
|
||||
else printf(".");
|
||||
}
|
||||
printf("|%3ld%%, test N° %ld/%ld]",(num_test+1)*100/count_tests,num_test,count_tests-1);
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
//printf("%c",prgss[cur]);
|
||||
//printf("\33[2K\r"); // remove current line and go to begin of the current line
|
||||
//if(chg==40000){
|
||||
chg=0;
|
||||
if(cur<len-1) ++cur;
|
||||
else cur=0;
|
||||
//}else ++chg;
|
||||
//printf("\n");
|
||||
//sleep(1);
|
||||
//usleep(500000);
|
||||
nnsleep(200000000);// 200 milliseconds
|
||||
}while(tmp);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void bar_progress_test_(){
|
||||
bar_progress_start();
|
||||
|
||||
struct func *tmp;
|
||||
size_t num_test=0;
|
||||
|
||||
do{
|
||||
tmp = current_fn;
|
||||
//UNLOCK(mut_current_test);
|
||||
if(tmp)
|
||||
num_test = extract_num__f(tmp->name);
|
||||
if(strlen(bar_progress) < strlen(default_bar_progress))
|
||||
bar_progress_step_msg(num_test, count_tests, "test N°", default_bar_progress[0],default_bar_progress[1],default_bar_progress[2]=='c');
|
||||
else bar_progress_step_msg(num_test, count_tests, "test N°", bar_progress[0],bar_progress[1],bar_progress[2]=='c');
|
||||
nnsleep(200000000);// 200 milliseconds
|
||||
}while(tmp);
|
||||
|
||||
|
||||
|
||||
bar_progress_stop();
|
||||
|
||||
}
|
||||
|
||||
void*
|
||||
run_progress_tests(void *max_d)
|
||||
{
|
||||
int max_col = 80; //*(int*)max_d;
|
||||
//progress_test_(max_col);
|
||||
bar_progress_test_();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ====================== end funcs progress bar =======
|
||||
|
||||
void
|
||||
append_func(void (*run)(void), char *name){
|
||||
@@ -839,6 +1000,7 @@ void execute_all(struct func *fun){
|
||||
bool exec_test=0;
|
||||
//PRINT_HK_C(GREEN_K, HK_EQ," Running %lu tests.\n",count_tests);
|
||||
while(tmp){
|
||||
current_fn = tmp;
|
||||
CHECK_IF_SELECTED_TEST(tmp->name)
|
||||
if(exec_test){
|
||||
begin_execute_func(tmp->name, &start_t);
|
||||
@@ -847,118 +1009,28 @@ void execute_all(struct func *fun){
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
current_fn = tmp;
|
||||
}
|
||||
|
||||
/*
|
||||
void execute_one_test(struct func *fun, size_t num){
|
||||
size_t cur = 0;
|
||||
struct timespec start_t;
|
||||
struct func *tmp = fun;
|
||||
while(tmp){
|
||||
if(cur++ == num){
|
||||
begin_execute_func(tmp->name, &start_t);
|
||||
tmp->run();
|
||||
end_execute_func(tmp->name, start_t);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void execute_some_tests_ordered(struct func *fun, size_t cnt, size_t *array )
|
||||
{
|
||||
struct timespec start_t;
|
||||
struct func *tmp = fun;
|
||||
size_t cur = 0, index = 0;
|
||||
|
||||
while(tmp){
|
||||
if((cur < cnt) && (index++ == array[cur])){
|
||||
begin_execute_func(tmp->name, &start_t);
|
||||
tmp->run();
|
||||
end_execute_func(tmp->name, start_t);
|
||||
++cur;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run_some_tests(size_t cnt, ...)
|
||||
{
|
||||
struct timespec start_t;
|
||||
head_run(cnt, &start_t);
|
||||
va_list args;
|
||||
va_start(args, cnt);
|
||||
for(size_t i=0; i < cnt; ++i){
|
||||
execute_one_test(f_beging, va_arg(args, size_t));
|
||||
}
|
||||
va_end(args);
|
||||
stat_end_run(cnt, start_t);
|
||||
}
|
||||
|
||||
void
|
||||
run_some_tests_ordered(size_t cnt, ... )
|
||||
{
|
||||
struct timespec start_t;
|
||||
head_run(cnt, &start_t);
|
||||
va_list args;
|
||||
va_start(args, cnt);
|
||||
size_t *array=malloc(cnt*sizeof(size_t));
|
||||
for(size_t i=0; i < cnt; ++i){
|
||||
array[i] = va_arg(args, size_t);
|
||||
}
|
||||
|
||||
execute_some_tests_ordered(f_beging, cnt, array);
|
||||
va_end(args);
|
||||
stat_end_run(cnt, start_t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void execute_all_tests_exept(struct func *fun, size_t cnt, size_t *array )
|
||||
{
|
||||
struct timespec start_t;
|
||||
struct func *tmp = fun;
|
||||
size_t cur = 0;
|
||||
while(tmp){
|
||||
if(!is_in_array(array, cnt, cur++)){
|
||||
begin_execute_func(tmp->name, &start_t);
|
||||
tmp->run();
|
||||
end_execute_func(tmp->name, start_t);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run_all_tests_exept(size_t cnt, ... )
|
||||
{
|
||||
struct timespec start_t;
|
||||
if(count_tests >= cnt)
|
||||
head_run(count_tests - cnt, &start_t);
|
||||
va_list args;
|
||||
va_start(args, cnt);
|
||||
size_t *array=malloc(cnt*sizeof(size_t));
|
||||
for(size_t i=0; i < cnt; ++i){
|
||||
array[i] = va_arg(args, size_t);
|
||||
}
|
||||
|
||||
execute_all_tests_exept(f_beging, cnt, array);
|
||||
va_end(args);
|
||||
if(count_tests >= cnt)
|
||||
stat_end_run(count_tests - cnt, start_t);
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
run_all_tests()
|
||||
{
|
||||
//progress = true;
|
||||
#if 1
|
||||
pthread_t thrd_progress;
|
||||
if(progress) pthread_create(&thrd_progress, NULL, run_progress_tests, NULL);
|
||||
//if(progress) pthread_create(&thrd_progress, NULL, run_progress_tests, (void*)&max_col);
|
||||
#endif
|
||||
|
||||
struct timespec start_t;
|
||||
head_run(count_tests, &start_t);
|
||||
execute_all(f_beging);
|
||||
//stat_end_run(count_tests, start_t);
|
||||
stat_end_run(count_pass_global + count_fail_global, start_t);
|
||||
|
||||
if(progress) pthread_join(thrd_progress, NULL);
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -1086,85 +1158,6 @@ void end_execute_func_parallel(char *fun_ame, struct timespec start_t, size_t id
|
||||
}
|
||||
}
|
||||
|
||||
unsigned sleep(unsigned x) { time_t t0=time(0); while (difftime(time(0),t0)<x); return 0; }
|
||||
unsigned nnsleep(long long x) {
|
||||
struct timespec time_stop;
|
||||
struct timespec time_start;
|
||||
clock_gettime(CLOCK_REALTIME, &time_start);
|
||||
|
||||
long long diff;
|
||||
do{
|
||||
clock_gettime(CLOCK_REALTIME, &time_stop);
|
||||
|
||||
diff = 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);
|
||||
}while(diff < x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void progress_test_(){
|
||||
struct func *tmp;
|
||||
size_t num_test=0;
|
||||
int cur = 0, len;
|
||||
//get_cursor_position(&col, &row);
|
||||
int width;
|
||||
long int chg=0;
|
||||
|
||||
char prgss[]="\\|/-";
|
||||
struct winsize w;
|
||||
//ioctl(1,TIOCGWINSZ, &w); // 1 =STDOUT_FILENO
|
||||
//printf ("lines %d\n", w.ws_row);
|
||||
//width = w.ws_col - 50;
|
||||
//printf ("columns %d vs width.choice: %d\n", w.ws_col, width);
|
||||
|
||||
len=strlen(prgss);
|
||||
|
||||
do{
|
||||
ioctl(1,TIOCGWINSZ, &w); // 1 =STDOUT_FILENO
|
||||
width = w.ws_col - 50;
|
||||
//LOCK(mut_current_test);
|
||||
tmp = current_fn;
|
||||
//UNLOCK(mut_current_test);
|
||||
if(tmp)
|
||||
num_test = extract_num__f(tmp->name);
|
||||
//gotoxy(13,0);
|
||||
printf("\r(%c)[",prgss[cur]);
|
||||
|
||||
for(int i=0; i< width; ++i) {
|
||||
if(i<=(num_test+1)*width/count_tests){
|
||||
//usleep(20000);
|
||||
printf("#");
|
||||
}
|
||||
else printf(".");
|
||||
}
|
||||
printf("|%3ld%%, test N° %ld/%ld]",(num_test+1)*100/count_tests,num_test,count_tests-1);
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
//printf("%c",prgss[cur]);
|
||||
//printf("\33[2K\r"); // remove current line and go to begin of the current line
|
||||
//if(chg==40000){
|
||||
chg=0;
|
||||
if(cur<len-1) ++cur;
|
||||
else cur=0;
|
||||
//}else ++chg;
|
||||
//printf("\n");
|
||||
//sleep(1);
|
||||
//usleep(500000);
|
||||
nnsleep(200000000);// 200 milliseconds
|
||||
}while(tmp);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void*
|
||||
run_progress_tests(void *max_d)
|
||||
{
|
||||
int max_col = 80; //*(int*)max_d;
|
||||
progress_test_(max_col);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void execute_test_parallel(size_t id_thrd){
|
||||
|
||||
struct timespec start_t;
|
||||
@@ -1212,7 +1205,7 @@ init_parallel_test_()
|
||||
{
|
||||
if(savelog) ordered =1;
|
||||
|
||||
progress = ordered;
|
||||
//progress = ordered;
|
||||
|
||||
is_parallel_nb = 1;
|
||||
|
||||
@@ -1281,7 +1274,12 @@ final_parallel_test_()
|
||||
pthread_mutex_destroy(&mut_count_fail_local);
|
||||
|
||||
|
||||
char reader[256];
|
||||
char reader[256]="here the ordered results on each threads";
|
||||
|
||||
struct winsize w;
|
||||
ioctl(1, TIOCGWINSZ, &w);
|
||||
|
||||
fprintf(F_OUT,"\n\n%0*d\n %*s \n%0*d\n\n",w.ws_col,0, (int)(w.ws_col+strlen(reader))/2, reader,w.ws_col,0 );
|
||||
|
||||
if(savelog){
|
||||
FILE *f_savelog;
|
||||
@@ -1307,6 +1305,7 @@ final_parallel_test_()
|
||||
if(removelog){
|
||||
for(size_t i=0; i<=parallel_nb; ++i){
|
||||
remove(log_name_file_thrd[i]);
|
||||
PRINT_DEBUG("file log of treard[%ld] removed\n",i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+198
-14
@@ -11,11 +11,16 @@
|
||||
#include <sys/ioctl.h> /* to have size of screen, for progress bar */
|
||||
|
||||
#include "tools_t/tools_t.h"
|
||||
|
||||
#include "bar_progress/bar_progress.h"
|
||||
|
||||
#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 COLOR_SZ 6
|
||||
extern char *colors_f[];
|
||||
|
||||
#ifdef HK
|
||||
#define HK_EQ "[==========]"
|
||||
@@ -51,7 +56,9 @@
|
||||
extern FILE **f_ou_th;
|
||||
extern bool unicolour;
|
||||
extern bool ordered;
|
||||
extern bool log_parallel;
|
||||
|
||||
extern int kdefaukt, kgreen, kred, kyellow, kblue, knothing;
|
||||
|
||||
#ifndef SAVE_LOG
|
||||
#define SAVE_LOG 0
|
||||
@@ -61,11 +68,152 @@ extern bool ordered;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
#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!
|
||||
*/
|
||||
#define PRINT_HK_C(color,hk,...)\
|
||||
do{ \
|
||||
if(is_parallel_nb){\
|
||||
size_t 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__); \
|
||||
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);\
|
||||
}\
|
||||
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__); \
|
||||
}\
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
|
||||
else fprintf(F_OUT, hk __VA_ARGS__); \
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
|
||||
|
||||
#define PRINT_LOC(fmt, ...) \
|
||||
do{ \
|
||||
if(ordered){\
|
||||
/*if(ordered){*/\
|
||||
if(is_parallel_nb){\
|
||||
size_t 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__);\
|
||||
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);\
|
||||
}\
|
||||
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__);\
|
||||
}\
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#define PRINTF( ...) \
|
||||
do{ \
|
||||
if(is_parallel_nb){\
|
||||
size_t id_thread=id_of_thread_executed();\
|
||||
if(log_parallel){\
|
||||
INIT_STREAM_MEM (stream, msg);\
|
||||
fprintf(stream, __VA_ARGS__);\
|
||||
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);\
|
||||
}\
|
||||
else{\
|
||||
if(id_thread < 0){\
|
||||
fprintf(F_OUT,__VA_ARGS__);\
|
||||
}\
|
||||
else{\
|
||||
fprintf(f_ou_th[id_thread], __VA_ARGS__);\
|
||||
}\
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
fprintf(F_OUT, __VA_ARGS__);\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#define LOG(...) PRINTF(__VA_ARGS__)
|
||||
|
||||
//#endif
|
||||
#else /* below alternative of above solution, but it execute twice functions called in print functions when log_parallel == 1 */
|
||||
//#if 1
|
||||
|
||||
#define PRINT_LOC(fmt, ...) \
|
||||
do{ \
|
||||
/*if(ordered){*/\
|
||||
if(is_parallel_nb){\
|
||||
size_t id_thread=id_of_thread_executed();\
|
||||
if(id_thread < 0){\
|
||||
@@ -77,12 +225,12 @@ extern bool ordered;
|
||||
__LINE__, __func__, __VA_ARGS__);\
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
/*else{\
|
||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);\
|
||||
}\
|
||||
}\
|
||||
else{\
|
||||
else{*/if(log_parallel || !is_parallel_nb){\
|
||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);\
|
||||
}\
|
||||
@@ -90,7 +238,8 @@ extern bool ordered;
|
||||
|
||||
#define PRINTF( ...) \
|
||||
do{ \
|
||||
if(ordered){\
|
||||
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){\
|
||||
@@ -100,11 +249,11 @@ extern bool ordered;
|
||||
fprintf(f_ou_th[id_thread], __VA_ARGS__);\
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
/*else{\
|
||||
fprintf(F_OUT, __VA_ARGS__);\
|
||||
}\
|
||||
}\
|
||||
else{\
|
||||
else{*/if(log_parallel || !is_parallel_nb){\
|
||||
fprintf(F_OUT, __VA_ARGS__);\
|
||||
}\
|
||||
}while(0)
|
||||
@@ -113,7 +262,7 @@ extern bool ordered;
|
||||
|
||||
#define PRINT_HK_C(color,hk,...)\
|
||||
do{ \
|
||||
if(ordered){\
|
||||
/*if(ordered){*/\
|
||||
if(is_parallel_nb){\
|
||||
size_t id_thread=id_of_thread_executed();\
|
||||
if(id_thread < 0){\
|
||||
@@ -125,17 +274,20 @@ extern bool ordered;
|
||||
else fprintf(f_ou_th[id_thread], hk __VA_ARGS__); \
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
/*else{\
|
||||
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
|
||||
else fprintf(F_OUT, hk __VA_ARGS__); \
|
||||
}\
|
||||
}\
|
||||
else{\
|
||||
}*/\
|
||||
/*}*/\
|
||||
/*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
|
||||
|
||||
/*
|
||||
@@ -152,7 +304,7 @@ extern bool ordered;
|
||||
*/
|
||||
#define SKIP(...)\
|
||||
PRINT_HK_C(GREEN_K, HK_SK __VA_ARGS__);\
|
||||
PRINT_LOC("%s\n\n"," Skiped"); return;
|
||||
PRINT_LOC("%s\n\n" DEFAULT_K," Skiped "); return;
|
||||
|
||||
|
||||
|
||||
@@ -310,6 +462,38 @@ GEN_EXPECTED_OP_TYPE_FUNC(NE, TYPE_STRING)
|
||||
* ******************** end NE generation ************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* only expect
|
||||
*/
|
||||
#define HANDLE_OP_EXPECT_NAME(OP,type,var1,var2,name_f,msg_call) \
|
||||
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); \
|
||||
} \
|
||||
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); \
|
||||
} \
|
||||
}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);*/ \
|
||||
} \
|
||||
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); \
|
||||
} \
|
||||
}\
|
||||
}while(0);
|
||||
|
||||
//#define EXPECT_OP_(OP,type,var1,var2) HANDLE_OP_EXPECT_(OP,type,var1,var2)
|
||||
|
||||
/**
|
||||
* is_assert : 0 for EXPECT and 1 for ASSERT
|
||||
@@ -609,7 +793,7 @@ do{
|
||||
#define CONCAT(x,y) x ## y
|
||||
#define STRFY(x) # x
|
||||
|
||||
#define test_label test
|
||||
//#define test_label test
|
||||
|
||||
#define FTEST_(count, name_f) \
|
||||
void CONCAT(test_##name_f##____,count)(void); \
|
||||
|
||||
+98
-8
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "permutation_t/permutation_t.h"
|
||||
|
||||
#if 1
|
||||
|
||||
TEST(size_permutation2){
|
||||
PRINTF("another size_permutation2 again\n");
|
||||
ASSERT_TRUE(false);
|
||||
@@ -28,7 +30,6 @@ TEST(size_permutation)
|
||||
PRINTF("test size_permutation2\n");
|
||||
}
|
||||
|
||||
#if 1
|
||||
TEST(size_permutation2){
|
||||
PRINTF("another size_permutation2 again false\n");
|
||||
bool val_bool = false;
|
||||
@@ -165,26 +166,115 @@ TEST(sleep){sleep(1);}
|
||||
TEST(sleep){sleep(1);}
|
||||
TEST(sleep){sleep(1);}
|
||||
TEST(sleep){sleep(1);}
|
||||
|
||||
TEST(sleep){sleep(1);}
|
||||
TEST(sleep){sleep(1);}
|
||||
TEST(sleep){sleep(1);}
|
||||
|
||||
#endif
|
||||
|
||||
MOCK_FUNC(int, f_mock, (), ())
|
||||
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),1, 2) {return 12;}
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),1, 0) {return 10;}
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),1, 2) {/*EXPECT_EQ(1,3);*/ EXPECT_EQ_IN_MOCKF(21,21,f_mock);
|
||||
EXPECT_EQ_IN_MOCKF(23,24,f_mock); return 12;}
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),1, 1) { EXPECT_EQ_IN_MOCKF(23,21,f_mock);return 10;}
|
||||
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),0, 1) {return 18;}
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),1==2||2<1, 1) {return 18;}
|
||||
EXPECT_MOCK_CALL(int,f_mock, (),1, INFINITY) {return -18;}
|
||||
|
||||
TEST(mock){
|
||||
for(int i = 0; i<8; ++i)
|
||||
LOG("call %d: ret:%d\n",i,f_mock());
|
||||
TEST(mockf1){
|
||||
INIT_CALLER_MOCK(f_mock);
|
||||
|
||||
for(int i = 0; i<8; ++i){
|
||||
|
||||
LOG("call f_mock:%d: ret:%d\n",i,f_mock());
|
||||
// int val=f_mock();
|
||||
//PRINTF("call f_mock:%d: ret:%d\n",i,val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MOCK_FUNC(int, f2_mock,(int a,int b),(a,b))
|
||||
|
||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a<b), 3){
|
||||
return a+b;
|
||||
}
|
||||
|
||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), ((a<b)&&(b<100)), 1){
|
||||
return a*b;
|
||||
}
|
||||
|
||||
WILL_MOCK_CALL(int, f2_mock, (int a,int b), (a!=b), 6){
|
||||
return a/b;
|
||||
}
|
||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a==b), 1){
|
||||
return a/b;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
MOCK_FUNC(int, f3_mock,(int a,int b),(a,b))
|
||||
|
||||
EXPECT_MOCK_CALL(int, f3_mock, (int a,int b), (a<b), 2){
|
||||
return a+b;
|
||||
}
|
||||
|
||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), ((a<b)&&(b<100)), 1){
|
||||
return a*b;
|
||||
}
|
||||
|
||||
WILL_MOCK_CALL(int, f2_mock, (int a,int b), (a!=b), 6){
|
||||
return a/b;
|
||||
}
|
||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a==b), 1){
|
||||
return a/b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (1), INFINITY){
|
||||
return a*b;
|
||||
}
|
||||
|
||||
TEST(f2mock_test){
|
||||
INIT_CALLER_MOCK(f2_mock);
|
||||
//LOG("--------------------------- > call f2_mock:%d: %d\n",0,f2_mock(1,4));
|
||||
|
||||
|
||||
for(int i=0; i<8; ++i){
|
||||
|
||||
if(i<2) {
|
||||
//int val = f2_mock(i,4);
|
||||
//LOG("call f2_mock:%d: %d\n",i,val);
|
||||
LOG("call f2_mock:%d: %d\n",i,f2_mock(i,4));
|
||||
|
||||
}
|
||||
else if(i<4) LOG("call:%d: %d\n",i,f2_mock(i,3));
|
||||
else LOG("call:%d:%d\n",i,f2_mock(i,i*i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(f3_mock_test){
|
||||
INIT_CALLER_MOCK(f3_mock);
|
||||
|
||||
|
||||
for(int i=0; i<7; ++i){
|
||||
|
||||
if(i<1) {
|
||||
LOG("call f3_mock:%d: %d\n",i,f3_mock(1,i));
|
||||
|
||||
}
|
||||
else LOG("call:%d:%d\n",i,f3_mock(i,i*i));
|
||||
}
|
||||
for(int i=COLOR_SZ-1; i>=0; --i)
|
||||
LOG("%s colors_fld\n",colors_f[i]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user