summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am8
-rw-r--r--tests/tar_sparse_gnu1.c100
2 files changed, 107 insertions, 1 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 004f83c..f9232dc 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -50,16 +50,22 @@ test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c
test_tar_sparse_gnu_LDADD = libtar.a libutil.a
test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
+test_tar_sparse_gnu1_SOURCES = tests/tar_sparse_gnu1.c
+test_tar_sparse_gnu1_LDADD = libtar.a libutil.a
+test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS)
+test_tar_sparse_gnu1_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_ustar test_tar_pax test_tar_gnu test_tar_sparse_gnu
+check_PROGRAMS += test_tar_sparse_gnu1
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_ustar test_tar_pax
-TESTS += test_tar_gnu test_tar_sparse_gnu
+TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1
EXTRA_DIST += $(top_srcdir)/tests/tar
diff --git a/tests/tar_sparse_gnu1.c b/tests/tar_sparse_gnu1.c
new file mode 100644
index 0000000..fac23f1
--- /dev/null
+++ b/tests/tar_sparse_gnu1.c
@@ -0,0 +1,100 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "util.h"
+#include "tar.h"
+
+#include <unistd.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+#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;
+ sparse_map_t *sparse;
+ int fd;
+
+ assert(chdir(TEST_PATH) == 0);
+
+ fd = open_read("sparse-files/pax-gnu0-0.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 == 2097152);
+ assert(hdr.actual_size == 2097152);
+ assert(hdr.record_size == 32768);
+ assert(strcmp(hdr.name, "input.bin") == 0);
+ assert(!hdr.unknown_record);
+
+ sparse = hdr.sparse;
+ assert(sparse != NULL);
+ assert(sparse->offset == 0);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 262144);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 524288);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 786432);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 1048576);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 1310720);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 1572864);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 1835008);
+ assert(sparse->count == 4096);
+
+ sparse = sparse->next;
+ assert(sparse != NULL);
+ assert(sparse->offset == 2097152);
+ assert(sparse->count == 0);
+
+ sparse = sparse->next;
+ assert(sparse == NULL);
+
+ clear_header(&hdr);
+ close(fd);
+
+ return EXIT_SUCCESS;
+}