From b950412ca3a91aa37349cf51ebe98cc84767d448 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 5 Mar 2021 15:53:21 +0100 Subject: Cleanup: add some structure to the test directory Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 287 +----- tests/abi.c | 22 - tests/add_by_path.c | 133 --- tests/canonicalize_name.c | 77 -- tests/filename_sane.c | 93 -- tests/fstree1.txt | 9 - tests/fstree_from_dir.c | 380 -------- tests/fstree_from_file.c | 89 -- tests/fstree_fuzz.c | 34 - tests/fstree_glob1.c | 224 ----- tests/fstree_glob1.txt | 2 - tests/fstree_glob2.txt | 3 - tests/fstree_init.c | 49 - tests/fstree_sort.c | 101 -- tests/gen_inode_numbers.c | 89 -- tests/get_line.c | 164 ---- tests/get_line.txt | 11 - tests/get_path.c | 58 -- tests/libfstream/Makemodule.am | 11 + tests/libfstream/get_line.c | 164 ++++ tests/libfstream/get_line.txt | 11 + tests/libfstree/Makemodule.am | 76 ++ tests/libfstree/add_by_path.c | 133 +++ tests/libfstree/canonicalize_name.c | 77 ++ tests/libfstree/filename_sane.c | 93 ++ tests/libfstree/fstree1.txt | 9 + tests/libfstree/fstree_from_dir.c | 380 ++++++++ tests/libfstree/fstree_from_file.c | 89 ++ tests/libfstree/fstree_fuzz.c | 34 + tests/libfstree/fstree_glob1.c | 224 +++++ tests/libfstree/fstree_glob1.txt | 2 + tests/libfstree/fstree_glob2.txt | 3 + tests/libfstree/fstree_init.c | 49 + tests/libfstree/fstree_sort.c | 101 ++ tests/libfstree/gen_inode_numbers.c | 89 ++ tests/libfstree/get_path.c | 58 ++ tests/libfstree/mknode_dir.c | 62 ++ tests/libfstree/mknode_reg.c | 41 + tests/libfstree/mknode_simple.c | 97 ++ tests/libfstree/mknode_slink.c | 53 ++ tests/libsqfs/Makemodule.am | 5 + tests/libsqfs/abi.c | 22 + tests/libtar/Makemodule.am | 178 ++++ tests/libtar/data/CREDITS | 35 + tests/libtar/data/file-size/12-digit.tar | Bin 0 -> 2048 bytes tests/libtar/data/file-size/gnu.tar | Bin 0 -> 2048 bytes tests/libtar/data/file-size/pax.tar | Bin 0 -> 2048 bytes tests/libtar/data/format-acceptance/gnu-g.tar | Bin 0 -> 2048 bytes tests/libtar/data/format-acceptance/gnu.tar | Bin 0 -> 2048 bytes .../libtar/data/format-acceptance/link_filled.tar | Bin 0 -> 10240 bytes tests/libtar/data/format-acceptance/pax.tar | Bin 0 -> 3072 bytes .../data/format-acceptance/ustar-pre-posix.tar | Bin 0 -> 2048 bytes tests/libtar/data/format-acceptance/ustar.tar | Bin 0 -> 2048 bytes tests/libtar/data/format-acceptance/v7.tar | Bin 0 -> 2048 bytes tests/libtar/data/large-mtime/12-digit.tar | Bin 0 -> 2048 bytes tests/libtar/data/large-mtime/gnu.tar | Bin 0 -> 2048 bytes tests/libtar/data/large-mtime/pax.tar | Bin 0 -> 3072 bytes tests/libtar/data/long-paths/gnu.tar | Bin 0 -> 3072 bytes tests/libtar/data/long-paths/pax.tar | Bin 0 -> 3072 bytes tests/libtar/data/long-paths/ustar.tar | Bin 0 -> 2048 bytes tests/libtar/data/negative-mtime/gnu.tar | Bin 0 -> 10240 bytes tests/libtar/data/negative-mtime/pax.tar | Bin 0 -> 10240 bytes tests/libtar/data/sparse-files/gnu-small.tar | Bin 0 -> 9728 bytes tests/libtar/data/sparse-files/gnu.tar | Bin 0 -> 34816 bytes tests/libtar/data/sparse-files/pax-gnu0-0.tar | Bin 0 -> 35840 bytes tests/libtar/data/sparse-files/pax-gnu0-1.tar | Bin 0 -> 35328 bytes tests/libtar/data/sparse-files/pax-gnu1-0.tar | Bin 0 -> 35840 bytes tests/libtar/data/sqfs.sha512 | 28 + tests/libtar/data/user-group-largenum/8-digit.tar | Bin 0 -> 2048 bytes tests/libtar/data/user-group-largenum/gnu.tar | Bin 0 -> 2048 bytes tests/libtar/data/user-group-largenum/pax.tar | Bin 0 -> 3072 bytes tests/libtar/data/xattr/acl.tar | Bin 0 -> 3072 bytes tests/libtar/data/xattr/xattr-libarchive.tar | Bin 0 -> 3072 bytes tests/libtar/data/xattr/xattr-schily-binary.tar | Bin 0 -> 3072 bytes tests/libtar/data/xattr/xattr-schily.tar | Bin 0 -> 3072 bytes tests/libtar/tar_big_file.c | 30 + tests/libtar/tar_fuzz.c | 48 + tests/libtar/tar_simple.c | 69 ++ tests/libtar/tar_sparse.c | 85 ++ tests/libtar/tar_sparse_gnu.c | 51 + tests/libtar/tar_target_filled.c | 108 +++ tests/libtar/tar_xattr.c | 41 + tests/libtar/tar_xattr_bin.c | 49 + tests/libutil/Makemodule.am | 16 + tests/libutil/rbtree.c | 173 ++++ tests/libutil/str_table.c | 84 ++ tests/libutil/words.txt | 1000 ++++++++++++++++++++ tests/libutil/xxhash.c | 65 ++ tests/mknode_dir.c | 62 -- tests/mknode_reg.c | 41 - tests/mknode_simple.c | 97 -- tests/mknode_slink.c | 53 -- tests/rbtree.c | 173 ---- tests/str_table.c | 84 -- tests/tar/CREDITS | 35 - tests/tar/file-size/12-digit.tar | Bin 2048 -> 0 bytes tests/tar/file-size/gnu.tar | Bin 2048 -> 0 bytes tests/tar/file-size/pax.tar | Bin 2048 -> 0 bytes tests/tar/format-acceptance/gnu-g.tar | Bin 2048 -> 0 bytes tests/tar/format-acceptance/gnu.tar | Bin 2048 -> 0 bytes tests/tar/format-acceptance/link_filled.tar | Bin 10240 -> 0 bytes tests/tar/format-acceptance/pax.tar | Bin 3072 -> 0 bytes tests/tar/format-acceptance/ustar-pre-posix.tar | Bin 2048 -> 0 bytes tests/tar/format-acceptance/ustar.tar | Bin 2048 -> 0 bytes tests/tar/format-acceptance/v7.tar | Bin 2048 -> 0 bytes tests/tar/large-mtime/12-digit.tar | Bin 2048 -> 0 bytes tests/tar/large-mtime/gnu.tar | Bin 2048 -> 0 bytes tests/tar/large-mtime/pax.tar | Bin 3072 -> 0 bytes tests/tar/long-paths/gnu.tar | Bin 3072 -> 0 bytes tests/tar/long-paths/pax.tar | Bin 3072 -> 0 bytes tests/tar/long-paths/ustar.tar | Bin 2048 -> 0 bytes tests/tar/negative-mtime/gnu.tar | Bin 10240 -> 0 bytes tests/tar/negative-mtime/pax.tar | Bin 10240 -> 0 bytes tests/tar/sparse-files/gnu-small.tar | Bin 9728 -> 0 bytes tests/tar/sparse-files/gnu.tar | Bin 34816 -> 0 bytes tests/tar/sparse-files/pax-gnu0-0.tar | Bin 35840 -> 0 bytes tests/tar/sparse-files/pax-gnu0-1.tar | Bin 35328 -> 0 bytes tests/tar/sparse-files/pax-gnu1-0.tar | Bin 35840 -> 0 bytes tests/tar/sqfs.sha512 | 28 - tests/tar/user-group-largenum/8-digit.tar | Bin 2048 -> 0 bytes tests/tar/user-group-largenum/gnu.tar | Bin 2048 -> 0 bytes tests/tar/user-group-largenum/pax.tar | Bin 3072 -> 0 bytes tests/tar/xattr/acl.tar | Bin 3072 -> 0 bytes tests/tar/xattr/xattr-libarchive.tar | Bin 3072 -> 0 bytes tests/tar/xattr/xattr-schily-binary.tar | Bin 3072 -> 0 bytes tests/tar/xattr/xattr-schily.tar | Bin 3072 -> 0 bytes tests/tar_big_file.c | 30 - tests/tar_fuzz.c | 48 - tests/tar_simple.c | 69 -- tests/tar_sparse.c | 85 -- tests/tar_sparse_gnu.c | 51 - tests/tar_target_filled.c | 108 --- tests/tar_xattr.c | 41 - tests/tar_xattr_bin.c | 49 - tests/test_tar_sqfs.sh.in | 4 +- tests/words.txt | 1000 -------------------- tests/xxhash.c | 65 -- 137 files changed, 3950 insertions(+), 3941 deletions(-) delete mode 100644 tests/abi.c delete mode 100644 tests/add_by_path.c delete mode 100644 tests/canonicalize_name.c delete mode 100644 tests/filename_sane.c delete mode 100644 tests/fstree1.txt delete mode 100644 tests/fstree_from_dir.c delete mode 100644 tests/fstree_from_file.c delete mode 100644 tests/fstree_fuzz.c delete mode 100644 tests/fstree_glob1.c delete mode 100644 tests/fstree_glob1.txt delete mode 100644 tests/fstree_glob2.txt delete mode 100644 tests/fstree_init.c delete mode 100644 tests/fstree_sort.c delete mode 100644 tests/gen_inode_numbers.c delete mode 100644 tests/get_line.c delete mode 100644 tests/get_line.txt delete mode 100644 tests/get_path.c create mode 100644 tests/libfstream/Makemodule.am create mode 100644 tests/libfstream/get_line.c create mode 100644 tests/libfstream/get_line.txt create mode 100644 tests/libfstree/Makemodule.am create mode 100644 tests/libfstree/add_by_path.c create mode 100644 tests/libfstree/canonicalize_name.c create mode 100644 tests/libfstree/filename_sane.c create mode 100644 tests/libfstree/fstree1.txt create mode 100644 tests/libfstree/fstree_from_dir.c create mode 100644 tests/libfstree/fstree_from_file.c create mode 100644 tests/libfstree/fstree_fuzz.c create mode 100644 tests/libfstree/fstree_glob1.c create mode 100644 tests/libfstree/fstree_glob1.txt create mode 100644 tests/libfstree/fstree_glob2.txt create mode 100644 tests/libfstree/fstree_init.c create mode 100644 tests/libfstree/fstree_sort.c create mode 100644 tests/libfstree/gen_inode_numbers.c create mode 100644 tests/libfstree/get_path.c create mode 100644 tests/libfstree/mknode_dir.c create mode 100644 tests/libfstree/mknode_reg.c create mode 100644 tests/libfstree/mknode_simple.c create mode 100644 tests/libfstree/mknode_slink.c create mode 100644 tests/libsqfs/Makemodule.am create mode 100644 tests/libsqfs/abi.c create mode 100644 tests/libtar/Makemodule.am create mode 100644 tests/libtar/data/CREDITS create mode 100644 tests/libtar/data/file-size/12-digit.tar create mode 100644 tests/libtar/data/file-size/gnu.tar create mode 100644 tests/libtar/data/file-size/pax.tar create mode 100644 tests/libtar/data/format-acceptance/gnu-g.tar create mode 100644 tests/libtar/data/format-acceptance/gnu.tar create mode 100644 tests/libtar/data/format-acceptance/link_filled.tar create mode 100644 tests/libtar/data/format-acceptance/pax.tar create mode 100644 tests/libtar/data/format-acceptance/ustar-pre-posix.tar create mode 100644 tests/libtar/data/format-acceptance/ustar.tar create mode 100644 tests/libtar/data/format-acceptance/v7.tar create mode 100644 tests/libtar/data/large-mtime/12-digit.tar create mode 100644 tests/libtar/data/large-mtime/gnu.tar create mode 100644 tests/libtar/data/large-mtime/pax.tar create mode 100644 tests/libtar/data/long-paths/gnu.tar create mode 100644 tests/libtar/data/long-paths/pax.tar create mode 100644 tests/libtar/data/long-paths/ustar.tar create mode 100644 tests/libtar/data/negative-mtime/gnu.tar create mode 100644 tests/libtar/data/negative-mtime/pax.tar create mode 100644 tests/libtar/data/sparse-files/gnu-small.tar create mode 100644 tests/libtar/data/sparse-files/gnu.tar create mode 100644 tests/libtar/data/sparse-files/pax-gnu0-0.tar create mode 100644 tests/libtar/data/sparse-files/pax-gnu0-1.tar create mode 100644 tests/libtar/data/sparse-files/pax-gnu1-0.tar create mode 100644 tests/libtar/data/sqfs.sha512 create mode 100644 tests/libtar/data/user-group-largenum/8-digit.tar create mode 100644 tests/libtar/data/user-group-largenum/gnu.tar create mode 100644 tests/libtar/data/user-group-largenum/pax.tar create mode 100644 tests/libtar/data/xattr/acl.tar create mode 100644 tests/libtar/data/xattr/xattr-libarchive.tar create mode 100644 tests/libtar/data/xattr/xattr-schily-binary.tar create mode 100644 tests/libtar/data/xattr/xattr-schily.tar create mode 100644 tests/libtar/tar_big_file.c create mode 100644 tests/libtar/tar_fuzz.c create mode 100644 tests/libtar/tar_simple.c create mode 100644 tests/libtar/tar_sparse.c create mode 100644 tests/libtar/tar_sparse_gnu.c create mode 100644 tests/libtar/tar_target_filled.c create mode 100644 tests/libtar/tar_xattr.c create mode 100644 tests/libtar/tar_xattr_bin.c create mode 100644 tests/libutil/Makemodule.am create mode 100644 tests/libutil/rbtree.c create mode 100644 tests/libutil/str_table.c create mode 100644 tests/libutil/words.txt create mode 100644 tests/libutil/xxhash.c delete mode 100644 tests/mknode_dir.c delete mode 100644 tests/mknode_reg.c delete mode 100644 tests/mknode_simple.c delete mode 100644 tests/mknode_slink.c delete mode 100644 tests/rbtree.c delete mode 100644 tests/str_table.c delete mode 100644 tests/tar/CREDITS delete mode 100644 tests/tar/file-size/12-digit.tar delete mode 100644 tests/tar/file-size/gnu.tar delete mode 100644 tests/tar/file-size/pax.tar delete mode 100644 tests/tar/format-acceptance/gnu-g.tar delete mode 100644 tests/tar/format-acceptance/gnu.tar delete mode 100644 tests/tar/format-acceptance/link_filled.tar delete mode 100644 tests/tar/format-acceptance/pax.tar delete mode 100644 tests/tar/format-acceptance/ustar-pre-posix.tar delete mode 100644 tests/tar/format-acceptance/ustar.tar delete mode 100644 tests/tar/format-acceptance/v7.tar delete mode 100644 tests/tar/large-mtime/12-digit.tar delete mode 100644 tests/tar/large-mtime/gnu.tar delete mode 100644 tests/tar/large-mtime/pax.tar delete mode 100644 tests/tar/long-paths/gnu.tar delete mode 100644 tests/tar/long-paths/pax.tar delete mode 100644 tests/tar/long-paths/ustar.tar delete mode 100644 tests/tar/negative-mtime/gnu.tar delete mode 100644 tests/tar/negative-mtime/pax.tar delete mode 100644 tests/tar/sparse-files/gnu-small.tar delete mode 100644 tests/tar/sparse-files/gnu.tar delete mode 100644 tests/tar/sparse-files/pax-gnu0-0.tar delete mode 100644 tests/tar/sparse-files/pax-gnu0-1.tar delete mode 100644 tests/tar/sparse-files/pax-gnu1-0.tar delete mode 100644 tests/tar/sqfs.sha512 delete mode 100644 tests/tar/user-group-largenum/8-digit.tar delete mode 100644 tests/tar/user-group-largenum/gnu.tar delete mode 100644 tests/tar/user-group-largenum/pax.tar delete mode 100644 tests/tar/xattr/acl.tar delete mode 100644 tests/tar/xattr/xattr-libarchive.tar delete mode 100644 tests/tar/xattr/xattr-schily-binary.tar delete mode 100644 tests/tar/xattr/xattr-schily.tar delete mode 100644 tests/tar_big_file.c delete mode 100644 tests/tar_fuzz.c delete mode 100644 tests/tar_simple.c delete mode 100644 tests/tar_sparse.c delete mode 100644 tests/tar_sparse_gnu.c delete mode 100644 tests/tar_target_filled.c delete mode 100644 tests/tar_xattr.c delete mode 100644 tests/tar_xattr_bin.c delete mode 100644 tests/words.txt delete mode 100644 tests/xxhash.c diff --git a/tests/Makemodule.am b/tests/Makemodule.am index dd49ccd..8669fb1 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -1,294 +1,17 @@ -test_canonicalize_name_SOURCES = tests/canonicalize_name.c tests/test.h -test_canonicalize_name_LDADD = libfstree.a - -test_str_table_SOURCES = tests/str_table.c tests/test.h -test_str_table_LDADD = libutil.a libfstream.a libcompat.a -test_str_table_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests -test_str_table_CPPFLAGS += -I$(top_srcdir)/lib/sqfs - -test_rbtree_SOURCES = tests/rbtree.c tests/test.h -test_rbtree_LDADD = libutil.a libcompat.a -test_rbtree_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/sqfs - -test_xxhash_SOURCES = tests/xxhash.c -test_xxhash_LDADD = libutil.a libcompat.a -test_xxhash_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/sqfs - -test_abi_SOURCES = tests/abi.c tests/test.h -test_abi_LDADD = libsquashfs.la - -check_PROGRAMS += test_canonicalize_name test_str_table test_abi test_rbtree -check_PROGRAMS += test_xxhash -TESTS += test_canonicalize_name test_str_table test_abi test_rbtree test_xxhash +include tests/libutil/Makemodule.am +include tests/libfstream/Makemodule.am +include tests/libfstree/Makemodule.am +include tests/libtar/Makemodule.am +include tests/libsqfs/Makemodule.am if BUILD_TOOLS -test_mknode_simple_SOURCES = tests/mknode_simple.c tests/test.h -test_mknode_simple_LDADD = libfstree.a libcompat.a - -test_mknode_slink_SOURCES = tests/mknode_slink.c tests/test.h -test_mknode_slink_LDADD = libfstree.a libcompat.a - -test_mknode_reg_SOURCES = tests/mknode_reg.c tests/test.h -test_mknode_reg_LDADD = libfstree.a libcompat.a - -test_mknode_dir_SOURCES = tests/mknode_dir.c tests/test.h -test_mknode_dir_LDADD = libfstree.a libcompat.a - -test_gen_inode_numbers_SOURCES = tests/gen_inode_numbers.c tests/test.h -test_gen_inode_numbers_LDADD = libfstree.a libcompat.a - -test_add_by_path_SOURCES = tests/add_by_path.c tests/test.h -test_add_by_path_LDADD = libfstree.a libcompat.a - -test_get_path_SOURCES = tests/get_path.c tests/test.h -test_get_path_LDADD = libfstree.a libcompat.a - -test_fstree_sort_SOURCES = tests/fstree_sort.c tests/test.h -test_fstree_sort_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree -test_fstree_sort_LDADD = libfstree.a libfstream.a libcompat.a - -test_fstree_from_file_SOURCES = tests/fstree_from_file.c tests/test.h -test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/fstree1.txt -test_fstree_from_file_LDADD = libfstree.a libfstream.a libcompat.a - -test_fstree_glob1_SOURCES = tests/fstree_glob1.c tests/test.h -test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests -test_fstree_glob1_LDADD = libfstree.a libfstream.a libcompat.a - -test_fstree_from_dir_SOURCES = tests/fstree_from_dir.c tests/test.h -test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_fstree_from_dir_LDADD = libfstree.a libcompat.a - -test_fstree_init_SOURCES = tests/fstree_init.c tests/test.h -test_fstree_init_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree -test_fstree_init_LDADD = libfstree.a libfstream.a libcompat.a - -test_filename_sane_SOURCES = tests/filename_sane.c lib/fstree/filename_sane.c - -test_filename_sane_w32_SOURCES = tests/filename_sane.c -test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c -test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1 - -test_tar_gnu0_SOURCES = tests/tar_simple.c tests/test.h -test_tar_gnu0_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu0_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar - -test_tar_gnu1_SOURCES = tests/tar_simple.c tests/test.h -test_tar_gnu1_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu1_CPPFLAGS += -DTESTFILE=format-acceptance/gnu-g.tar - -test_tar_gnu2_SOURCES = tests/tar_simple.c tests/test.h -test_tar_gnu2_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu2_CPPFLAGS += -DTESTFILE=user-group-largenum/gnu.tar -test_tar_gnu2_CPPFLAGS += -DTESTUID=0x80000000 -DTESTGID=0x80000000 -test_tar_gnu2_CPPFLAGS += -DTESTTS=1542995392 - -test_tar_gnu3_SOURCES = tests/tar_simple.c tests/test.h -test_tar_gnu3_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu3_CPPFLAGS += -DTESTFILE=negative-mtime/gnu.tar -DTESTTS=-315622800 - -test_tar_gnu4_SOURCES = tests/tar_simple.c tests/test.h -test_tar_gnu4_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu4_CPPFLAGS += -DTESTFILE=long-paths/gnu.tar -DLONG_NAME_TEST -test_tar_gnu4_CPPFLAGS += -DTESTTS=1542909670 - -test_tar_gnu5_SOURCES = tests/tar_simple.c tests/test.h -test_tar_gnu5_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu5_CPPFLAGS += -DTESTFILE=large-mtime/gnu.tar -DTESTTS=8589934592L - -test_tar_gnu6_SOURCES = tests/tar_big_file.c tests/test.h -test_tar_gnu6_LDADD = libtar.a libfstream.a libcompat.a -test_tar_gnu6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_gnu6_CPPFLAGS += -DTESTFILE=file-size/gnu.tar - -test_tar_pax0_SOURCES = tests/tar_simple.c tests/test.h -test_tar_pax0_LDADD = libtar.a libfstream.a libcompat.a -test_tar_pax0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax0_CPPFLAGS += -DTESTFILE=format-acceptance/pax.tar - -test_tar_pax1_SOURCES = tests/tar_simple.c tests/test.h -test_tar_pax1_LDADD = libtar.a libfstream.a libcompat.a -test_tar_pax1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax1_CPPFLAGS += -DTESTFILE=user-group-largenum/pax.tar -test_tar_pax1_CPPFLAGS += -DTESTUID=2147483648UL -DTESTGID=2147483648UL -test_tar_pax1_CPPFLAGS += -DTESTTS=1542995392 - -test_tar_pax2_SOURCES = tests/tar_simple.c tests/test.h -test_tar_pax2_LDADD = libtar.a libfstream.a libcompat.a -test_tar_pax2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax2_CPPFLAGS += -DTESTFILE=large-mtime/pax.tar -DTESTTS=8589934592L - -test_tar_pax3_SOURCES = tests/tar_simple.c tests/test.h -test_tar_pax3_LDADD = libtar.a libfstream.a libcompat.a -test_tar_pax3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax3_CPPFLAGS += -DTESTFILE=negative-mtime/pax.tar -DTESTTS=-315622800 - -test_tar_pax4_SOURCES = tests/tar_simple.c tests/test.h -test_tar_pax4_LDADD = libtar.a libfstream.a libcompat.a -test_tar_pax4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax4_CPPFLAGS += -DTESTFILE=long-paths/pax.tar -test_tar_pax4_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670 - -test_tar_pax5_SOURCES = tests/tar_big_file.c tests/test.h -test_tar_pax5_LDADD = libtar.a libfstream.a libcompat.a -test_tar_pax5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax5_CPPFLAGS += -DTESTFILE=file-size/pax.tar - -test_tar_ustar0_SOURCES = tests/tar_simple.c tests/test.h -test_tar_ustar0_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar0_CPPFLAGS += -DTESTFILE=format-acceptance/ustar.tar - -test_tar_ustar1_SOURCES = tests/tar_simple.c tests/test.h -test_tar_ustar1_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar1_CPPFLAGS += -DTESTFILE=format-acceptance/ustar-pre-posix.tar - -test_tar_ustar2_SOURCES = tests/tar_simple.c tests/test.h -test_tar_ustar2_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar2_CPPFLAGS += -DTESTFILE=format-acceptance/v7.tar - -test_tar_ustar3_SOURCES = tests/tar_simple.c tests/test.h -test_tar_ustar3_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar3_CPPFLAGS += -DTESTFILE=user-group-largenum/8-digit.tar -test_tar_ustar3_CPPFLAGS += -DTESTUID=8388608 -DTESTGID=8388608 -test_tar_ustar3_CPPFLAGS += -DTESTTS=1542995392 - -test_tar_ustar4_SOURCES = tests/tar_simple.c tests/test.h -test_tar_ustar4_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar4_CPPFLAGS += -DTESTFILE=large-mtime/12-digit.tar -test_tar_ustar4_CPPFLAGS += -DTESTTS=8589934592L - -test_tar_ustar5_SOURCES = tests/tar_simple.c tests/test.h -test_tar_ustar5_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar5_CPPFLAGS += -DTESTFILE=long-paths/ustar.tar -test_tar_ustar5_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670 - -test_tar_ustar6_SOURCES = tests/tar_big_file.c tests/test.h -test_tar_ustar6_LDADD = libtar.a libfstream.a libcompat.a -test_tar_ustar6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar6_CPPFLAGS += -DTESTFILE=file-size/12-digit.tar - -test_tar_target_filled_SOURCES = tests/tar_target_filled.c tests/test.h -test_tar_target_filled_LDADD = libtar.a libfstream.a libcompat.a -test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_target_filled_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar - -test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c tests/test.h -test_tar_sparse_gnu_LDADD = libtar.a libfstream.a libcompat.a -test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar - -test_tar_sparse_gnu0_SOURCES = tests/tar_sparse.c tests/test.h -test_tar_sparse_gnu0_LDADD = libtar.a libfstream.a libcompat.a -test_tar_sparse_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_sparse_gnu0_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu0_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-0.tar - -test_tar_sparse_gnu1_SOURCES = tests/tar_sparse.c tests/test.h -test_tar_sparse_gnu1_LDADD = libtar.a libfstream.a libcompat.a -test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_sparse_gnu1_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu1_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-1.tar - -test_tar_sparse_gnu2_SOURCES = tests/tar_sparse.c tests/test.h -test_tar_sparse_gnu2_LDADD = libtar.a libfstream.a libcompat.a -test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_sparse_gnu2_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu2_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu1-0.tar - -test_tar_sparse_gnu3_SOURCES = tests/tar_sparse.c tests/test.h -test_tar_sparse_gnu3_LDADD = libtar.a libfstream.a libcompat.a -test_tar_sparse_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_sparse_gnu3_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu3_CPPFLAGS += -DTESTFILE=sparse-files/gnu.tar - -test_tar_xattr_bsd_SOURCES = tests/tar_xattr.c tests/test.h -test_tar_xattr_bsd_LDADD = libtar.a libfstream.a libcompat.a -test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_xattr_bsd_CPPFLAGS += -DTESTFILE=xattr/xattr-libarchive.tar - -test_tar_xattr_schily_SOURCES = tests/tar_xattr.c tests/test.h -test_tar_xattr_schily_LDADD = libtar.a libfstream.a libcompat.a -test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_xattr_schily_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_xattr_schily_CPPFLAGS += -DTESTFILE=xattr/xattr-schily.tar - -test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_bin.c tests/test.h -test_tar_xattr_schily_bin_LDADD = libtar.a libfstream.a libcompat.a -test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS) -test_tar_xattr_schily_bin_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_xattr_schily_bin_CPPFLAGS += -DTESTFILE=xattr/xattr-schily-binary.tar - -fstree_fuzz_SOURCES = tests/fstree_fuzz.c -fstree_fuzz_LDADD = libfstree.a libfstream.a libcompat.a - -tar_fuzz_SOURCES = tests/tar_fuzz.c -tar_fuzz_LDADD = libtar.a libfstream.a libcompat.a - -test_get_line_SOURCES = tests/get_line.c tests/test.h -test_get_line_LDADD = libfstream.a libcompat.a -test_get_line_CPPFLAGS = $(AM_CPPFLAGS) -test_get_line_CPPFLAGS += -DTESTFILE=$(top_srcdir)/tests/get_line.txt - -check_PROGRAMS += test_mknode_simple test_mknode_slink test_mknode_reg -check_PROGRAMS += test_mknode_dir test_gen_inode_numbers test_add_by_path -check_PROGRAMS += test_get_path test_fstree_sort test_fstree_from_file -check_PROGRAMS += test_fstree_init test_filename_sane test_filename_sane_w32 -check_PROGRAMS += test_fstree_from_dir test_fstree_glob1 -check_PROGRAMS += test_tar_ustar0 test_tar_ustar1 test_tar_ustar2 -check_PROGRAMS += test_tar_ustar3 test_tar_ustar4 test_tar_ustar5 -check_PROGRAMS += test_tar_ustar6 -check_PROGRAMS += test_tar_pax0 test_tar_pax1 test_tar_pax2 test_tar_pax3 -check_PROGRAMS += test_tar_pax4 test_tar_pax5 -check_PROGRAMS += test_tar_gnu0 test_tar_gnu1 test_tar_gnu2 test_tar_gnu3 -check_PROGRAMS += test_tar_gnu4 test_tar_gnu5 test_tar_gnu6 -check_PROGRAMS += test_tar_sparse_gnu test_tar_sparse_gnu0 test_tar_sparse_gnu1 -check_PROGRAMS += test_tar_sparse_gnu2 test_tar_sparse_gnu3 -check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily -check_PROGRAMS += test_tar_xattr_schily_bin test_tar_target_filled -check_PROGRAMS += test_get_line - -noinst_PROGRAMS += fstree_fuzz tar_fuzz - -TESTS += test_mknode_simple test_mknode_slink -TESTS += test_mknode_reg test_mknode_dir test_gen_inode_numbers -TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file -TESTS += test_fstree_init test_filename_sane test_filename_sane_w32 -TESTS += test_fstree_from_dir test_fstree_glob1 -TESTS += test_tar_ustar0 test_tar_ustar1 test_tar_ustar2 test_tar_ustar3 -TESTS += test_tar_ustar4 test_tar_ustar5 test_tar_ustar6 -TESTS += test_tar_gnu0 test_tar_gnu1 test_tar_gnu2 test_tar_gnu3 test_tar_gnu4 -TESTS += test_tar_gnu5 test_tar_gnu6 -TESTS += test_tar_pax0 test_tar_pax1 test_tar_pax2 test_tar_pax3 test_tar_pax4 -TESTS += test_tar_pax5 -TESTS += test_tar_sparse_gnu test_tar_sparse_gnu0 -TESTS += test_tar_sparse_gnu1 test_tar_sparse_gnu2 test_tar_sparse_gnu3 -TESTS += test_tar_xattr_bsd test_tar_xattr_schily -TESTS += test_tar_xattr_schily_bin test_tar_target_filled test_get_line - if CORPORA_TESTS check_SCRIPTS += tests/cantrbry.sh tests/test_tar_sqfs.sh tests/pack_dir_root.sh TESTS += tests/cantrbry.sh tests/test_tar_sqfs.sh tests/pack_dir_root.sh endif endif -EXTRA_DIST += $(top_srcdir)/tests/tar $(top_srcdir)/tests/words.txt EXTRA_DIST += $(top_srcdir)/tests/tar2sqfs -EXTRA_DIST += $(top_srcdir)/tests/fstree1.txt -EXTRA_DIST += $(top_srcdir)/tests/fstree_glob1.txt -EXTRA_DIST += $(top_srcdir)/tests/fstree_glob2.txt EXTRA_DIST += $(top_srcdir)/tests/corpus/cantrbry.tar.xz EXTRA_DIST += $(top_srcdir)/tests/corpus/cantrbry.sha512 EXTRA_DIST += $(top_srcdir)/tests/pack_dir_root.txt.ref -EXTRA_DIST += $(top_srcdir)/tests/get_line.txt diff --git a/tests/abi.c b/tests/abi.c deleted file mode 100644 index 8ae2220..0000000 --- a/tests/abi.c +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * abi.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "sqfs/compressor.h" -#include "test.h" - -int main(void) -{ - sqfs_compressor_config_t cfg; - - TEST_EQUAL_UI(sizeof(cfg.opt.gzip), sizeof(cfg.opt)); - TEST_EQUAL_UI(sizeof(cfg.opt.lzo), sizeof(cfg.opt)); - TEST_EQUAL_UI(sizeof(cfg.opt.xz), sizeof(cfg.opt)); - TEST_EQUAL_UI(sizeof(cfg.opt.padd0), sizeof(cfg.opt)); - - return EXIT_SUCCESS; -} diff --git a/tests/add_by_path.c b/tests/add_by_path.c deleted file mode 100644 index f575011..0000000 --- a/tests/add_by_path.c +++ /dev/null @@ -1,133 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * add_by_path.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *a, *b; - struct stat sb; - fstree_t fs; - char *opts; - - opts = strdup("mode=0755,uid=21,gid=42"); - TEST_ASSERT(fstree_init(&fs, opts) == 0); - free(opts); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0750; - sb.st_uid = 1000; - sb.st_gid = 100; - - TEST_EQUAL_UI(fs.root->link_count, 2); - - a = fstree_add_generic(&fs, "dir", &sb, NULL); - TEST_NOT_NULL(a); - TEST_STR_EQUAL(a->name, "dir"); - TEST_EQUAL_UI(a->mode, sb.st_mode); - TEST_EQUAL_UI(a->uid, sb.st_uid); - TEST_EQUAL_UI(a->gid, sb.st_gid); - TEST_ASSERT(a->parent == fs.root); - TEST_EQUAL_UI(a->link_count, 2); - TEST_NULL(a->next); - TEST_ASSERT(fs.root->data.dir.children == a); - TEST_EQUAL_UI(fs.root->link_count, 3); - TEST_ASSERT(!a->data.dir.created_implicitly); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFBLK | 0640; - sb.st_rdev = 1234; - - b = fstree_add_generic(&fs, "blkdev", &sb, NULL); - TEST_NOT_NULL(b); - TEST_ASSERT(b != a); - TEST_STR_EQUAL(b->name, "blkdev"); - TEST_EQUAL_UI(b->mode, sb.st_mode); - TEST_EQUAL_UI(b->uid, sb.st_uid); - TEST_EQUAL_UI(b->gid, sb.st_gid); - TEST_ASSERT(b->parent == fs.root); - TEST_EQUAL_UI(b->link_count, 1); - TEST_EQUAL_UI(b->data.devno, sb.st_rdev); - TEST_ASSERT(b->next == a); - TEST_EQUAL_UI(fs.root->link_count, 4); - TEST_ASSERT(fs.root->data.dir.children == b); - - TEST_NULL(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL)); - TEST_EQUAL_UI(errno, ENOTDIR); - - TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); - TEST_EQUAL_UI(errno, EEXIST); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0755; - TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); - TEST_EQUAL_UI(errno, EEXIST); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFCHR | 0444; - b = fstree_add_generic(&fs, "dir/chrdev", &sb, NULL); - TEST_NOT_NULL(b); - TEST_EQUAL_UI(b->mode, sb.st_mode); - TEST_EQUAL_UI(b->uid, sb.st_uid); - TEST_EQUAL_UI(b->gid, sb.st_gid); - TEST_EQUAL_UI(b->link_count, 1); - TEST_ASSERT(b->parent == a); - TEST_EQUAL_UI(b->data.devno, sb.st_rdev); - TEST_NULL(b->next); - TEST_ASSERT(a->data.dir.children == b); - - TEST_EQUAL_UI(a->link_count, 3); - TEST_EQUAL_UI(fs.root->link_count, 4); - - b = fstree_add_generic(&fs, "dir/foo/chrdev", &sb, NULL); - TEST_NOT_NULL(b); - TEST_NULL(b->next); - TEST_EQUAL_UI(b->mode, sb.st_mode); - TEST_EQUAL_UI(b->uid, sb.st_uid); - TEST_EQUAL_UI(b->gid, sb.st_gid); - TEST_EQUAL_UI(b->link_count, 1); - TEST_ASSERT(b->parent != a); - TEST_ASSERT(b->parent->parent == a); - TEST_EQUAL_UI(b->data.devno, sb.st_rdev); - TEST_NULL(b->next); - - TEST_EQUAL_UI(a->link_count, 4); - TEST_EQUAL_UI(fs.root->link_count, 4); - TEST_ASSERT(a->data.dir.children != b); - - b = b->parent; - TEST_ASSERT(b->data.dir.created_implicitly); - TEST_EQUAL_UI(b->mode, S_IFDIR | 0755); - TEST_EQUAL_UI(b->uid, 21); - TEST_EQUAL_UI(b->gid, 42); - TEST_EQUAL_UI(b->link_count, 3); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0750; - sb.st_uid = 1000; - sb.st_gid = 100; - - a = fstree_add_generic(&fs, "dir/foo", &sb, NULL); - TEST_NOT_NULL(a); - TEST_ASSERT(a == b); - TEST_ASSERT(!a->data.dir.created_implicitly); - TEST_EQUAL_UI(a->mode, sb.st_mode); - TEST_EQUAL_UI(a->uid, sb.st_uid); - TEST_EQUAL_UI(a->gid, sb.st_gid); - TEST_EQUAL_UI(a->link_count, 3); - - TEST_EQUAL_UI(a->parent->link_count, 4); - TEST_EQUAL_UI(fs.root->link_count, 4); - - TEST_NULL(fstree_add_generic(&fs, "dir/foo", &sb, NULL)); - TEST_EQUAL_UI(errno, EEXIST); - - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} diff --git a/tests/canonicalize_name.c b/tests/canonicalize_name.c deleted file mode 100644 index 2ab73a0..0000000 --- a/tests/canonicalize_name.c +++ /dev/null @@ -1,77 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * canonicalize_name.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "fstree.h" -#include "test.h" - -static const struct { - const char *in; - const char *out; -} must_work[] = { - { "", "" }, - { "/", "" }, - { "\\", "\\" }, - { "///", "" }, - { "\\\\\\", "\\\\\\" }, - { "/\\//\\\\/", "\\/\\\\" }, - { "foo/bar/test", "foo/bar/test" }, - { "foo\\bar\\test", "foo\\bar\\test" }, - { "/foo/bar/test/", "foo/bar/test" }, - { "\\foo\\bar\\test\\", "\\foo\\bar\\test\\" }, - { "///foo//bar//test///", "foo/bar/test" }, - { "./foo/././bar/test/./.", "foo/bar/test" }, - { "./foo/././", "foo" }, - { ".", "" }, - { "./", "" }, - { "./.", "" }, - { "foo/.../bar", "foo/.../bar" }, - { "foo/.test/bar", "foo/.test/bar" }, -}; - -static const char *must_not_work[] = { - "..", - "foo/../bar", - "../foo/bar", - "foo/bar/..", - "foo/bar/../", -}; - -int main(void) -{ - char buffer[512]; - size_t i; - - for (i = 0; i < sizeof(must_work) / sizeof(must_work[0]); ++i) { - strcpy(buffer, must_work[i].in); - - if (canonicalize_name(buffer)) { - fprintf(stderr, "Test case rejected: '%s'\n", - must_work[i].in); - return EXIT_FAILURE; - } - - if (strcmp(buffer, must_work[i].out) != 0) { - fprintf(stderr, "Expected result: %s\n", - must_work[i].out); - fprintf(stderr, "Actual result: %s\n", buffer); - return EXIT_FAILURE; - } - } - - for (i = 0; i < sizeof(must_not_work) / sizeof(must_not_work[0]); ++i) { - strcpy(buffer, must_not_work[i]); - - if (canonicalize_name(buffer) == 0) { - fprintf(stderr, "Test case accepted: '%s'\n", - must_not_work[i]); - fprintf(stderr, "Transformed into: '%s'\n", buffer); - return EXIT_FAILURE; - } - } - - return EXIT_SUCCESS; -} diff --git a/tests/filename_sane.c b/tests/filename_sane.c deleted file mode 100644 index 86270b3..0000000 --- a/tests/filename_sane.c +++ /dev/null @@ -1,93 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * filename_sane.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "fstree.h" -#include "test.h" - -static const char *must_work[] = { - "foobar", - "test.txt", -#if !defined(_WIN32) && !defined(__WINDOWS__) && !defined(TEST_WIN32) - "\\foo", "foo\\", "foo\\bar", -#endif - NULL, -}; - -static const char *must_not_work[] = { - ".", - "..", - "/foo", - "foo/", - "foo/bar", - NULL, -}; - -static const char *must_not_work_here[] = { -#if defined(_WIN32) || defined(__WINDOWS__) || defined(TEST_WIN32) - "\\foo", "foo\\", "foo\\bar", - "foo", "fo:o", "fo\"o", - "fo|o", "fo?o", "fo*o", "fo\ro", - "CON", "PRN", "AUX", "NUL", - "COM1", "COM2", "LPT1", "LPT2", - "con", "prn", "aux", "nul", - "com1", "com2", "lpt1", "lpt2", - "AUX.txt", "aux.txt", "NUL.txt", "nul.txt", -#endif - NULL, -}; - -int main(void) -{ - size_t i; - - for (i = 0; must_work[i] != NULL; ++i) { - if (!is_filename_sane(must_work[i], false)) { - fprintf(stderr, "%s was rejected!\n", must_work[i]); - return EXIT_FAILURE; - } - - if (!is_filename_sane(must_work[i], true)) { - fprintf(stderr, - "%s was rejected when testing for " - "OS specific stuff!\n", must_work[i]); - return EXIT_FAILURE; - } - } - - for (i = 0; must_not_work[i] != NULL; ++i) { - if (is_filename_sane(must_not_work[i], false)) { - fprintf(stderr, "%s was accepted!\n", - must_not_work[i]); - return EXIT_FAILURE; - } - - if (is_filename_sane(must_not_work[i], true)) { - fprintf(stderr, - "%s was accepted when testing for " - "OS specific stuff!\n", must_not_work[i]); - return EXIT_FAILURE; - } - } - - for (i = 0; must_not_work_here[i] != NULL; ++i) { - if (!is_filename_sane(must_not_work_here[i], false)) { - fprintf(stderr, - "%s was rejected in the generic test!\n", - must_not_work_here[i]); - return EXIT_FAILURE; - } - - if (is_filename_sane(must_not_work_here[i], true)) { - fprintf(stderr, - "%s was accepted when testing for " - "OS specific stuff!\n", must_not_work_here[i]); - return EXIT_FAILURE; - } - } - - return EXIT_SUCCESS; -} diff --git a/tests/fstree1.txt b/tests/fstree1.txt deleted file mode 100644 index 090aff9..0000000 --- a/tests/fstree1.txt +++ /dev/null @@ -1,9 +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 "/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/fstree_from_dir.c b/tests/fstree_from_dir.c deleted file mode 100644 index af48d4d..0000000 --- a/tests/fstree_from_dir.c +++ /dev/null @@ -1,380 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_from_dir.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "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(void) -{ - struct stat sb; - tree_node_t *n; - fstree_t fs; - - /* 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/fstree_from_file.c b/tests/fstree_from_file.c deleted file mode 100644 index 140ffd7..0000000 --- a/tests/fstree_from_file.c +++ /dev/null @@ -1,89 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_from_file.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *n; - fstree_t fs; - - 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(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/fstree_fuzz.c b/tests/fstree_fuzz.c deleted file mode 100644 index ebc8c45..0000000 --- a/tests/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 "fstree.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/fstree_glob1.c b/tests/fstree_glob1.c deleted file mode 100644 index a3a5074..0000000 --- a/tests/fstree_glob1.c +++ /dev/null @@ -1,224 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_glob1.c - * - * Copyright (C) 2021 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "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, "tarcorpus"); - TEST_ASSERT(S_ISDIR(n->mode)); - TEST_ASSERT(n->parent == root); - TEST_NULL(n->next); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - - 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 == root->data.dir.children); - TEST_NULL(n->data.dir.children); - - n = n->next; - TEST_NULL(n); -} - -int main(void) -{ - fstree_t fs; - int ret; - - /* 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, 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); - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} diff --git a/tests/fstree_glob1.txt b/tests/fstree_glob1.txt deleted file mode 100644 index 0d96391..0000000 --- a/tests/fstree_glob1.txt +++ /dev/null @@ -1,2 +0,0 @@ -dir /tarcorpus 0755 0 0 -glob /tarcorpus 0755 0 0 -type d -- tar diff --git a/tests/fstree_glob2.txt b/tests/fstree_glob2.txt deleted file mode 100644 index f423b4a..0000000 --- a/tests/fstree_glob2.txt +++ /dev/null @@ -1,3 +0,0 @@ -dir /tarcorpus 0755 0 0 -glob /tarcorpus 0755 0 0 -type d tar -glob /tarcorpus 0644 0 0 -type f -name "*gnu*.tar" -- tar diff --git a/tests/fstree_init.c b/tests/fstree_init.c deleted file mode 100644 index 5970159..0000000 --- a/tests/fstree_init.c +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_init.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "internal.h" -#include "test.h" - -int main(void) -{ - fstree_t fs; - char *str; - - str = strdup("mtime=1337,uid=1000,gid=100,mode=0321"); - TEST_NOT_NULL(str); - TEST_ASSERT(fstree_init(&fs, str) == 0); - free(str); - TEST_EQUAL_UI(fs.defaults.st_mtime, 1337); - TEST_EQUAL_UI(fs.defaults.st_uid, 1000); - TEST_EQUAL_UI(fs.defaults.st_gid, 100); - TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0321); - fstree_cleanup(&fs); - - TEST_ASSERT(fstree_init(&fs, NULL) == 0); - if (fs.defaults.st_mtime != 0) { - TEST_EQUAL_UI(fs.defaults.st_mtime, get_source_date_epoch()); - } - TEST_EQUAL_UI(fs.defaults.st_uid, 0); - TEST_EQUAL_UI(fs.defaults.st_gid, 0); - TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0755); - fstree_cleanup(&fs); - - str = strdup("mode=07777"); - TEST_NOT_NULL(str); - TEST_ASSERT(fstree_init(&fs, str) == 0); - free(str); - fstree_cleanup(&fs); - - str = strdup("mode=017777"); - TEST_NOT_NULL(str); - TEST_ASSERT(fstree_init(&fs, str) != 0); - free(str); - - return EXIT_SUCCESS; -} diff --git a/tests/fstree_sort.c b/tests/fstree_sort.c deleted file mode 100644 index 40a270f..0000000 --- a/tests/fstree_sort.c +++ /dev/null @@ -1,101 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_sort.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "internal.h" -#include "test.h" - -int main(void) -{ - tree_node_t *a, *b, *c, *d; - struct stat sb; - fstree_t fs; - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFBLK | 0600; - sb.st_rdev = 1337; - - a = fstree_mknode(NULL, "a", 1, NULL, &sb); - b = fstree_mknode(NULL, "b", 1, NULL, &sb); - c = fstree_mknode(NULL, "c", 1, NULL, &sb); - d = fstree_mknode(NULL, "d", 1, NULL, &sb); - TEST_ASSERT(a != NULL && b != NULL && c != NULL && d != NULL); - - /* empty list */ - TEST_NULL(tree_node_list_sort(NULL)); - - /* single element */ - TEST_ASSERT(tree_node_list_sort(a) == a); - TEST_NULL(a->next); - - /* two elements, reverse order */ - b->next = a; - TEST_ASSERT(tree_node_list_sort(b) == a); - TEST_ASSERT(a->next == b); - TEST_NULL(b->next); - - /* two elements, sorted order */ - TEST_ASSERT(tree_node_list_sort(a) == a); - TEST_ASSERT(a->next == b); - TEST_NULL(b->next); - - /* three elements, reverse order */ - c->next = b; - b->next = a; - a->next = NULL; - - TEST_ASSERT(tree_node_list_sort(c) == a); - TEST_ASSERT(a->next == b); - TEST_ASSERT(b->next == c); - TEST_NULL(c->next); - - /* three elements, ordered */ - TEST_ASSERT(tree_node_list_sort(a) == a); - TEST_ASSERT(a->next == b); - TEST_ASSERT(b->next == c); - TEST_NULL(c->next); - - /* four elements, reverse order */ - d->next = c; - c->next = b; - b->next = a; - a->next = NULL; - - TEST_ASSERT(tree_node_list_sort(d) == a); - TEST_ASSERT(a->next == b); - TEST_ASSERT(b->next == c); - TEST_ASSERT(c->next == d); - TEST_NULL(d->next); - - /* four elements, sorted order */ - TEST_ASSERT(tree_node_list_sort(a) == a); - TEST_ASSERT(a->next == b); - TEST_ASSERT(b->next == c); - TEST_ASSERT(c->next == d); - TEST_NULL(d->next); - - /* force merge sort to go through LRLR pattern */ - b->next = a; - a->next = d; - d->next = c; - c->next = NULL; - - TEST_ASSERT(tree_node_list_sort(b) == a); - TEST_ASSERT(a->next == b); - TEST_ASSERT(b->next == c); - TEST_ASSERT(c->next == d); - TEST_NULL(d->next); - - /* cleanup and done */ - free(a); - free(b); - free(c); - free(d); - return EXIT_SUCCESS; -} diff --git a/tests/gen_inode_numbers.c b/tests/gen_inode_numbers.c deleted file mode 100644 index 68b06e8..0000000 --- a/tests/gen_inode_numbers.c +++ /dev/null @@ -1,89 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * gen_inode_table.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -static tree_node_t *gen_node(tree_node_t *parent, const char *name) -{ - struct stat sb; - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0755; - - return fstree_mknode(parent, name, strlen(name), NULL, &sb); -} - -static void check_children_before_root(tree_node_t *root) -{ - tree_node_t *n; - - for (n = root->data.dir.children; n != NULL; n = n->next) - TEST_LESS_THAN_UI(n->inode_num, root->inode_num); - - for (n = root->data.dir.children; n != NULL; n = n->next) - check_children_before_root(n); -} - -static void check_children_continuous(tree_node_t *root) -{ - tree_node_t *n; - - for (n = root->data.dir.children; n != NULL; n = n->next) { - if (n->next != NULL) { - TEST_EQUAL_UI(n->next->inode_num, (n->inode_num + 1)); - } - } - - for (n = root->data.dir.children; n != NULL; n = n->next) - check_children_continuous(n); -} - -int main(void) -{ - tree_node_t *a, *b, *c; - fstree_t fs; - - // inode table for the empty tree - TEST_ASSERT(fstree_init(&fs, NULL) == 0); - fstree_post_process(&fs); - TEST_EQUAL_UI(fs.unique_inode_count, 1); - TEST_EQUAL_UI(fs.root->inode_num, 1); - fstree_cleanup(&fs); - - // tree with 2 levels under root, fan out 3 - TEST_ASSERT(fstree_init(&fs, NULL) == 0); - - a = gen_node(fs.root, "a"); - b = gen_node(fs.root, "b"); - c = gen_node(fs.root, "c"); - TEST_NOT_NULL(a); - TEST_NOT_NULL(b); - TEST_NOT_NULL(c); - - TEST_NOT_NULL(gen_node(a, "a_a")); - TEST_NOT_NULL(gen_node(a, "a_b")); - TEST_NOT_NULL(gen_node(a, "a_c")); - - TEST_NOT_NULL(gen_node(b, "b_a")); - TEST_NOT_NULL(gen_node(b, "b_b")); - TEST_NOT_NULL(gen_node(b, "b_c")); - - TEST_NOT_NULL(gen_node(c, "c_a")); - TEST_NOT_NULL(gen_node(c, "c_b")); - TEST_NOT_NULL(gen_node(c, "c_c")); - - fstree_post_process(&fs); - TEST_EQUAL_UI(fs.unique_inode_count, 13); - - check_children_before_root(fs.root); - check_children_continuous(fs.root); - - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} diff --git a/tests/get_line.c b/tests/get_line.c deleted file mode 100644 index c317c0e..0000000 --- a/tests/get_line.c +++ /dev/null @@ -1,164 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * get_line.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstream.h" -#include "test.h" - -typedef struct { - size_t line_num; - const char *str; -} line_t; - -static void run_test_case(const line_t *lines, size_t count, - int flags) -{ - size_t i, line_num, old_line_num; - istream_t *fp; - char *line; - int ret; - - fp = istream_open_file(STRVALUE(TESTFILE)); - TEST_NOT_NULL(fp); - - line_num = 1; - line = NULL; - - for (i = 0; i < count; ++i) { - old_line_num = line_num; - ret = istream_get_line(fp, &line, &line_num, flags); - - TEST_ASSERT(line_num >= old_line_num); - TEST_EQUAL_I(ret, 0); - TEST_NOT_NULL(line); - - TEST_EQUAL_UI(line_num, lines[i].line_num); - TEST_STR_EQUAL(line, lines[i].str); - - free(line); - line = NULL; - line_num += 1; - } - - ret = istream_get_line(fp, &line, &line_num, flags); - TEST_ASSERT(ret > 0); - - sqfs_destroy(fp); -} - -static const line_t lines_raw[] = { - { 1, "" }, - { 2, "The quick" }, - { 3, " " }, - { 4, " brown fox " }, - { 5, "" }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 9, "" }, - { 10, "dog" }, - { 11, "" }, -}; - -static const line_t lines_ltrim[] = { - { 1, "" }, - { 2, "The quick" }, - { 3, "" }, - { 4, "brown fox " }, - { 5, "" }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 9, "" }, - { 10, "dog" }, - { 11, "" }, -}; - -static const line_t lines_rtrim[] = { - { 1, "" }, - { 2, "The quick" }, - { 3, "" }, - { 4, " brown fox" }, - { 5, "" }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 9, "" }, - { 10, "dog" }, - { 11, "" }, -}; - -static const line_t lines_trim[] = { - { 1, "" }, - { 2, "The quick" }, - { 3, "" }, - { 4, "brown fox" }, - { 5, "" }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 9, "" }, - { 10, "dog" }, - { 11, "" }, -}; - -static const line_t lines_no_empty[] = { - { 2, "The quick" }, - { 3, " " }, - { 4, " brown fox " }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 10, "dog" }, -}; - -static const line_t lines_no_empty_ltrim[] = { - { 2, "The quick" }, - { 4, "brown fox " }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 10, "dog" }, -}; - -static const line_t lines_no_empty_rtrim[] = { - { 2, "The quick" }, - { 4, " brown fox" }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 10, "dog" }, -}; - -static const line_t lines_no_empty_trim[] = { - { 2, "The quick" }, - { 4, "brown fox" }, - { 6, "jumps over" }, - { 7, "the" }, - { 8, "lazy" }, - { 10, "dog" }, -}; - -int main(void) -{ - run_test_case(lines_raw, 11, 0); - run_test_case(lines_ltrim, 11, ISTREAM_LINE_LTRIM); - run_test_case(lines_rtrim, 11, ISTREAM_LINE_RTRIM); - run_test_case(lines_trim, 11, - ISTREAM_LINE_LTRIM | ISTREAM_LINE_RTRIM); - - run_test_case(lines_no_empty, 7, ISTREAM_LINE_SKIP_EMPTY); - run_test_case(lines_no_empty_ltrim, 6, - ISTREAM_LINE_SKIP_EMPTY | ISTREAM_LINE_LTRIM); - run_test_case(lines_no_empty_rtrim, 6, - ISTREAM_LINE_SKIP_EMPTY | ISTREAM_LINE_RTRIM); - run_test_case(lines_no_empty_trim, 6, - ISTREAM_LINE_SKIP_EMPTY | ISTREAM_LINE_LTRIM | - ISTREAM_LINE_RTRIM); - - return EXIT_SUCCESS; -} diff --git a/tests/get_line.txt b/tests/get_line.txt deleted file mode 100644 index a1994f0..0000000 --- a/tests/get_line.txt +++ /dev/null @@ -1,11 +0,0 @@ - -The quick - - brown fox - -jumps over -the -lazy - -dog - diff --git a/tests/get_path.c b/tests/get_path.c deleted file mode 100644 index 8ca0ce0..0000000 --- a/tests/get_path.c +++ /dev/null @@ -1,58 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * get_path.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *a, *b, *c, *d; - struct stat sb; - fstree_t fs; - char *str; - - TEST_ASSERT(fstree_init(&fs, NULL) == 0); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0750; - sb.st_uid = 1000; - sb.st_gid = 100; - - a = fstree_add_generic(&fs, "foo", &sb, NULL); - b = fstree_add_generic(&fs, "foo/bar", &sb, NULL); - c = fstree_add_generic(&fs, "foo/bar/baz", &sb, NULL); - d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL); - - str = fstree_get_path(fs.root); - TEST_NOT_NULL(str); - TEST_STR_EQUAL(str, "/"); - free(str); - - str = fstree_get_path(a); - TEST_NOT_NULL(str); - TEST_STR_EQUAL(str, "/foo"); - free(str); - - str = fstree_get_path(b); - TEST_NOT_NULL(str); - TEST_STR_EQUAL(str, "/foo/bar"); - free(str); - - str = fstree_get_path(c); - TEST_NOT_NULL(str); - TEST_STR_EQUAL(str, "/foo/bar/baz"); - free(str); - - str = fstree_get_path(d); - TEST_NOT_NULL(str); - TEST_STR_EQUAL(str, "/foo/bar/baz/dir"); - free(str); - - fstree_cleanup(&fs); - return EXIT_SUCCESS; -} diff --git a/tests/libfstream/Makemodule.am b/tests/libfstream/Makemodule.am new file mode 100644 index 0000000..bba35f5 --- /dev/null +++ b/tests/libfstream/Makemodule.am @@ -0,0 +1,11 @@ +test_get_line_SOURCES = tests/libfstream/get_line.c tests/test.h +test_get_line_LDADD = libfstream.a libcompat.a +test_get_line_CPPFLAGS = $(AM_CPPFLAGS) +test_get_line_CPPFLAGS += -DTESTFILE=$(top_srcdir)/tests/libfstream/get_line.txt + +if BUILD_TOOLS +check_PROGRAMS += test_get_line +TESTS += test_get_line +endif + +EXTRA_DIST += $(top_srcdir)/tests/libfstream/get_line.txt diff --git a/tests/libfstream/get_line.c b/tests/libfstream/get_line.c new file mode 100644 index 0000000..a2f6d85 --- /dev/null +++ b/tests/libfstream/get_line.c @@ -0,0 +1,164 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * get_line.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstream.h" +#include "../test.h" + +typedef struct { + size_t line_num; + const char *str; +} line_t; + +static void run_test_case(const line_t *lines, size_t count, + int flags) +{ + size_t i, line_num, old_line_num; + istream_t *fp; + char *line; + int ret; + + fp = istream_open_file(STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + + line_num = 1; + line = NULL; + + for (i = 0; i < count; ++i) { + old_line_num = line_num; + ret = istream_get_line(fp, &line, &line_num, flags); + + TEST_ASSERT(line_num >= old_line_num); + TEST_EQUAL_I(ret, 0); + TEST_NOT_NULL(line); + + TEST_EQUAL_UI(line_num, lines[i].line_num); + TEST_STR_EQUAL(line, lines[i].str); + + free(line); + line = NULL; + line_num += 1; + } + + ret = istream_get_line(fp, &line, &line_num, flags); + TEST_ASSERT(ret > 0); + + sqfs_destroy(fp); +} + +static const line_t lines_raw[] = { + { 1, "" }, + { 2, "The quick" }, + { 3, " " }, + { 4, " brown fox " }, + { 5, "" }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 9, "" }, + { 10, "dog" }, + { 11, "" }, +}; + +static const line_t lines_ltrim[] = { + { 1, "" }, + { 2, "The quick" }, + { 3, "" }, + { 4, "brown fox " }, + { 5, "" }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 9, "" }, + { 10, "dog" }, + { 11, "" }, +}; + +static const line_t lines_rtrim[] = { + { 1, "" }, + { 2, "The quick" }, + { 3, "" }, + { 4, " brown fox" }, + { 5, "" }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 9, "" }, + { 10, "dog" }, + { 11, "" }, +}; + +static const line_t lines_trim[] = { + { 1, "" }, + { 2, "The quick" }, + { 3, "" }, + { 4, "brown fox" }, + { 5, "" }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 9, "" }, + { 10, "dog" }, + { 11, "" }, +}; + +static const line_t lines_no_empty[] = { + { 2, "The quick" }, + { 3, " " }, + { 4, " brown fox " }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 10, "dog" }, +}; + +static const line_t lines_no_empty_ltrim[] = { + { 2, "The quick" }, + { 4, "brown fox " }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 10, "dog" }, +}; + +static const line_t lines_no_empty_rtrim[] = { + { 2, "The quick" }, + { 4, " brown fox" }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 10, "dog" }, +}; + +static const line_t lines_no_empty_trim[] = { + { 2, "The quick" }, + { 4, "brown fox" }, + { 6, "jumps over" }, + { 7, "the" }, + { 8, "lazy" }, + { 10, "dog" }, +}; + +int main(void) +{ + run_test_case(lines_raw, 11, 0); + run_test_case(lines_ltrim, 11, ISTREAM_LINE_LTRIM); + run_test_case(lines_rtrim, 11, ISTREAM_LINE_RTRIM); + run_test_case(lines_trim, 11, + ISTREAM_LINE_LTRIM | ISTREAM_LINE_RTRIM); + + run_test_case(lines_no_empty, 7, ISTREAM_LINE_SKIP_EMPTY); + run_test_case(lines_no_empty_ltrim, 6, + ISTREAM_LINE_SKIP_EMPTY | ISTREAM_LINE_LTRIM); + run_test_case(lines_no_empty_rtrim, 6, + ISTREAM_LINE_SKIP_EMPTY | ISTREAM_LINE_RTRIM); + run_test_case(lines_no_empty_trim, 6, + ISTREAM_LINE_SKIP_EMPTY | ISTREAM_LINE_LTRIM | + ISTREAM_LINE_RTRIM); + + return EXIT_SUCCESS; +} diff --git a/tests/libfstream/get_line.txt b/tests/libfstream/get_line.txt new file mode 100644 index 0000000..a1994f0 --- /dev/null +++ b/tests/libfstream/get_line.txt @@ -0,0 +1,11 @@ + +The quick + + brown fox + +jumps over +the +lazy + +dog + diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am new file mode 100644 index 0000000..4dc6da1 --- /dev/null +++ b/tests/libfstree/Makemodule.am @@ -0,0 +1,76 @@ +FSTDATADIR=$(top_srcdir)/tests/libfstree + +test_canonicalize_name_SOURCES = tests/libfstree/canonicalize_name.c +test_canonicalize_name_SOURCES += tests/test.h +test_canonicalize_name_LDADD = libfstree.a + +test_mknode_simple_SOURCES = tests/libfstree/mknode_simple.c tests/test.h +test_mknode_simple_LDADD = libfstree.a libcompat.a + +test_mknode_slink_SOURCES = tests/libfstree/mknode_slink.c tests/test.h +test_mknode_slink_LDADD = libfstree.a libcompat.a + +test_mknode_reg_SOURCES = tests/libfstree/mknode_reg.c tests/test.h +test_mknode_reg_LDADD = libfstree.a libcompat.a + +test_mknode_dir_SOURCES = tests/libfstree/mknode_dir.c tests/test.h +test_mknode_dir_LDADD = libfstree.a libcompat.a + +test_gen_inode_numbers_SOURCES = tests/libfstree/gen_inode_numbers.c +test_gen_inode_numbers_SOURCES += tests/test.h +test_gen_inode_numbers_LDADD = libfstree.a libcompat.a + +test_add_by_path_SOURCES = tests/libfstree/add_by_path.c tests/test.h +test_add_by_path_LDADD = libfstree.a libcompat.a + +test_get_path_SOURCES = tests/libfstree/get_path.c tests/test.h +test_get_path_LDADD = libfstree.a libcompat.a + +test_fstree_sort_SOURCES = tests/libfstree/fstree_sort.c tests/test.h +test_fstree_sort_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree +test_fstree_sort_LDADD = libfstree.a libfstream.a libcompat.a + +test_fstree_from_file_SOURCES = tests/libfstree/fstree_from_file.c tests/test.h +test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) +test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(FSTDATADIR)/fstree1.txt +test_fstree_from_file_LDADD = libfstree.a libfstream.a libcompat.a + +test_fstree_glob1_SOURCES = tests/libfstree/fstree_glob1.c tests/test.h +test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(FSTDATADIR) +test_fstree_glob1_LDADD = libfstree.a libfstream.a libcompat.a + +test_fstree_from_dir_SOURCES = tests/libfstree/fstree_from_dir.c tests/test.h +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 libcompat.a + +test_fstree_init_SOURCES = tests/libfstree/fstree_init.c tests/test.h +test_fstree_init_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree +test_fstree_init_LDADD = libfstree.a libfstream.a libcompat.a + +test_filename_sane_SOURCES = tests/libfstree/filename_sane.c +test_filename_sane_SOURCES += lib/fstree/filename_sane.c + +test_filename_sane_w32_SOURCES = tests/libfstree/filename_sane.c +test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c +test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1 + +fstree_fuzz_SOURCES = tests/libfstree/fstree_fuzz.c +fstree_fuzz_LDADD = libfstree.a libfstream.a libcompat.a + +FSTREE_TESTS = \ + test_canonicalize_name 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_filename_sane test_filename_sane_w32 \ + test_fstree_from_dir test_fstree_glob1 + +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 diff --git a/tests/libfstree/add_by_path.c b/tests/libfstree/add_by_path.c new file mode 100644 index 0000000..94c0dc9 --- /dev/null +++ b/tests/libfstree/add_by_path.c @@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * add_by_path.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *a, *b; + struct stat sb; + fstree_t fs; + char *opts; + + opts = strdup("mode=0755,uid=21,gid=42"); + TEST_ASSERT(fstree_init(&fs, opts) == 0); + free(opts); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0750; + sb.st_uid = 1000; + sb.st_gid = 100; + + TEST_EQUAL_UI(fs.root->link_count, 2); + + a = fstree_add_generic(&fs, "dir", &sb, NULL); + TEST_NOT_NULL(a); + TEST_STR_EQUAL(a->name, "dir"); + TEST_EQUAL_UI(a->mode, sb.st_mode); + TEST_EQUAL_UI(a->uid, sb.st_uid); + TEST_EQUAL_UI(a->gid, sb.st_gid); + TEST_ASSERT(a->parent == fs.root); + TEST_EQUAL_UI(a->link_count, 2); + TEST_NULL(a->next); + TEST_ASSERT(fs.root->data.dir.children == a); + TEST_EQUAL_UI(fs.root->link_count, 3); + TEST_ASSERT(!a->data.dir.created_implicitly); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFBLK | 0640; + sb.st_rdev = 1234; + + b = fstree_add_generic(&fs, "blkdev", &sb, NULL); + TEST_NOT_NULL(b); + TEST_ASSERT(b != a); + TEST_STR_EQUAL(b->name, "blkdev"); + TEST_EQUAL_UI(b->mode, sb.st_mode); + TEST_EQUAL_UI(b->uid, sb.st_uid); + TEST_EQUAL_UI(b->gid, sb.st_gid); + TEST_ASSERT(b->parent == fs.root); + TEST_EQUAL_UI(b->link_count, 1); + TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_ASSERT(b->next == a); + TEST_EQUAL_UI(fs.root->link_count, 4); + TEST_ASSERT(fs.root->data.dir.children == b); + + TEST_NULL(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL)); + TEST_EQUAL_UI(errno, ENOTDIR); + + TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); + TEST_EQUAL_UI(errno, EEXIST); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0755; + TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); + TEST_EQUAL_UI(errno, EEXIST); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFCHR | 0444; + b = fstree_add_generic(&fs, "dir/chrdev", &sb, NULL); + TEST_NOT_NULL(b); + TEST_EQUAL_UI(b->mode, sb.st_mode); + TEST_EQUAL_UI(b->uid, sb.st_uid); + TEST_EQUAL_UI(b->gid, sb.st_gid); + TEST_EQUAL_UI(b->link_count, 1); + TEST_ASSERT(b->parent == a); + TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_NULL(b->next); + TEST_ASSERT(a->data.dir.children == b); + + TEST_EQUAL_UI(a->link_count, 3); + TEST_EQUAL_UI(fs.root->link_count, 4); + + b = fstree_add_generic(&fs, "dir/foo/chrdev", &sb, NULL); + TEST_NOT_NULL(b); + TEST_NULL(b->next); + TEST_EQUAL_UI(b->mode, sb.st_mode); + TEST_EQUAL_UI(b->uid, sb.st_uid); + TEST_EQUAL_UI(b->gid, sb.st_gid); + TEST_EQUAL_UI(b->link_count, 1); + TEST_ASSERT(b->parent != a); + TEST_ASSERT(b->parent->parent == a); + TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_NULL(b->next); + + TEST_EQUAL_UI(a->link_count, 4); + TEST_EQUAL_UI(fs.root->link_count, 4); + TEST_ASSERT(a->data.dir.children != b); + + b = b->parent; + TEST_ASSERT(b->data.dir.created_implicitly); + TEST_EQUAL_UI(b->mode, S_IFDIR | 0755); + TEST_EQUAL_UI(b->uid, 21); + TEST_EQUAL_UI(b->gid, 42); + TEST_EQUAL_UI(b->link_count, 3); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0750; + sb.st_uid = 1000; + sb.st_gid = 100; + + a = fstree_add_generic(&fs, "dir/foo", &sb, NULL); + TEST_NOT_NULL(a); + TEST_ASSERT(a == b); + TEST_ASSERT(!a->data.dir.created_implicitly); + TEST_EQUAL_UI(a->mode, sb.st_mode); + TEST_EQUAL_UI(a->uid, sb.st_uid); + TEST_EQUAL_UI(a->gid, sb.st_gid); + TEST_EQUAL_UI(a->link_count, 3); + + TEST_EQUAL_UI(a->parent->link_count, 4); + TEST_EQUAL_UI(fs.root->link_count, 4); + + TEST_NULL(fstree_add_generic(&fs, "dir/foo", &sb, NULL)); + TEST_EQUAL_UI(errno, EEXIST); + + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/canonicalize_name.c b/tests/libfstree/canonicalize_name.c new file mode 100644 index 0000000..37b07e3 --- /dev/null +++ b/tests/libfstree/canonicalize_name.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * canonicalize_name.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "fstree.h" +#include "../test.h" + +static const struct { + const char *in; + const char *out; +} must_work[] = { + { "", "" }, + { "/", "" }, + { "\\", "\\" }, + { "///", "" }, + { "\\\\\\", "\\\\\\" }, + { "/\\//\\\\/", "\\/\\\\" }, + { "foo/bar/test", "foo/bar/test" }, + { "foo\\bar\\test", "foo\\bar\\test" }, + { "/foo/bar/test/", "foo/bar/test" }, + { "\\foo\\bar\\test\\", "\\foo\\bar\\test\\" }, + { "///foo//bar//test///", "foo/bar/test" }, + { "./foo/././bar/test/./.", "foo/bar/test" }, + { "./foo/././", "foo" }, + { ".", "" }, + { "./", "" }, + { "./.", "" }, + { "foo/.../bar", "foo/.../bar" }, + { "foo/.test/bar", "foo/.test/bar" }, +}; + +static const char *must_not_work[] = { + "..", + "foo/../bar", + "../foo/bar", + "foo/bar/..", + "foo/bar/../", +}; + +int main(void) +{ + char buffer[512]; + size_t i; + + for (i = 0; i < sizeof(must_work) / sizeof(must_work[0]); ++i) { + strcpy(buffer, must_work[i].in); + + if (canonicalize_name(buffer)) { + fprintf(stderr, "Test case rejected: '%s'\n", + must_work[i].in); + return EXIT_FAILURE; + } + + if (strcmp(buffer, must_work[i].out) != 0) { + fprintf(stderr, "Expected result: %s\n", + must_work[i].out); + fprintf(stderr, "Actual result: %s\n", buffer); + return EXIT_FAILURE; + } + } + + for (i = 0; i < sizeof(must_not_work) / sizeof(must_not_work[0]); ++i) { + strcpy(buffer, must_not_work[i]); + + if (canonicalize_name(buffer) == 0) { + fprintf(stderr, "Test case accepted: '%s'\n", + must_not_work[i]); + fprintf(stderr, "Transformed into: '%s'\n", buffer); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/filename_sane.c b/tests/libfstree/filename_sane.c new file mode 100644 index 0000000..4d25b33 --- /dev/null +++ b/tests/libfstree/filename_sane.c @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * filename_sane.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "fstree.h" +#include "../test.h" + +static const char *must_work[] = { + "foobar", + "test.txt", +#if !defined(_WIN32) && !defined(__WINDOWS__) && !defined(TEST_WIN32) + "\\foo", "foo\\", "foo\\bar", +#endif + NULL, +}; + +static const char *must_not_work[] = { + ".", + "..", + "/foo", + "foo/", + "foo/bar", + NULL, +}; + +static const char *must_not_work_here[] = { +#if defined(_WIN32) || defined(__WINDOWS__) || defined(TEST_WIN32) + "\\foo", "foo\\", "foo\\bar", + "foo", "fo:o", "fo\"o", + "fo|o", "fo?o", "fo*o", "fo\ro", + "CON", "PRN", "AUX", "NUL", + "COM1", "COM2", "LPT1", "LPT2", + "con", "prn", "aux", "nul", + "com1", "com2", "lpt1", "lpt2", + "AUX.txt", "aux.txt", "NUL.txt", "nul.txt", +#endif + NULL, +}; + +int main(void) +{ + size_t i; + + for (i = 0; must_work[i] != NULL; ++i) { + if (!is_filename_sane(must_work[i], false)) { + fprintf(stderr, "%s was rejected!\n", must_work[i]); + return EXIT_FAILURE; + } + + if (!is_filename_sane(must_work[i], true)) { + fprintf(stderr, + "%s was rejected when testing for " + "OS specific stuff!\n", must_work[i]); + return EXIT_FAILURE; + } + } + + for (i = 0; must_not_work[i] != NULL; ++i) { + if (is_filename_sane(must_not_work[i], false)) { + fprintf(stderr, "%s was accepted!\n", + must_not_work[i]); + return EXIT_FAILURE; + } + + if (is_filename_sane(must_not_work[i], true)) { + fprintf(stderr, + "%s was accepted when testing for " + "OS specific stuff!\n", must_not_work[i]); + return EXIT_FAILURE; + } + } + + for (i = 0; must_not_work_here[i] != NULL; ++i) { + if (!is_filename_sane(must_not_work_here[i], false)) { + fprintf(stderr, + "%s was rejected in the generic test!\n", + must_not_work_here[i]); + return EXIT_FAILURE; + } + + if (is_filename_sane(must_not_work_here[i], true)) { + fprintf(stderr, + "%s was accepted when testing for " + "OS specific stuff!\n", must_not_work_here[i]); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/fstree1.txt b/tests/libfstree/fstree1.txt new file mode 100644 index 0000000..090aff9 --- /dev/null +++ b/tests/libfstree/fstree1.txt @@ -0,0 +1,9 @@ +# 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 "/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 new file mode 100644 index 0000000..7db1b74 --- /dev/null +++ b/tests/libfstree/fstree_from_dir.c @@ -0,0 +1,380 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_from_dir.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../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(void) +{ + struct stat sb; + tree_node_t *n; + fstree_t fs; + + /* 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 new file mode 100644 index 0000000..c8816e6 --- /dev/null +++ b/tests/libfstree/fstree_from_file.c @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_from_file.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *n; + fstree_t fs; + + 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(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 new file mode 100644 index 0000000..ebc8c45 --- /dev/null +++ b/tests/libfstree/fstree_fuzz.c @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_fuzz.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.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/libfstree/fstree_glob1.c b/tests/libfstree/fstree_glob1.c new file mode 100644 index 0000000..592180b --- /dev/null +++ b/tests/libfstree/fstree_glob1.c @@ -0,0 +1,224 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_glob1.c + * + * Copyright (C) 2021 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../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, "tarcorpus"); + TEST_ASSERT(S_ISDIR(n->mode)); + TEST_ASSERT(n->parent == root); + TEST_NULL(n->next); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + + 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 == root->data.dir.children); + TEST_NULL(n->data.dir.children); + + n = n->next; + TEST_NULL(n); +} + +int main(void) +{ + fstree_t fs; + int ret; + + /* 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, 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); + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/fstree_glob1.txt b/tests/libfstree/fstree_glob1.txt new file mode 100644 index 0000000..b1df979 --- /dev/null +++ b/tests/libfstree/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/libfstree/fstree_glob2.txt b/tests/libfstree/fstree_glob2.txt new file mode 100644 index 0000000..3c8019b --- /dev/null +++ b/tests/libfstree/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/libfstree/fstree_init.c b/tests/libfstree/fstree_init.c new file mode 100644 index 0000000..a101143 --- /dev/null +++ b/tests/libfstree/fstree_init.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_init.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "internal.h" +#include "../test.h" + +int main(void) +{ + fstree_t fs; + char *str; + + str = strdup("mtime=1337,uid=1000,gid=100,mode=0321"); + TEST_NOT_NULL(str); + TEST_ASSERT(fstree_init(&fs, str) == 0); + free(str); + TEST_EQUAL_UI(fs.defaults.st_mtime, 1337); + TEST_EQUAL_UI(fs.defaults.st_uid, 1000); + TEST_EQUAL_UI(fs.defaults.st_gid, 100); + TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0321); + fstree_cleanup(&fs); + + TEST_ASSERT(fstree_init(&fs, NULL) == 0); + if (fs.defaults.st_mtime != 0) { + TEST_EQUAL_UI(fs.defaults.st_mtime, get_source_date_epoch()); + } + TEST_EQUAL_UI(fs.defaults.st_uid, 0); + TEST_EQUAL_UI(fs.defaults.st_gid, 0); + TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0755); + fstree_cleanup(&fs); + + str = strdup("mode=07777"); + TEST_NOT_NULL(str); + TEST_ASSERT(fstree_init(&fs, str) == 0); + free(str); + fstree_cleanup(&fs); + + str = strdup("mode=017777"); + TEST_NOT_NULL(str); + TEST_ASSERT(fstree_init(&fs, str) != 0); + free(str); + + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/fstree_sort.c b/tests/libfstree/fstree_sort.c new file mode 100644 index 0000000..6fc7543 --- /dev/null +++ b/tests/libfstree/fstree_sort.c @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * fstree_sort.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "internal.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *a, *b, *c, *d; + struct stat sb; + fstree_t fs; + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFBLK | 0600; + sb.st_rdev = 1337; + + a = fstree_mknode(NULL, "a", 1, NULL, &sb); + b = fstree_mknode(NULL, "b", 1, NULL, &sb); + c = fstree_mknode(NULL, "c", 1, NULL, &sb); + d = fstree_mknode(NULL, "d", 1, NULL, &sb); + TEST_ASSERT(a != NULL && b != NULL && c != NULL && d != NULL); + + /* empty list */ + TEST_NULL(tree_node_list_sort(NULL)); + + /* single element */ + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_NULL(a->next); + + /* two elements, reverse order */ + b->next = a; + TEST_ASSERT(tree_node_list_sort(b) == a); + TEST_ASSERT(a->next == b); + TEST_NULL(b->next); + + /* two elements, sorted order */ + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_ASSERT(a->next == b); + TEST_NULL(b->next); + + /* three elements, reverse order */ + c->next = b; + b->next = a; + a->next = NULL; + + TEST_ASSERT(tree_node_list_sort(c) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_NULL(c->next); + + /* three elements, ordered */ + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_NULL(c->next); + + /* four elements, reverse order */ + d->next = c; + c->next = b; + b->next = a; + a->next = NULL; + + TEST_ASSERT(tree_node_list_sort(d) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_ASSERT(c->next == d); + TEST_NULL(d->next); + + /* four elements, sorted order */ + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_ASSERT(c->next == d); + TEST_NULL(d->next); + + /* force merge sort to go through LRLR pattern */ + b->next = a; + a->next = d; + d->next = c; + c->next = NULL; + + TEST_ASSERT(tree_node_list_sort(b) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_ASSERT(c->next == d); + TEST_NULL(d->next); + + /* cleanup and done */ + free(a); + free(b); + free(c); + free(d); + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/gen_inode_numbers.c b/tests/libfstree/gen_inode_numbers.c new file mode 100644 index 0000000..8ee2315 --- /dev/null +++ b/tests/libfstree/gen_inode_numbers.c @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * gen_inode_table.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +static tree_node_t *gen_node(tree_node_t *parent, const char *name) +{ + struct stat sb; + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0755; + + return fstree_mknode(parent, name, strlen(name), NULL, &sb); +} + +static void check_children_before_root(tree_node_t *root) +{ + tree_node_t *n; + + for (n = root->data.dir.children; n != NULL; n = n->next) + TEST_LESS_THAN_UI(n->inode_num, root->inode_num); + + for (n = root->data.dir.children; n != NULL; n = n->next) + check_children_before_root(n); +} + +static void check_children_continuous(tree_node_t *root) +{ + tree_node_t *n; + + for (n = root->data.dir.children; n != NULL; n = n->next) { + if (n->next != NULL) { + TEST_EQUAL_UI(n->next->inode_num, (n->inode_num + 1)); + } + } + + for (n = root->data.dir.children; n != NULL; n = n->next) + check_children_continuous(n); +} + +int main(void) +{ + tree_node_t *a, *b, *c; + fstree_t fs; + + // inode table for the empty tree + TEST_ASSERT(fstree_init(&fs, NULL) == 0); + fstree_post_process(&fs); + TEST_EQUAL_UI(fs.unique_inode_count, 1); + TEST_EQUAL_UI(fs.root->inode_num, 1); + fstree_cleanup(&fs); + + // tree with 2 levels under root, fan out 3 + TEST_ASSERT(fstree_init(&fs, NULL) == 0); + + a = gen_node(fs.root, "a"); + b = gen_node(fs.root, "b"); + c = gen_node(fs.root, "c"); + TEST_NOT_NULL(a); + TEST_NOT_NULL(b); + TEST_NOT_NULL(c); + + TEST_NOT_NULL(gen_node(a, "a_a")); + TEST_NOT_NULL(gen_node(a, "a_b")); + TEST_NOT_NULL(gen_node(a, "a_c")); + + TEST_NOT_NULL(gen_node(b, "b_a")); + TEST_NOT_NULL(gen_node(b, "b_b")); + TEST_NOT_NULL(gen_node(b, "b_c")); + + TEST_NOT_NULL(gen_node(c, "c_a")); + TEST_NOT_NULL(gen_node(c, "c_b")); + TEST_NOT_NULL(gen_node(c, "c_c")); + + fstree_post_process(&fs); + TEST_EQUAL_UI(fs.unique_inode_count, 13); + + check_children_before_root(fs.root); + check_children_continuous(fs.root); + + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/get_path.c b/tests/libfstree/get_path.c new file mode 100644 index 0000000..9bf618b --- /dev/null +++ b/tests/libfstree/get_path.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * get_path.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *a, *b, *c, *d; + struct stat sb; + fstree_t fs; + char *str; + + TEST_ASSERT(fstree_init(&fs, NULL) == 0); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0750; + sb.st_uid = 1000; + sb.st_gid = 100; + + a = fstree_add_generic(&fs, "foo", &sb, NULL); + b = fstree_add_generic(&fs, "foo/bar", &sb, NULL); + c = fstree_add_generic(&fs, "foo/bar/baz", &sb, NULL); + d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL); + + str = fstree_get_path(fs.root); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/"); + free(str); + + str = fstree_get_path(a); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo"); + free(str); + + str = fstree_get_path(b); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo/bar"); + free(str); + + str = fstree_get_path(c); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo/bar/baz"); + free(str); + + str = fstree_get_path(d); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo/bar/baz/dir"); + free(str); + + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/mknode_dir.c b/tests/libfstree/mknode_dir.c new file mode 100644 index 0000000..be1156f --- /dev/null +++ b/tests/libfstree/mknode_dir.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * mknode_dir.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *root, *a, *b; + struct stat sb; + fstree_t fs; + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFDIR | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 4096; + + root = fstree_mknode(NULL, "rootdir", 7, NULL, &sb); + TEST_EQUAL_UI(root->uid, sb.st_uid); + TEST_EQUAL_UI(root->gid, sb.st_gid); + TEST_EQUAL_UI(root->mode, sb.st_mode); + TEST_EQUAL_UI(root->link_count, 2); + TEST_ASSERT(root->name >= (char *)root->payload); + TEST_STR_EQUAL(root->name, "rootdir"); + TEST_NULL(root->data.dir.children); + TEST_NULL(root->parent); + TEST_NULL(root->next); + + a = fstree_mknode(root, "adir", 4, NULL, &sb); + TEST_ASSERT(a->parent == root); + TEST_NULL(a->next); + TEST_EQUAL_UI(a->link_count, 2); + TEST_EQUAL_UI(root->link_count, 3); + TEST_ASSERT(root->data.dir.children == a); + TEST_NULL(root->parent); + TEST_NULL(root->next); + + b = fstree_mknode(root, "bdir", 4, NULL, &sb); + TEST_ASSERT(a->parent == root); + TEST_ASSERT(b->parent == root); + TEST_EQUAL_UI(b->link_count, 2); + TEST_ASSERT(root->data.dir.children == b); + TEST_EQUAL_UI(root->link_count, 4); + TEST_ASSERT(b->next == a); + TEST_NULL(a->next); + TEST_NULL(root->parent); + TEST_NULL(root->next); + + free(root); + free(a); + free(b); + + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/mknode_reg.c b/tests/libfstree/mknode_reg.c new file mode 100644 index 0000000..1f7ec88 --- /dev/null +++ b/tests/libfstree/mknode_reg.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * mknode_reg.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *node; + struct stat sb; + fstree_t fs; + + memset(&fs, 0, sizeof(fs)); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFREG | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 4096; + + node = fstree_mknode(NULL, "filename", 8, "input", &sb); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_NULL(node->parent); + TEST_EQUAL_UI(node->link_count, 1); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.file.input_file >= (char *)node->payload); + TEST_ASSERT(node->data.file.input_file >= node->name + 8); + TEST_STR_EQUAL(node->name, "filename"); + TEST_STR_EQUAL(node->data.file.input_file, "input"); + free(node); + + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/mknode_simple.c b/tests/libfstree/mknode_simple.c new file mode 100644 index 0000000..b8505ed --- /dev/null +++ b/tests/libfstree/mknode_simple.c @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * mknode_simple.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *node; + struct stat sb; + fstree_t fs; + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFSOCK | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 1337; + + node = fstree_mknode(NULL, "sockfile", 8, NULL, &sb); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "sockfile"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_NULL(node->data.target); + TEST_EQUAL_UI(node->data.devno, 0); + free(node); + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFIFO | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 1337; + + node = fstree_mknode(NULL, "fifo", 4, NULL, &sb); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "fifo"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_NULL(node->data.target); + TEST_EQUAL_UI(node->data.devno, 0); + free(node); + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFBLK | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 1337; + + node = fstree_mknode(NULL, "blkdev", 6, NULL, &sb); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "blkdev"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_EQUAL_UI(node->data.devno, sb.st_rdev); + TEST_NULL(node->parent); + free(node); + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFCHR | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 1337; + + node = fstree_mknode(NULL, "chardev", 7, NULL, &sb); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "chardev"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_EQUAL_UI(node->data.devno, sb.st_rdev); + TEST_NULL(node->parent); + free(node); + + return EXIT_SUCCESS; +} diff --git a/tests/libfstree/mknode_slink.c b/tests/libfstree/mknode_slink.c new file mode 100644 index 0000000..29f2679 --- /dev/null +++ b/tests/libfstree/mknode_slink.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * mknode_slink.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "fstree.h" +#include "../test.h" + +int main(void) +{ + tree_node_t *node; + struct stat sb; + fstree_t fs; + + memset(&fs, 0, sizeof(fs)); + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFLNK | 0654; + sb.st_uid = 123; + sb.st_gid = 456; + sb.st_rdev = 789; + sb.st_size = 1337; + + node = fstree_mknode(NULL, "symlink", 7, "target", &sb); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.target >= (char *)node->payload); + TEST_ASSERT(node->data.target >= node->name + 8); + TEST_STR_EQUAL(node->name, "symlink"); + TEST_STR_EQUAL(node->data.target, "target"); + free(node); + + node = fstree_mknode(NULL, "symlink", 7, "", &sb); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.target >= (char *)node->payload); + TEST_ASSERT(node->data.target >= node->name + 8); + TEST_STR_EQUAL(node->name, "symlink"); + TEST_STR_EQUAL(node->data.target, ""); + free(node); + + return EXIT_SUCCESS; +} diff --git a/tests/libsqfs/Makemodule.am b/tests/libsqfs/Makemodule.am new file mode 100644 index 0000000..8ca38b1 --- /dev/null +++ b/tests/libsqfs/Makemodule.am @@ -0,0 +1,5 @@ +test_abi_SOURCES = tests/libsqfs/abi.c tests/test.h +test_abi_LDADD = libsquashfs.la + +check_PROGRAMS += test_abi +TESTS += test_abi diff --git a/tests/libsqfs/abi.c b/tests/libsqfs/abi.c new file mode 100644 index 0000000..ea0049d --- /dev/null +++ b/tests/libsqfs/abi.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * abi.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "sqfs/compressor.h" +#include "../test.h" + +int main(void) +{ + sqfs_compressor_config_t cfg; + + TEST_EQUAL_UI(sizeof(cfg.opt.gzip), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.lzo), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.xz), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.padd0), sizeof(cfg.opt)); + + return EXIT_SUCCESS; +} diff --git a/tests/libtar/Makemodule.am b/tests/libtar/Makemodule.am new file mode 100644 index 0000000..bc829fb --- /dev/null +++ b/tests/libtar/Makemodule.am @@ -0,0 +1,178 @@ +TARDATADIR=$(top_srcdir)/tests/libtar/data + +test_tar_gnu0_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_gnu0_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu0_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar + +test_tar_gnu1_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_gnu1_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu1_CPPFLAGS += -DTESTFILE=format-acceptance/gnu-g.tar + +test_tar_gnu2_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_gnu2_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu2_CPPFLAGS += -DTESTFILE=user-group-largenum/gnu.tar +test_tar_gnu2_CPPFLAGS += -DTESTUID=0x80000000 -DTESTGID=0x80000000 +test_tar_gnu2_CPPFLAGS += -DTESTTS=1542995392 + +test_tar_gnu3_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_gnu3_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu3_CPPFLAGS += -DTESTFILE=negative-mtime/gnu.tar -DTESTTS=-315622800 + +test_tar_gnu4_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_gnu4_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu4_CPPFLAGS += -DTESTFILE=long-paths/gnu.tar -DLONG_NAME_TEST +test_tar_gnu4_CPPFLAGS += -DTESTTS=1542909670 + +test_tar_gnu5_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_gnu5_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu5_CPPFLAGS += -DTESTFILE=large-mtime/gnu.tar -DTESTTS=8589934592L + +test_tar_gnu6_SOURCES = tests/libtar/tar_big_file.c tests/test.h +test_tar_gnu6_LDADD = libtar.a libfstream.a libcompat.a +test_tar_gnu6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_gnu6_CPPFLAGS += -DTESTFILE=file-size/gnu.tar + +test_tar_pax0_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_pax0_LDADD = libtar.a libfstream.a libcompat.a +test_tar_pax0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_pax0_CPPFLAGS += -DTESTFILE=format-acceptance/pax.tar + +test_tar_pax1_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_pax1_LDADD = libtar.a libfstream.a libcompat.a +test_tar_pax1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_pax1_CPPFLAGS += -DTESTFILE=user-group-largenum/pax.tar +test_tar_pax1_CPPFLAGS += -DTESTUID=2147483648UL -DTESTGID=2147483648UL +test_tar_pax1_CPPFLAGS += -DTESTTS=1542995392 + +test_tar_pax2_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_pax2_LDADD = libtar.a libfstream.a libcompat.a +test_tar_pax2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_pax2_CPPFLAGS += -DTESTFILE=large-mtime/pax.tar -DTESTTS=8589934592L + +test_tar_pax3_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_pax3_LDADD = libtar.a libfstream.a libcompat.a +test_tar_pax3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_pax3_CPPFLAGS += -DTESTFILE=negative-mtime/pax.tar -DTESTTS=-315622800 + +test_tar_pax4_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_pax4_LDADD = libtar.a libfstream.a libcompat.a +test_tar_pax4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_pax4_CPPFLAGS += -DTESTFILE=long-paths/pax.tar +test_tar_pax4_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670 + +test_tar_pax5_SOURCES = tests/libtar/tar_big_file.c tests/test.h +test_tar_pax5_LDADD = libtar.a libfstream.a libcompat.a +test_tar_pax5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_pax5_CPPFLAGS += -DTESTFILE=file-size/pax.tar + +test_tar_ustar0_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_ustar0_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar0_CPPFLAGS += -DTESTFILE=format-acceptance/ustar.tar + +test_tar_ustar1_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_ustar1_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar1_CPPFLAGS += -DTESTFILE=format-acceptance/ustar-pre-posix.tar + +test_tar_ustar2_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_ustar2_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar2_CPPFLAGS += -DTESTFILE=format-acceptance/v7.tar + +test_tar_ustar3_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_ustar3_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar3_CPPFLAGS += -DTESTFILE=user-group-largenum/8-digit.tar +test_tar_ustar3_CPPFLAGS += -DTESTUID=8388608 -DTESTGID=8388608 +test_tar_ustar3_CPPFLAGS += -DTESTTS=1542995392 + +test_tar_ustar4_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_ustar4_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar4_CPPFLAGS += -DTESTFILE=large-mtime/12-digit.tar +test_tar_ustar4_CPPFLAGS += -DTESTTS=8589934592L + +test_tar_ustar5_SOURCES = tests/libtar/tar_simple.c tests/test.h +test_tar_ustar5_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar5_CPPFLAGS += -DTESTFILE=long-paths/ustar.tar +test_tar_ustar5_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670 + +test_tar_ustar6_SOURCES = tests/libtar/tar_big_file.c tests/test.h +test_tar_ustar6_LDADD = libtar.a libfstream.a libcompat.a +test_tar_ustar6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_ustar6_CPPFLAGS += -DTESTFILE=file-size/12-digit.tar + +test_tar_target_filled_SOURCES = tests/libtar/tar_target_filled.c tests/test.h +test_tar_target_filled_LDADD = libtar.a libfstream.a libcompat.a +test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) + +test_tar_sparse_gnu_SOURCES = tests/libtar/tar_sparse_gnu.c tests/test.h +test_tar_sparse_gnu_LDADD = libtar.a libfstream.a libcompat.a +test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) + +test_tar_sparse_gnu0_SOURCES = tests/libtar/tar_sparse.c tests/test.h +test_tar_sparse_gnu0_LDADD = libtar.a libfstream.a libcompat.a +test_tar_sparse_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_sparse_gnu0_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-0.tar + +test_tar_sparse_gnu1_SOURCES = tests/libtar/tar_sparse.c tests/test.h +test_tar_sparse_gnu1_LDADD = libtar.a libfstream.a libcompat.a +test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_sparse_gnu1_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-1.tar + +test_tar_sparse_gnu2_SOURCES = tests/libtar/tar_sparse.c tests/test.h +test_tar_sparse_gnu2_LDADD = libtar.a libfstream.a libcompat.a +test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_sparse_gnu2_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu1-0.tar + +test_tar_sparse_gnu3_SOURCES = tests/libtar/tar_sparse.c tests/test.h +test_tar_sparse_gnu3_LDADD = libtar.a libfstream.a libcompat.a +test_tar_sparse_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_sparse_gnu3_CPPFLAGS += -DTESTFILE=sparse-files/gnu.tar + +test_tar_xattr_bsd_SOURCES = tests/libtar/tar_xattr.c tests/test.h +test_tar_xattr_bsd_LDADD = libtar.a libfstream.a libcompat.a +test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_xattr_bsd_CPPFLAGS += -DTESTFILE=xattr/xattr-libarchive.tar + +test_tar_xattr_schily_SOURCES = tests/libtar/tar_xattr.c tests/test.h +test_tar_xattr_schily_LDADD = libtar.a libfstream.a libcompat.a +test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_xattr_schily_CPPFLAGS += -DTESTFILE=xattr/xattr-schily.tar + +test_tar_xattr_schily_bin_SOURCES = tests/libtar/tar_xattr_bin.c tests/test.h +test_tar_xattr_schily_bin_LDADD = libtar.a libfstream.a libcompat.a +test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) +test_tar_xattr_schily_bin_CPPFLAGS += -DTESTFILE=xattr/xattr-schily-binary.tar + +tar_fuzz_SOURCES = tests/libtar/tar_fuzz.c +tar_fuzz_LDADD = libtar.a libfstream.a libcompat.a + +LIBTAR_TESTS = \ + test_tar_ustar0 test_tar_ustar1 test_tar_ustar2 test_tar_ustar3 \ + test_tar_ustar4 test_tar_ustar5 test_tar_ustar6 \ + test_tar_pax0 test_tar_pax1 test_tar_pax2 test_tar_pax3 test_tar_pax4 \ + test_tar_pax5 \ + test_tar_gnu0 test_tar_gnu1 test_tar_gnu2 test_tar_gnu3 test_tar_gnu4 \ + test_tar_gnu5 test_tar_gnu6 \ + test_tar_sparse_gnu test_tar_sparse_gnu0 test_tar_sparse_gnu1 \ + test_tar_sparse_gnu2 test_tar_sparse_gnu3 \ + test_tar_xattr_bsd test_tar_xattr_schily test_tar_xattr_schily_bin \ + test_tar_target_filled + +if BUILD_TOOLS +check_PROGRAMS += $(LIBTAR_TESTS) +TESTS += $(LIBTAR_TESTS) + +noinst_PROGRAMS += tar_fuzz +endif + +EXTRA_DIST += $(TARDATADIR) diff --git a/tests/libtar/data/CREDITS b/tests/libtar/data/CREDITS new file mode 100644 index 0000000..7a2738f --- /dev/null +++ b/tests/libtar/data/CREDITS @@ -0,0 +1,35 @@ +The tar archives in this directory have been obtained from here: + + https://github.com/mgorny/tar-test-inputs + + git commit hash a2110a6 + +This repository was linked in the following article on interoperability of +various different tar programs: + + https://dev.gentoo.org/~mgorny/articles/portability-of-tar-features.html + +The original intention of the example archives was to test various tar programs +for interoperability with each others extensions and format quirks. + +The following have been removed since there is no intention in adding support +for those features: + + - volume-label tests + - multi-volume tests + - longe user + group names + - sun tar samples + - star samples + - file flags tests + +In addition to that, the files in "file-size" are truncated, since we are only +interested in parsing the header. + +The following addtional files have been added: + - xattr/xattr-shily-binary.tar + Created from xattr/xattr-shily.tar by manually patching in a capability + xattr key/value pair. + - tar/format-acceptance/link_filled.tar + Contributed in GitHub issue #64. A tar ball that contains a hard link + where the 100 byte target field is completely filled without containing + a null-terminator. diff --git a/tests/libtar/data/file-size/12-digit.tar b/tests/libtar/data/file-size/12-digit.tar new file mode 100644 index 0000000..a6b3553 Binary files /dev/null and b/tests/libtar/data/file-size/12-digit.tar differ diff --git a/tests/libtar/data/file-size/gnu.tar b/tests/libtar/data/file-size/gnu.tar new file mode 100644 index 0000000..aad726f Binary files /dev/null and b/tests/libtar/data/file-size/gnu.tar differ diff --git a/tests/libtar/data/file-size/pax.tar b/tests/libtar/data/file-size/pax.tar new file mode 100644 index 0000000..e391fee Binary files /dev/null and b/tests/libtar/data/file-size/pax.tar differ diff --git a/tests/libtar/data/format-acceptance/gnu-g.tar b/tests/libtar/data/format-acceptance/gnu-g.tar new file mode 100644 index 0000000..a72f60d Binary files /dev/null and b/tests/libtar/data/format-acceptance/gnu-g.tar differ diff --git a/tests/libtar/data/format-acceptance/gnu.tar b/tests/libtar/data/format-acceptance/gnu.tar new file mode 100644 index 0000000..98e8157 Binary files /dev/null and b/tests/libtar/data/format-acceptance/gnu.tar differ diff --git a/tests/libtar/data/format-acceptance/link_filled.tar b/tests/libtar/data/format-acceptance/link_filled.tar new file mode 100644 index 0000000..9b80f89 Binary files /dev/null and b/tests/libtar/data/format-acceptance/link_filled.tar differ diff --git a/tests/libtar/data/format-acceptance/pax.tar b/tests/libtar/data/format-acceptance/pax.tar new file mode 100644 index 0000000..69a029f Binary files /dev/null and b/tests/libtar/data/format-acceptance/pax.tar differ diff --git a/tests/libtar/data/format-acceptance/ustar-pre-posix.tar b/tests/libtar/data/format-acceptance/ustar-pre-posix.tar new file mode 100644 index 0000000..4230f5f Binary files /dev/null and b/tests/libtar/data/format-acceptance/ustar-pre-posix.tar differ diff --git a/tests/libtar/data/format-acceptance/ustar.tar b/tests/libtar/data/format-acceptance/ustar.tar new file mode 100644 index 0000000..9a6d9b3 Binary files /dev/null and b/tests/libtar/data/format-acceptance/ustar.tar differ diff --git a/tests/libtar/data/format-acceptance/v7.tar b/tests/libtar/data/format-acceptance/v7.tar new file mode 100644 index 0000000..5483b4b Binary files /dev/null and b/tests/libtar/data/format-acceptance/v7.tar differ diff --git a/tests/libtar/data/large-mtime/12-digit.tar b/tests/libtar/data/large-mtime/12-digit.tar new file mode 100644 index 0000000..8202b28 Binary files /dev/null and b/tests/libtar/data/large-mtime/12-digit.tar differ diff --git a/tests/libtar/data/large-mtime/gnu.tar b/tests/libtar/data/large-mtime/gnu.tar new file mode 100644 index 0000000..4e3dda2 Binary files /dev/null and b/tests/libtar/data/large-mtime/gnu.tar differ diff --git a/tests/libtar/data/large-mtime/pax.tar b/tests/libtar/data/large-mtime/pax.tar new file mode 100644 index 0000000..8d32530 Binary files /dev/null and b/tests/libtar/data/large-mtime/pax.tar differ diff --git a/tests/libtar/data/long-paths/gnu.tar b/tests/libtar/data/long-paths/gnu.tar new file mode 100644 index 0000000..4eee731 Binary files /dev/null and b/tests/libtar/data/long-paths/gnu.tar differ diff --git a/tests/libtar/data/long-paths/pax.tar b/tests/libtar/data/long-paths/pax.tar new file mode 100644 index 0000000..1e63e9c Binary files /dev/null and b/tests/libtar/data/long-paths/pax.tar differ diff --git a/tests/libtar/data/long-paths/ustar.tar b/tests/libtar/data/long-paths/ustar.tar new file mode 100644 index 0000000..812255c Binary files /dev/null and b/tests/libtar/data/long-paths/ustar.tar differ diff --git a/tests/libtar/data/negative-mtime/gnu.tar b/tests/libtar/data/negative-mtime/gnu.tar new file mode 100644 index 0000000..a9b1272 Binary files /dev/null and b/tests/libtar/data/negative-mtime/gnu.tar differ diff --git a/tests/libtar/data/negative-mtime/pax.tar b/tests/libtar/data/negative-mtime/pax.tar new file mode 100644 index 0000000..d0b3e6c Binary files /dev/null and b/tests/libtar/data/negative-mtime/pax.tar differ diff --git a/tests/libtar/data/sparse-files/gnu-small.tar b/tests/libtar/data/sparse-files/gnu-small.tar new file mode 100644 index 0000000..7a1b222 Binary files /dev/null and b/tests/libtar/data/sparse-files/gnu-small.tar differ diff --git a/tests/libtar/data/sparse-files/gnu.tar b/tests/libtar/data/sparse-files/gnu.tar new file mode 100644 index 0000000..3d641a2 Binary files /dev/null and b/tests/libtar/data/sparse-files/gnu.tar differ diff --git a/tests/libtar/data/sparse-files/pax-gnu0-0.tar b/tests/libtar/data/sparse-files/pax-gnu0-0.tar new file mode 100644 index 0000000..628f09e Binary files /dev/null and b/tests/libtar/data/sparse-files/pax-gnu0-0.tar differ diff --git a/tests/libtar/data/sparse-files/pax-gnu0-1.tar b/tests/libtar/data/sparse-files/pax-gnu0-1.tar new file mode 100644 index 0000000..87e362e Binary files /dev/null and b/tests/libtar/data/sparse-files/pax-gnu0-1.tar differ diff --git a/tests/libtar/data/sparse-files/pax-gnu1-0.tar b/tests/libtar/data/sparse-files/pax-gnu1-0.tar new file mode 100644 index 0000000..edb0ccf Binary files /dev/null and b/tests/libtar/data/sparse-files/pax-gnu1-0.tar differ diff --git a/tests/libtar/data/sqfs.sha512 b/tests/libtar/data/sqfs.sha512 new file mode 100644 index 0000000..10df2f4 --- /dev/null +++ b/tests/libtar/data/sqfs.sha512 @@ -0,0 +1,28 @@ +8fcf00ec57c764bd26e2d2c9db7a95acadd96f106ba37395216f0b331a664e8f5f29c70fcab82dc27f61f89237f23f29637930cd4843bfd7a9632d36088034b4 tests/libtar/data/long-paths/gnu.sqfs +8fcf00ec57c764bd26e2d2c9db7a95acadd96f106ba37395216f0b331a664e8f5f29c70fcab82dc27f61f89237f23f29637930cd4843bfd7a9632d36088034b4 tests/libtar/data/long-paths/pax.sqfs +8fcf00ec57c764bd26e2d2c9db7a95acadd96f106ba37395216f0b331a664e8f5f29c70fcab82dc27f61f89237f23f29637930cd4843bfd7a9632d36088034b4 tests/libtar/data/long-paths/ustar.sqfs +9e2241cf26c1457824f3e3c7a0bd2fc1be1e748ec5725afa33acdb63156b948a9db5f7182d00551587d1892565e05742775243be6e7377174f3d21911fdb7d15 tests/libtar/data/sparse-files/gnu-small.sqfs +5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/libtar/data/sparse-files/gnu.sqfs +5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/libtar/data/sparse-files/pax-gnu0-1.sqfs +5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/libtar/data/sparse-files/pax-gnu0-0.sqfs +5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/libtar/data/sparse-files/pax-gnu1-0.sqfs +1b9525453fb10f266cd7f52300fa2ff586a9b5a1c141da46f72c6370485d4dc7e306f2e778108644cdea6f06ee95a2972325f950ef5fce98bf439db1869c692a tests/libtar/data/large-mtime/12-digit.sqfs +1b9525453fb10f266cd7f52300fa2ff586a9b5a1c141da46f72c6370485d4dc7e306f2e778108644cdea6f06ee95a2972325f950ef5fce98bf439db1869c692a tests/libtar/data/large-mtime/gnu.sqfs +1b9525453fb10f266cd7f52300fa2ff586a9b5a1c141da46f72c6370485d4dc7e306f2e778108644cdea6f06ee95a2972325f950ef5fce98bf439db1869c692a tests/libtar/data/large-mtime/pax.sqfs +b43a83dcd5c9ccef1272caa1c9828e7401d3c19579def2caf9f51e814190662d19fbd0ee0c5c20d02e2d404533c593e5d8a549ac18509ce5e829c33cf6c272b0 tests/libtar/data/negative-mtime/gnu.sqfs +b43a83dcd5c9ccef1272caa1c9828e7401d3c19579def2caf9f51e814190662d19fbd0ee0c5c20d02e2d404533c593e5d8a549ac18509ce5e829c33cf6c272b0 tests/libtar/data/negative-mtime/pax.sqfs +d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/libtar/data/format-acceptance/gnu-g.sqfs +d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/libtar/data/format-acceptance/gnu.sqfs +d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/libtar/data/format-acceptance/ustar-pre-posix.sqfs +d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/libtar/data/format-acceptance/v7.sqfs +d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/libtar/data/format-acceptance/pax.sqfs +d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/libtar/data/format-acceptance/ustar.sqfs +2f41b640b8aeec7f5e489fbbeef22bac118c8b1cb068b795433bb6e2f8e9a1ff4f11654e9617b9547ff34b4da7b8e660afcbe69cf630bc112c63693fc56d4e3e tests/libtar/data/format-acceptance/link_filled.sqfs +f97561018def03e8af41c3b479925052469d4a15645886c500a60a5caa835a1ad152b4e72912df52bde29e3645d6bda46002dd91982c3bc91ff844b5724d0917 tests/libtar/data/user-group-largenum/gnu.sqfs +b34d720e04bb7c1fb93c9c3520aa1c653992f9b80339de2416097d95603ab7bbc02ea46300823ec3808c0cfe37ed7477f110ac2eb0fd791832a93f3e5c8a1500 tests/libtar/data/user-group-largenum/8-digit.sqfs +f97561018def03e8af41c3b479925052469d4a15645886c500a60a5caa835a1ad152b4e72912df52bde29e3645d6bda46002dd91982c3bc91ff844b5724d0917 tests/libtar/data/user-group-largenum/pax.sqfs +2dcfaace3235719558d93ed5a0f3e59fc10ab91f070add8ac8f7c4e6bcf5356942ff9db0fea5d8223280863c6e7b216b218b15dc8a2f61d2d42b62ea605cd0d5 tests/libtar/data/xattr/xattr-schily-binary.sqfs +273eb1af519f01f116fd0017f6016d50474fe94e596bda8f3e2467e7dd5741fb45fb7df8830d9e62112a24ce8f8a40f8afa6783459ec04f4c0004ca40a050c49 tests/libtar/data/xattr/xattr-schily.sqfs +273eb1af519f01f116fd0017f6016d50474fe94e596bda8f3e2467e7dd5741fb45fb7df8830d9e62112a24ce8f8a40f8afa6783459ec04f4c0004ca40a050c49 tests/libtar/data/xattr/xattr-libarchive.sqfs +dabba481b7e0d6888c1cb429eca304aac3c39146910ab0160179947de5ee3b68b5dcca2be3aff4536343357c6c48733f22b26cee1c2d4ff000c2edc276f2c235 tests/libtar/data/xattr/acl.sqfs +a050ee2a296900bcb06d9616d06b1d947d9f26f0b57d6aff318c3dc656810c919f63a24144f890a4fae60268fda19becf9021182f1c0afd8acc0874e720f720e tests/tar2sqfs/root-becomes.sqfs diff --git a/tests/libtar/data/user-group-largenum/8-digit.tar b/tests/libtar/data/user-group-largenum/8-digit.tar new file mode 100644 index 0000000..a48ea5d Binary files /dev/null and b/tests/libtar/data/user-group-largenum/8-digit.tar differ diff --git a/tests/libtar/data/user-group-largenum/gnu.tar b/tests/libtar/data/user-group-largenum/gnu.tar new file mode 100644 index 0000000..4c30f57 Binary files /dev/null and b/tests/libtar/data/user-group-largenum/gnu.tar differ diff --git a/tests/libtar/data/user-group-largenum/pax.tar b/tests/libtar/data/user-group-largenum/pax.tar new file mode 100644 index 0000000..a9fe54c Binary files /dev/null and b/tests/libtar/data/user-group-largenum/pax.tar differ diff --git a/tests/libtar/data/xattr/acl.tar b/tests/libtar/data/xattr/acl.tar new file mode 100644 index 0000000..a65c0af Binary files /dev/null and b/tests/libtar/data/xattr/acl.tar differ diff --git a/tests/libtar/data/xattr/xattr-libarchive.tar b/tests/libtar/data/xattr/xattr-libarchive.tar new file mode 100644 index 0000000..3bd6125 Binary files /dev/null and b/tests/libtar/data/xattr/xattr-libarchive.tar differ diff --git a/tests/libtar/data/xattr/xattr-schily-binary.tar b/tests/libtar/data/xattr/xattr-schily-binary.tar new file mode 100644 index 0000000..0312807 Binary files /dev/null and b/tests/libtar/data/xattr/xattr-schily-binary.tar differ diff --git a/tests/libtar/data/xattr/xattr-schily.tar b/tests/libtar/data/xattr/xattr-schily.tar new file mode 100644 index 0000000..1cf525c Binary files /dev/null and b/tests/libtar/data/xattr/xattr-schily.tar differ diff --git a/tests/libtar/tar_big_file.c b/tests/libtar/tar_big_file.c new file mode 100644 index 0000000..69263ef --- /dev/null +++ b/tests/libtar/tar_big_file.c @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_big_file.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +int main(void) +{ + tar_header_decoded_t hdr; + istream_t *fp; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 8589934592); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542959190); + TEST_EQUAL_UI(hdr.mtime, 1542959190); + TEST_STR_EQUAL(hdr.name, "big-file.bin"); + TEST_ASSERT(!hdr.unknown_record); + clear_header(&hdr); + sqfs_destroy(fp); + return EXIT_SUCCESS; +} diff --git a/tests/libtar/tar_fuzz.c b/tests/libtar/tar_fuzz.c new file mode 100644 index 0000000..e5f5c0b --- /dev/null +++ b/tests/libtar/tar_fuzz.c @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_fuzz.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "tar.h" + +#include +#include + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + istream_t *fp; + int ret; + + if (argc != 2) { + fputs("usage: tar_fuzz \n", stderr); + return EXIT_FAILURE; + } + + fp = istream_open_file(argv[1]); + if (fp == NULL) + return EXIT_FAILURE; + + for (;;) { + ret = read_header(fp, &hdr); + if (ret > 0) + break; + if (ret < 0) + goto fail; + + ret = istream_skip(fp, hdr.sb.st_size); + + clear_header(&hdr); + if (ret < 0) + goto fail; + } + + sqfs_destroy(fp); + return EXIT_SUCCESS; +fail: + sqfs_destroy(fp); + return EXIT_FAILURE; +} diff --git a/tests/libtar/tar_simple.c b/tests/libtar/tar_simple.c new file mode 100644 index 0000000..ffaafea --- /dev/null +++ b/tests/libtar/tar_simple.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_simple.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +#ifndef TESTUID +#define TESTUID 1000 +#endif + +#ifndef TESTGID +#define TESTGID TESTUID +#endif + +#ifndef TESTFNAME +#define TESTFNAME input.txt +#endif + +#ifndef TESTTS +#define TESTTS 1542905892 +#endif + +#ifdef LONG_NAME_TEST +static const char *fname = +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/input.txt"; +#else +static const char *fname = STRVALUE(TESTFNAME); +#endif + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + sqfs_s64 ts; + istream_t *fp; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, TESTUID); + TEST_EQUAL_UI(hdr.sb.st_gid, TESTGID); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + + ts = TESTTS; + + if (sizeof(time_t) < sizeof(ts) && ts > INT32_MAX) { + TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX); + } else { + TEST_EQUAL_UI(hdr.sb.st_mtime, ts); + } + + TEST_EQUAL_UI(hdr.mtime, ts); + TEST_STR_EQUAL(hdr.name, fname); + TEST_ASSERT(!hdr.unknown_record); + + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + clear_header(&hdr); + sqfs_destroy(fp); + return EXIT_SUCCESS; +} diff --git a/tests/libtar/tar_sparse.c b/tests/libtar/tar_sparse.c new file mode 100644 index 0000000..c4e1c71 --- /dev/null +++ b/tests/libtar/tar_sparse.c @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_sparse.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +static void test_case_sparse(const char *path) +{ + tar_header_decoded_t hdr; + sparse_map_t *sparse; + istream_t *fp; + + fp = istream_open_file(path); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 2097152); + TEST_EQUAL_UI(hdr.actual_size, 2097152); + TEST_EQUAL_UI(hdr.record_size, 32768); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); + + sparse = hdr.sparse; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 786432); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1048576); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1310720); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1572864); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1835008); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 2097152); + TEST_EQUAL_UI(sparse->count, 0); + + sparse = sparse->next; + TEST_NULL(sparse); + + clear_header(&hdr); + sqfs_destroy(fp); +} + +int main(void) +{ + test_case_sparse( STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE) ); + return EXIT_SUCCESS; +} diff --git a/tests/libtar/tar_sparse_gnu.c b/tests/libtar/tar_sparse_gnu.c new file mode 100644 index 0000000..1405026 --- /dev/null +++ b/tests/libtar/tar_sparse_gnu.c @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_sparse_gnu.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +int main(void) +{ + tar_header_decoded_t hdr; + sparse_map_t *sparse; + istream_t *fp; + + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = istream_open_file("sparse-files/gnu-small.tar"); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 524288); + TEST_EQUAL_UI(hdr.actual_size, 524288); + TEST_EQUAL_UI(hdr.record_size, 8192); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); + + sparse = hdr.sparse; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); + + sparse = sparse->next; + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 0); + + TEST_NULL(sparse->next); + + clear_header(&hdr); + sqfs_destroy(fp); + return EXIT_SUCCESS; +} diff --git a/tests/libtar/tar_target_filled.c b/tests/libtar/tar_target_filled.c new file mode 100644 index 0000000..0028e5e --- /dev/null +++ b/tests/libtar/tar_target_filled.c @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_target_filled.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[16]; + istream_t *fp; + + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = istream_open_file("format-acceptance/link_filled.tar"); + TEST_NOT_NULL(fp); + + /* "deep" directory hierarchy containg 2 files */ + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/" + "errored_file_tst"); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + TEST_ASSERT(skip_padding(fp, 5) == 0); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777); + TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" + "20_characters_here03/20_characters_here04/" + "some_test_file"); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + TEST_ASSERT(skip_padding(fp, 5) == 0); + clear_header(&hdr); + + /* "deep" directory hierarchy containg a hard link */ + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/20CharsForLnkTest004/"); + clear_header(&hdr); + + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" + "20CharsForLnkTest003/20CharsForLnkTest004/" + "01234567890123456789"); + TEST_ASSERT(hdr.is_hard_link); + + TEST_STR_EQUAL(hdr.link_target, "20_characters_here01/" + "20_characters_here02/20_characters_here03/" + "20_characters_here04/errored_file_tst"); + clear_header(&hdr); + + /* end of file */ + TEST_ASSERT(read_header(fp, &hdr) > 0); + sqfs_destroy(fp); + + return EXIT_SUCCESS; +} diff --git a/tests/libtar/tar_xattr.c b/tests/libtar/tar_xattr.c new file mode 100644 index 0000000..70329fe --- /dev/null +++ b/tests/libtar/tar_xattr.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_xattr.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + istream_t *fp; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type"); + TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain"); + TEST_EQUAL_UI(hdr.xattr->value_len, 10); + TEST_NULL(hdr.xattr->next); + + clear_header(&hdr); + sqfs_destroy(fp); + return EXIT_SUCCESS; +} diff --git a/tests/libtar/tar_xattr_bin.c b/tests/libtar/tar_xattr_bin.c new file mode 100644 index 0000000..52c407c --- /dev/null +++ b/tests/libtar/tar_xattr_bin.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_xattr_bin.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "tar.h" +#include "../test.h" + +static const uint8_t value[] = { + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + istream_t *fp; + + fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_NOT_NULL(fp); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(istream_read(fp, buffer, 5) == 5); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "security.capability"); + TEST_EQUAL_UI(hdr.xattr->value_len, sizeof(value)); + TEST_ASSERT(memcmp(hdr.xattr->value, value, sizeof(value)) == 0); + TEST_NULL(hdr.xattr->next); + + clear_header(&hdr); + sqfs_destroy(fp); + return EXIT_SUCCESS; +} diff --git a/tests/libutil/Makemodule.am b/tests/libutil/Makemodule.am new file mode 100644 index 0000000..1153db4 --- /dev/null +++ b/tests/libutil/Makemodule.am @@ -0,0 +1,16 @@ +test_str_table_SOURCES = tests/libutil/str_table.c tests/test.h +test_str_table_LDADD = libutil.a libfstream.a libcompat.a +test_str_table_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/libutil + +test_rbtree_SOURCES = tests/libutil/rbtree.c tests/test.h +test_rbtree_LDADD = libutil.a libcompat.a + +test_xxhash_SOURCES = tests/libutil/xxhash.c +test_xxhash_LDADD = libutil.a libcompat.a + +LIBUTIL_TESTS = \ + test_str_table test_rbtree test_xxhash + +check_PROGRAMS += $(LIBUTIL_TESTS) +TESTS += $(LIBUTIL_TESTS) +EXTRA_DIST += $(top_srcdir)/tests/libutil/words.txt diff --git a/tests/libutil/rbtree.c b/tests/libutil/rbtree.c new file mode 100644 index 0000000..173df1c --- /dev/null +++ b/tests/libutil/rbtree.c @@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * rbtree.c + * + * Copyright (C) 2020 David Oberhollenzer + */ +#include "config.h" + +#include "rbtree.h" +#include "../test.h" + +static int key_compare(const void *a, const void *b) +{ + return *((sqfs_s32 *)a) - *((sqfs_s32 *)b); +} + +static size_t count_nodes_dfs(rbtree_node_t *n) +{ + return 1 + (n->left == NULL ? 0 : count_nodes_dfs(n->left)) + + (n->right == NULL ? 0 : count_nodes_dfs(n->right)); +} + +static size_t min_depth(rbtree_node_t *n) +{ + size_t lhs, rhs; + + if (n == NULL) + return 0; + + lhs = min_depth(n->left) + 1; + rhs = min_depth(n->right) + 1; + + return lhs < rhs ? lhs : rhs; +} + +static size_t max_depth(rbtree_node_t *n) +{ + size_t lhs, rhs; + + if (n == NULL) + return 0; + + lhs = min_depth(n->left) + 1; + rhs = min_depth(n->right) + 1; + + return lhs > rhs ? lhs : rhs; +} + +static size_t get_ref_black_depth(rbtree_t *rb) +{ + rbtree_node_t *n; + size_t count = 0; + + for (n = rb->root; n != NULL; n = n->left) { + if (!n->is_red) + count += 1; + } + + return count; +} + +static void check_binary_tree_dfs(rbtree_node_t *n) +{ + const void *key = rbtree_node_key(n); + const void *cmp; + + if (n->left != NULL) { + cmp = rbtree_node_key(n->left); + TEST_ASSERT(key_compare(cmp, key) < 0); + + check_binary_tree_dfs(n->left); + } + + if (n->right != NULL) { + cmp = rbtree_node_key(n->right); + TEST_ASSERT(key_compare(cmp, key) > 0); + + check_binary_tree_dfs(n->right); + } +} + +static void check_colors_dfs(rbtree_node_t *n) +{ + if (n->is_red) { + TEST_ASSERT(n->left == NULL || !n->left->is_red); + TEST_ASSERT(n->right == NULL || !n->right->is_red); + } + + if (n->left != NULL) + check_colors_dfs(n->left); + + if (n->right != NULL) + check_colors_dfs(n->right); +} + +static void check_black_depth_dfs(rbtree_node_t *n, size_t ref, + size_t counter) +{ + if (!n->is_red) + counter += 1; + + if (n->left == NULL || n->right == NULL) + TEST_EQUAL_UI(counter, ref); + + if (n->left != NULL) + check_black_depth_dfs(n->left, ref, counter); + + if (n->right != NULL) + check_black_depth_dfs(n->right, ref, counter); +} + +int main(void) +{ + size_t count, blkdepth, mind, maxd; + sqfs_s32 key, key2; + rbtree_node_t *n; + sqfs_u64 value; + rbtree_t rb; + + TEST_ASSERT(rbtree_init(&rb, sizeof(sqfs_s32), + sizeof(sqfs_u64), key_compare) == 0); + + count = 0; + + for (key = -1000; key < 1000; ++key) { + /* lookup of current key must fail prior to insert */ + TEST_NULL(rbtree_lookup(&rb, &key)); + + /* previous key/value pairs must still be there */ + for (key2 = -1000; key2 < key; ++key2) { + n = rbtree_lookup(&rb, &key2); + TEST_NOT_NULL(n); + value = *((sqfs_u64 *)rbtree_node_value(n)); + TEST_EQUAL_UI((sqfs_u64)(key2 + 10000), value); + } + + /* insert key value pair */ + value = key + 10000; + TEST_ASSERT(rbtree_insert(&rb, &key, &value) == 0); + count += 1; + + /* check if the tree has the right number of nodes */ + TEST_EQUAL_UI(count_nodes_dfs(rb.root), count); + + /* check if it is still a binary tree */ + check_binary_tree_dfs(rb.root); + + /* root node must be black. Every red node + must have black children. */ + TEST_ASSERT(!rb.root->is_red); + check_colors_dfs(rb.root); + + /* every path from the root to a leave must have + the same number of black nodes. */ + blkdepth = get_ref_black_depth(&rb); + check_black_depth_dfs(rb.root, blkdepth, 0); + + /* longest root to leaf path must be at most + twice as long as the shortest. */ + mind = min_depth(rb.root); + maxd = max_depth(rb.root); + TEST_ASSERT(maxd <= mind * 2); + + /* lookup of current key must work after insert */ + n = rbtree_lookup(&rb, &key); + TEST_NOT_NULL(n); + value = *((sqfs_u64 *)rbtree_node_value(n)); + TEST_EQUAL_UI((sqfs_u64)(key + 10000), value); + } + + rbtree_cleanup(&rb); + return EXIT_SUCCESS; +} diff --git a/tests/libutil/str_table.c b/tests/libutil/str_table.c new file mode 100644 index 0000000..83526af --- /dev/null +++ b/tests/libutil/str_table.c @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * str_table.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "str_table.h" +#include "fstream.h" +#include "compat.h" +#include "../test.h" + +static char *strings[1000]; + +static int read_strings(void) +{ + istream_t *fp; + ssize_t ret; + char *line; + int i; + + fp = istream_open_file("words.txt"); + TEST_NOT_NULL(fp); + + for (i = 0; i < 1000; ++i) { + ret = istream_get_line(fp, &line, NULL, 0); + TEST_EQUAL_I(ret, 0); + + strings[i] = line; + } + + sqfs_destroy(fp); + return 0; +} + +int main(void) +{ + str_table_t table; + size_t i, j, idx; + const char *str; + + TEST_ASSERT(chdir(TEST_PATH) == 0); + + if (read_strings()) + return EXIT_FAILURE; + + TEST_ASSERT(str_table_init(&table, 64) == 0); + + for (i = 0; i < 1000; ++i) { + TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0); + + TEST_EQUAL_UI(idx, i); + + for (j = 0; j <= i; ++j) { + str = str_table_get_string(&table, j); + + TEST_NOT_NULL(str); + TEST_ASSERT(str != strings[i]); + TEST_STR_EQUAL(str, strings[j]); + } + + for (; j < 1000; ++j) + TEST_NULL(str_table_get_string(&table, j)); + } + + for (i = 0; i < 1000; ++i) { + TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0); + TEST_EQUAL_UI(idx, i); + + str = str_table_get_string(&table, i); + + TEST_NOT_NULL(str); + TEST_ASSERT(str != strings[i]); + TEST_STR_EQUAL(str, strings[i]); + } + + str_table_cleanup(&table); + + for (i = 0; i < 1000; ++i) + free(strings[i]); + + return EXIT_SUCCESS; +} diff --git a/tests/libutil/words.txt b/tests/libutil/words.txt new file mode 100644 index 0000000..9496e14 --- /dev/null +++ b/tests/libutil/words.txt @@ -0,0 +1,1000 @@ +a +ability +able +about +above +accept +according +account +across +act +action +activity +actually +add +address +administration +admit +adult +affect +after +again +against +age +agency +agent +ago +agree +agreement +ahead +air +all +allow +almost +alone +along +already +also +although +always +American +among +amount +analysis +and +animal +another +answer +any +anyone +anything +appear +apply +approach +area +argue +arm +around +arrive +art +article +artist +as +ask +assume +at +attack +attention +attorney +audience +author +authority +available +avoid +away +baby +back +bad +bag +ball +bank +bar +base +be +beat +beautiful +because +become +bed +before +begin +behavior +behind +believe +benefit +best +better +between +beyond +big +bill +billion +bit +black +blood +blue +board +body +book +born +both +box +boy +break +bring +brother +budget +build +building +business +but +buy +by +call +camera +campaign +can +cancer +candidate +capital +car +card +care +career +carry +case +catch +cause +cell +center +central +century +certain +certainly +chair +challenge +chance +change +character +charge +check +child +choice +choose +church +citizen +city +civil +claim +class +clear +clearly +close +coach +cold +collection +college +color +come +commercial +common +community +company +compare +computer +concern +condition +conference +Congress +consider +consumer +contain +continue +control +cost +could +country +couple +course +court +cover +create +crime +cultural +culture +cup +current +customer +cut +dark +data +daughter +day +dead +deal +death +debate +decade +decide +decision +deep +defense +degree +Democrat +democratic +describe +design +despite +detail +determine +develop +development +die +difference +different +difficult +dinner +direction +director +discover +discuss +discussion +disease +do +doctor +dog +door +down +draw +dream +drive +drop +drug +during +each +early +east +easy +eat +economic +economy +edge +education +effect +effort +eight +either +election +else +employee +end +energy +enjoy +enough +enter +entire +environment +environmental +especially +establish +even +evening +event +ever +every +everybody +everyone +everything +evidence +exactly +example +executive +exist +expect +experience +expert +explain +eye +face +fact +factor +fail +fall +family +far +fast +father +fear +federal +feel +feeling +few +field +fight +figure +fill +film +final +finally +financial +find +fine +finger +finish +fire +firm +first +fish +five +floor +fly +focus +follow +food +foot +for +force +foreign +forget +form +former +forward +four +free +friend +from +front +full +fund +future +game +garden +gas +general +generation +get +girl +give +glass +go +goal +good +government +great +green +ground +group +grow +growth +guess +gun +guy +hair +half +hand +hang +happen +happy +hard +have +he +head +health +hear +heart +heat +heavy +help +her +here +herself +high +him +himself +his +history +hit +hold +home +hope +hospital +hot +hotel +hour +house +how +however +huge +human +hundred +husband +I +idea +identify +if +image +imagine +impact +important +improve +in +include +including +increase +indeed +indicate +individual +industry +information +inside +instead +institution +interest +interesting +international +interview +into +investment +involve +issue +it +item +its +itself +job +join +just +keep +key +kid +kill +kind +kitchen +know +knowledge +land +language +large +last +late +later +laugh +law +lawyer +lay +lead +leader +learn +least +leave +left +leg +legal +less +let +letter +level +lie +life +light +like +likely +line +list +listen +little +live +local +long +look +lose +loss +lot +love +low +machine +magazine +main +maintain +major +majority +make +man +manage +management +manager +many +market +marriage +material +matter +may +maybe +me +mean +measure +media +medical +meet +meeting +member +memory +mention +message +method +middle +might +military +million +mind +minute +miss +mission +model +modern +moment +money +month +more +morning +most +mother +mouth +move +movement +movie +Mr +Mrs +much +music +must +my +myself +name +nation +national +natural +nature +near +nearly +necessary +need +network +never +new +news +newspaper +next +nice +night +no +none +nor +north +not +note +nothing +notice +now +n't +number +occur +of +off +offer +office +officer +official +often +oh +oil +ok +old +on +once +one +only +onto +open +operation +opportunity +option +or +order +organization +other +others +our +out +outside +over +own +owner +page +pain +painting +paper +parent +part +participant +particular +particularly +partner +party +pass +past +patient +pattern +pay +peace +people +per +perform +performance +perhaps +period +person +personal +phone +physical +pick +picture +piece +place +plan +plant +play +player +PM +point +police +policy +political +politics +poor +popular +population +position +positive +possible +power +practice +prepare +present +president +pressure +pretty +prevent +price +private +probably +problem +process +produce +product +production +professional +professor +program +project +property +protect +prove +provide +public +pull +purpose +push +put +quality +question +quickly +quite +race +radio +raise +range +rate +rather +reach +read +ready +real +reality +realize +really +reason +receive +recent +recently +recognize +record +red +reduce +reflect +region +relate +relationship +religious +remain +remember +remove +report +represent +Republican +require +research +resource +respond +response +responsibility +rest +result +return +reveal +rich +right +rise +risk +road +rock +role +room +rule +run +safe +same +save +say +scene +school +science +scientist +score +sea +season +seat +second +section +security +see +seek +seem +sell +send +senior +sense +series +serious +serve +service +set +seven +several +sex +sexual +shake +share +she +shoot +short +shot +should +shoulder +show +side +sign +significant +similar +simple +simply +since +sing +single +sister +sit +site +situation +six +size +skill +skin +small +smile +so +social +society +soldier +some +somebody +someone +something +sometimes +son +song +soon +sort +sound +source +south +southern +space +speak +special +specific +speech +spend +sport +spring +staff +stage +stand +standard +star +start +state +statement +station +stay +step +still +stock +stop +store +story +strategy +street +strong +structure +student +study +stuff +style +subject +success +successful +such +suddenly +suffer +suggest +summer +support +sure +surface +system +table +take +talk +task +tax +teach +teacher +team +technology +television +tell +ten +tend +term +test +than +thank +that +the +their +them +themselves +then +theory +there +these +they +thing +think +third +this +those +though +thought +thousand +threat +three +through +throughout +throw +thus +time +to +today +together +tonight +too +top +total +tough +toward +town +trade +traditional +training +travel +treat +treatment +tree +trial +trip +trouble +true +truth +try +turn +TV +two +type +under +understand +unit +until +up +upon +us +use +usually +value +various +very +victim +view +violence +visit +voice +vote +wait +walk +wall +want +war +watch +water +way +we +weapon +wear +week +weight +well +west +western +what +whatever +when +where +whether +which +while +white +who +whole +whom +whose +why +wide +wife +will +win +wind +window +wish +with +within +without +woman +wonder +word +work +worker +world +worry +would +write +writer +wrong +yard +yeah +year +yes +yet +you +young +your +yourself diff --git a/tests/libutil/xxhash.c b/tests/libutil/xxhash.c new file mode 100644 index 0000000..6e17097 --- /dev/null +++ b/tests/libutil/xxhash.c @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * xxhash.c + * + * Copyright (C) 2020 David Oberhollenzer + */ +#include "config.h" + +#include "util.h" +#include "../test.h" + +static const struct { + const char *plaintext; + size_t psize; + sqfs_u32 digest; +} test_vectors[] = { + { + .plaintext = "\x9e", + .psize = 1, + .digest = 0xB85CBEE5, + }, + { + .plaintext = "\x9e\xff\x1f\x4b\x5e\x53\x2f\xdd" + "\xb5\x54\x4d\x2a\x95\x2b", + .psize = 14, + .digest = 0xE5AA0AB4, + }, + { + .plaintext = "\x9e\xff\x1f\x4b\x5e\x53\x2f\xdd" + "\xb5\x54\x4d\x2a\x95\x2b\x57\xae" + "\x5d\xba\x74\xe9\xd3\xa6\x4c\x98" + "\x30\x60\xc0\x80\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00", + .psize = 101, + .digest = 0x018F52BC, + }, +}; + +int main(void) +{ + sqfs_u32 hash; + size_t i; + + for (i = 0; i < sizeof(test_vectors) / sizeof(test_vectors[0]); ++i) { + hash = xxh32(test_vectors[i].plaintext, test_vectors[i].psize); + + if (hash != test_vectors[i].digest) { + fprintf(stderr, "Test case " PRI_SZ " failed!\n", i); + fprintf(stderr, "Expected result: 0x%08X\n", + test_vectors[i].digest); + fprintf(stderr, "Actual result: 0x%08X\n", hash); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/tests/mknode_dir.c b/tests/mknode_dir.c deleted file mode 100644 index 9495bb8..0000000 --- a/tests/mknode_dir.c +++ /dev/null @@ -1,62 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * mknode_dir.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *root, *a, *b; - struct stat sb; - fstree_t fs; - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 4096; - - root = fstree_mknode(NULL, "rootdir", 7, NULL, &sb); - TEST_EQUAL_UI(root->uid, sb.st_uid); - TEST_EQUAL_UI(root->gid, sb.st_gid); - TEST_EQUAL_UI(root->mode, sb.st_mode); - TEST_EQUAL_UI(root->link_count, 2); - TEST_ASSERT(root->name >= (char *)root->payload); - TEST_STR_EQUAL(root->name, "rootdir"); - TEST_NULL(root->data.dir.children); - TEST_NULL(root->parent); - TEST_NULL(root->next); - - a = fstree_mknode(root, "adir", 4, NULL, &sb); - TEST_ASSERT(a->parent == root); - TEST_NULL(a->next); - TEST_EQUAL_UI(a->link_count, 2); - TEST_EQUAL_UI(root->link_count, 3); - TEST_ASSERT(root->data.dir.children == a); - TEST_NULL(root->parent); - TEST_NULL(root->next); - - b = fstree_mknode(root, "bdir", 4, NULL, &sb); - TEST_ASSERT(a->parent == root); - TEST_ASSERT(b->parent == root); - TEST_EQUAL_UI(b->link_count, 2); - TEST_ASSERT(root->data.dir.children == b); - TEST_EQUAL_UI(root->link_count, 4); - TEST_ASSERT(b->next == a); - TEST_NULL(a->next); - TEST_NULL(root->parent); - TEST_NULL(root->next); - - free(root); - free(a); - free(b); - - return EXIT_SUCCESS; -} diff --git a/tests/mknode_reg.c b/tests/mknode_reg.c deleted file mode 100644 index 677c934..0000000 --- a/tests/mknode_reg.c +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * mknode_reg.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *node; - struct stat sb; - fstree_t fs; - - memset(&fs, 0, sizeof(fs)); - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFREG | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 4096; - - node = fstree_mknode(NULL, "filename", 8, "input", &sb); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); - TEST_NULL(node->parent); - TEST_EQUAL_UI(node->link_count, 1); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_ASSERT(node->data.file.input_file >= (char *)node->payload); - TEST_ASSERT(node->data.file.input_file >= node->name + 8); - TEST_STR_EQUAL(node->name, "filename"); - TEST_STR_EQUAL(node->data.file.input_file, "input"); - free(node); - - return EXIT_SUCCESS; -} diff --git a/tests/mknode_simple.c b/tests/mknode_simple.c deleted file mode 100644 index 271ff96..0000000 --- a/tests/mknode_simple.c +++ /dev/null @@ -1,97 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * mknode_simple.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *node; - struct stat sb; - fstree_t fs; - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFSOCK | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_mknode(NULL, "sockfile", 8, NULL, &sb); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_STR_EQUAL(node->name, "sockfile"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); - TEST_EQUAL_UI(node->link_count, 1); - TEST_NULL(node->parent); - TEST_NULL(node->data.target); - TEST_EQUAL_UI(node->data.devno, 0); - free(node); - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFIFO | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_mknode(NULL, "fifo", 4, NULL, &sb); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_STR_EQUAL(node->name, "fifo"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); - TEST_EQUAL_UI(node->link_count, 1); - TEST_NULL(node->parent); - TEST_NULL(node->data.target); - TEST_EQUAL_UI(node->data.devno, 0); - free(node); - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFBLK | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_mknode(NULL, "blkdev", 6, NULL, &sb); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_STR_EQUAL(node->name, "blkdev"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); - TEST_EQUAL_UI(node->link_count, 1); - TEST_EQUAL_UI(node->data.devno, sb.st_rdev); - TEST_NULL(node->parent); - free(node); - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFCHR | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_mknode(NULL, "chardev", 7, NULL, &sb); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_STR_EQUAL(node->name, "chardev"); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, sb.st_mode); - TEST_EQUAL_UI(node->link_count, 1); - TEST_EQUAL_UI(node->data.devno, sb.st_rdev); - TEST_NULL(node->parent); - free(node); - - return EXIT_SUCCESS; -} diff --git a/tests/mknode_slink.c b/tests/mknode_slink.c deleted file mode 100644 index 19fc8f2..0000000 --- a/tests/mknode_slink.c +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * mknode_slink.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "fstree.h" -#include "test.h" - -int main(void) -{ - tree_node_t *node; - struct stat sb; - fstree_t fs; - - memset(&fs, 0, sizeof(fs)); - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFLNK | 0654; - sb.st_uid = 123; - sb.st_gid = 456; - sb.st_rdev = 789; - sb.st_size = 1337; - - node = fstree_mknode(NULL, "symlink", 7, "target", &sb); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); - TEST_EQUAL_UI(node->link_count, 1); - TEST_NULL(node->parent); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_ASSERT(node->data.target >= (char *)node->payload); - TEST_ASSERT(node->data.target >= node->name + 8); - TEST_STR_EQUAL(node->name, "symlink"); - TEST_STR_EQUAL(node->data.target, "target"); - free(node); - - node = fstree_mknode(NULL, "symlink", 7, "", &sb); - TEST_EQUAL_UI(node->uid, sb.st_uid); - TEST_EQUAL_UI(node->gid, sb.st_gid); - TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); - TEST_EQUAL_UI(node->link_count, 1); - TEST_NULL(node->parent); - TEST_ASSERT((char *)node->name >= (char *)node->payload); - TEST_ASSERT(node->data.target >= (char *)node->payload); - TEST_ASSERT(node->data.target >= node->name + 8); - TEST_STR_EQUAL(node->name, "symlink"); - TEST_STR_EQUAL(node->data.target, ""); - free(node); - - return EXIT_SUCCESS; -} diff --git a/tests/rbtree.c b/tests/rbtree.c deleted file mode 100644 index fc607a5..0000000 --- a/tests/rbtree.c +++ /dev/null @@ -1,173 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * rbtree.c - * - * Copyright (C) 2020 David Oberhollenzer - */ -#include "config.h" - -#include "rbtree.h" -#include "test.h" - -static int key_compare(const void *a, const void *b) -{ - return *((sqfs_s32 *)a) - *((sqfs_s32 *)b); -} - -static size_t count_nodes_dfs(rbtree_node_t *n) -{ - return 1 + (n->left == NULL ? 0 : count_nodes_dfs(n->left)) - + (n->right == NULL ? 0 : count_nodes_dfs(n->right)); -} - -static size_t min_depth(rbtree_node_t *n) -{ - size_t lhs, rhs; - - if (n == NULL) - return 0; - - lhs = min_depth(n->left) + 1; - rhs = min_depth(n->right) + 1; - - return lhs < rhs ? lhs : rhs; -} - -static size_t max_depth(rbtree_node_t *n) -{ - size_t lhs, rhs; - - if (n == NULL) - return 0; - - lhs = min_depth(n->left) + 1; - rhs = min_depth(n->right) + 1; - - return lhs > rhs ? lhs : rhs; -} - -static size_t get_ref_black_depth(rbtree_t *rb) -{ - rbtree_node_t *n; - size_t count = 0; - - for (n = rb->root; n != NULL; n = n->left) { - if (!n->is_red) - count += 1; - } - - return count; -} - -static void check_binary_tree_dfs(rbtree_node_t *n) -{ - const void *key = rbtree_node_key(n); - const void *cmp; - - if (n->left != NULL) { - cmp = rbtree_node_key(n->left); - TEST_ASSERT(key_compare(cmp, key) < 0); - - check_binary_tree_dfs(n->left); - } - - if (n->right != NULL) { - cmp = rbtree_node_key(n->right); - TEST_ASSERT(key_compare(cmp, key) > 0); - - check_binary_tree_dfs(n->right); - } -} - -static void check_colors_dfs(rbtree_node_t *n) -{ - if (n->is_red) { - TEST_ASSERT(n->left == NULL || !n->left->is_red); - TEST_ASSERT(n->right == NULL || !n->right->is_red); - } - - if (n->left != NULL) - check_colors_dfs(n->left); - - if (n->right != NULL) - check_colors_dfs(n->right); -} - -static void check_black_depth_dfs(rbtree_node_t *n, size_t ref, - size_t counter) -{ - if (!n->is_red) - counter += 1; - - if (n->left == NULL || n->right == NULL) - TEST_EQUAL_UI(counter, ref); - - if (n->left != NULL) - check_black_depth_dfs(n->left, ref, counter); - - if (n->right != NULL) - check_black_depth_dfs(n->right, ref, counter); -} - -int main(void) -{ - size_t count, blkdepth, mind, maxd; - sqfs_s32 key, key2; - rbtree_node_t *n; - sqfs_u64 value; - rbtree_t rb; - - TEST_ASSERT(rbtree_init(&rb, sizeof(sqfs_s32), - sizeof(sqfs_u64), key_compare) == 0); - - count = 0; - - for (key = -1000; key < 1000; ++key) { - /* lookup of current key must fail prior to insert */ - TEST_NULL(rbtree_lookup(&rb, &key)); - - /* previous key/value pairs must still be there */ - for (key2 = -1000; key2 < key; ++key2) { - n = rbtree_lookup(&rb, &key2); - TEST_NOT_NULL(n); - value = *((sqfs_u64 *)rbtree_node_value(n)); - TEST_EQUAL_UI((sqfs_u64)(key2 + 10000), value); - } - - /* insert key value pair */ - value = key + 10000; - TEST_ASSERT(rbtree_insert(&rb, &key, &value) == 0); - count += 1; - - /* check if the tree has the right number of nodes */ - TEST_EQUAL_UI(count_nodes_dfs(rb.root), count); - - /* check if it is still a binary tree */ - check_binary_tree_dfs(rb.root); - - /* root node must be black. Every red node - must have black children. */ - TEST_ASSERT(!rb.root->is_red); - check_colors_dfs(rb.root); - - /* every path from the root to a leave must have - the same number of black nodes. */ - blkdepth = get_ref_black_depth(&rb); - check_black_depth_dfs(rb.root, blkdepth, 0); - - /* longest root to leaf path must be at most - twice as long as the shortest. */ - mind = min_depth(rb.root); - maxd = max_depth(rb.root); - TEST_ASSERT(maxd <= mind * 2); - - /* lookup of current key must work after insert */ - n = rbtree_lookup(&rb, &key); - TEST_NOT_NULL(n); - value = *((sqfs_u64 *)rbtree_node_value(n)); - TEST_EQUAL_UI((sqfs_u64)(key + 10000), value); - } - - rbtree_cleanup(&rb); - return EXIT_SUCCESS; -} diff --git a/tests/str_table.c b/tests/str_table.c deleted file mode 100644 index 7bcf4cc..0000000 --- a/tests/str_table.c +++ /dev/null @@ -1,84 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * str_table.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "str_table.h" -#include "fstream.h" -#include "compat.h" -#include "test.h" - -static char *strings[1000]; - -static int read_strings(void) -{ - istream_t *fp; - ssize_t ret; - char *line; - int i; - - fp = istream_open_file("words.txt"); - TEST_NOT_NULL(fp); - - for (i = 0; i < 1000; ++i) { - ret = istream_get_line(fp, &line, NULL, 0); - TEST_EQUAL_I(ret, 0); - - strings[i] = line; - } - - sqfs_destroy(fp); - return 0; -} - -int main(void) -{ - str_table_t table; - size_t i, j, idx; - const char *str; - - TEST_ASSERT(chdir(TEST_PATH) == 0); - - if (read_strings()) - return EXIT_FAILURE; - - TEST_ASSERT(str_table_init(&table, 64) == 0); - - for (i = 0; i < 1000; ++i) { - TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0); - - TEST_EQUAL_UI(idx, i); - - for (j = 0; j <= i; ++j) { - str = str_table_get_string(&table, j); - - TEST_NOT_NULL(str); - TEST_ASSERT(str != strings[i]); - TEST_STR_EQUAL(str, strings[j]); - } - - for (; j < 1000; ++j) - TEST_NULL(str_table_get_string(&table, j)); - } - - for (i = 0; i < 1000; ++i) { - TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0); - TEST_EQUAL_UI(idx, i); - - str = str_table_get_string(&table, i); - - TEST_NOT_NULL(str); - TEST_ASSERT(str != strings[i]); - TEST_STR_EQUAL(str, strings[i]); - } - - str_table_cleanup(&table); - - for (i = 0; i < 1000; ++i) - free(strings[i]); - - return EXIT_SUCCESS; -} diff --git a/tests/tar/CREDITS b/tests/tar/CREDITS deleted file mode 100644 index 7a2738f..0000000 --- a/tests/tar/CREDITS +++ /dev/null @@ -1,35 +0,0 @@ -The tar archives in this directory have been obtained from here: - - https://github.com/mgorny/tar-test-inputs - - git commit hash a2110a6 - -This repository was linked in the following article on interoperability of -various different tar programs: - - https://dev.gentoo.org/~mgorny/articles/portability-of-tar-features.html - -The original intention of the example archives was to test various tar programs -for interoperability with each others extensions and format quirks. - -The following have been removed since there is no intention in adding support -for those features: - - - volume-label tests - - multi-volume tests - - longe user + group names - - sun tar samples - - star samples - - file flags tests - -In addition to that, the files in "file-size" are truncated, since we are only -interested in parsing the header. - -The following addtional files have been added: - - xattr/xattr-shily-binary.tar - Created from xattr/xattr-shily.tar by manually patching in a capability - xattr key/value pair. - - tar/format-acceptance/link_filled.tar - Contributed in GitHub issue #64. A tar ball that contains a hard link - where the 100 byte target field is completely filled without containing - a null-terminator. diff --git a/tests/tar/file-size/12-digit.tar b/tests/tar/file-size/12-digit.tar deleted file mode 100644 index a6b3553..0000000 Binary files a/tests/tar/file-size/12-digit.tar and /dev/null differ diff --git a/tests/tar/file-size/gnu.tar b/tests/tar/file-size/gnu.tar deleted file mode 100644 index aad726f..0000000 Binary files a/tests/tar/file-size/gnu.tar and /dev/null differ diff --git a/tests/tar/file-size/pax.tar b/tests/tar/file-size/pax.tar deleted file mode 100644 index e391fee..0000000 Binary files a/tests/tar/file-size/pax.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/gnu-g.tar b/tests/tar/format-acceptance/gnu-g.tar deleted file mode 100644 index a72f60d..0000000 Binary files a/tests/tar/format-acceptance/gnu-g.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/gnu.tar b/tests/tar/format-acceptance/gnu.tar deleted file mode 100644 index 98e8157..0000000 Binary files a/tests/tar/format-acceptance/gnu.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/link_filled.tar b/tests/tar/format-acceptance/link_filled.tar deleted file mode 100644 index 9b80f89..0000000 Binary files a/tests/tar/format-acceptance/link_filled.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/pax.tar b/tests/tar/format-acceptance/pax.tar deleted file mode 100644 index 69a029f..0000000 Binary files a/tests/tar/format-acceptance/pax.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/ustar-pre-posix.tar b/tests/tar/format-acceptance/ustar-pre-posix.tar deleted file mode 100644 index 4230f5f..0000000 Binary files a/tests/tar/format-acceptance/ustar-pre-posix.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/ustar.tar b/tests/tar/format-acceptance/ustar.tar deleted file mode 100644 index 9a6d9b3..0000000 Binary files a/tests/tar/format-acceptance/ustar.tar and /dev/null differ diff --git a/tests/tar/format-acceptance/v7.tar b/tests/tar/format-acceptance/v7.tar deleted file mode 100644 index 5483b4b..0000000 Binary files a/tests/tar/format-acceptance/v7.tar and /dev/null differ diff --git a/tests/tar/large-mtime/12-digit.tar b/tests/tar/large-mtime/12-digit.tar deleted file mode 100644 index 8202b28..0000000 Binary files a/tests/tar/large-mtime/12-digit.tar and /dev/null differ diff --git a/tests/tar/large-mtime/gnu.tar b/tests/tar/large-mtime/gnu.tar deleted file mode 100644 index 4e3dda2..0000000 Binary files a/tests/tar/large-mtime/gnu.tar and /dev/null differ diff --git a/tests/tar/large-mtime/pax.tar b/tests/tar/large-mtime/pax.tar deleted file mode 100644 index 8d32530..0000000 Binary files a/tests/tar/large-mtime/pax.tar and /dev/null differ diff --git a/tests/tar/long-paths/gnu.tar b/tests/tar/long-paths/gnu.tar deleted file mode 100644 index 4eee731..0000000 Binary files a/tests/tar/long-paths/gnu.tar and /dev/null differ diff --git a/tests/tar/long-paths/pax.tar b/tests/tar/long-paths/pax.tar deleted file mode 100644 index 1e63e9c..0000000 Binary files a/tests/tar/long-paths/pax.tar and /dev/null differ diff --git a/tests/tar/long-paths/ustar.tar b/tests/tar/long-paths/ustar.tar deleted file mode 100644 index 812255c..0000000 Binary files a/tests/tar/long-paths/ustar.tar and /dev/null differ diff --git a/tests/tar/negative-mtime/gnu.tar b/tests/tar/negative-mtime/gnu.tar deleted file mode 100644 index a9b1272..0000000 Binary files a/tests/tar/negative-mtime/gnu.tar and /dev/null differ diff --git a/tests/tar/negative-mtime/pax.tar b/tests/tar/negative-mtime/pax.tar deleted file mode 100644 index d0b3e6c..0000000 Binary files a/tests/tar/negative-mtime/pax.tar and /dev/null differ diff --git a/tests/tar/sparse-files/gnu-small.tar b/tests/tar/sparse-files/gnu-small.tar deleted file mode 100644 index 7a1b222..0000000 Binary files a/tests/tar/sparse-files/gnu-small.tar and /dev/null differ diff --git a/tests/tar/sparse-files/gnu.tar b/tests/tar/sparse-files/gnu.tar deleted file mode 100644 index 3d641a2..0000000 Binary files a/tests/tar/sparse-files/gnu.tar and /dev/null differ diff --git a/tests/tar/sparse-files/pax-gnu0-0.tar b/tests/tar/sparse-files/pax-gnu0-0.tar deleted file mode 100644 index 628f09e..0000000 Binary files a/tests/tar/sparse-files/pax-gnu0-0.tar and /dev/null differ diff --git a/tests/tar/sparse-files/pax-gnu0-1.tar b/tests/tar/sparse-files/pax-gnu0-1.tar deleted file mode 100644 index 87e362e..0000000 Binary files a/tests/tar/sparse-files/pax-gnu0-1.tar and /dev/null differ diff --git a/tests/tar/sparse-files/pax-gnu1-0.tar b/tests/tar/sparse-files/pax-gnu1-0.tar deleted file mode 100644 index edb0ccf..0000000 Binary files a/tests/tar/sparse-files/pax-gnu1-0.tar and /dev/null differ diff --git a/tests/tar/sqfs.sha512 b/tests/tar/sqfs.sha512 deleted file mode 100644 index 0abbe82..0000000 --- a/tests/tar/sqfs.sha512 +++ /dev/null @@ -1,28 +0,0 @@ -8fcf00ec57c764bd26e2d2c9db7a95acadd96f106ba37395216f0b331a664e8f5f29c70fcab82dc27f61f89237f23f29637930cd4843bfd7a9632d36088034b4 tests/tar/long-paths/gnu.sqfs -8fcf00ec57c764bd26e2d2c9db7a95acadd96f106ba37395216f0b331a664e8f5f29c70fcab82dc27f61f89237f23f29637930cd4843bfd7a9632d36088034b4 tests/tar/long-paths/pax.sqfs -8fcf00ec57c764bd26e2d2c9db7a95acadd96f106ba37395216f0b331a664e8f5f29c70fcab82dc27f61f89237f23f29637930cd4843bfd7a9632d36088034b4 tests/tar/long-paths/ustar.sqfs -9e2241cf26c1457824f3e3c7a0bd2fc1be1e748ec5725afa33acdb63156b948a9db5f7182d00551587d1892565e05742775243be6e7377174f3d21911fdb7d15 tests/tar/sparse-files/gnu-small.sqfs -5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/tar/sparse-files/gnu.sqfs -5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/tar/sparse-files/pax-gnu0-1.sqfs -5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/tar/sparse-files/pax-gnu0-0.sqfs -5b032c35f80b73f21aef8e9f558c16605676e3e621e927177c4ab0a60ba7441a7501dd21a1c37d43d8432bfa694b6afcbe834a277e2fd8f23315e16bc3cdd86a tests/tar/sparse-files/pax-gnu1-0.sqfs -1b9525453fb10f266cd7f52300fa2ff586a9b5a1c141da46f72c6370485d4dc7e306f2e778108644cdea6f06ee95a2972325f950ef5fce98bf439db1869c692a tests/tar/large-mtime/12-digit.sqfs -1b9525453fb10f266cd7f52300fa2ff586a9b5a1c141da46f72c6370485d4dc7e306f2e778108644cdea6f06ee95a2972325f950ef5fce98bf439db1869c692a tests/tar/large-mtime/gnu.sqfs -1b9525453fb10f266cd7f52300fa2ff586a9b5a1c141da46f72c6370485d4dc7e306f2e778108644cdea6f06ee95a2972325f950ef5fce98bf439db1869c692a tests/tar/large-mtime/pax.sqfs -b43a83dcd5c9ccef1272caa1c9828e7401d3c19579def2caf9f51e814190662d19fbd0ee0c5c20d02e2d404533c593e5d8a549ac18509ce5e829c33cf6c272b0 tests/tar/negative-mtime/gnu.sqfs -b43a83dcd5c9ccef1272caa1c9828e7401d3c19579def2caf9f51e814190662d19fbd0ee0c5c20d02e2d404533c593e5d8a549ac18509ce5e829c33cf6c272b0 tests/tar/negative-mtime/pax.sqfs -d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/gnu-g.sqfs -d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/gnu.sqfs -d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/ustar-pre-posix.sqfs -d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/v7.sqfs -d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/pax.sqfs -d7fd043c8c4614b6b8b430ef8c56fcf35417d6886a3679762b83afcbfa231c9169b514d1da8880e54303df749e0267a606dd3631b4e91bb7cf91d8e71f329687 tests/tar/format-acceptance/ustar.sqfs -2f41b640b8aeec7f5e489fbbeef22bac118c8b1cb068b795433bb6e2f8e9a1ff4f11654e9617b9547ff34b4da7b8e660afcbe69cf630bc112c63693fc56d4e3e tests/tar/format-acceptance/link_filled.sqfs -f97561018def03e8af41c3b479925052469d4a15645886c500a60a5caa835a1ad152b4e72912df52bde29e3645d6bda46002dd91982c3bc91ff844b5724d0917 tests/tar/user-group-largenum/gnu.sqfs -b34d720e04bb7c1fb93c9c3520aa1c653992f9b80339de2416097d95603ab7bbc02ea46300823ec3808c0cfe37ed7477f110ac2eb0fd791832a93f3e5c8a1500 tests/tar/user-group-largenum/8-digit.sqfs -f97561018def03e8af41c3b479925052469d4a15645886c500a60a5caa835a1ad152b4e72912df52bde29e3645d6bda46002dd91982c3bc91ff844b5724d0917 tests/tar/user-group-largenum/pax.sqfs -2dcfaace3235719558d93ed5a0f3e59fc10ab91f070add8ac8f7c4e6bcf5356942ff9db0fea5d8223280863c6e7b216b218b15dc8a2f61d2d42b62ea605cd0d5 tests/tar/xattr/xattr-schily-binary.sqfs -273eb1af519f01f116fd0017f6016d50474fe94e596bda8f3e2467e7dd5741fb45fb7df8830d9e62112a24ce8f8a40f8afa6783459ec04f4c0004ca40a050c49 tests/tar/xattr/xattr-schily.sqfs -273eb1af519f01f116fd0017f6016d50474fe94e596bda8f3e2467e7dd5741fb45fb7df8830d9e62112a24ce8f8a40f8afa6783459ec04f4c0004ca40a050c49 tests/tar/xattr/xattr-libarchive.sqfs -dabba481b7e0d6888c1cb429eca304aac3c39146910ab0160179947de5ee3b68b5dcca2be3aff4536343357c6c48733f22b26cee1c2d4ff000c2edc276f2c235 tests/tar/xattr/acl.sqfs -a050ee2a296900bcb06d9616d06b1d947d9f26f0b57d6aff318c3dc656810c919f63a24144f890a4fae60268fda19becf9021182f1c0afd8acc0874e720f720e tests/tar2sqfs/root-becomes.sqfs diff --git a/tests/tar/user-group-largenum/8-digit.tar b/tests/tar/user-group-largenum/8-digit.tar deleted file mode 100644 index a48ea5d..0000000 Binary files a/tests/tar/user-group-largenum/8-digit.tar and /dev/null differ diff --git a/tests/tar/user-group-largenum/gnu.tar b/tests/tar/user-group-largenum/gnu.tar deleted file mode 100644 index 4c30f57..0000000 Binary files a/tests/tar/user-group-largenum/gnu.tar and /dev/null differ diff --git a/tests/tar/user-group-largenum/pax.tar b/tests/tar/user-group-largenum/pax.tar deleted file mode 100644 index a9fe54c..0000000 Binary files a/tests/tar/user-group-largenum/pax.tar and /dev/null differ diff --git a/tests/tar/xattr/acl.tar b/tests/tar/xattr/acl.tar deleted file mode 100644 index a65c0af..0000000 Binary files a/tests/tar/xattr/acl.tar and /dev/null differ diff --git a/tests/tar/xattr/xattr-libarchive.tar b/tests/tar/xattr/xattr-libarchive.tar deleted file mode 100644 index 3bd6125..0000000 Binary files a/tests/tar/xattr/xattr-libarchive.tar and /dev/null differ diff --git a/tests/tar/xattr/xattr-schily-binary.tar b/tests/tar/xattr/xattr-schily-binary.tar deleted file mode 100644 index 0312807..0000000 Binary files a/tests/tar/xattr/xattr-schily-binary.tar and /dev/null differ diff --git a/tests/tar/xattr/xattr-schily.tar b/tests/tar/xattr/xattr-schily.tar deleted file mode 100644 index 1cf525c..0000000 Binary files a/tests/tar/xattr/xattr-schily.tar and /dev/null differ diff --git a/tests/tar_big_file.c b/tests/tar_big_file.c deleted file mode 100644 index c9fbcc5..0000000 --- a/tests/tar_big_file.c +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_big_file.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -int main(void) -{ - tar_header_decoded_t hdr; - istream_t *fp; - - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); - TEST_NOT_NULL(fp); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, 01750); - TEST_EQUAL_UI(hdr.sb.st_gid, 01750); - TEST_EQUAL_UI(hdr.sb.st_size, 8589934592); - TEST_EQUAL_UI(hdr.sb.st_mtime, 1542959190); - TEST_EQUAL_UI(hdr.mtime, 1542959190); - TEST_STR_EQUAL(hdr.name, "big-file.bin"); - TEST_ASSERT(!hdr.unknown_record); - clear_header(&hdr); - sqfs_destroy(fp); - return EXIT_SUCCESS; -} diff --git a/tests/tar_fuzz.c b/tests/tar_fuzz.c deleted file mode 100644 index e5f5c0b..0000000 --- a/tests/tar_fuzz.c +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_fuzz.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "tar.h" - -#include -#include - -int main(int argc, char **argv) -{ - tar_header_decoded_t hdr; - istream_t *fp; - int ret; - - if (argc != 2) { - fputs("usage: tar_fuzz \n", stderr); - return EXIT_FAILURE; - } - - fp = istream_open_file(argv[1]); - if (fp == NULL) - return EXIT_FAILURE; - - for (;;) { - ret = read_header(fp, &hdr); - if (ret > 0) - break; - if (ret < 0) - goto fail; - - ret = istream_skip(fp, hdr.sb.st_size); - - clear_header(&hdr); - if (ret < 0) - goto fail; - } - - sqfs_destroy(fp); - return EXIT_SUCCESS; -fail: - sqfs_destroy(fp); - return EXIT_FAILURE; -} diff --git a/tests/tar_simple.c b/tests/tar_simple.c deleted file mode 100644 index fb30205..0000000 --- a/tests/tar_simple.c +++ /dev/null @@ -1,69 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_simple.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -#ifndef TESTUID -#define TESTUID 1000 -#endif - -#ifndef TESTGID -#define TESTGID TESTUID -#endif - -#ifndef TESTFNAME -#define TESTFNAME input.txt -#endif - -#ifndef TESTTS -#define TESTTS 1542905892 -#endif - -#ifdef LONG_NAME_TEST -static const char *fname = -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/input.txt"; -#else -static const char *fname = STRVALUE(TESTFNAME); -#endif - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - sqfs_s64 ts; - istream_t *fp; - - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); - TEST_NOT_NULL(fp); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, TESTUID); - TEST_EQUAL_UI(hdr.sb.st_gid, TESTGID); - TEST_EQUAL_UI(hdr.sb.st_size, 5); - - ts = TESTTS; - - if (sizeof(time_t) < sizeof(ts) && ts > INT32_MAX) { - TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX); - } else { - TEST_EQUAL_UI(hdr.sb.st_mtime, ts); - } - - TEST_EQUAL_UI(hdr.mtime, ts); - TEST_STR_EQUAL(hdr.name, fname); - TEST_ASSERT(!hdr.unknown_record); - - TEST_ASSERT(istream_read(fp, buffer, 5) == 5); - buffer[5] = '\0'; - TEST_STR_EQUAL(buffer, "test\n"); - clear_header(&hdr); - sqfs_destroy(fp); - return EXIT_SUCCESS; -} diff --git a/tests/tar_sparse.c b/tests/tar_sparse.c deleted file mode 100644 index 79d2041..0000000 --- a/tests/tar_sparse.c +++ /dev/null @@ -1,85 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_sparse.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -static void test_case_sparse(const char *path) -{ - tar_header_decoded_t hdr; - sparse_map_t *sparse; - istream_t *fp; - - fp = istream_open_file(path); - TEST_NOT_NULL(fp); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, 01750); - TEST_EQUAL_UI(hdr.sb.st_gid, 01750); - TEST_EQUAL_UI(hdr.sb.st_size, 2097152); - TEST_EQUAL_UI(hdr.actual_size, 2097152); - TEST_EQUAL_UI(hdr.record_size, 32768); - TEST_STR_EQUAL(hdr.name, "input.bin"); - TEST_ASSERT(!hdr.unknown_record); - - sparse = hdr.sparse; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 0); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 262144); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 524288); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 786432); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 1048576); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 1310720); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 1572864); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 1835008); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 2097152); - TEST_EQUAL_UI(sparse->count, 0); - - sparse = sparse->next; - TEST_NULL(sparse); - - clear_header(&hdr); - sqfs_destroy(fp); -} - -int main(void) -{ - test_case_sparse( STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE) ); - return EXIT_SUCCESS; -} diff --git a/tests/tar_sparse_gnu.c b/tests/tar_sparse_gnu.c deleted file mode 100644 index 536ec21..0000000 --- a/tests/tar_sparse_gnu.c +++ /dev/null @@ -1,51 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_sparse_gnu.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -int main(void) -{ - tar_header_decoded_t hdr; - sparse_map_t *sparse; - istream_t *fp; - - TEST_ASSERT(chdir(TEST_PATH) == 0); - - fp = istream_open_file("sparse-files/gnu-small.tar"); - TEST_NOT_NULL(fp); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, 01750); - TEST_EQUAL_UI(hdr.sb.st_gid, 01750); - TEST_EQUAL_UI(hdr.sb.st_size, 524288); - TEST_EQUAL_UI(hdr.actual_size, 524288); - TEST_EQUAL_UI(hdr.record_size, 8192); - TEST_STR_EQUAL(hdr.name, "input.bin"); - TEST_ASSERT(!hdr.unknown_record); - - sparse = hdr.sparse; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 0); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 262144); - TEST_EQUAL_UI(sparse->count, 4096); - - sparse = sparse->next; - TEST_NOT_NULL(sparse); - TEST_EQUAL_UI(sparse->offset, 524288); - TEST_EQUAL_UI(sparse->count, 0); - - TEST_NULL(sparse->next); - - clear_header(&hdr); - sqfs_destroy(fp); - return EXIT_SUCCESS; -} diff --git a/tests/tar_target_filled.c b/tests/tar_target_filled.c deleted file mode 100644 index 3ab2421..0000000 --- a/tests/tar_target_filled.c +++ /dev/null @@ -1,108 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_target_filled.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[16]; - istream_t *fp; - - TEST_ASSERT(chdir(TEST_PATH) == 0); - - fp = istream_open_file("format-acceptance/link_filled.tar"); - TEST_NOT_NULL(fp); - - /* "deep" directory hierarchy containg 2 files */ - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20_characters_here01/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" - "20_characters_here03/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" - "20_characters_here03/20_characters_here04/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777); - TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" - "20_characters_here03/20_characters_here04/" - "errored_file_tst"); - TEST_EQUAL_UI(hdr.sb.st_size, 5); - TEST_ASSERT(istream_read(fp, buffer, 5) == 5); - buffer[5] = '\0'; - TEST_STR_EQUAL(buffer, "test\n"); - TEST_ASSERT(skip_padding(fp, 5) == 0); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0777); - TEST_STR_EQUAL(hdr.name, "20_characters_here01/20_characters_here02/" - "20_characters_here03/20_characters_here04/" - "some_test_file"); - TEST_EQUAL_UI(hdr.sb.st_size, 5); - TEST_ASSERT(istream_read(fp, buffer, 5) == 5); - buffer[5] = '\0'; - TEST_STR_EQUAL(buffer, "test\n"); - TEST_ASSERT(skip_padding(fp, 5) == 0); - clear_header(&hdr); - - /* "deep" directory hierarchy containg a hard link */ - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" - "20CharsForLnkTest003/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFDIR | 0777); - TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" - "20CharsForLnkTest003/20CharsForLnkTest004/"); - clear_header(&hdr); - - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_STR_EQUAL(hdr.name, "20CharsForLnkTest001/20CharsForLnkTest002/" - "20CharsForLnkTest003/20CharsForLnkTest004/" - "01234567890123456789"); - TEST_ASSERT(hdr.is_hard_link); - - TEST_STR_EQUAL(hdr.link_target, "20_characters_here01/" - "20_characters_here02/20_characters_here03/" - "20_characters_here04/errored_file_tst"); - clear_header(&hdr); - - /* end of file */ - TEST_ASSERT(read_header(fp, &hdr) > 0); - sqfs_destroy(fp); - - return EXIT_SUCCESS; -} diff --git a/tests/tar_xattr.c b/tests/tar_xattr.c deleted file mode 100644 index d864ba3..0000000 --- a/tests/tar_xattr.c +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_xattr.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - istream_t *fp; - - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); - TEST_NOT_NULL(fp); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, 01750); - TEST_EQUAL_UI(hdr.sb.st_gid, 01750); - TEST_EQUAL_UI(hdr.sb.st_size, 5); - TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); - TEST_EQUAL_UI(hdr.mtime, 1543094477); - TEST_STR_EQUAL(hdr.name, "input.txt"); - TEST_ASSERT(!hdr.unknown_record); - TEST_ASSERT(istream_read(fp, buffer, 5) == 5); - buffer[5] = '\0'; - TEST_STR_EQUAL(buffer, "test\n"); - - TEST_NOT_NULL(hdr.xattr); - TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type"); - TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain"); - TEST_EQUAL_UI(hdr.xattr->value_len, 10); - TEST_NULL(hdr.xattr->next); - - clear_header(&hdr); - sqfs_destroy(fp); - return EXIT_SUCCESS; -} diff --git a/tests/tar_xattr_bin.c b/tests/tar_xattr_bin.c deleted file mode 100644 index 5f45c15..0000000 --- a/tests/tar_xattr_bin.c +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_xattr_bin.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" -#include "tar.h" -#include "test.h" - -static const uint8_t value[] = { - 0x00, 0x00, 0x00, 0x02, - 0x00, 0x30, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, -}; - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - istream_t *fp; - - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); - TEST_NOT_NULL(fp); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, 01750); - TEST_EQUAL_UI(hdr.sb.st_gid, 01750); - TEST_EQUAL_UI(hdr.sb.st_size, 5); - TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); - TEST_EQUAL_UI(hdr.mtime, 1543094477); - TEST_STR_EQUAL(hdr.name, "input.txt"); - TEST_ASSERT(!hdr.unknown_record); - TEST_ASSERT(istream_read(fp, buffer, 5) == 5); - buffer[5] = '\0'; - TEST_STR_EQUAL(buffer, "test\n"); - - TEST_NOT_NULL(hdr.xattr); - TEST_STR_EQUAL(hdr.xattr->key, "security.capability"); - TEST_EQUAL_UI(hdr.xattr->value_len, sizeof(value)); - TEST_ASSERT(memcmp(hdr.xattr->value, value, sizeof(value)) == 0); - TEST_NULL(hdr.xattr->next); - - clear_header(&hdr); - sqfs_destroy(fp); - return EXIT_SUCCESS; -} diff --git a/tests/test_tar_sqfs.sh.in b/tests/test_tar_sqfs.sh.in index c23a217..ad9fba3 100755 --- a/tests/test_tar_sqfs.sh.in +++ b/tests/test_tar_sqfs.sh.in @@ -2,9 +2,9 @@ set -e -TARDIR="@abs_top_srcdir@/tests/tar" +TARDIR="@abs_top_srcdir@/tests/libtar/data" TARDIR2="@abs_top_srcdir@/tests/tar2sqfs" -SHA512FILE="@abs_top_srcdir@/tests/tar/sqfs.sha512" +SHA512FILE="@abs_top_srcdir@/tests/libtar/data/sqfs.sha512" TAR2SQFS="@abs_top_builddir@/tar2sqfs" if [ ! -f "$TAR2SQFS" -a -f "${TAR2SQFS}.exe" ]; then diff --git a/tests/words.txt b/tests/words.txt deleted file mode 100644 index 9496e14..0000000 --- a/tests/words.txt +++ /dev/null @@ -1,1000 +0,0 @@ -a -ability -able -about -above -accept -according -account -across -act -action -activity -actually -add -address -administration -admit -adult -affect -after -again -against -age -agency -agent -ago -agree -agreement -ahead -air -all -allow -almost -alone -along -already -also -although -always -American -among -amount -analysis -and -animal -another -answer -any -anyone -anything -appear -apply -approach -area -argue -arm -around -arrive -art -article -artist -as -ask -assume -at -attack -attention -attorney -audience -author -authority -available -avoid -away -baby -back -bad -bag -ball -bank -bar -base -be -beat -beautiful -because -become -bed -before -begin -behavior -behind -believe -benefit -best -better -between -beyond -big -bill -billion -bit -black -blood -blue -board -body -book -born -both -box -boy -break -bring -brother -budget -build -building -business -but -buy -by -call -camera -campaign -can -cancer -candidate -capital -car -card -care -career -carry -case -catch -cause -cell -center -central -century -certain -certainly -chair -challenge -chance -change -character -charge -check -child -choice -choose -church -citizen -city -civil -claim -class -clear -clearly -close -coach -cold -collection -college -color -come -commercial -common -community -company -compare -computer -concern -condition -conference -Congress -consider -consumer -contain -continue -control -cost -could -country -couple -course -court -cover -create -crime -cultural -culture -cup -current -customer -cut -dark -data -daughter -day -dead -deal -death -debate -decade -decide -decision -deep -defense -degree -Democrat -democratic -describe -design -despite -detail -determine -develop -development -die -difference -different -difficult -dinner -direction -director -discover -discuss -discussion -disease -do -doctor -dog -door -down -draw -dream -drive -drop -drug -during -each -early -east -easy -eat -economic -economy -edge -education -effect -effort -eight -either -election -else -employee -end -energy -enjoy -enough -enter -entire -environment -environmental -especially -establish -even -evening -event -ever -every -everybody -everyone -everything -evidence -exactly -example -executive -exist -expect -experience -expert -explain -eye -face -fact -factor -fail -fall -family -far -fast -father -fear -federal -feel -feeling -few -field -fight -figure -fill -film -final -finally -financial -find -fine -finger -finish -fire -firm -first -fish -five -floor -fly -focus -follow -food -foot -for -force -foreign -forget -form -former -forward -four -free -friend -from -front -full -fund -future -game -garden -gas -general -generation -get -girl -give -glass -go -goal -good -government -great -green -ground -group -grow -growth -guess -gun -guy -hair -half -hand -hang -happen -happy -hard -have -he -head -health -hear -heart -heat -heavy -help -her -here -herself -high -him -himself -his -history -hit -hold -home -hope -hospital -hot -hotel -hour -house -how -however -huge -human -hundred -husband -I -idea -identify -if -image -imagine -impact -important -improve -in -include -including -increase -indeed -indicate -individual -industry -information -inside -instead -institution -interest -interesting -international -interview -into -investment -involve -issue -it -item -its -itself -job -join -just -keep -key -kid -kill -kind -kitchen -know -knowledge -land -language -large -last -late -later -laugh -law -lawyer -lay -lead -leader -learn -least -leave -left -leg -legal -less -let -letter -level -lie -life -light -like -likely -line -list -listen -little -live -local -long -look -lose -loss -lot -love -low -machine -magazine -main -maintain -major -majority -make -man -manage -management -manager -many -market -marriage -material -matter -may -maybe -me -mean -measure -media -medical -meet -meeting -member -memory -mention -message -method -middle -might -military -million -mind -minute -miss -mission -model -modern -moment -money -month -more -morning -most -mother -mouth -move -movement -movie -Mr -Mrs -much -music -must -my -myself -name -nation -national -natural -nature -near -nearly -necessary -need -network -never -new -news -newspaper -next -nice -night -no -none -nor -north -not -note -nothing -notice -now -n't -number -occur -of -off -offer -office -officer -official -often -oh -oil -ok -old -on -once -one -only -onto -open -operation -opportunity -option -or -order -organization -other -others -our -out -outside -over -own -owner -page -pain -painting -paper -parent -part -participant -particular -particularly -partner -party -pass -past -patient -pattern -pay -peace -people -per -perform -performance -perhaps -period -person -personal -phone -physical -pick -picture -piece -place -plan -plant -play -player -PM -point -police -policy -political -politics -poor -popular -population -position -positive -possible -power -practice -prepare -present -president -pressure -pretty -prevent -price -private -probably -problem -process -produce -product -production -professional -professor -program -project -property -protect -prove -provide -public -pull -purpose -push -put -quality -question -quickly -quite -race -radio -raise -range -rate -rather -reach -read -ready -real -reality -realize -really -reason -receive -recent -recently -recognize -record -red -reduce -reflect -region -relate -relationship -religious -remain -remember -remove -report -represent -Republican -require -research -resource -respond -response -responsibility -rest -result -return -reveal -rich -right -rise -risk -road -rock -role -room -rule -run -safe -same -save -say -scene -school -science -scientist -score -sea -season -seat -second -section -security -see -seek -seem -sell -send -senior -sense -series -serious -serve -service -set -seven -several -sex -sexual -shake -share -she -shoot -short -shot -should -shoulder -show -side -sign -significant -similar -simple -simply -since -sing -single -sister -sit -site -situation -six -size -skill -skin -small -smile -so -social -society -soldier -some -somebody -someone -something -sometimes -son -song -soon -sort -sound -source -south -southern -space -speak -special -specific -speech -spend -sport -spring -staff -stage -stand -standard -star -start -state -statement -station -stay -step -still -stock -stop -store -story -strategy -street -strong -structure -student -study -stuff -style -subject -success -successful -such -suddenly -suffer -suggest -summer -support -sure -surface -system -table -take -talk -task -tax -teach -teacher -team -technology -television -tell -ten -tend -term -test -than -thank -that -the -their -them -themselves -then -theory -there -these -they -thing -think -third -this -those -though -thought -thousand -threat -three -through -throughout -throw -thus -time -to -today -together -tonight -too -top -total -tough -toward -town -trade -traditional -training -travel -treat -treatment -tree -trial -trip -trouble -true -truth -try -turn -TV -two -type -under -understand -unit -until -up -upon -us -use -usually -value -various -very -victim -view -violence -visit -voice -vote -wait -walk -wall -want -war -watch -water -way -we -weapon -wear -week -weight -well -west -western -what -whatever -when -where -whether -which -while -white -who -whole -whom -whose -why -wide -wife -will -win -wind -window -wish -with -within -without -woman -wonder -word -work -worker -world -worry -would -write -writer -wrong -yard -yeah -year -yes -yet -you -young -your -yourself diff --git a/tests/xxhash.c b/tests/xxhash.c deleted file mode 100644 index a7ab4a9..0000000 --- a/tests/xxhash.c +++ /dev/null @@ -1,65 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * xxhash.c - * - * Copyright (C) 2020 David Oberhollenzer - */ -#include "config.h" - -#include "util.h" -#include "test.h" - -static const struct { - const char *plaintext; - size_t psize; - sqfs_u32 digest; -} test_vectors[] = { - { - .plaintext = "\x9e", - .psize = 1, - .digest = 0xB85CBEE5, - }, - { - .plaintext = "\x9e\xff\x1f\x4b\x5e\x53\x2f\xdd" - "\xb5\x54\x4d\x2a\x95\x2b", - .psize = 14, - .digest = 0xE5AA0AB4, - }, - { - .plaintext = "\x9e\xff\x1f\x4b\x5e\x53\x2f\xdd" - "\xb5\x54\x4d\x2a\x95\x2b\x57\xae" - "\x5d\xba\x74\xe9\xd3\xa6\x4c\x98" - "\x30\x60\xc0\x80\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00", - .psize = 101, - .digest = 0x018F52BC, - }, -}; - -int main(void) -{ - sqfs_u32 hash; - size_t i; - - for (i = 0; i < sizeof(test_vectors) / sizeof(test_vectors[0]); ++i) { - hash = xxh32(test_vectors[i].plaintext, test_vectors[i].psize); - - if (hash != test_vectors[i].digest) { - fprintf(stderr, "Test case " PRI_SZ " failed!\n", i); - fprintf(stderr, "Expected result: 0x%08X\n", - test_vectors[i].digest); - fprintf(stderr, "Actual result: 0x%08X\n", hash); - return EXIT_FAILURE; - } - } - - return EXIT_SUCCESS; -} -- cgit v1.2.3