summaryrefslogtreecommitdiff
path: root/auto_tests/tox_many_tcp_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-03-28 13:36:14 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-04-03 17:43:22 +0000
commit37d4a0b2ca1377268a82c085809edf63d19cc782 (patch)
tree9b0724cb55f479689cbc04c8b72f9bde99f775ab /auto_tests/tox_many_tcp_test.c
parent7fa0c89c96bdaf45bf202d770aa56dc7c68959b9 (diff)
Avoid the use of rand() in tests.
We control the random functions in crypto_core, so we can make them deterministic more easily. This will help test reproducibility in the future.
Diffstat (limited to 'auto_tests/tox_many_tcp_test.c')
-rw-r--r--auto_tests/tox_many_tcp_test.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c
index 6c3f2350..34b01d16 100644
--- a/auto_tests/tox_many_tcp_test.c
+++ b/auto_tests/tox_many_tcp_test.c
@@ -15,6 +15,7 @@
15#include <stdlib.h> 15#include <stdlib.h>
16#include <time.h> 16#include <time.h>
17 17
18#include "../toxcore/crypto_core.h"
18#include "../toxcore/tox.h" 19#include "../toxcore/tox.h"
19#include "../toxcore/util.h" 20#include "../toxcore/util.h"
20 21
@@ -84,8 +85,8 @@ START_TEST(test_many_clients_tcp)
84 85
85 for (i = 0; i < NUM_FRIENDS; ++i) { 86 for (i = 0; i < NUM_FRIENDS; ++i) {
86loop_top: 87loop_top:
87 pairs[i].tox1 = rand() % NUM_TOXES_TCP; 88 pairs[i].tox1 = random_u32() % NUM_TOXES_TCP;
88 pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP; 89 pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP;
89 90
90 for (j = 0; j < i; ++j) { 91 for (j = 0; j < i; ++j) {
91 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { 92 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
@@ -178,8 +179,8 @@ START_TEST(test_many_clients_tcp_b)
178 179
179 for (i = 0; i < NUM_FRIENDS; ++i) { 180 for (i = 0; i < NUM_FRIENDS; ++i) {
180loop_top: 181loop_top:
181 pairs[i].tox1 = rand() % NUM_TOXES_TCP; 182 pairs[i].tox1 = random_u32() % NUM_TOXES_TCP;
182 pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP; 183 pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP;
183 184
184 for (j = 0; j < i; ++j) { 185 for (j = 0; j < i; ++j) {
185 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { 186 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {