Now, we can rec results of each thread in separate files, and print all results at the end of all tests
This commit is contained in:
@@ -30,13 +30,14 @@ GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_SIZE_T)
|
||||
p->perm = malloc(size * sizeof(type));\
|
||||
return p; }\
|
||||
\
|
||||
PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(PERMUTATION_##type *p ){\
|
||||
PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(const PERMUTATION_##type *p ){\
|
||||
if (p == NULL) return NULL;\
|
||||
PERMUTATION_TYPE_SIZE_T *t_p = malloc(sizeof(PERMUTATION_TYPE_SIZE_T));\
|
||||
size_t size = p->size;\
|
||||
t_p->size = size;\
|
||||
t_p->perm = malloc(size * sizeof(TYPE_SIZE_T));\
|
||||
type *sorted_perm = malloc(size * sizeof(type));\
|
||||
COPY_ARRAY_##type(sorted_perm, p->perm, size);\
|
||||
COPY_ARRAY_##type(sorted_perm,(const type*)p->perm, size);\
|
||||
qsort(sorted_perm, size, sizeof(type), COMPARE_N_##type);\
|
||||
size_t *rec_index_visited = malloc(size * sizeof(size_t));\
|
||||
size_t cur_rec = 0; bool found_rec;\
|
||||
@@ -48,12 +49,17 @@ GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(TYPE_SIZE_T)
|
||||
if(rec_index_visited[k] == j){\
|
||||
found_rec == true; break; } } \
|
||||
if(found_rec == false){\
|
||||
t_p->perm[i] = j;\
|
||||
/*t_p->perm[i] = j;*/\
|
||||
t_p->perm[j] = i;\
|
||||
rec_index_visited[cur_rec++] = j; \
|
||||
break; } } } } \
|
||||
break; }\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
free(rec_index_visited);\
|
||||
free(sorted_perm);\
|
||||
return t_p; }\
|
||||
return t_p; \
|
||||
}\
|
||||
\
|
||||
bool IS_PERMUTATION_##type(const PERMUTATION_##type *p){\
|
||||
if(p == NULL) return false;\
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
\
|
||||
typedef struct PERMUTATION_##type PERMUTATION_##type;\
|
||||
PERMUTATION_##type * CREATE_PERMUTATION_##type(size_t size);\
|
||||
PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(const PERMUTATION_##type *p );\
|
||||
|
||||
|
||||
|
||||
GENERATE_PERMUTATION(TYPE_SIZE_T)
|
||||
GENERATE_PERMUTATION(TYPE_CHAR)
|
||||
GENERATE_PERMUTATION(TYPE_U_CHAR)
|
||||
GENERATE_PERMUTATION(TYPE_INT)
|
||||
GENERATE_PERMUTATION(TYPE_U_INT)
|
||||
GENERATE_PERMUTATION(TYPE_L_INT)
|
||||
GENERATE_PERMUTATION(TYPE_U_L_INT)
|
||||
GENERATE_PERMUTATION(TYPE_SIZE_T)
|
||||
GENERATE_PERMUTATION(TYPE_FLOAT)
|
||||
GENERATE_PERMUTATION(TYPE_DOUBLE)
|
||||
GENERATE_PERMUTATION(TYPE_L_DOUBLE)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
type *set; \
|
||||
}; \
|
||||
typedef struct SET_THEORIC_##type SET_THEORIC_##type; \
|
||||
SET_THEORIC_##type * CREATE_SET_THEORIC_##type(TYPE_##type); \
|
||||
SET_THEORIC_##type * CREATE_SET_THEORIC_##type(size_t id/*TYPE_##type*/); \
|
||||
bool IS_SET_THEORIC_##type(SET_THEORIC_##type *st); \
|
||||
|
||||
GENERATE_UNSIGNED_SET_THEORIC(TYPE_U_CHAR)
|
||||
|
||||
+27
-17
@@ -11,43 +11,41 @@
|
||||
|
||||
#include "src/test_t/test_t.h"
|
||||
|
||||
//#include "src/permutation_t/permutation_t.h"
|
||||
#include "src/permutation_t/permutation_t.h"
|
||||
|
||||
TEST(size_permutation2){
|
||||
printf("another size_permutation2 again\n");
|
||||
PRINTF("another size_permutation2 again\n");
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TEST(size_permutation)
|
||||
{
|
||||
/*
|
||||
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
|
||||
|
||||
printf(" size = %u \n",p->size);
|
||||
if(p->size == 3) print_OK_with_msg_endl(" FF yeah GOOD test size passed ");
|
||||
else print_KO_with_msg_endl("NOT GOOD test size not passed ");
|
||||
*/
|
||||
printf("test size_permutation2\n");
|
||||
PRINTF(" size = %lu \n",p->size);
|
||||
EXPECT_EQ(p->size, 3);
|
||||
PRINTF("test size_permutation2\n");
|
||||
}
|
||||
TEST(size_permutation2){
|
||||
printf("another size_permutation2 again false\n");
|
||||
PRINTF("another size_permutation2 again false\n");
|
||||
bool val_bool = false;
|
||||
ASSERT_TRUE(val_bool);
|
||||
}
|
||||
TEST(size_permutation2)
|
||||
{
|
||||
printf("test size_permutation2\n");
|
||||
PRINTF("test size_permutation2\n");
|
||||
bool val_bool = true;
|
||||
ASSERT_FALSE(val_bool);
|
||||
/*
|
||||
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
|
||||
|
||||
printf(" size = %u \n",p->size);
|
||||
PRINTF(" size = %u \n",p->size);
|
||||
if(p->size == 3) print_OK_with_msg_endl(" FF yeah GOOD test size passed ");
|
||||
else print_KO_with_msg_endl("NOT GOOD test size not passed ");
|
||||
*/
|
||||
}
|
||||
TEST(float_equal){
|
||||
printf("another size_permutation2 float\n");
|
||||
PRINTF("another size_permutation2 float\n");
|
||||
ASSERT_TRUE(true);
|
||||
float a = 1.00001f;
|
||||
float b = 1.00001f;
|
||||
@@ -57,7 +55,7 @@ TEST(float_equal){
|
||||
ASSERT_EQ_TYPE_FLOAT(1.0000102f,b);
|
||||
}
|
||||
TEST(double_equal){
|
||||
printf("another size_permutation2 double\n");
|
||||
PRINTF("another size_permutation2 double\n");
|
||||
ASSERT_TRUE(true);
|
||||
double a = 1.00000001;
|
||||
double b = 1.00000001;
|
||||
@@ -100,20 +98,32 @@ TEST(expect){
|
||||
}
|
||||
|
||||
TEST(){
|
||||
printf("no test, only print\n");
|
||||
PRINTF("no test, only print\n");
|
||||
}
|
||||
|
||||
TEST(){
|
||||
printf("no test, only print\n");
|
||||
PRINTF("no test, only print\n");
|
||||
}
|
||||
|
||||
TEST(){
|
||||
printf("no test, only print\n");
|
||||
PRINTF("no test, only print\n");
|
||||
}
|
||||
|
||||
|
||||
TEST(){
|
||||
printf("no test, only print\n");
|
||||
|
||||
PERMUTATION_TYPE_CHAR *p_char = CREATE_PERMUTATION_TYPE_CHAR(6);
|
||||
p_char->perm[0]='B';
|
||||
p_char->perm[1]='A';
|
||||
p_char->perm[2]='Y';
|
||||
p_char->perm[3]='C';
|
||||
p_char->perm[4]='D';
|
||||
p_char->perm[5]='Z';
|
||||
|
||||
PERMUTATION_TYPE_SIZE_T *tr_p_char = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_CHAR(p_char);
|
||||
|
||||
for(int i = 0; i < tr_p_char->size; ++i) PRINTF(" [%d ]%ld ,",i,tr_p_char->perm[i]);
|
||||
PRINTF("p_char == %s\n",p_char->perm);
|
||||
}
|
||||
|
||||
TEST(lessThan){
|
||||
|
||||
+37
-5
@@ -27,6 +27,8 @@
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
#ifndef PARALLEL
|
||||
#define PARALLEL 1
|
||||
@@ -70,6 +72,8 @@ struct failed_lists{
|
||||
*/
|
||||
bool is_parallel = 0;
|
||||
|
||||
FILE **f_ou_th;
|
||||
|
||||
size_t count_tests = 0;
|
||||
|
||||
size_t count_pass_global = 0;
|
||||
@@ -174,7 +178,7 @@ void append_failed_list(struct failed_lists **fn_failed_list ,const char *name_f
|
||||
*/
|
||||
long int id_of_thread_executed(void){
|
||||
size_t id_from_self = pthread_self();
|
||||
for(size_t i=0; i<parallel_nb; ++i){
|
||||
for(size_t i=0; i<parallel_nb + 1; ++i){
|
||||
if(id_thread_self[i] == id_from_self)
|
||||
return i;
|
||||
}
|
||||
@@ -621,6 +625,9 @@ void head_all_parallel_run(struct timespec *start_t){
|
||||
* print on the top of test in parallel
|
||||
*/
|
||||
void head_parallel_run(struct timespec *start_t, size_t id_thrd){
|
||||
char name_file_output[256];
|
||||
sprintf(name_file_output,"log_thread_%ld_id_%ld",id_thrd,pthread_self());
|
||||
f_ou_th[id_thrd] = fopen(name_file_output, "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());
|
||||
}
|
||||
@@ -739,6 +746,16 @@ void
|
||||
init_parallel_test_()
|
||||
{
|
||||
is_parallel = 1;
|
||||
|
||||
f_ou_th = malloc((parallel_nb + 1) *sizeof(FILE*));
|
||||
/*
|
||||
* on thread principale
|
||||
*/
|
||||
char name_file_output[256];
|
||||
sprintf(name_file_output,"log_principal_thread_%ld_id_%ld",parallel_nb,pthread_self());
|
||||
f_ou_th[parallel_nb] = fopen(name_file_output, "w+");
|
||||
|
||||
|
||||
count_pass_test = malloc(count_tests * sizeof(size_t));
|
||||
count_fail_test = malloc(count_tests * sizeof(size_t));
|
||||
for(size_t i=0; i<count_tests; ++i){
|
||||
@@ -749,8 +766,10 @@ init_parallel_test_()
|
||||
thread_test_failed_l = malloc(parallel_nb * sizeof(struct failed_lists*));
|
||||
count_pass_thread = malloc(parallel_nb * sizeof(size_t));
|
||||
count_fail_thread = malloc(parallel_nb * sizeof(size_t));
|
||||
id_thread_self = malloc(parallel_nb * sizeof(size_t));
|
||||
|
||||
id_thread_self = malloc((parallel_nb + 1) * sizeof(size_t));
|
||||
|
||||
id_thread_self[parallel_nb]= pthread_self();// main thread
|
||||
|
||||
for(size_t i=0; i<parallel_nb; ++i){
|
||||
thread_test_failed_l[i] = NULL;
|
||||
count_pass_thread[i] = 0;
|
||||
@@ -786,16 +805,29 @@ final_parallel_test_()
|
||||
pthread_mutex_destroy(&mut_count_fail_global);
|
||||
pthread_mutex_destroy(&mut_count_pass_local);
|
||||
pthread_mutex_destroy(&mut_count_fail_local);
|
||||
|
||||
char reader[256];
|
||||
for(size_t id_thrd =0 ; id_thrd <= parallel_nb; ++id_thrd){
|
||||
rewind(f_ou_th[id_thrd]); // put the file pointer to the begin of file;
|
||||
|
||||
while(fgets(reader, 255,f_ou_th[id_thrd] )){
|
||||
fprintf(F_OUT,"%s",reader);
|
||||
}
|
||||
fclose(f_ou_th[id_thrd]);
|
||||
}
|
||||
//fclose(f_ou_th[parallel_nb]);
|
||||
}
|
||||
|
||||
void run_all_tests_parallel(size_t parallel)
|
||||
{
|
||||
parallel_nb = parallel;
|
||||
parallel_nb = parallel; /* need to be here to initialise parallel_nb for init_parallel_test_ */
|
||||
|
||||
init_parallel_test_();
|
||||
|
||||
struct timespec start_t;
|
||||
|
||||
head_all_parallel_run(&start_t);
|
||||
|
||||
init_parallel_test_();
|
||||
|
||||
pthread_t *thrd = malloc(parallel_nb * sizeof(pthread_t));
|
||||
size_t *id_th = malloc( parallel_nb * sizeof(size_t));
|
||||
|
||||
+97
-13
@@ -34,7 +34,7 @@
|
||||
#define HK_FL "===== FAIL"
|
||||
#define HK_PS "===== PASS"
|
||||
#define HK_SK "===== SKIP"
|
||||
#endif
|
||||
#endif /* HK */
|
||||
|
||||
/*
|
||||
* compare symbol
|
||||
@@ -53,16 +53,10 @@
|
||||
#define DESCRIPTION_GE "greate than or equality"
|
||||
#define DESCRIPTION_NE "inequality"
|
||||
|
||||
/*
|
||||
// F_OUT file (stream) to log
|
||||
#ifndef F_OUT
|
||||
#define F_OUT stdout
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef NOT_COLORED
|
||||
#define NOT_COLORED 0
|
||||
#endif
|
||||
#endif /* NOT_COLORED */
|
||||
|
||||
#if 0
|
||||
#ifndef PARALLEL
|
||||
@@ -74,9 +68,94 @@
|
||||
#define UNLOCK(mutex_var) pthread_mutex_unlock(&mutex_var);
|
||||
#define is_parallel 1
|
||||
#endif
|
||||
#endif
|
||||
#endif /* 0 */
|
||||
|
||||
extern FILE **f_ou_th;
|
||||
|
||||
// ===================== rec not in file
|
||||
|
||||
|
||||
#ifndef REC_IN_FILE
|
||||
|
||||
#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(!NOT_COLORED) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
|
||||
else fprintf(F_OUT, hk __VA_ARGS__); } while(0)
|
||||
|
||||
/* =================================== end no file */
|
||||
#else /* REC_IN_FILE */
|
||||
/* ====================== rec in file */
|
||||
|
||||
#define PRINT_LOC(fmt, ...) \
|
||||
do{ \
|
||||
if(is_parallel){\
|
||||
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__);\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#define PRINTF( ...) \
|
||||
do{ \
|
||||
if(is_parallel){\
|
||||
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__);\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#define PRINT_HK_C(color,hk,...)\
|
||||
do{ \
|
||||
if(is_parallel){\
|
||||
size_t id_thread=id_of_thread_executed();\
|
||||
if(id_thread < 0){\
|
||||
if(!NOT_COLORED) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
|
||||
else fprintf(F_OUT, hk __VA_ARGS__); \
|
||||
}\
|
||||
else{\
|
||||
if(!NOT_COLORED) fprintf(f_ou_th[id_thread], color hk DEFAULT_K __VA_ARGS__); \
|
||||
else fprintf(f_ou_th[id_thread], hk __VA_ARGS__); \
|
||||
}\
|
||||
} \
|
||||
else{\
|
||||
if(!NOT_COLORED) fprintf(F_OUT, color hk DEFAULT_K __VA_ARGS__); \
|
||||
else fprintf(F_OUT, hk __VA_ARGS__); \
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
#endif /* REC_IN_FILE */
|
||||
|
||||
// ====================== = end rec log in file
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
/*
|
||||
* print [ HK_NAME ] with color
|
||||
@@ -84,22 +163,29 @@
|
||||
#define PRINT_HK_C(color,hk,format,...)\
|
||||
do{ if(!NOT_COLORED) 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(msg)\
|
||||
PRINT_HK_C(GREEN_K, HK_SK," %s\n",#msg);\
|
||||
#define SKIP(...)\
|
||||
PRINT_HK_C(GREEN_K, HK_SK __VA_ARGS__);\
|
||||
PRINT_LOC("%s\n\n"," Skiped"); return;
|
||||
|
||||
|
||||
|
||||
struct func {
|
||||
char *name;
|
||||
void (*run)(void);
|
||||
struct func *next;
|
||||
};
|
||||
|
||||
|
||||
extern bool is_parallel;
|
||||
|
||||
long int id_of_thread_executed(void);
|
||||
|
||||
void run_all_tests();
|
||||
void execute_all(struct func *fun);
|
||||
void append_func(void (*run)(void), char *name);
|
||||
@@ -569,6 +655,4 @@ do{
|
||||
if(expected_false_f(val,#val,__func__) == false) {error_print("%s\n\n","Failure"); return;}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif /* __TEST_C_H__ */
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "src/tools_t/tools_t.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start){
|
||||
return (time_stop.tv_sec - time_start.tv_sec) + 1.0e-9 * (time_stop.tv_nsec - time_start.tv_nsec);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#define DEBUG 0
|
||||
#endif
|
||||
|
||||
|
||||
// F_OUT file (stream) to log
|
||||
#ifndef F_OUT
|
||||
#define F_OUT stdout
|
||||
@@ -21,6 +22,10 @@
|
||||
#define F_ERR stderr
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#ifndef SECOND
|
||||
#define SECOND 0
|
||||
@@ -51,7 +56,7 @@ long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_s
|
||||
fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
#define PRINT_LOC(fmt, ...) \
|
||||
#define PRINT_LOC_T(fmt, ...) \
|
||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user