add progress bar when ordered parallel, and cleanup repository

This commit is contained in:
2023-08-26 07:54:57 +02:00
parent 9191e6c8ca
commit e779b37852
24 changed files with 86 additions and 21987 deletions
-26
View File
@@ -1,26 +0,0 @@
#include "src/set_theoric/set_theoric.h"
set_theoric * create_set_theoric(unsigned int id)
{
if(id == 0) return NULL;
set_theoric *ret_set = malloc(sizeof(set_theoric));
ret_set.set=malloc(id*sizeof(unsigned int));
ret_set.id = id;
for(int i = 0; i < id; ++i)
ret_set.set[i] = i;
return ret_set;
}
bool is_set_theoric(set_theoric *st)
{
if(st == NULL) return true;
for(int i = 0; i < st->id; ++i)
if(st->set[i] != i) return false;
return true;
}
-22
View File
@@ -1,22 +0,0 @@
#ifndef __SET_THEORIC_C__H
#define __SET_THEORIC_C__H
#include <stdlib.h>
#include "src/tools/tools.h"
struct set_theoric
{
unsigned int id;
unsigned int *set;
};
typedef set_theoric set_theoric;
set_theoric * create_set_theoric(unsigned int id);
bool is_set_theoric(set_theoric *st);
#endif /*__SET_THEORIC_C__H*/
+35 -15
View File
@@ -84,6 +84,7 @@ struct failed_lists{
#define default_unicolour 0
#define default_removelog 0
#define default_parallel_nb 1
#define default_width 1
/*
@@ -103,6 +104,8 @@ char *timeunit="ms";
char *savelog=NULL;
char *default_timeunit="ms";
char *default_savelog="log_all_tests";
size_t width = 80;
/*
* number of threads
*/
@@ -113,6 +116,7 @@ size_t parallel_nb = 0;
*/
bool is_parallel_nb = 0;
bool is_width=0;
bool progress = false;
FILE **f_ou_th;
@@ -226,7 +230,7 @@ long int id_of_thread_executed(void){
/*
* format name of TEST(name_f) is: 'TEST_name_f____NUM',
* format name of TEST(name_f) is: 'TEST_name_f____NUM|',
* and name attribute is 'TEST(name_f): test N° NUM!' (! at the end is random):
* we extract NUM here
* to have hash_table of the count when parallel test!
@@ -235,7 +239,8 @@ size_t extract_num__f(const char *name_f){
size_t len = strlen(name_f);
size_t val = 0, p = 1;
for(long i= len-1; i>=0; --i){
PRINT_DEBUG(" name_f[%ld] = %c\n",i,name_f[i]);
PRINT_DEBUG(" name_f(%s)[%ld] = %c\n",name_f,i,name_f[i]);
if(name_f[i]=='|') val = 0;
if(name_f[i] >= '0' && name_f[i] <= '9'){
val += p * (name_f[i]-'0');
p *= 10;
@@ -254,7 +259,8 @@ void usage(int argc, char **argv){
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 -s <file>, --savelog <file>, -s=file, --savelog=file\n\t\tthis option save the global ordered result in 'file',\n\t\this option active the option -o or --ordered. \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,\n\t\tex: -w100, or --width=100 or -wi 100\n\n");
if(some_thing_wrong){
printf("invalid argument\n");
@@ -371,6 +377,7 @@ void parse_options(int argc, char **argv){
PRINT_DEBUG("argc=%d, argv[%d]=%s\n",argc,i,argv[i]);
IF_OPTION_NO_ARG(help)
IF_OPTION_WITH_ARG_NUM(parallel_nb)
IF_OPTION_WITH_ARG_NUM(width)
IF_OPTION_WITH_ARG_STR(savelog)
IF_OPTION_WITH_ARG_STR(timeunit)
IF_OPTION_NO_ARG(ordered)
@@ -875,8 +882,9 @@ void end_execute_func_parallel(char *fun_ame, struct timespec start_t, size_t id
}
}
#if 1
void progress_test_(int max_colon){
unsigned sleep(unsigned x) { time_t t0=time(0); while (difftime(time(0),t0)<x); return 0; }
void progress_test_(){
struct func *tmp;
size_t num_test=0;
int cur = 0, len;
@@ -885,32 +893,44 @@ void progress_test_(int max_colon){
char prgss[]="/ | --";
len=strlen(prgss);
do{
LOCK(mut_current_test);
//LOCK(mut_current_test);
tmp = current_fn;
UNLOCK(mut_current_test);
//UNLOCK(mut_current_test);
if(tmp)
num_test = extract_num__f(tmp->name);
gotoxy(13,0);
for(int i=0; i<(num_test*max_colon/count_tests); ++i) printf("#");
//gotoxy(13,0);
printf("\r[");
for(int i=0; i< width; ++i) {
if(i<=(num_test+1)*width/count_tests){
//usleep(20000);
printf("#");
}
else printf(" ");
}
printf("|%ld%%, 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 */
//printf("\33[2K\r"); // remove current line and go to begin of the current line
if(cur<len-1) ++cur;
else cur=0;
//printf("\n");
//sleep(1);
//usleep(50000);
//usleep(500000);
}while(tmp);
printf("\n");
}
void*
run_progress_tests(void *max_d)
{
int max_col = 180; //*(int*)max_d;
//progress_test_(max_col);
int max_col = 80; //*(int*)max_d;
progress_test_(max_col);
}
#endif
void execute_test_parallel(size_t id_thrd){
@@ -951,7 +971,7 @@ run_parallel_tests(void *id)
void
init_parallel_test_()
{
progress = PROGRESS;
progress = ordered;
is_parallel_nb = 1;
+47 -80
View File
@@ -46,34 +46,10 @@
#define GE >=
#define NE !=
#define DESCRIPTION_EQ "equality"
#define DESCRIPTION_LT "less than"
#define DESCRIPTION_GT "greate than"
#define DESCRIPTION_LE "less than or equality"
#define DESCRIPTION_GE "greate than or equality"
#define DESCRIPTION_NE "inequality"
#if 0
#ifndef unicolour
#define unicolour 0
#endif /* unicolour */
#ifndef PARALLEL
#define PARALLEL 1
#define LOCK(mut)
#define UNLOCK(mut)
#else /*PARALLEL defined*/
#define LOCK(mutex_var) pthread_mutex_lock(&mutex_var);
#define UNLOCK(mutex_var) pthread_mutex_unlock(&mutex_var);
#define is_parallel_nb 1
#endif
#endif /* 0 */
extern FILE **f_ou_th;
extern bool unicolour;
// ===================== rec not in file
extern bool ordered;
#ifndef SAVE_LOG
@@ -85,86 +61,78 @@ extern bool unicolour;
#endif
#ifndef ORDER_LOG
#define PRINT_LOC(fmt, ...) \
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__)
#define PRINTF( ...) \
fprintf(F_OUT, __VA_ARGS__)
/*
* print [ HK_NAME ] with color
*/
#define PRINT_HK_C(color,hk,...)\
do{ if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); } while(0)
/* =================================== end no file */
#else /* ORDER_LOG */
/* ====================== rec in file */
#define PRINT_LOC(fmt, ...) \
do{ \
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__);\
}\
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_ou_th[id_thread], "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
}\
} \
}\
else{\
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, __VA_ARGS__);\
__LINE__, __func__, __VA_ARGS__);\
}\
}while(0)
#define PRINTF( ...) \
do{ \
if(is_parallel_nb){\
size_t id_thread=id_of_thread_executed();\
if(id_thread < 0){\
fprintf(F_OUT,__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_ou_th[id_thread], __VA_ARGS__);\
fprintf(F_OUT, __VA_ARGS__);\
}\
} \
}\
else{\
fprintf(F_OUT, __VA_ARGS__);\
fprintf(F_OUT, __VA_ARGS__);\
}\
}while(0)
#define PRINT_HK_C(color,hk,...)\
do{ \
if(is_parallel_nb){\
size_t id_thread=id_of_thread_executed();\
if(id_thread < 0){\
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(!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__); \
if(!unicolour) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
else fprintf(F_OUT, hk __VA_ARGS__); \
}\
}while(0)
#endif /* ORDER_LOG */
// ====================== = end rec log in file
#if 0
/*
@@ -426,7 +394,6 @@ do{ \
#define EXPECT_LT(var1, var2) HANDLE_OP_EXPECT_ASSERT(LT, TYPE_L_INT,var1, var2, 0)
// ============== ASERT =====================
#define ASSERT_LT_TYPE_CHAR(var1, var2) HANDLE_OP_EXPECT_ASSERT(LT, TYPE_CHAR,var1, var2, 1)
@@ -651,7 +618,7 @@ do{
void CONCAT(TEST_##name_f##____,count)(void); \
__attribute__((constructor)) \
void CONCAT(append_test_##name_f,count)(void){ \
append_func(CONCAT(TEST_##name_f##____,count),STRFY(TEST(name_f): test N° count )); \
append_func(CONCAT(TEST_##name_f##____,count),STRFY(TEST(name_f): test N° count|)); \
} \
void CONCAT(TEST_##name_f##____,count)(void)
-144
View File
@@ -1,144 +0,0 @@
#include "src/tools/tools.h"
int
compare_int(void* a, void* b)
{
return (*(int*)a - *(int*)b);
}
int
compare_unsigned_int(void* a, void* b)
{
return ((unsigned int*)a-*(unsigned int*)b);
}
int
compare_float(void *a, void *b)
{
if (*(float*)a == *(float*)b) return 0;
if (*(float*)a > *(float*)b) return 1;
return -1;
}
int
compare_double(void *a, void *b)
{
if (*(double*)a == *(double*)b) return 0;
if (*(double*)a > *(double*)b) return 1;
return -1;
}
int
compare_string(void *a, void *b)
{
return strcmp((char*)a, (char*)b);
}
int
max_array_int(int * arr, size_t sz)
{
if(sz == 0) return 0;
int mx = arr[0];
for(size_t i = 1; i < sz; ++i)
if(mx < arr[i]) mx = arr[i];
return mx;
}
unsigned int
max_array_unsigned_int(unsigned int *arr, size_t sz)
{
if(sz == 0) return 0;
unsigned int mx = arr[0];
for(size_t i = 1; i < sz; ++i)
if(mx < arr[i]) mx = arr[i];
return mx;
}
int
min_array_int(int * arr, size_t sz)
{
if(sz == 0) return 0;
int mn = arr[0];
for(size_t i = 1; i < sz; ++i)
if(mn > arr[i]) mn = arr[i];
return mn;
}
unsigned int
min_array_unsigned_int(unsigned int *arr, size_t sz)
{
if(sz == 0) return 0;
unsigned int mn = arr[0];
for(size_t i = 1; i < sz; ++i)
if(mn > arr[i]) mn = arr[i];
return mn;
}
size_t
arg_max_array_int(int * arr, size_t sz)
{
if(sz == 0) return 0;
size_t i_mx = 0;
for(size_t i = 1; i < sz; ++i)
if(arr[i_mx] < arr[i]) i_mx = i;
return i_mx;
}
size_t
arg_max_array_unsigned_int(unsigned int *arr, size_t sz)
{
if(sz == 0) return 0;
size_t i_mx = 0;
for(size_t i = 1; i < sz; ++i)
if(arr[i_mx] < arr[i]) i_mx = i;
return i_mx;
}
size_t
arg_min_array_int(int * arr, size_t sz)
{
if(sz == 0) return 0;
size_t i_mn = 0;
for(size_t i = 1; i < sz; ++i)
if(arr[i_mn] > arr[i]) i_mn = i;
return i_mn;
}
size_t
arg_min_array_unsigned_int(unsigned int *arr, size_t sz)
{
if(sz == 0) return 0;
size_t i_mn = 0;
for(size_t i = 1; i < sz; ++i)
if(arr[i_mn] > arr[i]) i_mn = i;
return i_mn;
}
void
copy_array_unsigned_int(unsigned int *dst, const unsigned int *src, size_t size)
{
for(size_t i=0; i< size; ++i)
dst[i]=src[i];
}
/*
bool is_less_eq_than_i(int a, int b) { return a <= b; }
bool is_less_than_i(int a, int b) { return a < b; }
bool is_great_eq_than_i(int a, int b) { return a >= b; }
bool is_great_than_i(int a, int b) { return a > b; }
*/
int incr_i(int i) { return i + 1; }
int decr_i(int i) { return i - 1; }
/*
bool is_less_eq_than_u(unsigned int a, unsigned int b) { return a <= b; }
bool is_less_than_u(unsigned int a, unsigned int b) { return a < b; }
bool is_great_eq_than_u(unsigned int a, unsigned int b) { return a >= b; }
bool is_great_than_u(unsigned int a, unsigned int b) { return a > b; }
*/
unsigned int incr_u(unsigned int i) { return i + 1; }
unsigned int decr_u(unsigned int i) { return i - 1; }
-48
View File
@@ -1,48 +0,0 @@
#ifndef __TOOLS_C_H__
#define __TOOLS_C_H__
#include <stdlib.h>
#include <string.h>
#define FREE(x) { free((x)); (x) = NULL;}
int compare_int(void* a, void* b);
int compare_unsigned_int(void* a, void* b);
int compare_float(void *a, void *b);
int compare_double(void *a, void *b);
int compare_string(void *a, void *b);
int max_array_int(int *arr, size_t sz);
unsigned int max_array_unsigned_int(unsigned int *arr, size_t sz);
int min_array_int(int *arr, size_t sz);
unsigned int min_array_unsigned_int(unsigned int *arr, size_t sz);
size_t arg_max_array_int(int *arr, size_t sz);
size_t arg_max_array_unsigned_int(unsigned int *arr, size_t sz);
size_t arg_min_array_int(int *arr, size_t sz);
size_t arg_min_array_unsigned_int(unsigned int *arr, size_t sz);
void copy_array_unsigned_int(unsigned int *dst, const unsigned int *src, size_t size);
/*
bool is_less_eq_than_i(int a, int b); // { return a <= b; }
bool is_less_than_i(int a, int b); // { return a < b; }
bool is_great_eq_than_i(int a, int b); // { return a >= b; }
bool is_great_than_i(int a, int b); // { return a > b; }
*/
int incr_i(int i); // { return i + 1; }
int decr_i(int i); // { return i - 1; }
/*
bool is_less_eq_than_u(unsigned int a, unsigned int b); // { return a <= b; }
bool is_less_than_u(unsigned int a, unsigned int b); // { return a < b; }
bool is_great_eq_than_u(unsigned int a, unsigned int b); // { return a >= b; }
bool is_great_than_u(unsigned int a, unsigned int b); // { return a > b; }
*/
unsigned int incr_u(unsigned int i); // { return i + 1; }
unsigned int decr_u(unsigned int i); // { return i - 1; }
#endif /*__TOOLS_C_H__*/
+4 -1
View File
@@ -171,14 +171,17 @@ GENERATE_FUNCTION_ALL(TYPE_STRING)
*/
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start){
//PRINT_DEBUG("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
return (time_stop.tv_sec - time_start.tv_sec) + 1.0e-9 * (time_stop.tv_nsec - time_start.tv_nsec);
}
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start){
return 1.0e3 * (time_stop.tv_sec - time_start.tv_sec) + 1.0e-3 * (time_stop.tv_nsec - time_start.tv_nsec);
//PRINT_DEBUG("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
return 1.0e3 * (time_stop.tv_sec - time_start.tv_sec) + 1.0e-6 * (time_stop.tv_nsec - time_start.tv_nsec);
}
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start){
//PRINT_DEBUG("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);
return 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);
}
-2
View File
@@ -24,8 +24,6 @@
/*
#ifndef SECOND
#define SECOND 0