From 2c1e4f0487cbeb41d3801d65077c2ea5ad15e3dc Mon Sep 17 00:00:00 2001 From: fanasina Date: Tue, 29 Aug 2023 15:40:22 +0200 Subject: [PATCH] add options wich allow to execute only some tests selected with nametest or numtest --- .gitignore | 2 +- Makefile | 2 +- compile.sh | 2 +- src/ftest/ftest.c | 275 +++++++++++++++++++++++++++++++++++++----- src/ftest/ftest.h | 2 + src/tools_t/tools_t.c | 1 + test/is_good.c | 4 + 7 files changed, 253 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 2f1faa4..86b2fd8 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -**.swp +**.sw* log* **.o *.o diff --git a/Makefile b/Makefile index a9bb36d..b1dbc8c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ NAME_TEST=is_good CC=gcc -LDFLAGS=-lpthread +LDFLAGS=-lpthread -D DEBUG=1 ROOT_DIR=$(shell pwd) INCLUDE_DIR=$(ROOT_DIR)/src CFLAGS=-I$(INCLUDE_DIR) diff --git a/compile.sh b/compile.sh index bd869d8..9a417a6 100755 --- a/compile.sh +++ b/compile.sh @@ -1,4 +1,4 @@ #!/bin/bash gcc test/is_good.c src/ftest/ftest.c src/tools_t/tools_t.c \ src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c \ - -I./src -o launch_is_good_c && ./launch_is_good_c -h -p + -I./src $1 -o launch_is_good_c #&& ./launch_is_good_c -h -p diff --git a/src/ftest/ftest.c b/src/ftest/ftest.c index 9c7dd19..9c40342 100644 --- a/src/ftest/ftest.c +++ b/src/ftest/ftest.c @@ -102,10 +102,19 @@ bool unicolour = 0; bool removelog = 0; char *timeunit="ms"; char *savelog=NULL; -char *default_timeunit="ms"; +char *defiault_timeunit="ms"; char *default_savelog="log_all_tests"; size_t width = 80; + +bool some_tests_selected=0; + +size_t *array_TYPE_SIZE_T=NULL; /* if active, size = count_tests */ +char **array_TYPE_STRING=NULL; + +size_t cur_array_TYPE_SIZE_T=0; /* < count_tests */ +size_t cur_array_TYPE_STRING=0; + /* * number of threads */ @@ -250,6 +259,8 @@ size_t extract_num__f(const char *name_f){ return val; } +// ===================================== begin options handle ======================================================= + void usage(int argc, char **argv){ printf("usage: %s [OPTIONS] [] \n\n or : %s [OPTIONS]=[]\n\n",argv[0],argv[0]); printf("OPTIONS\n"); @@ -262,6 +273,19 @@ void usage(int argc, char **argv){ printf("\t -s , --savelog , -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 , --width , -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=, ... ,--numtests=,...\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=, ... ,--listests=,...\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"); + + 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]); + } + } + if(array_TYPE_STRING) { + for(int i=0; i< cur_array_TYPE_STRING; ++i){ + PRINT_DEBUG("array_TYPE_STRING[%d]=%s\n",i,array_TYPE_STRING[i]); + } + } if(some_thing_wrong){ printf("invalid argument\n"); exit(0); @@ -294,11 +318,18 @@ long int extract_num_after_equal_symbole_in_string(char * in_str){ return -1; } +#define LOG_WRONG(option,arg,msg)\ + some_thing_wrong=1;\ + help=1;\ + printf("incorrect %s option is interpreted as -%c, %s \n\n",arg,#option[0],msg);\ + break; + #define IF_OPTION_WITH_ARG_NUM(option)\ if(argv[i][0]=='-'){\ j=1;\ - if(argv[i][j]=='-') ++j;\ + while(argv[i][j]=='-') ++j;\ if(argv[i][j] == #option[0]){\ + arg=argv[i];\ long ret_num=extract_num_after_equal_symbole_in_string(argv[i]);\ PRINT_DEBUG("option=%s, ret_num = %ld, argv[%d]=%s\n",#option,ret_num,i,argv[i]);\ is_##option = 1;\ @@ -307,25 +338,22 @@ long int extract_num_after_equal_symbole_in_string(char * in_str){ else{\ if(i0)\ option = ret_num;\ else{ \ - help=1;\ option = default_##option;\ - some_thing_wrong = 1;\ + LOG_WRONG(option,arg, "wait for args")\ }\ }\ }\ else{\ - help=1;\ option = default_##option;\ - some_thing_wrong = 1;\ + LOG_WRONG(option,arg, "wait for args")\ }\ }\ PRINT_DEBUG("option %s activated, its value is %ld\n",#option,option);\ @@ -336,8 +364,9 @@ long int extract_num_after_equal_symbole_in_string(char * in_str){ #define IF_OPTION_WITH_ARG_STR(option)\ if(argv[i][0]=='-'){\ j=1;\ - if(argv[i][j]=='-') ++j;\ + while(argv[i][j]=='-') ++j;/* to accept multiple -- */\ if(argv[i][j] == #option[0]){\ + arg=argv[i];\ char* ret_str=(char*)extract_string_after_equal_symbole_in_string(argv[i]);\ PRINT_DEBUG("option=%s, ret_str = %s, argv[%d]=%s\n",#option,ret_str,i,argv[i]);\ if(ret_str ==NULL || strlen(ret_str)==0){\ @@ -363,16 +392,109 @@ long int extract_num_after_equal_symbole_in_string(char * in_str){ #define IF_OPTION_NO_ARG(option)\ if(argv[i][0]=='-'){\ j=1;\ - if(argv[i][j]=='-') ++j;\ + while(argv[i][j]=='-') ++j;\ if(argv[i][j] == #option[0]){\ option=1;\ continue;\ }\ }\ +void extract_to_array_TYPE_SIZE_T(char * in_str){ + size_t len=strlen(in_str); + long int val=0, p=10; + for(long i=0; i= '0' && in_str[i] <= '9' ) || (in_str[i] >= 'A' && in_str[i] <= 'z' ) || (in_str[i]=='_')|| (in_str[i]=='-')){ + ++i; + } + } + else if(in_str[i] >= '0' && in_str[i] <= '9' ){ + val = (p * val) + (in_str[i]-'0'); + } + else{ + /* rec val in array */ + PRINT_DEBUG("val=(%ld) \n",val); + array_TYPE_SIZE_T[cur_array_TYPE_SIZE_T++]=val; + val=0; + } + } + PRINT_DEBUG("end val=(%ld) \n",val); + if(val) + array_TYPE_SIZE_T[cur_array_TYPE_SIZE_T++]=val; + +} + +void extract_to_array_TYPE_STRING(char * in_str){ + size_t len=strlen(in_str); + char *val=malloc(len); + size_t cur_val=0; + for(long i=0; i= '0' && in_str[i] <= '9' ) || (in_str[i] >= 'A' && in_str[i] <= 'z' ) || (in_str[i]=='_')|| (in_str[i]=='-')){ + ++i; + } + } + else if((in_str[i] >= '0' && in_str[i] <= '9' ) || (in_str[i] >= 'A' && in_str[i] <= 'z' ) || (in_str[i]=='_')){ + val[cur_val++] = in_str[i]; + } + else{ + /* rec val in array */ + val[cur_val++]='\0'; + + PRINT_DEBUG("val_str=(((%s) cur_val=[%ld]\n",val,cur_val); + array_TYPE_STRING[cur_array_TYPE_STRING]=malloc(strlen(val)); + strcpy(array_TYPE_STRING[cur_array_TYPE_STRING++],val); + cur_val=0; + } + } + if(cur_val){ + val[cur_val++]='\0'; + PRINT_DEBUG("val_str=(%s) cur_val=[%ld]\n",val,cur_val); + + array_TYPE_STRING[cur_array_TYPE_STRING]=malloc(strlen(val)); + strcpy(array_TYPE_STRING[cur_array_TYPE_STRING++],val); + + } +} + + + +#define IF_OPTION_WITH_MULTIPLE_ARG(option,type)\ + if(argv[i][0]=='-'){\ + j=1;\ + while(argv[i][j]=='-') ++j;\ + if(argv[i][j] == #option[0]){\ + arg=argv[i];\ + array_##type=malloc(sizeof(type)*count_tests);\ + some_tests_selected= 1;\ + do{\ + extract_to_array_##type(argv[i]);\ + PRINT_DEBUG("option=%s, cur = %ld, argv[%d]=%s\n",#option,cur_array_##type,i,argv[i]);\ + }while(i=0){ + if(name_org[i] == ')') + break; + else + name_test[cur++]=name_org[i]; } - } - return found; + } + name_test[cur]='\0'; + PRINT_DEBUG("name_test =%s\n",name_test); + *name_f = name_test; + } +#define CHECK_IF_SELECTED_TEST(name_f)\ + exec_test=0;\ + if(some_tests_selected == 0){\ + exec_test=1; \ + }\ + else{\ + if(cur_array_TYPE_SIZE_T){\ + num_f=extract_num__f(name_f) ;\ + exec_test = is_in_array_TYPE_SIZE_T(array_TYPE_SIZE_T, num_f);\ + }\ + if(exec_test == 0 && cur_array_TYPE_STRING){\ + extract_name_test_from_name(name_f, &name_test);\ + exec_test = is_in_array_TYPE_STRING(array_TYPE_STRING, name_test );\ + free(name_test);\ + }\ + }\ + + + void execute_all(struct func *fun){ struct func *tmp = fun; struct timespec start_t; + 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); while(tmp){ - begin_execute_func(tmp->name, &start_t); - tmp->run(); - end_execute_func(tmp->name, start_t); + CHECK_IF_SELECTED_TEST(tmp->name) + if(exec_test){ + begin_execute_func(tmp->name, &start_t); + tmp->run(); + end_execute_func(tmp->name, start_t); + } tmp = tmp->next; } } +/* void execute_one_test(struct func *fun, size_t num){ size_t cur = 0; struct timespec start_t; @@ -747,7 +949,7 @@ run_all_tests_exept(size_t cnt, ... ) if(count_tests >= cnt) stat_end_run(count_tests - cnt, start_t); } - +*/ void run_all_tests() @@ -755,7 +957,8 @@ run_all_tests() 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_tests, start_t); + stat_end_run(count_pass_global + count_fail_global, start_t); } #if 0 @@ -796,7 +999,8 @@ run_all_div_tests(void *id) */ void head_all_parallel_run(struct timespec *start_t){ clock_gettime(CLOCK_REALTIME, start_t); - PRINT_HK_C(GREEN_K, HK_EQ," Running tests on %ld threads\n", parallel_nb); + 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); } /* @@ -936,6 +1140,9 @@ void execute_test_parallel(size_t id_thrd){ struct timespec start_t; struct func *tmp; + size_t num_f; + char *name_test=NULL; + bool exec_test=0; do{ LOCK(mut_current_test); @@ -943,10 +1150,13 @@ void execute_test_parallel(size_t id_thrd){ if(tmp){ current_fn = tmp->next; UNLOCK(mut_current_test); - PRINT_DEBUG(" *** thread[%ld], func_name = %s *** \n", id_thrd, tmp->name); - begin_execute_func_parallel(tmp->name, &start_t, id_thrd); - tmp->run(); - end_execute_func_parallel(tmp->name, start_t, id_thrd); + CHECK_IF_SELECTED_TEST(tmp->name) + if(exec_test){ + PRINT_DEBUG(" *** thread[%ld], func_name = %s *** \n", id_thrd, tmp->name); + begin_execute_func_parallel(tmp->name, &start_t, id_thrd); + tmp->run(); + end_execute_func_parallel(tmp->name, start_t, id_thrd); + } } else{ UNLOCK(mut_current_test); @@ -1104,7 +1314,8 @@ if(progress) pthread_create(&thrd_progress, NULL, run_progress_tests, NULL); if(progress) pthread_join(thrd_progress, NULL); - stat_end_all_parallel_run(count_tests, start_t ); + //stat_end_all_parallel_run(count_tests, start_t ); + stat_end_all_parallel_run(count_pass_global + count_fail_global, start_t ); free(id_th); free(thrd); diff --git a/src/ftest/ftest.h b/src/ftest/ftest.h index b98adc2..c2fd233 100644 --- a/src/ftest/ftest.h +++ b/src/ftest/ftest.h @@ -169,9 +169,11 @@ void parse_options(int argc, char **argv); void run_all_tests(); void execute_all(struct func *fun); void append_func(void (*run)(void), char *name); +/* void run_some_tests(size_t cnt, ... ); void run_all_tests_exept(size_t cnt, ... ); void run_some_tests_ordered(size_t cnt, ... ); +*/ void run_all_tests_parallel(size_t parallel /*, int max_col*/); diff --git a/src/tools_t/tools_t.c b/src/tools_t/tools_t.c index a7be1c5..30ce1a5 100644 --- a/src/tools_t/tools_t.c +++ b/src/tools_t/tools_t.c @@ -102,6 +102,7 @@ TYPE_STRING TYPE_STRING_TO_STR(TYPE_STRING var){ int COMPARE_N_TYPE_STRING(const void *a,const void* b) { + PRINT_DEBUG("a=%s, b=%s\n",(char*)a, (char*)b); return strcmp(( char*)a,( char*)b); } diff --git a/test/is_good.c b/test/is_good.c index b62472c..a52d540 100644 --- a/test/is_good.c +++ b/test/is_good.c @@ -26,6 +26,8 @@ TEST(size_permutation) EXPECT_EQ(p->size, 3); PRINTF("test size_permutation2\n"); } + +#if 1 TEST(size_permutation2){ PRINTF("another size_permutation2 again false\n"); bool val_bool = false; @@ -141,6 +143,8 @@ TEST(sleep){sleep(2);} TEST(sleep){sleep(2);} TEST(sleep){sleep(2);} +#endif + int main(int argc, char **argv){ //run_all_tests();