clean up and add Makefile
This commit is contained in:
@@ -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,7 +1,7 @@
|
||||
#ifndef __COORDINATE_C__H__
|
||||
#define __COORDINATE_C__H__
|
||||
|
||||
#include "src/dimension/dimension.h"
|
||||
#include "dimension/dimension.h"
|
||||
|
||||
|
||||
struct coordinate
|
||||
|
||||
@@ -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"
|
||||
|
||||
/*void dimension::initDim(int* arr, bool end = true) {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <windows.h>
|
||||
#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){
|
||||
PRINTF("another size_permutation2 again\n");
|
||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
#include "src/permutation_t/permutation_t.h"
|
||||
#include "permutation_t/permutation_t.h"
|
||||
|
||||
#define GENERATE_PERMUTATION_FUNCTIONS_UNSIGNED(type)\
|
||||
bool IS_PERMUTATION_SET_THEORIC_##type(const PERMUTATION_##type *p){\
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef __PERMUTATION_T_C_H__
|
||||
#define __PERMUTATION_T_C_H__
|
||||
|
||||
#include "src/tools_t/tools_t.h"
|
||||
#include "src/set_theoric_t/set_theoric_t.h"
|
||||
#include "tools_t/tools_t.h"
|
||||
#include "set_theoric_t/set_theoric_t.h"
|
||||
|
||||
/* struct of permutation, not necessarly set_theoric
|
||||
*
|
||||
|
||||
Binary file not shown.
@@ -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) \
|
||||
SET_THEORIC_##type * CREATE_SET_THEORIC_##type(size_t id){ \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "src/tools_t/tools_t.h"
|
||||
#include "tools_t/tools_t.h"
|
||||
|
||||
#define GENERATE_UNSIGNED_SET_THEORIC(type) \
|
||||
struct SET_THEORIC_##type{ \
|
||||
|
||||
Binary file not shown.
@@ -7,14 +7,14 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tens0neD/tens0neD.h"
|
||||
#include "src/tensor/tens0neD/tens0neD.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/tensor/tens0neD/tens0neD.h"
|
||||
#include "tensor/tens0neD/tens0neD.h"
|
||||
//#include "include/tens0neD.h"
|
||||
|
||||
|
||||
//#include "cudatensor.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/permutation/permutation.h"
|
||||
#include "src/permutation/permutation.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/permutation/permutation.h"
|
||||
#include "permutation/permutation.h"
|
||||
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
//#include "tensor.h"
|
||||
//#include "cudatensor.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/dimension/dimension.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/permutation/permutation.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/tensCuda.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/dimension/dimension.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/permutation/permutation.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/tensCuda.h"
|
||||
|
||||
#include "src/dimension/dimension.h"
|
||||
#include "src/permutation/permutation.h"
|
||||
#include "src/tensor/tensCuda/tensCuda.h"
|
||||
#include "dimension/dimension.h"
|
||||
#include "permutation/permutation.h"
|
||||
#include "tensor/tensCuda/tensCuda.h"
|
||||
|
||||
template<typename T>
|
||||
struct Tensor {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
//#include "cuda_device_runtime_api.h"
|
||||
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/d_tensCuda.h"
|
||||
#include "src/tensor/tensCuda/d_tensCuda.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/d_tensCuda.h"
|
||||
#include "tensor/tensCuda/d_tensCuda.h"
|
||||
|
||||
|
||||
//#1D grid of 1D blocks
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#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 "src/tensor/tensCuda/tensCuda.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/tensCuda.h"
|
||||
#include "tensor/tensCuda/tensCuda.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tens0neD/tens0neD.h"
|
||||
#include "src/tensor/tens0neD/tens0neD.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/tensor/tens0neD/tens0neD.h"
|
||||
#include "tensor/tens0neD/tens0neD.h"
|
||||
|
||||
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/d_tensCuda.h"
|
||||
#include "src/tensor/tensCuda/d_tensCuda.h"
|
||||
//#include "src/dimension/dimension.h"
|
||||
//#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/d_tensCuda.h"
|
||||
#include "tensor/tensCuda/d_tensCuda.h"
|
||||
//#include "dimension/dimension.h"
|
||||
|
||||
template<typename T>
|
||||
struct Tensor;
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -9,7 +9,7 @@
|
||||
#include <pthread.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
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
#include "src/tools_t/tools_t.h"
|
||||
#include "tools_t/tools_t.h"
|
||||
|
||||
|
||||
void gotoxy(int x, int y)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user