From 72c8155d9fc0eaeac72c053f46ebb7b231d4596a Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 31 Jan 2023 11:30:46 +0100 Subject: Reintegrate test code with library code Signed-off-by: David Oberhollenzer --- tests/gensquashfs/Makemodule.am | 63 --------- tests/gensquashfs/filemap_xattr.c | 98 ------------- tests/gensquashfs/fstree1.txt | 10 -- tests/gensquashfs/fstree_from_dir.c | 178 ------------------------ tests/gensquashfs/fstree_from_file.c | 93 ------------- tests/gensquashfs/fstree_fuzz.c | 34 ----- tests/gensquashfs/fstree_glob1.c | 246 --------------------------------- tests/gensquashfs/fstree_glob1.txt | 2 - tests/gensquashfs/fstree_glob2.txt | 3 - tests/gensquashfs/fstree_glob3.txt | 2 - tests/gensquashfs/sort_file.c | 217 ----------------------------- tests/gensquashfs/testdir/dira/file_a0 | 0 tests/gensquashfs/testdir/dira/file_a1 | 0 tests/gensquashfs/testdir/dira/file_a2 | 0 tests/gensquashfs/testdir/dirb/file_b0 | 0 tests/gensquashfs/testdir/dirb/file_b1 | 0 tests/gensquashfs/testdir/dirb/file_b2 | 0 tests/gensquashfs/testdir/dirc/file_c0 | 0 tests/gensquashfs/testdir/dirc/file_c1 | 0 tests/gensquashfs/testdir/dirc/file_c2 | 0 tests/gensquashfs/xattr1.txt | 9 -- 21 files changed, 955 deletions(-) delete mode 100644 tests/gensquashfs/Makemodule.am delete mode 100644 tests/gensquashfs/filemap_xattr.c delete mode 100644 tests/gensquashfs/fstree1.txt delete mode 100644 tests/gensquashfs/fstree_from_dir.c delete mode 100644 tests/gensquashfs/fstree_from_file.c delete mode 100644 tests/gensquashfs/fstree_fuzz.c delete mode 100644 tests/gensquashfs/fstree_glob1.c delete mode 100644 tests/gensquashfs/fstree_glob1.txt delete mode 100644 tests/gensquashfs/fstree_glob2.txt delete mode 100644 tests/gensquashfs/fstree_glob3.txt delete mode 100644 tests/gensquashfs/sort_file.c delete mode 100644 tests/gensquashfs/testdir/dira/file_a0 delete mode 100644 tests/gensquashfs/testdir/dira/file_a1 delete mode 100644 tests/gensquashfs/testdir/dira/file_a2 delete mode 100644 tests/gensquashfs/testdir/dirb/file_b0 delete mode 100644 tests/gensquashfs/testdir/dirb/file_b1 delete mode 100644 tests/gensquashfs/testdir/dirb/file_b2 delete mode 100644 tests/gensquashfs/testdir/dirc/file_c0 delete mode 100644 tests/gensquashfs/testdir/dirc/file_c1 delete mode 100644 tests/gensquashfs/testdir/dirc/file_c2 delete mode 100644 tests/gensquashfs/xattr1.txt (limited to 'tests/gensquashfs') diff --git a/tests/gensquashfs/Makemodule.am b/tests/gensquashfs/Makemodule.am deleted file mode 100644 index 9dd9d76..0000000 --- a/tests/gensquashfs/Makemodule.am +++ /dev/null @@ -1,63 +0,0 @@ -GENDATADIR=$(top_srcdir)/tests/gensquashfs - -test_filemap_xattr_SOURCES = tests/gensquashfs/filemap_xattr.c \ - bin/gensquashfs/src/filemap_xattr.c \ - bin/gensquashfs/src/mkfs.h -test_filemap_xattr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src -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/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ - bin/gensquashfs/src/mkfs.h -test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_file_CPPFLAGS += -I$(top_srcdir)/bin/gensquashfs/src -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/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ - bin/gensquashfs/src/mkfs.h -test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src -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/src/fstree_from_dir.c \ - bin/gensquashfs/src/mkfs.h -test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_dir_CPPFLAGS += -I$(top_srcdir)/bin/gensquashfs/src -test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/testdir -test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a - -test_sort_file_SOURCES = tests/gensquashfs/sort_file.c \ - bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ - bin/gensquashfs/src/sort_by_file.c \ - bin/gensquashfs/src/mkfs.h -test_sort_file_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src -test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a - -fstree_fuzz_SOURCES = tests/gensquashfs/fstree_fuzz.c \ - bin/gensquashfs/src/fstree_from_file.c \ - bin/gensquashfs/src/fstree_from_dir.c \ - bin/gensquashfs/src/mkfs.h -fstree_fuzz_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src -fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a - -GENSQUASHFS_TESTS = \ - test_filemap_xattr test_fstree_from_file test_fstree_from_dir \ - test_fstree_glob1 test_sort_file - -noinst_PROGRAMS += fstree_fuzz - -check_PROGRAMS += $(GENSQUASHFS_TESTS) -TESTS += $(GENSQUASHFS_TESTS) - -EXTRA_DIST += $(GENDATADIR)/xattr1.txt $(GENDATADIR)/fstree1.txt -EXTRA_DIST += $(GENDATADIR)/fstree_glob1.txt $(GENDATADIR)/fstree_glob2.txt -EXTRA_DIST += $(GENDATADIR)/fstree_glob3.txt -EXTRA_DIST += $(GENDATADIR)/testdir diff --git a/tests/gensquashfs/filemap_xattr.c b/tests/gensquashfs/filemap_xattr.c deleted file mode 100644 index d258d89..0000000 --- a/tests/gensquashfs/filemap_xattr.c +++ /dev/null @@ -1,98 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * filemap_xattr.c - * - * Copyright (C) 2022 David Oberhollenzer - */ -#include "config.h" - -#include "util/test.h" -#include "mkfs.h" - -static const char *dev_selinux = "system_u:object_r:device_t:s0"; -static const char *zero_selinux = "system_u:object_r:zero_device_t:s0"; -static const char *rfkill_selinux = "system_u:object_r:wireless_device_t:s0"; - -static const sqfs_u8 rfkill_acl[] = { - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x06, 0x00, - 0xe8, 0x03, 0x00, 0x00, 0x04, 0x00, 0x06, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x06, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x20, 0x00, 0x04, 0x00, - 0xff, 0xff, 0xff, 0xff -}; - -int main(int argc, char **argv) -{ - struct XattrMapPattern *pat; - struct XattrMapEntry *ent; - struct XattrMap *map; - int ret; - (void)argc; (void)argv; - - map = xattr_open_map_file(TEST_PATH); - TEST_NOT_NULL(map); - - /* the third pattern */ - pat = map->patterns; - TEST_NOT_NULL(pat); - TEST_STR_EQUAL(pat->path, "dev/rfkill"); - - ent = pat->entries; - TEST_NOT_NULL(ent); - TEST_STR_EQUAL(ent->key, "system.posix_acl_access"); - - TEST_EQUAL_UI(ent->value_len, sizeof(rfkill_acl)); - ret = memcmp(ent->value, rfkill_acl, ent->value_len); - TEST_EQUAL_I(ret, 0); - - ent = ent->next; - TEST_NOT_NULL(ent); - TEST_STR_EQUAL(ent->key, "security.selinux"); - - TEST_EQUAL_UI(ent->value_len, strlen(rfkill_selinux)); - ret = memcmp(ent->value, rfkill_selinux, ent->value_len); - TEST_EQUAL_I(ret, 0); - - ent = ent->next; - TEST_NULL(ent); - - /* the second pattern */ - pat = pat->next; - TEST_NOT_NULL(pat); - TEST_STR_EQUAL(pat->path, "dev/zero"); - - ent = pat->entries; - TEST_NOT_NULL(ent); - TEST_STR_EQUAL(ent->key, "security.selinux"); - - TEST_EQUAL_UI(ent->value_len, strlen(zero_selinux)); - ret = memcmp(ent->value, zero_selinux, ent->value_len); - TEST_EQUAL_I(ret, 0); - - ent = ent->next; - TEST_NULL(ent); - - /* the first pattern */ - pat = pat->next; - TEST_NOT_NULL(pat); - TEST_STR_EQUAL(pat->path, "dev"); - - ent = pat->entries; - TEST_NOT_NULL(ent); - TEST_STR_EQUAL(ent->key, "security.selinux"); - - TEST_EQUAL_UI(ent->value_len, strlen(dev_selinux)); - ret = memcmp(ent->value, dev_selinux, ent->value_len); - TEST_EQUAL_I(ret, 0); - - ent = ent->next; - TEST_NULL(ent); - - /* no more patterns */ - pat = pat->next; - TEST_NULL(pat); - - xattr_close_map_file(map); - return EXIT_SUCCESS; -} diff --git a/tests/gensquashfs/fstree1.txt b/tests/gensquashfs/fstree1.txt deleted file mode 100644 index 95ee469..0000000 --- a/tests/gensquashfs/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/gensquashfs/fstree_from_dir.c b/tests/gensquashfs/fstree_from_dir.c deleted file mode 100644 index 5e73fa4..0000000 --- a/tests/gensquashfs/fstree_from_dir.c +++ /dev/null @@ -1,178 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_from_dir.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#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, "dira"); - 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, "file_a0"); - TEST_ASSERT(S_ISREG(m->mode)); - TEST_ASSERT(m->parent == n); - - m = m->next; - TEST_NOT_NULL(m); - TEST_STR_EQUAL(m->name, "file_a1"); - TEST_ASSERT(S_ISREG(m->mode)); - TEST_ASSERT(m->parent == n); - - m = m->next; - TEST_NOT_NULL(m); - TEST_STR_EQUAL(m->name, "file_a2"); - 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, "dirb"); - 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, "file_b0"); - TEST_ASSERT(S_ISREG(m->mode)); - TEST_ASSERT(m->parent == n); - - m = m->next; - TEST_NOT_NULL(m); - TEST_STR_EQUAL(m->name, "file_b1"); - TEST_ASSERT(S_ISREG(m->mode)); - TEST_ASSERT(m->parent == n); - - m = m->next; - TEST_NOT_NULL(m); - TEST_STR_EQUAL(m->name, "file_b2"); - 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, "dirc"); - 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, "file_c0"); - TEST_ASSERT(S_ISREG(m->mode)); - TEST_ASSERT(m->parent == n); - - m = m->next; - TEST_NOT_NULL(m); - TEST_STR_EQUAL(m->name, "file_c1"); - TEST_ASSERT(S_ISREG(m->mode)); - TEST_ASSERT(m->parent == n); - - m = m->next; - TEST_NOT_NULL(m); - TEST_STR_EQUAL(m->name, "file_c2"); - 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 deleted file mode 100644 index 2a9ba1e..0000000 --- a/tests/gensquashfs/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 - */ -#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 deleted file mode 100644 index 4fbb72b..0000000 --- a/tests/gensquashfs/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 - */ -#include "config.h" - -#include "mkfs.h" - -#include -#include - -int main(int argc, char **argv) -{ - int ret = EXIT_FAILURE; - fstree_t fs; - - if (argc != 2) { - fputs("Usage: fstree_fuzz \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 deleted file mode 100644 index fbcbf91..0000000 --- a/tests/gensquashfs/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 - */ -#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 deleted file mode 100644 index b1df979..0000000 --- a/tests/gensquashfs/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/gensquashfs/fstree_glob2.txt b/tests/gensquashfs/fstree_glob2.txt deleted file mode 100644 index 3c8019b..0000000 --- a/tests/gensquashfs/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/gensquashfs/fstree_glob3.txt b/tests/gensquashfs/fstree_glob3.txt deleted file mode 100644 index 35090e4..0000000 --- a/tests/gensquashfs/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/gensquashfs/sort_file.c b/tests/gensquashfs/sort_file.c deleted file mode 100644 index 951328e..0000000 --- a/tests/gensquashfs/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 - */ -#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; -} diff --git a/tests/gensquashfs/testdir/dira/file_a0 b/tests/gensquashfs/testdir/dira/file_a0 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dira/file_a1 b/tests/gensquashfs/testdir/dira/file_a1 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dira/file_a2 b/tests/gensquashfs/testdir/dira/file_a2 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dirb/file_b0 b/tests/gensquashfs/testdir/dirb/file_b0 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dirb/file_b1 b/tests/gensquashfs/testdir/dirb/file_b1 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dirb/file_b2 b/tests/gensquashfs/testdir/dirb/file_b2 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dirc/file_c0 b/tests/gensquashfs/testdir/dirc/file_c0 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dirc/file_c1 b/tests/gensquashfs/testdir/dirc/file_c1 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/testdir/dirc/file_c2 b/tests/gensquashfs/testdir/dirc/file_c2 deleted file mode 100644 index e69de29..0000000 diff --git a/tests/gensquashfs/xattr1.txt b/tests/gensquashfs/xattr1.txt deleted file mode 100644 index ffe5fec..0000000 --- a/tests/gensquashfs/xattr1.txt +++ /dev/null @@ -1,9 +0,0 @@ -# file: dev/ -security.selinux="system_u:object_r:device_t:s0" - -# file: dev/zero -security.selinux="system_u:object_r:zero_device_t:s0" - -# file: dev/rfkill -security.selinux="system_u:object_r:wireless_device_t:s0" -system.posix_acl_access=0sAgAAAAEABgD/////AgAGAOgDAAAEAAYA/////xAABgD/////IAAEAP////8= -- cgit v1.2.3