From: Alan T. DeKok Date: Thu, 4 Jan 2018 18:24:36 +0000 (-0500) Subject: start of testings without path compression X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6f21ca0ae1b01ed1ff15002cca2f424bb9d7f3b0;p=thirdparty%2Ffreeradius-server.git start of testings without path compression it currently fails when merging nodes of different size, so it's commented out --- diff --git a/src/lib/util/trie.c b/src/lib/util/trie.c index 52a9b8efeb7..0889aa077d2 100644 --- a/src/lib/util/trie.c +++ b/src/lib/util/trie.c @@ -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)); diff --git a/src/tests/trie/.gitignore b/src/tests/trie/.gitignore index 25974e3d69a..d9717c9bbe8 100644 --- a/src/tests/trie/.gitignore +++ b/src/tests/trie/.gitignore @@ -1 +1,2 @@ trie.c +nopc.c diff --git a/src/tests/trie/all.mk b/src/tests/trie/all.mk index 2c44b4fa5ce..64ae18c72a6 100644 --- a/src/tests/trie/all.mk +++ b/src/tests/trie/all.mk @@ -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 index 00000000000..ab57f21024a --- /dev/null +++ b/src/tests/trie/nopc.mk @@ -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 $^ $@ diff --git a/src/tests/trie/test.mk b/src/tests/trie/test.mk index 412cf2f243e..dd39b896a22 100644 --- a/src/tests/trie/test.mk +++ b/src/tests/trie/test.mk @@ -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.