mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 15:39:07 +00:00
Add automatic testing
This commit is contained in:
parent
34a41163bc
commit
c0deaa4952
@ -6,8 +6,6 @@ compiler:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- make test-all
|
- make test-all
|
||||||
- if [[ $(find . -iname *.h -o -iname *.c | xargs clang-format -style=file) ]]; then;
|
- make check-format
|
||||||
echo "Files need formatting.";
|
- make tidy
|
||||||
exit 1;
|
|
||||||
fi;
|
|
||||||
# vim: set ft=yaml ts=2 sw=2 tw=0 et :
|
# vim: set ft=yaml ts=2 sw=2 tw=0 et :
|
||||||
|
84
Makefile
84
Makefile
@ -1,6 +1,17 @@
|
|||||||
# This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE)
|
# This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE)
|
||||||
CFLAGS=-Wall -Wextra -Wpedantic -Werror -std=c99 $(EXTRAFLAGS)
|
CFLAGS=-Wall -Wextra -Wpedantic -Werror -std=c99 $(EXTRAFLAGS)
|
||||||
|
|
||||||
|
ALL_SCHEMES=$(filter-out crypto_%/test.c, $(wildcard crypto_*/*))
|
||||||
|
|
||||||
|
default: help
|
||||||
|
|
||||||
|
.PHONY: require_scheme
|
||||||
|
require_scheme:
|
||||||
|
# assumes a SCHEME variable; e.g. make functest_kem SCHEME=crypto_kem/kyber768
|
||||||
|
ifndef SCHEME
|
||||||
|
$(error The SCHEME variable is not set. Example: SCHEME=crypto_kem/kyber768)
|
||||||
|
endif
|
||||||
|
|
||||||
bin/functest_$(subst /,_,$(SCHEME)): $(dir $(SCHEME))test.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
|
bin/functest_$(subst /,_,$(SCHEME)): $(dir $(SCHEME))test.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
$(CC) $(CFLAGS) \
|
$(CC) $(CFLAGS) \
|
||||||
@ -26,49 +37,70 @@ clean:
|
|||||||
format:
|
format:
|
||||||
find . -iname *.h -o -iname *.c | xargs clang-format -i -style=file
|
find . -iname *.h -o -iname *.c | xargs clang-format -i -style=file
|
||||||
|
|
||||||
|
.PHONY: check-format
|
||||||
|
check-format:
|
||||||
|
@for src in $(SOURCES) ; do \
|
||||||
|
var=`clang-format "$(SRC_DIR)/$$src" | diff "$(SRC_DIR)/$$src" - | wc -l` ; \
|
||||||
|
if [ $$var -ne 0 ] ; then \
|
||||||
|
echo "$$src does not respect the coding style (diff: $$var lines)" ; \
|
||||||
|
exit 1 ; \
|
||||||
|
fi ; \
|
||||||
|
done
|
||||||
|
@echo "Style check passed"
|
||||||
|
|
||||||
.PHONY: tidy
|
.PHONY: tidy
|
||||||
tidy: require_scheme
|
tidy:
|
||||||
|
$(eval undefine .TIDY_FIX)
|
||||||
|
$(MAKE) do-tidy
|
||||||
|
|
||||||
|
do-tidy: require_scheme
|
||||||
clang-tidy \
|
clang-tidy \
|
||||||
|
-quiet $(.TIDY_FIX) \
|
||||||
$(SCHEME)/clean/*.c \
|
$(SCHEME)/clean/*.c \
|
||||||
$(SCHEME)/../test.c \
|
$(SCHEME)/../test.c \
|
||||||
common/*.c \
|
common/*.c \
|
||||||
$(.TIDY_FIX) \
|
|
||||||
-- -iquote "common/" -iquote "$(SCHEME)/clean"
|
-- -iquote "common/" -iquote "$(SCHEME)/clean"
|
||||||
|
|
||||||
.PHONY: fix-tidy
|
.PHONY: apply-tidy
|
||||||
apply-tidy: | $(eval .TIDY_FIX = -fix) tidy
|
apply-tidy:
|
||||||
|
$(MAKE) do-tidy .TIDY_FIX=-fix
|
||||||
|
|
||||||
|
# The below should be outlined with ts=8
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help:
|
help:
|
||||||
@echo make functest SCHEME=scheme run functional tests for SCHEME
|
@echo "make functest SCHEME=scheme Build functional tests for SCHEME"
|
||||||
@echo make clean clean up the bin/ folder
|
@echo "make run-functest SCHEME=scheme Run functional tests for SCHEME"
|
||||||
@echo make format Automatically formats all the source code
|
@echo "make run-functest-all Run all functests"
|
||||||
@echo make tidy SCHEME=scheme Runs the clang-tidy linter against SCHEME
|
@echo "make clean Clean up the bin/ folder"
|
||||||
@echo make fix-tidy SCHEME=scheme Tries to automatically fix the issues found by clang-tidy in SCHEME
|
@echo "make format Automatically formats all the source code"
|
||||||
@echo make help Displays this message
|
@echo "make tidy SCHEME=scheme Runs the clang-tidy linter against SCHEME"
|
||||||
|
@echo "make apply-tidy SCHEME=scheme Tries to automatically fix the issues found by clang-tidy in SCHEME"
|
||||||
|
@echo "make tidy-all Runs the clang-tidy linter against all schemes"
|
||||||
|
@echo "make apply-tidy-all Tidy up all schemes"
|
||||||
|
@echo "make help Displays this message"
|
||||||
|
|
||||||
.PHONY: require_scheme
|
.PHONY: functest-all
|
||||||
require_scheme:
|
build-functests: $(foreach skeme,$(ALL_SCHEMES),bin/functest_$(subst /,_,$(skeme)))
|
||||||
# assumes a SCHEME variable; e.g. make functest_kem SCHEME=crypto_kem/kyber768
|
|
||||||
ifndef SCHEME
|
|
||||||
$(error The SCHEME variable is not set. Example: SCHEME=crypto_kem/kyber768)
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: build-functests
|
.PHONY: run-functest-all
|
||||||
build-functests:
|
run-functest-all: build-functests
|
||||||
find crypto_kem/ crypto_sign/ -mindepth 1 -maxdepth 1 -type d -exec make functest SCHEME={} \;
|
@for functest in bin/functest_* ; do \
|
||||||
|
echo ./$$functest ; \
|
||||||
.PHONY: run-functests
|
./$$functest ; \
|
||||||
run-functests:
|
done
|
||||||
find crypto_kem/ crypto_sign/ -mindepth 1 -maxdepth 1 -type d -exec make run-functest SCHEME={} \;
|
@echo Tests completed
|
||||||
|
|
||||||
.PHONY: test-all
|
.PHONY: test-all
|
||||||
test-all: run-functests
|
test-all: run-functests
|
||||||
|
|
||||||
.PHONY: tidy-all
|
.PHONY: tidy-all
|
||||||
tidy-all:
|
tidy-all:
|
||||||
find crypto_kem/ crypto_sign/ -mindepth 1 -maxdepth 1 -type d -exec make tidy SCHEME={} \;
|
@for scheme in $(ALL_SCHEMES); do \
|
||||||
|
$(MAKE) tidy SCHEME=$$scheme; \
|
||||||
|
done
|
||||||
|
|
||||||
.PHONY: applytidy-all
|
.PHONY: apply-tidy-all
|
||||||
apply-tidy-all:
|
apply-tidy-all:
|
||||||
find crypto_kem/ crypto_sign/ -mindepth 1 -maxdepth 1 -type d -exec make apply-tidy SCHEME={} \;
|
@for scheme in $(ALL_SCHEMES); do \
|
||||||
|
$(MAKE) apply-tidy SCHEME=$$scheme; \
|
||||||
|
done
|
||||||
|
@ -16,7 +16,8 @@ static int check_canary(const unsigned char *d) {
|
|||||||
if (*(uint64_t *)d != 0x0123456789ABCDEF) {
|
if (*(uint64_t *)d != 0x0123456789ABCDEF) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
{ return 0; }
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_keys(void) {
|
static int test_keys(void) {
|
||||||
|
@ -102,9 +102,8 @@ uint32_t use_hint(const uint32_t a, const unsigned int hint) {
|
|||||||
}
|
}
|
||||||
if (a0 > Q) {
|
if (a0 > Q) {
|
||||||
return (a1 + 1) & 0xF;
|
return (a1 + 1) & 0xF;
|
||||||
} else {
|
|
||||||
return (a1 - 1) & 0xF;
|
|
||||||
}
|
}
|
||||||
|
return (a1 - 1) & 0xF;
|
||||||
|
|
||||||
/* If decompose does not divide out ALPHA:
|
/* If decompose does not divide out ALPHA:
|
||||||
if(hint == 0)
|
if(hint == 0)
|
||||||
|
@ -17,6 +17,7 @@ static int check_canary(const unsigned char *d) {
|
|||||||
if (*(uint64_t *)d != 0x0123456789ABCDEF) {
|
if (*(uint64_t *)d != 0x0123456789ABCDEF) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int test_sign(void) {
|
static int test_sign(void) {
|
||||||
|
Loading…
Reference in New Issue
Block a user