diff options
-rw-r--r-- | tests/Makemodule.am | 173 | ||||
-rw-r--r-- | tests/tar_big_file.c | 27 | ||||
-rw-r--r-- | tests/tar_gnu.c | 32 | ||||
-rw-r--r-- | tests/tar_pax.c | 31 | ||||
-rw-r--r-- | tests/tar_simple.c | 66 | ||||
-rw-r--r-- | tests/tar_sparse.c | 82 | ||||
-rw-r--r-- | tests/tar_sparse_gnu.c | 2 | ||||
-rw-r--r-- | tests/tar_sparse_gnu1.c | 15 | ||||
-rw-r--r-- | tests/tar_sparse_gnu2.c | 16 | ||||
-rw-r--r-- | tests/tar_ustar.c | 33 | ||||
-rw-r--r-- | tests/tar_xattr.c | 38 | ||||
-rw-r--r-- | tests/tar_xattr_bin.c (renamed from tests/tar_xattr_schily_bin.c) | 6 | ||||
-rw-r--r-- | tests/tar_xattr_bsd.c | 15 | ||||
-rw-r--r-- | tests/tar_xattr_schily.c | 15 | ||||
-rw-r--r-- | tests/test_tar.h | 151 |
15 files changed, 364 insertions, 338 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 2bca679..809ff07 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -61,17 +61,115 @@ 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_gnu_SOURCES = tests/tar_gnu.c tests/test.h tests/test_tar.h -test_tar_gnu_LDADD = libtar.a libcompat.a -test_tar_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar - -test_tar_pax_SOURCES = tests/tar_pax.c tests/test.h tests/test_tar.h -test_tar_pax_LDADD = libtar.a libcompat.a -test_tar_pax_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar - -test_tar_ustar_SOURCES = tests/tar_ustar.c tests/test.h tests/test_tar.h -test_tar_ustar_LDADD = libtar.a libcompat.a -test_tar_ustar_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar +test_tar_gnu0_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h +test_tar_gnu0_LDADD = libtar.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 tests/test_tar.h +test_tar_gnu1_LDADD = libtar.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 tests/test_tar.h +test_tar_gnu2_LDADD = libtar.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 tests/test_tar.h +test_tar_gnu3_LDADD = libtar.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 tests/test_tar.h +test_tar_gnu4_LDADD = libtar.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 tests/test_tar.h +test_tar_gnu5_LDADD = libtar.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 tests/test_tar.h +test_tar_gnu6_LDADD = libtar.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 tests/test_tar.h +test_tar_pax0_LDADD = libtar.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 tests/test_tar.h +test_tar_pax1_LDADD = libtar.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 tests/test_tar.h +test_tar_pax2_LDADD = libtar.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 tests/test_tar.h +test_tar_pax3_LDADD = libtar.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 tests/test_tar.h +test_tar_pax4_LDADD = libtar.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 tests/test_tar.h +test_tar_pax5_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar0_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar1_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar2_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar3_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar4_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar5_LDADD = libtar.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 tests/test_tar.h +test_tar_ustar6_LDADD = libtar.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_SOURCES += tests/test_tar.h @@ -84,33 +182,47 @@ test_tar_sparse_gnu_SOURCES += tests/test_tar.h test_tar_sparse_gnu_LDADD = libtar.a libcompat.a test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu1_SOURCES = tests/tar_sparse_gnu1.c tests/test.h -test_tar_sparse_gnu1_SOURCES += tests/test_tar.h +test_tar_sparse_gnu0_SOURCES = tests/tar_sparse.c tests/test.h tests/test_tar.h +test_tar_sparse_gnu0_LDADD = libtar.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 tests/test_tar.h test_tar_sparse_gnu1_LDADD = libtar.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_gnu2.c tests/test.h -test_tar_sparse_gnu2_SOURCES += tests/test_tar.h +test_tar_sparse_gnu2_SOURCES = tests/tar_sparse.c tests/test.h tests/test_tar.h test_tar_sparse_gnu2_LDADD = libtar.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 tests/test_tar.h +test_tar_sparse_gnu3_LDADD = libtar.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_bsd.c tests/test.h tests/test_tar.h +test_tar_xattr_bsd_SOURCES = tests/tar_xattr.c tests/test.h tests/test_tar.h test_tar_xattr_bsd_LDADD = libtar.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_schily.c tests/test.h -test_tar_xattr_schily_SOURCES += tests/test_tar.h +test_tar_xattr_schily_SOURCES = tests/tar_xattr.c tests/test.h tests/test_tar.h test_tar_xattr_schily_LDADD = libtar.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_schily_bin.c tests/test.h +test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_bin.c tests/test.h test_tar_xattr_schily_bin_SOURCES += tests/test_tar.h test_tar_xattr_schily_bin_LDADD = libtar.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 libcompat.a @@ -122,8 +234,15 @@ 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_tar_ustar test_tar_pax test_tar_gnu -check_PROGRAMS += test_tar_sparse_gnu test_tar_sparse_gnu1 test_tar_sparse_gnu2 +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 @@ -133,9 +252,15 @@ 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_tar_ustar test_tar_pax -TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1 -TESTS += test_tar_sparse_gnu2 test_tar_xattr_bsd test_tar_xattr_schily +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 if CORPORA_TESTS diff --git a/tests/tar_big_file.c b/tests/tar_big_file.c new file mode 100644 index 0000000..b949f60 --- /dev/null +++ b/tests/tar_big_file.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_big_file.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "test_tar.h" + +int main(void) +{ + tar_header_decoded_t hdr; + FILE *fp; + + fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + 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); + fclose(fp); + return EXIT_SUCCESS; +} diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c deleted file mode 100644 index b21c283..0000000 --- a/tests/tar_gnu.c +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_gnu.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -static const char *filename = -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/input.txt"; - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - testcase_simple("format-acceptance/gnu.tar", 1542905892, - 1000, 1000, "input.txt"); - testcase_simple("format-acceptance/gnu-g.tar", 013375560044, - 1000, 1000, "input.txt"); - testcase_simple("user-group-largenum/gnu.tar", 013376036700, - 0x80000000, 0x80000000, "input.txt"); - testcase_simple("negative-mtime/gnu.tar", -315622800, - 1000, 1000, "input.txt"); - testcase_simple("long-paths/gnu.tar", 1542909670, - 1000, 1000, filename); - testcase_simple("large-mtime/gnu.tar", 8589934592L, - 1000, 1000, "input.txt"); - test_case_file_size("file-size/gnu.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/tar_pax.c b/tests/tar_pax.c deleted file mode 100644 index 52b3481..0000000 --- a/tests/tar_pax.c +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_pax.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -static const char *filename = -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/input.txt"; - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - testcase_simple("format-acceptance/pax.tar", 1542905892, - 1000, 1000, "input.txt"); - testcase_simple("user-group-largenum/pax.tar", 013376036700, - 2147483648UL, 2147483648UL, "input.txt"); - testcase_simple("large-mtime/pax.tar", 8589934592L, - 1000, 1000, "input.txt"); - testcase_simple("negative-mtime/pax.tar", -315622800, - 1000, 1000, "input.txt"); - testcase_simple("long-paths/pax.tar", 1542909670, - 1000, 1000, filename); - - test_case_file_size("file-size/pax.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/tar_simple.c b/tests/tar_simple.c new file mode 100644 index 0000000..02bd521 --- /dev/null +++ b/tests/tar_simple.c @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_simple.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "test_tar.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; + FILE *fp; + + fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + 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(read_retry("tar data", fp, buffer, 5) == 0); + buffer[5] = '\0'; + TEST_STR_EQUAL(buffer, "test\n"); + clear_header(&hdr); + fclose(fp); + return EXIT_SUCCESS; +} diff --git a/tests/tar_sparse.c b/tests/tar_sparse.c new file mode 100644 index 0000000..50940d0 --- /dev/null +++ b/tests/tar_sparse.c @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_sparse.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "test_tar.h" + +static void test_case_sparse(const char *path) +{ + tar_header_decoded_t hdr; + sparse_map_t *sparse; + FILE *fp; + + fp = test_open_read(path); + 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); + fclose(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 index fdeb53e..216a54a 100644 --- a/tests/tar_sparse_gnu.c +++ b/tests/tar_sparse_gnu.c @@ -44,7 +44,5 @@ int main(void) clear_header(&hdr); fclose(fp); - - test_case_sparse("sparse-files/gnu.tar"); return EXIT_SUCCESS; } diff --git a/tests/tar_sparse_gnu1.c b/tests/tar_sparse_gnu1.c deleted file mode 100644 index 1e74969..0000000 --- a/tests/tar_sparse_gnu1.c +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_sparse_gnu1.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - test_case_sparse("sparse-files/pax-gnu0-0.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/tar_sparse_gnu2.c b/tests/tar_sparse_gnu2.c deleted file mode 100644 index f08f286..0000000 --- a/tests/tar_sparse_gnu2.c +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_sparse_gnu2.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - test_case_sparse("sparse-files/pax-gnu0-1.tar"); - test_case_sparse("sparse-files/pax-gnu1-0.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c deleted file mode 100644 index 8ca1b36..0000000 --- a/tests/tar_ustar.c +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_ustar.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -static const char *filename = -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/input.txt"; - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - testcase_simple("format-acceptance/ustar.tar", 1542905892, - 1000, 1000, "input.txt"); - testcase_simple("format-acceptance/ustar-pre-posix.tar", 1542905892, - 1000, 1000, "input.txt"); - testcase_simple("format-acceptance/v7.tar", 1542905892, - 1000, 1000, "input.txt"); - testcase_simple("user-group-largenum/8-digit.tar", 1542995392, - 8388608, 8388608, "input.txt"); - testcase_simple("large-mtime/12-digit.tar", 8589934592L, - 1000, 1000, "input.txt"); - testcase_simple("long-paths/ustar.tar", 1542909670, - 1000, 1000, filename); - - test_case_file_size("file-size/12-digit.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/tar_xattr.c b/tests/tar_xattr.c new file mode 100644 index 0000000..179af2e --- /dev/null +++ b/tests/tar_xattr.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar_xattr.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "test_tar.h" + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + FILE *fp; + + fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + 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(read_retry("reading tar data", fp, buffer, 5) == 0); + 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); + fclose(fp); + return EXIT_SUCCESS; +} diff --git a/tests/tar_xattr_schily_bin.c b/tests/tar_xattr_bin.c index 0fe2004..ca0f918 100644 --- a/tests/tar_xattr_schily_bin.c +++ b/tests/tar_xattr_bin.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ /* - * tar_xattr_schily_bin.c + * tar_xattr_bin.c * * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> */ @@ -20,9 +20,7 @@ int main(void) char buffer[6]; FILE *fp; - TEST_ASSERT(chdir(TEST_PATH) == 0); - - fp = test_open_read("xattr/xattr-schily-binary.tar"); + fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); 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); diff --git a/tests/tar_xattr_bsd.c b/tests/tar_xattr_bsd.c deleted file mode 100644 index 4918afe..0000000 --- a/tests/tar_xattr_bsd.c +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_xattr_bsd.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - test_case_xattr_simple("xattr/xattr-libarchive.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/tar_xattr_schily.c b/tests/tar_xattr_schily.c deleted file mode 100644 index 1ca735b..0000000 --- a/tests/tar_xattr_schily.c +++ /dev/null @@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * tar_xattr_schily.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "test_tar.h" - -int main(void) -{ - TEST_ASSERT(chdir(TEST_PATH) == 0); - - test_case_xattr_simple("xattr/xattr-schily.tar"); - return EXIT_SUCCESS; -} diff --git a/tests/test_tar.h b/tests/test_tar.h index 3bbf328..9ec2b12 100644 --- a/tests/test_tar.h +++ b/tests/test_tar.h @@ -16,155 +16,4 @@ #define TEST_PATH STRVALUE(TESTPATH) -static ATTRIB_UNUSED void testcase_simple(const char *path, sqfs_s64 ts, - sqfs_u32 uid, sqfs_u32 gid, - const char *fname) -{ - tar_header_decoded_t hdr; - char buffer[6]; - FILE *fp; - - fp = test_open_read(path); - TEST_ASSERT(read_header(fp, &hdr) == 0); - TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); - TEST_EQUAL_UI(hdr.sb.st_uid, uid); - TEST_EQUAL_UI(hdr.sb.st_gid, gid); - TEST_EQUAL_UI(hdr.sb.st_size, 5); - - 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(read_retry("tar data", fp, buffer, 5) == 0); - buffer[5] = '\0'; - TEST_STR_EQUAL(buffer, "test\n"); - clear_header(&hdr); - fclose(fp); - -} - -static ATTRIB_UNUSED void test_case_file_size(const char *path) -{ - tar_header_decoded_t hdr; - FILE *fp; - - fp = test_open_read(path); - 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); - fclose(fp); -} - -static ATTRIB_UNUSED void test_case_sparse(const char *path) -{ - tar_header_decoded_t hdr; - sparse_map_t *sparse; - FILE *fp; - - fp = test_open_read(path); - 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); - fclose(fp); -} - -static ATTRIB_UNUSED void test_case_xattr_simple(const char *path) -{ - tar_header_decoded_t hdr; - char buffer[6]; - FILE *fp; - - fp = test_open_read(path); - 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(read_retry("reading tar data", fp, buffer, 5) == 0); - 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); - fclose(fp); -} - #endif /* TEST_TAR_H */ |