From 62c596a761d9a511bbf908de36e51dc76b5e3340 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 28 Jun 2019 11:44:07 +0200 Subject: Regroup tar format tests Instead of having test cases per feature with multiple vendors, pack the tests into test case per vendor with miltiple features. This should make errors easier to find, since the code many vendor extensions is closely related for all features. E.g. breaking pax header parser is will now trigger the pax test case and the others still work, vs all tests breaking because each feature test also tries to read the pax version. Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 34 ++++------- tests/tar_big_size.c | 79 ------------------------ tests/tar_formats.c | 140 ------------------------------------------- tests/tar_gnu.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/tar_large_uid.c | 89 --------------------------- tests/tar_long_paths.c | 94 ----------------------------- tests/tar_mtime.c | 123 -------------------------------------- tests/tar_pax.c | 142 +++++++++++++++++++++++++++++++++++++++++++ tests/tar_ustar.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 472 insertions(+), 547 deletions(-) delete mode 100644 tests/tar_big_size.c delete mode 100644 tests/tar_formats.c create mode 100644 tests/tar_gnu.c delete mode 100644 tests/tar_large_uid.c delete mode 100644 tests/tar_long_paths.c delete mode 100644 tests/tar_mtime.c create mode 100644 tests/tar_pax.c create mode 100644 tests/tar_ustar.c (limited to 'tests') diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 44c6eda..75e8a14 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -34,36 +34,26 @@ test_fstree_init_LDADD = libfstree.a libutil.a test_fstree_xattr_SOURCES = tests/fstree_xattr.c test_fstree_xattr_LDADD = libfstree.a libutil.a -test_tar_formats_SOURCES = tests/tar_formats.c -test_tar_formats_LDADD = libtar.a libutil.a -test_tar_formats_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar +test_tar_gnu_SOURCES = tests/tar_gnu.c +test_tar_gnu_LDADD = libtar.a libutil.a +test_tar_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_big_size_SOURCES = tests/tar_big_size.c -test_tar_big_size_LDADD = libtar.a libutil.a -test_tar_big_size_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar +test_tar_pax_SOURCES = tests/tar_pax.c +test_tar_pax_LDADD = libtar.a libutil.a +test_tar_pax_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_long_paths_SOURCES = tests/tar_long_paths.c -test_tar_long_paths_LDADD = libtar.a libutil.a -test_tar_long_paths_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar - -test_tar_mtime_SOURCES = tests/tar_mtime.c -test_tar_mtime_LDADD = libtar.a libutil.a -test_tar_mtime_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar - -test_tar_large_uid_SOURCES = tests/tar_large_uid.c -test_tar_large_uid_LDADD = libtar.a libutil.a -test_tar_large_uid_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar +test_tar_ustar_SOURCES = tests/tar_ustar.c +test_tar_ustar_LDADD = libtar.a libutil.a +test_tar_ustar_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort check_PROGRAMS += test_fstree_from_file test_fstree_init test_fstree_xattr -check_PROGRAMS += test_tar_formats test_tar_long_paths test_tar_mtime -check_PROGRAMS += test_tar_large_uid test_tar_big_size +check_PROGRAMS += test_tar_ustar test_tar_pax test_tar_gnu TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file -TESTS += test_fstree_init test_fstree_xattr test_tar_formats -TESTS += test_tar_long_paths test_tar_mtime test_tar_large_uid -TESTS += test_tar_big_size +TESTS += test_fstree_init test_fstree_xattr test_tar_ustar test_tar_pax +TESTS += test_tar_gnu diff --git a/tests/tar_big_size.c b/tests/tar_big_size.c deleted file mode 100644 index 3b5b557..0000000 --- a/tests/tar_big_size.c +++ /dev/null @@ -1,79 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "util.h" -#include "tar.h" - -#include -#include -#include -#include -#include -#include - -#define STR(x) #x -#define STRVALUE(x) STR(x) - -#define TEST_PATH STRVALUE(TESTPATH) - -static int open_read(const char *path) -{ - int fd = open(path, O_RDONLY); - - if (fd < 0) { - perror(path); - exit(EXIT_FAILURE); - } - - return fd; -} - -int main(void) -{ - tar_header_decoded_t hdr; - int fd; - - assert(chdir(TEST_PATH) == 0); - - fd = open_read("file-size/pax.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 8589934592); - assert(hdr.sb.st_mtime == 1542959190); - assert(hdr.sb.st_atime == 1542959522); - assert(hdr.sb.st_ctime == 1542959190); - assert(strcmp(hdr.name, "big-file.bin") == 0); - assert(!hdr.unknown_record); - clear_header(&hdr); - close(fd); - - fd = open_read("file-size/gnu.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 8589934592); - assert(hdr.sb.st_mtime == 013375730126); - assert(hdr.sb.st_atime == 013375730126); - assert(hdr.sb.st_ctime == 013375730126); - assert(strcmp(hdr.name, "big-file.bin") == 0); - assert(!hdr.unknown_record); - clear_header(&hdr); - close(fd); - - fd = open_read("file-size/12-digit.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 8589934592); - assert(hdr.sb.st_mtime == 013375730126); - assert(hdr.sb.st_atime == 013375730126); - assert(hdr.sb.st_ctime == 013375730126); - assert(strcmp(hdr.name, "big-file.bin") == 0); - assert(!hdr.unknown_record); - clear_header(&hdr); - close(fd); - - return EXIT_SUCCESS; -} diff --git a/tests/tar_formats.c b/tests/tar_formats.c deleted file mode 100644 index a9dcbc3..0000000 --- a/tests/tar_formats.c +++ /dev/null @@ -1,140 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "util.h" -#include "tar.h" - -#include -#include -#include -#include -#include -#include - -#define STR(x) #x -#define STRVALUE(x) STR(x) - -#define TEST_PATH STRVALUE(TESTPATH) - -static int open_read(const char *path) -{ - int fd = open(path, O_RDONLY); - - if (fd < 0) { - perror(path); - exit(EXIT_FAILURE); - } - - return fd; -} - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - int fd; - - assert(chdir(TEST_PATH) == 0); - - fd = open_read("format-acceptance/pax.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.sb.st_atime == 1542905911); - assert(hdr.sb.st_ctime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("format-acceptance/ustar.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.sb.st_atime == 1542905892); - assert(hdr.sb.st_ctime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("format-acceptance/ustar-pre-posix.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.sb.st_atime == 1542905892); - assert(hdr.sb.st_ctime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("format-acceptance/v7.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.sb.st_atime == 1542905892); - assert(hdr.sb.st_ctime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("format-acceptance/gnu.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.sb.st_atime == 1542905892); - assert(hdr.sb.st_ctime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("format-acceptance/gnu-g.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013375560044); - assert(hdr.sb.st_atime == 013375561762); - assert(hdr.sb.st_ctime == 013375561750); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - return EXIT_SUCCESS; -} diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c new file mode 100644 index 0000000..5ce150f --- /dev/null +++ b/tests/tar_gnu.c @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "util.h" +#include "tar.h" + +#include +#include +#include +#include +#include +#include + +#define STR(x) #x +#define STRVALUE(x) STR(x) + +#define TEST_PATH STRVALUE(TESTPATH) + +static int open_read(const char *path) +{ + int fd = open(path, O_RDONLY); + + if (fd < 0) { + perror(path); + exit(EXIT_FAILURE); + } + + return fd; +} + +static const char *filename = +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/input.txt"; + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + int fd; + + assert(chdir(TEST_PATH) == 0); + + fd = open_read("format-acceptance/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.sb.st_atime == 1542905892); + assert(hdr.sb.st_ctime == 1542905892); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("format-acceptance/gnu-g.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 013375560044); + assert(hdr.sb.st_atime == 013375561762); + assert(hdr.sb.st_ctime == 013375561750); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("file-size/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 8589934592); + assert(hdr.sb.st_mtime == 013375730126); + assert(hdr.sb.st_atime == 013375730126); + assert(hdr.sb.st_ctime == 013375730126); + assert(strcmp(hdr.name, "big-file.bin") == 0); + assert(!hdr.unknown_record); + clear_header(&hdr); + close(fd); + + fd = open_read("user-group-largenum/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 0x80000000); + assert(hdr.sb.st_gid == 0x80000000); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 013376036700); + assert(hdr.sb.st_atime == 013376036700); + assert(hdr.sb.st_ctime == 013376036700); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("large-mtime/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 8589934592); + assert(hdr.sb.st_atime == 8589934592); + assert(hdr.sb.st_ctime == 8589934592); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("negative-mtime/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == -315622800); + assert(hdr.sb.st_atime == -315622800); + assert(hdr.sb.st_ctime == -315622800); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("long-paths/gnu.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542909670); + assert(hdr.sb.st_atime == 1542909670); + assert(hdr.sb.st_ctime == 1542909670); + assert(strcmp(hdr.name, filename) == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + return EXIT_SUCCESS; +} diff --git a/tests/tar_large_uid.c b/tests/tar_large_uid.c deleted file mode 100644 index 36ef222..0000000 --- a/tests/tar_large_uid.c +++ /dev/null @@ -1,89 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "util.h" -#include "tar.h" - -#include -#include -#include -#include -#include -#include - -#define STR(x) #x -#define STRVALUE(x) STR(x) - -#define TEST_PATH STRVALUE(TESTPATH) - -static int open_read(const char *path) -{ - int fd = open(path, O_RDONLY); - - if (fd < 0) { - perror(path); - exit(EXIT_FAILURE); - } - - return fd; -} - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - int fd; - - assert(chdir(TEST_PATH) == 0); - - fd = open_read("user-group-largenum/8-digit.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 8388608); - assert(hdr.sb.st_gid == 8388608); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013376036700); - assert(hdr.sb.st_atime == 013376036700); - assert(hdr.sb.st_ctime == 013376036700); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("user-group-largenum/pax.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 2147483648); - assert(hdr.sb.st_gid == 2147483648); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013376036700); - assert(hdr.sb.st_atime == 1542999264); - assert(hdr.sb.st_ctime == 1542999260); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("user-group-largenum/gnu.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 0x80000000); - assert(hdr.sb.st_gid == 0x80000000); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013376036700); - assert(hdr.sb.st_atime == 013376036700); - assert(hdr.sb.st_ctime == 013376036700); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - return EXIT_SUCCESS; -} diff --git a/tests/tar_long_paths.c b/tests/tar_long_paths.c deleted file mode 100644 index a19a235..0000000 --- a/tests/tar_long_paths.c +++ /dev/null @@ -1,94 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "util.h" -#include "tar.h" - -#include -#include -#include -#include -#include -#include - -#define STR(x) #x -#define STRVALUE(x) STR(x) - -#define TEST_PATH STRVALUE(TESTPATH) - -static int open_read(const char *path) -{ - int fd = open(path, O_RDONLY); - - if (fd < 0) { - perror(path); - exit(EXIT_FAILURE); - } - - return fd; -} - -static const char *filename = -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/012345678901234567890123456789/" -"012345678901234567890123456789/input.txt"; - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - int fd; - - assert(chdir(TEST_PATH) == 0); - - fd = open_read("long-paths/pax.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542909670); - assert(hdr.sb.st_atime == 1542909708); - assert(hdr.sb.st_ctime == 1542909670); - assert(strcmp(hdr.name, filename) == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("long-paths/ustar.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542909670); - assert(hdr.sb.st_atime == 1542909670); - assert(hdr.sb.st_ctime == 1542909670); - assert(strcmp(hdr.name, filename) == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("long-paths/gnu.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542909670); - assert(hdr.sb.st_atime == 1542909670); - assert(hdr.sb.st_ctime == 1542909670); - assert(strcmp(hdr.name, filename) == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - return EXIT_SUCCESS; -} diff --git a/tests/tar_mtime.c b/tests/tar_mtime.c deleted file mode 100644 index b255656..0000000 --- a/tests/tar_mtime.c +++ /dev/null @@ -1,123 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include "util.h" -#include "tar.h" - -#include -#include -#include -#include -#include -#include - -#define STR(x) #x -#define STRVALUE(x) STR(x) - -#define TEST_PATH STRVALUE(TESTPATH) - -static int open_read(const char *path) -{ - int fd = open(path, O_RDONLY); - - if (fd < 0) { - perror(path); - exit(EXIT_FAILURE); - } - - return fd; -} - -int main(void) -{ - tar_header_decoded_t hdr; - char buffer[6]; - int fd; - - assert(chdir(TEST_PATH) == 0); - - fd = open_read("large-mtime/12-digit.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 8589934592); - assert(hdr.sb.st_atime == 8589934592); - assert(hdr.sb.st_ctime == 8589934592); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("large-mtime/gnu.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 8589934592); - assert(hdr.sb.st_atime == 8589934592); - assert(hdr.sb.st_ctime == 8589934592); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("large-mtime/pax.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 8589934592); - assert(hdr.sb.st_atime == 1543015522); - assert(hdr.sb.st_ctime == 1543015033); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("negative-mtime/pax.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == -315622800); - assert(hdr.sb.st_atime == -315622800); - assert(hdr.sb.st_ctime == 1543015908); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - fd = open_read("negative-mtime/gnu.tar"); - assert(read_header(fd, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == -315622800); - assert(hdr.sb.st_atime == -315622800); - assert(hdr.sb.st_ctime == -315622800); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry(fd, buffer, 5) == 5); - buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); - clear_header(&hdr); - close(fd); - - return EXIT_SUCCESS; -} diff --git a/tests/tar_pax.c b/tests/tar_pax.c new file mode 100644 index 0000000..6ecc361 --- /dev/null +++ b/tests/tar_pax.c @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "util.h" +#include "tar.h" + +#include +#include +#include +#include +#include +#include + +#define STR(x) #x +#define STRVALUE(x) STR(x) + +#define TEST_PATH STRVALUE(TESTPATH) + +static int open_read(const char *path) +{ + int fd = open(path, O_RDONLY); + + if (fd < 0) { + perror(path); + exit(EXIT_FAILURE); + } + + return fd; +} + +static const char *filename = +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/input.txt"; + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + int fd; + + assert(chdir(TEST_PATH) == 0); + + fd = open_read("format-acceptance/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.sb.st_atime == 1542905911); + assert(hdr.sb.st_ctime == 1542905892); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("file-size/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 8589934592); + assert(hdr.sb.st_mtime == 1542959190); + assert(hdr.sb.st_atime == 1542959522); + assert(hdr.sb.st_ctime == 1542959190); + assert(strcmp(hdr.name, "big-file.bin") == 0); + assert(!hdr.unknown_record); + clear_header(&hdr); + close(fd); + + fd = open_read("user-group-largenum/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 2147483648); + assert(hdr.sb.st_gid == 2147483648); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 013376036700); + assert(hdr.sb.st_atime == 1542999264); + assert(hdr.sb.st_ctime == 1542999260); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("large-mtime/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 8589934592); + assert(hdr.sb.st_atime == 1543015522); + assert(hdr.sb.st_ctime == 1543015033); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("negative-mtime/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == -315622800); + assert(hdr.sb.st_atime == -315622800); + assert(hdr.sb.st_ctime == 1543015908); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("long-paths/pax.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542909670); + assert(hdr.sb.st_atime == 1542909708); + assert(hdr.sb.st_ctime == 1542909670); + assert(strcmp(hdr.name, filename) == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + return EXIT_SUCCESS; +} diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c new file mode 100644 index 0000000..acd7097 --- /dev/null +++ b/tests/tar_ustar.c @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "util.h" +#include "tar.h" + +#include +#include +#include +#include +#include +#include + +#define STR(x) #x +#define STRVALUE(x) STR(x) + +#define TEST_PATH STRVALUE(TESTPATH) + +static int open_read(const char *path) +{ + int fd = open(path, O_RDONLY); + + if (fd < 0) { + perror(path); + exit(EXIT_FAILURE); + } + + return fd; +} + +static const char *filename = +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/012345678901234567890123456789/" +"012345678901234567890123456789/input.txt"; + +int main(void) +{ + tar_header_decoded_t hdr; + char buffer[6]; + int fd; + + assert(chdir(TEST_PATH) == 0); + + fd = open_read("format-acceptance/ustar.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.sb.st_atime == 1542905892); + assert(hdr.sb.st_ctime == 1542905892); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("format-acceptance/ustar-pre-posix.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.sb.st_atime == 1542905892); + assert(hdr.sb.st_ctime == 1542905892); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("format-acceptance/v7.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.sb.st_atime == 1542905892); + assert(hdr.sb.st_ctime == 1542905892); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("file-size/12-digit.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 8589934592); + assert(hdr.sb.st_mtime == 013375730126); + assert(hdr.sb.st_atime == 013375730126); + assert(hdr.sb.st_ctime == 013375730126); + assert(strcmp(hdr.name, "big-file.bin") == 0); + assert(!hdr.unknown_record); + clear_header(&hdr); + close(fd); + + fd = open_read("user-group-largenum/8-digit.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 8388608); + assert(hdr.sb.st_gid == 8388608); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 013376036700); + assert(hdr.sb.st_atime == 013376036700); + assert(hdr.sb.st_ctime == 013376036700); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("large-mtime/12-digit.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 8589934592); + assert(hdr.sb.st_atime == 8589934592); + assert(hdr.sb.st_ctime == 8589934592); + assert(strcmp(hdr.name, "input.txt") == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + fd = open_read("long-paths/ustar.tar"); + assert(read_header(fd, &hdr) == 0); + assert(hdr.sb.st_mode == (S_IFREG | 0644)); + assert(hdr.sb.st_uid == 01750); + assert(hdr.sb.st_gid == 01750); + assert(hdr.sb.st_size == 5); + assert(hdr.sb.st_mtime == 1542909670); + assert(hdr.sb.st_atime == 1542909670); + assert(hdr.sb.st_ctime == 1542909670); + assert(strcmp(hdr.name, filename) == 0); + assert(!hdr.unknown_record); + assert(read_retry(fd, buffer, 5) == 5); + buffer[5] = '\0'; + assert(strcmp(buffer, "test\n") == 0); + clear_header(&hdr); + close(fd); + + return EXIT_SUCCESS; +} -- cgit v1.2.3