From a6a8d623f8261b50044fbe0c43b0ae5ed2f78dc6 Mon Sep 17 00:00:00 2001 From: Joongi Kim Date: Wed, 24 Feb 2016 16:47:29 +0900 Subject: [PATCH] refs #27: Add stubs for IPv4 lookup element tests. --- compilelib.py | 2 ++ tests/test_ipv4route.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/test_ipv4route.cc diff --git a/compilelib.py b/compilelib.py index 0c72088..277dbae 100644 --- a/compilelib.py +++ b/compilelib.py @@ -95,6 +95,7 @@ def get_includes(srcfile, nba_include_dir): ) return _find_deps_with_regex(srcfile, nba_include_dir, regexs) +_rx_required_local_obj_sig = re.compile(r'^#require\s*"(.+\.o)"') _rx_required_obj_sig = re.compile(r'^#require\s*<(.+\.o)>') def get_requires(srcfile, nba_src_dir): ''' @@ -102,6 +103,7 @@ def get_requires(srcfile, nba_src_dir): (e.g., #require ) ''' regexs = ( + (_rx_required_local_obj_sig, True), (_rx_required_obj_sig, False), ) return _find_deps_with_regex(srcfile, nba_src_dir, regexs) diff --git a/tests/test_ipv4route.cc b/tests/test_ipv4route.cc new file mode 100644 index 0000000..cd98657 --- /dev/null +++ b/tests/test_ipv4route.cc @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include "../elements/ip/ip_route_core.hh" +#include "../elements/ip/IPlookup_kernel.hh" +#if 0 +#require "../elements/ip/ip_route_core.o" +#require "../elements/ip/IPlookup_kernel.o" +#endif + +using namespace std; +using namespace nba; + +TEST(IPLookupTest, Loading) { + ipv4route::route_hash_t tables[33]; + ipv4route::load_rib_from_file(tables, "configs/routing_info.txt"); + size_t num_entries = 0; + for (int i = 0; i <= 32; i++) { + printf("table[%d] size: %lu\n", i, tables[i].size()); + num_entries += tables[i].size(); + } + EXPECT_EQ(282797, num_entries) << "All entries (lines) should exist."; + + // Add extra 32 entries and check overflowing. + uint16_t *tbl24 = (uint16_t *) malloc(sizeof(uint16_t) * (ipv4route::get_TBL24_size() + 32)); + uint16_t *tbllong = (uint16_t *) malloc(sizeof(uint16_t) * (ipv4route::get_TBLlong_size() + 32)); + for (int i = 0; i < 32; i++) + tbl24[ipv4route::get_TBL24_size() + i] = i; + ipv4route::build_direct_fib(tables, tbl24, tbllong); + for (int i = 0; i < 32; i++) + EXPECT_EQ(i, tbl24[ipv4route::get_TBL24_size() + i]); + free(tbl24); + free(tbllong); +} + + +// vim: ts=8 sts=4 sw=4 et