Skip to content

Commit 193325b

Browse files
pbhandar2facebook-github-bot
authored andcommittedAug 21, 2024
Use MockDevice.cpp when building navy, move code within #ifdefn in FDP Device tests (#335)
Summary: This pull request addresses two build failures in the CacheLib repository: Navy library MockDevice integration The navy library recently started using MockDevice, but the build was failing due to missing API calls. This was caused by MockDevice.cpp not being included in the build process, and gmock not being linked. Changes made: Added MockDevice.cpp to the build process for navy Linked gmock library to resolve missing API calls FDP code test Some variables used in FDP tests were not defined because they were contained with code blocks accessable only when FDP flags were set. Changes made: Move the FDP test code within #ifdefn block Pull Request resolved: #335 Reviewed By: haowu14 Differential Revision: D61602277 Pulled By: pbhandar2 fbshipit-source-id: adde868319d5bfbdce87181454403d9c00fcfaed
1 parent 28d296a commit 193325b

File tree

2 files changed

+85
-73
lines changed

2 files changed

+85
-73
lines changed
 

‎cachelib/navy/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_library (cachelib_navy
4444
scheduler/ThreadPoolJobScheduler.cpp
4545
scheduler/ThreadPoolJobQueue.cpp
4646
serialization/RecordIO.cpp
47+
testing/MockDevice.cpp
4748
)
4849
add_dependencies(cachelib_navy thrift_generated_files)
4950

@@ -57,6 +58,7 @@ endif()
5758

5859
target_link_libraries(cachelib_navy PUBLIC
5960
cachelib_common
61+
GTest::gmock
6062
)
6163

6264
install(TARGETS cachelib_navy

‎cachelib/navy/common/tests/DeviceTest.cpp

+83-73
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,89 @@
3434
using testing::_;
3535

3636
namespace facebook::cachelib::navy::tests {
37+
#ifndef CACHELIB_IOURING_DISABLE
38+
39+
// Reference: https://github.com/axboe/fio/blob/master/engines/nvme.h
40+
// If the uapi headers installed on the system lacks nvme uring command
41+
// support, use the local version to prevent compilation issues.
42+
#ifndef CONFIG_NVME_URING_CMD
43+
44+
// Test for FdpNvme Constructor
45+
TEST(FDP, InitializationTest) {
46+
int nsId = 1;
47+
uint32_t lbaShift = 12;
48+
uint32_t maxTfrSize = 262144;
49+
uint64_t startLba = 0;
50+
uint32_t numRuhs = 10;
51+
52+
NvmeData data(nsId, lbaShift, maxTfrSize, startLba);
53+
struct nvme_fdp_ruh_status* ruh_status{};
54+
Buffer buffer{sizeof(struct nvme_fdp_ruh_status) +
55+
(numRuhs * sizeof(struct nvme_fdp_ruh_status_desc))};
56+
ruh_status = reinterpret_cast<nvme_fdp_ruh_status*>(buffer.data());
57+
ruh_status->nruhsd = numRuhs;
58+
EXPECT_NO_THROW(FdpNvme fdp = FdpNvme(data, ruh_status));
59+
}
60+
61+
// Test the Fdp Handle allocation
62+
TEST(FDP, FdpHandleAllocationTest) {
63+
int nsId = 1;
64+
uint32_t lbaShift = 12;
65+
uint32_t maxTfrSize = 262144;
66+
uint64_t startLba = 0;
67+
uint32_t numRuhs = 10;
68+
69+
NvmeData data(nsId, lbaShift, maxTfrSize, startLba);
70+
struct nvme_fdp_ruh_status* ruh_status{};
71+
Buffer buffer{sizeof(struct nvme_fdp_ruh_status) +
72+
(numRuhs * sizeof(struct nvme_fdp_ruh_status_desc))};
73+
ruh_status = reinterpret_cast<nvme_fdp_ruh_status*>(buffer.data());
74+
ruh_status->nruhsd = numRuhs;
75+
FdpNvme fdp = FdpNvme(data, ruh_status);
76+
for (auto i = 1; i < ruh_status->nruhsd; i++) {
77+
EXPECT_EQ(i, fdp.allocateFdpHandle());
78+
}
79+
80+
EXPECT_EQ(0, fdp.allocateFdpHandle());
81+
}
82+
83+
// Test IO uring read, write command preparation
84+
TEST(FDP, PrepUringTest) {
85+
int nsId = 1;
86+
uint32_t lbaShift = 12;
87+
uint32_t maxTfrSize = 262144;
88+
uint64_t startLba = 0;
89+
uint32_t numRuhs = 10;
90+
91+
NvmeData data(nsId, lbaShift, maxTfrSize, startLba);
92+
struct nvme_fdp_ruh_status* ruh_status{};
93+
Buffer buffer{sizeof(struct nvme_fdp_ruh_status) +
94+
(numRuhs * sizeof(struct nvme_fdp_ruh_status_desc))};
95+
ruh_status = reinterpret_cast<nvme_fdp_ruh_status*>(buffer.data());
96+
ruh_status->nruhsd = numRuhs;
97+
FdpNvme fdp = FdpNvme(data, ruh_status);
98+
std::unique_ptr<folly::IoUringOp> iouringCmdOp;
99+
folly::IoUringOp::Options options;
100+
options.sqe128 = true;
101+
options.cqe32 = true;
102+
103+
iouringCmdOp = std::make_unique<folly::IoUringOp>(
104+
folly::AsyncBaseOp::NotificationCallback(), options);
105+
iouringCmdOp->initBase();
106+
struct io_uring_sqe& sqe = iouringCmdOp->getSqe();
107+
108+
void* buf{};
109+
size_t size = 8192;
110+
off_t start = 0;
111+
int handle = 1;
112+
113+
EXPECT_NO_THROW(fdp.prepReadUringCmdSqe(sqe, buf, size, start));
114+
EXPECT_NO_THROW(fdp.prepWriteUringCmdSqe(sqe, buf, size, start, handle));
115+
}
116+
117+
#endif
118+
#endif
119+
37120
TEST(Device, BytesWritten) {
38121
MockDevice device{100, 1};
39122
EXPECT_CALL(device, writeImpl(_, _, _, _))
@@ -296,79 +379,6 @@ TEST(Device, Stats) {
296379
device.getCounters({toCallback(visitor)});
297380
}
298381

299-
// Test for FdpNvme Constructor
300-
TEST(FDP, InitializationTest) {
301-
int nsId = 1;
302-
uint32_t lbaShift = 12;
303-
uint32_t maxTfrSize = 262144;
304-
uint64_t startLba = 0;
305-
uint32_t numRuhs = 10;
306-
307-
NvmeData data(nsId, lbaShift, maxTfrSize, startLba);
308-
struct nvme_fdp_ruh_status* ruh_status{};
309-
Buffer buffer{sizeof(struct nvme_fdp_ruh_status) +
310-
(numRuhs * sizeof(struct nvme_fdp_ruh_status_desc))};
311-
ruh_status = reinterpret_cast<nvme_fdp_ruh_status*>(buffer.data());
312-
ruh_status->nruhsd = numRuhs;
313-
EXPECT_NO_THROW(FdpNvme fdp = FdpNvme(data, ruh_status));
314-
}
315-
316-
// Test the Fdp Handle allocation
317-
TEST(FDP, FdpHandleAllocationTest) {
318-
int nsId = 1;
319-
uint32_t lbaShift = 12;
320-
uint32_t maxTfrSize = 262144;
321-
uint64_t startLba = 0;
322-
uint32_t numRuhs = 10;
323-
324-
NvmeData data(nsId, lbaShift, maxTfrSize, startLba);
325-
struct nvme_fdp_ruh_status* ruh_status{};
326-
Buffer buffer{sizeof(struct nvme_fdp_ruh_status) +
327-
(numRuhs * sizeof(struct nvme_fdp_ruh_status_desc))};
328-
ruh_status = reinterpret_cast<nvme_fdp_ruh_status*>(buffer.data());
329-
ruh_status->nruhsd = numRuhs;
330-
FdpNvme fdp = FdpNvme(data, ruh_status);
331-
for (auto i = 1; i < ruh_status->nruhsd; i++) {
332-
EXPECT_EQ(i, fdp.allocateFdpHandle());
333-
}
334-
335-
EXPECT_EQ(0, fdp.allocateFdpHandle());
336-
}
337-
338-
// Test IO uring read, write command preparation
339-
TEST(FDP, PrepUringTest) {
340-
int nsId = 1;
341-
uint32_t lbaShift = 12;
342-
uint32_t maxTfrSize = 262144;
343-
uint64_t startLba = 0;
344-
uint32_t numRuhs = 10;
345-
346-
NvmeData data(nsId, lbaShift, maxTfrSize, startLba);
347-
struct nvme_fdp_ruh_status* ruh_status{};
348-
Buffer buffer{sizeof(struct nvme_fdp_ruh_status) +
349-
(numRuhs * sizeof(struct nvme_fdp_ruh_status_desc))};
350-
ruh_status = reinterpret_cast<nvme_fdp_ruh_status*>(buffer.data());
351-
ruh_status->nruhsd = numRuhs;
352-
FdpNvme fdp = FdpNvme(data, ruh_status);
353-
std::unique_ptr<folly::IoUringOp> iouringCmdOp;
354-
folly::IoUringOp::Options options;
355-
options.sqe128 = true;
356-
options.cqe32 = true;
357-
358-
iouringCmdOp = std::make_unique<folly::IoUringOp>(
359-
folly::AsyncBaseOp::NotificationCallback(), options);
360-
iouringCmdOp->initBase();
361-
struct io_uring_sqe& sqe = iouringCmdOp->getSqe();
362-
363-
void* buf{};
364-
size_t size = 8192;
365-
off_t start = 0;
366-
int handle = 1;
367-
368-
EXPECT_NO_THROW(fdp.prepReadUringCmdSqe(sqe, buf, size, start));
369-
EXPECT_NO_THROW(fdp.prepWriteUringCmdSqe(sqe, buf, size, start, handle));
370-
}
371-
372382
struct DeviceParamTest
373383
: public testing::TestWithParam<std::tuple<IoEngine, int>> {
374384
DeviceParamTest()

0 commit comments

Comments
 (0)
Please sign in to comment.