Added testing targets

This commit is contained in:
saundersp
2024-07-22 22:03:30 +02:00
parent 1ec28f78de
commit 95eaffda4d
6 changed files with 171 additions and 108 deletions

View File

@ -3,7 +3,7 @@ FROM nvidia/cuda:12.5.0-devel-ubi9 as builder
WORKDIR /home/ViolaJones/cpp
COPY *.cu *.cpp *.hpp Makefile ./
RUN make -j "$(nproc)"
RUN make -j "$(nproc)" && make -j "$(nproc)" ./bin/ViolaJonesTest
FROM nvidia/cuda:12.5.0-base-ubi9

View File

@ -10,8 +10,10 @@ CFLAGS := -dlto -O2 -Xcompiler -O2
#CFLAGS := -dlto -O2 -g -Xcompiler -O2,-g,-ggdb
CFLAGS := $(CFLAGS) -MMD -MP -Werror=all-warnings -Xcompiler -Wall,-Werror,-Wextra
EXEC := $(OBJ_DIR)/ViolaJones
EXEC_TEST := $(OBJ_DIR)/ViolaJonesTest
DATA := $(DATA_PATH)/X_train.bin $(DATA_PATH)/X_test.bin $(DATA_PATH)/y_train.bin $(DATA_PATH)/y_test.bin
SRC := $(shell find $(SRC_DIR) -name '*.cpp' -o -name '*.cu')
SRC := $(shell find $(SRC_DIR) \( -name '*.cpp' -o -name '*.cu' \) -and -not -name projet_test.cpp)
SRC_TEST := $(shell find $(SRC_DIR) \( -name '*.cpp' -o -name '*.cu' \) -and -not -name projet.cpp)
OBJ_EXT := o
ifeq ($(OS), Windows_NT)
EXEC := $(EXEC).exe
@ -19,6 +21,8 @@ ifeq ($(OS), Windows_NT)
endif
OBJ := $(SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.$(OBJ_EXT))
OBJ := $(OBJ:$(SRC_DIR)/%.cu=$(OBJ_DIR)/%.$(OBJ_EXT))
OBJ_TEST := $(SRC_TEST:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.$(OBJ_EXT))
OBJ_TEST := $(OBJ_TEST:$(SRC_DIR)/%.cu=$(OBJ_DIR)/%.$(OBJ_EXT))
.PHONY: all
all: $(EXEC)
@ -42,6 +46,12 @@ $(EXEC): $(OBJ)
@echo Linking objects files to $@
@$(CC) $(CFLAGS) $^ -o $@
# FIXME When using the docker image, Make check prequisites even when the target already exists
#$(EXEC_TEST): $(OBJ_TEST) | check-nvcc-works
$(EXEC_TEST): $(OBJ_TEST)
@echo Linking objects files to $@
@$(CC) $(CFLAGS) $^ -o $@
$(DATA):
@echo 'Missing $(DATA) files, use downloader first' && exit 1
@ -49,6 +59,10 @@ $(DATA):
start: $(EXEC) $(DATA)
@./$(EXEC)
.PHONY: test
test: $(EXEC_TEST)
@./$(EXEC_TEST)
.PHONY: debug
debug: $(EXEC) $(DATA)
#@cuda-gdb -q $(EXEC)

31
cpp/projet_test.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "toolbox.hpp"
#include "config.hpp"
#include "toolbox_unit_test.hpp"
#include "ViolaJones.hpp"
#if GPU_BOOSTED
#include "gpu_unit_test.hpp"
#endif
int32_t main(void){
setlocale(LC_NUMERIC, ""); // Allow proper number display
const std::chrono::system_clock::time_point unit_timestamp = perf_counter_ns();
const std::array<int32_t, 3> unit_gaps = { 27, -18, 29 };
header(unit_gaps, { "Unit testing", "Time spent (ns)", "Formatted time spent" });
#if GPU_BOOSTED
benchmark_function_void("Testing GPU capabilities 1D", unit_gaps[0], test_working, 50000);
benchmark_function_void("Testing GPU capabilities 2D", unit_gaps[0], test_working_2d, 200, 500);
benchmark_function_void("Testing GPU capabilities 3D", unit_gaps[0], test_working_3d, 30, 40, 500);
#endif
benchmark_function_void("Testing format_time", unit_gaps[0], format_time_test);
benchmark_function_void("Testing format_time_ns", unit_gaps[0], format_time_ns_test);
benchmark_function_void("Testing format_byte_size", unit_gaps[0], format_byte_size_test);
benchmark_function_void("Testing thousand_sep", unit_gaps[0], thousand_sep_test);
const long long time_spent = duration_ns(perf_counter_ns() - unit_timestamp);
formatted_line(unit_gaps, "", "", "", "");
formatted_row(unit_gaps, { "Unit testing summary", thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str() });
footer(unit_gaps);
return EXIT_SUCCESS;
}