From b88a3d0cc85c9e0173f945875f74cd9ff5105f16 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 28 Aug 2017 23:39:50 +0200 Subject: Add basic test Makefile. --- test/src/Makefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/src/Makefile (limited to 'test/src') diff --git a/test/src/Makefile b/test/src/Makefile new file mode 100644 index 0000000..e22dcd3 --- /dev/null +++ b/test/src/Makefile @@ -0,0 +1,27 @@ +#### +# +# ecgen, tool for generating Elliptic curve domain parameters +# Copyright (C) 2017 J08nY +# +#### + + +CC ?= gcc +CFLAGS = -Wall -g -O0 +LDFLAGS = -L../../lib/parson -L../../lib/sha1 -L../../lib/pari -L../lib/criterion/build +INCLUDES = -I. -I../../lib -I../lib/criterion/include +LIBS = -lrt -lpari -lpthread -lparson -lsha1 -lcriterion + +TEST_SRC = $(wildcard *.c) $(wildcard */*.c) +TEST_OBJ = $(patsubst %.c,%.o, $(TEST_SRC)) +TESTS = $(patsubst %.c,%, $(TEST_SRC)) + +all: test_ecgen + LD_LIBRARY_PATH=../lib/criterion/build ./test_ecgen + +test_ecgen: $(TEST_OBJ) + $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS) + +%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + -- cgit v1.3.1 From 61df4c7b7fe27497cd2076e09f40d8c8a6223ed2 Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 14:38:17 +0200 Subject: Add Makefiles and CMakelists for tests. --- CMakeLists.txt | 8 +++++--- Makefile | 8 ++++++-- test/CMakeLists.txt | 17 +++++++++++++++++ test/Makefile | 4 +++- test/src/Makefile | 7 +++++-- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 test/CMakeLists.txt (limited to 'test/src') diff --git a/CMakeLists.txt b/CMakeLists.txt index b696f5e..a13030d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 2.8.11) project(ecgen C) set(CMAKE_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/lib) -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -g -Wall -Werror -pedantic") -SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG -O3 -Wall") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -g -Wall -Werror -pedantic") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG -O3 -Wall") include_directories(src) include_directories(lib) @@ -19,4 +19,6 @@ add_executable(ecgen ${ECGEN_SRC}) add_executable(econvert ${ECONVERT_SRC}) target_link_libraries(ecgen pthread rt pari ${parson} ${sha1}) -target_link_libraries(econvert pthread rt pari ${parson} ${sha1}) \ No newline at end of file +target_link_libraries(econvert pthread rt pari ${parson} ${sha1}) + +add_subdirectory(test) \ No newline at end of file diff --git a/Makefile b/Makefile index 9a3a880..a4a5238 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ docs: test: all +$(MAKE) -C test test +unittest: all + +$(MAKE) -C test unittest + help: @echo "ecgen, tool for generating Elliptic curve domain parameters" @echo @@ -33,14 +36,15 @@ help: @echo " - econvert : build the format conversion binary" @echo " - docs : generate doxygen docs" @echo " - test : test the main binary" + @echo " - unittest : " @echo " - clean : cleans up after a build" @echo " - clean-all : cleans all" @echo " - format : run clang-format on source files" @echo " - help : print this help" -.PHONY: all clean clean-all docs test help +.PHONY: all clean clean-all docs test unittest help -ifeq (, $(filter all clean clean-all docs test help, $(MAKECMDGOALS))) +ifeq (, $(filter all clean clean-all docs test unittest help, $(MAKECMDGOALS))) # Just pass all targets to a Makefile in src $(MAKECMDGOALS): +$(MAKE) -C src $@ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..3def321 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.11) +project(test_ecgen C) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/criterion/include) + +message("${CMAKE_LIBRARY_PATH}") + +find_library(criterion NAMES criterion PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/criterion/build) + +file(GLOB TEST_SRC "src/math/*.c" "src/gen/*.c" "src/cm/*.c" "src/invalid/*.c" "src/io/*.c" "src/exhaustive/*.c" "src/util/*.c") +add_executable(test_ecgen ${TEST_SRC} ${SRC}) + +target_link_libraries(test_ecgen pthread rt pari ${parson} ${sha1} ${criterion}) + +enable_testing() +add_test(NAME test_ecgen COMMAND test_ecgen) \ No newline at end of file diff --git a/test/Makefile b/test/Makefile index abb836f..8c5fd8b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,7 +5,9 @@ # #### -test: unit ecgen econvert +test: ecgen econvert + +unittest: unit ecgen econvert unit: cd lib/criterion && mkdir -p build && cd build && cmake .. && cmake --build . diff --git a/test/src/Makefile b/test/src/Makefile index e22dcd3..e9d3d8e 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -9,17 +9,20 @@ CC ?= gcc CFLAGS = -Wall -g -O0 LDFLAGS = -L../../lib/parson -L../../lib/sha1 -L../../lib/pari -L../lib/criterion/build -INCLUDES = -I. -I../../lib -I../lib/criterion/include +INCLUDES = -I. -I../../src -I../../lib -I../lib/criterion/include LIBS = -lrt -lpari -lpthread -lparson -lsha1 -lcriterion TEST_SRC = $(wildcard *.c) $(wildcard */*.c) TEST_OBJ = $(patsubst %.c,%.o, $(TEST_SRC)) TESTS = $(patsubst %.c,%, $(TEST_SRC)) +ECGEN_SRC = $(wildcard ../../src/*/*.c) +ECGEN_OBJ = $(patsubst %.c,%.o, $(ECGEN_SRC)) + all: test_ecgen LD_LIBRARY_PATH=../lib/criterion/build ./test_ecgen -test_ecgen: $(TEST_OBJ) +test_ecgen: $(TEST_OBJ) $(ECGEN_OBJ) $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS) %.o: %.c -- cgit v1.3.1 From 3da8316ca3edf81cb17e19551d9499855d52905c Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 14:53:36 +0200 Subject: Add first working test. --- Makefile | 1 + src/math/subgroups.c | 2 +- test/Makefile | 8 ++++++-- test/src/Makefile | 8 ++++++++ test/src/math/test_subgroups.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 test/src/math/test_subgroups.c (limited to 'test/src') diff --git a/Makefile b/Makefile index a4a5238..33c5765 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ clean: clean-all: +$(MAKE) -C lib clean +$(MAKE) -C src clean-all + +$(MAKE) -C test clean-all rm -rf *.gcov rm -rf doc/* diff --git a/src/math/subgroups.c b/src/math/subgroups.c index 903401e..3b84d5c 100644 --- a/src/math/subgroups.c +++ b/src/math/subgroups.c @@ -61,7 +61,7 @@ static GEN subgroups_exponents(GEN order) { GEN subgroups_prime(const curve_t *curve, const config_t *cfg) { if (cfg->prime || isprime(curve->order)) { - return gtovec(curve->order); + return gtocol(curve->order); } else { return subgroups_factors(curve->order); } diff --git a/test/Makefile b/test/Makefile index 8c5fd8b..c39baac 100644 --- a/test/Makefile +++ b/test/Makefile @@ -11,10 +11,14 @@ unittest: unit ecgen econvert unit: cd lib/criterion && mkdir -p build && cd build && cmake .. && cmake --build . - $(MAKE) -C src all + +$(MAKE) -C src all ecgen: ./ecgen.sh econvert: - ./econvert.sh \ No newline at end of file + ./econvert.sh + +clean-all: + cd lib/criterion && rm -r build + +$(MAKE) -C src clean-all \ No newline at end of file diff --git a/test/src/Makefile b/test/src/Makefile index e9d3d8e..04279be 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -28,3 +28,11 @@ test_ecgen: $(TEST_OBJ) $(ECGEN_OBJ) %.o: %.c $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +clean-all: clean + rm -f ./test_ecgen + +clean: + find . -type f -name '*.o' -exec rm {} + + find . -type f -name '*.gcda' -exec rm {} + + find . -type f -name '*.gcno' -exec rm {} + + find . -type f -name '*.gcov' -exec rm {} + diff --git a/test/src/math/test_subgroups.c b/test/src/math/test_subgroups.c new file mode 100644 index 0000000..fa81788 --- /dev/null +++ b/test/src/math/test_subgroups.c @@ -0,0 +1,31 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include "gen/types.h" +#include "math/subgroups.h" +#include + +void setup(void) { + pari_init(1000000000, 1000000); +} + +TestSuite(subgroups, .init=setup); + +Test(subgroups, test_prime_factors) { + curve_t curve = {.order = stoi(12)}; + config_t cfg = {.prime = false}; + GEN divs = subgroups_prime(&curve, &cfg); + GEN vec = gtocol0(gen_0, 2); + gel(vec, 1) = stoi(2); + gel(vec, 2) = stoi(3); + cr_assert(gequal(divs, vec), "Factors not equal!"); +} + +Test(subgroups, test_prime_prime) { + curve_t curve = {.order = stoi(5)}; + config_t cfg = {.prime = true}; + GEN divs = subgroups_prime(&curve, &cfg); + GEN vec = gtocol(stoi(5)); + cr_assert(gequal(divs, vec), "Factors not equal!"); +} \ No newline at end of file -- cgit v1.3.1 From cbfd158745c345529631ceb168657bd5c46aebaf Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 15:05:11 +0200 Subject: Fix unittest target with TEST=1. --- test/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/src') diff --git a/test/src/Makefile b/test/src/Makefile index 04279be..d22e37e 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -7,7 +7,7 @@ CC ?= gcc -CFLAGS = -Wall -g -O0 +CFLAGS = -Wall --coverage -g -O0 LDFLAGS = -L../../lib/parson -L../../lib/sha1 -L../../lib/pari -L../lib/criterion/build INCLUDES = -I. -I../../src -I../../lib -I../lib/criterion/include LIBS = -lrt -lpari -lpthread -lparson -lsha1 -lcriterion -- cgit v1.3.1 From a826785b6d421057c11fc36cc52ce85a20af32f4 Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 15:14:51 +0200 Subject: Fix some test/src/Makefile CFLAGS. --- test/src/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/src') diff --git a/test/src/Makefile b/test/src/Makefile index d22e37e..27e6ea2 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -7,7 +7,11 @@ CC ?= gcc -CFLAGS = -Wall --coverage -g -O0 +CFLAGS = -Wall +TEST ?= 0 +ifeq ($(TEST), 1) + CFLAGS += --coverage -g -O0 +endif LDFLAGS = -L../../lib/parson -L../../lib/sha1 -L../../lib/pari -L../lib/criterion/build INCLUDES = -I. -I../../src -I../../lib -I../lib/criterion/include LIBS = -lrt -lpari -lpthread -lparson -lsha1 -lcriterion -- cgit v1.3.1 From 4b5d03eda289aa477e693cad8b598a398bb7e04c Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 16:57:31 +0200 Subject: Refactor test setup. --- test/CMakeLists.txt | 5 ++--- test/src/math/test_subgroups.c | 7 ++----- test/src/test/utils.c | 14 ++++++++++++++ test/src/test/utils.h | 12 ++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 test/src/test/utils.c create mode 100644 test/src/test/utils.h (limited to 'test/src') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3def321..066defb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,12 +4,11 @@ project(test_ecgen C) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/criterion/include) -message("${CMAKE_LIBRARY_PATH}") - find_library(criterion NAMES criterion PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/criterion/build) file(GLOB TEST_SRC "src/math/*.c" "src/gen/*.c" "src/cm/*.c" "src/invalid/*.c" "src/io/*.c" "src/exhaustive/*.c" "src/util/*.c") -add_executable(test_ecgen ${TEST_SRC} ${SRC}) +file(GLOB TESTING_SRC "src/test/*.c") +add_executable(test_ecgen ${TEST_SRC} ${TESTING_SRC} ${SRC}) target_link_libraries(test_ecgen pthread rt pari ${parson} ${sha1} ${criterion}) diff --git a/test/src/math/test_subgroups.c b/test/src/math/test_subgroups.c index fa81788..ad42282 100644 --- a/test/src/math/test_subgroups.c +++ b/test/src/math/test_subgroups.c @@ -5,12 +5,9 @@ #include "gen/types.h" #include "math/subgroups.h" #include +#include "test/utils.h" -void setup(void) { - pari_init(1000000000, 1000000); -} - -TestSuite(subgroups, .init=setup); +TestSuite(subgroups, .init=default_setup, .fini=default_teardown); Test(subgroups, test_prime_factors) { curve_t curve = {.order = stoi(12)}; diff --git a/test/src/test/utils.c b/test/src/test/utils.c new file mode 100644 index 0000000..a8a11db --- /dev/null +++ b/test/src/test/utils.c @@ -0,0 +1,14 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include "utils.h" +#include + +void default_setup(void) { + pari_init(1000000, 1000000); +} + +void default_teardown(void) { + pari_close(); +} \ No newline at end of file diff --git a/test/src/test/utils.h b/test/src/test/utils.h new file mode 100644 index 0000000..2780bd2 --- /dev/null +++ b/test/src/test/utils.h @@ -0,0 +1,12 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#ifndef ECGEN_UTILS_H +#define ECGEN_UTILS_H + +void default_setup(void); + +void default_teardown(void); + +#endif //ECGEN_UTILS_H -- cgit v1.3.1