LCOV - code coverage report
Current view: top level - UTests - testTempBuffer.cpp (source / functions) Hit Total Coverage
Test: Coverage example Lines: 34 34 100.0 %
Date: 2021-12-02 17:21:05 Functions: 9 9 100.0 %

          Line data    Source code
       1             : ///////////////////////////////////////////////////////////////////////////
       2             : // Spetabaru - Berenger Bramas MPCDF - 2017
       3             : // Under LGPL Licence, please you must read the LICENCE file.
       4             : ///////////////////////////////////////////////////////////////////////////
       5             : 
       6             : #include "UTester.hpp"
       7             : 
       8             : #include "Data/SpDataAccessMode.hpp"
       9             : #include "Utils/SpUtils.hpp"
      10             : 
      11             : #include "Task/SpTask.hpp"
      12             : #include "Legacy/SpRuntime.hpp"
      13             : 
      14             : #include "Utils/SpBufferDataView.hpp"
      15             : 
      16             : class TestClassWithCounter{
      17             :     static std::atomic<int> NbCreated;
      18             :     static std::atomic<int> NbDeleted;
      19             : 
      20             : public:
      21           1 :     TestClassWithCounter(){
      22           1 :         NbCreated += 1;
      23           1 :     }
      24             : 
      25             :     TestClassWithCounter(const TestClassWithCounter&) = delete;
      26             :     TestClassWithCounter(TestClassWithCounter&&) = delete;
      27             : 
      28             :     TestClassWithCounter& operator=(TestClassWithCounter&&) = delete;
      29             :     TestClassWithCounter& operator=(const TestClassWithCounter&) = delete;
      30             : 
      31           1 :     ~TestClassWithCounter(){
      32           1 :         NbDeleted += 1;
      33           1 :     }
      34             : 
      35           3 :     static int GetNbCreated(){
      36           3 :         return NbCreated;
      37             :     }
      38             : 
      39           3 :     static int GetNbDeleted(){
      40           3 :         return NbDeleted;
      41             :     }
      42             : };
      43             : 
      44             : std::atomic<int> TestClassWithCounter::NbCreated(0);
      45             : std::atomic<int> TestClassWithCounter::NbDeleted(0);
      46             : 
      47             : 
      48             : class BufferTest : public UTester< BufferTest > {
      49             :     using Parent = UTester< BufferTest >;
      50             : 
      51           1 :     void TestBasic(){
      52           1 :         const int NumThreads = SpUtils::DefaultNumThreads();
      53           1 :         SpRuntime runtime(NumThreads);
      54             : 
      55             :         {
      56           1 :             SpBufferDataView<TestClassWithCounter> testBuffer;
      57             : 
      58           1 :             TestClassWithCounter* objectPtr = nullptr;
      59             : 
      60           1 :             runtime.task(SpWrite(testBuffer.getDataDep()),
      61           1 :                          [&objectPtr](SpDataBuffer<TestClassWithCounter> testObject){
      62           1 :                 objectPtr = &(*testObject);
      63           2 :             });
      64           1 :             runtime.task(SpWrite(testBuffer.getDataDep()),
      65           2 :                          [this,&objectPtr](SpDataBuffer<TestClassWithCounter> testObject){
      66           1 :                 UASSERTETRUE(objectPtr == &(*testObject));
      67           3 :             });
      68             : 
      69           1 :             runtime.waitAllTasks();
      70             : 
      71           1 :             runtime.stopAllThreads();
      72             : 
      73           1 :             UASSERTETRUE(TestClassWithCounter::GetNbCreated() != TestClassWithCounter::GetNbDeleted());
      74             :         }
      75           1 :         std::cout << "TestClassWithCounter::GetNbCreated() " << TestClassWithCounter::GetNbCreated() << std::endl;
      76           1 :         std::cout << "TestClassWithCounter::GetNbDeleted() " << TestClassWithCounter::GetNbDeleted() << std::endl;
      77             : 
      78           1 :         UASSERTETRUE(TestClassWithCounter::GetNbCreated() == TestClassWithCounter::GetNbDeleted());
      79           1 :     }
      80             : 
      81           1 :     void SetTests() {
      82           1 :         Parent::AddTest(&BufferTest::TestBasic, "Basic test for vec type");
      83           1 :     }
      84             : };
      85             : 
      86             : // You must do this
      87           1 : TestClass(BufferTest)
      88             : 
      89             : 

Generated by: LCOV version 1.14