diff --git a/Makefile.am b/Makefile.am index f9b8835..bb264ff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,14 +6,16 @@ SUBDIRS = include #libutreexo_cpp_la_SOURCES = include/cpp/utreexo.cpp #libutreexo_cpp_la_LDFLAGS = -version-info 0:1:0 -check_PROGRAMS = test_flat_file test_forest test_leaf_map +check_PROGRAMS = test_flat_file test_forest test_leaf_map test_utils -test_flat_file_SOURCES = src/test_flat_file.c +test_flat_file_SOURCES = tests/test_flat_file.c -test_leaf_map_SOURCES = src/test_leaf_map.c +test_leaf_map_SOURCES = tests/test_leaf_map.c -test_forest_SOURCES = src/forest_test.c +test_forest_SOURCES = tests/test_forest.c test_forest_LDADD = libutreexo.la -lcrypto +test_utils_SOURCES = src/util.h tests/test_util_methods.c + lib_LTLIBRARIES = libutreexo.la libutreexo_la_SOURCES = src/mmap_forest.c diff --git a/contrib/format.sh b/contrib/format.sh index be78b8a..114d6df 100644 --- a/contrib/format.sh +++ b/contrib/format.sh @@ -2,7 +2,7 @@ set -e -for file in $(find src/ include/ -name *.[h,c]) +for file in $(find src/ include/ tests/ -name *.[h,c]) do clang-format -i $file done diff --git a/src/leaf_map_impl.h b/src/leaf_map_impl.h index de2b7e5..a6afa52 100644 --- a/src/leaf_map_impl.h +++ b/src/leaf_map_impl.h @@ -93,9 +93,9 @@ static inline void utreexo_leaf_map_set(utreexo_leaf_map *map, do { position = utreexo_leaf_map_get_pos(hash); ++hash; - + pread(map->fd, &pnode, sizeof(utreexo_forest_node **), position); - + if (pnode == NULL) break; } while (1); @@ -121,7 +121,7 @@ static inline void utreexo_leaf_map_delete(utreexo_leaf_map *map, ++hash; pread(map->fd, &pnode, sizeof(utreexo_forest_node *), position); - + if (pnode == utreexo_thumbstone) continue; diff --git a/src/util.h b/src/util.h index 2fc8b7d..3ca0e98 100644 --- a/src/util.h +++ b/src/util.h @@ -73,9 +73,9 @@ static inline node_offset detect_offset(uint64_t pos, uint64_t num_leaves) { tr -= 1; } return (node_offset){ - .bits = pos, .tree = (uint8_t)bigger_trees, .depth = (uint8_t)(tr - nr), + .bits = !pos, }; } diff --git a/src/test_flat_file.c b/tests/test_flat_file.c similarity index 100% rename from src/test_flat_file.c rename to tests/test_flat_file.c diff --git a/src/forest_test.c b/tests/test_forest.c similarity index 99% rename from src/forest_test.c rename to tests/test_forest.c index a97b9f5..1c86337 100644 --- a/src/forest_test.c +++ b/tests/test_forest.c @@ -14,7 +14,7 @@ static inline struct utreexo_forest get_test_forest(const char *filename) { void *heap = NULL; struct utreexo_forest_file *file = NULL; - + char forest_name[100]; sprintf(forest_name, "forest_%s", filename); utreexo_forest_file_init(&file, &heap, forest_name); @@ -164,7 +164,8 @@ void test_add_single() { utreexo_forest_file_init(&file, &heap, "forest_add_single.bin"); utreexo_leaf_map leaf_map; - utreexo_leaf_map_new(&leaf_map, "forest_leaves_single.bin", O_CREAT | O_RDWR, NULL); + utreexo_leaf_map_new(&leaf_map, "forest_leaves_single.bin", O_CREAT | O_RDWR, + NULL); struct utreexo_forest p = { .data = file, diff --git a/src/test_leaf_map.c b/tests/test_leaf_map.c similarity index 100% rename from src/test_leaf_map.c rename to tests/test_leaf_map.c diff --git a/src/test_util_methods.c b/tests/test_util_methods.c similarity index 97% rename from src/test_util_methods.c rename to tests/test_util_methods.c index 0a9e7ad..97f1745 100644 --- a/src/test_util_methods.c +++ b/tests/test_util_methods.c @@ -2,7 +2,7 @@ #include #include "test_utils.h" -#include "util.h" +#include void test_tree_rows() { ASSERT_EQ(tree_rows(8), 3); diff --git a/src/test_utils.h b/tests/test_utils.h similarity index 100% rename from src/test_utils.h rename to tests/test_utils.h