summaryrefslogtreecommitdiff
path: root/tests/libfstree/fstree_from_dir.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-22 14:45:32 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-22 14:45:32 +0100
commit168ef9be32ad754d7bcb38ed70787237fc12630d (patch)
tree39d567fa667b2f170783329a07481769dd538d43 /tests/libfstree/fstree_from_dir.c
parent61a0dd71c4b69c21ee4aacdc0459dba58504a24a (diff)
Move gensquashfs specific code from libfstree to gensquashfs
The "from dir" and from "from file" code, as well as the "sort file" code is specific to gensquashfs, so move them there and the test cases as well. The medium term idea is to reduce libfstree to a stub, merge it into the generic writer and ultimately hoist that into libsquashfs. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libfstree/fstree_from_dir.c')
-rw-r--r--tests/libfstree/fstree_from_dir.c381
1 files changed, 0 insertions, 381 deletions
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;
-}