summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/tests/internal/random.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:18 +0000
commit5da14042f70711ea5cf66e034699730335462f66 (patch)
tree0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/fluent-bit/tests/internal/random.c
parentReleasing debian version 1.44.3-2. (diff)
downloadnetdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz
netdata-5da14042f70711ea5cf66e034699730335462f66.zip
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fluent-bit/tests/internal/random.c')
-rw-r--r--src/fluent-bit/tests/internal/random.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/fluent-bit/tests/internal/random.c b/src/fluent-bit/tests/internal/random.c
new file mode 100644
index 000000000..236eaa575
--- /dev/null
+++ b/src/fluent-bit/tests/internal/random.c
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#include <fluent-bit/flb_random.h>
+
+#include "flb_tests_internal.h"
+
+void test_random_bytes()
+{
+ int ret;
+ unsigned char buf1[64] = {0};
+ unsigned char buf2[64] = {0};
+
+ /* The following tests check whether:
+ *
+ * (1) the random generator fills the buffer with numbers at all.
+ * (2) a successive call generates different numbers.
+ *
+ * These tests are probabilistic by nature; If we assume an ideal random
+ * generator, they are expected to fail once in 2^192 (= 10^57) runs.
+ */
+ ret = flb_random_bytes(buf1, 64);
+ TEST_CHECK(ret == 0);
+ TEST_CHECK(memcmp(buf1, buf2, 64) != 0);
+
+ ret = flb_random_bytes(buf2, 64);
+ TEST_CHECK(ret == 0);
+ TEST_CHECK(memcmp(buf1, buf2, 64) != 0);
+}
+
+TEST_LIST = {
+ {"random_bytes", test_random_bytes},
+ { 0 }
+};