Skip to content

Commit 34e16d3

Browse files
committed
allow testing of shared library
* move jenkins' prng out of the library into the demo's. * add CI test for shared library
1 parent fa94aa2 commit 34e16d3

File tree

14 files changed

+62
-55
lines changed

14 files changed

+62
-55
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ matrix:
8686
packages:
8787
- gcc-4.9
8888

89+
# Shared library build
90+
- env: COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc --make-option=-f --make-option=makefile.shared'
91+
addons:
92+
apt:
93+
packages:
94+
- libtool-bin
95+
8996
# GCC for the 32-bit architecture (no valgrind)
9097
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m32'
9198
addons:

s_mp_rand_jenkins.c renamed to demo/s_mp_rand_jenkins.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
/* Bob Jenkins' http://burtleburtle.net/bob/rand/smallprng.html */
77
/* Chosen for speed and a good "mix" */
8+
9+
/* TODO: jenkins prng is not thread safe as of now */
10+
811
typedef struct {
912
uint64_t a;
1013
uint64_t b;
@@ -25,7 +28,7 @@ static uint64_t s_rand_jenkins_val(void)
2528
return jenkins_x.d;
2629
}
2730

28-
void s_mp_rand_jenkins_init(uint64_t seed)
31+
static void s_mp_rand_jenkins_init(uint64_t seed)
2932
{
3033
int i;
3134
jenkins_x.a = 0xF1EA5EEDuL;
@@ -35,7 +38,7 @@ void s_mp_rand_jenkins_init(uint64_t seed)
3538
}
3639
}
3740

38-
mp_err s_mp_rand_jenkins(void *p, size_t n)
41+
static mp_err s_mp_rand_jenkins(void *p, size_t n)
3942
{
4043
char *q = (char *)p;
4144
while (n > 0u) {

demo/test.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include <inttypes.h>
22
#include "shared.h"
33

4+
#define S_MP_RAND_JENKINS_C
5+
#include "s_mp_rand_jenkins.c"
6+
47
static long rand_long(void)
58
{
69
long x;
7-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
10+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
811
fprintf(stderr, "s_mp_rand_source failed\n");
912
exit(EXIT_FAILURE);
1013
}
@@ -14,7 +17,7 @@ static long rand_long(void)
1417
static int rand_int(void)
1518
{
1619
int x;
17-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
20+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
1821
fprintf(stderr, "s_mp_rand_source failed\n");
1922
exit(EXIT_FAILURE);
2023
}
@@ -24,7 +27,7 @@ static int rand_int(void)
2427
static int32_t rand_int32(void)
2528
{
2629
int32_t x;
27-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
30+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
2831
fprintf(stderr, "s_mp_rand_source failed\n");
2932
exit(EXIT_FAILURE);
3033
}
@@ -34,7 +37,7 @@ static int32_t rand_int32(void)
3437
static int64_t rand_int64(void)
3538
{
3639
int64_t x;
37-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
40+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
3841
fprintf(stderr, "s_mp_rand_source failed\n");
3942
exit(EXIT_FAILURE);
4043
}
@@ -2134,15 +2137,20 @@ static int test_mp_pack_unpack(void)
21342137
return EXIT_FAILURE;
21352138
}
21362139

2140+
#ifndef LTM_TEST_DYNAMIC
2141+
#define ONLY_PUBLIC_API_C
2142+
#endif
2143+
21372144
static int unit_tests(int argc, char **argv)
21382145
{
21392146
static const struct {
21402147
const char *name;
21412148
int (*fn)(void);
21422149
} test[] = {
2143-
#define T0(n) { #n, test_##n }
2144-
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
2145-
#define T2(n, o1, o2) { #n, (MP_HAS(o1) && MP_HAS(o2)) ? test_##n : NULL }
2150+
#define T0(n) { #n, test_##n }
2151+
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
2152+
#define T2(n, o1, o2) { #n, (MP_HAS(o1) && MP_HAS(o2)) ? test_##n : NULL }
2153+
#define T3(n, o1, o2, o3) { #n, (MP_HAS(o1) && MP_HAS(o2) && MP_HAS(o3)) ? test_##n : NULL }
21462154
T0(feature_detection),
21472155
T0(trivial_stuff),
21482156
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
@@ -2151,7 +2159,7 @@ static int unit_tests(int argc, char **argv)
21512159
T1(mp_cnt_lsb, MP_CNT_LSB),
21522160
T1(mp_complement, MP_COMPLEMENT),
21532161
T1(mp_decr, MP_SUB_D),
2154-
T1(s_mp_div_3, S_MP_DIV_3),
2162+
T2(s_mp_div_3, ONLY_PUBLIC_API, S_MP_DIV_3),
21552163
T1(mp_dr_reduce, MP_DR_REDUCE),
21562164
T2(mp_pack_unpack,MP_PACK, MP_UNPACK),
21572165
T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
@@ -2176,21 +2184,22 @@ static int unit_tests(int argc, char **argv)
21762184
T1(mp_reduce_2k, MP_REDUCE_2K),
21772185
T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
21782186
T1(mp_radix_size, MP_RADIX_SIZE),
2179-
T1(s_mp_radix_size_overestimate, S_MP_RADIX_SIZE_OVERESTIMATE),
2187+
T2(s_mp_radix_size_overestimate, ONLY_PUBLIC_API, S_MP_RADIX_SIZE_OVERESTIMATE),
21802188
#if defined(MP_HAS_SET_DOUBLE)
21812189
T1(mp_set_double, MP_SET_DOUBLE),
21822190
#endif
21832191
T1(mp_signed_rsh, MP_SIGNED_RSH),
21842192
T2(mp_sqrt, MP_SQRT, MP_ROOT_N),
21852193
T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
21862194
T1(mp_xor, MP_XOR),
2187-
T2(s_mp_div_recursive, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
2188-
T2(s_mp_div_small, S_MP_DIV_SMALL, S_MP_DIV_SCHOOL),
2189-
T1(s_mp_mul_balance, S_MP_MUL_BALANCE),
2190-
T1(s_mp_mul_karatsuba, S_MP_MUL_KARATSUBA),
2191-
T1(s_mp_sqr_karatsuba, S_MP_SQR_KARATSUBA),
2192-
T1(s_mp_mul_toom, S_MP_MUL_TOOM),
2193-
T1(s_mp_sqr_toom, S_MP_SQR_TOOM)
2195+
T3(s_mp_div_recursive, ONLY_PUBLIC_API, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
2196+
T3(s_mp_div_small, ONLY_PUBLIC_API, S_MP_DIV_SMALL, S_MP_DIV_SCHOOL),
2197+
T2(s_mp_mul_balance, ONLY_PUBLIC_API, S_MP_MUL_BALANCE),
2198+
T2(s_mp_mul_karatsuba, ONLY_PUBLIC_API, S_MP_MUL_KARATSUBA),
2199+
T2(s_mp_sqr_karatsuba, ONLY_PUBLIC_API, S_MP_SQR_KARATSUBA),
2200+
T2(s_mp_mul_toom, ONLY_PUBLIC_API, S_MP_MUL_TOOM),
2201+
T2(s_mp_sqr_toom, ONLY_PUBLIC_API, S_MP_SQR_TOOM)
2202+
#undef T3
21942203
#undef T2
21952204
#undef T1
21962205
};

etc/makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
LTM_CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
2-
LTM_CFLAGS += $(CFLAGS)
1+
LTM_TUNE_CFLAGS = $(CFLAGS) $(LTM_CFLAGS) -Wall -W -Wextra -Wshadow -O3 -I../
32

43
# default lib name (requires install with root)
54
# LIBNAME=-ltommath
@@ -9,31 +8,31 @@ LIBNAME=../libtommath.a
98

109
#provable primes
1110
pprime: pprime.o
12-
$(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
11+
$(CC) $(LTM_TUNE_CFLAGS) pprime.o $(LIBNAME) -o pprime
1312

1413
# portable [well requires clock()] tuning app
1514
tune: tune.o
16-
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
15+
$(CC) $(LTM_TUNE_CFLAGS) tune.o $(LIBNAME) -o tune
1716
./tune_it.sh
1817

1918
test_standalone: tune.o
2019
# The benchmark program works as a testtool, too
21-
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o test
20+
$(CC) $(LTM_TUNE_CFLAGS) tune.o $(LIBNAME) -o test
2221

2322
# spits out mersenne primes
2423
mersenne: mersenne.o
25-
$(CC) $(LTM_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
24+
$(CC) $(LTM_TUNE_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
2625

2726
# finds DR safe primes for the given config
2827
drprime: drprime.o
29-
$(CC) $(LTM_CFLAGS) drprime.o $(LIBNAME) -o drprime
28+
$(CC) $(LTM_TUNE_CFLAGS) drprime.o $(LIBNAME) -o drprime
3029

3130
# finds 2k safe primes for the given config
3231
2kprime: 2kprime.o
33-
$(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
32+
$(CC) $(LTM_TUNE_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
3433

3534
mont: mont.o
36-
$(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
35+
$(CC) $(LTM_TUNE_CFLAGS) mont.o $(LIBNAME) -o mont
3736

3837

3938
clean:

etc/tune.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
*
33
* Tom St Denis, tstdenis82@gmail.com
44
*/
5-
#include "../tommath.h"
6-
#include "../tommath_private.h"
5+
#include "tommath_private.h"
76
#include <time.h>
87
#include <inttypes.h>
98
#include <errno.h>
109

10+
#define S_MP_RAND_JENKINS_C
11+
#include "../demo/s_mp_rand_jenkins.c"
12+
1113
/*
1214
Please take in mind that both multiplicands are of the same size. The balancing
1315
mechanism in mp_balance works well but has some overhead itself. You can test

libtommath_VS2008.vcproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,6 @@
896896
RelativePath="s_mp_radix_size_overestimate.c"
897897
>
898898
</File>
899-
<File
900-
RelativePath="s_mp_rand_jenkins.c"
901-
>
902-
</File>
903899
<File
904900
RelativePath="s_mp_rand_platform.c"
905901
>

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_b
4848
s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o \
4949
s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \
5050
s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o \
51-
s_mp_radix_size_overestimate.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \
52-
s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o
51+
s_mp_radix_size_overestimate.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o s_mp_sqr_karatsuba.o \
52+
s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o
5353

5454
#END_INS
5555

@@ -104,7 +104,7 @@ timing: demo/timing.c $(LIBNAME)
104104
$(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o timing
105105

106106
tune: $(LIBNAME)
107-
$(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)"
107+
$(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS) -I../"
108108
$(MAKE)
109109

110110
# You have to create a file .coveralls.yml with the content "repo_token: <the token>"

makefile.mingw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_b
5050
s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o \
5151
s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \
5252
s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o \
53-
s_mp_radix_size_overestimate.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \
54-
s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o
53+
s_mp_radix_size_overestimate.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o s_mp_sqr_karatsuba.o \
54+
s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o
5555

5656
HEADERS_PUB=tommath.h
5757
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB)

makefile.msvc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ s_mp_div_school.obj s_mp_div_small.obj s_mp_exptmod.obj s_mp_exptmod_fast.obj s_
4646
s_mp_invmod_odd.obj s_mp_log.obj s_mp_log_2expt.obj s_mp_log_d.obj s_mp_montgomery_reduce_comba.obj s_mp_mul.obj \
4747
s_mp_mul_balance.obj s_mp_mul_comba.obj s_mp_mul_high.obj s_mp_mul_high_comba.obj s_mp_mul_karatsuba.obj \
4848
s_mp_mul_toom.obj s_mp_prime_is_divisible.obj s_mp_prime_tab.obj s_mp_radix_map.obj \
49-
s_mp_radix_size_overestimate.obj s_mp_rand_jenkins.obj s_mp_rand_platform.obj s_mp_sqr.obj s_mp_sqr_comba.obj \
50-
s_mp_sqr_karatsuba.obj s_mp_sqr_toom.obj s_mp_sub.obj s_mp_zero_buf.obj s_mp_zero_digs.obj
49+
s_mp_radix_size_overestimate.obj s_mp_rand_platform.obj s_mp_sqr.obj s_mp_sqr_comba.obj s_mp_sqr_karatsuba.obj \
50+
s_mp_sqr_toom.obj s_mp_sub.obj s_mp_zero_buf.obj s_mp_zero_digs.obj
5151

5252
HEADERS_PUB=tommath.h
5353
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB)

makefile.shared

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_b
4545
s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o \
4646
s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \
4747
s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o \
48-
s_mp_radix_size_overestimate.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \
49-
s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o
48+
s_mp_radix_size_overestimate.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o s_mp_sqr_karatsuba.o \
49+
s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o
5050

5151
#END_INS
5252

@@ -75,7 +75,7 @@ uninstall:
7575
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
7676

7777
test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o
78-
$(LTLINK) $(LTM_LDFLAGS) demo/$@.o $^ -o $@
78+
$(LTLINK) $(LTM_LDFLAGS) -DLTM_TEST_DYNAMIC demo/$@.o $^ -o $@
7979

8080
.PHONY: mtest
8181
mtest:

0 commit comments

Comments
 (0)