]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
start of testings without path compression
authorAlan T. DeKok <aland@freeradius.org>
Thu, 4 Jan 2018 18:24:36 +0000 (13:24 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 4 Jan 2018 18:24:36 +0000 (13:24 -0500)
it currently fails when merging nodes of different size,
so it's commented out

src/lib/util/trie.c
src/tests/trie/.gitignore
src/tests/trie/all.mk
src/tests/trie/nopc.mk [new file with mode: 0644]
src/tests/trie/test.mk

index 52a9b8efeb7d237ad0a323bd14b3be3ca0750174..0889aa077d213c7ba308d9af5ddf0adb759afd46 100644 (file)
@@ -76,7 +76,9 @@ RCSID("$Id$")
  *  create a large number of intermediate 2^N-way nodes, all of which
  *  would have only one edge.
  */
+#ifndef NO_PATH_COMPRESSION
 #define WITH_PATH_COMPRESSION
+#endif
 
 /**  Internal sanity checks for debugging.
  *
@@ -183,8 +185,8 @@ struct fr_trie_t {
 #define PUT_PATH(_x)   ((void *) (((uintptr_t) _x) | 0x03))
 
 static void *fr_trie_path_merge_paths(TALLOC_CTX *ctx, fr_trie_path_t *path1, fr_trie_path_t *path2, int depth) CC_HINT(nonnull);
-static int fr_trie_merge(TALLOC_CTX *ctx, void **out, void *a, void *b, int depth);
 #endif
+static int fr_trie_merge(TALLOC_CTX *ctx, void **out, void *a, void *b, int depth);
 
 static int fr_trie_key_insert(TALLOC_CTX *ctx, void **trie_p, uint8_t const *key, int start_bit, int end_bit, void *trie) CC_HINT(nonnull);
 
@@ -1045,7 +1047,6 @@ static uint16_t get_chunk(uint8_t const *key, int num_bits, int start_bit, int e
 }
 
 
-#ifdef WITH_PATH_COMPRESSION
 /** A generic merge routine
  *
  * @param ctx  the talloc ctx
@@ -1201,8 +1202,6 @@ static int fr_trie_merge(TALLOC_CTX *ctx, void **out, void *a, void *b, int dept
                        assert(bits < 8);
 
                        for (j = 0; j < (1 << bits); j++) {
-                               void *trie;
-
                                /*
                                 *      If the entry in the larger
                                 *      node is empty, we don't need
@@ -1210,6 +1209,9 @@ static int fr_trie_merge(TALLOC_CTX *ctx, void **out, void *a, void *b, int dept
                                 */
                                if (!node2->entry[(i << bits) + j]) continue;
 
+#ifdef WITH_PATH_COMPRESSION
+                               void *trie;
+
                                /*
                                 *      Convert the entry in node2
                                 *      into a path + trailing
@@ -1223,6 +1225,43 @@ static int fr_trie_merge(TALLOC_CTX *ctx, void **out, void *a, void *b, int dept
                                                  node1->entry[i], trie, depth) < 0) {
                                        return -1;
                                }
+#else
+                               fr_trie_node_t  *sub;
+
+                               /*
+                                *      Allocate a sub-node to fill
+                                *      the gap.
+                                */
+                               if (!node1->entry[i]) {
+                                       sub = fr_trie_node_alloc(node1, bits);
+                                       assert(sub != NULL);
+                                       node1->entry[i] = sub;
+
+                               } else if (IS_NODE(node1->entry[i])) {
+                                       sub = node1->entry[i];
+                                       assert(IS_NODE(sub));
+
+                               } else {
+                                       fr_trie_user_t *user;
+
+                                       assert(IS_USER(node1->entry[i]));
+                                       user = GET_USER(node1->entry[i]);
+
+                                       sub = user->trie;
+                                       if (!sub) {
+                                               sub = fr_trie_node_alloc(user, bits);
+                                               assert(sub != NULL);
+                                               user->trie = sub;
+
+                                       } else {
+                                               assert(sub->size == bits);
+                                       }
+                               }
+
+                               if (fr_trie_merge(sub, &sub->entry[j], sub->entry[j], node2->entry[(i << bits) | j], depth) < 0) {
+                                       return -1;
+                               }
+#endif
                        }
                }
 
@@ -1237,7 +1276,6 @@ static int fr_trie_merge(TALLOC_CTX *ctx, void **out, void *a, void *b, int dept
 
        return -1;
 }   
-#endif
 
 
 /** Match a key in a trie and return user ctx, if any
@@ -1377,26 +1415,23 @@ static int fr_trie_key_insert(TALLOC_CTX *ctx, void **trie_p, uint8_t const *key
        fr_trie_node_t *node;
 
        if (!trie) {
-               int size;
+               if (start_bit == end_bit) {
+                       reparent(ctx, subtrie);
+                       *trie_p = subtrie;
+                       return 0;
+               }
 
 #ifdef WITH_PATH_COMPRESSION
                /*
                 *      If we have key, just create a path.
                 */
-               if (start_bit < end_bit) {
-                       path = fr_trie_path_alloc(ctx, key, start_bit, end_bit, subtrie);
-                       if (!path) return -1;
+               path = fr_trie_path_alloc(ctx, key, start_bit, end_bit, subtrie);
+               if (!path) return -1;
 
-                       *trie_p = PUT_PATH(path);
-                       return 0;
-               }
-#endif
-
-               if (start_bit == end_bit) {
-                       reparent(ctx, subtrie);
-                       *trie_p = subtrie;
-                       return 0;
-               }
+               *trie_p = PUT_PATH(path);
+               return 0;
+#else
+               int size;
 
                /*
                 *      Avoid splitting the main node immediately
@@ -1407,9 +1442,10 @@ static int fr_trie_key_insert(TALLOC_CTX *ctx, void **trie_p, uint8_t const *key
 
                node = fr_trie_node_alloc(ctx, size);
                if (!node) return -1;
-               *trie_p = node;
-//             goto insert_node;
-               assert(0 == 1);
+
+               *trie_p = trie = node;
+               goto insert_node;
+#endif
        }
 
        /*
@@ -1517,6 +1553,8 @@ static int fr_trie_key_insert(TALLOC_CTX *ctx, void **trie_p, uint8_t const *key
                *trie_p = trie;
                return 0;
        }
+#else
+insert_node:
 #endif
 
        assert(IS_NODE(trie));
index 25974e3d69a347a2baad4b95b42009a1154113e6..d9717c9bbe8cd7eff89a9825820bb99605bcb69f 100644 (file)
@@ -1 +1,2 @@
 trie.c
+nopc.c
index 2c44b4fa5ce4918b939e74bfa01ba093511174e7..64ae18c72a66dc34ac782d8fc096aa6e55bd2524 100644 (file)
@@ -1,2 +1,2 @@
-SUBMAKEFILES := trie.mk test.mk
+SUBMAKEFILES := trie.mk nopc.mk test.mk
 
diff --git a/src/tests/trie/nopc.mk b/src/tests/trie/nopc.mk
new file mode 100644 (file)
index 0000000..ab57f21
--- /dev/null
@@ -0,0 +1,17 @@
+TARGET         := nopc
+
+SRC_CFLAGS     := -DTESTING -DNO_PATH_COMPRESSION
+SOURCES                := nopc.c
+TGT_LDLIBS     := $(LIBS)
+TGT_PREREQS    := libfreeradius-util.a
+
+#
+#  The build system maps one source file to one object file.  So in
+#  order to build a test binary, we need to create a new source file.
+#
+#  We could move the test code into a "trie.c" file in this directory.
+#  But it's useful for the test code to access internal functions /
+#  definitions in the trie library.
+#
+src/tests/trie/nopc.c: ${top_srcdir}/src/lib/util/trie.c
+       @[-e $@ ] || ln -s $^ $@
index 412cf2f243ea0a3941ef69feb610a6f1334fe7a0..dd39b896a221cba58fdf4c65f089d46f2594751a 100644 (file)
@@ -10,14 +10,19 @@ TRIE_FILES := $(subst $(DIR)/,,$(wildcard $(DIR)/*.txt))
 $(BUILD_DIR)/tests/trie:
        ${Q}mkdir -p $@
 
-$(BUILD_DIR)/tests/trie/%: $(DIR)/% $(TESTBINDIR)/trie | $(BUILD_DIR)/tests/trie
+$(BUILD_DIR)/tests/trie/trie-%: $(DIR)/% $(TESTBINDIR)/trie | $(BUILD_DIR)/tests/trie
        @echo TRIE-TEST $(dir $@)
        @$(TESTBINDIR)/trie $^ > $@
 
+$(BUILD_DIR)/tests/trie/nopc-%: $(DIR)/% $(TESTBINDIR)/nopc | $(BUILD_DIR)/tests/trie
+       @echo TRIE-NO-PC-TEST $(dir $@)
+       @$(TESTBINDIR)/nopc $^ > $@
+
 #
 #  Get all of the unit test output files
 #
-TESTS.TRIE_FILES := $(addprefix $(BUILD_DIR)/tests/trie/,$(TRIE_FILES))
+TESTS.TRIE_FILES := $(addprefix $(BUILD_DIR)/tests/trie/trie-,$(TRIE_FILES))
+#TESTS.TRIE_FILES += $(addprefix $(BUILD_DIR)/tests/trie/nopc-,$(TRIE_FILES))
 
 #
 #  Depend on the output files, and create the directory first.