summaryrefslogtreecommitdiff
path: root/tests/gensquashfs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gensquashfs')
-rw-r--r--tests/gensquashfs/Makemodule.am48
-rw-r--r--tests/gensquashfs/fstree1.txt10
-rw-r--r--tests/gensquashfs/fstree_from_dir.c381
-rw-r--r--tests/gensquashfs/fstree_from_file.c93
-rw-r--r--tests/gensquashfs/fstree_fuzz.c34
-rw-r--r--tests/gensquashfs/fstree_glob1.c246
-rw-r--r--tests/gensquashfs/fstree_glob1.txt2
-rw-r--r--tests/gensquashfs/fstree_glob2.txt3
-rw-r--r--tests/gensquashfs/fstree_glob3.txt2
-rw-r--r--tests/gensquashfs/sort_file.c217
10 files changed, 1033 insertions, 3 deletions
diff --git a/tests/gensquashfs/Makemodule.am b/tests/gensquashfs/Makemodule.am
index a20e6ef..c1ab164 100644
--- a/tests/gensquashfs/Makemodule.am
+++ b/tests/gensquashfs/Makemodule.am
@@ -8,13 +8,55 @@ test_filemap_xattr_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/xattr1.txt
test_filemap_xattr_LDADD = libsquashfs.la libfstree.a libutil.a
test_filemap_xattr_LDADD += libio.a libcompat.a
+test_fstree_from_file_SOURCES = tests/gensquashfs/fstree_from_file.c \
+ bin/gensquashfs/fstree_from_file.c \
+ bin/gensquashfs/fstree_from_dir.c \
+ bin/gensquashfs/mkfs.h
+test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs
+test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/fstree1.txt
+test_fstree_from_file_LDADD = libfstree.a libio.a libutil.a libcompat.a
+
+test_fstree_glob1_SOURCES = tests/gensquashfs/fstree_glob1.c \
+ bin/gensquashfs/fstree_from_file.c \
+ bin/gensquashfs/fstree_from_dir.c \
+ bin/gensquashfs/mkfs.h
+test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs
+test_fstree_glob1_CPPFLAGS += -DTESTPATH=$(GENDATADIR)
+test_fstree_glob1_LDADD = libfstree.a libio.a libutil.a libcompat.a
+
+test_fstree_from_dir_SOURCES = tests/gensquashfs/fstree_from_dir.c \
+ bin/gensquashfs/fstree_from_dir.c \
+ bin/gensquashfs/mkfs.h
+test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs
+test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/libtar/data
+test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a
+
+test_sort_file_SOURCES = tests/gensquashfs/sort_file.c \
+ bin/gensquashfs/fstree_from_file.c \
+ bin/gensquashfs/fstree_from_dir.c \
+ bin/gensquashfs/sort_by_file.c \
+ bin/gensquashfs/mkfs.h
+test_sort_file_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs
+test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a
+
+fstree_fuzz_SOURCES = tests/gensquashfs/fstree_fuzz.c \
+ bin/gensquashfs/fstree_from_file.c \
+ bin/gensquashfs/fstree_from_dir.c \
+ bin/gensquashfs/mkfs.h
+fstree_fuzz_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs
+fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a
+
GENSQUASHFS_TESTS = \
- test_filemap_xattr
+ test_filemap_xattr test_fstree_from_file test_fstree_from_dir \
+ test_fstree_glob1 test_sort_file
if BUILD_TOOLS
+noinst_PROGRAMS += fstree_fuzz
+
check_PROGRAMS += $(GENSQUASHFS_TESTS)
TESTS += $(GENSQUASHFS_TESTS)
endif
-EXTRA_DIST += $(GENDATADIR)/xattr1.txt
-
+EXTRA_DIST += $(GENDATADIR)/xattr1.txt $(GENDATADIR)/fstree1.txt
+EXTRA_DIST += $(GENDATADIR)/fstree_glob1.txt $(GENDATADIR)/fstree_glob2.txt
+EXTRA_DIST += $(GENDATADIR)/fstree_glob3.txt
diff --git a/tests/gensquashfs/fstree1.txt b/tests/gensquashfs/fstree1.txt
new file mode 100644
index 0000000..95ee469
--- /dev/null
+++ b/tests/gensquashfs/fstree1.txt
@@ -0,0 +1,10 @@
+# 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/gensquashfs/fstree_from_dir.c b/tests/gensquashfs/fstree_from_dir.c
new file mode 100644
index 0000000..2799bf3
--- /dev/null
+++ b/tests/gensquashfs/fstree_from_dir.c
@@ -0,0 +1,381 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_from_dir.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "util/test.h"
+#include "mkfs.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/gensquashfs/fstree_from_file.c b/tests/gensquashfs/fstree_from_file.c
new file mode 100644
index 0000000..2a9ba1e
--- /dev/null
+++ b/tests/gensquashfs/fstree_from_file.c
@@ -0,0 +1,93 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_from_file.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "util/test.h"
+#include "mkfs.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/gensquashfs/fstree_fuzz.c b/tests/gensquashfs/fstree_fuzz.c
new file mode 100644
index 0000000..4fbb72b
--- /dev/null
+++ b/tests/gensquashfs/fstree_fuzz.c
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_fuzz.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "mkfs.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/gensquashfs/fstree_glob1.c b/tests/gensquashfs/fstree_glob1.c
new file mode 100644
index 0000000..fbcbf91
--- /dev/null
+++ b/tests/gensquashfs/fstree_glob1.c
@@ -0,0 +1,246 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_glob1.c
+ *
+ * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "util/test.h"
+#include "mkfs.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/gensquashfs/fstree_glob1.txt b/tests/gensquashfs/fstree_glob1.txt
new file mode 100644
index 0000000..b1df979
--- /dev/null
+++ b/tests/gensquashfs/fstree_glob1.txt
@@ -0,0 +1,2 @@
+dir /tarcorpus 0755 0 0
+glob /tarcorpus 0755 0 0 -type d -- ../libtar/data
diff --git a/tests/gensquashfs/fstree_glob2.txt b/tests/gensquashfs/fstree_glob2.txt
new file mode 100644
index 0000000..3c8019b
--- /dev/null
+++ b/tests/gensquashfs/fstree_glob2.txt
@@ -0,0 +1,3 @@
+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/gensquashfs/fstree_glob3.txt b/tests/gensquashfs/fstree_glob3.txt
new file mode 100644
index 0000000..35090e4
--- /dev/null
+++ b/tests/gensquashfs/fstree_glob3.txt
@@ -0,0 +1,2 @@
+glob / 0755 0 0 -type d ../libtar/data
+glob / 0644 0 0 -type f -name "*gnu*.tar" -- ../libtar/data
diff --git a/tests/gensquashfs/sort_file.c b/tests/gensquashfs/sort_file.c
new file mode 100644
index 0000000..951328e
--- /dev/null
+++ b/tests/gensquashfs/sort_file.c
@@ -0,0 +1,217 @@
+/* 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 "util/test.h"
+#include "util/util.h"
+#include "mkfs.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;
+}