From e1d7a751aeff505294af7c0c066ac341be136e77 Mon Sep 17 00:00:00 2001 From: Ilya Baldin Date: Fri, 27 Sep 2024 16:46:18 -0400 Subject: [PATCH] Added unit tests for INI file reading of flags; modified meson.build to properly produce a unified e2sar.a --- src/meson.build | 9 +++++---- test/e2sar_reas_test.cpp | 37 +++++++++++++++++++++++++++++++++++++ test/e2sar_seg_test.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/meson.build b/src/meson.build index 4009468d..779701b6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -11,10 +11,11 @@ libe2sar_t = static_library('e2sar_t', install : true) # build one library from the E2SAR and gRPC library pieces -libe2sar = static_library('e2sar', - objects : [libe2sar_t.extract_all_objects(recursive: false), - liblbgrpc.extract_all_objects(recursive: false)], - install : true) +#libe2sar = static_library('e2sar', +# objects : [libe2sar_t.extract_all_objects(recursive: false), +# liblbgrpc.extract_all_objects(recursive: false)], +# install : true) +libe2sar = static_library('e2sar', link_whole : [libe2sar_t, liblbgrpc], install : true) # The pybind subdir('pybind') diff --git a/test/e2sar_reas_test.cpp b/test/e2sar_reas_test.cpp index 2f27bd0d..ad39c03c 100644 --- a/test/e2sar_reas_test.cpp +++ b/test/e2sar_reas_test.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "e2sar.hpp" @@ -634,4 +637,38 @@ BOOST_AUTO_TEST_CASE(DPReasTest4) } } +BOOST_AUTO_TEST_CASE(DPReasTest5) +{ + // test reading SegmenterFlags from INI files + // generate a file, read it in and compare expected values + boost::property_tree::ptree paramTree; + Reassembler::ReassemblerFlags rFlags; + std::string iniFileName = "/tmp/reassembler.ini"; + + // fill in the parameters + paramTree.put("general.useCP", false); + paramTree.put("control-plane.useHostAddress", true); + paramTree.put("data-plane.rcvSocketBufSize", 10000); + + try { + boost::property_tree::ini_parser::write_ini(iniFileName, paramTree); + } catch(boost::property_tree::ini_parser_error &ie) { + std::cout << "Unable to parse the segmenter flags configuration file "s + iniFileName << std::endl; + BOOST_CHECK(false); + } + + Reassembler::ReassemblerFlags segDefaults; + Reassembler::ReassemblerFlags readFlags; + auto res = Reassembler::ReassemblerFlags::getFromINI(iniFileName); + BOOST_CHECK(!res.has_error()); + readFlags = res.value(); + + BOOST_CHECK(readFlags.useCP == paramTree.get("general.useCP")); + BOOST_CHECK(readFlags.useHostAddress == paramTree.get("control-plane.useHostAddress")); + BOOST_CHECK(readFlags.validateCert == segDefaults.validateCert); + BOOST_CHECK(readFlags.rcvSocketBufSize == paramTree.get("data-plane.rcvSocketBufSize")); + + std::remove(iniFileName.c_str()); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test/e2sar_seg_test.cpp b/test/e2sar_seg_test.cpp index 3c1033b5..a5184684 100644 --- a/test/e2sar_seg_test.cpp +++ b/test/e2sar_seg_test.cpp @@ -1,6 +1,9 @@ #define BOOST_TEST_MODULE DPSegTests #include #include +#include +#include +#include #include #include #include @@ -8,6 +11,9 @@ #include #include #include +#include +#include +#include #include "e2sar.hpp" @@ -332,4 +338,37 @@ BOOST_AUTO_TEST_CASE(DPSegTest4) // stop threads and exit } +BOOST_AUTO_TEST_CASE(DPSegTest5) +{ + // test reading SegmenterFlags from INI files + // generate a file, read it in and compare expected values + boost::property_tree::ptree paramTree; + Segmenter::SegmenterFlags sFlags; + std::string iniFileName = "/tmp/segmenter.ini"; + + // fill in the parameters + paramTree.put("general.useCP", false); + paramTree.put("data-plane.zeroCopy", true); + paramTree.put("data-plane.sndSocketBufSize", 10000); + + try { + boost::property_tree::ini_parser::write_ini(iniFileName, paramTree); + } catch(boost::property_tree::ini_parser_error &ie) { + std::cout << "Unable to parse the segmenter flags configuration file "s + iniFileName << std::endl; + BOOST_CHECK(false); + } + + Segmenter::SegmenterFlags segDefaults; + Segmenter::SegmenterFlags readFlags; + auto res = Segmenter::SegmenterFlags::getFromINI(iniFileName); + BOOST_CHECK(!res.has_error()); + readFlags = res.value(); + + BOOST_CHECK(readFlags.useCP == paramTree.get("general.useCP")); + BOOST_CHECK(readFlags.zeroCopy == paramTree.get("data-plane.zeroCopy")); + BOOST_CHECK(readFlags.dpV6 == segDefaults.dpV6); + BOOST_CHECK(readFlags.sndSocketBufSize == paramTree.get("data-plane.sndSocketBufSize")); + + std::remove(iniFileName.c_str()); +} BOOST_AUTO_TEST_SUITE_END()