Skip to content

Commit 0da3c65

Browse files
authored
Merge pull request #352 from libtom/dedup-test-binary
Deduplicate the test binary
2 parents 6e16021 + f8d64c6 commit 0da3c65

File tree

13 files changed

+57
-40
lines changed

13 files changed

+57
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ test
2323
test.exe
2424
mtest
2525
mtest.exe
26+
mtest_opponent
27+
mtest_opponent.exe
2628

2729
# ignore eclipse project files
2830
.cproject

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ API/ABI changes: [check here](https://abi-laboratory.pro/tracker/timeline/libtom
2424

2525
The `develop` branch contains the in-development version. Stable releases are tagged.
2626

27-
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.
27+
Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`.
28+
There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used.
2829

29-
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.
30+
The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`,
31+
there are several other build targets, see the makefile for details.
32+
There are also makefiles for certain specific platforms.
3033

3134
## Testing
3235

3336
Tests are located in `demo/` and can be built in two flavors.
34-
* `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
35-
* `make test_standalone` creates a stand-alone test binary that executes several test routines.
37+
* `make test` creates a stand-alone test binary that executes several test routines.
38+
* `make mtest_opponent` creates a test binary that is intended to be run against `mtest`.
39+
`mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./mtest_opponent`.
40+
`mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm
3641

3742
## Building and Installing
3843

demo/opponent.c renamed to demo/mtest_opponent.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void draw(mp_int *a)
1717
if (!ret) { fprintf(stderr, "\n%d: fgets failed\n", __LINE__); goto LBL_ERR; } \
1818
}
1919

20-
int mtest_opponent(void)
20+
static int mtest_opponent(void)
2121
{
2222
char cmd[4096];
2323
char buf[4096];
@@ -394,3 +394,10 @@ int mtest_opponent(void)
394394
printf("\n");
395395
return EXIT_FAILURE;
396396
}
397+
398+
int main(void)
399+
{
400+
print_header();
401+
402+
return mtest_opponent();
403+
}

demo/main.c renamed to demo/shared.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "shared.h"
22

3-
int mtest_opponent(void);
4-
int unit_tests(int argc, char **argv);
5-
63
void ndraw(mp_int *a, const char *name)
74
{
85
char *buf;
@@ -24,7 +21,7 @@ void ndraw(mp_int *a, const char *name)
2421
free(buf);
2522
}
2623

27-
int main(int argc, char **argv)
24+
void print_header(void)
2825
{
2926
#ifdef MP_8BIT
3027
printf("Digit size 8 Bit \n");
@@ -42,9 +39,4 @@ int main(int argc, char **argv)
4239
printf("Size of mp_word: %u\n", (unsigned int)sizeof(mp_word));
4340
printf("MP_DIGIT_BIT: %d\n", MP_DIGIT_BIT);
4441
printf("MP_PREC: %d\n", MP_PREC);
45-
46-
if (LTM_DEMO_TEST_VS_MTEST) {
47-
return mtest_opponent();
48-
}
49-
return unit_tests(argc, argv);
5042
}

demo/shared.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
/*
66
* Configuration
77
*/
8-
#ifndef LTM_DEMO_TEST_VS_MTEST
9-
#define LTM_DEMO_TEST_VS_MTEST 1
10-
#endif
11-
128
#ifndef LTM_DEMO_TEST_REDUCE_2K_L
139
/* This test takes a moment so we disable it by default, but it can be:
1410
* 0 to disable testing
@@ -22,3 +18,4 @@
2218
#include "tommath_private.h"
2319

2420
extern void ndraw(mp_int* a, const char* name);
21+
extern void print_header(void);

demo/test.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ static int test_s_mp_toom_sqr(void)
22142214
return EXIT_FAILURE;
22152215
}
22162216

2217-
int unit_tests(int argc, char **argv)
2217+
static int unit_tests(int argc, char **argv)
22182218
{
22192219
static const struct {
22202220
const char *name;
@@ -2304,3 +2304,10 @@ int unit_tests(int argc, char **argv)
23042304
if (fail != 0) return EXIT_FAILURE;
23052305
else return EXIT_SUCCESS;
23062306
}
2307+
2308+
int main(int argc, char **argv)
2309+
{
2310+
print_header();
2311+
2312+
return unit_tests(argc, argv);
2313+
}

makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ uninstall:
9595
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
9696
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
9797

98-
test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
99-
$(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o test
98+
test_standalone: test
99+
@echo "test_standalone is deprecated, please use make-target 'test'"
100+
101+
test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o
102+
$(CC) $(LTM_CFLAGS) $(LTM_LFLAGS) demo/$@.o $^ -o $@
100103

101104
.PHONY: mtest
102105
mtest:

makefile.mingw

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ $(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS)
8181
$(CC) -s -shared -o $(LIBMAIN_D) $^ -Wl,--enable-auto-import,--export-all -Wl,--out-implib=$(LIBMAIN_I) $(LTM_LDFLAGS)
8282
$(STRIP) -S $(LIBMAIN_D)
8383

84-
#Build test_standalone suite
85-
test.exe: demo/main.c demo/opponent.c demo/test.c $(LIBMAIN_S)
86-
$(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -DLTM_DEMO_TEST_VS_MTEST=0 -o $@
84+
#Build test suite
85+
test.exe: demo/shared.o demo/test.o $(LIBMAIN_S)
86+
$(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@
8787
@echo NOTICE: start the tests by launching test.exe
8888

8989
test_standalone: test.exe
90+
@echo test_standalone is deprecated, please use make-target 'test.exe'
9091

91-
all: $(LIBMAIN_S) test_standalone
92+
all: $(LIBMAIN_S) test.exe
9293

9394
tune: $(LIBNAME_S)
9495
$(MAKE) -C etc tune

makefile.msvc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ $(OBJECTS): $(HEADERS)
6767
$(LIBMAIN_S): $(OBJECTS)
6868
lib /out:$(LIBMAIN_S) $(OBJECTS)
6969

70-
#Build test_standalone suite
71-
test.exe: $(LIBMAIN_S) demo/main.c demo/opponent.c demo/test.c
72-
cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/main.c demo/opponent.c demo/test.c /DLTM_DEMO_TEST_VS_MTEST=0 /Fe$@
70+
#Build test suite
71+
test.exe: $(LIBMAIN_S) demo/shared.obj demo/test.obj
72+
cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/shared.c demo/test.c /Fe$@
7373
@echo NOTICE: start the tests by launching test.exe
7474

7575
test_standalone: test.exe
76+
@echo test_standalone is deprecated, please use make-target 'test.exe'
7677

77-
all: $(LIBMAIN_S) test_standalone
78+
all: $(LIBMAIN_S) test.exe
7879

7980
tune: $(LIBMAIN_S)
8081
$(MAKE) -C etc tune

makefile.shared

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ uninstall:
7979
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
8080
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
8181

82-
test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
83-
$(LTLINK) $(LTM_LDFLAGS) $^ -o test
82+
test_standalone: test
83+
@echo "test_standalone is deprecated, please use make-target 'test'"
84+
85+
test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o
86+
$(LTLINK) $(LTM_LDFLAGS) demo/[email protected] $^ -o $@
8487

8588
.PHONY: mtest
8689
mtest:

0 commit comments

Comments
 (0)