LCOV - code coverage report
Current view: top level - tests/harness - testrunner.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 39 58 67.2 %
Date: 2019-06-30 05:20:33 Functions: 7 7 100.0 %
Branches: 39 117 33.3 %

           Branch data     Line data    Source code
       1                 :            : /** @file testrunner.cc
       2                 :            :  * @brief Run multiple tests for different backends.
       3                 :            :  */
       4                 :            : /* Copyright 2008,2009 Lemur Consulting Ltd
       5                 :            :  * Copyright 2008,2009,2010,2011,2015,2017,2018,2019 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "testrunner.h"
      26                 :            : 
      27                 :            : #include "testsuite.h"
      28                 :            : #include "backendmanager.h"
      29                 :            : #include "backendmanager_glass.h"
      30                 :            : #include "backendmanager_honey.h"
      31                 :            : #include "backendmanager_inmemory.h"
      32                 :            : #include "backendmanager_multi.h"
      33                 :            : #include "backendmanager_remoteprog.h"
      34                 :            : #include "backendmanager_remotetcp.h"
      35                 :            : #include "backendmanager_singlefile.h"
      36                 :            : 
      37                 :            : #include "stringutils.h"
      38                 :            : #include <iostream>
      39                 :            : 
      40                 :            : using namespace std;
      41                 :            : 
      42                 :            : BackendManager * backendmanager;
      43                 :            : 
      44         [ -  + ]:          2 : TestRunner::~TestRunner() { }
      45                 :            : 
      46                 :            : bool
      47                 :          8 : TestRunner::use_backend(const string & backend_name)
      48                 :            : {
      49         [ +  - ]:          8 :     if (user_backend.empty())
      50                 :          8 :         return true;
      51         [ #  # ]:          0 :     if (backend_name == user_backend)
      52                 :          0 :         return true;
      53         [ #  # ]:          0 :     if (startswith(backend_name, user_backend + "_"))
      54                 :          0 :         return true;
      55                 :          0 :     return false;
      56                 :            : }
      57                 :            : 
      58                 :            : void
      59                 :          8 : TestRunner::set_properties_for_backend(const string & backend_name)
      60                 :            : {
      61                 :            :     /// A description of the properties which a particular backend supports.
      62                 :            :     struct BackendProperties {
      63                 :            :         const char * name;
      64                 :            :         unsigned properties;
      65                 :            :     };
      66                 :            : 
      67                 :            :     /// A list of the properties of each backend.
      68                 :            :     static const BackendProperties backend_properties[] = {
      69                 :            :         { "none", 0 },
      70                 :            :         { "inmemory", INMEMORY|
      71                 :            :             BACKEND|POSITIONAL|WRITABLE|METADATA|VALUESTATS|GENERATED },
      72                 :            :         { "glass", GLASS|
      73                 :            :             BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|SPELLING|METADATA|
      74                 :            :             SYNONYMS|VALUESTATS|GENERATED|COMPACT|PATH
      75                 :            : #ifdef XAPIAN_HAS_REMOTE_BACKEND
      76                 :            :             |REPLICAS
      77                 :            : #endif
      78                 :            :         },
      79                 :            :         { "multi_glass", MULTI|
      80                 :            :             BACKEND|POSITIONAL|WRITABLE|METADATA|
      81                 :            :             SYNONYMS|VALUESTATS|GENERATED|COMPACT|PATH },
      82                 :            :         { "remoteprog_glass", REMOTE|
      83                 :            :             BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS|
      84                 :            :             GENERATED
      85                 :            :         },
      86                 :            :         { "remotetcp_glass", REMOTE|
      87                 :            :             BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS|
      88                 :            :             GENERATED
      89                 :            :         },
      90                 :            :         { "singlefile_glass", SINGLEFILE|
      91                 :            :             BACKEND|POSITIONAL|VALUESTATS|COMPACT|PATH },
      92                 :            :         { "honey", HONEY|
      93                 :            :             BACKEND|POSITIONAL|VALUESTATS|COMPACT|PATH
      94                 :            : #ifdef XAPIAN_HAS_GLASS_BACKEND
      95                 :            :             |GENERATED
      96                 :            : #endif
      97                 :            :         },
      98                 :            :         { NULL, 0 }
      99                 :            :     };
     100                 :            : 
     101         [ +  - ]:         36 :     for (const BackendProperties * i = backend_properties; i->name; ++i) {
     102         [ +  + ]:         36 :         if (backend_name == i->name) {
     103                 :          8 :             properties = i->properties;
     104                 :          8 :             return;
     105                 :            :         }
     106                 :            :     }
     107 [ #  # ][ #  # ]:          0 :     throw Xapian::InvalidArgumentError("Unknown backend " + backend_name);
                 [ #  # ]
     108                 :            : }
     109                 :            : 
     110                 :            : void
     111                 :          8 : TestRunner::do_tests_for_backend_(BackendManager* manager)
     112                 :            : {
     113                 :          8 :     const string& backend_name = manager->get_dbtype();
     114 [ +  - ][ +  - ]:          8 :     if (use_backend(backend_name)) {
     115         [ +  - ]:          8 :         set_properties_for_backend(backend_name);
     116 [ +  - ][ +  - ]:          8 :         cout << "Running tests with backend \"" << backend_name << "\"..."
                 [ +  - ]
     117         [ +  - ]:          8 :              << endl;
     118                 :          8 :         backendmanager = manager;
     119         [ +  - ]:          8 :         result_so_far = max(result_so_far, run());
     120                 :          8 :         backendmanager = NULL;
     121                 :          8 :     }
     122                 :          8 : }
     123                 :            : 
     124                 :            : int
     125                 :          1 : TestRunner::run_tests(int argc, char ** argv)
     126                 :            : {
     127                 :          1 :     result_so_far = 0;
     128                 :            :     try {
     129 [ +  - ][ +  - ]:          1 :         test_driver::add_command_line_option("backend", 'b', &user_backend);
     130         [ +  - ]:          1 :         test_driver::parse_command_line(argc, argv);
     131 [ +  - ][ +  - ]:          1 :         srcdir = test_driver::get_srcdir();
     132         [ +  - ]:          1 :         string datadir = srcdir + "/testdata/";
     133                 :            : 
     134                 :            : #ifdef XAPIAN_HAS_HONEY_BACKEND
     135                 :            : # ifdef XAPIAN_HAS_GLASS_BACKEND
     136                 :            :         {
     137         [ +  - ]:          1 :             BackendManagerGlass glass_man(datadir);
     138 [ +  - ][ +  - ]:          1 :             do_tests_for_backend(BackendManagerHoney(datadir, &glass_man));
     139                 :            :         }
     140                 :            : # else
     141                 :            :         do_tests_for_backend(BackendManagerHoney(datadir));
     142                 :            : # endif
     143                 :            : #endif
     144                 :            : 
     145 [ +  - ][ +  - ]:          1 :         do_tests_for_backend(BackendManager(string()));
                 [ +  - ]
     146                 :            : 
     147                 :            : #ifdef XAPIAN_HAS_INMEMORY_BACKEND
     148 [ +  - ][ +  - ]:          1 :         do_tests_for_backend(BackendManagerInMemory(datadir));
     149                 :            : #endif
     150                 :            : 
     151                 :            : #ifdef XAPIAN_HAS_GLASS_BACKEND
     152                 :            :         {
     153         [ +  - ]:          1 :             BackendManagerGlass glass_man(datadir);
     154         [ +  - ]:          1 :             do_tests_for_backend(glass_man);
     155 [ +  - ][ +  - ]:          1 :             do_tests_for_backend(BackendManagerSingleFile(datadir, &glass_man));
     156 [ +  - ][ +  - ]:          1 :             do_tests_for_backend(BackendManagerMulti(datadir, &glass_man));
     157                 :            : # ifdef XAPIAN_HAS_REMOTE_BACKEND
     158 [ +  - ][ +  - ]:          1 :             do_tests_for_backend(BackendManagerRemoteProg(&glass_man));
     159 [ +  - ][ +  - ]:          1 :             do_tests_for_backend(BackendManagerRemoteTcp(&glass_man));
     160                 :            : # endif
     161                 :          1 :         }
     162                 :            : #endif
     163                 :          0 :     } catch (const std::exception& e) {
     164   [ #  #  #  # ]:          0 :         cerr << "\nTest harness failed with std::exception: " << e.what()
     165         [ #  # ]:          0 :              << endl;
     166                 :          0 :         return 1;
     167                 :          0 :     } catch (const Xapian::Error &e) {
     168   [ #  #  #  #  :          0 :         cerr << "\nTest harness failed with " << e.get_description() << endl;
             #  #  #  # ]
     169                 :          0 :         return 1;
     170                 :          0 :     } catch (const std::string &e) {
     171   [ #  #  #  #  :          0 :         cerr << "\nTest harness failed with \"" << e << "\"" << endl;
             #  #  #  # ]
     172                 :          0 :         return 1;
     173   [ #  #  #  #  :          0 :     } catch (const char * e) {
                      # ]
     174   [ #  #  #  # ]:          0 :         cout << e << endl;
     175                 :          0 :         return 1;
     176                 :            :     }
     177                 :          1 :     return result_so_far;
     178 [ +  - ][ +  - ]:         12 : }

Generated by: LCOV version 1.11