diff options
Diffstat (limited to 'archivers/libarchive/files/cpio')
16 files changed, 361 insertions, 191 deletions
diff --git a/archivers/libarchive/files/cpio/cpio.c b/archivers/libarchive/files/cpio/cpio.c index 0a0771bbaef..1d78ce1266f 100644 --- a/archivers/libarchive/files/cpio/cpio.c +++ b/archivers/libarchive/files/cpio/cpio.c @@ -70,7 +70,7 @@ static void mode_pass(struct cpio *, const char *); static void restore_time(struct cpio *, struct archive_entry *, const char *, int fd); static void usage(void); -static void version(FILE *); +static void version(void); int main(int argc, char *argv[]) @@ -204,7 +204,7 @@ main(int argc, char *argv[]) cpio->verbose++; break; case OPTION_VERSION: /* GNU convention */ - version(stdout); + version(); break; #if 0 /* @@ -326,16 +326,16 @@ long_help(void) } else putchar(*p); } - version(stdout); + version(); } static void -version(FILE *out) +version(void) { - fprintf(out,"bsdcpio %s -- %s\n", + fprintf(stdout,"bsdcpio %s -- %s\n", BSDCPIO_VERSION_STRING, archive_version()); - exit(1); + exit(0); } static void @@ -412,7 +412,10 @@ static int file_to_archive(struct cpio *cpio, const char *srcpath) { struct stat st; + const char *destpath; struct archive_entry *entry, *spare; + size_t len; + const char *p; int lnklen; int r; @@ -422,7 +425,7 @@ file_to_archive(struct cpio *cpio, const char *srcpath) entry = archive_entry_new(); if (entry == NULL) cpio_errc(1, 0, "Couldn't allocate entry"); - archive_entry_set_pathname(entry, srcpath); + archive_entry_copy_sourcepath(entry, srcpath); /* Get stat information. */ if (cpio->option_follow_links) @@ -455,45 +458,11 @@ file_to_archive(struct cpio *cpio, const char *srcpath) } /* - * If we're trying to preserve hardlinks, match them here. + * Generate a destination path for this entry. + * "destination path" is the name to which it will be copied in + * pass mode or the name that will go into the archive in + * output mode. */ - spare = NULL; - if (cpio->linkresolver != NULL - && !S_ISDIR(st.st_mode)) { - archive_entry_linkify(cpio->linkresolver, &entry, &spare); - } - - if (entry != NULL) { - r = entry_to_archive(cpio, entry); - archive_entry_free(entry); - } - if (spare != NULL) { - if (r == 0) - r = entry_to_archive(cpio, spare); - archive_entry_free(spare); - } - return (r); -} - -static int -entry_to_archive(struct cpio *cpio, struct archive_entry *entry) -{ - const char *destpath; - char *srcpath; - int fd = -1; - ssize_t bytes_read; - size_t len; - const char *p; - int r; - - /* - * Generate a target path for this entry. - */ - p = archive_entry_pathname(entry); - srcpath = malloc(strlen(p) + 1); - if (srcpath == NULL) - cpio_errc(1, ENOMEM, "Can't allocate path buffer"); - strcpy(srcpath, p); destpath = srcpath; if (cpio->destdir) { len = strlen(cpio->destdir) + strlen(srcpath) + 8; @@ -517,12 +486,40 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry) } if (cpio->option_rename) destpath = cpio_rename(destpath); - if (destpath == NULL) { - free(srcpath); + if (destpath == NULL) return (0); - } archive_entry_copy_pathname(entry, destpath); + /* + * If we're trying to preserve hardlinks, match them here. + */ + spare = NULL; + if (cpio->linkresolver != NULL + && !S_ISDIR(st.st_mode)) { + archive_entry_linkify(cpio->linkresolver, &entry, &spare); + } + + if (entry != NULL) { + r = entry_to_archive(cpio, entry); + archive_entry_free(entry); + } + if (spare != NULL) { + if (r == 0) + r = entry_to_archive(cpio, spare); + archive_entry_free(spare); + } + return (r); +} + +static int +entry_to_archive(struct cpio *cpio, struct archive_entry *entry) +{ + const char *destpath = archive_entry_pathname(entry); + const char *srcpath = archive_entry_sourcepath(entry); + int fd = -1; + ssize_t bytes_read; + int r; + /* Print out the destination name to the user. */ if (cpio->verbose) fprintf(stderr,"%s", destpath); @@ -539,7 +536,6 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry) archive_error_string(cpio->archive)); if (r == ARCHIVE_FATAL) exit(1); - free(srcpath); return (0); } @@ -594,7 +590,6 @@ cleanup: fprintf(stderr,"\n"); if (fd >= 0) close(fd); - free(srcpath); return (0); } diff --git a/archivers/libarchive/files/cpio/test/list.h b/archivers/libarchive/files/cpio/test/list.h index 9b0197cd50f..42cc5588218 100644 --- a/archivers/libarchive/files/cpio/test/list.h +++ b/archivers/libarchive/files/cpio/test/list.h @@ -1,3 +1,4 @@ +DEFINE_TEST(test_0) DEFINE_TEST(test_basic) DEFINE_TEST(test_format_newc) DEFINE_TEST(test_gcpio_compat) diff --git a/archivers/libarchive/files/cpio/test/main.c b/archivers/libarchive/files/cpio/test/main.c index f06f75a918c..c88dd2ac341 100644 --- a/archivers/libarchive/files/cpio/test/main.c +++ b/archivers/libarchive/files/cpio/test/main.c @@ -64,10 +64,14 @@ extern char *optarg; extern int optind; #endif -/* Default is to crash and try to force a core dump on failure. */ -static int dump_on_failure = 1; +/* Enable core dump on failure. */ +static int dump_on_failure = 0; +/* Default is to remove temp dirs for successful tests. */ +static int keep_temp_files = 0; /* Default is to print some basic information about each test. */ static int quiet_flag = 0; +/* Default is to summarize repeated failures. */ +static int verbose = 0; /* Cumulative count of component failures. */ static int failures = 0; /* Cumulative count of skipped component tests. */ @@ -243,7 +247,7 @@ test_assert(const char *file, int line, int value, const char *condition, void * return (value); } failures ++; - if (previous_failures(file, line)) + if (!verbose && previous_failures(file, line)) return (value); fprintf(stderr, "%s:%d: Assertion failed\n", file, line); fprintf(stderr, " Condition: %s\n", condition); @@ -262,7 +266,7 @@ test_assert_equal_int(const char *file, int line, return (1); } failures ++; - if (previous_failures(file, line)) + if (!verbose && previous_failures(file, line)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n", file, line); @@ -314,16 +318,16 @@ test_assert_equal_string(const char *file, int line, return (1); } failures ++; - if (previous_failures(file, line)) + if (!verbose && previous_failures(file, line)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n", file, line); fprintf(stderr, " %s = ", e1); strdump(v1); - fprintf(stderr, "\n"); + fprintf(stderr, " (length %d)\n", v1 == NULL ? 0 : strlen(v1)); fprintf(stderr, " %s = ", e2); strdump(v2); - fprintf(stderr, "\n"); + fprintf(stderr, " (length %d)\n", v2 == NULL ? 0 : strlen(v2)); report_failure(extra); return (0); } @@ -372,7 +376,7 @@ test_assert_equal_wstring(const char *file, int line, return (1); } failures ++; - if (previous_failures(file, line)) + if (!verbose && previous_failures(file, line)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n", file, line); @@ -442,7 +446,7 @@ test_assert_equal_mem(const char *file, int line, return (1); } failures ++; - if (previous_failures(file, line)) + if (!verbose && previous_failures(file, line)) return (0); fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n", file, line); @@ -474,12 +478,13 @@ test_assert_empty_file(const char *f1fmt, ...) if (stat(f1, &st) != 0) { fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1); report_failure(NULL); + return (0); } if (st.st_size == 0) return (1); failures ++; - if (previous_failures(test_filename, test_line)) + if (!verbose && previous_failures(test_filename, test_line)) return (0); fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1); @@ -526,7 +531,7 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...) break; } failures ++; - if (previous_failures(test_filename, test_line)) + if (!verbose && previous_failures(test_filename, test_line)) return (0); fprintf(stderr, "%s:%d: Files are not identical\n", test_filename, test_line); @@ -697,6 +702,12 @@ static int test_run(int i, const char *tmpdir) (*tests[i].func)(); /* Summarize the results of this test. */ summarize(); + /* If there were no failures, we can remove the work dir. */ + if (failures == failures_before) { + if (!keep_temp_files && chdir(tmpdir) == 0) { + systemf("rm -rf %s", tests[i].name); + } + } /* Return appropriate status. */ return (failures == failures_before ? 0 : 1); } @@ -710,8 +721,9 @@ static void usage(const char *program) printf("Default is to run all tests.\n"); printf("Otherwise, specify the numbers of the tests you wish to run.\n"); printf("Options:\n"); - printf(" -k Keep running after failures.\n"); - printf(" Default: Core dump after any failure.\n"); + printf(" -d Dump core after any failure, for debugging.\n"); + printf(" -k Keep all temp files.\n"); + printf(" Default: temp files for successful tests deleted.\n"); #ifdef PROGRAM printf(" -p <path> Path to executable to be tested.\n"); printf(" Default: path taken from " ENVBASE " environment variable.\n"); @@ -719,6 +731,7 @@ static void usage(const char *program) printf(" -q Quiet.\n"); printf(" -r <dir> Path to dir containing reference files.\n"); printf(" Default: Current directory.\n"); + printf(" -v Verbose.\n"); printf("Available tests:\n"); for (i = 0; i < limit; i++) printf(" %d: %s\n", i, tests[i].name); @@ -811,9 +824,9 @@ int main(int argc, char **argv) testprog = getenv(ENVBASE); #endif - /* Allow -k to be controlled through the environment. */ - if (getenv(ENVBASE "_KEEP_GOING") != NULL) - dump_on_failure = 0; + /* Allow -d to be controlled through the environment. */ + if (getenv(ENVBASE "_DEBUG") != NULL) + dump_on_failure = 1; /* Get the directory holding test files from environment. */ refdir = getenv(ENVBASE "_TEST_FILES"); @@ -821,10 +834,13 @@ int main(int argc, char **argv) /* * Parse options. */ - while ((opt = getopt(argc, argv, "kp:qr:")) != -1) { + while ((opt = getopt(argc, argv, "dkp:qr:v")) != -1) { switch (opt) { + case 'd': + dump_on_failure = 1; + break; case 'k': - dump_on_failure = 0; + keep_temp_files = 1; break; case 'p': #ifdef PROGRAM @@ -839,6 +855,9 @@ int main(int argc, char **argv) case 'r': refdir = optarg; break; + case 'v': + verbose = 1; + break; case '?': default: usage(progname); @@ -887,6 +906,7 @@ int main(int argc, char **argv) --p; *p = '\0'; } + systemf("rm %s/refdir", tmpdir); } /* @@ -942,5 +962,9 @@ int main(int argc, char **argv) free(refdir_alloc); + /* If the final tmpdir is empty, we can remove it. */ + /* This should be the usual case when all tests succeed. */ + rmdir(tmpdir); + return (tests_failed); } diff --git a/archivers/libarchive/files/cpio/test/test_0.c b/archivers/libarchive/files/cpio/test/test_0.c new file mode 100644 index 00000000000..7a72af1c8ed --- /dev/null +++ b/archivers/libarchive/files/cpio/test/test_0.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * This first test does basic sanity checks on the environment. For + * most of these, we just exit on failure. + */ + +DEFINE_TEST(test_0) +{ + struct stat st; + + failure("File %s does not exist?!", testprog); + if (!assertEqualInt(0, stat(testprog, &st))) + exit(1); + + failure("%s is not executable?!", testprog); + if (!assert((st.st_mode & 0111) != 0)) + exit(1); + + /* + * Try to succesfully run the program; this requires that + * we know some option that will succeed. + */ + if (0 == systemf("%s --version >/dev/null", testprog)) { + /* This worked. */ + } else if (0 == systemf("%s -W version >/dev/null", testprog)) { + /* This worked. */ + } else { + failure("Unable to successfully run any of the following:\n" + " * %s --version\n" + " * %s -W version\n", + testprog, testprog); + assert(0); + } + + /* TODO: Ensure that our reference files are available. */ +} 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); } diff --git a/archivers/libarchive/files/cpio/test/test_format_newc.c b/archivers/libarchive/files/cpio/test/test_format_newc.c index 68cc193cf2a..0714bd427e2 100644 --- a/archivers/libarchive/files/cpio/test/test_format_newc.c +++ b/archivers/libarchive/files/cpio/test/test_format_newc.c @@ -66,7 +66,7 @@ DEFINE_TEST(test_format_newc) int fd, list; int r; int devmajor, devminor, ino, gid; - time_t t, now; + time_t t, t2, now; char *p, *e; size_t s; mode_t oldmask; @@ -106,13 +106,13 @@ DEFINE_TEST(test_format_newc) /* Use the cpio program to create an archive. */ close(list); - r = systemf("%s -o --format=newc --quiet <list >newc.out 2>newc.err", + r = systemf("%s -o --format=newc <list >newc.out 2>newc.err", testprog); if (!assertEqualInt(r, 0)) return; /* Verify that nothing went to stderr. */ - assertEmptyFile("newc.err"); + assertFileContents("2 blocks\n", 9, "newc.err"); /* Verify that stdout is a well-formed cpio file in "newc" format. */ p = slurpfile(&s, "newc.out"); @@ -159,7 +159,9 @@ DEFINE_TEST(test_format_newc) assertEqualInt(from_hex(e + 22, 8), getuid()); /* uid */ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualInt(t, from_hex(e + 46, 8)); /* mtime */ + t2 = from_hex(e + 46, 8); /* mtime */ + failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualMem(e + 54, "00000005", 8); /* File size */ assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ @@ -179,7 +181,9 @@ DEFINE_TEST(test_format_newc) assertEqualInt(from_hex(e + 22, 8), getuid()); /* uid */ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ assertEqualMem(e + 38, "00000002", 8); /* nlink */ - assertEqualInt(t, from_hex(e + 46, 8)); /* mtime */ + t2 = from_hex(e + 46, 8); /* mtime */ + failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualMem(e + 54, "00000000", 8); /* File size */ assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ @@ -203,7 +207,9 @@ DEFINE_TEST(test_format_newc) assertEqualInt(from_hex(e + 22, 8), getuid()); /* uid */ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ assertEqualMem(e + 38, "00000003", 8); /* nlink */ - assertEqualInt(t, from_hex(e + 46, 8)); /* mtime */ + t2 = from_hex(e + 46, 8); /* mtime */ + failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualInt(10, from_hex(e + 54, 8)); /* File size */ assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ diff --git a/archivers/libarchive/files/cpio/test/test_gcpio_compat.c b/archivers/libarchive/files/cpio/test/test_gcpio_compat.c index 61c9878b11e..4c69abb6368 100644 --- a/archivers/libarchive/files/cpio/test/test_gcpio_compat.c +++ b/archivers/libarchive/files/cpio/test/test_gcpio_compat.c @@ -27,7 +27,7 @@ __FBSDID("$FreeBSD$"); static void -unpack_test(const char *from, const char *options) +unpack_test(const char *from, const char *options, const char *se) { struct stat st, st2; char buff[128]; @@ -41,14 +41,14 @@ unpack_test(const char *from, const char *options) * Use cpio to unpack the sample archive */ extract_reference_file(from); - r = systemf("%s -i --quiet %s < %s >unpack.out 2>unpack.err", + r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", testprog, options, from); - failure("Error invoking %s -i --quiet %s < %s", + failure("Error invoking %s -i %s < %s", testprog, options, from); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ - assertEmptyFile("unpack.err"); + assertFileContents(se, strlen(se), "unpack.err"); /* * Verify unpacked files. @@ -118,10 +118,10 @@ DEFINE_TEST(test_gcpio_compat) oldumask = umask(0); /* Dearchive sample files with a variety of options. */ - unpack_test("test_gcpio_compat_ref.bin", ""); - unpack_test("test_gcpio_compat_ref.crc", ""); - unpack_test("test_gcpio_compat_ref.newc", ""); - unpack_test("test_gcpio_compat_ref.ustar", ""); + unpack_test("test_gcpio_compat_ref.bin", "", "1 block\n"); + unpack_test("test_gcpio_compat_ref.crc", "", "2 blocks\n"); + unpack_test("test_gcpio_compat_ref.newc", "", "2 blocks\n"); + unpack_test("test_gcpio_compat_ref.ustar", "", "7 blocks\n"); umask(oldumask); } diff --git a/archivers/libarchive/files/cpio/test/test_option_B.c b/archivers/libarchive/files/cpio/test/test_option_B.c index 17533180cec..80838823f9d 100644 --- a/archivers/libarchive/files/cpio/test/test_option_B.c +++ b/archivers/libarchive/files/cpio/test/test_option_B.c @@ -39,16 +39,16 @@ DEFINE_TEST(test_option_B) close(fd); /* Create an archive without -B; this should be 512 bytes. */ - r = systemf("echo file | %s -o --quiet > small.cpio 2>small.err", testprog); + r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog); assertEqualInt(r, 0); - assertEmptyFile("small.err"); + assertFileContents("1 block\n", 8, "small.err"); assertEqualInt(0, stat("small.cpio", &st)); assertEqualInt(512, st.st_size); /* Create an archive with -B; this should be 5120 bytes. */ - r = systemf("echo file | %s -oB --quiet > large.cpio 2>large.err", testprog); + r = systemf("echo file | %s -oB > large.cpio 2>large.err", testprog); assertEqualInt(r, 0); - assertEmptyFile("large.err"); + assertFileContents("1 block\n", 8, "large.err"); assertEqualInt(0, stat("large.cpio", &st)); assertEqualInt(5120, st.st_size); } diff --git a/archivers/libarchive/files/cpio/test/test_option_L.c b/archivers/libarchive/files/cpio/test/test_option_L.c index d91c001631f..2d69ab6ec34 100644 --- a/archivers/libarchive/files/cpio/test/test_option_L.c +++ b/archivers/libarchive/files/cpio/test/test_option_L.c @@ -46,13 +46,13 @@ DEFINE_TEST(test_option_L) close(filelist); - r = systemf("cat filelist | %s -pd --quiet copy >copy.out 2>copy.err", testprog); + r = systemf("cat filelist | %s -pd copy >copy.out 2>copy.err", testprog); assertEqualInt(r, 0); assertEqualInt(0, lstat("copy/symlink", &st)); failure("Regular -p without -L should preserve symlinks."); assert(S_ISLNK(st.st_mode)); - r = systemf("cat filelist | %s -pd -L --quiet copy-L >copy-L.out 2>copy-L.err", testprog); + r = systemf("cat filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog); assertEqualInt(r, 0); assertEmptyFile("copy-L.out"); assertEmptyFile("copy-L.err"); @@ -60,8 +60,8 @@ DEFINE_TEST(test_option_L) failure("-pdL should dereference symlinks and turn them into files."); assert(!S_ISLNK(st.st_mode)); - r = systemf("cat filelist | %s -o --quiet >archive.out 2>archive.err", testprog); - failure("Error invoking %s -o --quiet", testprog); + r = systemf("cat filelist | %s -o >archive.out 2>archive.err", testprog); + failure("Error invoking %s -o ", testprog); assertEqualInt(r, 0); assertEqualInt(0, mkdir("unpack", 0755)); @@ -71,8 +71,8 @@ DEFINE_TEST(test_option_L) assertEqualInt(0, lstat("unpack/symlink", &st)); assert(S_ISLNK(st.st_mode)); - r = systemf("cat filelist | %s -oL --quiet >archive-L.out 2>archive-L.err", testprog); - failure("Error invoking %s -oL --quiet", testprog); + r = systemf("cat filelist | %s -oL >archive-L.out 2>archive-L.err", testprog); + failure("Error invoking %s -oL", testprog); assertEqualInt(r, 0); assertEqualInt(0, mkdir("unpack-L", 0755)); diff --git a/archivers/libarchive/files/cpio/test/test_option_a.c b/archivers/libarchive/files/cpio/test/test_option_a.c index 39118d71171..c063280f7d7 100644 --- a/archivers/libarchive/files/cpio/test/test_option_a.c +++ b/archivers/libarchive/files/cpio/test/test_option_a.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2008 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,33 +23,70 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "test.h" +#include <utime.h> __FBSDID("$FreeBSD$"); +static struct { + const char *name; + time_t atime_sec; +} files[] = { + { "f0", 0 }, + { "f1", 0 }, + { "f2", 0 }, + { "f3", 0 }, + { "f4", 0 }, + { "f5", 0 } +}; + /* - * Create a file on disk and set the atime to a known value. + * Create a bunch of test files and record their atimes. + * For the atime preserve/change tests, the files must have + * atimes in the past. We can accomplish this by explicitly invoking + * utime() on platforms that support it or by simply sleeping + * for a second after creating the files. (Creating all of the files + * at once means we only need to sleep once.) */ static void -test_create(const char *filename) +test_create(void) { + struct stat st; + struct utimbuf times; + static const int numfiles = sizeof(files) / sizeof(files[0]); + int i; int fd; - struct timeval times[2]; - fd = open(filename, O_CREAT | O_WRONLY, 0644); - assert(fd >= 0); - /* - * Note: Have to write at least one byte to the file. - * cpio doesn't bother reading the file if it's zero length, - * so the atime never gets changed in that case, which - * makes the tests below rather pointless. - */ - assertEqualInt(1, write(fd, "a", 1)); - memset(times, 0, sizeof(times)); - times[0].tv_sec = 1; /* atime = 1.000000002 */ - times[0].tv_usec = 2; - times[1].tv_sec = 3; /* mtime = 3.000000004 */ - times[1].tv_usec = 4; - assertEqualInt(0, futimes(fd, times)); - close(fd); + for (i = 0; i < numfiles; ++i) { + fd = open(files[i].name, O_CREAT | O_WRONLY, 0644); + assert(fd >= 0); + /* + * Note: Have to write at least one byte to the file. + * cpio doesn't bother reading the file if it's zero length, + * so the atime never gets changed in that case, which + * makes the tests below rather pointless. + */ + assertEqualInt(1, write(fd, "a", 1)); + close(fd); + + /* If utime() isn't supported on your platform, just + * #ifdef this section out. Most of the test below is + * still valid. */ + memset(×, 0, sizeof(times)); + times.actime = 1; + times.modtime = 3; + assertEqualInt(0, utime(files[i].name, ×)); + + /* Record whatever atime the file ended up with. */ + /* If utime() is available, this should be 1, but there's + * no harm in being careful. */ + assertEqualInt(0, stat(files[i].name, &st)); + files[i].atime_sec = st.st_atime; + } + + /* Wait until the atime on the last file is actually in the past. */ + /* If utime() is supported above, there's no sleep here which + * makes the test faster. */ + while (files[numfiles - 1].atime_sec >= time(NULL)) + sleep(1); } DEFINE_TEST(test_option_a) @@ -59,18 +96,15 @@ DEFINE_TEST(test_option_a) int f; char buff[64]; - /* Sanity check; verify that test_create really works. */ - test_create("f0"); - assertEqualInt(0, stat("f0", &st)); - failure("test_create function is supposed to create a file with atime == 1; if this doesn't work, test_option_a is entirely invalid."); - assertEqualInt(st.st_atime, 1); + /* Create all of the test files. */ + test_create(); /* Sanity check; verify that atimes really do get modified. */ - f = open("f0", O_RDONLY); + f = open(files[0].name, O_RDONLY); assertEqualInt(1, read(f,buff, 1)); assertEqualInt(0, close(f)); assertEqualInt(0, stat("f0", &st)); - if (st.st_atime == 1) { + if (st.st_atime == files[0].atime_sec) { skipping("Cannot verify -a option\n" " Your system appears to not support atime."); } @@ -82,23 +116,21 @@ DEFINE_TEST(test_option_a) */ /* Copy the file without -a; should change the atime. */ - test_create("f1"); - r = systemf("echo f1 | %s -pd --quiet copy-no-a > copy-no-a.out 2>copy-no-a.err", testprog); + r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog); assertEqualInt(r, 0); assertEmptyFile("copy-no-a.err"); assertEmptyFile("copy-no-a.out"); - assertEqualInt(0, stat("f1", &st)); - failure("Copying file without -a should have changed atime. Ignore this if your system does not record atimes."); - assert(st.st_atime != 1); + assertEqualInt(0, stat(files[1].name, &st)); + failure("Copying file without -a should have changed atime."); + assert(st.st_atime != files[1].atime_sec); /* Archive the file without -a; should change the atime. */ - test_create("f2"); - r = systemf("echo f2 | %s -o --quiet > archive-no-a.out 2>archive-no-a.err", testprog); + r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog); assertEqualInt(r, 0); assertEmptyFile("copy-no-a.err"); - assertEqualInt(0, stat("f2", &st)); - failure("Archiving file without -a should have changed atime. Ignore this if your system does not record atimes."); - assert(st.st_atime != 1); + assertEqualInt(0, stat(files[2].name, &st)); + failure("Archiving file without -a should have changed atime."); + assert(st.st_atime != files[2].atime_sec); } /* @@ -107,22 +139,21 @@ DEFINE_TEST(test_option_a) */ /* Copy the file with -a; should not change the atime. */ - test_create("f3"); - r = systemf("echo f3 | %s -pad --quiet copy-a > copy-a.out 2>copy-a.err", testprog); + r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err", + files[3].name, testprog); assertEqualInt(r, 0); assertEmptyFile("copy-a.err"); assertEmptyFile("copy-a.out"); - assertEqualInt(0, stat("f3", &st)); + assertEqualInt(0, stat(files[3].name, &st)); failure("Copying file with -a should not have changed atime."); - assertEqualInt(st.st_atime, 1); + assertEqualInt(st.st_atime, files[3].atime_sec); - /* Archive the file without -a; should change the atime. */ - test_create("f4"); - r = systemf("echo f4 | %s -oa --quiet > archive-a.out 2>archive-a.err", testprog); + /* Archive the file with -a; should not change the atime. */ + r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err", + files[4].name, testprog); assertEqualInt(r, 0); assertEmptyFile("copy-a.err"); - assertEqualInt(0, stat("f4", &st)); + assertEqualInt(0, stat(files[4].name, &st)); failure("Archiving file with -a should not have changed atime."); - assertEqualInt(st.st_atime, 1); - + assertEqualInt(st.st_atime, files[4].atime_sec); } diff --git a/archivers/libarchive/files/cpio/test/test_option_c.c b/archivers/libarchive/files/cpio/test/test_option_c.c index 9c422c97058..05b48c29cc3 100644 --- a/archivers/libarchive/files/cpio/test/test_option_c.c +++ b/archivers/libarchive/files/cpio/test/test_option_c.c @@ -88,9 +88,9 @@ DEFINE_TEST(test_option_c) /* Use the cpio program to create an archive. */ close(filelist); - r = systemf("%s -oc --quiet <filelist >basic.out 2>basic.err", testprog); + r = systemf("%s -oc <filelist >basic.out 2>basic.err", testprog); /* Verify that nothing went to stderr. */ - assertEmptyFile("basic.err"); + assertFileContents("1 block\n", 8, "basic.err"); /* Assert that the program finished. */ failure("%s -oc crashed", testprog); diff --git a/archivers/libarchive/files/cpio/test/test_option_d.c b/archivers/libarchive/files/cpio/test/test_option_d.c index cc962cc5856..370c82ae2d0 100644 --- a/archivers/libarchive/files/cpio/test/test_option_d.c +++ b/archivers/libarchive/files/cpio/test/test_option_d.c @@ -40,9 +40,9 @@ DEFINE_TEST(test_option_d) close(fd); /* Create an archive. */ - r = systemf("echo dir/file | %s -o --quiet > archive.cpio 2>archive.err", testprog); + r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog); assertEqualInt(r, 0); - assertEmptyFile("archive.err"); + assertFileContents("1 block\n", 8, "archive.err"); assertEqualInt(0, stat("archive.cpio", &st)); assertEqualInt(512, st.st_size); @@ -59,10 +59,10 @@ DEFINE_TEST(test_option_d) assertEqualInt(0, chdir("..")); assertEqualInt(0, mkdir("with-d", 0755)); assertEqualInt(0, chdir("with-d")); - r = systemf("%s -id --quiet < ../archive.cpio >out 2>err", testprog); + r = systemf("%s -id < ../archive.cpio >out 2>err", testprog); assertEqualInt(r, 0); assertEmptyFile("out"); - assertEmptyFile("err"); + assertFileContents("1 block\n", 8, "err"); /* And the file should be restored. */ assertEqualInt(0, stat("dir/file", &st)); } diff --git a/archivers/libarchive/files/cpio/test/test_option_ell.c b/archivers/libarchive/files/cpio/test/test_option_ell.c index caf2a80b6d4..36bb0acc350 100644 --- a/archivers/libarchive/files/cpio/test/test_option_ell.c +++ b/archivers/libarchive/files/cpio/test/test_option_ell.c @@ -47,7 +47,7 @@ DEFINE_TEST(test_option_ell) assertEqualInt(0, stat("f", &st)); /* Copy the file to the "copy" dir. */ - r = systemf("echo f | %s -pd --quiet copy >copy.out 2>copy.err", + r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", testprog); assertEqualInt(r, 0); @@ -56,7 +56,7 @@ DEFINE_TEST(test_option_ell) assert(st2.st_ino != st.st_ino); /* Copy the file to the "link" dir with the -l option. */ - r = systemf("echo f | %s -pld --quiet link >link.out 2>link.err", + r = systemf("echo f | %s -pld link >link.out 2>link.err", testprog); assertEqualInt(r, 0); diff --git a/archivers/libarchive/files/cpio/test/test_option_f.c b/archivers/libarchive/files/cpio/test/test_option_f.c index 37aba7fa41d..d1af91290d4 100644 --- a/archivers/libarchive/files/cpio/test/test_option_f.c +++ b/archivers/libarchive/files/cpio/test/test_option_f.c @@ -36,7 +36,7 @@ unpack(const char *dirname, const char *option) assertEqualInt(0, mkdir(dirname, 0755)); assertEqualInt(0, chdir(dirname)); extract_reference_file("test_option_f.cpio"); - r = systemf("%s -i --quiet %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option); + r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option); assertEqualInt(0, r); assertEqualInt(0, chdir("..")); } diff --git a/archivers/libarchive/files/cpio/test/test_option_u.c b/archivers/libarchive/files/cpio/test/test_option_u.c index b35719f6c52..7abd7f0f0ef 100644 --- a/archivers/libarchive/files/cpio/test/test_option_u.c +++ b/archivers/libarchive/files/cpio/test/test_option_u.c @@ -23,11 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "test.h" +#include <utime.h> __FBSDID("$FreeBSD$"); DEFINE_TEST(test_option_u) { - struct timeval times[2]; + struct utimbuf times; char *p; size_t s; int fd; @@ -40,7 +41,7 @@ DEFINE_TEST(test_option_u) close(fd); /* Copy the file to the "copy" dir. */ - r = systemf("echo f | %s -pd --quiet copy >copy.out 2>copy.err", + r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", testprog); assertEqualInt(r, 0); @@ -56,15 +57,13 @@ DEFINE_TEST(test_option_u) close(fd); /* Set the mtime to the distant past. */ - memset(times, 0, sizeof(times)); - times[0].tv_sec = 1; /* atime = 1.000000002 */ - times[0].tv_usec = 2; - times[1].tv_sec = 3; /* mtime = 3.000000004 */ - times[1].tv_usec = 4; - assertEqualInt(0, utimes("f", times)); + memset(×, 0, sizeof(times)); + times.actime = 1; + times.modtime = 3; + assertEqualInt(0, utime("f", ×)); /* Copy the file to the "copy" dir. */ - r = systemf("echo f | %s -pd --quiet copy >copy.out 2>copy.err", + r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", testprog); assertEqualInt(r, 0); @@ -74,7 +73,7 @@ DEFINE_TEST(test_option_u) assertEqualMem(p, "a", 1); /* Copy the file to the "copy" dir with -u (force) */ - r = systemf("echo f | %s -pud --quiet copy >copy.out 2>copy.err", + r = systemf("echo f | %s -pud copy >copy.out 2>copy.err", testprog); assertEqualInt(r, 0); diff --git a/archivers/libarchive/files/cpio/test/test_option_version.c b/archivers/libarchive/files/cpio/test/test_option_version.c index ff90dfd824e..95258eb7e82 100644 --- a/archivers/libarchive/files/cpio/test/test_option_version.c +++ b/archivers/libarchive/files/cpio/test/test_option_version.c @@ -88,6 +88,14 @@ DEFINE_TEST(test_option_version) size_t s; r = systemf("%s --version >version.stdout 2>version.stderr", testprog); + if (r != 0) + r = systemf("%s -W version >version.stdout 2>version.stderr", + testprog); + failure("Unable to run either %s --version or %s -W version", + testprog, testprog); + if (!assert(r == 0)) + return; + /* --version should generate nothing to stderr. */ assertEmptyFile("version.stderr"); /* Verify format of version message. */ |