LCOV - code coverage report
Current view: top level - tpglibs/unittest - avx_factory_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 95.6 % 45 43
Test Date: 2026-10-11 15:05:20 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /**
       2              :  * @file avx_factory_test.cxx
       3              :  *
       4              :  * @copyright This is part of the DUNE DAQ Software Suite, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #define BOOST_TEST_MODULE boost_test_macro_overview
      10              : #define FMT_HEADER_ONLY
      11              : 
      12              : #include "tpglibs/AVXFactory.hpp"
      13              : 
      14              : #include <boost/test/unit_test.hpp>
      15              : #include <fmt/core.h>
      16              : #include <fmt/ranges.h>
      17              : 
      18              : namespace tpglibs {
      19              : 
      20            2 : BOOST_AUTO_TEST_CASE(test_macro_overview)
      21              : {
      22              :   // This is the focus test. The rest is just to make something interesting to pass.
      23            1 :   auto avx_factory = AVXFactory::get_instance();
      24            1 :   std::shared_ptr<AVXProcessor> threshold = avx_factory->create_processor("AVXThresholdProcessor");
      25            1 :   std::shared_ptr<AVXProcessor> abs_rs = avx_factory->create_processor("AVXAbsRunSumProcessor");
      26            1 :   std::shared_ptr<AVXProcessor> rs = avx_factory->create_processor("AVXRunSumProcessor");
      27              : 
      28            1 :   int16_t plane_numbers[16] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2 };
      29              : 
      30           10 :   nlohmann::json thr_config = { { "plane0", 300 }, { "plane1", 1000 }, { "plane2", 1600 } };
      31            1 :   threshold->configure(thr_config, plane_numbers);
      32              : 
      33            5 :   nlohmann::json rs_config = { { "memory_factor_plane0", 8 },   { "memory_factor_plane1", 8 },
      34            4 :                                { "memory_factor_plane2", 8 },   { "scale_factor_plane0", 5 },
      35            4 :                                { "scale_factor_plane1", 5 },    { "scale_factor_plane2", 5 },
      36            4 :                                { "memory_divisor_plane0", 10 }, { "memory_divisor_plane1", 10 },
      37            4 :                                { "memory_divisor_plane2", 10 }, { "scale_divisor_plane0", 10 },
      38           37 :                                { "scale_divisor_plane1", 10 },  { "scale_divisor_plane2", 10 } };
      39            1 :   abs_rs->configure(rs_config, plane_numbers);
      40            1 :   rs->configure(rs_config, plane_numbers);
      41              : 
      42            1 :   abs_rs->set_next_processor(threshold);
      43            1 :   rs->set_next_processor(threshold);
      44              : 
      45              :   // Arbitrary input choices. Set so RS resets to 0.
      46            1 :   __m256i input0 =
      47            1 :     _mm256_set_epi16(-1600, 1500, -1400, 1300, -1200, 1100, -1000, 900, -800, 700, -600, 500, -400, 300, -200, 100);
      48            1 :   __m256i input1 =
      49            1 :     _mm256_set_epi16(2880, -2700, 2520, -2340, 2160, -1980, 1800, -1620, 1440, -1260, 1080, -900, 720, -540, 360, -180);
      50            1 :   __m256i input2 =
      51            1 :     _mm256_set_epi16(-1280, 1200, -1120, 1040, -960, 880, -800, 720, -640, 560, -480, 400, -320, 240, -160, 80);
      52              : 
      53            1 :   __m256i avx_abs_output = abs_rs->process(input0);
      54            1 :   avx_abs_output = abs_rs->process(input1);
      55            1 :   avx_abs_output = abs_rs->process(input2);
      56              : 
      57            1 :   __m256i avx_rs_output = rs->process(input0);
      58            1 :   avx_rs_output = rs->process(input1);
      59            1 :   avx_rs_output = rs->process(input2);
      60              : 
      61            1 :   int16_t abs_output[16], rs_output[16];
      62            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&abs_output), avx_abs_output);
      63            1 :   _mm256_storeu_si256(reinterpret_cast<__m256i*>(&rs_output), avx_rs_output);
      64              : 
      65            1 :   bool same_abs = true;
      66            1 :   bool same_rs = true;
      67              : 
      68            1 :   int16_t expected_abs[16] = { 0, 0, 432, 576, 720, 0, 1008, 1152, 1296, 1440, 0, 1728, 1872, 2016, 2160, 2304 };
      69            1 :   int16_t expected_rs[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
      70              : 
      71           17 :   for (int i = 0; i < 16; i++) {
      72           16 :     if (expected_abs[i] != abs_output[i])
      73            0 :       same_abs = false;
      74           16 :     if (expected_rs[i] != rs_output[i])
      75            0 :       same_rs = false;
      76              :   }
      77              : 
      78              :   //  fmt::print("AbsRS: [{:5}]\n", fmt::join(abs_output, ","));
      79              :   //  fmt::print("RS:    [{:5}]\n", fmt::join(rs_output, ","));
      80              : 
      81            1 :   BOOST_TEST(same_abs);
      82            1 :   BOOST_TEST(same_rs);
      83           34 : }
      84              : 
      85              : } // namespace tpglibs
        

Generated by: LCOV version 2.0-1