summaryrefslogtreecommitdiff
path: root/tar/test
diff options
context:
space:
mode:
Diffstat (limited to 'tar/test')
-rw-r--r--tar/test/CMakeLists.txt9
-rw-r--r--tar/test/main.c154
-rw-r--r--tar/test/test.h29
-rw-r--r--tar/test/test_extract.tar.lz4.uu8
-rw-r--r--tar/test/test_extract_tar_lz4.c48
-rw-r--r--tar/test/test_leading_slash.c49
-rw-r--r--tar/test/test_leading_slash.tar.uu60
-rw-r--r--tar/test/test_option_X_upper.c14
-rw-r--r--tar/test/test_option_b.c19
-rw-r--r--tar/test/test_option_lz4.c74
-rw-r--r--tar/test/test_option_passphrase.c43
-rw-r--r--tar/test/test_option_passphrase.zip.uu12
-rw-r--r--tar/test/test_option_s.c23
-rw-r--r--tar/test/test_version.c5
14 files changed, 520 insertions, 27 deletions
diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt
index 98f49e29298b..9648e4892a3c 100644
--- a/tar/test/CMakeLists.txt
+++ b/tar/test/CMakeLists.txt
@@ -18,11 +18,13 @@ IF(ENABLE_TAR AND ENABLE_TEST)
test_extract_tar_gz.c
test_extract_tar_lrz.c
test_extract_tar_lz.c
+ test_extract_tar_lz4.c
test_extract_tar_lzma.c
test_extract_tar_lzo.c
test_extract_tar_xz.c
test_format_newc.c
test_help.c
+ test_leading_slash.c
test_option_C_upper.c
test_option_H_upper.c
test_option_L_upper.c
@@ -40,12 +42,14 @@ IF(ENABLE_TAR AND ENABLE_TEST)
test_option_k.c
test_option_keep_newer_files.c
test_option_lrzip.c
+ test_option_lz4.c
test_option_lzma.c
test_option_lzop.c
test_option_n.c
test_option_newer_than.c
test_option_nodump.c
test_option_older_than.c
+ test_option_passphrase.c
test_option_q.c
test_option_r.c
test_option_s.c
@@ -90,11 +94,12 @@ IF(ENABLE_TAR AND ENABLE_TEST)
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
- INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/test_utils)
+ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils)
# Experimental new test handling
ADD_CUSTOM_TARGET(run_bsdtar_test
- COMMAND bsdtar_test -p ${BSDTAR} -r ${CMAKE_CURRENT_SOURCE_DIR})
+ COMMAND bsdtar_test -p $<TARGET_FILE:bsdtar>
+ -r ${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEPENDENCIES(run_bsdtar_test bsdtar)
ADD_DEPENDENCIES(run_all_tests run_bsdtar_test)
diff --git a/tar/test/main.c b/tar/test/main.c
index f2dcaf4ae83b..90801a98bc8f 100644
--- a/tar/test/main.c
+++ b/tar/test/main.c
@@ -130,6 +130,16 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.6 2008/11/05 06:40:53 kientz
# include <crtdbg.h>
#endif
+/* Path to working directory for current test */
+const char *testworkdir;
+#ifdef PROGRAM
+/* Pathname of exe to be tested. */
+const char *testprogfile;
+/* Name of exe to use in printf-formatted command strings. */
+/* On Windows, this includes leading/trailing quotes. */
+const char *testprog;
+#endif
+
#if defined(_WIN32) && !defined(__CYGWIN__)
static void *GetFunctionKernel32(const char *);
static int my_CreateSymbolicLinkA(const char *, const char *, int);
@@ -194,7 +204,7 @@ my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi)
}
#endif
-#if defined(HAVE__CrtSetReportMode)
+#if defined(HAVE__CrtSetReportMode) && !defined(__WATCOMC__)
static void
invalid_parameter_handler(const wchar_t * expression,
const wchar_t * function, const wchar_t * file,
@@ -565,10 +575,10 @@ static void strdump(const char *e, const char *p, int ewidth, int utf8)
while (*p != '\0') {
unsigned int c = 0xff & *p++;
switch (c) {
- case '\a': printf("\a"); break;
- case '\b': printf("\b"); break;
- case '\n': printf("\n"); break;
- case '\r': printf("\r"); break;
+ case '\a': logprintf("\\a"); break;
+ case '\b': logprintf("\\b"); break;
+ case '\n': logprintf("\\n"); break;
+ case '\r': logprintf("\\r"); break;
default:
if (c >= 32 && c < 127)
logprintf("%c", c);
@@ -771,6 +781,34 @@ assertion_equal_mem(const char *file, int line,
return (0);
}
+/* Verify that a block of memory is filled with the specified byte. */
+int
+assertion_memory_filled_with(const char *file, int line,
+ const void *_v1, const char *vd,
+ size_t l, const char *ld,
+ char b, const char *bd, void *extra)
+{
+ const char *v1 = (const char *)_v1;
+ size_t c = 0;
+ size_t i;
+ (void)ld; /* UNUSED */
+
+ assertion_count(file, line);
+
+ for (i = 0; i < l; ++i) {
+ if (v1[i] == b) {
+ ++c;
+ }
+ }
+ if (c == l)
+ return (1);
+
+ failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd);
+ logprintf(" Only %d bytes were correct\n", (int)c);
+ failure_finish(extra);
+ return (0);
+}
+
/* Verify that the named file exists and is empty. */
int
assertion_empty_file(const char *filename, int line, const char *f1)
@@ -1061,7 +1099,8 @@ assertion_file_contains_lines_any_order(const char *file, int line,
free(expected);
return (0);
}
- for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
+ for (j = 0, p = buff; p < buff + buff_size;
+ p += 1 + strlen(p)) {
if (*p != '\0') {
actual[j] = p;
++j;
@@ -1913,6 +1952,18 @@ canGzip(void)
* Can this platform run the lrzip program?
*/
int
+canRunCommand(const char *cmd)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("%s %s", cmd, redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+int
canLrzip(void)
{
static int tested = 0, value = 0;
@@ -1925,6 +1976,21 @@ canLrzip(void)
}
/*
+ * Can this platform run the lz4 program?
+ */
+int
+canLz4(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("lz4 -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
* Can this platform run the lzip program?
*/
int
@@ -2136,8 +2202,31 @@ slurpfile(size_t * sizep, const char *fmt, ...)
return (p);
}
+/*
+ * Slurp a file into memory for ease of comparison and testing.
+ * Returns size of file in 'sizep' if non-NULL, null-terminates
+ * data in memory for ease of use.
+ */
+void
+dumpfile(const char *filename, void *data, size_t len)
+{
+ ssize_t bytes_written;
+ FILE *f;
+
+ f = fopen(filename, "wb");
+ if (f == NULL) {
+ logprintf("Can't open file %s for writing\n", filename);
+ return;
+ }
+ bytes_written = fwrite(data, 1, len, f);
+ if (bytes_written < (ssize_t)len)
+ logprintf("Can't write file %s\n", filename);
+ fclose(f);
+}
+
/* Read a uuencoded file from the reference directory, decode, and
* write the result into the current directory. */
+#define VALID_UUDECODE(c) (c >= 32 && c <= 96)
#define UUDECODE(c) (((c) - 0x20) & 0x3f)
void
extract_reference_file(const char *name)
@@ -2161,7 +2250,6 @@ extract_reference_file(const char *name)
break;
}
/* Now, decode the rest and write it. */
- /* Not a lot of error checking here; the input better be right. */
out = fopen(name, "wb");
while (fgets(buff, sizeof(buff), in) != NULL) {
char *p = buff;
@@ -2175,17 +2263,21 @@ extract_reference_file(const char *name)
int n = 0;
/* Write out 1-3 bytes from that. */
if (bytes > 0) {
+ assert(VALID_UUDECODE(p[0]));
+ assert(VALID_UUDECODE(p[1]));
n = UUDECODE(*p++) << 18;
n |= UUDECODE(*p++) << 12;
fputc(n >> 16, out);
--bytes;
}
if (bytes > 0) {
+ assert(VALID_UUDECODE(p[0]));
n |= UUDECODE(*p++) << 6;
fputc((n >> 8) & 0xFF, out);
--bytes;
}
if (bytes > 0) {
+ assert(VALID_UUDECODE(p[0]));
n |= UUDECODE(*p++);
fputc(n & 0xFF, out);
--bytes;
@@ -2196,6 +2288,32 @@ extract_reference_file(const char *name)
fclose(in);
}
+void
+copy_reference_file(const char *name)
+{
+ char buff[1024];
+ FILE *in, *out;
+ size_t rbytes;
+
+ sprintf(buff, "%s/%s", refdir, name);
+ in = fopen(buff, "rb");
+ failure("Couldn't open reference file %s", buff);
+ assert(in != NULL);
+ if (in == NULL)
+ return;
+ /* Now, decode the rest and write it. */
+ /* Not a lot of error checking here; the input better be right. */
+ out = fopen(name, "wb");
+ while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) {
+ if (fwrite(buff, 1, rbytes, out) != rbytes) {
+ logprintf("Error: fwrite\n");
+ break;
+ }
+ }
+ fclose(out);
+ fclose(in);
+}
+
int
is_LargeInode(const char *file)
{
@@ -2217,6 +2335,14 @@ is_LargeInode(const char *file)
return (ino > 0xffffffff);
#endif
}
+
+void
+extract_reference_files(const char **names)
+{
+ while (names && *names)
+ extract_reference_file(*names++);
+}
+
/*
*
* TEST management
@@ -2246,7 +2372,7 @@ struct test_list_t tests[] = {
* Summarize repeated failures in the just-completed test.
*/
static void
-test_summarize(int failed)
+test_summarize(int failed, int skips_num)
{
unsigned int i;
@@ -2256,7 +2382,7 @@ test_summarize(int failed)
fflush(stdout);
break;
case VERBOSITY_PASSFAIL:
- printf(failed ? "FAIL\n" : "ok\n");
+ printf(failed ? "FAIL\n" : skips_num ? "ok (S)\n" : "ok\n");
break;
}
@@ -2281,13 +2407,14 @@ test_run(int i, const char *tmpdir)
char workdir[1024];
char logfilename[64];
int failures_before = failures;
+ int skips_before = skips;
int oldumask;
switch (verbosity) {
case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */
break;
case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */
- printf("%3d: %-50s", i, tests[i].name);
+ printf("%3d: %-64s", i, tests[i].name);
fflush(stdout);
break;
default: /* Title of test, details will follow */
@@ -2337,7 +2464,7 @@ test_run(int i, const char *tmpdir)
}
/* Report per-test summaries. */
tests[i].failures = failures - failures_before;
- test_summarize(tests[i].failures);
+ test_summarize(tests[i].failures, skips - skips_before);
/* Close the per-test log file. */
fclose(logfile);
logfile = NULL;
@@ -2480,6 +2607,7 @@ get_refdir(const char *d)
failure:
printf("Unable to locate known reference file %s\n", KNOWNREF);
printf(" Checked following directories:\n%s\n", tried);
+ printf("Use -r option to specify full path to reference directory\n");
#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
DebugBreak();
#endif
@@ -2516,7 +2644,7 @@ main(int argc, char **argv)
while (pwd[strlen(pwd) - 1] == '\n')
pwd[strlen(pwd) - 1] = '\0';
-#if defined(HAVE__CrtSetReportMode)
+#if defined(HAVE__CrtSetReportMode) && !defined(__WATCOMC__)
/* To stop to run the default invalid parameter handler. */
_set_invalid_parameter_handler(invalid_parameter_handler);
/* Disable annoying assertion message box. */
@@ -2563,7 +2691,7 @@ main(int argc, char **argv)
exit(1);
}
memmove(testprogdir + strlen(pwd) + 1, testprogdir,
- strlen(testprogdir));
+ strlen(testprogdir) + 1);
memcpy(testprogdir, pwd, strlen(pwd));
testprogdir[strlen(pwd)] = '/';
}
diff --git a/tar/test/test.h b/tar/test/test.h
index a0a9bb6f600c..704a137ed3fb 100644
--- a/tar/test/test.h
+++ b/tar/test/test.h
@@ -66,6 +66,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -91,7 +92,7 @@
#endif
/* Visual Studio */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf sprintf_s
#endif
@@ -144,6 +145,9 @@
/* As above, but raw blocks of bytes. */
#define assertEqualMem(v1, v2, l) \
assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL)
+/* Assert that memory is full of a specified byte */
+#define assertMemoryFilledWith(v1, l, b) \
+ assertion_memory_filled_with(__FILE__, __LINE__, (v1), #v1, (l), #l, (b), #b, NULL)
/* Assert two files are the same. */
#define assertEqualFile(f1, f2) \
assertion_equal_file(__FILE__, __LINE__, (f1), (f2))
@@ -227,6 +231,7 @@ int assertion_empty_file(const char *, int, const char *);
int assertion_equal_file(const char *, int, const char *, const char *);
int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *);
int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *);
+int assertion_memory_filled_with(const char *, int, const void *, const char *, size_t, const char *, char, const char *, void *);
int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *, int);
int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
int assertion_file_atime(const char *, int, const char *, long, long);
@@ -277,9 +282,15 @@ int canGrzip(void);
/* Return true if this platform can run the "gzip" program. */
int canGzip(void);
+/* Return true if this platform can run the specified command. */
+int canRunCommand(const char *);
+
/* Return true if this platform can run the "lrzip" program. */
int canLrzip(void);
+/* Return true if this platform can run the "lz4" program. */
+int canLz4(void);
+
/* Return true if this platform can run the "lzip" program. */
int canLzip(void);
@@ -302,21 +313,31 @@ int is_LargeInode(const char *);
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
char *slurpfile(size_t *, const char *fmt, ...);
+/* Dump block of bytes to a file. */
+void dumpfile(const char *filename, void *, size_t);
+
/* Extracts named reference file to the current directory. */
void extract_reference_file(const char *);
+/* Copies named reference file to the current directory. */
+void copy_reference_file(const char *);
+
+/* Extracts a list of files to the current directory.
+ * List must be NULL terminated.
+ */
+void extract_reference_files(const char **);
/* Path to working directory for current test */
-const char *testworkdir;
+extern const char *testworkdir;
/*
* Special interfaces for program test harness.
*/
/* Pathname of exe to be tested. */
-const char *testprogfile;
+extern const char *testprogfile;
/* Name of exe to use in printf-formatted command strings. */
/* On Windows, this includes leading/trailing quotes. */
-const char *testprog;
+extern const char *testprog;
#ifdef USE_DMALLOC
#include <dmalloc.h>
diff --git a/tar/test/test_extract.tar.lz4.uu b/tar/test/test_extract.tar.lz4.uu
new file mode 100644
index 000000000000..a10ac0275ad7
--- /dev/null
+++ b/tar/test/test_extract.tar.lz4.uu
@@ -0,0 +1,8 @@
+begin 644 test_extract.tar.lz4
+M!")-&&1PN:L```!O9FEL93$``0!+Z#`P,#8V-"``,#`Q-S4P"``#`@#_"3(S
+M(#$R,#,R-S0P,C,T(#`Q,3,V-0`@,)<`2P("`+)U<W1A<@`P,&-U91$`#P(`
+M!`\@``T"RP``W0```@`?($8`!`\"`'[!8V]N=&5N=',@;V8@#`(O+@JD`'X/
+M`@#_2@#T`1\R80%,#P`$&B$T-0`$+S<P``3_9!\R``3_W0\"`/___^M0````
+*````````J.?`=```
+`
+end
diff --git a/tar/test/test_extract_tar_lz4.c b/tar/test/test_extract_tar_lz4.c
new file mode 100644
index 000000000000..150d57d71551
--- /dev/null
+++ b/tar/test/test_extract_tar_lz4.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012,2014 Michihiro NAKAJIMA
+ * 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$");
+
+DEFINE_TEST(test_extract_tar_lz4)
+{
+ const char *reffile = "test_extract.tar.lz4";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLz4()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems lz4 is not supported on this platform");
+ }
+}
diff --git a/tar/test/test_leading_slash.c b/tar/test/test_leading_slash.c
new file mode 100644
index 000000000000..a8921ebcbae8
--- /dev/null
+++ b/tar/test/test_leading_slash.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2003-2014 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$");
+
+DEFINE_TEST(test_leading_slash)
+{
+ const char *reffile = "test_leading_slash.tar";
+ char *errfile;
+ size_t errfile_size;
+ const char *expected_errmsg = "Removing leading '/' from member names";
+
+ extract_reference_file(reffile);
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", testprog, reffile));
+ assertFileExists("foo/file");
+ assertTextFileContents("foo\x0a", "foo/file");
+ assertTextFileContents("foo\x0a", "foo/hardlink");
+ assertIsHardlink("foo/file", "foo/hardlink");
+ assertEmptyFile("test.out");
+
+ /* Verify the error output contains the expected text somewhere in it */
+ if (assertFileExists("test.err")) {
+ errfile = slurpfile(&errfile_size, "test.err");
+ assert(strstr(errfile, expected_errmsg) != NULL);
+ }
+}
+
diff --git a/tar/test/test_leading_slash.tar.uu b/tar/test/test_leading_slash.tar.uu
new file mode 100644
index 000000000000..eeb27c3bbf40
--- /dev/null
+++ b/tar/test/test_leading_slash.tar.uu
@@ -0,0 +1,60 @@
+begin 644 test_leading_slash.tar
+M+V9O;R]F:6QE````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#8T-"``,#`P,#`P(``P,#`P,#`@`#`P,#`P,#`P,#`T
+M(#$R-#$V,S4U-34V(#`Q,C8V-P`@,```````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,')O;W0`
+M````````````````````````````````````=VAE96P`````````````````
+M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````!F;V\*````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````"]F;V\O:&%R9&QI
+M;FL`````````````````````````````````````````````````````````
+M```````````````````````````````````````````````````````````P
+M,#`V-#0@`#`P,#`P,"``,#`P,#`P(``P,#`P,#`P,#`P,"`Q,C0Q-C,U-34U
+M-B`P,34R-#,`(#$O9F]O+V9I;&4`````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#!R;V]T````````````````
+M`````````````````````'=H965L````````````````````````````````
+M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+H````````````````````````````````````````````````````````
+`
+end
diff --git a/tar/test/test_option_X_upper.c b/tar/test/test_option_X_upper.c
index 1aa21fc90a67..4916af2970e8 100644
--- a/tar/test/test_option_X_upper.c
+++ b/tar/test/test_option_X_upper.c
@@ -142,4 +142,18 @@ DEFINE_TEST(test_option_X_upper)
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
+
+ /* Test 8: with empty exclusions file */
+ assertMakeDir("test8", 0755);
+ assertChdir("test8");
+ assertMakeFile("exclusions", 0644, "");
+ assertEqualInt(0,
+ systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
+ assertFileContents("file1", 5, "file1");
+ assertFileContents("file2", 5, "file2");
+ assertFileContents("file3a", 6, "file3a");
+ assertFileContents("file4a", 6, "file4a");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ assertChdir("..");
}
diff --git a/tar/test/test_option_b.c b/tar/test/test_option_b.c
index be2ae65c75a8..81f50be8355e 100644
--- a/tar/test/test_option_b.c
+++ b/tar/test/test_option_b.c
@@ -25,18 +25,25 @@
#include "test.h"
__FBSDID("$FreeBSD$");
+#define USTAR_OPT " --format=ustar"
+
DEFINE_TEST(test_option_b)
{
+ char *testprog_ustar;
+
assertMakeFile("file1", 0644, "file1");
if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) {
skipping("Platform doesn't have cat");
return;
}
+ testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1);
+ strcpy(testprog_ustar, testprog);
+ strcat(testprog_ustar, USTAR_OPT);
/*
* Bsdtar does not pad if the output is going directly to a disk file.
*/
- assertEqualInt(0, systemf("%s -cf archive1.tar file1 >test1.out 2>test1.err", testprog));
+ assertEqualInt(0, systemf("%s -cf archive1.tar file1 >test1.out 2>test1.err", testprog_ustar));
failure("bsdtar does not pad archives written directly to regular files");
assertFileSize("archive1.tar", 2048);
assertEmptyFile("test1.out");
@@ -46,24 +53,24 @@ DEFINE_TEST(test_option_b)
* Bsdtar does pad to the block size if the output is going to a socket.
*/
/* Default is -b 20 */
- assertEqualInt(0, systemf("%s -cf - file1 2>test2.err | cat >archive2.tar ", testprog));
+ assertEqualInt(0, systemf("%s -cf - file1 2>test2.err | cat >archive2.tar ", testprog_ustar));
failure("bsdtar does pad archives written to pipes");
assertFileSize("archive2.tar", 10240);
assertEmptyFile("test2.err");
- assertEqualInt(0, systemf("%s -cf - -b 20 file1 2>test3.err | cat >archive3.tar ", testprog));
+ assertEqualInt(0, systemf("%s -cf - -b 20 file1 2>test3.err | cat >archive3.tar ", testprog_ustar));
assertFileSize("archive3.tar", 10240);
assertEmptyFile("test3.err");
- assertEqualInt(0, systemf("%s -cf - -b 10 file1 2>test4.err | cat >archive4.tar ", testprog));
+ assertEqualInt(0, systemf("%s -cf - -b 10 file1 2>test4.err | cat >archive4.tar ", testprog_ustar));
assertFileSize("archive4.tar", 5120);
assertEmptyFile("test4.err");
- assertEqualInt(0, systemf("%s -cf - -b 1 file1 2>test5.err | cat >archive5.tar ", testprog));
+ assertEqualInt(0, systemf("%s -cf - -b 1 file1 2>test5.err | cat >archive5.tar ", testprog_ustar));
assertFileSize("archive5.tar", 2048);
assertEmptyFile("test5.err");
- assertEqualInt(0, systemf("%s -cf - -b 8192 file1 2>test6.err | cat >archive6.tar ", testprog));
+ assertEqualInt(0, systemf("%s -cf - -b 8192 file1 2>test6.err | cat >archive6.tar ", testprog_ustar));
assertFileSize("archive6.tar", 4194304);
assertEmptyFile("test6.err");
diff --git a/tar/test/test_option_lz4.c b/tar/test/test_option_lz4.c
new file mode 100644
index 000000000000..5dc945216300
--- /dev/null
+++ b/tar/test/test_option_lz4.c
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * 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$");
+
+DEFINE_TEST(test_option_lz4)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lz4 compression. */
+ r = systemf("%s -cf - --lz4 f >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "Unsupported compression") != NULL) {
+ skipping("This version of bsdtar was compiled "
+ "without lz4 support");
+ return;
+ }
+ /* POSIX permits different handling of the spawnp
+ * system call used to launch the subsidiary
+ * program: */
+ /* Some systems fail immediately to spawn the new process. */
+ if (strstr(p, "Can't launch") != NULL && !canLz4()) {
+ skipping("This version of bsdtar uses an external lz4 program "
+ "but no such program is available on this system.");
+ return;
+ }
+ /* Some systems successfully spawn the new process,
+ * but fail to exec a program within that process.
+ * This results in failure at the first attempt to
+ * write. */
+ if (strstr(p, "Can't write") != NULL && !canLz4()) {
+ skipping("This version of bsdtar uses an external lz4 program "
+ "but no such program is available on this system.");
+ return;
+ }
+ failure("--lz4 option is broken: %s", p);
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an lz4 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x04\x22\x4d\x18", 4);
+}
diff --git a/tar/test/test_option_passphrase.c b/tar/test/test_option_passphrase.c
new file mode 100644
index 000000000000..337292c95bfc
--- /dev/null
+++ b/tar/test/test_option_passphrase.c
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2014 Michihiro NAKAJIMA
+ * 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$");
+
+DEFINE_TEST(test_option_passphrase)
+{
+ const char *reffile = "test_option_passphrase.zip";
+
+ extract_reference_file(reffile);
+ failure("--passphrase option is broken");
+ assertEqualInt(0, systemf(
+ "%s --passphrase pass1 -xf %s >test.out 2>test.err",
+ testprog, reffile));
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+}
diff --git a/tar/test/test_option_passphrase.zip.uu b/tar/test/test_option_passphrase.zip.uu
new file mode 100644
index 000000000000..021ae8585fe8
--- /dev/null
+++ b/tar/test/test_option_passphrase.zip.uu
@@ -0,0 +1,12 @@
+begin 644 test_option_passphrase.zip
+M4$L#!`H`"0```#B91$7D$C4,'P```!,````%`!P`9FEL93%55`D``VS'+U0"
+MQR]4=7@+``$$]0$```04````BHPD*"^*I04=XKI\_FQ*TE+#),TD7TTKSP/7
+MR6R35%!+!PCD$C4,'P```!,```!02P,$"@`)````09E$1;VL<PX?````$P``
+M``4`'`!F:6QE,E54"0`#><<O5`+'+U1U>`L``03U`0``!!0```!D#6Z\@CI8
+MV1GIJO5TISQF^I:7.;Y3<-G3$YOCL(C_4$L'"+VL<PX?````$P```%!+`0(>
+M`PH`"0```#B91$7D$C4,'P```!,````%`!@```````$```"D@0````!F:6QE
+M,554!0`#;,<O5'5X"P`!!/4!```$%````%!+`0(>`PH`"0```$&91$6]K',.
+M'P```!,````%`!@```````$```"D@6X```!F:6QE,E54!0`#><<O5'5X"P`!
+@!/4!```$%````%!+!08``````@`"`)8```#<````````
+`
+end
diff --git a/tar/test/test_option_s.c b/tar/test/test_option_s.c
index a1f8697e32b2..ee8332f34fd5 100644
--- a/tar/test/test_option_s.c
+++ b/tar/test/test_option_s.c
@@ -82,9 +82,9 @@ DEFINE_TEST(test_option_s)
*/
assertMakeDir("test4", 0755);
systemf("%s -cf test4.tar in/d1/foo in/d1/bar",
- testprog, testprog);
+ testprog);
systemf("%s -xf test4.tar -s /foo/bar/ -s }bar}baz} -C test4",
- testprog, testprog);
+ testprog);
assertFileContents("foo", 3, "test4/in/d1/bar");
assertFileContents("bar", 3, "test4/in/d1/baz");
@@ -258,4 +258,23 @@ DEFINE_TEST(test_option_s)
assertFileContents("foo", 3, "test13a/in/d1/hardlink2");
assertIsHardlink("test13a/in/d1/foo", "test13a/in/d1/hardlink2");
/* TODO: See above; expand this test to verify renames at creation. */
+
+ /*
+ * Test 14: Global substitutions when extracting archive.
+ */
+ /* Global substitution. */
+ assertMakeDir("test14", 0755);
+ systemf("%s -cf test14.tar in/d1/foo in/d1/bar",
+ testprog);
+ systemf("%s -xf test14.tar -s /o/z/g -s /bar/baz/ -C test14",
+ testprog);
+ assertFileContents("foo", 3, "test14/in/d1/fzz");
+ assertFileContents("bar", 3, "test14/in/d1/baz");
+ /* Singular substitution. */
+ systemf("%s -cf test14.tar in/d1/foo in/d1/bar",
+ testprog);
+ systemf("%s -xf test14.tar -s /o/z/ -s /bar/baz/ -C test14",
+ testprog);
+ assertFileContents("foo", 3, "test14/in/d1/fzo");
+ assertFileContents("bar", 3, "test14/in/d1/baz");
}
diff --git a/tar/test/test_version.c b/tar/test/test_version.c
index 42472d1bc264..5474261d207a 100644
--- a/tar/test/test_version.c
+++ b/tar/test/test_version.c
@@ -87,6 +87,11 @@ DEFINE_TEST(test_version)
/* Skip a single trailing a,b,c, or d. */
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
++q;
+ /* Skip arbitrary third-party version numbers. */
+ while (s > 0 && (*q == ' ' || *q == '/' || *q == '.' || isalnum(*q))) {
+ ++q;
+ --s;
+ }
/* All terminated by end-of-line. */
assert(s >= 1);
/* Skip an optional CR character (e.g., Windows) */