]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Synchronize the test harnesses and force atime tests to always pass
authorTim Kientzle <kientzle@gmail.com>
Sat, 31 Oct 2009 17:14:50 +0000 (13:14 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 31 Oct 2009 17:14:50 +0000 (13:14 -0400)
on Haiku (which doesn't support atime).

SVN-Revision: 1552

cpio/test/main.c
libarchive/test/main.c
tar/test/main.c

index 278deb64c579980fc0381d2bdc915253308f5ec2..2091b52255a0841f8d06ea8324c2346ccaa933c1 100644 (file)
@@ -279,7 +279,7 @@ failure_start(const char *filename, int line, const char *fmt, ...)
 
        /* Record another failure for this line. */
        ++failures;
-       test_filename = filename;
+       /* test_filename = filename; */
        failed_lines[line].count++;
 
        /* Determine whether to log header to console. */
@@ -407,9 +407,11 @@ assertion_equal_int(const char *file, int line,
 
 static void strdump(const char *e, const char *p)
 {
+       const char *q = p;
+
        logprintf("      %s = ", e);
        if (p == NULL) {
-               logprintf("(null)");
+               logprintf("NULL");
                return;
        }
        logprintf("\"");
@@ -428,7 +430,7 @@ static void strdump(const char *e, const char *p)
                }
        }
        logprintf("\"");
-       logprintf(" (length %d)\n", p == NULL ? 0 : (int)strlen(p));
+       logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q));
 }
 
 /* Verify two strings are equal, dump them if not. */
@@ -439,7 +441,7 @@ assertion_equal_string(const char *file, int line,
     void *extra)
 {
        assertion_count(file, line);
-       if (v1 == v2 || strcmp(v1, v2) == 0)
+       if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0))
                return (1);
        failure_start(file, line, "%s != %s", e1, e2);
        strdump(e1, v1);
@@ -499,6 +501,10 @@ hexdump(const char *p, const char *ref, size_t l, size_t offset)
        size_t i, j;
        char sep;
 
+       if (p == NULL) {
+               logprintf("(null)\n");
+               return;
+       }
        for(i=0; i < l; i+=16) {
                logprintf("%04x", (unsigned)(i + offset));
                sep = ' ';
@@ -538,7 +544,7 @@ assertion_equal_mem(const char *file, int line,
        size_t offset;
 
        assertion_count(file, line);
-       if (v1 == v2 || memcmp(v1, v2, l) == 0)
+       if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
                return (1);
 
        failure_start(file, line, "%s != %s", e1, e2);
@@ -750,10 +756,10 @@ assertion_file_contents(const void *buff, int s, const char *fpattern, ...)
        failure_start(test_filename, test_line, "File contents don't match");
        logprintf("  file=\"%s\"\n", fn);
        if (n > 0)
-               hexdump(contents, buff, n > 512 ? 512 : 0, 0);
+               hexdump(contents, buff, n > 512 ? 512 : n, 0);
        else {
                logprintf("  File empty, contents should be:\n");
-               hexdump(buff, NULL, s > 512 ? 512 : 0, 0);
+               hexdump(buff, NULL, s > 512 ? 512 : n, 0);
        }
        failure_finish(test_extra);
        free(contents);
@@ -956,6 +962,9 @@ assertion_file_time(const char *file, int line,
 #else
        filet_nsec = nsec = 0;  /* Generic POSIX only has whole seconds. */
        if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */
+#if defined(__HAIKU__)
+       if (type == 'a') return (1); /* Haiku doesn't have atime. */
+#endif
 #endif
 #endif
        if (recent) {
@@ -1157,6 +1166,9 @@ is_symlink(const char *file, int line,
 {
 #if defined(_WIN32) && !defined(__CYGWIN__)
        assertion_count(file, line);
+       /* Windows sort-of has real symlinks, but they're only usable
+        * by privileged users and are crippled even then, so there's
+        * really not much point in bothering with this. */
        return (0);
 #else
        char buff[300];
@@ -1341,6 +1353,13 @@ assertion_umask(const char *file, int line, int mask)
  * for tests to use in deciding whether to bother testing symlink
  * support; if the platform doesn't support symlinks, there's no point
  * in checking whether the program being tested can create them.
+ *
+ * Note that the first time this test is called, we actually go out to
+ * disk to create and verify a symlink.  This is necessary because
+ * symlink support is actually a property of a particular filesystem
+ * and can thus vary between directories on a single system.  After
+ * the first call, this returns the cached result from memory, so it's
+ * safe to call it as often as you wish.
  */
 int
 canSymlink(void)
@@ -1352,6 +1371,8 @@ canSymlink(void)
 
        ++tested;
        assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a");
+       /* Note: Cygwin has its own symlink() emulation that does not
+        * use the Win32 CreateSymbolicLink() function. */
 #if defined(_WIN32) && !defined(__CYGWIN__)
        value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0)
            && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0");
index 4bcec392d0aafb5e33076717cb86504bade138fb..1b0a8cca684346bd3f0553ec6c16ef30675cc4d9 100644 (file)
@@ -91,6 +91,7 @@ __FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.17 2008/12/21 00:13:50 ki
 #define rmdir _rmdir
 #define strdup _strdup
 #define umask _umask
+#define int64_t __int64
 #endif
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
@@ -139,6 +140,7 @@ my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi)
        HANDLE h;
        int r;
 
+       memset(bhfi, 0, sizeof(*bhfi));
        h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL,
                OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (h == INVALID_HANDLE_VALUE)
@@ -276,7 +278,7 @@ failure_start(const char *filename, int line, const char *fmt, ...)
 
        /* Record another failure for this line. */
        ++failures;
-       test_filename = filename;
+       /* test_filename = filename; */
        failed_lines[line].count++;
 
        /* Determine whether to log header to console. */
@@ -404,9 +406,11 @@ assertion_equal_int(const char *file, int line,
 
 static void strdump(const char *e, const char *p)
 {
+       const char *q = p;
+
        logprintf("      %s = ", e);
        if (p == NULL) {
-               logprintf("(null)\n");
+               logprintf("NULL");
                return;
        }
        logprintf("\"");
@@ -425,7 +429,7 @@ static void strdump(const char *e, const char *p)
                }
        }
        logprintf("\"");
-       logprintf(" (length %d)\n", p == NULL ? 0 : (int)strlen(p));
+       logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q));
 }
 
 /* Verify two strings are equal, dump them if not. */
@@ -751,10 +755,10 @@ assertion_file_contents(const void *buff, int s, const char *fpattern, ...)
        failure_start(test_filename, test_line, "File contents don't match");
        logprintf("  file=\"%s\"\n", fn);
        if (n > 0)
-               hexdump(contents, buff, n > 512 ? 512 : 0, 0);
+               hexdump(contents, buff, n > 512 ? 512 : n, 0);
        else {
                logprintf("  File empty, contents should be:\n");
-               hexdump(buff, NULL, s > 512 ? 512 : 0, 0);
+               hexdump(buff, NULL, s > 512 ? 512 : n, 0);
        }
        failure_finish(test_extra);
        free(contents);
@@ -835,7 +839,8 @@ is_hardlink(const char *file, int line,
                failure_finish(NULL);
                return (0);
        }
-       return (bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
+       return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber
+               && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
                && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow);
 #else
        struct stat st1, st2;
@@ -956,6 +961,9 @@ assertion_file_time(const char *file, int line,
 #else
        filet_nsec = nsec = 0;  /* Generic POSIX only has whole seconds. */
        if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */
+#if defined(__HAIKU__)
+       if (type == 'a') return (1); /* Haiku doesn't have atime. */
+#endif
 #endif
 #endif
        if (recent) {
@@ -1060,15 +1068,27 @@ assertion_file_nlinks(const char *file, int line,
 int
 assertion_file_size(const char *file, int line, const char *pathname, long size)
 {
-       struct stat st;
+       int64_t filesize;
        int r;
 
        assertion_count(file, line);
-       r = lstat(pathname, &st);
-       if (r == 0 && st.st_size == size)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       {
+               BY_HANDLE_FILE_INFORMATION bhfi;
+               r = !my_GetFileInformationByName(pathname, &bhfi);
+               filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow;
+       }
+#else
+       {
+               struct stat st;
+               r = lstat(pathname, &st);
+               filesize = st.st_size;
+       }
+#endif
+       if (r == 0 && filesize == size)
                        return (1);
        failure_start(file, line, "File %s has size %ld, expected %ld",
-           pathname, (long)st.st_size, (long)size);
+           pathname, (long)filesize, (long)size);
        failure_finish(NULL);
        return (0);
 }
@@ -1145,6 +1165,9 @@ is_symlink(const char *file, int line,
 {
 #if defined(_WIN32) && !defined(__CYGWIN__)
        assertion_count(file, line);
+       /* Windows sort-of has real symlinks, but they're only usable
+        * by privileged users and are crippled even then, so there's
+        * really not much point in bothering with this. */
        return (0);
 #else
        char buff[300];
@@ -1329,6 +1352,13 @@ assertion_umask(const char *file, int line, int mask)
  * for tests to use in deciding whether to bother testing symlink
  * support; if the platform doesn't support symlinks, there's no point
  * in checking whether the program being tested can create them.
+ *
+ * Note that the first time this test is called, we actually go out to
+ * disk to create and verify a symlink.  This is necessary because
+ * symlink support is actually a property of a particular filesystem
+ * and can thus vary between directories on a single system.  After
+ * the first call, this returns the cached result from memory, so it's
+ * safe to call it as often as you wish.
  */
 int
 canSymlink(void)
@@ -1340,6 +1370,8 @@ canSymlink(void)
 
        ++tested;
        assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a");
+       /* Note: Cygwin has its own symlink() emulation that does not
+        * use the Win32 CreateSymbolicLink() function. */
 #if defined(_WIN32) && !defined(__CYGWIN__)
        value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0)
            && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0");
index 416372c8a5b588a00e13457c5e1639d0493b47a1..daba4015b90f056d59388fed6b25cbb5ee726f4c 100644 (file)
@@ -80,6 +80,7 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.6 2008/11/05 06:40:53 kientz
 #define S_ISREG(m)  ((m) & _S_IFREG)
 #endif
 #define access _access
+#define chdir _chdir
 #ifndef fileno
 #define fileno _fileno
 #endif
@@ -91,6 +92,7 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.6 2008/11/05 06:40:53 kientz
 #define rmdir _rmdir
 #define strdup _strdup
 #define umask _umask
+#define int64_t __int64
 #endif
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
@@ -139,6 +141,7 @@ my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi)
        HANDLE h;
        int r;
 
+       memset(bhfi, 0, sizeof(*bhfi));
        h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL,
                OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (h == INVALID_HANDLE_VALUE)
@@ -438,7 +441,7 @@ assertion_equal_string(const char *file, int line,
     void *extra)
 {
        assertion_count(file, line);
-       if (v1 == v2 || strcmp(v1, v2) == 0)
+       if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0))
                return (1);
        failure_start(file, line, "%s != %s", e1, e2);
        strdump(e1, v1);
@@ -498,6 +501,10 @@ hexdump(const char *p, const char *ref, size_t l, size_t offset)
        size_t i, j;
        char sep;
 
+       if (p == NULL) {
+               logprintf("(null)\n");
+               return;
+       }
        for(i=0; i < l; i+=16) {
                logprintf("%04x", (unsigned)(i + offset));
                sep = ' ';
@@ -537,7 +544,7 @@ assertion_equal_mem(const char *file, int line,
        size_t offset;
 
        assertion_count(file, line);
-       if (v1 == v2 || memcmp(v1, v2, l) == 0)
+       if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
                return (1);
 
        failure_start(file, line, "%s != %s", e1, e2);
@@ -833,7 +840,8 @@ is_hardlink(const char *file, int line,
                failure_finish(NULL);
                return (0);
        }
-       return (bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
+       return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber
+               && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh
                && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow);
 #else
        struct stat st1, st2;
@@ -954,6 +962,9 @@ assertion_file_time(const char *file, int line,
 #else
        filet_nsec = nsec = 0;  /* Generic POSIX only has whole seconds. */
        if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */
+#if defined(__HAIKU__)
+       if (type == 'a') return (1); /* Haiku doesn't have atime. */
+#endif
 #endif
 #endif
        if (recent) {
@@ -1058,15 +1069,27 @@ assertion_file_nlinks(const char *file, int line,
 int
 assertion_file_size(const char *file, int line, const char *pathname, long size)
 {
-       struct stat st;
+       int64_t filesize;
        int r;
 
        assertion_count(file, line);
-       r = lstat(pathname, &st);
-       if (r == 0 && st.st_size == size)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       {
+               BY_HANDLE_FILE_INFORMATION bhfi;
+               r = !my_GetFileInformationByName(pathname, &bhfi);
+               filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow;
+       }
+#else
+       {
+               struct stat st;
+               r = lstat(pathname, &st);
+               filesize = st.st_size;
+       }
+#endif
+       if (r == 0 && filesize == size)
                        return (1);
        failure_start(file, line, "File %s has size %ld, expected %ld",
-           pathname, (long)st.st_size, (long)size);
+           pathname, (long)filesize, (long)size);
        failure_finish(NULL);
        return (0);
 }