From d0bee5d85c1c862639450bad69c0ad20a98ef5c9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 12 Jul 2013 11:14:19 -0700 Subject: [PATCH] cls_refcount: add type tests Signed-off-by: Sage Weil --- src/Makefile.am | 9 ++-- src/cls/refcount/cls_refcount_ops.cc | 80 ++++++++++++++++++++++++++++ src/cls/refcount/cls_refcount_ops.h | 16 ++++++ src/common/ceph_json.h | 40 +++++++------- src/test/encoding/ceph_dencoder.cc | 6 +-- src/test/encoding/types.h | 8 +++ 6 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 src/cls/refcount/cls_refcount_ops.cc diff --git a/src/Makefile.am b/src/Makefile.am index e2e60720dac13..64a1da80b4882 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -153,7 +153,9 @@ rgw_dencoder_src = rgw/rgw_dencoder.cc \ ceph_dencoder_SOURCES = test/encoding/ceph_dencoder.cc ${rgw_dencoder_src} perfglue/disabled_heap_profiler.cc ceph_dencoder_CXXFLAGS = ${AM_CXXFLAGS} ceph_dencoder_LDADD = $(LIBGLOBAL_LDA) libcls_lock_client.a \ - libcls_rgw_client.a libcls_replica_log_client.a \ + libcls_rgw_client.a \ + libcls_replica_log_client.a \ + libcls_refcount_client.a \ libosd.a libmds.a libosdc.la $(LIBOS_LDA) libmon.a bin_PROGRAMS += ceph-dencoder @@ -550,7 +552,7 @@ libcls_lock_la_LDFLAGS = ${AM_LDFLAGS} -version-info 1:0:0 -export-symbols-regex radoslib_LTLIBRARIES += libcls_lock.la # refcount class -libcls_refcount_la_SOURCES = cls/refcount/cls_refcount.cc +libcls_refcount_la_SOURCES = cls/refcount/cls_refcount.cc cls/refcount/cls_refcount_ops.cc libcls_refcount_la_CFLAGS = ${AM_CFLAGS} libcls_refcount_la_CXXFLAGS= ${AM_CXXFLAGS} libcls_refcount_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS) @@ -611,7 +613,8 @@ libcls_lock_client_a_SOURCES = \ noinst_LIBRARIES += libcls_lock_client.a libcls_refcount_client_a_SOURCES = \ - cls/refcount/cls_refcount_client.cc + cls/refcount/cls_refcount_client.cc \ + cls/refcount/cls_refcount_ops.cc noinst_LIBRARIES += libcls_refcount_client.a libcls_version_client_a_SOURCES = \ diff --git a/src/cls/refcount/cls_refcount_ops.cc b/src/cls/refcount/cls_refcount_ops.cc new file mode 100644 index 0000000000000..1c6a3b3b3b9b6 --- /dev/null +++ b/src/cls/refcount/cls_refcount_ops.cc @@ -0,0 +1,80 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "cls_refcount_ops.h" +#include "common/Formatter.h" +#include "common/ceph_json.h" + +void cls_refcount_get_op::dump(ceph::Formatter *f) const +{ + f->dump_string("tag", tag); + f->dump_int("implicit_ref", (int)implicit_ref); +} + +void cls_refcount_get_op::generate_test_instances(list& ls) +{ + ls.push_back(new cls_refcount_get_op); + ls.push_back(new cls_refcount_get_op); + ls.back()->tag = "foo"; + ls.back()->implicit_ref = true; +} + + +void cls_refcount_put_op::dump(ceph::Formatter *f) const +{ + f->dump_string("tag", tag); + f->dump_int("implicit_ref", (int)implicit_ref); +} + +void cls_refcount_put_op::generate_test_instances(list& ls) +{ + ls.push_back(new cls_refcount_put_op); + ls.push_back(new cls_refcount_put_op); + ls.back()->tag = "foo"; + ls.back()->implicit_ref = true; +} + + + +void cls_refcount_set_op::dump(ceph::Formatter *f) const +{ + encode_json("refs", refs, f); +} + +void cls_refcount_set_op::generate_test_instances(list& ls) +{ + ls.push_back(new cls_refcount_set_op); + ls.push_back(new cls_refcount_set_op); + ls.back()->refs.push_back("foo"); + ls.back()->refs.push_back("bar"); +} + + +void cls_refcount_read_op::dump(ceph::Formatter *f) const +{ + f->dump_int("implicit_ref", (int)implicit_ref); +} + +void cls_refcount_read_op::generate_test_instances(list& ls) +{ + ls.push_back(new cls_refcount_read_op); + ls.push_back(new cls_refcount_read_op); + ls.back()->implicit_ref = true; +} + + +void cls_refcount_read_ret::dump(ceph::Formatter *f) const +{ + f->open_array_section("refs"); + for (list::const_iterator p = refs.begin(); p != refs.end(); ++p) + f->dump_string("ref", *p); + f->close_section(); +} + +void cls_refcount_read_ret::generate_test_instances(list& ls) +{ + ls.push_back(new cls_refcount_read_ret); + ls.push_back(new cls_refcount_read_ret); + ls.back()->refs.push_back("foo"); + ls.back()->refs.push_back("bar"); +} diff --git a/src/cls/refcount/cls_refcount_ops.h b/src/cls/refcount/cls_refcount_ops.h index 6126b8db46695..813a1c1c96bda 100644 --- a/src/cls/refcount/cls_refcount_ops.h +++ b/src/cls/refcount/cls_refcount_ops.h @@ -8,6 +8,8 @@ #include "include/types.h" +class Formatter; + struct cls_refcount_get_op { string tag; bool implicit_ref; @@ -27,6 +29,8 @@ struct cls_refcount_get_op { ::decode(implicit_ref, bl); DECODE_FINISH(bl); } + void dump(ceph::Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(cls_refcount_get_op) @@ -50,6 +54,9 @@ struct cls_refcount_put_op { ::decode(implicit_ref, bl); DECODE_FINISH(bl); } + + void dump(ceph::Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(cls_refcount_put_op) @@ -69,6 +76,9 @@ struct cls_refcount_set_op { ::decode(refs, bl); DECODE_FINISH(bl); } + + void dump(ceph::Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(cls_refcount_set_op) @@ -89,6 +99,9 @@ struct cls_refcount_read_op { ::decode(implicit_ref, bl); DECODE_FINISH(bl); } + + void dump(ceph::Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(cls_refcount_read_op) @@ -108,6 +121,9 @@ struct cls_refcount_read_ret { ::decode(refs, bl); DECODE_FINISH(bl); } + + void dump(ceph::Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(cls_refcount_read_ret) diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 67efeae0e2a13..32f5dcfc6fed3 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -252,7 +252,7 @@ void JSONDecoder::decode_json(const char *name, T& val, T& default_val, JSONObj } template -static void encode_json(const char *name, const T& val, Formatter *f) +static void encode_json(const char *name, const T& val, ceph::Formatter *f) { f->open_object_section(name); val.dump(f); @@ -261,21 +261,21 @@ static void encode_json(const char *name, const T& val, Formatter *f) class utime_t; -void encode_json(const char *name, const string& val, Formatter *f); -void encode_json(const char *name, const char *val, Formatter *f); -void encode_json(const char *name, bool val, Formatter *f); -void encode_json(const char *name, int val, Formatter *f); -void encode_json(const char *name, unsigned val, Formatter *f); -void encode_json(const char *name, long val, Formatter *f); -void encode_json(const char *name, unsigned long val, Formatter *f); -void encode_json(const char *name, long long val, Formatter *f); -void encode_json(const char *name, const utime_t& val, Formatter *f); -void encode_json(const char *name, const bufferlist& bl, Formatter *f); -void encode_json(const char *name, long long val, Formatter *f); -void encode_json(const char *name, long long unsigned val, Formatter *f); +void encode_json(const char *name, const string& val, ceph::Formatter *f); +void encode_json(const char *name, const char *val, ceph::Formatter *f); +void encode_json(const char *name, bool val, ceph::Formatter *f); +void encode_json(const char *name, int val, ceph::Formatter *f); +void encode_json(const char *name, unsigned val, ceph::Formatter *f); +void encode_json(const char *name, long val, ceph::Formatter *f); +void encode_json(const char *name, unsigned long val, ceph::Formatter *f); +void encode_json(const char *name, long long val, ceph::Formatter *f); +void encode_json(const char *name, const utime_t& val, ceph::Formatter *f); +void encode_json(const char *name, const bufferlist& bl, ceph::Formatter *f); +void encode_json(const char *name, long long val, ceph::Formatter *f); +void encode_json(const char *name, long long unsigned val, ceph::Formatter *f); template -static void encode_json(const char *name, const std::map& m, Formatter *f) +static void encode_json(const char *name, const std::map& m, ceph::Formatter *f) { f->open_array_section(name); for (typename std::map::const_iterator i = m.begin(); i != m.end(); ++i) { @@ -288,7 +288,7 @@ static void encode_json(const char *name, const std::map& m, Formatter *f) } template -static void encode_json(const char *name, const std::list& l, Formatter *f) +static void encode_json(const char *name, const std::list& l, ceph::Formatter *f) { f->open_array_section(name); for (typename std::list::const_iterator iter = l.begin(); iter != l.end(); ++iter) { @@ -298,7 +298,7 @@ static void encode_json(const char *name, const std::list& l, Formatter *f) } template -void encode_json_map(const char *name, const map& m, Formatter *f) +void encode_json_map(const char *name, const map& m, ceph::Formatter *f) { f->open_array_section(name); typename map::const_iterator iter; @@ -312,8 +312,8 @@ void encode_json_map(const char *name, const map& m, Formatter *f) template void encode_json_map(const char *name, const char *index_name, const char *object_name, const char *value_name, - void (*cb)(const char *, const V&, Formatter *, void *), void *parent, - const map& m, Formatter *f) + void (*cb)(const char *, const V&, ceph::Formatter *, void *), void *parent, + const map& m, ceph::Formatter *f) { f->open_array_section(name); typename map::const_iterator iter; @@ -346,14 +346,14 @@ void encode_json_map(const char *name, const char *index_name, template void encode_json_map(const char *name, const char *index_name, const char *object_name, const char *value_name, - const map& m, Formatter *f) + const map& m, ceph::Formatter *f) { encode_json_map(name, index_name, object_name, value_name, NULL, NULL, m, f); } template void encode_json_map(const char *name, const char *index_name, const char *value_name, - const map& m, Formatter *f) + const map& m, ceph::Formatter *f) { encode_json_map(name, index_name, NULL, value_name, NULL, NULL, m, f); } diff --git a/src/test/encoding/ceph_dencoder.cc b/src/test/encoding/ceph_dencoder.cc index b98edcb61eecf..81abcd1de9e3b 100644 --- a/src/test/encoding/ceph_dencoder.cc +++ b/src/test/encoding/ceph_dencoder.cc @@ -44,7 +44,7 @@ struct Dencoder { virtual ~Dencoder() {} virtual string decode(bufferlist bl) = 0; virtual void encode(bufferlist& out, uint64_t features) = 0; - virtual void dump(Formatter *f) = 0; + virtual void dump(ceph::Formatter *f) = 0; virtual void generate() = 0; virtual int num_generated() = 0; virtual string select_generated(unsigned n) = 0; @@ -79,7 +79,7 @@ public: virtual void encode(bufferlist& out, uint64_t features) = 0; - void dump(Formatter *f) { + void dump(ceph::Formatter *f) { m_object->dump(f); } @@ -163,7 +163,7 @@ public: encode_message(m_object, features, out); } - void dump(Formatter *f) { + void dump(ceph::Formatter *f) { m_object->dump(f); } diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index e3349a02f0b0a..ee389d653d212 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -250,6 +250,14 @@ TYPE(cls_replica_log_set_marker_op) TYPE(cls_replica_log_get_bounds_op) TYPE(cls_replica_log_get_bounds_ret) +#include "cls/refcount/cls_refcount_ops.h" +TYPE(cls_refcount_get_op) +TYPE(cls_refcount_put_op) +TYPE(cls_refcount_read_op) +TYPE(cls_refcount_read_ret) +TYPE(cls_refcount_set_op) + + // --- messages --- #include "messages/MAuth.h" MESSAGE(MAuth) -- 2.39.5