xapian-core  1.4.26
testrunner.cc
Go to the documentation of this file.
1 
4 /* Copyright 2008,2009 Lemur Consulting Ltd
5  * Copyright 2008,2009,2010,2011,2015,2017,2018,2019,2023 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_chert.h"
30 #include "backendmanager_glass.h"
32 #include "backendmanager_multi.h"
36 
37 #include "stringutils.h"
38 #include <iostream>
39 
40 using namespace std;
41 
43 
45 
46 bool
48 {
49  if (user_backend.empty())
50  return true;
51  if (backend_name == user_backend)
52  return true;
53  if (startswith(backend_name, user_backend + "_"))
54  return true;
55  return false;
56 }
57 
58 void
60 {
62  struct BackendProperties {
63  const char * name;
64  unsigned properties;
65  };
66 
68  static const BackendProperties backend_properties[] = {
69  { "none", 0 },
70  { "inmemory", INMEMORY|
71  BACKEND|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
72  { "chert", CHERT|
73  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|SPELLING|METADATA|
74  SYNONYMS|VALUESTATS|CHECK|COMPACT|PATH
75 #ifdef XAPIAN_HAS_REMOTE_BACKEND
76  |REPLICAS
77 #endif
78  },
79  { "glass", GLASS|
80  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|SPELLING|METADATA|
81  SYNONYMS|VALUESTATS|CHECK|COMPACT|PATH
82 #ifdef XAPIAN_HAS_REMOTE_BACKEND
83  |REPLICAS
84 #endif
85  },
86  { "multi_chert", MULTI|
87  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS|
88  PATH },
89  { "multi_glass", MULTI|
90  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS|
91  SPELLING|CHECK|COMPACT|PATH },
92  { "remoteprog_chert", REMOTE|
93  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
94  { "remotetcp_chert", REMOTE|
95  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
96  { "multi_glass_remoteprog_glass", MULTI|REMOTE|
97  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
98  { "multi_remoteprog_glass", MULTI|REMOTE|
99  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
100  { "remoteprog_glass", REMOTE|
101  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS
102  },
103  { "remotetcp_glass", REMOTE|
104  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS
105  },
106  { "singlefile_glass", SINGLEFILE|
107  BACKEND|POSITIONAL|METADATA|SPELLING|SYNONYMS|VALUESTATS|
108  CHECK|COMPACT|PATH
109  },
110  { NULL, 0 }
111  };
112 
113  for (const BackendProperties * i = backend_properties; i->name; ++i) {
114  if (backend_name == i->name) {
115  properties = i->properties;
116  return;
117  }
118  }
119  throw Xapian::InvalidArgumentError("Unknown backend " + backend_name);
120 }
121 
122 void
124 {
125  const string& backend_name = manager->get_dbtype();
126  if (use_backend(backend_name)) {
127  set_properties_for_backend(backend_name);
128  cout << "Running tests with backend \"" << backend_name << "\"...\n";
129  backendmanager = manager;
130  result_so_far = max(result_so_far, run());
131  backendmanager = NULL;
132  }
133 }
134 
135 int
136 TestRunner::run_tests(int argc, char ** argv)
137 {
138  result_so_far = 0;
139  try {
140  test_driver::add_command_line_option("backend", 'b', &user_backend);
143  string datadir = srcdir + "/testdata/";
144 
145  do_tests_for_backend(BackendManager(string(), "none"));
146 
147 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
148  do_tests_for_backend(BackendManagerInMemory(datadir));
149 #endif
150 
151 #ifdef XAPIAN_HAS_GLASS_BACKEND
152  {
153  BackendManagerGlass glass_man(datadir);
154 
155  // Vector for multi backendmanagers.
156  vector<BackendManager*> multi_mans;
157  multi_mans = {&glass_man, &glass_man};
158 
159  do_tests_for_backend(glass_man);
160  do_tests_for_backend(BackendManagerSingleFile(datadir, &glass_man));
161  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
162 # ifdef XAPIAN_HAS_REMOTE_BACKEND
163  BackendManagerGlass sub_glass_man(datadir);
164  BackendManagerRemoteProg remoteprog_glass_man(&sub_glass_man);
165 
166  multi_mans = {&glass_man, &remoteprog_glass_man};
167 
168  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
169 
170  multi_mans = {&remoteprog_glass_man, &remoteprog_glass_man};
171 
172  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
173 
174  do_tests_for_backend(BackendManagerRemoteProg(&glass_man));
175  do_tests_for_backend(BackendManagerRemoteTcp(&glass_man));
176 # endif
177  }
178 #endif
179 
180  {
181  BackendManagerChert chert_man(datadir);
182 
183  // Vector for multi backendmanagers.
184  vector<BackendManager*> multi_mans;
185  multi_mans = {&chert_man, &chert_man};
186 
187 #ifdef XAPIAN_HAS_CHERT_BACKEND
188  do_tests_for_backend(chert_man);
189  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
190 # ifdef XAPIAN_HAS_REMOTE_BACKEND
191  do_tests_for_backend(BackendManagerRemoteProg(&chert_man));
192  do_tests_for_backend(BackendManagerRemoteTcp(&chert_man));
193 # endif
194  }
195 #endif
196  } catch (const std::exception& e) {
197  cerr << "\nTest harness failed with std::exception: " << e.what()
198  << '\n';
199  return 1;
200  } catch (const Xapian::Error &e) {
201  cerr << "\nTest harness failed with " << e.get_description() << '\n';
202  return 1;
203  } catch (const std::string &e) {
204  cerr << "\nTest harness failed with \"" << e << "\"\n";
205  return 1;
206  } catch (const char * e) {
207  cout << e << '\n';
208  return 1;
209  }
210  return result_so_far;
211 }
Run multiple tests for different backends.
const char * backend_name(int code)
Definition: backends.h:33
const std::string & get_dbtype() const
Get the database type currently in use.
static void parse_command_line(int argc, char **argv)
Parse the command line arguments.
Definition: testsuite.cc:828
BackendManager subclass for chert databases.
a generic test suite engine
STL namespace.
void set_properties_for_backend(const std::string &backend_name)
Set the property flags to those for the named backend.
Definition: testrunner.cc:59
BackendManager subclass for singlefile databases.
BackendManager subclass for remotetcp databases.
BackendManager subclass for multi databases.
static std::string get_srcdir()
Read srcdir from environment and if not present, make a valiant attempt to guess a value...
Definition: testsuite.cc:129
static void add_command_line_option(const std::string &l, char s, std::string *arg)
Add a test-specific command line option.
Definition: testsuite.cc:817
virtual ~TestRunner()
Virtual destructor - needed for abstract class.
Definition: testrunner.cc:44
int run_tests(int argc, char **argv)
Run all the tests.
Definition: testrunner.cc:136
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Definition: error.h:241
Base class for backend handling in test harness.
bool use_backend(const std::string &backend_name)
Return true iff we should use the named backend.
Definition: testrunner.cc:47
BackendManager subclass for remoteprog databases.
static string srcdir
Definition: stemtest.cc:43
BackendManager subclass for remoteprog databases.
BackendManager * backendmanager
backendmanager is global so that it can be accessed by individual tests.
Definition: testrunner.cc:42
void do_tests_for_backend_(BackendManager *manager)
Definition: testrunner.cc:123
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:51
BackendManager subclass for glass databases.
BackendManager subclass for remotetcp databases.
std::string get_description() const
Return a string describing this object.
Definition: error.cc:93
BackendManager subclass for singlefile databases.
BackendManager subclass for chert databases.
BackendManager subclass for multi databases.
char name[9]
Definition: dbcheck.cc:55
BackendManager subclass for inmemory databases.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
Definition: error.h:43
BackendManager subclass for inmemory databases.
Various handy helpers which std::string really should provide.
BackendManager subclass for glass databases.