Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / librbd / test_mock_fixture.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H
5 #define CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H
6
7 #include "test/librbd/test_fixture.h"
8 #include "test/librbd/mock/MockImageCtx.h"
9 #include "test/librados_test_stub/LibradosTestStub.h"
10 #include "common/WorkQueue.h"
11 #include <boost/shared_ptr.hpp>
12 #include <gmock/gmock.h>
13
14 namespace librados {
15 class TestCluster;
16 class MockTestMemCluster;
17 class MockTestMemIoCtxImpl;
18 class MockTestMemRadosClient;
19 }
20 namespace librbd {
21 class MockImageCtx;
22 }
23
24 ACTION_P(CopyInBufferlist, str) {
25   arg0->append(str);
26 }
27
28 ACTION_P2(CompleteContext, r, wq) {
29   ContextWQ *context_wq = reinterpret_cast<ContextWQ *>(wq);
30   if (context_wq != NULL) {
31     context_wq->queue(arg0, r);
32   } else {
33     arg0->complete(r);
34   }
35 }
36
37 ACTION_P(DispatchContext, wq) {
38   wq->queue(arg0, arg1);
39 }
40
41 ACTION_P3(FinishRequest, request, r, mock) {
42   librbd::MockImageCtx *mock_image_ctx =
43     reinterpret_cast<librbd::MockImageCtx *>(mock);
44   mock_image_ctx->image_ctx->op_work_queue->queue(request->on_finish, r);
45 }
46
47 ACTION_P(GetReference, ref_object) {
48   ref_object->get();
49 }
50
51 ACTION_P(Notify, ctx) {
52   ctx->complete(0);
53 }
54
55 MATCHER_P(ContentsEqual, bl, "") {
56   // TODO fix const-correctness of bufferlist
57   return const_cast<bufferlist &>(arg).contents_equal(
58     const_cast<bufferlist &>(bl));
59 }
60
61 class TestMockFixture : public TestFixture {
62 public:
63   typedef boost::shared_ptr<librados::TestCluster> TestClusterRef;
64
65   static void SetUpTestCase();
66   static void TearDownTestCase();
67
68   void TearDown() override;
69
70   void expect_op_work_queue(librbd::MockImageCtx &mock_image_ctx);
71   void expect_unlock_exclusive_lock(librbd::ImageCtx &ictx);
72
73   void initialize_features(librbd::ImageCtx *ictx,
74                            librbd::MockImageCtx &mock_image_ctx,
75                            librbd::MockExclusiveLock &mock_exclusive_lock,
76                            librbd::MockJournal &mock_journal,
77                            librbd::MockObjectMap &mock_object_map);
78
79   void expect_is_journal_appending(librbd::MockJournal &mock_journal,
80                                    bool appending);
81   void expect_is_journal_replaying(librbd::MockJournal &mock_journal);
82   void expect_is_journal_ready(librbd::MockJournal &mock_journal);
83   void expect_allocate_op_tid(librbd::MockImageCtx &mock_image_ctx);
84   void expect_append_op_event(librbd::MockImageCtx &mock_image_ctx,
85                               bool can_affect_io, int r);
86   void expect_commit_op_event(librbd::MockImageCtx &mock_image_ctx, int r);
87
88 private:
89   static TestClusterRef s_test_cluster;
90 };
91
92 #endif // CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H