Line data Source code
1 : /**
2 : * @file DaphneV3Interface_test.cxx
3 : *
4 : * Simple unittest for the daphne v3 interface
5 : *
6 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : *
10 : */
11 :
12 : #define BOOST_TEST_MODULE DaphneV3InterfaceTest // NOLINT
13 : #include <boost/test/included/unit_test.hpp>
14 :
15 : #include "DaphneV3Interface.hpp"
16 : #include <cstdlib>
17 : #include <iostream>
18 :
19 : using namespace dunedaq::daphnemodules;
20 :
21 : BOOST_AUTO_TEST_SUITE(DaphneInterfaceV3_test)
22 :
23 2 : BOOST_AUTO_TEST_CASE(bad_address)
24 : {
25 :
26 3 : BOOST_CHECK_THROW(dunedaq::daphnemodules::DaphneV3Interface i("bad/address", "v3_unittest"),
27 : dunedaq::daphnemodules::InvalidIPAddress);
28 :
29 3 : BOOST_CHECK_THROW(dunedaq::daphnemodules::DaphneV3Interface i("bad.address:14q4", "v3_unittest"),
30 : dunedaq::daphnemodules::InvalidIPAddress);
31 :
32 3 : BOOST_CHECK_THROW(dunedaq::daphnemodules::DaphneV3Interface i("non.existing.address", "v3_unittest"),
33 : dunedaq::daphnemodules::FailedPing);
34 :
35 3 : BOOST_CHECK_THROW(dunedaq::daphnemodules::DaphneV3Interface i("non.existing.address.with.port:7954", "v3_unittest"),
36 : dunedaq::daphnemodules::FailedPing);
37 1 : }
38 :
39 : BOOST_AUTO_TEST_SUITE_END()
40 :
41 : // static std::string get_env_or_default(const char* name, const char* def)
42 : // {
43 : // if (const char* v = std::getenv(name))
44 : // return v;
45 : // return def;
46 : // }
47 :
48 : // BOOST_AUTO_TEST_CASE(connection_test)
49 : // {
50 : // std::string ip = get_env_or_default("DAPHNE_IP", "");
51 : // std::string port = get_env_or_default("DAPHNE_PORT", "");
52 :
53 : // const auto& args = boost::unit_test::framework::master_test_suite().argv;
54 : // const int argc = boost::unit_test::framework::master_test_suite().argc;
55 :
56 : // for (int i = 1; i < argc; ++i) {
57 : // std::string a = args[i];
58 : // if (a == "--ip" && i + 1 < argc) ip = args[++i];
59 : // else if (a == "--port" && i + 1 < argc) port = args[++i];
60 : // }
61 :
62 : // if (ip.empty()) {
63 : // BOOST_FAIL("No IP provided (use -- --ip <addr> [--port <num>] or DAPHNE_IP env)");
64 : // }
65 :
66 : // std::string address = ip;
67 : // if (!port.empty())
68 : // address += ":" + port;
69 :
70 : // std::cout << "[TEST] Connecting to " << address << std::endl;
71 :
72 : // std::chrono::milliseconds timeout(3000);
73 : // DaphneV3Interface iface(address, "v3_unittest", timeout);
74 :
75 : // uint64_t val = 0;
76 : // bool ok = iface.read_test_register(val);
77 :
78 : // std::cout << "[TEST] Test register value: 0x" << std::hex << val << std::dec << std::endl;
79 :
80 : // BOOST_CHECK_MESSAGE(ok, "Failed to read test register");
81 : // BOOST_CHECK_EQUAL(val, 0xDEADBEEF);
82 : // }
|