5 #include <gtest/gtest.h>
7 #include "common/errno.h"
8 #include "common/config.h"
9 #include "os/ObjectStore.h"
11 #if defined(WITH_BLUESTORE)
12 #include "os/bluestore/BlueStore.h"
14 #include "store_test_fixture.h"
16 static void rm_r(const string
& path
)
18 string cmd
= string("rm -r ") + path
;
19 cout
<< "==> " << cmd
<< std::endl
;
20 int r
= ::system(cmd
.c_str());
24 cerr
<< "system() failed to fork() " << cpp_strerror(r
)
25 << ", continuing anyway" << std::endl
;
27 cerr
<< "failed with exit code " << r
28 << ", continuing anyway" << std::endl
;
33 void StoreTestFixture::SetUp()
36 int r
= ::mkdir(data_dir
.c_str(), 0777);
39 cerr
<< __func__
<< ": unable to create " << data_dir
<< ": " << cpp_strerror(r
) << std::endl
;
43 store
.reset(ObjectStore::create(g_ceph_context
,
46 string("store_test_temp_journal")));
48 cerr
<< __func__
<< ": objectstore type " << type
<< " doesn't exist yet!" << std::endl
;
51 #if defined(WITH_BLUESTORE)
52 if (type
== "bluestore") {
53 BlueStore
*s
= static_cast<BlueStore
*>(store
.get());
54 // better test coverage!
55 s
->set_cache_shards(5);
58 ASSERT_EQ(0, store
->mkfs());
59 ASSERT_EQ(0, store
->mount());
61 // we keep this stuff 'unsafe' out of test case scope to be able to update ANY
62 // config settings. Hence setting it to 'safe' here to proceed with the test
64 g_conf().set_safe_to_start_threads();
67 void StoreTestFixture::TearDown()
69 // we keep this stuff 'unsafe' out of test case scope to be able to update ANY
70 // config settings. Hence setting it to 'unsafe' here as test case is closing.
71 g_conf()._clear_safe_to_start_threads();
73 if (!orig_death_test_style
.empty()) {
74 ::testing::FLAGS_gtest_death_test_style
= orig_death_test_style
;
75 orig_death_test_style
.clear();
78 int r
= store
->umount();
84 void StoreTestFixture::SetVal(ConfigProxy
& _conf
, const char* key
, const char* val
)
86 ceph_assert(!conf
|| conf
== &_conf
);
88 std::string
skey(key
);
90 conf
->get_val(skey
, &prev_val
);
91 conf
->set_val_or_die(key
, val
);
92 saved_settings
.emplace(skey
, prev_val
);
95 void StoreTestFixture::PopSettings(size_t pos
)
98 ceph_assert(pos
== 0 || pos
<= saved_settings
.size()); // for sanity
99 while(pos
< saved_settings
.size())
101 auto& e
= saved_settings
.top();
102 conf
->set_val_or_die(e
.first
, e
.second
);
103 saved_settings
.pop();
105 conf
->apply_changes(NULL
);