diff options
| author | Qiuwen Lu <[email protected]> | 2016-11-04 19:36:40 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2016-11-04 19:36:40 +0800 |
| commit | 753522085286884e281260fbed1ee0d13dc0b519 (patch) | |
| tree | fcc1046ab066d7b553b0e4a667c58311a4c0ddb4 /test | |
| parent | df63f60821b8b2dd8416c92a932174f06b0b79f8 (diff) | |
重构邻居子系统实现,接口与MR3类似,增加对应的单元测试代码。
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | test/TestStackNeigh.cc | 93 |
2 files changed, 87 insertions, 10 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 03898c5..8cf7596 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,5 +30,5 @@ set(TEST_LINK_LIBRARIES ${DPDK_LIBRARY} gtest) # add_executable(TestVMan TestVMan.cc Unittest.cc)
# target_link_libraries(TestVMan ${TEST_LINK_LIBRARIES} core)
-# add_executable(TestNeigh TestStackNeigh.cc Unittest.cc)
-# target_link_libraries(TestNeigh ${TEST_LINK_LIBRARIES} stack)
\ No newline at end of file +add_executable(TestNeigh TestStackNeigh.cc Unittest.cc)
+target_link_libraries(TestNeigh ${TEST_LINK_LIBRARIES} stack)
\ No newline at end of file diff --git a/test/TestStackNeigh.cc b/test/TestStackNeigh.cc index 36fab6d..711c101 100644 --- a/test/TestStackNeigh.cc +++ b/test/TestStackNeigh.cc @@ -1,30 +1,107 @@ #include <gtest/gtest.h> #include <sk_device.h> -#include <sk_neigh.h> #include <netinet/in.h> +#include <sk_neigh.h> +#include <arpa/inet.h> class TCStackNeigh : public ::testing::Test { protected: - struct sk_neigh_table neigh_tbl_; - struct sk_dev_desc neigh_dev_desc_; + struct neighbour_manager nbl_object_; + struct sk_dev_info dev_info_; virtual void SetUp() { - int ret = neigh_tbl_init(&neigh_tbl_, "TestNeigh", 10000); - neigh_dev_desc_.dev_info = new sk_dev_info; + int ret = neighbour_mamanger_init(&nbl_object_, "TestNeighbour", + 1024, 8, 0, 0); ASSERT_EQ(ret, 0); } virtual void TearDown() { + int ret = neighbour_mamanger_deinit(&nbl_object_); + ASSERT_EQ(ret, 0); } }; -TEST_F(TCStackNeigh, TestNeighCreate) +TEST_F(TCStackNeigh, CreateAndQuery) { + int ret = 0; struct in_addr _in_addr; - _in_addr.s_addr = 1000000; - neigh_create(&neigh_tbl_, _in_addr, &neigh_dev_desc_); + inet_pton(AF_INET, "192.168.11.101", &_in_addr); + struct ether_addr _ether_addr = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; + + ret = neigh_create_or_update(&nbl_object_, + _in_addr, &_ether_addr, &dev_info_, 1); + + ASSERT_EQ(ret, 0); + + struct ether_addr _ether_addr_query; + struct sk_dev_info * _dev_info_query; + + ret = neigh_query(&nbl_object_, _in_addr, &_ether_addr_query, + &_dev_info_query); + + ASSERT_EQ(ret, 0); + EXPECT_EQ(is_same_ether_addr(&_ether_addr_query, &_ether_addr), 1); + EXPECT_EQ(_dev_info_query, &dev_info_); +} + +TEST_F(TCStackNeigh, CreateAndUpdate) +{ + int ret = 0; + struct in_addr _in_addr; + inet_pton(AF_INET, "192.168.11.101", &_in_addr); + struct ether_addr _ether_addr = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; + + ret = neigh_create_or_update(&nbl_object_, + _in_addr, &_ether_addr, &dev_info_, 1); + + ASSERT_EQ(ret, 0); + + struct ether_addr _ether_addr_query; + struct sk_dev_info * _dev_info_query; + + ret = neigh_query(&nbl_object_, _in_addr, &_ether_addr_query, + &_dev_info_query); + + ASSERT_EQ(ret, 0); + EXPECT_EQ(is_same_ether_addr(&_ether_addr_query, &_ether_addr), 1); + EXPECT_EQ(_dev_info_query, &dev_info_); + + struct ether_addr _ether_addr_update = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; + ret = neigh_create_or_update(&nbl_object_, _in_addr, &_ether_addr_update, + &dev_info_, 1); + + ASSERT_EQ(ret, 0); + + ret = neigh_query(&nbl_object_, _in_addr, &_ether_addr_query, &_dev_info_query); + ASSERT_EQ(ret, 0); + EXPECT_EQ(is_same_ether_addr(&_ether_addr_query, &_ether_addr_update), 1); + EXPECT_EQ(_dev_info_query, &dev_info_); +} + +TEST_F(TCStackNeigh, CreateAndDelete) +{ + int ret = 0; + struct in_addr _in_addr; + inet_pton(AF_INET, "192.168.11.101", &_in_addr); + struct ether_addr _ether_addr = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; + + ret = neigh_create_or_update(&nbl_object_, + _in_addr, &_ether_addr, &dev_info_, 1); + + ASSERT_EQ(ret, 0); + + ret = neigh_delete(&nbl_object_, _in_addr); + ASSERT_EQ(ret, 0); + + struct ether_addr _ether_addr_query; + struct sk_dev_info * _dev_info_query; + + ret = neigh_query(&nbl_object_, _in_addr, &_ether_addr_query, + &_dev_info_query); + + ASSERT_LE(ret, 0); }
\ No newline at end of file |
