mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-04 13:31:48 +00:00
tests: use PRNG in checksum test
(And don't try to go beyond fletcher checksum offset special value.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
89087f23b5
commit
9b6ef21e51
@ -148,7 +148,7 @@ check_PROGRAMS += tests/lib/test_checksum
|
||||
tests_lib_test_checksum_CFLAGS = $(TESTS_CFLAGS)
|
||||
tests_lib_test_checksum_CPPFLAGS = $(TESTS_CPPFLAGS)
|
||||
tests_lib_test_checksum_LDADD = $(ALL_TESTS_LDADD)
|
||||
tests_lib_test_checksum_SOURCES = tests/lib/test_checksum.c
|
||||
tests_lib_test_checksum_SOURCES = tests/lib/test_checksum.c tests/helpers/c/prng.c
|
||||
|
||||
|
||||
check_PROGRAMS += tests/lib/test_graph
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "checksum.h"
|
||||
#include "network.h"
|
||||
#include "prng.h"
|
||||
|
||||
struct thread_master *master;
|
||||
|
||||
@ -468,24 +469,19 @@ int main(int argc, char **argv)
|
||||
uint8_t buffer[BUFSIZE];
|
||||
int exercise = 0;
|
||||
#define EXERCISESTEP 257
|
||||
srandom(time(NULL));
|
||||
struct prng *prng = prng_new(0);
|
||||
|
||||
while (1) {
|
||||
uint16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc;
|
||||
int i, j;
|
||||
int i;
|
||||
|
||||
exercise += EXERCISESTEP;
|
||||
exercise %= MAXDATALEN;
|
||||
|
||||
printf("\rexercising length %d\033[K", exercise);
|
||||
|
||||
for (i = 0; i < exercise; i += sizeof(long int)) {
|
||||
long int rand = frr_weak_random();
|
||||
|
||||
for (j = sizeof(long int); j > 0; j--)
|
||||
buffer[i + (sizeof(long int) - j)] =
|
||||
(rand >> (j * 8)) & 0xff;
|
||||
}
|
||||
for (i = 0; i < exercise; i++)
|
||||
buffer[i] = prng_rand(prng);
|
||||
|
||||
in_csum = in_cksum(buffer, exercise);
|
||||
in_csum_res = in_cksum_optimized(buffer, exercise);
|
||||
@ -537,6 +533,9 @@ int main(int argc, char **argv)
|
||||
iov[2].iov_len, in_csum_iov, in_csum);
|
||||
}
|
||||
|
||||
if (exercise >= FLETCHER_CHECKSUM_VALIDATE)
|
||||
continue;
|
||||
|
||||
ospfd = ospfd_checksum(buffer, exercise + sizeof(uint16_t),
|
||||
exercise);
|
||||
if (verify(buffer, exercise + sizeof(uint16_t)))
|
||||
|
Loading…
Reference in New Issue
Block a user