Skip to content

Commit 00ca6cd

Browse files
authored
[TransferEngine] Add tests for Topology (#74)
1 parent bedd1c3 commit 00ca6cd

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

mooncake-transfer-engine/tests/topology_test.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,76 @@ TEST(ToplogyTest, GetTopologyMatrix)
1616
ASSERT_EQ(topology.toString(), json_str);
1717
}
1818

19+
TEST(ToplogyTest, TestEmpty) {
20+
mooncake::Topology topology;
21+
std::string json_str = "{\"cpu:0\" : [[\"erdma_0\"],[\"erdma_1\"]],\"cpu:1\" "
22+
": [[\"erdma_1\"],[\"erdma_0\"]]}";
23+
topology.clear();
24+
topology.parse(json_str);
25+
ASSERT_TRUE(!topology.empty());
26+
}
27+
28+
TEST(ToplogyTest, TestHcaList) {
29+
mooncake::Topology topology;
30+
std::string json_str = "{\"cpu:0\" : [[\"erdma_0\"],[\"erdma_0\"]],\"cpu:1\" "
31+
": [[\"erdma_0\"],[\"erdma_0\"]]}";
32+
topology.clear();
33+
topology.parse(json_str);
34+
ASSERT_EQ(topology.getHcaList().size(), 1);
35+
std::set<std::string> HcaList = {"erdma_0"};
36+
for (auto &hca : topology.getHcaList()) {
37+
ASSERT_TRUE(HcaList.count(hca));
38+
}
39+
}
40+
41+
TEST(ToplogyTest, TestHcaListSize) {
42+
mooncake::Topology topology;
43+
std::string json_str = "{\"cpu:0\" : [[\"erdma_0\"],[\"erdma_1\"]],\"cpu:1\" "
44+
": [[\"erdma_2\"],[\"erdma_3\"]]}";
45+
topology.clear();
46+
topology.parse(json_str);
47+
ASSERT_EQ(topology.getHcaList().size(), 4);
48+
}
49+
50+
TEST(ToplogyTest, TestHcaList2) {
51+
mooncake::Topology topology;
52+
std::string json_str = "{\"cpu:0\" : [[\"erdma_0\"],[\"erdma_1\"]],\"cpu:1\" "
53+
": [[\"erdma_1\"],[\"erdma_0\"]]}";
54+
topology.clear();
55+
topology.parse(json_str);
56+
ASSERT_EQ(topology.getHcaList().size(), 2);
57+
std::set<std::string> HcaList = {"erdma_0", "erdma_1"};
58+
for (auto &hca : topology.getHcaList()) {
59+
ASSERT_TRUE(HcaList.count(hca));
60+
}
61+
}
62+
63+
TEST(ToplogyTest, TestMatrix) {
64+
mooncake::Topology topology;
65+
std::string json_str = "{\"cpu:0\" : [[\"erdma_0\"],[\"erdma_1\"]]}";
66+
topology.clear();
67+
topology.parse(json_str);
68+
auto matrix = topology.getMatrix();
69+
ASSERT_TRUE(matrix.size() == 1);
70+
ASSERT_TRUE(matrix.count("cpu:0"));
71+
}
72+
73+
TEST(ToplogyTest, TestSelectDevice) {
74+
mooncake::Topology topology;
75+
std::string json_str = "{\"cpu:0\" : [[\"erdma_0\"],[\"erdma_1\"]]}";
76+
topology.clear();
77+
topology.parse(json_str);
78+
std::set<int> items = {0, 1};
79+
int device;
80+
device = topology.selectDevice("cpu:0", 2);
81+
ASSERT_TRUE(items.count(device));
82+
items.erase(device);
83+
device = topology.selectDevice("cpu:0", 1);
84+
ASSERT_TRUE(items.count(device));
85+
items.erase(device);
86+
ASSERT_TRUE(items.empty());
87+
}
88+
1989
int main(int argc, char **argv)
2090
{
2191
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)