From f8d64c645abfd46f3ad8199f9819f520eabeb1b4 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 10 Sep 2019 16:05:27 +0200 Subject: [PATCH] create `mtest_opponent` instead of alt version of `test` --- .gitignore | 2 ++ README.md | 13 +++++++++---- demo/{opponent.c => mtest_opponent.c} | 9 ++++++++- demo/{main.c => shared.c} | 10 +--------- demo/shared.h | 5 +---- demo/test.c | 9 ++++++++- makefile | 7 +++++-- makefile.mingw | 9 +++++---- makefile.msvc | 9 +++++---- makefile.shared | 7 +++++-- makefile.unix | 7 ++++--- makefile_include.mk | 2 -- testme.sh | 8 ++++---- 13 files changed, 57 insertions(+), 40 deletions(-) rename demo/{opponent.c => mtest_opponent.c} (99%) rename demo/{main.c => shared.c} (81%) diff --git a/.gitignore b/.gitignore index 224c38f..d39d275 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,8 @@ test test.exe mtest mtest.exe +mtest_opponent +mtest_opponent.exe # ignore eclipse project files .cproject diff --git a/README.md b/README.md index 70e015d..be5b207 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,20 @@ API/ABI changes: [check here](https://abi-laboratory.pro/tracker/timeline/libtom The `develop` branch contains the in-development version. Stable releases are tagged. -Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`. There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used. +Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`. +There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used. -The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`, there are several other build targets, see the makefile for details. There are also makefiles for certain specific platforms. +The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`, +there are several other build targets, see the makefile for details. +There are also makefiles for certain specific platforms. ## Testing Tests are located in `demo/` and can be built in two flavors. -* `make test` creates a test binary that is intended to be run against `mtest`. `mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./test`. `mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm -* `make test_standalone` creates a stand-alone test binary that executes several test routines. +* `make test` creates a stand-alone test binary that executes several test routines. +* `make mtest_opponent` creates a test binary that is intended to be run against `mtest`. + `mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./mtest_opponent`. + `mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm ## Building and Installing diff --git a/demo/opponent.c b/demo/mtest_opponent.c similarity index 99% rename from demo/opponent.c rename to demo/mtest_opponent.c index dc0893c..5e8d770 100644 --- a/demo/opponent.c +++ b/demo/mtest_opponent.c @@ -17,7 +17,7 @@ static void draw(mp_int *a) if (!ret) { fprintf(stderr, "\n%d: fgets failed\n", __LINE__); goto LBL_ERR; } \ } -int mtest_opponent(void) +static int mtest_opponent(void) { char cmd[4096]; char buf[4096]; @@ -394,3 +394,10 @@ LBL_ERR: printf("\n"); return EXIT_FAILURE; } + +int main(void) +{ + print_header(); + + return mtest_opponent(); +} diff --git a/demo/main.c b/demo/shared.c similarity index 81% rename from demo/main.c rename to demo/shared.c index b2e670d..2e2b1f9 100644 --- a/demo/main.c +++ b/demo/shared.c @@ -1,8 +1,5 @@ #include "shared.h" -int mtest_opponent(void); -int unit_tests(int argc, char **argv); - void ndraw(mp_int *a, const char *name) { char *buf; @@ -24,7 +21,7 @@ void ndraw(mp_int *a, const char *name) free(buf); } -int main(int argc, char **argv) +void print_header(void) { #ifdef MP_8BIT printf("Digit size 8 Bit \n"); @@ -42,9 +39,4 @@ int main(int argc, char **argv) printf("Size of mp_word: %u\n", (unsigned int)sizeof(mp_word)); printf("MP_DIGIT_BIT: %d\n", MP_DIGIT_BIT); printf("MP_PREC: %d\n", MP_PREC); - - if (LTM_DEMO_TEST_VS_MTEST) { - return mtest_opponent(); - } - return unit_tests(argc, argv); } diff --git a/demo/shared.h b/demo/shared.h index 872465d..4d5eb53 100644 --- a/demo/shared.h +++ b/demo/shared.h @@ -5,10 +5,6 @@ /* * Configuration */ -#ifndef LTM_DEMO_TEST_VS_MTEST -#define LTM_DEMO_TEST_VS_MTEST 1 -#endif - #ifndef LTM_DEMO_TEST_REDUCE_2K_L /* This test takes a moment so we disable it by default, but it can be: * 0 to disable testing @@ -22,3 +18,4 @@ #include "tommath_private.h" extern void ndraw(mp_int* a, const char* name); +extern void print_header(void); diff --git a/demo/test.c b/demo/test.c index 79cfb38..99a5fa7 100644 --- a/demo/test.c +++ b/demo/test.c @@ -2214,7 +2214,7 @@ LTM_ERR: return EXIT_FAILURE; } -int unit_tests(int argc, char **argv) +static int unit_tests(int argc, char **argv) { static const struct { const char *name; @@ -2304,3 +2304,10 @@ int unit_tests(int argc, char **argv) if (fail != 0) return EXIT_FAILURE; else return EXIT_SUCCESS; } + +int main(int argc, char **argv) +{ + print_header(); + + return unit_tests(argc, argv); +} diff --git a/makefile b/makefile index 89d2b3b..4c6997a 100644 --- a/makefile +++ b/makefile @@ -95,8 +95,11 @@ uninstall: rm $(DESTDIR)$(LIBPATH)/$(LIBNAME) rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%) -test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME) - $(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o test +test_standalone: test + @echo "test_standalone is deprecated, please use make-target 'test'" + +test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o + $(CC) $(LTM_CFLAGS) $(LTM_LFLAGS) demo/$@.o $^ -o $@ .PHONY: mtest mtest: diff --git a/makefile.mingw b/makefile.mingw index 5497a1f..fcab293 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -81,14 +81,15 @@ $(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS) $(CC) -s -shared -o $(LIBMAIN_D) $^ -Wl,--enable-auto-import,--export-all -Wl,--out-implib=$(LIBMAIN_I) $(LTM_LDFLAGS) $(STRIP) -S $(LIBMAIN_D) -#Build test_standalone suite -test.exe: demo/main.c demo/opponent.c demo/test.c $(LIBMAIN_S) - $(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -DLTM_DEMO_TEST_VS_MTEST=0 -o $@ +#Build test suite +test.exe: demo/shared.o demo/test.o $(LIBMAIN_S) + $(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@ @echo NOTICE: start the tests by launching test.exe test_standalone: test.exe + @echo test_standalone is deprecated, please use make-target 'test.exe' -all: $(LIBMAIN_S) test_standalone +all: $(LIBMAIN_S) test.exe tune: $(LIBNAME_S) $(MAKE) -C etc tune diff --git a/makefile.msvc b/makefile.msvc index bddadd1..5a4418a 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -67,14 +67,15 @@ $(OBJECTS): $(HEADERS) $(LIBMAIN_S): $(OBJECTS) lib /out:$(LIBMAIN_S) $(OBJECTS) -#Build test_standalone suite -test.exe: $(LIBMAIN_S) demo/main.c demo/opponent.c demo/test.c - cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/main.c demo/opponent.c demo/test.c /DLTM_DEMO_TEST_VS_MTEST=0 /Fe$@ +#Build test suite +test.exe: $(LIBMAIN_S) demo/shared.obj demo/test.obj + cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/shared.c demo/test.c /Fe$@ @echo NOTICE: start the tests by launching test.exe test_standalone: test.exe + @echo test_standalone is deprecated, please use make-target 'test.exe' -all: $(LIBMAIN_S) test_standalone +all: $(LIBMAIN_S) test.exe tune: $(LIBMAIN_S) $(MAKE) -C etc tune diff --git a/makefile.shared b/makefile.shared index f77b5e5..ae3c850 100644 --- a/makefile.shared +++ b/makefile.shared @@ -79,8 +79,11 @@ uninstall: rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%) rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc -test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME) - $(LTLINK) $(LTM_LDFLAGS) $^ -o test +test_standalone: test + @echo "test_standalone is deprecated, please use make-target 'test'" + +test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o + $(LTLINK) $(LTM_LDFLAGS) demo/$@.o $^ -o $@ .PHONY: mtest mtest: diff --git a/makefile.unix b/makefile.unix index 4bdb5d5..ba8c243 100644 --- a/makefile.unix +++ b/makefile.unix @@ -80,13 +80,14 @@ $(LIBMAIN_S): $(OBJECTS) $(RANLIB) $@ #Build test_standalone suite -test: demo/main.c demo/opponent.c demo/test.c $(LIBMAIN_S) - $(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -DLTM_DEMO_TEST_VS_MTEST=0 -o $@ +test: demo/shared.o demo/test.o $(LIBMAIN_S) + $(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@ @echo "NOTICE: start the tests by: ./test" test_standalone: test + @echo "test_standalone is deprecated, please use make-target 'test'" -all: $(LIBMAIN_S) test_standalone +all: $(LIBMAIN_S) test tune: $(LIBMAIN_S) $(MAKE) -C etc tune diff --git a/makefile_include.mk b/makefile_include.mk index a766343..be81586 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -126,8 +126,6 @@ endif HEADERS_PUB=tommath.h HEADERS=tommath_private.h tommath_class.h tommath_superclass.h $(HEADERS_PUB) -test_standalone: LTM_CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0 - #LIBPATH The directory for libtommath to be installed to. #INCPATH The directory to install the header files for libtommath. #DATAPATH The directory to install the pdf docs. diff --git a/testme.sh b/testme.sh index df1b60b..40fa32d 100755 --- a/testme.sh +++ b/testme.sh @@ -130,7 +130,7 @@ _runtest() _make "$1" "$2" "" $_timeout $TUNE_CMD > test_${suffix}.log || _die "running autotune" $? else - _make "$1" "$2" "test_standalone" + _make "$1" "$2" "test" echo -e "\rRun test $1 $2" $_timeout ./test > test_${suffix}.log || _die "running tests" $? fi @@ -156,7 +156,7 @@ echo "autotune branch" echo -e "\rRun etc/tune $1 $2 once inside valgrind" $_timeout $VALGRIND_BIN $VALGRIND_OPTS $TUNE_CMD > test_${suffix}.log || _die "running etc/tune" $? else - _make "$1" "$2" "test_standalone" + _make "$1" "$2" "test" echo -e "\rRun test $1 $2 inside valgrind" $_timeout $VALGRIND_BIN $VALGRIND_OPTS ./test > test_${suffix}.log || _die "running tests" $? fi @@ -336,14 +336,14 @@ _banner if [[ "$TEST_VS_MTEST" != "" ]] then make clean > /dev/null - _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "test" + _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "mtest_opponent" echo _make "gcc" "$MTEST_RAND" "mtest" echo echo "Run test vs. mtest for $TEST_VS_MTEST iterations" _timeout="" which timeout >/dev/null && _timeout="timeout --foreground 1800" - $_timeout ./mtest/mtest $TEST_VS_MTEST | $VALGRIND_BIN $VALGRIND_OPTS ./test > valgrind_test.log 2> test_vs_mtest_err.log + $_timeout ./mtest/mtest $TEST_VS_MTEST | $VALGRIND_BIN $VALGRIND_OPTS ./mtest_opponent > valgrind_test.log 2> test_vs_mtest_err.log retval=$? head -n 5 valgrind_test.log tail -n 2 valgrind_test.log