diff options
Diffstat (limited to 'tests/libfstree')
| -rw-r--r-- | tests/libfstree/Makemodule.am | 31 | ||||
| -rw-r--r-- | tests/libfstree/fstree1.txt | 10 | ||||
| -rw-r--r-- | tests/libfstree/fstree_from_dir.c | 381 | ||||
| -rw-r--r-- | tests/libfstree/fstree_from_file.c | 93 | ||||
| -rw-r--r-- | tests/libfstree/fstree_fuzz.c | 34 | ||||
| -rw-r--r-- | tests/libfstree/fstree_glob1.c | 246 | ||||
| -rw-r--r-- | tests/libfstree/fstree_glob1.txt | 2 | ||||
| -rw-r--r-- | tests/libfstree/fstree_glob2.txt | 3 | ||||
| -rw-r--r-- | tests/libfstree/fstree_glob3.txt | 2 | ||||
| -rw-r--r-- | tests/libfstree/sort_file.c | 217 | 
10 files changed, 2 insertions, 1017 deletions
| diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am index 7826cf8..5ae44a6 100644 --- a/tests/libfstree/Makemodule.am +++ b/tests/libfstree/Makemodule.am @@ -25,43 +25,16 @@ test_fstree_sort_SOURCES = tests/libfstree/fstree_sort.c  test_fstree_sort_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree  test_fstree_sort_LDADD = libfstree.a libio.a libutil.a libcompat.a -test_fstree_from_file_SOURCES = tests/libfstree/fstree_from_file.c -test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(FSTDATADIR)/fstree1.txt -test_fstree_from_file_LDADD = libfstree.a libio.a libutil.a libcompat.a - -test_fstree_glob1_SOURCES = tests/libfstree/fstree_glob1.c -test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(FSTDATADIR) -test_fstree_glob1_LDADD = libfstree.a libio.a libutil.a libcompat.a - -test_fstree_from_dir_SOURCES = tests/libfstree/fstree_from_dir.c -test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/libtar/data -test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a -  test_fstree_init_SOURCES = tests/libfstree/fstree_init.c  test_fstree_init_LDADD = libfstree.a libio.a libutil.a libcompat.a -test_sort_file_SOURCES = tests/libfstree/sort_file.c -test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a - -fstree_fuzz_SOURCES = tests/libfstree/fstree_fuzz.c -fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a -  FSTREE_TESTS = \  	test_mknode_simple test_mknode_slink \  	test_mknode_reg test_mknode_dir test_gen_inode_numbers \ -	test_add_by_path test_get_path test_fstree_sort test_fstree_from_file \ -	test_fstree_init test_fstree_from_dir test_fstree_glob1 \ -	test_sort_file +	test_add_by_path test_get_path test_fstree_sort \ +	test_fstree_init  if BUILD_TOOLS  check_PROGRAMS += $(FSTREE_TESTS) -noinst_PROGRAMS += fstree_fuzz -  TESTS += $(FSTREE_TESTS)  endif - -EXTRA_DIST += $(FSTDATADIR)/fstree1.txt -EXTRA_DIST += $(FSTDATADIR)/fstree_glob1.txt $(FSTDATADIR)/fstree_glob2.txt -EXTRA_DIST += $(FSTDATADIR)/fstree_glob3.txt diff --git a/tests/libfstree/fstree1.txt b/tests/libfstree/fstree1.txt deleted file mode 100644 index 95ee469..0000000 --- a/tests/libfstree/fstree1.txt +++ /dev/null @@ -1,10 +0,0 @@ -# comment line -slink /slink 0644 2 3 slinktarget -dir /dir 0755 4 5 -nod /chardev 0600 6 7 c 13 37 -nod /blkdev 0600 8 9 b 42 21 -pipe /pipe 0644 10 11 -dir / 0755 1000 100 -dir "/foo bar" 0755 0 0 -dir "/foo bar/ test \"/" 0755 0 0 -  sock  /sock  0555  12  13  
\ No newline at end of file diff --git a/tests/libfstree/fstree_from_dir.c b/tests/libfstree/fstree_from_dir.c deleted file mode 100644 index 438e357..0000000 --- a/tests/libfstree/fstree_from_dir.c +++ /dev/null @@ -1,381 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_from_dir.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" -#include "util/test.h" - -static void check_hierarchy(tree_node_t *root, bool recursive) -{ -	tree_node_t *n, *m; - -	n = root->data.dir.children; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "CREDITS"); -	TEST_ASSERT(S_ISREG(n->mode)); -	TEST_ASSERT(n->parent == root); - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "file-size"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "12-digit.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "format-acceptance"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu-g.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "link_filled.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "ustar-pre-posix.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "ustar.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "v7.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "large-mtime"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "12-digit.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "long-paths"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "ustar.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "negative-mtime"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "sparse-files"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu-small.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax-gnu0-0.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax-gnu0-1.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax-gnu1-0.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "sqfs.sha512"); -	TEST_ASSERT(S_ISREG(n->mode)); -	TEST_ASSERT(n->parent == root); - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "user-group-largenum"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "8-digit.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "xattr"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == root); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "acl.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "xattr-libarchive.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "xattr-schily-binary.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "xattr-schily.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NULL(n); -} - -int main(int argc, char **argv) -{ -	struct stat sb; -	tree_node_t *n; -	fstree_t fs; -	(void)argc; (void)argv; - -	/* recursively scan into root */ -	TEST_ASSERT(fstree_init(&fs, NULL) == 0); -	TEST_ASSERT(fstree_from_dir(&fs, fs.root, TEST_PATH, -				    NULL, NULL, 0) == 0); - -	fstree_post_process(&fs); -	check_hierarchy(fs.root, true); -	fstree_cleanup(&fs); - -	/* non-recursively scan into root */ -	TEST_ASSERT(fstree_init(&fs, NULL) == 0); -	TEST_ASSERT(fstree_from_dir(&fs, fs.root, TEST_PATH, NULL, NULL, -				    DIR_SCAN_NO_RECURSION) == 0); - -	fstree_post_process(&fs); -	check_hierarchy(fs.root, false); -	fstree_cleanup(&fs); - -	/* recursively scan into a sub-directory of root */ -	memset(&sb, 0, sizeof(sb)); -	sb.st_mode = S_IFDIR | 0755; - -	TEST_ASSERT(fstree_init(&fs, NULL) == 0); - -	n = fstree_mknode(fs.root, "foodir", 6, NULL, &sb); -	TEST_NOT_NULL(n); -	fs.root->data.dir.children = n; - -	TEST_ASSERT(fstree_from_dir(&fs, n, TEST_PATH, NULL, NULL, 0) == 0); - -	TEST_ASSERT(fs.root->data.dir.children == n); -	TEST_NULL(n->next); - -	fstree_post_process(&fs); -	check_hierarchy(n, true); -	fstree_cleanup(&fs); - -	/* non-recursively scan into a sub-directory of root */ -	memset(&sb, 0, sizeof(sb)); -	sb.st_mode = S_IFDIR | 0755; - -	TEST_ASSERT(fstree_init(&fs, NULL) == 0); - -	n = fstree_mknode(fs.root, "foodir", 6, NULL, &sb); -	TEST_NOT_NULL(n); -	fs.root->data.dir.children = n; - -	TEST_ASSERT(fstree_from_dir(&fs, n, TEST_PATH, NULL, NULL, -				    DIR_SCAN_NO_RECURSION) == 0); - -	TEST_ASSERT(fs.root->data.dir.children == n); -	TEST_NULL(n->next); - -	fstree_post_process(&fs); -	check_hierarchy(n, false); -	fstree_cleanup(&fs); - -	return EXIT_SUCCESS; -} diff --git a/tests/libfstree/fstree_from_file.c b/tests/libfstree/fstree_from_file.c deleted file mode 100644 index 184c011..0000000 --- a/tests/libfstree/fstree_from_file.c +++ /dev/null @@ -1,93 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_from_file.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" -#include "util/test.h" - -int main(int argc, char **argv) -{ -	tree_node_t *n; -	fstree_t fs; -	(void)argc; (void)argv; - -	TEST_ASSERT(fstree_init(&fs, NULL) == 0); -	TEST_ASSERT(fstree_from_file(&fs, TEST_PATH, NULL) == 0); - -	fstree_post_process(&fs); -	n = fs.root->data.dir.children; - -	TEST_EQUAL_UI(fs.root->link_count, 9); -	TEST_EQUAL_UI(fs.root->mode, S_IFDIR | 0755); -	TEST_EQUAL_UI(fs.root->uid, 1000); -	TEST_EQUAL_UI(fs.root->gid, 100); - -	TEST_EQUAL_UI(n->mode, S_IFBLK | 0600); -	TEST_EQUAL_UI(n->uid, 8); -	TEST_EQUAL_UI(n->gid, 9); -	TEST_EQUAL_UI(n->link_count, 1); -	TEST_STR_EQUAL(n->name, "blkdev"); -	TEST_EQUAL_UI(n->data.devno, makedev(42, 21)); - -	n = n->next; -	TEST_EQUAL_UI(n->mode, S_IFCHR | 0600); -	TEST_EQUAL_UI(n->uid, 6); -	TEST_EQUAL_UI(n->gid, 7); -	TEST_EQUAL_UI(n->link_count, 1); -	TEST_STR_EQUAL(n->name, "chardev"); -	TEST_EQUAL_UI(n->data.devno, makedev(13, 37)); - -	n = n->next; -	TEST_EQUAL_UI(n->mode, S_IFDIR | 0755); -	TEST_EQUAL_UI(n->uid, 4); -	TEST_EQUAL_UI(n->gid, 5); -	TEST_EQUAL_UI(n->link_count, 2); -	TEST_STR_EQUAL(n->name, "dir"); -	TEST_NULL(n->data.dir.children); - -	n = n->next; -	TEST_EQUAL_UI(n->mode, S_IFDIR | 0755); -	TEST_EQUAL_UI(n->uid, 0); -	TEST_EQUAL_UI(n->gid, 0); -	TEST_EQUAL_UI(n->link_count, 3); -	TEST_STR_EQUAL(n->name, "foo bar"); -	TEST_NOT_NULL(n->data.dir.children); - -	TEST_NULL(n->data.dir.children->next); -	TEST_EQUAL_UI(n->data.dir.children->mode, S_IFDIR | 0755); -	TEST_EQUAL_UI(n->data.dir.children->uid, 0); -	TEST_EQUAL_UI(n->data.dir.children->gid, 0); -	TEST_EQUAL_UI(n->data.dir.children->link_count, 2); -	TEST_STR_EQUAL(n->data.dir.children->name, " test \""); -	TEST_NULL(n->data.dir.children->data.dir.children); - -	n = n->next; -	TEST_EQUAL_UI(n->mode, S_IFIFO | 0644); -	TEST_EQUAL_UI(n->uid, 10); -	TEST_EQUAL_UI(n->gid, 11); -	TEST_EQUAL_UI(n->link_count, 1); -	TEST_STR_EQUAL(n->name, "pipe"); - -	n = n->next; -	TEST_EQUAL_UI(n->mode, S_IFLNK | 0777); -	TEST_EQUAL_UI(n->uid, 2); -	TEST_EQUAL_UI(n->gid, 3); -	TEST_EQUAL_UI(n->link_count, 1); -	TEST_STR_EQUAL(n->name, "slink"); -	TEST_STR_EQUAL(n->data.target, "slinktarget"); - -	n = n->next; -	TEST_EQUAL_UI(n->mode, S_IFSOCK | 0555); -	TEST_EQUAL_UI(n->uid, 12); -	TEST_EQUAL_UI(n->gid, 13); -	TEST_EQUAL_UI(n->link_count, 1); -	TEST_STR_EQUAL(n->name, "sock"); -	TEST_NULL(n->next); - -	fstree_cleanup(&fs); -	return EXIT_SUCCESS; -} diff --git a/tests/libfstree/fstree_fuzz.c b/tests/libfstree/fstree_fuzz.c deleted file mode 100644 index ebc8c45..0000000 --- a/tests/libfstree/fstree_fuzz.c +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_fuzz.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" - -#include <stdlib.h> -#include <stdio.h> - -int main(int argc, char **argv) -{ -	int ret = EXIT_FAILURE; -	fstree_t fs; - -	if (argc != 2) { -		fputs("Usage: fstree_fuzz <input_file>\n", stderr); -		return EXIT_FAILURE; -	} - -	if (fstree_init(&fs, NULL)) -		return EXIT_FAILURE; - -	if (fstree_from_file(&fs, argv[1], NULL)) -		goto out_fs; - -	ret = EXIT_SUCCESS; -out_fs: -	fstree_cleanup(&fs); -	return ret; -} diff --git a/tests/libfstree/fstree_glob1.c b/tests/libfstree/fstree_glob1.c deleted file mode 100644 index 3aff21a..0000000 --- a/tests/libfstree/fstree_glob1.c +++ /dev/null @@ -1,246 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_glob1.c - * - * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" -#include "util/test.h" - -static void check_hierarchy(tree_node_t *root, bool subdir, bool recursive) -{ -	tree_node_t *n, *m, *parentdir; - -	if (subdir) { -		n = root->data.dir.children; -		TEST_NOT_NULL(n); -		TEST_STR_EQUAL(n->name, "tarcorpus"); -		TEST_ASSERT(S_ISDIR(n->mode)); -		TEST_ASSERT(n->parent == root); -		TEST_NULL(n->next); -	} else { -		n = root; -		TEST_NOT_NULL(n); -		TEST_STR_EQUAL(n->name, ""); -		TEST_ASSERT(S_ISDIR(n->mode)); -		TEST_NULL(n->parent); -		TEST_NULL(n->next); -	} - -	parentdir = n; -	n = n->data.dir.children; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "file-size"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "format-acceptance"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu-g.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "large-mtime"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "long-paths"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "negative-mtime"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "sparse-files"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu-small.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax-gnu0-0.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax-gnu0-1.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "pax-gnu1-0.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "user-group-largenum"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); - -	if (recursive) { -		m = n->data.dir.children; -		TEST_NOT_NULL(m); -		TEST_STR_EQUAL(m->name, "gnu.tar"); -		TEST_ASSERT(S_ISREG(m->mode)); -		TEST_ASSERT(m->parent == n); - -		m = m->next; -		TEST_NULL(m); -	} else { -		TEST_NULL(n->data.dir.children); -	} - -	n = n->next; -	TEST_NOT_NULL(n); -	TEST_STR_EQUAL(n->name, "xattr"); -	TEST_ASSERT(S_ISDIR(n->mode)); -	TEST_ASSERT(n->parent == parentdir); -	TEST_NULL(n->data.dir.children); - -	n = n->next; -	TEST_NULL(n); -} - -int main(int argc, char **argv) -{ -	fstree_t fs; -	int ret; -	(void)argc; (void)argv; - -	/* first test case, directory tree only */ -	ret = fstree_init(&fs, NULL); -	TEST_EQUAL_I(ret, 0); - -	ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob1.txt", TEST_PATH); -	TEST_EQUAL_I(ret, 0); - -	fstree_post_process(&fs); -	check_hierarchy(fs.root, true, false); -	fstree_cleanup(&fs); - -	/* first test case, directory tree plus fnmatch()ed files */ -	ret = fstree_init(&fs, NULL); -	TEST_EQUAL_I(ret, 0); - -	ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob2.txt", TEST_PATH); -	TEST_EQUAL_I(ret, 0); - -	fstree_post_process(&fs); -	check_hierarchy(fs.root, true, true); -	fstree_cleanup(&fs); - -	/* third test case, same as second, but entries directly at the root */ -	ret = fstree_init(&fs, NULL); -	TEST_EQUAL_I(ret, 0); - -	ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob3.txt", TEST_PATH); -	TEST_EQUAL_I(ret, 0); - -	fstree_post_process(&fs); -	check_hierarchy(fs.root, false, true); -	fstree_cleanup(&fs); -	return EXIT_SUCCESS; -} diff --git a/tests/libfstree/fstree_glob1.txt b/tests/libfstree/fstree_glob1.txt deleted file mode 100644 index b1df979..0000000 --- a/tests/libfstree/fstree_glob1.txt +++ /dev/null @@ -1,2 +0,0 @@ -dir /tarcorpus 0755 0 0 -glob /tarcorpus 0755 0 0 -type d -- ../libtar/data diff --git a/tests/libfstree/fstree_glob2.txt b/tests/libfstree/fstree_glob2.txt deleted file mode 100644 index 3c8019b..0000000 --- a/tests/libfstree/fstree_glob2.txt +++ /dev/null @@ -1,3 +0,0 @@ -dir /tarcorpus 0755 0 0 -glob /tarcorpus 0755 0 0 -type d ../libtar/data -glob /tarcorpus 0644 0 0 -type f -name "*gnu*.tar" -- ../libtar/data diff --git a/tests/libfstree/fstree_glob3.txt b/tests/libfstree/fstree_glob3.txt deleted file mode 100644 index 35090e4..0000000 --- a/tests/libfstree/fstree_glob3.txt +++ /dev/null @@ -1,2 +0,0 @@ -glob / 0755 0 0 -type d ../libtar/data -glob / 0644 0 0 -type f -name "*gnu*.tar" -- ../libtar/data diff --git a/tests/libfstree/sort_file.c b/tests/libfstree/sort_file.c deleted file mode 100644 index 78d1606..0000000 --- a/tests/libfstree/sort_file.c +++ /dev/null @@ -1,217 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * sort_file.c - * - * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "sqfs/block.h" -#include "fstree.h" -#include "util/test.h" -#include "util/util.h" - -static const char *listing = -"dir /bin 0755 0 0\n" -"dir /lib 0755 0 0\n" -"dir /usr 0755 0 0\n" -"dir /usr/share 0755 0 0\n" -"\n" -"file /bin/chown 0755 0 0\n" -"file /bin/ls 0755 0 0\n" -"file /bin/chmod 0755 0 0\n" -"file /bin/dir 0755 0 0\n" -"file /bin/cp 0755 0 0\n" -"file /bin/dd 0755 0 0\n" -"file /bin/ln 0755 0 0\n" -"file /bin/mkdir 0755 0 0\n" -"file /bin/mknod 0755 0 0\n" -"\n" -"file /lib/libssl.so 0755 0 0\n" -"file /lib/libfoobar.so 0755 0 0\n" -"file /lib/libwhatever.so 0755 0 0\n" -"\n" -"file /usr/share/bla.txt 0644 0 0\n"; - -static const char *sort_file = -"# Blockwise reverse the order of the /bin files\n" -"  10 [glob] /bin/mk*\n" -"  20 [glob] /bin/ch*\n" -"  30 [glob] /bin/d*\n" -"  40        /bin/cp\n" -"  50 [glob] /bin/*\n" -"\n" -"# Make this file appear first\n" -"  -10000 [dont_compress,dont_fragment,align] /usr/share/bla.txt"; - -static const char *initial_order[] = { -	"bin/chmod", -	"bin/chown", -	"bin/cp", -	"bin/dd", -	"bin/dir", -	"bin/ln", -	"bin/ls", -	"bin/mkdir", -	"bin/mknod", -	"lib/libfoobar.so", -	"lib/libssl.so", -	"lib/libwhatever.so", -	"usr/share/bla.txt", -}; - -static const char *after_sort_order[] = { -	"usr/share/bla.txt", -	"lib/libfoobar.so", -	"lib/libssl.so", -	"lib/libwhatever.so", -	"bin/mkdir", -	"bin/mknod", -	"bin/chmod", -	"bin/chown", -	"bin/dd", -	"bin/dir", -	"bin/cp", -	"bin/ln", -	"bin/ls", -}; - -static sqfs_s64 priorities[] = { -	-10000, -	0, -	0, -	0, -	10, -	10, -	20, -	20, -	30, -	30, -	40, -	50, -	50, -}; - -static int flags[] = { -	SQFS_BLK_DONT_COMPRESS | SQFS_BLK_ALIGN | SQFS_BLK_DONT_FRAGMENT, -	0, -	0, -	0, -	0, -	0, -	0, -	0, -	0, -	0, -	0, -	0, -	0, -}; - -/*****************************************************************************/ - -static sqfs_u8 temp_buffer[2048]; -static const char *input_file = NULL; - -static void destroy_noop(sqfs_object_t *obj) -{ -	(void)obj; -} - -static int memfile_load(istream_t *strm) -{ -	strcpy((char *)temp_buffer, input_file); -	strm->eof = true; -	strm->buffer_used = strlen(input_file); -	return 0; -} - -static const char *get_filename(istream_t *strm) -{ -	(void)strm; -	return "memstream"; -} - -static istream_t memstream = { -	.base = { -		.destroy = destroy_noop, -	}, - -	.buffer_used = 0, -	.buffer_offset = 0, -	.eof = false, -	.buffer = temp_buffer, - -	.precache = memfile_load, -	.get_filename = get_filename, -}; - -/*****************************************************************************/ - -int main(int argc, char **argv) -{ -	file_info_t *fi; -	fstree_t fs; -	size_t i; -	(void)argc; (void)argv; - -	input_file = listing; -	memstream.buffer_used = 0; -	memstream.buffer_offset = 0; -	memstream.eof = false; - -	TEST_ASSERT(fstree_init(&fs, NULL) == 0); -	TEST_ASSERT(fstree_from_file_stream(&fs, &memstream, NULL) == 0); - -	fstree_post_process(&fs); - -	for (i = 0, fi = fs.files; fi != NULL; fi = fi->next, ++i) { -		tree_node_t *n = container_of(fi, tree_node_t, data.file); -		char *path = fstree_get_path(n); -		int ret; - -		TEST_NOT_NULL(path); - -		ret = canonicalize_name(path); -		TEST_EQUAL_I(ret, 0); - -		TEST_STR_EQUAL(initial_order[i], path); -		free(path); - -		TEST_EQUAL_I(fi->priority, 0); -		TEST_EQUAL_I(fi->flags, 0); -	} - -	TEST_EQUAL_UI(i, sizeof(initial_order) / sizeof(initial_order[0])); - - -	input_file = sort_file; -	memstream.buffer_used = 0; -	memstream.buffer_offset = 0; -	memstream.eof = false; - -	TEST_ASSERT(fstree_sort_files(&fs, &memstream) == 0); - -	for (i = 0, fi = fs.files; fi != NULL; fi = fi->next, ++i) { -		tree_node_t *n = container_of(fi, tree_node_t, data.file); -		char *path = fstree_get_path(n); -		int ret; - -		TEST_NOT_NULL(path); - -		ret = canonicalize_name(path); -		TEST_EQUAL_I(ret, 0); - -		TEST_STR_EQUAL(after_sort_order[i], path); -		free(path); - -		TEST_EQUAL_I(fi->priority, priorities[i]); -		TEST_EQUAL_I(fi->flags, flags[i]); -	} - -	TEST_EQUAL_UI(i, sizeof(after_sort_order) / -		      sizeof(after_sort_order[0])); - -	fstree_cleanup(&fs); -	return EXIT_SUCCESS; -} | 
