From 351f78d7b9a3049a6b199e9881c847d674e82ad4 Mon Sep 17 00:00:00 2001 From: wangzhengyong Date: Fri, 21 Apr 2017 16:57:24 +0800 Subject: [PATCH] ceph_test_rados_api_misc: add cmpext tests Signed-off-by: Zhengyong Wang Signed-off-by: Mike Christie [ddiss@suse.de: add rados_cmpext() test coverage] Reviewed-by: David Disseldorp --- src/test/librados/misc.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/librados/misc.cc b/src/test/librados/misc.cc index a7d44ace6f8fe..bdc94cd72381f 100644 --- a/src/test/librados/misc.cc +++ b/src/test/librados/misc.cc @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "mds/mdstypes.h" +#include "include/err.h" #include "include/buffer.h" #include "include/rbd_types.h" #include "include/rados/librados.h" @@ -1198,3 +1199,32 @@ TYPED_TEST(LibRadosChecksum, Chunked) { ASSERT_EQ(expected_values[i], value); } } + +TEST_F(LibRadosMiscPP, CmpExtPP) { + bufferlist cmp_bl, bad_cmp_bl, write_bl; + char stored_str[] = "1234567891"; + char mismatch_str[] = "1234577777"; + + write_bl.append(stored_str); + ioctx.write("cmpextpp", write_bl, write_bl.length(), 0); + cmp_bl.append(stored_str); + ASSERT_EQ(0, ioctx.cmpext("cmpextpp", 0, cmp_bl)); + + bad_cmp_bl.append(mismatch_str); + ASSERT_EQ(-MAX_ERRNO - 5, ioctx.cmpext("cmpextpp", 0, bad_cmp_bl)); +} + +TEST_F(LibRadosMisc, CmpExt) { + bufferlist cmp_bl, bad_cmp_bl, write_bl; + char stored_str[] = "1234567891"; + char mismatch_str[] = "1234577777"; + + ASSERT_EQ(0, + rados_write(ioctx, "cmpextpp", stored_str, sizeof(stored_str), 0)); + + ASSERT_EQ(0, + rados_cmpext(ioctx, "cmpextpp", stored_str, sizeof(stored_str), 0)); + + ASSERT_EQ(-MAX_ERRNO - 5, + rados_cmpext(ioctx, "cmpextpp", mismatch_str, sizeof(mismatch_str), 0)); +} -- 2.39.5