summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2017-02-28 17:01:38 +0100
committerMartin Matuska <martin@matuska.org>2017-02-28 17:01:38 +0100
commit13e1442f6f7a61c7a43c5abbee6286b4830a639b (patch)
treee7b01ca7a5b3983ea7e0cecadeab794214e5e3c1 /test_utils
parentb5037bb961c38ce25f4254be3e110fe08bc7f7f7 (diff)
downloadlibarchive-13e1442f6f7a61c7a43c5abbee6286b4830a639b.tar.gz
Compare full file flags in test_option_fflags
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/test_common.h11
-rw-r--r--test_utils/test_main.c92
2 files changed, 66 insertions, 37 deletions
diff --git a/test_utils/test_common.h b/test_utils/test_common.h
index ce06f4e9..88ef04c3 100644
--- a/test_utils/test_common.h
+++ b/test_utils/test_common.h
@@ -158,6 +158,9 @@
/* chdir() and error if it fails */
#define assertChdir(path) \
assertion_chdir(__FILE__, __LINE__, path)
+/* Assert two files have the same file flags */
+#define assertEqualFflags(patha, pathb) \
+ assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 0)
/* Assert two integers are the same. Reports value of each one if not. */
#define assertEqualInt(v1,v2) \
assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
@@ -239,12 +242,13 @@
assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
#define assertMakeSymlink(newfile, linkto) \
assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
-#define assertHasNodump(path, isset) \
- assertion_has_nodump(__FILE__, __LINE__, path, isset)
#define assertSetNodump(path) \
assertion_set_nodump(__FILE__, __LINE__, path)
#define assertUmask(mask) \
assertion_umask(__FILE__, __LINE__, mask)
+/* Assert that two files have unequal file flags */
+#define assertUnequalFflags(patha, pathb) \
+ assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 1)
#define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec) \
assertion_utimes(__FILE__, __LINE__, pathname, atime, atime_nsec, mtime, mtime_nsec)
#ifndef PROGRAM
@@ -267,6 +271,8 @@
void failure(const char *fmt, ...);
int assertion_assert(const char *, int, int, const char *, void *);
int assertion_chdir(const char *, int, const char *);
+int assertion_compare_fflags(const char *, int, const char *, const char *,
+ int);
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 *);
@@ -288,7 +294,6 @@ int assertion_file_mtime_recent(const char *, int, const char *);
int assertion_file_nlinks(const char *, int, const char *, int);
int assertion_file_not_exists(const char *, int, const char *);
int assertion_file_size(const char *, int, const char *, long);
-int assertion_has_nodump(const char *, int, const char *, int);
int assertion_is_dir(const char *, int, const char *, int);
int assertion_is_hardlink(const char *, int, const char *, const char *);
int assertion_is_not_hardlink(const char *, int, const char *, const char *);
diff --git a/test_utils/test_main.c b/test_utils/test_main.c
index 8ae6c444..ec2fbfed 100644
--- a/test_utils/test_main.c
+++ b/test_utils/test_main.c
@@ -1882,34 +1882,45 @@ assertion_utimes(const char *file, int line,
return (1);
#endif /* defined(_WIN32) && !defined(__CYGWIN__) */
}
-/* Get nodump. */
+
+/* Compare file flags */
int
-assertion_has_nodump(const char *file, int line, const char *pathname, int isset)
+assertion_compare_fflags(const char *file, int line, const char *patha,
+ const char *pathb, int nomatch)
{
#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
- struct stat sb;
+ struct stat sa, sb;
assertion_count(file, line);
- if (stat(pathname, &sb) < 0)
+ if (stat(patha, &sa) < 0)
+ return (0);
+ if (stat(pathb, &sb) < 0)
+ return (0);
+ if (!nomatch && sa.st_flags != sb.st_flags) {
+ failure_start(file, line, "File flags should be identical: "
+ "%s=%#010x %s=%#010x", patha, sa.st_flags, pathb,
+ sb.st_flags);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (nomatch && sa.st_flags == sb.st_flags) {
+ failure_start(file, line, "File flags should be different: "
+ "%s=%#010x %s=%#010x", patha, sa.st_flags, pathb,
+ sb.st_flags);
+ failure_finish(NULL);
return (0);
- if (sb.st_flags & UF_NODUMP) {
- if (isset)
- return (1);
- } else {
- if (!isset)
- return (1);
}
#elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS) && \
defined(FS_NODUMP_FL)) || \
(defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS) \
&& defined(EXT2_NODUMP_FL))
- int fd, r, flags;
+ int fd, r, flagsa, flagsb;
assertion_count(file, line);
- fd = open(pathname, O_RDONLY | O_NONBLOCK);
+ fd = open(patha, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- failure_start(file, line, "Can't open %s\n", pathname);
+ failure_start(file, line, "Can't open %s\n", patha);
failure_finish(NULL);
return (0);
}
@@ -1919,35 +1930,48 @@ assertion_has_nodump(const char *file, int line, const char *pathname, int isset
#else
EXT2_IOC_GETFLAGS,
#endif
- &flags);
+ &flagsa);
+ close(fd);
if (r < 0) {
- failure_start(file, line, "Can't get flags %s\n", pathname);
+ failure_start(file, line, "Can't get flags %s\n", patha);
failure_finish(NULL);
return (0);
}
-#ifdef FS_NODUMP_FL
- if (flags & FS_NODUMP_FL)
+ fd = open(pathb, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ failure_start(file, line, "Can't open %s\n", pathb);
+ failure_finish(NULL);
+ return (0);
+ }
+ r = ioctl(fd,
+#ifdef FS_IOC_GETFLAGS
+ FS_IOC_GETFLAGS,
#else
- if (flags & EXT2_NODUMP_FL)
+ EXT2_IOC_GETFLAGS,
#endif
- {
- if (!isset) {
- failure_start(file, line,
- "Nodump flag should not be set on %s\n", pathname);
- failure_finish(NULL);
- return (0);
- }
- } else {
- if (isset) {
- failure_start(file, line,
- "Nodump flag should be set on %s\n", pathname);
- failure_finish(NULL);
- return (0);
- }
+ &flagsb);
+ close(fd);
+ if (r < 0) {
+ failure_start(file, line, "Can't get flags %s\n", pathb);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (!nomatch && flagsa != flagsb) {
+ failure_start(file, line, "File flags should be identical: "
+ "%s=%#010x %s=%#010x", patha, flagsa, pathb, flagsb);
+ failure_finish(NULL);
+ return (0);
+ }
+ if (nomatch && flagsa == flagsb) {
+ failure_start(file, line, "File flags should be different: "
+ "%s=%#010x %s=%#010x", patha, flagsa, pathb, flagsb);
+ failure_finish(NULL);
+ return (0);
}
#else
- (void)pathname; /* UNUSED */
- (void)isset; /* UNUSED */
+ (void)patha; /* UNUSED */
+ (void)pathb; /* UNUSED */
+ (void)nomatch; /* UNUSED */
assertion_count(file, line);
#endif
return (1);