diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2021-03-05 15:53:21 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2021-03-06 22:08:36 +0100 |
commit | b950412ca3a91aa37349cf51ebe98cc84767d448 (patch) | |
tree | e3bb062114d019984321a5a21b29818c88c36795 /tests/libtar | |
parent | 3fc6bf24b5cc071fc323f08ece541e37578f6369 (diff) |
Cleanup: add some structure to the test directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libtar')
41 files changed, 722 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 0000000..a6b3553 --- /dev/null +++ b/tests/libtar/data/file-size/12-digit.tar diff --git a/tests/libtar/data/file-size/gnu.tar b/tests/libtar/data/file-size/gnu.tar Binary files differnew file mode 100644 index 0000000..aad726f --- /dev/null +++ b/tests/libtar/data/file-size/gnu.tar diff --git a/tests/libtar/data/file-size/pax.tar b/tests/libtar/data/file-size/pax.tar Binary files differnew file mode 100644 index 0000000..e391fee --- /dev/null +++ b/tests/libtar/data/file-size/pax.tar diff --git a/tests/libtar/data/format-acceptance/gnu-g.tar b/tests/libtar/data/format-acceptance/gnu-g.tar Binary files differnew file mode 100644 index 0000000..a72f60d --- /dev/null +++ b/tests/libtar/data/format-acceptance/gnu-g.tar diff --git a/tests/libtar/data/format-acceptance/gnu.tar b/tests/libtar/data/format-acceptance/gnu.tar Binary files differnew file mode 100644 index 0000000..98e8157 --- /dev/null +++ b/tests/libtar/data/format-acceptance/gnu.tar diff --git a/tests/libtar/data/format-acceptance/link_filled.tar b/tests/libtar/data/format-acceptance/link_filled.tar Binary files differnew file mode 100644 index 0000000..9b80f89 --- /dev/null +++ b/tests/libtar/data/format-acceptance/link_filled.tar diff --git a/tests/libtar/data/format-acceptance/pax.tar b/tests/libtar/data/format-acceptance/pax.tar Binary files differnew file mode 100644 index 0000000..69a029f --- /dev/null +++ b/tests/libtar/data/format-acceptance/pax.tar diff --git a/tests/libtar/data/format-acceptance/ustar-pre-posix.tar b/tests/libtar/data/format-acceptance/ustar-pre-posix.tar Binary files differnew file mode 100644 index 0000000..4230f5f --- /dev/null +++ b/tests/libtar/data/format-acceptance/ustar-pre-posix.tar diff --git a/tests/libtar/data/format-acceptance/ustar.tar b/tests/libtar/data/format-acceptance/ustar.tar Binary files differnew file mode 100644 index 0000000..9a6d9b3 --- /dev/null +++ b/tests/libtar/data/format-acceptance/ustar.tar diff --git a/tests/libtar/data/format-acceptance/v7.tar b/tests/libtar/data/format-acceptance/v7.tar Binary files differnew file mode 100644 index 0000000..5483b4b --- /dev/null +++ b/tests/libtar/data/format-acceptance/v7.tar diff --git a/tests/libtar/data/large-mtime/12-digit.tar b/tests/libtar/data/large-mtime/12-digit.tar Binary files differnew file mode 100644 index 0000000..8202b28 --- /dev/null +++ b/tests/libtar/data/large-mtime/12-digit.tar diff --git a/tests/libtar/data/large-mtime/gnu.tar b/tests/libtar/data/large-mtime/gnu.tar Binary files differnew file mode 100644 index 0000000..4e3dda2 --- /dev/null +++ b/tests/libtar/data/large-mtime/gnu.tar diff --git a/tests/libtar/data/large-mtime/pax.tar b/tests/libtar/data/large-mtime/pax.tar Binary files differnew file mode 100644 index 0000000..8d32530 --- /dev/null +++ b/tests/libtar/data/large-mtime/pax.tar diff --git a/tests/libtar/data/long-paths/gnu.tar b/tests/libtar/data/long-paths/gnu.tar Binary files differnew file mode 100644 index 0000000..4eee731 --- /dev/null +++ b/tests/libtar/data/long-paths/gnu.tar diff --git a/tests/libtar/data/long-paths/pax.tar b/tests/libtar/data/long-paths/pax.tar Binary files differnew file mode 100644 index 0000000..1e63e9c --- /dev/null +++ b/tests/libtar/data/long-paths/pax.tar diff --git a/tests/libtar/data/long-paths/ustar.tar b/tests/libtar/data/long-paths/ustar.tar Binary files differnew file mode 100644 index 0000000..812255c --- /dev/null +++ b/tests/libtar/data/long-paths/ustar.tar diff --git a/tests/libtar/data/negative-mtime/gnu.tar b/tests/libtar/data/negative-mtime/gnu.tar Binary files differnew file mode 100644 index 0000000..a9b1272 --- /dev/null +++ b/tests/libtar/data/negative-mtime/gnu.tar diff --git a/tests/libtar/data/negative-mtime/pax.tar b/tests/libtar/data/negative-mtime/pax.tar Binary files differnew file mode 100644 index 0000000..d0b3e6c --- /dev/null +++ b/tests/libtar/data/negative-mtime/pax.tar diff --git a/tests/libtar/data/sparse-files/gnu-small.tar b/tests/libtar/data/sparse-files/gnu-small.tar Binary files differnew file mode 100644 index 0000000..7a1b222 --- /dev/null +++ b/tests/libtar/data/sparse-files/gnu-small.tar diff --git a/tests/libtar/data/sparse-files/gnu.tar b/tests/libtar/data/sparse-files/gnu.tar Binary files differnew file mode 100644 index 0000000..3d641a2 --- /dev/null +++ b/tests/libtar/data/sparse-files/gnu.tar diff --git a/tests/libtar/data/sparse-files/pax-gnu0-0.tar b/tests/libtar/data/sparse-files/pax-gnu0-0.tar Binary files differnew file mode 100644 index 0000000..628f09e --- /dev/null +++ b/tests/libtar/data/sparse-files/pax-gnu0-0.tar diff --git a/tests/libtar/data/sparse-files/pax-gnu0-1.tar b/tests/libtar/data/sparse-files/pax-gnu0-1.tar Binary files differnew file mode 100644 index 0000000..87e362e --- /dev/null +++ b/tests/libtar/data/sparse-files/pax-gnu0-1.tar diff --git a/tests/libtar/data/sparse-files/pax-gnu1-0.tar b/tests/libtar/data/sparse-files/pax-gnu1-0.tar Binary files differnew file mode 100644 index 0000000..edb0ccf --- /dev/null +++ b/tests/libtar/data/sparse-files/pax-gnu1-0.tar 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 Binary files differnew file mode 100644 index 0000000..a48ea5d --- /dev/null +++ b/tests/libtar/data/user-group-largenum/8-digit.tar diff --git a/tests/libtar/data/user-group-largenum/gnu.tar b/tests/libtar/data/user-group-largenum/gnu.tar Binary files differnew file mode 100644 index 0000000..4c30f57 --- /dev/null +++ b/tests/libtar/data/user-group-largenum/gnu.tar diff --git a/tests/libtar/data/user-group-largenum/pax.tar b/tests/libtar/data/user-group-largenum/pax.tar Binary files differnew file mode 100644 index 0000000..a9fe54c --- /dev/null +++ b/tests/libtar/data/user-group-largenum/pax.tar diff --git a/tests/libtar/data/xattr/acl.tar b/tests/libtar/data/xattr/acl.tar Binary files differnew file mode 100644 index 0000000..a65c0af --- /dev/null +++ b/tests/libtar/data/xattr/acl.tar diff --git a/tests/libtar/data/xattr/xattr-libarchive.tar b/tests/libtar/data/xattr/xattr-libarchive.tar Binary files differnew file mode 100644 index 0000000..3bd6125 --- /dev/null +++ b/tests/libtar/data/xattr/xattr-libarchive.tar diff --git a/tests/libtar/data/xattr/xattr-schily-binary.tar b/tests/libtar/data/xattr/xattr-schily-binary.tar Binary files differnew file mode 100644 index 0000000..0312807 --- /dev/null +++ b/tests/libtar/data/xattr/xattr-schily-binary.tar diff --git a/tests/libtar/data/xattr/xattr-schily.tar b/tests/libtar/data/xattr/xattr-schily.tar Binary files differnew file mode 100644 index 0000000..1cf525c --- /dev/null +++ b/tests/libtar/data/xattr/xattr-schily.tar 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 <goliath@infraroot.at> + */ +#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 <goliath@infraroot.at> + */ +#include "config.h" + +#include "tar.h" + +#include <stdlib.h> +#include <stdio.h> + +int main(int argc, char **argv) +{ + tar_header_decoded_t hdr; + istream_t *fp; + int ret; + + if (argc != 2) { + fputs("usage: tar_fuzz <tarball>\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 <goliath@infraroot.at> + */ +#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 <goliath@infraroot.at> + */ +#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 <goliath@infraroot.at> + */ +#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 <goliath@infraroot.at> + */ +#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 <goliath@infraroot.at> + */ +#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 <goliath@infraroot.at> + */ +#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; +} |