create mtest_opponent instead of alt version of test

This commit is contained in:
Steffen Jaeckel 2019-09-10 16:05:27 +02:00
parent 6e160216b0
commit f8d64c645a
13 changed files with 57 additions and 40 deletions

2
.gitignore vendored
View File

@ -23,6 +23,8 @@ test
test.exe
mtest
mtest.exe
mtest_opponent
mtest_opponent.exe
# ignore eclipse project files
.cproject

View File

@ -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

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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.

View File

@ -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