Skip to content

Commit

Permalink
buffer: add a test for iterator::copy(huge_chunk, dest)
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/16010
Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Jun 7, 2016
1 parent 053bfa6 commit 3caafc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,20 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
return new raw_unshareable(len);
}

class dummy_raw : public buffer::raw {
public:
dummy_raw()
: raw(UINT_MAX)
{}
virtual raw* clone_empty() override {
return new dummy_raw();
}
};

buffer::raw* buffer::create_dummy() {
return new dummy_raw();
}

buffer::ptr::ptr(raw *r) : _raw(r), _off(0), _len(r->len) // no lock needed; this is an unref raw.
{
r->nref.inc();
Expand Down
1 change: 1 addition & 0 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace buffer CEPH_BUFFER_API {
raw* create_page_aligned(unsigned len);
raw* create_zero_copy(unsigned len, int fd, int64_t *offset);
raw* create_unshareable(unsigned len);
raw* create_dummy();

#if defined(HAVE_XIO)
raw* create_msg(unsigned len, char *buf, XioDispatchHook *m_hook);
Expand Down
15 changes: 15 additions & 0 deletions src/test/bufferlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,21 @@ TEST(BufferListIterator, copy) {
}
}

TEST(BufferListIterator, copy_huge) {
constexpr unsigned len = 2268888894U;
static_assert(int(len) < 0,
"should be a number underflows when being casted to int.");
bufferptr ptr(buffer::create_dummy());
ptr.set_length(len);

bufferlist src, dest;
src.append(ptr);
auto bp = src.begin();
bp.copy(len, dest);
// contents_equal() is not for this test
EXPECT_EQ(len, dest.length());
}

TEST(BufferListIterator, copy_in) {
bufferlist bl;
const char *existing = "XXX";
Expand Down

0 comments on commit 3caafc4

Please sign in to comment.