Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 367782418
  • Loading branch information
RDMA authored and swoloschek-goog committed Apr 10, 2021
1 parent 5b90fb4 commit 63b9725
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 54 deletions.
1 change: 1 addition & 0 deletions cases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ cc_library(
srcs = ["gunit_main.cc"],
deps = [
"//impl:introspection_mlx4",
"//impl:introspection_mlx5",
"//impl:introspection_rxe",
"@com_google_absl//absl/debugging:failure_signal_handler",
"@com_google_absl//absl/flags:parse",
Expand Down
10 changes: 8 additions & 2 deletions cases/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ TEST_P(BufferMWTest, ExceedFront) {
kMrMemoryOffset - kExceedLength, kMrMemoryLength + kExceedLength);
ibv_mw* mw = ibv_.AllocMw(setup.pd, GetParam());
EXPECT_NE(mw, nullptr);
EXPECT_EQ(IBV_WC_MW_BIND_ERR, DoBind(setup, mw, invalid_buffer));
const ibv_wc_status kExpected =
Introspection().CorrectlyReportsMemoryWindowErrors() ? IBV_WC_MW_BIND_ERR
: IBV_WC_SUCCESS;
EXPECT_EQ(kExpected, DoBind(setup, mw, invalid_buffer));
}

TEST_P(BufferMWTest, ExceedRear) {
Expand All @@ -401,7 +404,10 @@ TEST_P(BufferMWTest, ExceedRear) {
setup.buffer.subspan(kMrMemoryOffset, kMrMemoryLength + kExceedLength);
ibv_mw* mw = ibv_.AllocMw(setup.pd, GetParam());
ASSERT_NE(mw, nullptr);
EXPECT_EQ(IBV_WC_MW_BIND_ERR, DoBind(setup, mw, invalid_buffer));
const ibv_wc_status kExpected =
Introspection().CorrectlyReportsMemoryWindowErrors() ? IBV_WC_MW_BIND_ERR
: IBV_WC_SUCCESS;
EXPECT_EQ(kExpected, DoBind(setup, mw, invalid_buffer));
}

TEST_P(BufferMWTest, ReadExceedFront) {
Expand Down
8 changes: 1 addition & 7 deletions cases/cq_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ class CQAdvancedTest : public BasicFixture {

// Adds |count| QPs to setup.qps.
absl::Status CreateTestQps(BasicSetup& setup, int count) {
ibv_device_attr dev_attr = {};
int err = ibv_query_device(setup.context, &dev_attr);
if (err) {
return absl::InternalError(
absl::StrCat("Failed to query device (", err, ")."));
}
for (int i = 0; i < count; ++i) {
size_t qp_id = setup.qps.size();
CHECK_LT(qp_id, 1UL << kQueueIdBits) << "Maximum of 256 queues";
Expand All @@ -190,7 +184,7 @@ class CQAdvancedTest : public BasicFixture {
setup.command_queue_slots,
setup.command_queue_slots, IBV_QPT_RC,
/*sig_all=*/0);
CHECK(qp.qp);
CHECK(qp.qp) << "failed to create qp - " << errno;
qp.next_send_wr_id = qp_id << kQueueIdShift;
qp.next_recv_wr_id = qp_id << kQueueIdShift;
ibv_.SetUpSelfConnectedRcQp(qp.qp,
Expand Down
2 changes: 2 additions & 0 deletions cases/gunit_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "absl/debugging/failure_signal_handler.h"
#include "absl/flags/parse.h"
#include "impl/introspection_mlx4.h"
#include "impl/introspection_mlx5.h"
#include "impl/introspection_rxe.h"

// glog/gflag are restricted libraries internally so we need to declare them
Expand Down Expand Up @@ -45,6 +46,7 @@ int main(int argc, char* argv[]) {

// Register supported NIC's
rdma_unit_test::IntrospectionMlx4::Register();
rdma_unit_test::IntrospectionMlx5::Register();
rdma_unit_test::IntrospectionRxe::Register();

return RUN_ALL_TESTS();
Expand Down
37 changes: 24 additions & 13 deletions cases/loopback_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,9 @@ TEST_F(LoopbackRcQpTest, SendImmData) {
}

TEST_F(LoopbackRcQpTest, SendWithInvalidate) {
if (!Introspection().SupportsType2()) {
GTEST_SKIP() << "Needs type 2 MW.";
if (!Introspection().SupportsType2() ||
!Introspection().SupportsRcSendWithInvalidate()) {
GTEST_SKIP() << "Needs type 2 MW and SendWithInvalidate.";
}
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
Expand Down Expand Up @@ -482,8 +483,9 @@ TEST_F(LoopbackRcQpTest, SendWithInvalidate) {
}

TEST_F(LoopbackRcQpTest, SendWithInvalidateNoBuffer) {
if (!Introspection().SupportsType2()) {
GTEST_SKIP() << "Needs type 2 MW.";
if (!Introspection().SupportsType2() ||
!Introspection().SupportsRcSendWithInvalidate()) {
GTEST_SKIP() << "Needs type 2 MW and SendWithInvalidate.";
}
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
Expand Down Expand Up @@ -515,8 +517,9 @@ TEST_F(LoopbackRcQpTest, SendWithInvalidateNoBuffer) {
}

TEST_F(LoopbackRcQpTest, SendWithInvalidateBadRkey) {
if (!Introspection().SupportsType2()) {
GTEST_SKIP() << "Needs type 2 MW.";
if (!Introspection().SupportsType2() ||
!Introspection().SupportsRcSendWithInvalidate()) {
GTEST_SKIP() << "Needs type 2 MW and SendWithInvalidate.";
}
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
Expand Down Expand Up @@ -549,8 +552,9 @@ TEST_F(LoopbackRcQpTest, SendWithInvalidateBadRkey) {
}

TEST_F(LoopbackRcQpTest, SendWithInvalidateType1Rkey) {
if (!Introspection().SupportsType2()) {
GTEST_SKIP() << "Needs type 2 MW.";
if (!Introspection().SupportsType2() ||
!Introspection().SupportsRcSendWithInvalidate()) {
GTEST_SKIP() << "Needs type 2 MW and SendWithInvalidate.";
}
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
Expand Down Expand Up @@ -584,8 +588,9 @@ TEST_F(LoopbackRcQpTest, SendWithInvalidateType1Rkey) {

// Send with Invalidate targeting another QPs MW.
TEST_F(LoopbackRcQpTest, SendWithInvalidateWrongQp) {
if (!Introspection().SupportsType2()) {
GTEST_SKIP() << "Needs type 2 MW.";
if (!Introspection().SupportsType2() ||
!Introspection().SupportsRcSendWithInvalidate()) {
GTEST_SKIP() << "Needs type 2 MW and SendWithInvalidate.";
}
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
Expand Down Expand Up @@ -1519,6 +1524,7 @@ TEST_F(LoopbackRcQpTest, FetchAddUnalignedInvalidRKey) {
}

TEST_F(LoopbackRcQpTest, FetchAddInvalidSize) {
if (!Introspection().CorrectlyReportsInvalidSizeErrors()) GTEST_SKIP();
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
auto [local, remote] = client_pair_or.value();
Expand Down Expand Up @@ -1795,6 +1801,7 @@ TEST_F(LoopbackRcQpTest, CmpAndSwpUnalignedInvalidLKey) {
}

TEST_F(LoopbackRcQpTest, CmpAndSwpInvalidSize) {
if (!Introspection().CorrectlyReportsInvalidSizeErrors()) GTEST_SKIP();
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
auto [local, remote] = client_pair_or.value();
Expand Down Expand Up @@ -1930,16 +1937,20 @@ TEST_F(LoopbackRcQpTest, RequestOnFailedQp) {
/*wr_id=*/1, &rsge, /*num_sge=*/1, local.buffer.data(), local.mr->rkey);
verbs_util::PostSend(remote.qp, read2);

ibv_wc completion2 = verbs_util::WaitForCompletion(remote.cq).value();
ibv_wc completion2 =
verbs_util::WaitForCompletion(remote.cq,
verbs_util::kDefaultErrorCompletionTimeout)
.value();
EXPECT_EQ(IBV_WC_RETRY_EXC_ERR, completion2.status);
EXPECT_EQ(remote.qp->qp_num, completion2.qp_num);
EXPECT_EQ(1, completion2.wr_id);
EXPECT_THAT(remote.buffer.span(), ::testing::Each('b'));
}

TEST_F(LoopbackRcQpTest, FullSubmissionQueue) {
static_assert(kQueueSize % 2 == 0,
"Queue size must be even for this test to hit queue bounaries");
static_assert(
kQueueSize % 2 == 0,
"Queue size must be even for this test to hit queue boundaries");
static constexpr int kBatchSize = kQueueSize / 2;
auto client_pair_or = CreateConnectedClientsPair();
ASSERT_OK(client_pair_or);
Expand Down
32 changes: 26 additions & 6 deletions cases/mw_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ TEST_F(MwTest, BindType1ReadWithNoLocalWrite) {
ASSERT_NE(nullptr, mw);
ibv_wc_status bind_result = verbs_util::BindType1MwSync(
setup.qp, mw, setup.buffer.span(), mr, IBV_ACCESS_REMOTE_READ);
EXPECT_EQ(IBV_WC_MW_BIND_ERR, bind_result);
const ibv_wc_status kExpected =
Introspection().CorrectlyReportsMemoryWindowErrors() ? IBV_WC_MW_BIND_ERR
: IBV_WC_SUCCESS;
EXPECT_EQ(kExpected, bind_result);
}

TEST_F(MwTest, BindType1AtomicWithNoLocalWrite) {
Expand All @@ -142,7 +145,10 @@ TEST_F(MwTest, BindType1AtomicWithNoLocalWrite) {
ASSERT_NE(nullptr, mw);
ibv_wc_status bind_result = verbs_util::BindType1MwSync(
setup.qp, mw, setup.buffer.span(), mr, IBV_ACCESS_REMOTE_ATOMIC);
EXPECT_EQ(IBV_WC_MW_BIND_ERR, bind_result);
const ibv_wc_status kExpected =
Introspection().CorrectlyReportsMemoryWindowErrors() ? IBV_WC_MW_BIND_ERR
: IBV_WC_SUCCESS;
EXPECT_EQ(kExpected, bind_result);
}

TEST_F(MwTest, Read) {
Expand Down Expand Up @@ -204,9 +210,21 @@ TEST_F(MwTest, InvalidMr) {
ibv_mr dummy_mr_val{};
ibv_mr* dummy_mr = &dummy_mr_val;
dummy_mr->handle = -1;
ibv_wc_status bind_result =
verbs_util::BindType1MwSync(setup.qp, mw, setup.buffer.span(), dummy_mr);
EXPECT_EQ(IBV_WC_MW_BIND_ERR, bind_result);
// Some clients do client side validation on type 1. First check
// succcess/failure of the bind and if successful than check for completion.
ibv_mw_bind bind_args = verbs_util::CreateType1MwBind(
/*wr_id=*/1, setup.buffer.span(), dummy_mr,
IBV_ACCESS_REMOTE_READ | IBV_ACCESS_REMOTE_WRITE |
IBV_ACCESS_REMOTE_ATOMIC);
int result = ibv_bind_mw(setup.qp, mw, &bind_args);
EXPECT_THAT(result, testing::AnyOf(0, EPERM, EOPNOTSUPP));
if (result == 0) {
ibv_wc completion =
verbs_util::WaitForCompletion(setup.qp->send_cq).value();
if (completion.status == IBV_WC_SUCCESS) {
EXPECT_EQ(IBV_WC_BIND_MW, completion.opcode);
}
}
}

TEST_F(MwTest, InvalidMw) {
Expand All @@ -231,7 +249,9 @@ TEST_F(MwTest, DeregMrWhenBound) {
verbs_util::BindType1MwSync(setup.qp, mw, setup.buffer.span(), setup.mr);
ASSERT_EQ(IBV_WC_SUCCESS, result);

EXPECT_EQ(EBUSY, ibv_dereg_mr(setup.mr));
const int kExpected =
Introspection().CorrectlyReportsMemoryWindowErrors() ? EBUSY : 0;
EXPECT_EQ(kExpected, ibv_.DeregMr(setup.mr));
}

TEST_F(MwTest, DestroyQpWithType1Bound) {
Expand Down
37 changes: 33 additions & 4 deletions cases/pd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TEST_F(PdTest, OpenManyPd) {
}

TEST_F(PdTest, DeleteUnknownPd) {
if (!Introspection().CorrectlyReportsInvalidObjects()) GTEST_SKIP();
ibv_context* context = ibv_.OpenDevice().value();
ibv_pd dummy;
dummy.context = context;
Expand All @@ -65,6 +66,7 @@ TEST_F(PdTest, DeleteUnknownPd) {

// Check with a pointer in the correct range.
TEST_F(PdTest, DeleteInvalidPd) {
if (!Introspection().CorrectlyReportsInvalidObjects()) GTEST_SKIP();
ibv_context* context = ibv_.OpenDevice().value();
ibv_cq* cq = ibv_.CreateCq(context);
ASSERT_NE(nullptr, cq);
Expand Down Expand Up @@ -200,8 +202,22 @@ TEST_P(PdBindTest, MwOnOtherPd) {
ibv_mr* mr = ibv_.RegMr(setup.qp_pd, setup.buffer);
ibv_mw* mw = ibv_.AllocMw(setup.other_pd, GetParam());
if (GetParam() == IBV_MW_TYPE_1) {
EXPECT_EQ(IBV_WC_MW_BIND_ERR, verbs_util::BindType1MwSync(
setup.qp, mw, setup.buffer.span(), mr));
// Some clients do client side validation on type 1. First check
// succcess/failure of the bind and if successful than check for completion.
ibv_mw_bind bind_args = verbs_util::CreateType1MwBind(
/*wr_id=*/1, setup.buffer.span(), mr,
IBV_ACCESS_REMOTE_READ | IBV_ACCESS_REMOTE_WRITE |
IBV_ACCESS_REMOTE_ATOMIC);
int result = ibv_bind_mw(setup.qp, mw, &bind_args);
EXPECT_THAT(result, testing::AnyOf(0, EPERM));
if (result == 0) {
ibv_wc completion =
verbs_util::WaitForCompletion(setup.qp->send_cq).value();
if (completion.status == IBV_WC_SUCCESS) {
EXPECT_EQ(IBV_WC_BIND_MW, completion.opcode);
}
}

} else {
EXPECT_EQ(IBV_WC_MW_BIND_ERR,
verbs_util::BindType2MwSync(setup.qp, mw, setup.buffer.span(),
Expand All @@ -214,8 +230,21 @@ TEST_P(PdBindTest, MrOnOtherPd) {
ibv_mr* mr = ibv_.RegMr(setup.other_pd, setup.buffer);
ibv_mw* mw = ibv_.AllocMw(setup.qp_pd, GetParam());
if (GetParam() == IBV_MW_TYPE_1) {
EXPECT_EQ(IBV_WC_MW_BIND_ERR, verbs_util::BindType1MwSync(
setup.qp, mw, setup.buffer.span(), mr));
// Some clients do client side validation on type 1. First check
// succcess/failure of the bind and if successful than check for completion.
ibv_mw_bind bind_args = verbs_util::CreateType1MwBind(
/*wr_id=*/1, setup.buffer.span(), mr,
IBV_ACCESS_REMOTE_READ | IBV_ACCESS_REMOTE_WRITE |
IBV_ACCESS_REMOTE_ATOMIC);
int result = ibv_bind_mw(setup.qp, mw, &bind_args);
EXPECT_THAT(result, testing::AnyOf(0, EPERM));
if (result == 0) {
ibv_wc completion =
verbs_util::WaitForCompletion(setup.qp->send_cq).value();
if (completion.status == IBV_WC_SUCCESS) {
EXPECT_EQ(IBV_WC_BIND_MW, completion.opcode);
}
}
} else {
EXPECT_EQ(IBV_WC_MW_BIND_ERR,
verbs_util::BindType2MwSync(setup.qp, mw, setup.buffer.span(),
Expand Down
16 changes: 12 additions & 4 deletions cases/srq_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ TEST_F(SrqTest, OverflowSrq) {
recv_wrs[i + 1].wr_id = i + 1;
}
ibv_recv_wr* bad_wr = nullptr;
ASSERT_EQ(-1, ibv_post_srq_recv(srq, recv_wrs.data(), &bad_wr));
// mlx4 uses -1, mlx5 uses ENOMEM
EXPECT_THAT(ibv_post_srq_recv(srq, recv_wrs.data(), &bad_wr),
testing::AnyOf(-1, ENOMEM));
ASSERT_EQ(&recv_wrs[queue_size], bad_wr);
EXPECT_EQ(0, ibv_destroy_srq(srq));
}
Expand Down Expand Up @@ -279,7 +281,9 @@ TEST_F(SrqTest, ExceedsMaxSge) {
/*num_sge=*/sges.size());
recv_valid.next = &recv_valid;
ibv_recv_wr* bad_wr = nullptr;
EXPECT_EQ(-1, ibv_post_srq_recv(srq, &recv_invalid, &bad_wr));
// mlx4 uses -1, mlx5 uses EINVAL
EXPECT_THAT(ibv_post_srq_recv(srq, &recv_invalid, &bad_wr),
testing::AnyOf(-1, EINVAL));
EXPECT_EQ(&recv_invalid, bad_wr);
}

Expand All @@ -288,8 +292,12 @@ TEST_F(SrqTest, RnR) {
ibv_sge sge = verbs_util::CreateSge(setup.send_buffer.span(), setup.send_mr);
ibv_send_wr send = verbs_util::CreateSendWr(/*wr_id=*/1, &sge, /*num_sge=*/1);
verbs_util::PostSend(setup.send_qp, send);
ibv_wc completion = verbs_util::WaitForCompletion(setup.send_cq).value();
EXPECT_EQ(IBV_WC_RNR_RETRY_EXC_ERR, completion.status);
ibv_wc completion =
verbs_util::WaitForCompletion(setup.send_cq,
verbs_util::kDefaultErrorCompletionTimeout)
.value();
EXPECT_THAT(completion.status,
testing::AnyOf(IBV_WC_RNR_RETRY_EXC_ERR, IBV_WC_RETRY_EXC_ERR));
EXPECT_THAT(setup.recv_buffer.span(), ::testing::Each(kRecvContent));
}

Expand Down
10 changes: 10 additions & 0 deletions cases/status_matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
ASSERT_TRUE(statusor.status().ok()) << statusor.status(); \
lhs = std::move(statusor.value())

#define ASSIGN_OR_RETURN(lhs, rexpr) \
ASSIGN_OR_RETURN_IMPL(CONCAT_MACRO(_status_or, __COUNTER__), lhs, rexpr)

#define ASSIGN_OR_RETURN_IMPL(statusor, lhs, rexpr) \
auto statusor = (rexpr); \
if (PREDICT_FALSE(!statusor.ok())) { \
return statusor.status(); \
} \
lhs = std::move(statusor.value())

#endif

#endif // RDMA_UNIT_TEST_CASES_STATUS_MATCHERS_H_
11 changes: 11 additions & 0 deletions impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cc_library(
name = "introspection_extras",
deps = [
":introspection_mlx4",
":introspection_mlx5",
":introspection_rxe",
],
)
Expand All @@ -25,6 +26,16 @@ cc_library(
alwayslink = 1,
)

cc_library(
name = "introspection_mlx5",
hdrs = ["introspection_mlx5.h"],
deps = [
":introspection_registrar",
"//public:introspection",
],
alwayslink = 1,
)

cc_library(
name = "introspection_registrar",
srcs = ["introspection_registrar.cc"],
Expand Down
Loading

0 comments on commit 63b9725

Please sign in to comment.