improve tests, add coverage make target

This commit is contained in:
Steffen Jaeckel 2017-04-08 21:58:12 +02:00
parent df82859cc8
commit c2d5fbfd0e
4 changed files with 70 additions and 3 deletions

6
.gitignore vendored
View File

@ -15,6 +15,12 @@
/.libs
test_*.txt
*.gcda
*.gcno
*.info
coverage/
compat_reports/
test
test.exe
mtest

View File

@ -427,6 +427,9 @@ draw(&a);draw(&b);draw(&c);draw(&d);
printf("d == %lu\n", ix);
return 0;
}
} else if (!strcmp(cmd, "exit")) {
printf("\nokay, exiting now\n");
return 0;
}
}

View File

@ -141,6 +141,9 @@ test_standalone: CFLAGS+=-DTFM_DEMO_TEST_VS_MTEST=0
test_standalone: $(LIBNAME) demo/test.o
$(CC) $(CFLAGS) demo/test.o $(LIBNAME) $(PROF) -o test
testme: test mtest
./mtest/mtest -15 | ./test
timing: $(LIBNAME) demo/timing.o
$(CC) $(CFLAGS) demo/timing.o $(LIBNAME) $(PROF) -o timing
@ -151,7 +154,33 @@ profiled:
rm -f `find . -type f -name "*.a" | xargs`
rm -f test
CC=$(CC) PREFIX="${PREFIX} CFLAGS="${CFLAGS} -fprofile-use" MAKE=${MAKE} ${MAKE} timing
# target that pre-processes all coverage data
lcov-single-create:
lcov --capture --no-external --directory src -q --output-file coverage_std.info
# target that removes all coverage output
cleancov-clean:
rm -f `find . -type f -name "*.info" | xargs`
rm -rf coverage/
# generates html output from all coverage_*.info files
lcov:
lcov `find -name 'coverage_*.info' -exec echo -n " -a {}" \;` -o coverage.info -q 2>/dev/null
genhtml coverage.info --output-directory coverage
# combines all necessary steps to create the coverage from a single testrun with e.g.
lcov-single: | cleancov-clean lcov-single-create lcov
#make the code coverage of the library
coverage: CFLAGS += -fprofile-arcs -ftest-coverage
coverage: LDFLAGS += -lgcov
coverage: LIB_PRE = -Wl,--whole-archive
coverage: LIB_POST = -Wl,--no-whole-archive
coverage: | testme lcov-single
stest: $(LIBNAME) demo/stest.o
$(CC) $(CFLAGS) demo/stest.o $(LIBNAME) -o stest

View File

@ -38,7 +38,6 @@ mulmod
#include <stdlib.h>
#include <time.h>
#include <tommath.h>
#define CRYPT
#undef DIGIT_BIT
#include "../src/headers/tfm.h"
@ -72,8 +71,9 @@ void rand_num2(mp_int *a)
#define mp_to64(a, b) mp_toradix_n(a, b, 64, sizeof(b))
int main(void)
int main(int argc, char *argv[])
{
long long max;
int n, tmp;
mp_int a, b, c, d, e;
#ifdef MTEST_NO_FULLSPEED
@ -88,6 +88,27 @@ int main(void)
mp_init(&e);
if (argc > 1) {
max = strtol(argv[1], NULL, 0);
printf("%lld\n", max);
if (max < 0) {
max = -max;
printf("%lld\n", max);
if (max < 64) {
unsigned long long m = (1ULL << (max)) + 1;
max = (long long)m;
} else {
max = 1;
}
printf("%lld\n", max);
} else if (max == 0) {
max = 1;
}
}
else {
max = 0;
}
/* initial (2^n - 1)^2 testing, makes sure the comba multiplier works [it has the new carry code] */
/*
mp_set(&a, 1);
@ -125,6 +146,11 @@ int main(void)
}
#endif
n = fgetc(rng) % 16;
if (max != 0) {
--max;
if (max == 0)
n = 255;
}
if (n == 0) {
/* add tests */
rand_num(&a);
@ -318,6 +344,9 @@ int main(void)
printf("%s\n%d\n", buf, tmp);
mp_to64(&b, buf);
printf("%s\n", buf);
} else if (n == 255) {
printf("exit\n");
break;
}
}
fclose(rng);