apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r589929 - /apr/apr/trunk/test/testlfs.c
Date Tue, 30 Oct 2007 01:39:07 GMT
Author: wrowe
Date: Mon Oct 29 18:39:07 2007
New Revision: 589929

URL: http://svn.apache.org/viewvc?rev=589929&view=rev
Log:
Lots of testing on this first draft is needed.  Committing to make it easier
for myself and others to verify that these are good checks to determine if
we can use it.  I'd love if someone with zfs installed would check it out.


Modified:
    apr/apr/trunk/test/testlfs.c

Modified: apr/apr/trunk/test/testlfs.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testlfs.c?rev=589929&r1=589928&r2=589929&view=diff
==============================================================================
--- apr/apr/trunk/test/testlfs.c (original)
+++ apr/apr/trunk/test/testlfs.c Mon Oct 29 18:39:07 2007
@@ -24,21 +24,17 @@
 #include "apr_mmap.h"
 #include "testutil.h"
 
-/* XXX: bullshit - this condition needs to be made a feature-detect.
- * Only enable these tests by default on platforms which support sparse
- * files... just Unixes? */
-#if defined(OS2) || defined(NETWARE)
-static void test_nolfs(abts_case *tc, void *data)
-{
-    ABTS_NOT_IMPL(tc, "Large Files tests require Sparse file support");
-}
-#elif APR_HAS_LARGE_FILES
-#define USE_LFS_TESTS
+/* TODO: in 1.3.0 this becomes APR_HAS_SPARSE_FILES, HOWEVER we will
+ * still need to test csize before proceeding, because having sparse
+ * file support in the OS/APR does not mean this volume supports it!
+ */
+#if APR_HAS_LARGE_FILES
 
-/* Tests which create an 8Gb sparse file and then check it can be used
+/* Tests which create an 8GB sparse file and then check it can be used
  * as normal. */
 
-static apr_off_t eightGb = APR_INT64_C(2) << 32;
+static apr_off_t oneMB = APR_INT64_C(2) << 19;
+static apr_off_t eightGB = APR_INT64_C(2) << 32;
 
 static int madefile = 0;
 
@@ -51,6 +47,7 @@
 static void test_open(abts_case *tc, void *data)
 {
     apr_file_t *f;
+    apr_finfo_t testsize;
     apr_status_t rv;
 
     rv = apr_dir_make(TESTDIR, APR_OS_DEFAULT, p);
@@ -58,29 +55,57 @@
         APR_ASSERT_SUCCESS(tc, "make test directory", rv);
     }
 
+    /* First attempt a 1MB sparse file so we don't tax the poor test box */
+
     rv = apr_file_open(&f, TESTFN, APR_FOPEN_CREATE | APR_FOPEN_WRITE
                                  | APR_FOPEN_TRUNCATE | APR_FOPEN_SPARSE,
                        APR_OS_DEFAULT, p);
+
     APR_ASSERT_SUCCESS(tc, "open file", rv);
 
-    rv = apr_file_trunc(f, eightGb);
+    APR_ASSERT_SUCCESS(tc, "Truncate to 1MB", rv = apr_file_trunc(f, oneMB+1));
 
-    APR_ASSERT_SUCCESS(tc, "close large file", apr_file_close(f));
+    if (rv == APR_SUCCESS) {
+        rv = apr_file_info_get(&testsize, APR_FINFO_CSIZE, f);
+    }
 
-    /* 8Gb may pass rlimits or filesystem limits */
+    /* give up if we can't determine the allocation size of the file,
+     * or if it's not an obviously small allocation but the allocation
+     * unit doesn't appear insanely large
+     */
+    if ((rv != APR_SUCCESS) || ((testsize.csize > oneMB)
+                             && (testsize.csize < oneMB * 2)))
+    {
+        ABTS_NOT_IMPL(tc, "Creation of large file (apparently not sparse)");
+
+        madefile = 0;
+    }
+    else
+    {
+        /* Proceed with our 8GB sparse file now */
 
-    if (APR_STATUS_IS_EINVAL(rv)
+        rv = apr_file_trunc(f, eightGB);
+
+        /* 8GB may pass rlimits or filesystem limits */
+
+        if (APR_STATUS_IS_EINVAL(rv)
 #ifdef EFBIG
-        || rv == EFBIG
+            || rv == EFBIG
 #endif
-        ) {
-        ABTS_NOT_IMPL(tc, "Creation of large file (limited by rlimit or fs?)");
-    } 
-    else {
-        APR_ASSERT_SUCCESS(tc, "truncate file to 8gb", rv);
+            ) {
+            ABTS_NOT_IMPL(tc, "Creation of large file (rlimit, quota or fs)");
+        } 
+        else {
+            APR_ASSERT_SUCCESS(tc, "truncate file to 8gb", rv);
+        }
+        madefile = rv == APR_SUCCESS;
     }
 
-    madefile = rv == APR_SUCCESS;
+    APR_ASSERT_SUCCESS(tc, "close large file", apr_file_close(f));
+
+    if (!madefile) {
+        APR_ASSERT_SUCCESS(tc, "remove large file", apr_file_remove(TESTFN, p));
+    }
 }
 
 static void test_reopen(abts_case *tc, void *data)
@@ -93,13 +118,13 @@
     
     rv = apr_file_open(&fh, TESTFN, APR_FOPEN_SPARSE | APR_FOPEN_READ,
                        APR_OS_DEFAULT, p);
-    APR_ASSERT_SUCCESS(tc, "re-open 8Gb file", rv);
+    APR_ASSERT_SUCCESS(tc, "re-open 8GB file", rv);
 
     APR_ASSERT_SUCCESS(tc, "file_info_get failed",
                        apr_file_info_get(&finfo, APR_FINFO_NORM, fh));
     
     ABTS_ASSERT(tc, "file_info_get gave incorrect size",
-             finfo.size == eightGb);
+             finfo.size == eightGB);
 
     APR_ASSERT_SUCCESS(tc, "re-close large file", apr_file_close(fh));
 }
@@ -113,7 +138,7 @@
     APR_ASSERT_SUCCESS(tc, "stat large file", 
                        apr_stat(&finfo, TESTFN, APR_FINFO_NORM, p));
     
-    ABTS_ASSERT(tc, "stat gave incorrect size", finfo.size == eightGb);
+    ABTS_ASSERT(tc, "stat gave incorrect size", finfo.size == eightGB);
 }
 
 static void test_readdir(abts_case *tc, void *data)
@@ -133,7 +158,7 @@
         
         if (rv == APR_SUCCESS && strcmp(finfo.name, TESTFILE) == 0) {
             ABTS_ASSERT(tc, "apr_dir_read gave incorrect size for large file", 
-                     finfo.size == eightGb);
+                     finfo.size == eightGB);
         }
 
     } while (rv == APR_SUCCESS);
@@ -159,18 +184,18 @@
     rv = apr_file_open(&fh, TESTFN, APR_FOPEN_SPARSE | APR_FOPEN_WRITE 
                                   | APR_FOPEN_APPEND, 
                        APR_OS_DEFAULT, p);
-    APR_ASSERT_SUCCESS(tc, "open 8Gb file for append", rv);
+    APR_ASSERT_SUCCESS(tc, "open 8GB file for append", rv);
 
-    APR_ASSERT_SUCCESS(tc, "append to 8Gb file",
+    APR_ASSERT_SUCCESS(tc, "append to 8GB file",
                        apr_file_write_full(fh, TESTSTR, strlen(TESTSTR), NULL));
 
     APR_ASSERT_SUCCESS(tc, "file_info_get failed",
                        apr_file_info_get(&finfo, APR_FINFO_NORM, fh));
     
     ABTS_ASSERT(tc, "file_info_get gave incorrect size",
-             finfo.size == eightGb + strlen(TESTSTR));
+             finfo.size == eightGB + strlen(TESTSTR));
 
-    APR_ASSERT_SUCCESS(tc, "close 8Gb file", apr_file_close(fh));
+    APR_ASSERT_SUCCESS(tc, "close 8GB file", apr_file_close(fh));
 }
 
 static void test_seek(abts_case *tc, void *data)
@@ -183,20 +208,20 @@
     
     rv = apr_file_open(&fh, TESTFN, APR_FOPEN_SPARSE | APR_FOPEN_WRITE,
                        APR_OS_DEFAULT, p);
-    APR_ASSERT_SUCCESS(tc, "open 8Gb file for writing", rv);
+    APR_ASSERT_SUCCESS(tc, "open 8GB file for writing", rv);
 
     pos = 0;
     APR_ASSERT_SUCCESS(tc, "relative seek to end", 
                        apr_file_seek(fh, APR_END, &pos));
-    ABTS_ASSERT(tc, "seek to END gave 8Gb", pos == eightGb);
+    ABTS_ASSERT(tc, "seek to END gave 8GB", pos == eightGB);
     
-    pos = eightGb;
-    APR_ASSERT_SUCCESS(tc, "seek to 8Gb", apr_file_seek(fh, APR_SET, &pos));
-    ABTS_ASSERT(tc, "seek gave 8Gb offset", pos == eightGb);
+    pos = eightGB;
+    APR_ASSERT_SUCCESS(tc, "seek to 8GB", apr_file_seek(fh, APR_SET, &pos));
+    ABTS_ASSERT(tc, "seek gave 8GB offset", pos == eightGB);
 
     pos = 0;
     APR_ASSERT_SUCCESS(tc, "relative seek to 0", apr_file_seek(fh, APR_CUR, &pos));
-    ABTS_ASSERT(tc, "relative seek gave 8Gb offset", pos == eightGb);
+    ABTS_ASSERT(tc, "relative seek gave 8GB offset", pos == eightGB);
 
     apr_file_close(fh);
 }
@@ -204,23 +229,23 @@
 static void test_write(abts_case *tc, void *data)
 {
     apr_file_t *fh;
-    apr_off_t pos = eightGb - 4;
+    apr_off_t pos = eightGB - 4;
     apr_status_t rv;
 
     PRECOND;
 
     rv = apr_file_open(&fh, TESTFN, APR_FOPEN_SPARSE | APR_FOPEN_WRITE,
                        APR_OS_DEFAULT, p);
-    APR_ASSERT_SUCCESS(tc, "re-open 8Gb file", rv);
+    APR_ASSERT_SUCCESS(tc, "re-open 8GB file", rv);
 
-    APR_ASSERT_SUCCESS(tc, "seek to 8Gb - 4", 
+    APR_ASSERT_SUCCESS(tc, "seek to 8GB - 4", 
                        apr_file_seek(fh, APR_SET, &pos));
-    ABTS_ASSERT(tc, "seek gave 8Gb-4 offset", pos == eightGb - 4);
+    ABTS_ASSERT(tc, "seek gave 8GB-4 offset", pos == eightGB - 4);
 
-    APR_ASSERT_SUCCESS(tc, "write magic string to 8Gb-4",
+    APR_ASSERT_SUCCESS(tc, "write magic string to 8GB-4",
                        apr_file_write_full(fh, "FISH", 4, NULL));
 
-    APR_ASSERT_SUCCESS(tc, "close 8Gb file", apr_file_close(fh));
+    APR_ASSERT_SUCCESS(tc, "close 8GB file", apr_file_close(fh));
 }
 
 
@@ -230,7 +255,7 @@
     apr_mmap_t *map;
     apr_file_t *fh;
     apr_size_t len = 16384; /* hopefully a multiple of the page size */
-    apr_off_t off = eightGb - len; 
+    apr_off_t off = eightGB - len; 
     apr_status_t rv;
     void *ptr;
 
@@ -240,7 +265,7 @@
                        APR_OS_DEFAULT, p);
     APR_ASSERT_SUCCESS(tc, "open 8gb file for mmap", rv);
     
-    APR_ASSERT_SUCCESS(tc, "mmap 8Gb file",
+    APR_ASSERT_SUCCESS(tc, "mmap 8GB file",
                        apr_mmap_create(&map, fh, off, len, APR_MMAP_READ, p));
 
     APR_ASSERT_SUCCESS(tc, "close file", apr_file_close(fh));
@@ -263,10 +288,10 @@
 
     PRECOND;
 
-    off = apr_atoi64(apr_off_t_toa(p, eightGb));
+    off = apr_atoi64(apr_off_t_toa(p, eightGB));
 
     ABTS_ASSERT(tc, "apr_atoi64 parsed apr_off_t_toa result incorrectly",
-             off == eightGb);
+             off == eightGB);
 }
 
 #define TESTBUFFN TESTDIR "/buffer.bin"
@@ -286,27 +311,27 @@
     APR_ASSERT_SUCCESS(tc, "open buffered file", rv);
 
     APR_ASSERT_SUCCESS(tc, "truncate to 8GB",
-                       apr_file_trunc(f, eightGb));
+                       apr_file_trunc(f, eightGB));
 
-    off = eightGb;
+    off = eightGB;
     APR_ASSERT_SUCCESS(tc, "seek to 8GB",
                        apr_file_seek(f, APR_SET, &off));
     ABTS_ASSERT(tc, "returned seek position still 8GB",
-                off == eightGb);
+                off == eightGB);
 
     off = 0;
     APR_ASSERT_SUCCESS(tc, "relative seek",
                        apr_file_seek(f, APR_CUR, &off));
     ABTS_ASSERT(tc, "relative seek still at 8GB",
-                off == eightGb);
+                off == eightGB);
 
     off = 0;
     APR_ASSERT_SUCCESS(tc, "end-relative seek",
                        apr_file_seek(f, APR_END, &off));
     ABTS_ASSERT(tc, "end-relative seek still at 8GB",
-                off == eightGb);
+                off == eightGB);
 
-    off = -eightGb;
+    off = -eightGB;
     APR_ASSERT_SUCCESS(tc, "relative seek to beginning",
                        apr_file_seek(f, APR_CUR, &off));
     ABTS_ASSERT(tc, "seek to beginning got zero",
@@ -316,18 +341,20 @@
                        apr_file_close(f));
 }
 
-#else
+#else /* !APR_HAS_LARGE_FILES */
+
 static void test_nolfs(abts_case *tc, void *data)
 {
     ABTS_NOT_IMPL(tc, "Large Files not supported");
 }
+
 #endif
 
 abts_suite *testlfs(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
 
-#ifdef USE_LFS_TESTS
+#if APR_HAS_LARGE_FILES
     abts_run_test(suite, test_open, NULL);
     abts_run_test(suite, test_reopen, NULL);
     abts_run_test(suite, test_stat, NULL);



Mime
View raw message