summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/cpio/test/test_basic.c
diff options
context:
space:
mode:
Diffstat (limited to 'archivers/libarchive/files/cpio/test/test_basic.c')
-rw-r--r--archivers/libarchive/files/cpio/test/test_basic.c110
1 files changed, 77 insertions, 33 deletions
diff --git a/archivers/libarchive/files/cpio/test/test_basic.c b/archivers/libarchive/files/cpio/test/test_basic.c
index 449d90e67b9..7f1fe6de9f7 100644
--- a/archivers/libarchive/files/cpio/test/test_basic.c
+++ b/archivers/libarchive/files/cpio/test/test_basic.c
@@ -25,37 +25,13 @@
#include "test.h"
__FBSDID("$FreeBSD$");
-
static void
-basic_cpio(const char *target, const char *pack_options, const char *unpack_options)
+verify_files(const char *target)
{
struct stat st, st2;
char buff[128];
int r;
- assertEqualInt(0, mkdir(target, 0775));
-
- /* Use the cpio program to create an archive. */
- r = systemf("%s -o --quiet %s < filelist >%s/archive 2>%s/pack.err", testprog, pack_options, target, target);
- failure("Error invoking %s -o --quiet %s", testprog, pack_options);
- assertEqualInt(r, 0);
-
- chdir(target);
-
- /* Verify that nothing went to stderr. */
- assertEmptyFile("pack.err");
-
- /*
- * Use cpio to unpack the archive into another directory.
- */
- r = systemf("%s -i --quiet %s< archive >unpack.out 2>unpack.err", testprog, unpack_options);
- failure("Error invoking %s -i %s", testprog, unpack_options);
- assertEqualInt(r, 0);
-
- /* Verify stderr. */
- failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target);
- assertEmptyFile("unpack.err");
-
/*
* Verify unpacked files.
*/
@@ -68,7 +44,7 @@ basic_cpio(const char *target, const char *pack_options, const char *unpack_opti
assert(S_ISREG(st.st_mode));
assertEqualInt(0644, st.st_mode & 0777);
assertEqualInt(10, st.st_size);
- failure("file %s/file", target);
+ failure("file %s/file should have 2 links", target);
assertEqualInt(2, st.st_nlink);
}
@@ -80,11 +56,12 @@ basic_cpio(const char *target, const char *pack_options, const char *unpack_opti
assert(S_ISREG(st2.st_mode));
assertEqualInt(0644, st2.st_mode & 0777);
assertEqualInt(10, st2.st_size);
- failure("file %s/linkfile", target);
+ failure("file %s/linkfile should have 2 links", target);
assertEqualInt(2, st2.st_nlink);
/* Verify that the two are really hardlinked. */
assertEqualInt(st.st_dev, st2.st_dev);
- failure("%s/linkfile and %s/file aren't really hardlinks", target, target);
+ failure("%s/linkfile and %s/file should be hardlinked",
+ target, target);
assertEqualInt(st.st_ino, st2.st_ino);
}
@@ -111,7 +88,72 @@ basic_cpio(const char *target, const char *pack_options, const char *unpack_opti
assert(S_ISDIR(st.st_mode));
assertEqualInt(0775, st.st_mode & 0777);
}
+}
+
+static void
+basic_cpio(const char *target,
+ const char *pack_options,
+ const char *unpack_options,
+ const char *se)
+{
+ int r;
+
+ if (!assertEqualInt(0, mkdir(target, 0775)))
+ return;
+
+ /* Use the cpio program to create an archive. */
+ r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err",
+ testprog, pack_options, target, target);
+ failure("Error invoking %s -o %s", testprog, pack_options);
+ assertEqualInt(r, 0);
+
+ chdir(target);
+
+ /* Verify stderr. */
+ failure("Expected: %s, options=%s", se, pack_options);
+ assertFileContents(se, strlen(se), "pack.err");
+
+ /*
+ * Use cpio to unpack the archive into another directory.
+ */
+ r = systemf("%s -i %s< archive >unpack.out 2>unpack.err",
+ testprog, unpack_options);
+ failure("Error invoking %s -i %s", testprog, unpack_options);
+ assertEqualInt(r, 0);
+
+ /* Verify stderr. */
+ failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target);
+ assertFileContents(se, strlen(se), "unpack.err");
+
+ verify_files(target);
+
+ chdir("..");
+}
+
+static void
+passthrough(const char *target)
+{
+ int r;
+
+ if (!assertEqualInt(0, mkdir(target, 0775)))
+ return;
+
+ /*
+ * Use cpio passthrough mode to copy files to another directory.
+ */
+ r = systemf("%s -p -W quiet %s <filelist >%s/stdout 2>%s/stderr",
+ testprog, target, target, target);
+ failure("Error invoking %s -p", testprog);
+ assertEqualInt(r, 0);
+
+ chdir(target);
+
+ /* Verify stderr. */
+ failure("Error invoking %s -p in dir %s",
+ testprog, target);
+ assertEmptyFile("stderr");
+ verify_files(target);
chdir("..");
}
@@ -150,11 +192,13 @@ DEFINE_TEST(test_basic)
close(filelist);
/* Archive/dearchive with a variety of options. */
- basic_cpio("copy", "", "");
- basic_cpio("copy_odc", "--format=odc", "");
- basic_cpio("copy_newc", "-H newc", "");
- basic_cpio("copy_cpio", "-H odc", "");
- basic_cpio("copy_ustar", "-H ustar", "");
+ basic_cpio("copy", "", "", "1 block\n");
+ basic_cpio("copy_odc", "--format=odc", "", "1 block\n");
+ basic_cpio("copy_newc", "-H newc", "", "2 blocks\n");
+ basic_cpio("copy_cpio", "-H odc", "", "1 block\n");
+ basic_cpio("copy_ustar", "-H ustar", "", "7 blocks\n");
+ /* Copy in one step using -p */
+ passthrough("passthrough");
umask(oldumask);
}