summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Summermatter <elias.summermatter@seccom.ch>2021-03-18 08:45:31 +0100
committerElias Summermatter <elias.summermatter@seccom.ch>2021-03-18 08:45:31 +0100
commit0d6237ae0d35c07780aa49e192f6477bf378f281 (patch)
tree6ca54450b63a22c328b9b3fe29db5be23a2b7b3f
parentc4e97f3f77171eb93bd101e0d4550af441cb6d80 (diff)
Added some randum elemet generation test for setu
-rw-r--r--src/setu/test_setu_api.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/setu/test_setu_api.c b/src/setu/test_setu_api.c
index 95119873c..c2f913bd9 100644
--- a/src/setu/test_setu_api.c
+++ b/src/setu/test_setu_api.c
@@ -204,6 +204,57 @@ init_set2 (void *cls)
GNUNET_SETU_add_element (set2, &element, &start, NULL);
}
+/**
+ * Generate random byte stream
+ */
+
+unsigned char *gen_rdm_bytestream (size_t num_bytes)
+{
+ unsigned char *stream = malloc (num_bytes);
+ size_t i;
+ for (i = 0; i < num_bytes; i++)
+ {
+ stream[i] = rand ();
+ }
+ return stream;
+}
+
+/**
+ * Generate random sets
+ */
+
+static void
+initRandomSets(int overlap, int set1_size, int set2_size, int element_size_in_bytes)
+{
+ struct GNUNET_SETU_Element element;
+ element.element_type = 0;
+
+ // Add elements to both sets
+ for (int i = 0; i < overlap; i++) {
+ element.data = gen_rdm_bytestream(element_size_in_bytes);
+ element.size = strlen (element.data);
+ GNUNET_SETU_add_element (set1, &element, NULL, NULL);
+ GNUNET_SETU_add_element (set2, &element, NULL, NULL);
+ set1_size--;
+ set2_size--;
+ }
+
+ // Add other elements to set 1
+ while(set1_size>0) {
+ element.data = gen_rdm_bytestream(element_size_in_bytes);
+ element.size = strlen (element.data);
+ GNUNET_SETU_add_element (set1, &element, NULL, NULL);
+ set1_size--;
+ }
+
+ // Add other elements to set 2
+ while(set2_size > 0) {
+ element.data = gen_rdm_bytestream(element_size_in_bytes);
+ element.size = strlen (element.data);
+ GNUNET_SETU_add_element (set1, &element, NULL, NULL);
+ set2_size--;
+ }
+}
/**
* Initialize the first set, continue.
@@ -337,6 +388,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Running real set-reconciliation\n");
init_set1 ();
+ //initRandomSets(3,10,10,10);
}