]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: use PRNG in checksum test 10664/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Sat, 26 Feb 2022 14:13:28 +0000 (15:13 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Sat, 26 Feb 2022 15:49:12 +0000 (16:49 +0100)
(And don't try to go beyond fletcher checksum offset special value.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
tests/lib/subdir.am
tests/lib/test_checksum.c

index 6c897b132ed1fa32280e0dd54de22fc05bede262..62b194439fb210e5cb3dd1cebd942cead409d838 100644 (file)
@@ -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
index 0eedb96a5e94a64e05a1eee2eaf73460a9692057..9a7f2b147298bc5e3ca32430eb858c2a6763818b 100644 (file)
@@ -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)))