Skip to content

Commit

Permalink
Added unit tests for INI file reading of flags; modified meson.build …
Browse files Browse the repository at this point in the history
…to properly produce a unified e2sar.a
  • Loading branch information
ibaldin committed Sep 27, 2024
1 parent 407825d commit e1d7a75
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
37 changes: 37 additions & 0 deletions test/e2sar_reas_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <vector>
#include <boost/test/included/unit_test.hpp>
#include <boost/program_options.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/detail/file_parser_error.hpp>

#include "e2sar.hpp"

Expand Down Expand Up @@ -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<bool>("general.useCP", false);
paramTree.put<bool>("control-plane.useHostAddress", true);
paramTree.put<int>("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<bool>("general.useCP"));
BOOST_CHECK(readFlags.useHostAddress == paramTree.get<bool>("control-plane.useHostAddress"));
BOOST_CHECK(readFlags.validateCert == segDefaults.validateCert);
BOOST_CHECK(readFlags.rcvSocketBufSize == paramTree.get<int>("data-plane.rcvSocketBufSize"));

std::remove(iniFileName.c_str());
}

BOOST_AUTO_TEST_SUITE_END()
39 changes: 39 additions & 0 deletions test/e2sar_seg_test.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#define BOOST_TEST_MODULE DPSegTests
#include <stdlib.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <boost/asio.hpp>
#include <boost/chrono.hpp>
#include <boost/thread/thread.hpp>
#include <vector>
#include <boost/test/included/unit_test.hpp>
#include <boost/program_options.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/detail/file_parser_error.hpp>

#include "e2sar.hpp"

Expand Down Expand Up @@ -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<bool>("general.useCP", false);
paramTree.put<bool>("data-plane.zeroCopy", true);
paramTree.put<int>("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<bool>("general.useCP"));
BOOST_CHECK(readFlags.zeroCopy == paramTree.get<bool>("data-plane.zeroCopy"));
BOOST_CHECK(readFlags.dpV6 == segDefaults.dpV6);
BOOST_CHECK(readFlags.sndSocketBufSize == paramTree.get<int>("data-plane.sndSocketBufSize"));

std::remove(iniFileName.c_str());
}
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit e1d7a75

Please sign in to comment.