LCOV - code coverage report
Current view: top level - utilities/unittest - ReusableThread_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 25 25
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 7 7

            Line data    Source code
       1              : /**
       2              :  *
       3              :  * @file ReusableThread_test.cxx Utility functions Unit Tests
       4              :  *
       5              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       6              :  * Licensing/copyright details are in the COPYING file that you should have
       7              :  * received with this code.
       8              :  */
       9              : 
      10              : #include "utilities/Issues.hpp"
      11              : #include "utilities/ReusableThread.hpp"
      12              : 
      13              : #define BOOST_TEST_MODULE ReusableThread_test // NOLINT
      14              : 
      15              : #include "boost/test/unit_test.hpp"
      16              : 
      17              : #include <chrono>
      18              : #include <filesystem>
      19              : #include <fstream>
      20              : 
      21              : using namespace dunedaq::utilities;
      22              : 
      23              : std::atomic<int> result;
      24              : void
      25            1 : test_fun(int input)
      26              : {
      27            1 :   std::this_thread::sleep_for(std::chrono::milliseconds(100));
      28            1 :   result = input;
      29            1 : }
      30              : 
      31            2 : BOOST_AUTO_TEST_CASE(Constructors)
      32              : {
      33            1 :   auto rt = new ReusableThread(1);
      34            1 :   delete rt; // NOLINT(build/raw_ownership)
      35            1 : }
      36              : 
      37            2 : BOOST_AUTO_TEST_CASE(CopyAndMoveSemantics)
      38              : {
      39            1 :   BOOST_REQUIRE(!std::is_copy_constructible_v<ReusableThread>);
      40            1 :   BOOST_REQUIRE(!std::is_copy_assignable_v<ReusableThread>);
      41            1 :   BOOST_REQUIRE(!std::is_move_constructible_v<ReusableThread>);
      42            1 :   BOOST_REQUIRE(!std::is_move_assignable_v<ReusableThread>);
      43            1 : }
      44              : 
      45            2 : BOOST_AUTO_TEST_CASE(SetWork)
      46              : {
      47            1 :   ReusableThread worker(2);
      48              : 
      49            1 :   result = 0;
      50            1 :   auto res = worker.set_work(test_fun, 5);
      51            1 :   BOOST_REQUIRE_EQUAL(res, true);
      52            1 :   res = worker.set_work(test_fun, 3);
      53            1 :   BOOST_REQUIRE_EQUAL(res, false);
      54              : 
      55           96 :   while (!worker.get_readiness()) {
      56           95 :     std::this_thread::sleep_for(std::chrono::milliseconds(1));
      57              :   }
      58            1 :   BOOST_REQUIRE_EQUAL(result, 5);
      59            1 : }
        

Generated by: LCOV version 2.0-1