Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
Copyright 2018-2020, Barcelona Supercomputing Center (BSC), Spain
Copyright 2015-2020, Johannes Gutenberg Universitaet Mainz, Germany
This software was partially supported by the
EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
This software was partially supported by the
ADA-FS project under the SPPEXA project funded by the DFG.
SPDX-License-Identifier: MIT
*/
#include <catch2/catch.hpp>
#include <fmt/format.h>
#include <daemon/backend/data/pmdk/pool.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
// FIXME: temporary solution to have correct loggers for tests
#include <spdlog/sinks/basic_file_sink.h>
#include <vector>
#include <list>
namespace {
void
patch_gkfs_loggers(const std::vector<std::string>& loggers_name,
spdlog::level::level_enum level, const std::string& path) {
/* Create common sink */
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path);
/* Create and configure loggers */
auto loggers = std::list<std::shared_ptr<spdlog::logger>>();
for (const auto& name: loggers_name) {
if(spdlog::get(name)) {
continue;
}
auto logger = std::make_shared<spdlog::logger>(name, file_sink);
logger->flush_on(spdlog::level::trace);
loggers.push_back(logger);
}
/* register loggers */
for (const auto& logger: loggers) {
spdlog::register_logger(logger);
}
// set logger format
spdlog::set_pattern("[%C-%m-%d %H:%M:%S.%f] %P [%L][%n] %v");
spdlog::set_level(level);
}
} // namespace
// end of temporary solution
namespace {
fs::path
create_temporary_directory() {
auto tmpdir = fs::temp_directory_path() / fs::unique_path();
boost::system::error_code ec;
if(!fs::create_directory(tmpdir, ec)) {
throw std::runtime_error(ec.message());
}
return tmpdir;
}
} // namespace
SCENARIO( "PMDK pools can be created", "[pmdk_storage_pool]" ) {
auto logger_names = std::vector<std::string>{
"main",
"MetadataDB",
"DataModule",
};
::patch_gkfs_loggers(logger_names, spdlog::level::debug, "/dev/stdout");
GIVEN( "A valid parent directory " ) {
WHEN( "Size is a positive integer" ) {
std::size_t pool_size = 420;
auto tmpdir = create_temporary_directory();
pmdk::pool p(tmpdir, pool_size);
THEN( "The pool object is valid " ) {
REQUIRE(p);
REQUIRE(p.valid());
REQUIRE(p.size() == pool_size);
REQUIRE(p.data() != nullptr);
}
AND_THEN( "The mapping file exists and has the correct size" ) {
REQUIRE(fs::exists(p.path()));
REQUIRE(fs::file_size(p.path()) == pool_size);
}
}
WHEN( "Size is zero" ) {
auto tmpdir = create_temporary_directory();
pmdk::pool p(tmpdir, 0);
THEN( "The pool object is invalid " ) {
REQUIRE(!p);
REQUIRE(!p.valid());
AND_THEN( "Internal members are default initialized" ) {
REQUIRE(p.path().empty());
REQUIRE(p.data() == nullptr);
REQUIRE(p.size() == 0);
}
}
}
WHEN( "Size is negative" ) {
auto tmpdir = create_temporary_directory();
pmdk::pool p(tmpdir, -1);
THEN( "The pool object is invalid " ) {
REQUIRE(!p);
REQUIRE(!p.valid());
AND_THEN( "Internal members are default initialized" ) {
REQUIRE(p.path().empty());
REQUIRE(p.data() == nullptr);
REQUIRE(p.size() == 0);
}
}
}
}
GIVEN( "An invalid parent directory " ) {
WHEN( "Parent directory does not exist" ) {
std::size_t pool_size = 420;
auto tmpdir = create_temporary_directory();
pmdk::pool p("/foo/bar/", pool_size);
THEN( "The pool object is invalid " ) {
REQUIRE(!p);
REQUIRE(!p.valid());
AND_THEN( "Internal members are default initialized" ) {
REQUIRE(p.path().empty());
REQUIRE(p.data() == nullptr);
REQUIRE(p.size() == 0);
}
}
}
}
}