Make test suite work with libarchive 1.3.1: Take advantage of
ARCHIVE_VERSION_STAMP to selectively disable tests that don't apply to that version; new "skipping()" function reports skipped tests; modify final summary to report component test failures and skips. Note: I don't currently intend to MFC the test suite itself; anyone interested should just checkout and use this version of the test suite, which should work for any library version. Approved by: re (Ken Smith, blanket)
This commit is contained in:
parent
ab16ac785a
commit
dbb4eb7d9c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=171280
@ -38,8 +38,10 @@ __FBSDID("$FreeBSD$");
|
||||
static int dump_on_failure = 1;
|
||||
/* Default is to print some basic information about each test. */
|
||||
static int quiet_flag = 0;
|
||||
/* Cumulative count of failures. */
|
||||
/* Cumulative count of component failures. */
|
||||
static int failures = 0;
|
||||
/* Cumulative count of skipped component tests. */
|
||||
static int skips = 0;
|
||||
|
||||
/*
|
||||
* My own implementation of the standard assert() macro emits the
|
||||
@ -59,6 +61,19 @@ static int failures = 0;
|
||||
static char msg[4096];
|
||||
|
||||
|
||||
/* Inform user that we're skipping a test. */
|
||||
void
|
||||
skipping(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, " *** SKIPPING: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
++skips;
|
||||
}
|
||||
|
||||
/* Common handling of failed tests. */
|
||||
static void
|
||||
test_failed(struct archive *a)
|
||||
@ -202,7 +217,7 @@ static int test_run(int i, const char *tmpdir)
|
||||
exit(1);
|
||||
}
|
||||
(*tests[i].func)();
|
||||
return (failures - failures_before);
|
||||
return (failures == failures_before ? 0 : 1);
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
@ -226,7 +241,7 @@ static void usage(void)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
static const int limit = sizeof(tests) / sizeof(tests[0]);
|
||||
int i, tests_run = 0, tests_succeeded = 0, opt;
|
||||
int i, tests_run = 0, tests_failed = 0, opt;
|
||||
time_t now;
|
||||
char tmpdir[256];
|
||||
|
||||
@ -266,13 +281,16 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("Running libarchive tests in: %s\n", tmpdir);
|
||||
if (!quiet_flag) {
|
||||
printf("Running libarchive tests in: %s\n", tmpdir);
|
||||
printf("Exercising %s\n", archive_version());
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
/* Default: Run all tests. */
|
||||
for (i = 0; i < limit; i++) {
|
||||
if (test_run(i, tmpdir) == 0)
|
||||
tests_succeeded++;
|
||||
if (test_run(i, tmpdir))
|
||||
tests_failed++;
|
||||
tests_run++;
|
||||
}
|
||||
} else {
|
||||
@ -282,13 +300,16 @@ int main(int argc, char **argv)
|
||||
printf("*** INVALID Test %s\n", *argv);
|
||||
usage();
|
||||
} else {
|
||||
if (test_run(i, tmpdir) == 0)
|
||||
tests_succeeded++;
|
||||
if (test_run(i, tmpdir))
|
||||
tests_failed++;
|
||||
tests_run++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d of %d tests succeeded.\n", tests_succeeded, tests_run);
|
||||
return (tests_succeeded == tests_run ? 0 : 1);
|
||||
printf("\n");
|
||||
printf("%d of %d test groups reported failures\n",
|
||||
tests_failed, tests_run);
|
||||
printf(" Total of %d individual tests failed.\n", failures);
|
||||
printf(" Total of %d individual tests were skipped.\n", skips);
|
||||
return (tests_failed);
|
||||
}
|
||||
|
@ -68,6 +68,18 @@
|
||||
#define __FBSDID(a) /* null */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ARCHIVE_VERSION_STAMP first appeared in 1.9 and libarchive 2.2.4.
|
||||
* We can approximate it for earlier versions, though.
|
||||
* This is used to disable tests of features not present in the current
|
||||
* version.
|
||||
*/
|
||||
#ifndef ARCHIVE_VERSION_STAMP
|
||||
#define ARCHIVE_VERSION_STAMP \
|
||||
(ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* "list.h" is simply created by "grep DEFINE_TEST"; it has
|
||||
* a line like
|
||||
@ -106,6 +118,7 @@
|
||||
|
||||
/* Function declarations. These are defined in test_utility.c. */
|
||||
void failure(const char *fmt, ...);
|
||||
void skipping(const char *fmt, ...);
|
||||
void test_assert(const char *, int, int, const char *, struct archive *);
|
||||
void test_assert_equal_int(const char *, int, int, const char *, int, const char *, struct archive *);
|
||||
void test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, struct archive *);
|
||||
|
@ -165,7 +165,12 @@ compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode)
|
||||
assert(matched == 1);
|
||||
}
|
||||
}
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
/* Known broken before 1.9.0. */
|
||||
skipping("archive_entry_acl_next() exits with ARCHIVE_EOF");
|
||||
#else
|
||||
assertEqualInt(ARCHIVE_EOF, r);
|
||||
#endif
|
||||
assert((mode & 0777) == (archive_entry_mode(ae) & 0777));
|
||||
failure("Could not find match for ACL "
|
||||
"(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')",
|
||||
|
@ -390,7 +390,12 @@ compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode)
|
||||
assert(matched == 1);
|
||||
}
|
||||
}
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
/* Known broken before 1.9.0. */
|
||||
skipping("archive_entry_acl_next() exits with ARCHIVE_EOF");
|
||||
#else
|
||||
assertEqualInt(ARCHIVE_EOF, r);
|
||||
#endif
|
||||
assert((mode & 0777) == (archive_entry_mode(ae) & 0777));
|
||||
failure("Could not find match for ACL "
|
||||
"(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')",
|
||||
|
@ -29,5 +29,23 @@ DEFINE_TEST(test_archive_api_feature)
|
||||
{
|
||||
assertEqualInt(ARCHIVE_API_FEATURE, archive_api_feature());
|
||||
assertEqualInt(ARCHIVE_API_VERSION, archive_api_version());
|
||||
/*
|
||||
* Even though ARCHIVE_VERSION_STAMP only appears in
|
||||
* archive.h after 1.9.0 and 2.2.3, the macro is synthesized
|
||||
* in test.h, so this test is always valid.
|
||||
*/
|
||||
assertEqualInt(ARCHIVE_VERSION_STAMP / 1000, ARCHIVE_API_VERSION * 1000 + ARCHIVE_API_FEATURE);
|
||||
/*
|
||||
* The function, however, isn't always available. It appeared
|
||||
* sometime in the middle of 2.2.3, but the synthesized value
|
||||
* never has a release version, so the following conditional
|
||||
* exactly determines whether the current library has the
|
||||
* function.
|
||||
*/
|
||||
#if ARCHIVE_VERSION_STAMP / 1000 == 1009 || ARCHIVE_VERSION_STAMP > 2002000
|
||||
assertEqualInt(ARCHIVE_VERSION_STAMP, archive_version_stamp());
|
||||
#else
|
||||
skipping("archive_version_stamp()");
|
||||
#endif
|
||||
assertEqualString(ARCHIVE_LIBRARY_VERSION, archive_version());
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ DEFINE_TEST(test_entry)
|
||||
const char *xname; /* For xattr tests. */
|
||||
const void *xval; /* For xattr tests. */
|
||||
size_t xsize; /* For xattr tests. */
|
||||
int c;
|
||||
|
||||
assert((e = archive_entry_new()) != NULL);
|
||||
|
||||
@ -72,13 +73,21 @@ DEFINE_TEST(test_entry)
|
||||
archive_entry_set_ctime(e, 13580, 24681);
|
||||
assertEqualInt(archive_entry_ctime(e), 13580);
|
||||
assertEqualInt(archive_entry_ctime_nsec(e), 24681);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/* dev */
|
||||
archive_entry_set_dev(e, 235);
|
||||
assertEqualInt(archive_entry_dev(e), 235);
|
||||
#else
|
||||
skipping("archive_entry_dev()");
|
||||
#endif
|
||||
/* devmajor/devminor are tested specially below. */
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/* filetype */
|
||||
archive_entry_set_filetype(e, AE_IFREG);
|
||||
assertEqualInt(archive_entry_filetype(e), AE_IFREG);
|
||||
#else
|
||||
skipping("archive_entry_filetype()");
|
||||
#endif
|
||||
/* fflags are tested specially below */
|
||||
/* gid */
|
||||
archive_entry_set_gid(e, 204);
|
||||
@ -104,9 +113,13 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
|
||||
memset(wbuff, 0, sizeof(wbuff));
|
||||
assertEqualWString(archive_entry_hardlink_w(e), L"whardlink");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/* ino */
|
||||
archive_entry_set_ino(e, 8593);
|
||||
assertEqualInt(archive_entry_ino(e), 8593);
|
||||
#else
|
||||
skipping("archive_entry_ino()");
|
||||
#endif
|
||||
/* link */
|
||||
/* TODO: implement these tests. */
|
||||
/* mode */
|
||||
@ -116,9 +129,13 @@ DEFINE_TEST(test_entry)
|
||||
archive_entry_set_mtime(e, 13581, 24682);
|
||||
assertEqualInt(archive_entry_mtime(e), 13581);
|
||||
assertEqualInt(archive_entry_mtime_nsec(e), 24682);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/* nlink */
|
||||
archive_entry_set_nlink(e, 736);
|
||||
assertEqualInt(archive_entry_nlink(e), 736);
|
||||
#else
|
||||
skipping("archive_entry_nlink()");
|
||||
#endif
|
||||
/* pathname */
|
||||
archive_entry_set_pathname(e, "path");
|
||||
assertEqualString(archive_entry_pathname(e), "path");
|
||||
@ -134,9 +151,13 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualWString(archive_entry_pathname_w(e), L"wpath");
|
||||
memset(wbuff, 0, sizeof(wbuff));
|
||||
assertEqualWString(archive_entry_pathname_w(e), L"wpath");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/* rdev */
|
||||
archive_entry_set_rdev(e, 532);
|
||||
assertEqualInt(archive_entry_rdev(e), 532);
|
||||
#else
|
||||
skipping("archive_entry_rdev()");
|
||||
#endif
|
||||
/* rdevmajor/rdevminor are tested specially below. */
|
||||
/* size */
|
||||
archive_entry_set_size(e, 987654321);
|
||||
@ -144,11 +165,13 @@ DEFINE_TEST(test_entry)
|
||||
/* symlink */
|
||||
archive_entry_set_symlink(e, "symlinkname");
|
||||
assertEqualString(archive_entry_symlink(e), "symlinkname");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
strcpy(buff, "symlinkname2");
|
||||
archive_entry_copy_symlink(e, buff);
|
||||
assertEqualString(archive_entry_symlink(e), "symlinkname2");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
assertEqualString(archive_entry_symlink(e), "symlinkname2");
|
||||
#endif
|
||||
archive_entry_copy_symlink_w(e, L"wsymlink");
|
||||
assertEqualWString(archive_entry_symlink_w(e), L"wsymlink");
|
||||
/* uid */
|
||||
@ -212,17 +235,25 @@ DEFINE_TEST(test_entry)
|
||||
archive_entry_clear(e);
|
||||
archive_entry_set_atime(e, 13579, 24680);
|
||||
archive_entry_set_ctime(e, 13580, 24681);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_dev(e, 235);
|
||||
#endif
|
||||
archive_entry_set_fflags(e, 0x55, 0xAA);
|
||||
archive_entry_set_gid(e, 204);
|
||||
archive_entry_set_gname(e, "group");
|
||||
archive_entry_set_hardlink(e, "hardlinkname");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_ino(e, 8593);
|
||||
#endif
|
||||
archive_entry_set_mode(e, 0123456);
|
||||
archive_entry_set_mtime(e, 13581, 24682);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_nlink(e, 736);
|
||||
#endif
|
||||
archive_entry_set_pathname(e, "path");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_rdev(e, 532);
|
||||
#endif
|
||||
archive_entry_set_size(e, 987654321);
|
||||
archive_entry_set_symlink(e, "symlinkname");
|
||||
archive_entry_set_uid(e, 83);
|
||||
@ -241,26 +272,37 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(archive_entry_atime_nsec(e2), 24680);
|
||||
assertEqualInt(archive_entry_ctime(e2), 13580);
|
||||
assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_dev(e2), 235);
|
||||
#endif
|
||||
archive_entry_fflags(e, &set, &clear);
|
||||
assertEqualInt(clear, 0xAA);
|
||||
assertEqualInt(set, 0x55);
|
||||
assertEqualInt(archive_entry_gid(e2), 204);
|
||||
assertEqualString(archive_entry_gname(e2), "group");
|
||||
assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_ino(e2), 8593);
|
||||
#endif
|
||||
assertEqualInt(archive_entry_mode(e2), 0123456);
|
||||
assertEqualInt(archive_entry_mtime(e2), 13581);
|
||||
assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_nlink(e2), 736);
|
||||
#endif
|
||||
assertEqualString(archive_entry_pathname(e2), "path");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_rdev(e2), 532);
|
||||
#endif
|
||||
assertEqualInt(archive_entry_size(e2), 987654321);
|
||||
assertEqualString(archive_entry_symlink(e2), "symlinkname");
|
||||
assertEqualInt(archive_entry_uid(e2), 83);
|
||||
assertEqualString(archive_entry_uname(e2), "user");
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("ACL preserved by archive_entry_clone()");
|
||||
#else
|
||||
/* Verify ACL was copied. */
|
||||
assertEqualInt(4, archive_entry_acl_reset(e2,
|
||||
assertEqualInt(4, c = archive_entry_acl_reset(e2,
|
||||
ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
|
||||
/* First three are standard permission bits. */
|
||||
assertEqualInt(0, archive_entry_acl_next(e2,
|
||||
@ -296,28 +338,43 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
|
||||
assertEqualInt(qual, 77);
|
||||
assertEqualString(name, "user77");
|
||||
#endif
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("xattr data preserved by archive_entry_clone");
|
||||
#else
|
||||
/* Verify xattr was copied. */
|
||||
assertEqualInt(1, archive_entry_xattr_reset(e2));
|
||||
assertEqualInt(1, c = archive_entry_xattr_reset(e2));
|
||||
assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize));
|
||||
assertEqualString(xname, "xattr1");
|
||||
assertEqualString(xval, "xattrvalue");
|
||||
assertEqualInt(xsize, 11);
|
||||
#endif
|
||||
|
||||
/* Change the original */
|
||||
archive_entry_set_atime(e, 13580, 24690);
|
||||
archive_entry_set_ctime(e, 13590, 24691);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_dev(e, 245);
|
||||
#endif
|
||||
archive_entry_set_fflags(e, 0x85, 0xDA);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_filetype(e, AE_IFLNK);
|
||||
#endif
|
||||
archive_entry_set_gid(e, 214);
|
||||
archive_entry_set_gname(e, "grouper");
|
||||
archive_entry_set_hardlink(e, "hardlinkpath");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_ino(e, 8763);
|
||||
#endif
|
||||
archive_entry_set_mode(e, 0123654);
|
||||
archive_entry_set_mtime(e, 18351, 28642);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_nlink(e, 73);
|
||||
#endif
|
||||
archive_entry_set_pathname(e, "pathest");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_rdev(e, 132);
|
||||
#endif
|
||||
archive_entry_set_size(e, 987456321);
|
||||
archive_entry_set_symlink(e, "symlinkpath");
|
||||
archive_entry_set_uid(e, 93);
|
||||
@ -330,26 +387,37 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(archive_entry_atime_nsec(e2), 24680);
|
||||
assertEqualInt(archive_entry_ctime(e2), 13580);
|
||||
assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_dev(e2), 235);
|
||||
#endif
|
||||
archive_entry_fflags(e2, &set, &clear);
|
||||
assertEqualInt(clear, 0xAA);
|
||||
assertEqualInt(set, 0x55);
|
||||
assertEqualInt(archive_entry_gid(e2), 204);
|
||||
assertEqualString(archive_entry_gname(e2), "group");
|
||||
assertEqualString(archive_entry_hardlink(e2), "hardlinkname");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_ino(e2), 8593);
|
||||
#endif
|
||||
assertEqualInt(archive_entry_mode(e2), 0123456);
|
||||
assertEqualInt(archive_entry_mtime(e2), 13581);
|
||||
assertEqualInt(archive_entry_mtime_nsec(e2), 24682);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_nlink(e2), 736);
|
||||
#endif
|
||||
assertEqualString(archive_entry_pathname(e2), "path");
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_rdev(e2), 532);
|
||||
#endif
|
||||
assertEqualInt(archive_entry_size(e2), 987654321);
|
||||
assertEqualString(archive_entry_symlink(e2), "symlinkname");
|
||||
assertEqualInt(archive_entry_uid(e2), 83);
|
||||
assertEqualString(archive_entry_uname(e2), "user");
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("ACL held by clone of archive_entry");
|
||||
#else
|
||||
/* Verify ACL was unchanged. */
|
||||
assertEqualInt(4, archive_entry_acl_reset(e2,
|
||||
assertEqualInt(4, c = archive_entry_acl_reset(e2,
|
||||
ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
|
||||
/* First three are standard permission bits. */
|
||||
assertEqualInt(0, archive_entry_acl_next(e2,
|
||||
@ -385,8 +453,13 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER);
|
||||
assertEqualInt(qual, 77);
|
||||
assertEqualString(name, "user77");
|
||||
#endif
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("xattr preserved in archive_entry copy");
|
||||
#else
|
||||
/* Verify xattr was unchanged. */
|
||||
assertEqualInt(1, archive_entry_xattr_reset(e2));
|
||||
#endif
|
||||
|
||||
/* Release clone. */
|
||||
archive_entry_free(e2);
|
||||
@ -403,7 +476,9 @@ DEFINE_TEST(test_entry)
|
||||
archive_entry_fflags(e, &set, &clear);
|
||||
assertEqualInt(clear, 0);
|
||||
assertEqualInt(set, 0);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_filetype(e), 0);
|
||||
#endif
|
||||
assertEqualInt(archive_entry_gid(e), 0);
|
||||
assertEqualString(archive_entry_gname(e), NULL);
|
||||
assertEqualString(archive_entry_hardlink(e), NULL);
|
||||
@ -411,7 +486,9 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(archive_entry_mode(e), 0);
|
||||
assertEqualInt(archive_entry_mtime(e), 0);
|
||||
assertEqualInt(archive_entry_mtime_nsec(e), 0);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_nlink(e), 0);
|
||||
#endif
|
||||
assertEqualString(archive_entry_pathname(e), NULL);
|
||||
assertEqualInt(archive_entry_rdev(e), 0);
|
||||
assertEqualInt(archive_entry_size(e), 0);
|
||||
@ -455,7 +532,9 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(archive_entry_ino(e), 234);
|
||||
assertEqualInt(archive_entry_mode(e), 077777);
|
||||
assertEqualInt(archive_entry_mtime(e), 234567);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(archive_entry_nlink(e), 345);
|
||||
#endif
|
||||
assertEqualInt(archive_entry_size(e), 123456789);
|
||||
assertEqualInt(archive_entry_uid(e), 23);
|
||||
#if __FreeBSD__
|
||||
@ -474,13 +553,19 @@ DEFINE_TEST(test_entry)
|
||||
/* Set a bunch of fields individually. */
|
||||
archive_entry_set_atime(e, 456789, 321);
|
||||
archive_entry_set_ctime(e, 345678, 432);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_dev(e, 123);
|
||||
#endif
|
||||
archive_entry_set_gid(e, 34);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_ino(e, 234);
|
||||
#endif
|
||||
archive_entry_set_mode(e, 012345);
|
||||
archive_entry_set_mode(e, 012345);
|
||||
archive_entry_set_mtime(e, 234567, 543);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_nlink(e, 345);
|
||||
#endif
|
||||
archive_entry_set_size(e, 123456789);
|
||||
archive_entry_set_uid(e, 23);
|
||||
/* Retrieve a stat structure. */
|
||||
@ -488,12 +573,18 @@ DEFINE_TEST(test_entry)
|
||||
/* Check that the values match. */
|
||||
assertEqualInt(pst->st_atime, 456789);
|
||||
assertEqualInt(pst->st_ctime, 345678);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(pst->st_dev, 123);
|
||||
#endif
|
||||
assertEqualInt(pst->st_gid, 34);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(pst->st_ino, 234);
|
||||
#endif
|
||||
assertEqualInt(pst->st_mode, 012345);
|
||||
assertEqualInt(pst->st_mtime, 234567);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
assertEqualInt(pst->st_nlink, 345);
|
||||
#endif
|
||||
assertEqualInt(pst->st_size, 123456789);
|
||||
assertEqualInt(pst->st_uid, 23);
|
||||
#ifdef __FreeBSD__
|
||||
@ -510,24 +601,30 @@ DEFINE_TEST(test_entry)
|
||||
archive_entry_set_ctime(e, 345677, 431);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_ctime, 345677);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_dev(e, 122);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_dev, 122);
|
||||
#endif
|
||||
archive_entry_set_gid(e, 33);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_gid, 33);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_ino(e, 233);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_ino, 233);
|
||||
#endif
|
||||
archive_entry_set_mode(e, 012344);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_mode, 012344);
|
||||
archive_entry_set_mtime(e, 234566, 542);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_mtime, 234566);
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_nlink(e, 344);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_nlink, 344);
|
||||
#endif
|
||||
archive_entry_set_size(e, 123456788);
|
||||
assert((pst = archive_entry_stat(e)) != NULL);
|
||||
assertEqualInt(pst->st_size, 123456788);
|
||||
@ -551,6 +648,7 @@ DEFINE_TEST(test_entry)
|
||||
* the necessary definitions on every platform.
|
||||
*/
|
||||
#if __FreeBSD__
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
archive_entry_set_dev(e, 0x12345678);
|
||||
assertEqualInt(archive_entry_devmajor(e), major(0x12345678));
|
||||
assertEqualInt(archive_entry_devminor(e), minor(0x12345678));
|
||||
@ -569,6 +667,7 @@ DEFINE_TEST(test_entry)
|
||||
assertEqualInt(archive_entry_rdevmajor(e), 0xfe);
|
||||
assertEqualInt(archive_entry_rdevminor(e), 0xdcba98);
|
||||
assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Release the experimental entry. */
|
||||
|
@ -34,6 +34,9 @@ static unsigned char archive[] = {
|
||||
|
||||
DEFINE_TEST(test_read_compress_program)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("archive_read_support_compression_program()");
|
||||
#else
|
||||
struct archive_entry *ae;
|
||||
struct archive *a;
|
||||
assert((a = archive_read_new()) != NULL);
|
||||
@ -50,6 +53,7 @@ DEFINE_TEST(test_read_compress_program)
|
||||
#else
|
||||
archive_read_finish(a);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "test.h"
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/*
|
||||
* This "archive" is created by "GNU ar". Here we try to verify
|
||||
* our GNU format handling functionality.
|
||||
@ -54,9 +55,13 @@ static unsigned char archive[] = {
|
||||
'2','1',10};
|
||||
|
||||
char buff[64];
|
||||
#endif
|
||||
|
||||
DEFINE_TEST(test_read_format_ar)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("test_read_support_format_ar()");
|
||||
#else
|
||||
struct archive_entry *ae;
|
||||
struct archive *a;
|
||||
assert((a = archive_read_new()) != NULL);
|
||||
@ -112,4 +117,5 @@ DEFINE_TEST(test_read_format_ar)
|
||||
#else
|
||||
archive_read_finish(a);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ static unsigned char archive_old[] = {
|
||||
204,198,'g',1,'\\',3,213,'A','"',245,141,28,5,'#',8,140,166,159,'Q','0',10,
|
||||
'F',193,'(',24,24,0,0,'}','}',226,185,0,10,0,0};
|
||||
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
/* libarchive < 1.9 doesn't support these. */
|
||||
|
||||
/* GNU tar "0.0" posix format, as written by GNU tar 1.15.1. */
|
||||
static unsigned char archive_0_0[] = {
|
||||
31,139,8,0,171,221,'l','F',0,3,237,147,193,'N',195,'0',12,134,'s',206,'S',
|
||||
@ -95,13 +98,19 @@ static unsigned char archive_1_0[] = {
|
||||
132,'k','7',192,204,26,'~','?',12,195,'0',12,'s','y','>',0,244,'|','e',9,
|
||||
0,18,0,0};
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
test_data(const char *buff, int buff_size,
|
||||
int start_index, int data_index, const char *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
failure("This is known broken in libarchive 1.x < 1.9 and 2.x < 2.2");
|
||||
assert(buff_size > data_index - start_index);
|
||||
/* If the above fails, we can't test the actual contents. */
|
||||
if (buff_size < data_index - start_index)
|
||||
return;
|
||||
for (i = 0; i < data_index - start_index; i++)
|
||||
assert(buff[i] == 0);
|
||||
assert(0 == memcmp(buff + (data_index - start_index), data, strlen(data)));
|
||||
@ -132,8 +141,13 @@ verify_archive(void *b, size_t l)
|
||||
assertEqualIntA(a, ARCHIVE_EOF, archive_read_data_block(a, &d, &s, &o));
|
||||
failure("Size returned at EOF must be zero");
|
||||
assertEqualInt(s, 0);
|
||||
failure("Offset at EOF must be same as file size");
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
/* libarchive < 1.9 doesn't get this right */
|
||||
skipping("offset of final sparse chunk");
|
||||
#else
|
||||
failure("Offset of final empty chunk must be same as file size");
|
||||
assertEqualInt(o, 3145728);
|
||||
#endif
|
||||
|
||||
assert(0 == archive_read_close(a));
|
||||
#if ARCHIVE_API_VERSION > 1
|
||||
@ -146,9 +160,26 @@ verify_archive(void *b, size_t l)
|
||||
DEFINE_TEST(test_read_format_gtar_sparse)
|
||||
{
|
||||
verify_archive(archive_old, sizeof(archive_old));
|
||||
|
||||
/*
|
||||
* libarchive < 1.9 doesn't support the newer sparse formats
|
||||
* from GNU tar 1.15 and 1.16.
|
||||
*/
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("read support for GNUtar sparse format 0.0");
|
||||
#else
|
||||
verify_archive(archive_0_0, sizeof(archive_0_0));
|
||||
#endif
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("read support for GNUtar sparse format 0.1");
|
||||
#else
|
||||
verify_archive(archive_0_1, sizeof(archive_0_1));
|
||||
#endif
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("read support for GNUtar sparse format 1.0");
|
||||
#else
|
||||
verify_archive(archive_1_0, sizeof(archive_1_0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,6 +42,9 @@ test_filename(const char *prefix, int dlen, int flen)
|
||||
size_t used;
|
||||
size_t prefix_length = 0;
|
||||
int i = 0;
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
static int bug_reported_1 = 0, bug_reported_2 = 0, bug_reported_3 = 0;
|
||||
#endif
|
||||
|
||||
if (prefix) {
|
||||
strcpy(filename, prefix);
|
||||
@ -114,8 +117,14 @@ test_filename(const char *prefix, int dlen, int flen)
|
||||
|
||||
/* Read the file and check the filename. */
|
||||
assertA(0 == archive_read_next_header(a, &ae));
|
||||
failure("Pathname %d/%d: %s", dlen, flen, archive_entry_pathname(ae));
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
if (!bug_reported_3) {
|
||||
skipping("Leading '/' preserved on long filenames");
|
||||
++bug_reported_3;
|
||||
}
|
||||
#else
|
||||
assertEqualString(filename, archive_entry_pathname(ae));
|
||||
#endif
|
||||
assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae));
|
||||
|
||||
/*
|
||||
@ -123,16 +132,29 @@ test_filename(const char *prefix, int dlen, int flen)
|
||||
*
|
||||
* Both dirs should read back with the same name, since
|
||||
* tar should add a trailing '/' to any dir that doesn't
|
||||
* already have one.
|
||||
* already have one. We only report the first such failure
|
||||
* here.
|
||||
*/
|
||||
assertA(0 == archive_read_next_header(a, &ae));
|
||||
failure("Pathname %d/%d: %s", dlen, flen, archive_entry_pathname(ae));
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
if (!bug_reported_2) {
|
||||
skipping("Trailing '/' preserved on dirnames");
|
||||
++bug_reported_2;
|
||||
}
|
||||
#else
|
||||
assertEqualString(dirname, archive_entry_pathname(ae));
|
||||
#endif
|
||||
assert((S_IFDIR | 0755) == archive_entry_mode(ae));
|
||||
|
||||
assertA(0 == archive_read_next_header(a, &ae));
|
||||
failure("Pathname %d/%d: %s", dlen, flen, archive_entry_pathname(ae));
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
if (!bug_reported_1) {
|
||||
skipping("Trailing '/' added to dir names");
|
||||
++bug_reported_1;
|
||||
}
|
||||
#else
|
||||
assertEqualString(dirname, archive_entry_pathname(ae));
|
||||
#endif
|
||||
assert((S_IFDIR | 0755) == archive_entry_mode(ae));
|
||||
|
||||
/* Verify the end of the archive. */
|
||||
|
@ -30,6 +30,9 @@ char buff2[64];
|
||||
|
||||
DEFINE_TEST(test_write_compress_program)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("archive_write_set_compress_program()");
|
||||
#else
|
||||
struct archive_entry *ae;
|
||||
struct archive *a;
|
||||
size_t used;
|
||||
@ -94,4 +97,5 @@ DEFINE_TEST(test_write_compress_program)
|
||||
#else
|
||||
archive_read_finish(a);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "test.h"
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
|
||||
#define UMASK 022
|
||||
|
||||
static void create(struct archive_entry *ae, const char *msg)
|
||||
@ -48,9 +50,13 @@ static void create(struct archive_entry *ae, const char *msg)
|
||||
st.st_mode, archive_entry_mode(ae));
|
||||
assert(st.st_mode == (archive_entry_mode(ae) & ~UMASK));
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_TEST(test_write_disk)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("archive_write_disk interface");
|
||||
#else
|
||||
struct archive_entry *ae;
|
||||
|
||||
/* Force the umask to something predictable. */
|
||||
@ -90,4 +96,5 @@ DEFINE_TEST(test_write_disk)
|
||||
archive_entry_set_mode(ae, S_IFREG | 0744);
|
||||
create(ae, "Test creating a file over an existing dir.");
|
||||
archive_entry_free(ae);
|
||||
#endif
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "test.h"
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
|
||||
#define UMASK 022
|
||||
|
||||
static long _default_gid = -1;
|
||||
@ -113,6 +115,7 @@ defaultgid(void)
|
||||
searchgid();
|
||||
return (_default_gid);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exercise permission and ownership restores.
|
||||
@ -122,6 +125,9 @@ defaultgid(void)
|
||||
|
||||
DEFINE_TEST(test_write_disk_perms)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("archive_write_disk interface");
|
||||
#else
|
||||
struct archive *a;
|
||||
struct archive_entry *ae;
|
||||
struct stat st;
|
||||
@ -390,5 +396,5 @@ DEFINE_TEST(test_write_disk_perms)
|
||||
* not root, we should not have been able to set that. */
|
||||
assert(st.st_uid == getuid());
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
DEFINE_TEST(test_write_disk_secure)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("archive_write_disk interface");
|
||||
#else
|
||||
struct archive *a;
|
||||
struct archive_entry *ae;
|
||||
struct stat st;
|
||||
@ -140,4 +143,5 @@ DEFINE_TEST(test_write_disk_secure)
|
||||
assert(S_ISREG(st.st_mode));
|
||||
failure("link_to_dir2/filec: st.st_mode=%o", st.st_mode);
|
||||
assert((st.st_mode & 07777) == 0755);
|
||||
#endif
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ static unsigned char strtab[] = "abcdefghijklmn.o/\nggghhhjjjrrrttt.o/\niiijjjdd
|
||||
|
||||
DEFINE_TEST(test_write_format_ar)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
skipping("ar write support");
|
||||
#else
|
||||
struct archive_entry *ae;
|
||||
struct archive* a;
|
||||
size_t used;
|
||||
@ -101,7 +104,7 @@ DEFINE_TEST(test_write_format_ar)
|
||||
archive_write_close(a);
|
||||
#if ARCHIVE_API_VERSION > 1
|
||||
assert(0 == archive_write_finish(a));
|
||||
#elif
|
||||
#else
|
||||
archive_write_finish(a);
|
||||
#endif
|
||||
|
||||
@ -175,7 +178,7 @@ DEFINE_TEST(test_write_format_ar)
|
||||
archive_write_close(a);
|
||||
#if ARCHIVE_API_VERSION > 1
|
||||
assert(0 == archive_write_finish(a));
|
||||
#elif
|
||||
#else
|
||||
archive_write_finish(a);
|
||||
#endif
|
||||
|
||||
@ -205,4 +208,5 @@ DEFINE_TEST(test_write_format_ar)
|
||||
#else
|
||||
archive_read_finish(a);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "test.h"
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/* The version stamp macro was introduced after cpio write support. */
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
static void
|
||||
test_format(int (*set_format)(struct archive *))
|
||||
{
|
||||
@ -104,9 +106,14 @@ test_format(int (*set_format)(struct archive *))
|
||||
|
||||
free(buff);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_TEST(test_write_format_cpio)
|
||||
{
|
||||
#if ARCHIVE_VERSION_STAMP >= 1009000
|
||||
test_format(archive_write_set_format_cpio);
|
||||
test_format(archive_write_set_format_cpio_newc);
|
||||
#else
|
||||
skipping("cpio write support");
|
||||
#endif
|
||||
}
|
||||
|
@ -52,8 +52,12 @@ DEFINE_TEST(test_write_format_tar_empty)
|
||||
archive_write_finish(a);
|
||||
#endif
|
||||
|
||||
failure("Empty tar archive should be exactly 1024 bytes, was %d.", used);
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
/* Earlier versions wrote 0-length files for empty tar archives. */
|
||||
skipping("empty tar archive size");
|
||||
#else
|
||||
assert(used == 1024);
|
||||
#endif
|
||||
for (i = 0; i < used; i++) {
|
||||
failure("Empty tar archive should be all nulls.");
|
||||
assert(buff[i] == 0);
|
||||
@ -75,8 +79,12 @@ DEFINE_TEST(test_write_format_tar_empty)
|
||||
archive_write_finish(a);
|
||||
#endif
|
||||
|
||||
failure("Empty tar archive should be exactly 1024 bytes, was %d.", used);
|
||||
assert(used == 1024);
|
||||
#if ARCHIVE_VERSION_STAMP < 1009000
|
||||
/* Earlier versions wrote 0-length files for empty tar archives. */
|
||||
skipping("empty tar archive size");
|
||||
#else
|
||||
assertEqualInt(used, 1024);
|
||||
#endif
|
||||
for (i = 0; i < used; i++) {
|
||||
failure("Empty tar archive should be all nulls.");
|
||||
assert(buff[i] == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user