clean up and add Makefile

This commit is contained in:
2023-08-26 22:22:07 +02:00
parent 3828b39ca1
commit 7805c35cd9
29 changed files with 297 additions and 670 deletions
+52
View File
@@ -0,0 +1,52 @@
NAME_TEST=is_good
CC=gcc
LDFLAGS=-lpthread
ROOT_DIR=$(shell pwd)
INCLUDE_DIR=$(ROOT_DIR)/src
CFLAGS=-I$(INCLUDE_DIR)
SRC_DIR=$(ROOT_DIR)/src
SRC=$(wildcard */*/*.c)
OBJ=$(SRC:.c=.o)
#HEADS=$(OBJS:.o=.h)
TEST_DIR=$(ROOT_DIR)
EXECSRC=$(TEST_DIR)/$(NAME_TEST).c
EXEC=$(ROOT_DIR)/launch_$(NAME_TEST)
PERMSRC=$(wildcard */perm*/*perm*.c)
PERMSRC_O=$(PERMSRC:.c=.o)
SETTSRC=$(wildcard */set*/set*.c)
SETTSRC_O=$(SETTSRC:.c=.o)
TOOLSRC=$(wildcard */too*/tool*.c)
TOOLSRC_O=$(TOOLSRC:.c=.o)
TESTSRC=$(wildcard */test*/test*.c)
TESTSRC_O=$(TESTSRC:.c=.o)
all: $(EXEC)
$(EXEC): $(EXECSRC) $(OBJ)
$(CC) -o $@ $^ -I$(INCLUDE_DIR) $(LDFLAGS)
$(TESTSRC_O): $(TESTSRC) $(TOOLSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(PERMSRC_O): $(PERMSRC) $(SETTSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(TOOLSRC_O): $(TOOLSRC)
$(CC) -o $@ -c $< $(CFLAGS)
.PHONY: clean mrproper
clean:
rm -f $(OBJS)
mrproper: clean
rm -f $(EXEC)
run: $(EXEC)
$(EXEC) -p
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
gcc src/test_t/is_good.c src/test_t/test_t.c src/tools_t/tools_t.c \ gcc src/test_t/is_good.c src/test_t/test_t.c src/tools_t/tools_t.c \
src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c \ src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c \
-I. -o isgood && ./isgood -h -p -I./src -o isgood && ./isgood -h -p
+2 -2
View File
@@ -9,9 +9,9 @@
#include <windows.h> #include <windows.h>
#endif #endif
#include "src/test_t/test_t.h" #include "test_t/test_t.h"
#include "src/permutation_t/permutation_t.h" #include "permutation_t/permutation_t.h"
TEST(size_permutation2){ TEST(size_permutation2){
PRINTF("another size_permutation2 again\n"); PRINTF("another size_permutation2 again\n");
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+52
View File
@@ -0,0 +1,52 @@
NAME_TEST=is_good
CC=gcc
LDFLAGS=-lpthread
ROOT_DIR=$(shell pwd)
INCLUDE_DIR=$(ROOT_DIR)
CFLAGS=-I$(INCLUDE_DIR)
SRC_DIR=$(ROOT_DIR)
SRC=$(wildcard */*.c)
OBJ=$(SRC:.c=.o)
#HEADS=$(OBJS:.o=.h)
TEST_DIR=$(ROOT_DIR)
EXECSRC=$(TEST_DIR)/$(NAME_TEST).c
EXEC=$(ROOT_DIR)/launch_$(NAME_TEST)
PERMSRC=$(wildcard perm*/*perm*.c)
PERMSRC_O=$(PERMSRC:.c=.o)
SETTSRC=$(wildcard set*/set*.c)
SETTSRC_O=$(SETTSRC:.c=.o)
TOOLSRC=$(wildcard too*/tool*.c)
TOOLSRC_O=$(TOOLSRC:.c=.o)
TESTSRC=$(wildcard test*/test*.c)
TESTSRC_O=$(TESTSRC:.c=.o)
all: $(EXEC)
$(EXEC): $(EXECSRC) $(OBJ)
$(CC) -o $@ $^ -I$(INCLUDE_DIR) $(LDFLAGS)
$(TESTSRC_O): $(TESTSRC) $(TOOLSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(PERMSRC_O): $(PERMSRC) $(SETTSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
$(CC) -o $@ -c $< $(CFLAGS)
$(TOOLSRC_O): $(TOOLSRC)
$(CC) -o $@ -c $< $(CFLAGS)
.PHONY: clean mrproper
clean:
rm -f $(OBJS)
mrproper: clean
rm -f $(EXEC)
run: $(EXEC)
$(EXEC)
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef __COORDINATE_C__H__ #ifndef __COORDINATE_C__H__
#define __COORDINATE_C__H__ #define __COORDINATE_C__H__
#include "src/dimension/dimension.h" #include "dimension/dimension.h"
struct coordinate struct coordinate
+4 -4
View File
@@ -8,14 +8,14 @@
//#include "/home/fanasina/progr_/ptens0neD/src/dimension/dimension.h" //#include "/home/fanasina/progr_/ptens0neD/dimension/dimension.h"
//#include "/home/fanasina/progr_/ptens0neD/src/permutation/permutation.h" //#include "/home/fanasina/progr_/ptens0neD/permutation/permutation.h"
#include "src/dimension/dimension.hpp" #include "dimension/dimension.hpp"
#include "src/permutation/permutation.hpp" #include "permutation/permutation.hpp"
//#include "permutation.h" //#include "permutation.h"
/*void dimension::initDim(int* arr, bool end = true) { /*void dimension::initDim(int* arr, bool end = true) {
+157
View File
@@ -0,0 +1,157 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// for sleep !
#ifdef __linux__
#include <unistd.h>
#elif _WIN32
#include <windows.h>
#endif
#include "test_t/test_t.h"
#include "permutation_t/permutation_t.h"
TEST(size_permutation2){
PRINTF("another size_permutation2 again\n");
ASSERT_TRUE(false);
}
TEST(size_permutation)
{
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
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");
bool val_bool = false;
ASSERT_TRUE(val_bool);
}
TEST(size_permutation2)
{
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);
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");
ASSERT_TRUE(true);
float a = 1.00001f;
float b = 1.00001f;
ASSERT_EQ_TYPE_FLOAT(a,b);
b=1.0000101f;
ASSERT_EQ_TYPE_FLOAT(a,b);
ASSERT_EQ_TYPE_FLOAT(1.0000102f,b);
}
TEST(double_equal){
PRINTF("another size_permutation2 double\n");
ASSERT_TRUE(true);
double a = 1.00000001;
double b = 1.00000001;
ASSERT_EQ_TYPE_DOUBLE(a,b);
b=1.00000001000000001;
ASSERT_EQ_TYPE_DOUBLE(a,b);
ASSERT_EQ_TYPE_DOUBLE(1.0000000100000002,b);
}
TEST(){
unsigned char c = 'a';
debug_print("another size_permutation2, a = %c\n",c);
ASSERT_FALSE(true);
ASSERT_TRUE(true);
ASSERT_TRUE(true);
}
TEST(){
sleep(3);
int a = 5;
long b = 5;
ASSERT_EQ(a,b);
a=4;
ASSERT_EQ(a,b);
}
TEST(expect){
sleep(2);
int a = 5;
int b = 6;
EXPECT_EQ(a,b);
//SKIP();
SKIP("on skip eq string\n");
EXPECT_EQ_TYPE_STRING("hello","hello");
float f1 = 1.00019999, f2=1.00019999;
EXPECT_EQ_TYPE_FLOAT(f1,f2);
}
TEST(){
PRINTF("no test, only print\n");
}
TEST(){
PRINTF("no test, only print\n");
}
TEST(){
PRINTF("no test, only print\n");
}
TEST(){
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){
long int a=1,b=2;
EXPECT_LT(a,b);
EXPECT_LT(b,a);
}
TEST(sleep){sleep(2);}
TEST(sleep){sleep(2);}
TEST(sleep){sleep(2);}
TEST(sleep){sleep(2);}
TEST(sleep){sleep(2);}
TEST(sleep){sleep(2);}
TEST(sleep){sleep(2);}
int main(int argc, char **argv){
//run_all_tests();
//run_all_tests_parallel(4);
run_all_tests_args(argc, argv);
//purge_tests();
//run_some_tests(8, 1, 2, 2, 3, 3, 0, 4, 1);
//run_some_tests(8, 5, 7, 1, 1, 1, 1, 1, 1);
//run_some_tests_one_by_one(3, 1, 2, 2);
//run_all_tests_exept(2, 1, 3);
return 0;
}
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
#include "src/permutation_t/permutation_t.h" #include "permutation_t/permutation_t.h"
#define GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(type)\ #define GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(type)\
bool IS_PERMUTATION_SET_THEORIC_##type(const PERMUTATION_##type *p){\ bool IS_PERMUTATION_SET_THEORIC_##type(const PERMUTATION_##type *p){\
+2 -2
View File
@@ -1,8 +1,8 @@
#ifndef __PERMUTATION_T_C_H__ #ifndef __PERMUTATION_T_C_H__
#define __PERMUTATION_T_C_H__ #define __PERMUTATION_T_C_H__
#include "src/tools_t/tools_t.h" #include "tools_t/tools_t.h"
#include "src/set_theoric_t/set_theoric_t.h" #include "set_theoric_t/set_theoric_t.h"
/* struct of permutation, not necessarly set_theoric /* struct of permutation, not necessarly set_theoric
* *
Binary file not shown.
+1 -1
View File
@@ -1,5 +1,5 @@
#include "src/set_theoric_t/set_theoric_t.h" #include "set_theoric_t/set_theoric_t.h"
#define GENERATE_SET_THEORIC(type) \ #define GENERATE_SET_THEORIC(type) \
SET_THEORIC_##type * CREATE_SET_THEORIC_##type(size_t id){ \ SET_THEORIC_##type * CREATE_SET_THEORIC_##type(size_t id){ \
+1 -1
View File
@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "src/tools_t/tools_t.h" #include "tools_t/tools_t.h"
#define GENERATE_UNSIGNED_SET_THEORIC(type) \ #define GENERATE_UNSIGNED_SET_THEORIC(type) \
struct SET_THEORIC_##type{ \ struct SET_THEORIC_##type{ \
Binary file not shown.
+4 -4
View File
@@ -7,14 +7,14 @@
#include <algorithm> #include <algorithm>
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tens0neD/tens0neD.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tens0neD/tens0neD.h"
#include "src/tensor/tens0neD/tens0neD.h" #include "tensor/tens0neD/tens0neD.h"
//#include "include/tens0neD.h" //#include "include/tens0neD.h"
//#include "cudatensor.h" //#include "cudatensor.h"
//#include "/home/fanasina/progr_/ptens0neD/src/permutation/permutation.h" //#include "/home/fanasina/progr_/ptens0neD/permutation/permutation.h"
#include "src/permutation/permutation.h" #include "permutation/permutation.h"
template<typename T> template<typename T>
+6 -6
View File
@@ -8,13 +8,13 @@
//#include "tensor.h" //#include "tensor.h"
//#include "cudatensor.h" //#include "cudatensor.h"
//#include "/home/fanasina/progr_/ptens0neD/src/dimension/dimension.h" //#include "/home/fanasina/progr_/ptens0neD/dimension/dimension.h"
//#include "/home/fanasina/progr_/ptens0neD/src/permutation/permutation.h" //#include "/home/fanasina/progr_/ptens0neD/permutation/permutation.h"
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/tensCuda.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/tensCuda.h"
#include "src/dimension/dimension.h" #include "dimension/dimension.h"
#include "src/permutation/permutation.h" #include "permutation/permutation.h"
#include "src/tensor/tensCuda/tensCuda.h" #include "tensor/tensCuda/tensCuda.h"
template<typename T> template<typename T>
struct Tensor { struct Tensor {
+2 -2
View File
@@ -6,8 +6,8 @@
//#include "cuda_device_runtime_api.h" //#include "cuda_device_runtime_api.h"
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/d_tensCuda.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/d_tensCuda.h"
#include "src/tensor/tensCuda/d_tensCuda.h" #include "tensor/tensCuda/d_tensCuda.h"
//#1D grid of 1D blocks //#1D grid of 1D blocks
+3 -3
View File
@@ -7,10 +7,10 @@
#include <algorithm> #include <algorithm>
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tens0neD/tens0neD.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tens0neD/tens0neD.h"
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/tensCuda.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/tensCuda.h"
#include "src/tensor/tensCuda/tensCuda.h" #include "tensor/tensCuda/tensCuda.h"
+5 -5
View File
@@ -6,12 +6,12 @@
#include <stdexcept> #include <stdexcept>
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tens0neD/tens0neD.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tens0neD/tens0neD.h"
#include "src/tensor/tens0neD/tens0neD.h" #include "tensor/tens0neD/tens0neD.h"
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/d_tensCuda.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/d_tensCuda.h"
#include "src/tensor/tensCuda/d_tensCuda.h" #include "tensor/tensCuda/d_tensCuda.h"
//#include "src/dimension/dimension.h" //#include "dimension/dimension.h"
template<typename T> template<typename T>
struct Tensor; struct Tensor;
-450
View File
@@ -1,450 +0,0 @@
#include "src/test_t/test_t.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 HK_EQ "[==========]"
#define HK_TR "[----------]"
#define HK_RN "[RUN ]"
#define HK_DN "[ DONE]"
#define HK_OK "[ OK ]"
#define HK_FL "[ FAILED ]"
#define HK_PS "[ PASSED ]"
*/
#ifndef SECOND
#define SECOND 0
#endif
#ifndef NANOSECOND
#define NANOSECOND 0
#endif
#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);
#endif
#define INCREMENT(variable)\
LOCK(mut_##variable); \
++variable;\
UNLOCK(mut_##variable);
pthread_mutex_t mut_count_pass_global;
pthread_mutex_t mut_count_pass_local;
pthread_mutex_t mut_count_fail_global;
pthread_mutex_t mut_count_fail_local;
struct failed_lists{
char *name;
struct failed_lists *next;
} *failed_l = NULL;
void append_failed_list(const char *name_failed){
static struct failed_lists *failed_static = NULL;
if(failed_static == NULL){
failed_l = malloc(sizeof(struct failed_lists));
failed_l->name = malloc(strlen(name_failed));
strcpy(failed_l->name, name_failed);
failed_l->next = NULL;
failed_static = failed_l;
}
else{
struct failed_lists *tmp = malloc(sizeof(struct failed_lists));
tmp->name = malloc(strlen(name_failed));
strcpy(tmp->name, name_failed);
tmp->next = NULL;
failed_static->next = tmp;
failed_static = tmp;
}
}
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);
}
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);
}
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start){
return 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);
}
size_t count_tests = 0;
size_t count_pass_global = 0;
size_t count_pass_local = 0;
size_t count_fail_global = 0;
size_t count_fail_local = 0;
struct func *f_beging=NULL;
/*
* Tname format name is TEST_name_f____NUM, we extract NUM here
* to have hash_table of the count when parallel test!
*/
size_t extract_num_test__f(char *name_f){
size_t len = strlen(name_f);
size_t val = 0, p = 1;
for(size_t i= len-1; i>=0; --i){
if(name_f[i]=='_') break;
else if(name_f[i] >= '0' && name_f[i] <= '9'){
val += p * (name_f[i]-'0');
}
}
return val;
}
#define EXPECTED_EXPECT_F(expect, not_expect) \
bool expected_##expect##_f(bool val){ \
if(val == expect) { \
INCREMENT(count_pass_local); /*++count_pass_local*/ \
return true; \
}else { \
INCREMENT(count_fail_local); /*++count_fail_local*/ \
return false; \
} \
}
EXPECTED_EXPECT_F(true,false)
EXPECTED_EXPECT_F(false,true)
#define EXPECTED_EQ_TYPE(type) \
bool expected_eq_##type(type var1, type var2){ \
if(COMPARE_N_##type(&var1, &var2) == 0){ \
INCREMENT(count_pass_local); /*++count_pass_local*/ \
return true; \
}else { \
INCREMENT(count_fail_local); /*++count_fail_local*/ \
return false; \
} \
}
EXPECTED_EQ_TYPE(TYPE_CHAR)
EXPECTED_EQ_TYPE(TYPE_U_CHAR)
EXPECTED_EQ_TYPE(TYPE_INT)
EXPECTED_EQ_TYPE(TYPE_U_INT)
EXPECTED_EQ_TYPE(TYPE_L_INT)
EXPECTED_EQ_TYPE(TYPE_U_L_INT)
EXPECTED_EQ_TYPE(TYPE_SIZE_T)
EXPECTED_EQ_TYPE(TYPE_FLOAT)
EXPECTED_EQ_TYPE(TYPE_DOUBLE)
EXPECTED_EQ_TYPE(TYPE_L_DOUBLE)
EXPECTED_EQ_TYPE(TYPE_STRING)
void
append_func(void (*run)(void), char *name){
static struct func *f_static = NULL;
if(f_beging == NULL){
f_beging = malloc(sizeof(struct func));
f_static = f_beging;
f_static->name = malloc(strlen(name));
strcpy(f_static->name,name);
f_static->run = run;
f_static->next = NULL;
}
else{
struct func *tmp = malloc(sizeof(struct func));
tmp->run = run;
tmp->name = malloc(strlen(name));
strcpy(tmp->name,name);
tmp->next = NULL;
f_static->next = tmp;
f_static = tmp;
}
++count_tests;
}
void begin_execute_func(char *fun_ame, struct timespec *start_t){
clock_gettime(CLOCK_REALTIME, start_t);
PRINT_HK_C(GREEN_K,HK_RN," %s\n", fun_ame);
count_pass_local = 0;
count_fail_local = 0;
}
#define PRINT_TIMESTAMP_STAT(color)\
if(SECOND) PRINT_HK_C(color,HK_DN," %lu tests passed from %s (%lf s)\n\n",count_pass_local,fun_ame, diff_timespec_seconds(end_t, start_t));\
else if(NANOSECOND) PRINT_HK_C(color,HK_DN," %lu tests passed from %s (%ld ns)\n\n",count_pass_local,fun_ame, diff_timespec_nanoseconds(end_t, start_t));\
else PRINT_HK_C(color,HK_DN," %lu tests passed from %s (%lf ms)\n\n",count_pass_local,fun_ame, diff_timespec_milliseconds(end_t, start_t));
void end_execute_func(char *fun_ame, struct timespec start_t){
struct timespec end_t; clock_gettime(CLOCK_REALTIME, &end_t);
if(count_fail_local){
INCREMENT(count_fail_global); /*++count_fail_global*/
append_failed_list(fun_ame);
PRINT_HK_C(RED_K, HK_FL, " %lu tests failed from %s\n",count_fail_local,fun_ame);
PRINT_TIMESTAMP_STAT(RED_K);
}
else
{
INCREMENT(count_pass_global); /*++count_pass_global*/
PRINT_TIMESTAMP_STAT(GREEN_K);
}
}
void head_run(size_t nbtest, struct timespec *start_t){
clock_gettime(CLOCK_REALTIME, start_t);
PRINT_HK_C(GREEN_K, HK_EQ," Running %lu tests.\n",nbtest);
}
void list_failed_test(struct failed_lists *failed_lst){
PRINT_HK_C(RED_K, HK_FL," %s\n",failed_lst->name);
if(failed_lst->next) list_failed_test(failed_lst->next);
}
void
stat_end_run(size_t ntst, struct timespec start_t){
struct timespec end_t; clock_gettime(CLOCK_REALTIME, &end_t);
if(SECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran. (%lf s total)\n",ntst, diff_timespec_seconds(end_t, start_t));
else if(NANOSECOND) PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran. (%ld ns total)\n",ntst, diff_timespec_nanoseconds(end_t, start_t));
else PRINT_HK_C(GREEN_K, HK_EQ," %lu tests ran. (%lf ms total)\n",ntst, diff_timespec_milliseconds(end_t, start_t));
PRINT_HK_C(GREEN_K, HK_PS," %lu tests\n", count_pass_global);
if(failed_l != NULL){
PRINT_HK_C(RED_K, HK_FL," %lu tests, listed below:\n",count_fail_global);
list_failed_test(failed_l);
}
}
bool is_in_array(size_t *array, size_t sz, size_t num){
bool found = false;
for(size_t i = 0; i < sz; ++i){
if(array[i] == num){
found = true;
break;
}
}
return found;
}
void execute_all(struct func *fun){
struct func *tmp = fun;
struct timespec start_t;
//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);
tmp = tmp->next;
}
}
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()
{
struct timespec start_t;
head_run(count_tests, &start_t);
execute_all(f_beging);
stat_end_run(count_tests, start_t);
}
/*
*
*/
void execute_div_test(struct func *fun, size_t num){
size_t cur = 0;
struct timespec start_t;
struct func *tmp = fun;
while(tmp){
if(cur %PARALLEL == num){
PRINT_DEBUG("thread N° %ld, cur = %ld , cur%PARA = %ld , funcname = %s \n", num,cur, cur%PARALLEL, tmp->name);
begin_execute_func(tmp->name, &start_t);
tmp->run();
end_execute_func(tmp->name, start_t);
}
tmp = tmp->next;
++cur;
}
}
void*
run_all_div_tests(void *id)
{
size_t id_th=*(size_t*)id;
struct timespec start_t;
head_run(count_tests/PARALLEL, &start_t);
execute_div_test(f_beging, id_th);
stat_end_run(count_tests/PARALLEL, start_t);
}
void run_parallel_tests()
{
pthread_mutex_init(&mut_count_pass_global, NULL);
pthread_mutex_init(&mut_count_pass_local, NULL);
pthread_mutex_init(&mut_count_fail_global, NULL);
pthread_mutex_init(&mut_count_fail_local, NULL);
pthread_t *thrd = malloc(PARALLEL * sizeof(pthread_t));
size_t *id_th = malloc( PARALLEL * sizeof(size_t));
for(size_t i = 0; i < PARALLEL; ++i){
id_th[i]=i;
pthread_create(&thrd[i], NULL, run_all_div_tests, (void*)&id_th[i]);
}
for(size_t i=0; i<PARALLEL; ++i){
pthread_join(thrd[i], NULL);
}
free(id_th);
free(thrd);
pthread_mutex_destroy(&mut_count_pass_global);
pthread_mutex_destroy(&mut_count_pass_local);
pthread_mutex_destroy(&mut_count_fail_global);
pthread_mutex_destroy(&mut_count_fail_local);
}
void
clear_all_func(struct func **fun)
{
struct func *tmp = *fun, *ttmp;
while(tmp != NULL){
ttmp = tmp;
tmp = tmp->next;
free(ttmp);
}
}
/*
* to purge func list!
* optionnal but good practice
*/
void
purge_tests()
{
struct func *tmp = f_beging;
clear_all_func(&tmp);
PRINT_DEBUG("%s\n","purge done");
}
+1 -1
View File
@@ -1,4 +1,4 @@
#include "src/test_t/test_t.h" #include "test_t/test_t.h"
/* /*
#define DEFAULT_K "\033[0m" //Resets the text to default color #define DEFAULT_K "\033[0m" //Resets the text to default color
-129
View File
@@ -1,129 +0,0 @@
#include "src/test_t/test_t.h"
#define CHANGE_TO_DEFAULT_COLOR_IN_TERMINAL printf("\033[0m"); //Resets the text to default color
#define CHANGE_COLOR_TO_GREEN_IN_TERMINAL printf("\033[0;32m"); // Green
#define CHANGE_COLOR_TO_RED_IN_TERMINAL printf("\033[0;31m"); // Red
#define PRINT_HOOK_WITH_EQ_SYMBOLE \
printf("["); for(size_t i = 0; i< SIZE_OK; ++i) printf("="); printf("]");
//static function_list *p_f_l;
function_list *p_f_l;
void
print_OK()
{
CHANGE_COLOR_TO_GREEN_IN_TERMINAL
PRINT_HOOK_WITH_EQ_SYMBOLE
CHANGE_TO_DEFAULT_COLOR_IN_TERMINAL
printf("OK ");
}
void
print_KO()
{
CHANGE_COLOR_TO_GREEN_IN_TERMINAL
PRINT_HOOK_WITH_EQ_SYMBOLE
CHANGE_TO_DEFAULT_COLOR_IN_TERMINAL
printf("KO ");
}
void
print_OK_with_msg(char *msg)
{
print_OK();
printf(" %s ",msg);
}
void
print_KO_with_msg(char *msg)
{
print_KO();
printf(" %s ",msg);
}
void
print_OK_with_msg_endl(char *msg)
{
print_OK();
printf(" %s\n",msg);
}
void
print_KO_with_msg_endl(char *msg)
{
print_KO();
printf(" %s\n", msg);
}
void
run_all_tests()
{
initiation_test();
execute_all_function_list();
clear_fonction_list(&p_f_l);
}
void
append_function_list(void (*f)(void), char *name_function)
{
printf("append %s test\n",name_function);
static size_t counter=0;
function_list * f_l=malloc(sizeof(function_list));
if(f_l)
{
if(f_l->name_function) free(f_l->name_function);
f_l->name_function = malloc(sizeof(char)*strlen(name_function) + 1);
strcpy(f_l->name_function, name_function);
f_l->function_top = f;
f_l->next = NULL;
}
else
{
printf("error allocation f_l\n");
return;
}
if(p_f_l != NULL)
{
function_list *tmp_f_l = p_f_l;
while(tmp_f_l->next)
tmp_f_l = tmp_f_l->next;
tmp_f_l->next = f_l;
}
else p_f_l = f_l;
}
void
execute_all_function_list()
{
printf("run functions tests\n");
function_list * tmp_f_l = p_f_l;
while(tmp_f_l)
{
printf("RUN %s \n",tmp_f_l->name_function);
tmp_f_l->function_top();
tmp_f_l = tmp_f_l->next;
}
}
void
clear_fonction_list(function_list **f_l)
{
if(*f_l != NULL)
{
clear_fonction_list(&((*f_l)->next));
free(*f_l);
*f_l = NULL;
}
}
void
initiation_test()
{
if(p_f_l != NULL)
{
free(p_f_l);
p_f_l=NULL;
}
}
+1 -1
View File
@@ -9,7 +9,7 @@
#include <pthread.h> #include <pthread.h>
//#include <unistd.h> //#include <unistd.h>
#include "src/tools_t/tools_t.h" #include "tools_t/tools_t.h"
#define DEFAULT_K "\033[0m" //Resets the text to default color #define DEFAULT_K "\033[0m" //Resets the text to default color
-55
View File
@@ -1,55 +0,0 @@
#ifndef __TEST_C_H__
#define __TEST_C_H__
#include <stdio.h>
#include <stdlib.h>
#include "src/tools_t/tools_t.h"
#define SIZE_OK 7
/*
size_t COUNT_OK = 0;
size_t COUNT_KO = 0;
size_t COUNT_TEST = 0;
*/
struct function_list{
char * name_function;
void(*function_top)(void);
struct function_list * next;
};
typedef struct function_list function_list;
void clear_fonction_list(function_list **f_l);
void append_function_list(void(*f)(void), char *name_function);
void execute_all_function_list();
void run_all_tests();
void initiation_test();
#define TEST(name_f) \
void test_##name_f(void); \
void append_test_##name_f(void){ \
append_function_list(test_##name_f,#name_f); \
} \
struct STRUCT_##name_f{ \
void (*append)(void); \
} instance_struct_test_##name_f = {append_test_##name_f}; \
void test_##name_f(void)
void print_OK();
void print_KO();
void print_OK_with_msg(char* msg);
void print_KO_with_msg(char *msg);
void print_OK_with_msg_endl(char* msg);
void print_KO_with_msg_endl(char *msg);
#endif /* __TEST_C_H__ */
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
#include "src/tools_t/tools_t.h" #include "tools_t/tools_t.h"
void gotoxy(int x, int y) void gotoxy(int x, int y)
Binary file not shown.