summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2017-02-26 01:17:54 +0100
committerMartin Matuska <martin@matuska.org>2017-02-26 01:39:08 +0100
commitbe3e97ea862ba2d580d3da51d6ddf35f9304d99b (patch)
tree32f1ba575accea9b72cb123f9732413611ee70b9 /test_utils
parent077245ae42920b4de3d682617158e9bb85ac3be0 (diff)
downloadlibarchive-be3e97ea862ba2d580d3da51d6ddf35f9304d99b.tar.gz
bsdtar tests: add test_option_fflags
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/test_common.h9
-rw-r--r--test_utils/test_main.c72
2 files changed, 77 insertions, 4 deletions
diff --git a/test_utils/test_common.h b/test_utils/test_common.h
index 82e8483f..ce06f4e9 100644
--- a/test_utils/test_common.h
+++ b/test_utils/test_common.h
@@ -239,8 +239,10 @@
assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
#define assertMakeSymlink(newfile, linkto) \
assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
-#define assertNodump(path) \
- assertion_nodump(__FILE__, __LINE__, path)
+#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)
#define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec) \
@@ -286,6 +288,7 @@ 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 *);
@@ -295,8 +298,8 @@ int assertion_make_dir(const char *, int, const char *, int);
int assertion_make_file(const char *, int, const char *, int, int, const void *);
int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
int assertion_make_symlink(const char *, int, const char *newpath, const char *);
-int assertion_nodump(const char *, int, const char *);
int assertion_non_empty_file(const char *, int, const char *);
+int assertion_set_nodump(const char *, int, const char *);
int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
int assertion_umask(const char *, int, int);
int assertion_utimes(const char *, int, const char *, long, long, long, long );
diff --git a/test_utils/test_main.c b/test_utils/test_main.c
index 2ae6b38d..a50ed23f 100644
--- a/test_utils/test_main.c
+++ b/test_utils/test_main.c
@@ -1882,10 +1882,80 @@ assertion_utimes(const char *file, int line,
return (1);
#endif /* defined(_WIN32) && !defined(__CYGWIN__) */
}
+/* Get nodump. */
+int
+assertion_has_nodump(const char *file, int line, const char *pathname, int isset)
+{
+#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
+ struct stat sb;
+
+ assertion_count(file, line);
+
+ if (stat(pathname, &sb) < 0)
+ 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;
+
+ assertion_count(file, line);
+ fd = open(pathname, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ failure_start(file, line, "Can't open %s\n", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+ r = ioctl(fd,
+#ifdef FS_IOC_GETFLAGS
+ FS_IOC_GETFLAGS,
+#else
+ EXT2_IOC_GETFLAGS,
+#endif
+ &flags);
+ if (r < 0) {
+ failure_start(file, line, "Can't get flags %s\n", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+#ifdef FS_NODUMP_FL
+ if (flags & FS_NODUMP_FL)
+#else
+ if (flags & EXT2_NODUMP_FL)
+#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);
+ }
+ }
+#else
+ (void)pathname; /* UNUSED */
+ (void)isset; /* UNUSED */
+ assertion_count(file, line);
+#endif
+ return (1);
+}
/* Set nodump, report failures. */
int
-assertion_nodump(const char *file, int line, const char *pathname)
+assertion_set_nodump(const char *file, int line, const char *pathname)
{
#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
int r;