diff --git a/dataplane/unittest/meson.build b/dataplane/unittest/meson.build index 0ea0c28b..cf89482b 100644 --- a/dataplane/unittest/meson.build +++ b/dataplane/unittest/meson.build @@ -12,6 +12,7 @@ sources = files('unittest.cpp', 'sdp.cpp', 'random_prefixes.cpp', 'vrf_lpm_linear.cpp', + 'vrf_lpm_binary.cpp', '../vrf.cpp', ) diff --git a/dataplane/unittest/vrf_lpm_binary.cpp b/dataplane/unittest/vrf_lpm_binary.cpp new file mode 100644 index 00000000..b74be657 --- /dev/null +++ b/dataplane/unittest/vrf_lpm_binary.cpp @@ -0,0 +1,71 @@ +#include + +#include "../vrf.h" +#include "random_prefixes.h" +#include "vrf_lpm_common.h" +#include "vrf_lpm_map.h" + +namespace dataplane::vrflpm +{ + +static constexpr size_t size_of_mem = 1024 * 1024 * 100; + +TEST(VrfLpm4, SimpleBinaryTree) +{ + std::unique_ptr buffer = std::make_unique(size_of_mem); + VrfLpm4BinaryTree::BlocksAllocator allocator; + allocator.Init(buffer.get(), size_of_mem, YANET_RIB_VRF_MAX_NUMBER); + VrfLpm4BinaryTree vrf_linear(allocator); + + SimpleTestVrfLpm4(vrf_linear); +} + +TEST(VrfLpm6, SimpleBinaryTree) +{ + std::unique_ptr buffer = std::make_unique(size_of_mem); + VrfLpm6BinaryTree::BlocksAllocator allocator; + allocator.Init(buffer.get(), size_of_mem, YANET_RIB_VRF_MAX_NUMBER); + VrfLpm6BinaryTree vrf_linear(allocator); + + SimpleTestVrfLpm6(vrf_linear); +} + +TEST(VrfLpm4, CompareMapAndBinaryTree) +{ + auto all_tests = dataplane::vrflpm::BuildTestData4(); + for (const auto& test_data : all_tests) + { + auto prefixes = CreatePrefixesIpv4(test_data); + + VrfLpmMap vrf_map; + + std::unique_ptr buffer = std::make_unique(size_of_mem); + VrfLpm4BinaryTree::BlocksAllocator allocator; + allocator.Init(buffer.get(), size_of_mem, YANET_RIB_VRF_MAX_NUMBER); + VrfLpm4BinaryTree vrf_linear(allocator); + + bool result = CompareTwoImplementations(test_data.vrf_number, prefixes, vrf_map, vrf_linear); + ASSERT_EQ(result, true) << "\nTest data:\n\t" << test_data.Description() << "\n"; + } +} + +TEST(VrfLpm6, CompareMapAndBinaryTree) +{ + auto all_tests = dataplane::vrflpm::BuildTestData6(); + for (const auto& test_data : all_tests) + { + auto prefixes = CreatePrefixesIpv6(test_data); + + VrfLpmMap, ipv6_address_t> vrf_map; + + std::unique_ptr buffer = std::make_unique(size_of_mem); + VrfLpm6BinaryTree::BlocksAllocator allocator; + allocator.Init(buffer.get(), size_of_mem, YANET_RIB_VRF_MAX_NUMBER); + VrfLpm6BinaryTree vrf_linear(allocator); + + bool result = CompareTwoImplementations(test_data.vrf_number, prefixes, vrf_map, vrf_linear); + ASSERT_EQ(result, true) << "\nTest data:\n\t" << test_data.Description() << "\n"; + } +} + +}