]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/librbd/test_mock_fixture.h
import ceph 15.2.10
[ceph.git] / 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 MATCHER_P(ContentsEqual, bl, "") {
52 // TODO fix const-correctness of bufferlist
53 return const_cast<bufferlist &>(arg).contents_equal(
54 const_cast<bufferlist &>(bl));
55 }
56
57 class TestMockFixture : public TestFixture {
58 public:
59 typedef boost::shared_ptr<librados::TestCluster> TestClusterRef;
60
61 static void SetUpTestCase();
62 static void TearDownTestCase();
63
64 void TearDown() override;
65
66 void expect_op_work_queue(librbd::MockImageCtx &mock_image_ctx);
67 void expect_unlock_exclusive_lock(librbd::ImageCtx &ictx);
68
69 void initialize_features(librbd::ImageCtx *ictx,
70 librbd::MockImageCtx &mock_image_ctx,
71 librbd::MockExclusiveLock &mock_exclusive_lock,
72 librbd::MockJournal &mock_journal,
73 librbd::MockObjectMap &mock_object_map);
74
75 void expect_is_journal_appending(librbd::MockJournal &mock_journal,
76 bool appending);
77 void expect_is_journal_replaying(librbd::MockJournal &mock_journal);
78 void expect_is_journal_ready(librbd::MockJournal &mock_journal);
79 void expect_allocate_op_tid(librbd::MockImageCtx &mock_image_ctx);
80 void expect_append_op_event(librbd::MockImageCtx &mock_image_ctx,
81 bool can_affect_io, int r);
82 void expect_commit_op_event(librbd::MockImageCtx &mock_image_ctx, int r);
83
84 private:
85 static TestClusterRef s_test_cluster;
86 };
87
88 #endif // CEPH_TEST_LIBRBD_TEST_MOCK_FIXTURE_H