Line data Source code
1 :
2 : /**
3 : * @file TDE16Frame_test.cxx TDE16Frame class Unit Tests
4 : *
5 : * This is part of the DUNE DAQ Application Framework, copyright 2022.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 :
10 : #include "fddetdataformats/TDE16Frame.hpp"
11 :
12 : #define BOOST_TEST_MODULE TDE16Frame_test
13 :
14 : #include "boost/test/unit_test.hpp"
15 :
16 : #include <string>
17 : #include <vector>
18 :
19 : using namespace dunedaq::fddetdataformats;
20 :
21 : BOOST_AUTO_TEST_SUITE(TDE16Frame_test)
22 :
23 2 : BOOST_AUTO_TEST_CASE(TDE16Frame_StructMethods)
24 : {
25 1 : TDE16Frame tde16frame {};
26 :
27 1 : BOOST_REQUIRE(tde16frame.get_daq_header() != nullptr);
28 1 : BOOST_REQUIRE(tde16frame.get_tde_header() != nullptr);
29 1 : }
30 :
31 2 : BOOST_AUTO_TEST_CASE(TDE16Frame_HeaderMutators)
32 : {
33 1 : TDE16Frame tde16frame {};
34 1 : tde16frame.set_tde_errors(0xFC5F);
35 1 : tde16frame.set_timestamp(0x444455555555);
36 :
37 1 : BOOST_REQUIRE_EQUAL(tde16frame.get_tde_header()->tde_errors, 0xFC5F);
38 1 : BOOST_REQUIRE_EQUAL(tde16frame.get_daq_header()->timestamp, 0x444455555555);
39 1 : }
40 :
41 2 : BOOST_AUTO_TEST_CASE(TDE16Frame_StreamOperator)
42 : {
43 1 : TDE16Frame tde16frame {};
44 :
45 1 : std::ostringstream ostr;
46 1 : ostr << tde16frame;
47 1 : auto output = ostr.str();
48 1 : BOOST_TEST_MESSAGE("Stream operator: " << output);
49 1 : BOOST_REQUIRE(!output.empty());
50 1 : }
51 :
52 2 : BOOST_AUTO_TEST_CASE(TDE16Frame_ADCDataMutators)
53 : {
54 1 : TDE16Frame tde16frame {};
55 4475 : for(int i=0; i<tot_adc16_samples; i++) { tde16frame.set_adc_sample(0x63, i); }
56 :
57 31 : for(int i=0; i<30; i++) { BOOST_REQUIRE_EQUAL(tde16frame.get_adc_sample(i), 0x63); }
58 21 : for(int i=tot_adc16_samples-20; i<tot_adc16_samples; i++) { BOOST_REQUIRE_EQUAL(tde16frame.get_adc_sample(i), 0x63); }
59 1 : }
60 :
61 2 : BOOST_AUTO_TEST_CASE(TDE16Frame_FromRawData)
62 : {
63 1 : dunedaq::detdataformats::DAQEthHeader daq_header {};
64 1 : daq_header.timestamp = 0x222211111111;
65 1 : TDEHeader tde_header {};
66 1 : Sample samples_info[tot_adc16_samples] {};
67 :
68 1 : uint8_t* buff = static_cast<uint8_t*>(malloc(sizeof(daq_header)+sizeof(tde_header) + sizeof(samples_info)));
69 1 : memcpy(buff, &daq_header, sizeof(daq_header));
70 1 : memcpy(buff + sizeof(daq_header) + sizeof(tde_header), samples_info, sizeof(Sample) * tot_adc16_samples);
71 1 : TDE16Frame* from_raw_data = reinterpret_cast<TDE16Frame*>(buff);
72 :
73 1 : BOOST_REQUIRE_EQUAL(from_raw_data->get_timestamp(), 0x222211111111);
74 :
75 1 : from_raw_data = nullptr;
76 1 : free(buff);
77 1 : }
78 :
79 : BOOST_AUTO_TEST_SUITE_END()
|