]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/librados/TestCase.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / librados / TestCase.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_RADOS_TESTCASE_H
5 #define CEPH_TEST_RADOS_TESTCASE_H
6
7 #include "include/rados/librados.h"
8 #include "gtest/gtest.h"
9
10 #include <string>
11
12 /**
13 * These test cases create a temporary pool that lives as long as the
14 * test case. We initially use the default namespace and assume
15 * test will whatever namespaces it wants. After each test all objects
16 * are removed.
17 *
18 * Since pool creation and deletion is slow, this allows many tests to
19 * run faster.
20 */
21 class RadosTestNS : public ::testing::Test {
22 public:
23 RadosTestNS(bool c=false) : cleanup(c) {}
24 ~RadosTestNS() override {}
25 protected:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28 static void cleanup_all_objects(rados_ioctx_t ioctx);
29 static rados_t s_cluster;
30 static std::string pool_name;
31
32 void SetUp() override;
33 void TearDown() override;
34 rados_t cluster = nullptr;
35 rados_ioctx_t ioctx = nullptr;
36 bool cleanup;
37 };
38
39 struct RadosTestNSCleanup : public RadosTestNS {
40 RadosTestNSCleanup() : RadosTestNS(true) {}
41 };
42
43 class RadosTestECNS : public RadosTestNS {
44 public:
45 RadosTestECNS(bool c=false) : cleanup(c) {}
46 ~RadosTestECNS() override {}
47 protected:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 static rados_t s_cluster;
51 static std::string pool_name;
52
53 void SetUp() override;
54 void TearDown() override;
55 rados_t cluster = nullptr;
56 rados_ioctx_t ioctx = nullptr;
57 uint64_t alignment = 0;
58 bool cleanup;
59 };
60
61 struct RadosTestECNSCleanup : public RadosTestECNS {
62 RadosTestECNSCleanup() : RadosTestECNS(true) {}
63 };
64
65 /**
66 * These test cases create a temporary pool that lives as long as the
67 * test case. Each test within a test case gets a new ioctx set to a
68 * unique namespace within the pool.
69 *
70 * Since pool creation and deletion is slow, this allows many tests to
71 * run faster.
72 */
73 class RadosTest : public ::testing::Test {
74 public:
75 RadosTest(bool c=false) : cleanup(c) {}
76 ~RadosTest() override {}
77 protected:
78 static void SetUpTestCase();
79 static void TearDownTestCase();
80 static void cleanup_default_namespace(rados_ioctx_t ioctx);
81 static void cleanup_namespace(rados_ioctx_t ioctx, std::string ns);
82 static rados_t s_cluster;
83 static std::string pool_name;
84
85 void SetUp() override;
86 void TearDown() override;
87 rados_t cluster = nullptr;
88 rados_ioctx_t ioctx = nullptr;
89 std::string nspace;
90 bool cleanup;
91 };
92
93 class RadosTestEC : public RadosTest {
94 public:
95 RadosTestEC(bool c=false) : cleanup(c) {}
96 ~RadosTestEC() override {}
97 protected:
98 static void SetUpTestCase();
99 static void TearDownTestCase();
100 static rados_t s_cluster;
101 static std::string pool_name;
102
103 void SetUp() override;
104 void TearDown() override;
105 rados_t cluster = nullptr;
106 rados_ioctx_t ioctx = nullptr;
107 bool cleanup;
108 std::string nspace;
109 uint64_t alignment = 0;
110 };
111
112 /**
113 * Test case without creating a temporary pool in advance.
114 * This is necessary for scenarios such that we need to
115 * manually create a pool, start some long-runing tasks and
116 * then the related pool is suddenly gone.
117 */
118 class RadosTestNP: public ::testing::Test {
119 public:
120 RadosTestNP() {}
121 ~RadosTestNP() override {}
122 };
123
124 #endif