Return-Path: X-Original-To: apmail-subversion-commits-archive@minotaur.apache.org Delivered-To: apmail-subversion-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8CFE410EF2 for ; Sat, 13 Jul 2013 10:34:09 +0000 (UTC) Received: (qmail 31595 invoked by uid 500); 13 Jul 2013 10:34:09 -0000 Delivered-To: apmail-subversion-commits-archive@subversion.apache.org Received: (qmail 31491 invoked by uid 500); 13 Jul 2013 10:34:07 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 31484 invoked by uid 99); 13 Jul 2013 10:34:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Jul 2013 10:34:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Jul 2013 10:34:01 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F3D902388900; Sat, 13 Jul 2013 10:33:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1502770 - /subversion/trunk/subversion/tests/libsvn_subr/io-test.c Date: Sat, 13 Jul 2013 10:33:39 -0000 To: commits@subversion.apache.org From: stefan2@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130713103339.F3D902388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: stefan2 Date: Sat Jul 13 10:33:39 2013 New Revision: 1502770 URL: http://svn.apache.org/r1502770 Log: Add a test for svn_io_file_aligned_seek. * subversion/tests/libsvn_subr/io-test.c (aligned_seek, aligned_read_at, aligned_read): new sub-routines (aligned_seek_test): new test case (test_funcs): register new test Modified: subversion/trunk/subversion/tests/libsvn_subr/io-test.c Modified: subversion/trunk/subversion/tests/libsvn_subr/io-test.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/io-test.c?rev=1502770&r1=1502769&r2=1502770&view=diff ============================================================================== --- subversion/trunk/subversion/tests/libsvn_subr/io-test.c (original) +++ subversion/trunk/subversion/tests/libsvn_subr/io-test.c Sat Jul 13 10:33:39 2013 @@ -26,6 +26,7 @@ #include #include +#include #include "svn_pools.h" #include "svn_string.h" @@ -507,6 +508,135 @@ read_length_line_shouldnt_loop(apr_pool_ return SVN_NO_ERROR; } +/* Move the read pointer in FILE to absolute position OFFSET and align + * the read buffer to multiples of BLOCK_SIZE. Use POOL for allocations. + */ +static svn_error_t * +aligned_seek(apr_file_t *file, + apr_size_t block_size, + apr_size_t offset, + apr_pool_t *pool) +{ + apr_off_t block_start; + apr_off_t current; + + SVN_ERR(svn_io_file_aligned_seek(file, (apr_off_t)block_size, + &block_start, (apr_off_t)offset, pool)); + + /* block start shall be aligned to multiples of block_size. + If it isn't, it must be aligned to APR's default block size(pre-1.3 APR) + */ +#if APR_VERSION_AT_LEAST(1,3,0) + SVN_TEST_ASSERT(block_start % block_size == 0); + SVN_TEST_ASSERT(offset - block_start < block_size); +#else + SVN_TEST_ASSERT(block_start % 0x1000 == 0); + SVN_TEST_ASSERT(offset - block_start < 0x1000); +#endif + + /* we must be at the desired offset */ + current = 0; + SVN_ERR(svn_io_file_seek(file, SEEK_CUR, ¤t, pool)); + SVN_TEST_ASSERT(current == (apr_off_t)offset); + + return SVN_NO_ERROR; +} + +/* Move the read pointer in FILE to absolute position OFFSET, align the + * read buffer to multiples of BLOCK_SIZE and read one byte from that + * position. Verify that it matches the CONTENTS for that offset. + * Use POOL for allocations. + */ +static svn_error_t * +aligned_read_at(apr_file_t *file, + svn_stringbuf_t *contents, + apr_size_t block_size, + apr_size_t offset, + apr_pool_t *pool) +{ + char c; + SVN_ERR(aligned_seek(file, block_size, offset,pool)); + + /* the data we read must match whatever we wrote there */ + SVN_ERR(svn_io_file_getc(&c, file, pool)); + SVN_TEST_ASSERT(c == contents->data[offset]); + + return SVN_NO_ERROR; +} + +/* Verify that aligned seek with the given BLOCK_SIZE works for FILE. + * CONTENTS is the data expected from FILE. Use POOL for allocations. + */ +static svn_error_t * +aligned_read(apr_file_t *file, + svn_stringbuf_t *contents, + apr_size_t block_size, + apr_pool_t *pool) +{ + apr_size_t i; + apr_size_t offset = 0; + const apr_size_t prime = 78427; + + /* "random" access to different offsets */ + for (i = 0, offset = prime; i < 10; ++i, offset += prime) + SVN_ERR(aligned_read_at(file, contents, block_size, + offset % contents->len, pool)); + + /* we can seek to EOF */ + SVN_ERR(aligned_seek(file, contents->len, block_size, pool)); + + /* reversed order access to all bytes */ + for (i = contents->len; i > 0; --i) + SVN_ERR(aligned_read_at(file, contents, block_size, i - 1, pool)); + + /* forward order access to all bytes */ + for (i = 0; i < contents->len; ++i) + SVN_ERR(aligned_read_at(file, contents, block_size, i, pool)); + + return SVN_NO_ERROR; +} + +static svn_error_t * +aligned_seek_test(apr_pool_t *pool) +{ + apr_size_t i; + const char *tmp_dir; + const char *tmp_file; + apr_file_t *f; + svn_stringbuf_t *contents; + const apr_size_t file_size = 100000; + + /* create a temp folder & schedule it for automatic cleanup */ + + SVN_ERR(svn_dirent_get_absolute(&tmp_dir, "aligned_seek_tmp", pool)); + SVN_ERR(svn_io_remove_dir2(tmp_dir, TRUE, NULL, NULL, pool)); + SVN_ERR(svn_io_make_dir_recursively(tmp_dir, pool)); + svn_test_add_dir_cleanup(tmp_dir); + + /* create a temp file with know contents */ + + contents = svn_stringbuf_create_ensure(file_size, pool); + for (i = 0; i < file_size; ++i) + svn_stringbuf_appendbyte(contents, (char)rand()); + + SVN_ERR(svn_io_write_unique(&tmp_file, tmp_dir, contents->data, + contents->len, + svn_io_file_del_on_pool_cleanup, pool)); + + /* now, access read data with varying alignment sizes */ + SVN_ERR(svn_io_file_open(&f, tmp_file, APR_READ, APR_OS_DEFAULT, pool)); + SVN_ERR(aligned_read(f, contents, 0x1000, pool)); /* APR default */ + SVN_ERR(aligned_read(f, contents, 0x8000, pool)); /* "unusual" 32K */ + SVN_ERR(aligned_read(f, contents, 0x10000, pool)); /* FSX default */ + SVN_ERR(aligned_read(f, contents, 0x100000, pool)); /* larger than file */ + SVN_ERR(aligned_read(f, contents, 10001, pool)); /* odd, larger than + APR default */ + SVN_ERR(aligned_read(f, contents, 1003, pool)); /* odd, smaller than + APR default */ + + return SVN_NO_ERROR; +} + /* The test table. */ @@ -523,5 +653,7 @@ struct svn_test_descriptor_t test_funcs[ "three file content comparison"), SVN_TEST_PASS2(read_length_line_shouldnt_loop, "svn_io_read_length_line() shouldn't loop"), + SVN_TEST_PASS2(aligned_seek_test, + "test aligned seek"), SVN_TEST_NULL };