LCOV - code coverage report
Current view: top level - tests/kdb - testkdb_allplugins.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 22 24 91.7 %
Date: 2019-09-12 12:28:41 Functions: 11 13 84.6 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Tests for the Backend builder class
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #define ELEKTRA_PLUGINSPEC_WITH_COMPARE
      11             : 
      12             : #include <backend.hpp>
      13             : #include <backends.hpp>
      14             : #include <plugindatabase.hpp>
      15             : 
      16             : #include <algorithm>
      17             : #include <iostream>
      18             : #include <string>
      19             : #include <unordered_map>
      20             : 
      21             : #include <gtest/gtest.h>
      22             : #include <kdb.hpp>
      23             : #include <kdbconfig.h>
      24             : 
      25             : #ifdef ENABLE_ASAN
      26             : #include <sanitizer/lsan_interface.h>
      27             : #endif
      28             : 
      29           4 : std::vector<std::string> getAllPlugins ()
      30             : {
      31             :         using namespace kdb;
      32             :         using namespace kdb::tools;
      33           8 :         ModulesPluginDatabase mpd;
      34           4 :         std::vector<std::string> plugins = mpd.listAllPlugins ();
      35             : 
      36             :         // The JNI and Ruby plugins cause segmentation faults
      37          28 :         plugins.erase (std::remove (plugins.begin (), plugins.end (), "jni"), plugins.end ());
      38          28 :         plugins.erase (std::remove (plugins.begin (), plugins.end (), "ruby"), plugins.end ());
      39             : 
      40             : #ifdef ENABLE_ASAN
      41             :         // ASAN reports memory leaks for the Augeas plugin on macOS: https://travis-ci.org/sanssecours/elektra/jobs/418524229
      42             :         plugins.erase (std::remove (plugins.begin (), plugins.end (), "augeas"), plugins.end ());
      43             : 
      44             :         std::vector<std::string> pluginsWithMemoryLeaks;
      45             : 
      46             :         for (auto plugin : plugins)
      47             :         {
      48             :                 try
      49             :                 {
      50             :                         __lsan_disable ();
      51             :                         auto status = mpd.lookupInfo (PluginSpec (plugin), "status");
      52             :                         __lsan_enable ();
      53             :                         if (status.find ("memleak")) pluginsWithMemoryLeaks.push_back (plugin);
      54             :                 }
      55             :                 catch (std::exception const & error)
      56             :                 {
      57             :                         std::cerr << "Unable to determine status of plugin “" << plugin << "”: " << error.what () << std::endl;
      58             :                 }
      59             :         }
      60             : 
      61             :         for (auto plugin : pluginsWithMemoryLeaks)
      62             :         {
      63             :                 plugins.erase (std::remove (plugins.begin (), plugins.end (), plugin), plugins.end ());
      64             :         }
      65             : #endif
      66             : 
      67           4 :         return plugins;
      68             : }
      69             : 
      70        1680 : class AllPlugins : public ::testing::TestWithParam<std::string>
      71             : {
      72             : protected:
      73             : };
      74             : 
      75        1066 : TEST_P (AllPlugins, backend)
      76             : {
      77             :         using namespace kdb;
      78             :         using namespace kdb::tools;
      79         630 :         std::string p = GetParam ();
      80         420 :         std::cout << p << std::endl;
      81             : 
      82             :         try
      83             :         {
      84         420 :                 Backend b;
      85         848 :                 b.addPlugin (PluginSpec (p));
      86             :         }
      87          16 :         catch (std::exception const & e)
      88             :         {
      89          24 :                 EXPECT_TRUE (true) << p;
      90             :         }
      91         210 : }
      92             : 
      93        1066 : TEST_P (AllPlugins, modules)
      94             : {
      95             :         using namespace kdb;
      96             :         using namespace kdb::tools;
      97         630 :         std::string p = GetParam ();
      98         420 :         std::cout << p << std::endl;
      99             : 
     100             :         try
     101             :         {
     102         420 :                 Modules m;
     103         210 :                 m.load (p);
     104             :         }
     105           0 :         catch (std::exception const & e)
     106             :         {
     107           0 :                 EXPECT_TRUE (true) << p;
     108             :         }
     109         210 : }
     110             : 
     111             : 
     112         450 : INSTANTIATE_TEST_CASE_P (AllPlugins, AllPlugins, testing::ValuesIn (getAllPlugins ()), );

Generated by: LCOV version 1.13