From caf350448c0020f95b9bfdd65770d86faf548549 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 15 Dec 2019 19:29:34 +0100 Subject: Remove fstree inode table Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 8 ++-- tests/gen_inode_numbers.c | 92 +++++++++++++++++++++++++++++++++++++++++++ tests/gen_inode_table.c | 99 ----------------------------------------------- 3 files changed, 96 insertions(+), 103 deletions(-) create mode 100644 tests/gen_inode_numbers.c delete mode 100644 tests/gen_inode_table.c (limited to 'tests') diff --git a/tests/Makemodule.am b/tests/Makemodule.am index fc27de0..2fb7654 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -27,8 +27,8 @@ test_mknode_reg_LDADD = libfstree.a libcompat.a test_mknode_dir_SOURCES = tests/mknode_dir.c test_mknode_dir_LDADD = libfstree.a libcompat.a -test_gen_inode_table_SOURCES = tests/gen_inode_table.c -test_gen_inode_table_LDADD = libfstree.a libcompat.a +test_gen_inode_numbers_SOURCES = tests/gen_inode_numbers.c +test_gen_inode_numbers_LDADD = libfstree.a libcompat.a test_add_by_path_SOURCES = tests/add_by_path.c test_add_by_path_LDADD = libfstree.a libcompat.a @@ -93,7 +93,7 @@ tar_fuzz_SOURCES = tests/tar_fuzz.c tar_fuzz_LDADD = libtar.a libcompat.a check_PROGRAMS += test_mknode_simple test_mknode_slink test_mknode_reg -check_PROGRAMS += test_mknode_dir test_gen_inode_table test_add_by_path +check_PROGRAMS += test_mknode_dir test_gen_inode_numbers test_add_by_path check_PROGRAMS += test_get_path test_fstree_sort test_fstree_from_file check_PROGRAMS += test_fstree_init test_tar_ustar test_tar_pax test_tar_gnu check_PROGRAMS += test_tar_sparse_gnu test_tar_sparse_gnu1 test_tar_sparse_gnu2 @@ -104,7 +104,7 @@ check_SCRIPTS += tests/cantrbry.sh tests/test_tar_sqfs.sh noinst_PROGRAMS += fstree_fuzz tar_fuzz TESTS += test_mknode_simple test_mknode_slink -TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table +TESTS += test_mknode_reg test_mknode_dir test_gen_inode_numbers TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file TESTS += test_fstree_init test_tar_ustar test_tar_pax TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1 diff --git a/tests/gen_inode_numbers.c b/tests/gen_inode_numbers.c new file mode 100644 index 0000000..e16abbe --- /dev/null +++ b/tests/gen_inode_numbers.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * gen_inode_table.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" + +#include +#include +#include + +static tree_node_t *gen_node(tree_node_t *parent, const char *name) +{ + struct stat sb; + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0755; + + return fstree_mknode(parent, name, strlen(name), NULL, &sb); +} + +static void check_children_before_root(tree_node_t *root) +{ + tree_node_t *n; + + for (n = root->data.dir.children; n != NULL; n = n->next) + assert(n->inode_num < root->inode_num); + + for (n = root->data.dir.children; n != NULL; n = n->next) + check_children_before_root(n); +} + +static void check_children_continuous(tree_node_t *root) +{ + tree_node_t *n; + + for (n = root->data.dir.children; n != NULL; n = n->next) { + if (n->next != NULL) { + assert(n->next->inode_num == (n->inode_num + 1)); + } + } + + for (n = root->data.dir.children; n != NULL; n = n->next) + check_children_continuous(n); +} + +int main(void) +{ + tree_node_t *a, *b, *c; + fstree_t fs; + + // inode table for the empty tree + assert(fstree_init(&fs, NULL) == 0); + fstree_gen_inode_numbers(&fs); + assert(fs.unique_inode_count == 1); + assert(fs.root->inode_num == 1); + fstree_cleanup(&fs); + + // tree with 2 levels under root, fan out 3 + assert(fstree_init(&fs, NULL) == 0); + + a = gen_node(fs.root, "a"); + b = gen_node(fs.root, "b"); + c = gen_node(fs.root, "c"); + assert(a != NULL); + assert(b != NULL); + assert(c != NULL); + + assert(gen_node(a, "a_a") != NULL); + assert(gen_node(a, "a_b") != NULL); + assert(gen_node(a, "a_c") != NULL); + + assert(gen_node(b, "b_a") != NULL); + assert(gen_node(b, "b_b") != NULL); + assert(gen_node(b, "b_c") != NULL); + + assert(gen_node(c, "c_a") != NULL); + assert(gen_node(c, "c_b") != NULL); + assert(gen_node(c, "c_c") != NULL); + + fstree_gen_inode_numbers(&fs); + assert(fs.unique_inode_count == 13); + + check_children_before_root(fs.root); + check_children_continuous(fs.root); + + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} diff --git a/tests/gen_inode_table.c b/tests/gen_inode_table.c deleted file mode 100644 index d70f463..0000000 --- a/tests/gen_inode_table.c +++ /dev/null @@ -1,99 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * gen_inode_table.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" - -#include -#include -#include - -static tree_node_t *gen_node(tree_node_t *parent, const char *name) -{ - struct stat sb; - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0755; - - return fstree_mknode(parent, name, strlen(name), NULL, &sb); -} - -static void check_children_before_root(tree_node_t *root) -{ - tree_node_t *n; - - for (n = root->data.dir.children; n != NULL; n = n->next) - assert(n->inode_num < root->inode_num); - - for (n = root->data.dir.children; n != NULL; n = n->next) - check_children_before_root(n); -} - -static void check_children_continuous(tree_node_t *root) -{ - tree_node_t *n; - - for (n = root->data.dir.children; n != NULL; n = n->next) { - if (n->next != NULL) { - assert(n->next->inode_num == (n->inode_num + 1)); - } - } - - for (n = root->data.dir.children; n != NULL; n = n->next) - check_children_continuous(n); -} - -int main(void) -{ - tree_node_t *a, *b, *c; - unsigned int i; - fstree_t fs; - - // inode table for the empty tree - assert(fstree_init(&fs, NULL) == 0); - assert(fstree_gen_inode_table(&fs) == 0); - assert(fs.inode_tbl_size == 1); - assert(fs.root->inode_num == 1); - assert(fs.inode_table[0] == fs.root); - fstree_cleanup(&fs); - - // tree with 2 levels under root, fan out 3 - assert(fstree_init(&fs, NULL) == 0); - - a = gen_node(fs.root, "a"); - b = gen_node(fs.root, "b"); - c = gen_node(fs.root, "c"); - assert(a != NULL); - assert(b != NULL); - assert(c != NULL); - - assert(gen_node(a, "a_a") != NULL); - assert(gen_node(a, "a_b") != NULL); - assert(gen_node(a, "a_c") != NULL); - - assert(gen_node(b, "b_a") != NULL); - assert(gen_node(b, "b_b") != NULL); - assert(gen_node(b, "b_c") != NULL); - - assert(gen_node(c, "c_a") != NULL); - assert(gen_node(c, "c_b") != NULL); - assert(gen_node(c, "c_c") != NULL); - - assert(fstree_gen_inode_table(&fs) == 0); - assert(fs.inode_tbl_size == 13); - - for (i = 0; i < 13; ++i) { - assert(fs.inode_table[i] != NULL); - assert(fs.inode_table[i]->inode_num == i + 1); - } - - check_children_before_root(fs.root); - check_children_continuous(fs.root); - - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} -- cgit v1.2.3