xapian-core  1.4.19
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 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|GENERATED },
72  { "chert", CHERT|
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  { "glass", GLASS|
80  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|SPELLING|METADATA|
81  SYNONYMS|VALUESTATS|GENERATED|COMPACT|PATH
82 #ifdef XAPIAN_HAS_REMOTE_BACKEND
83  |REPLICAS
84 #endif
85  },
86  { "multi_chert", MULTI|
87  BACKEND|POSITIONAL|WRITABLE|METADATA|
88  SYNONYMS|VALUESTATS|PATH },
89  { "multi_glass", MULTI|
90  BACKEND|POSITIONAL|WRITABLE|METADATA|
91  SYNONYMS|VALUESTATS|GENERATED|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|
97  BACKEND|REMOTE|WRITABLE|GENERATED },
98  { "multi_remoteprog_glass", MULTI|
99  BACKEND|REMOTE|WRITABLE|GENERATED },
100  { "remoteprog_glass", REMOTE|
101  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS|
102  GENERATED
103  },
104  { "remotetcp_glass", REMOTE|
105  BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS|
106  GENERATED
107  },
108  { "singlefile_glass", SINGLEFILE|
109  BACKEND|POSITIONAL|VALUESTATS|COMPACT|PATH },
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 << "\"..."
129  << endl;
130  backendmanager = manager;
131  result_so_far = max(result_so_far, run());
132  backendmanager = NULL;
133  }
134 }
135 
136 int
137 TestRunner::run_tests(int argc, char ** argv)
138 {
139  result_so_far = 0;
140  try {
141  test_driver::add_command_line_option("backend", 'b', &user_backend);
144  string datadir = srcdir + "/testdata/";
145 
146  do_tests_for_backend(BackendManager(string()));
147 
148 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
149  do_tests_for_backend(BackendManagerInMemory(datadir));
150 #endif
151 
152 #ifdef XAPIAN_HAS_GLASS_BACKEND
153  {
154  BackendManagerGlass glass_man(datadir);
155 
156  // Vector for multi backendmanagers.
157  vector<BackendManager*> multi_mans;
158  multi_mans = {&glass_man, &glass_man};
159 
160  do_tests_for_backend(glass_man);
161  do_tests_for_backend(BackendManagerSingleFile(datadir, &glass_man));
162  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
163 # ifdef XAPIAN_HAS_REMOTE_BACKEND
164  BackendManagerGlass sub_glass_man(datadir);
165  BackendManagerRemoteProg remoteprog_glass_man(&sub_glass_man);
166 
167  multi_mans = {&glass_man, &remoteprog_glass_man};
168 
169  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
170 
171  multi_mans = {&remoteprog_glass_man, &remoteprog_glass_man};
172 
173  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
174 
175  do_tests_for_backend(BackendManagerRemoteProg(&glass_man));
176  do_tests_for_backend(BackendManagerRemoteTcp(&glass_man));
177 # endif
178  }
179 #endif
180 
181  {
182  BackendManagerChert chert_man(datadir);
183 
184  // Vector for multi backendmanagers.
185  vector<BackendManager*> multi_mans;
186  multi_mans = {&chert_man, &chert_man};
187 
188 #ifdef XAPIAN_HAS_CHERT_BACKEND
189  do_tests_for_backend(chert_man);
190  do_tests_for_backend(BackendManagerMulti(datadir, multi_mans));
191 # ifdef XAPIAN_HAS_REMOTE_BACKEND
192  do_tests_for_backend(BackendManagerRemoteProg(&chert_man));
193  do_tests_for_backend(BackendManagerRemoteTcp(&chert_man));
194 # endif
195  }
196 #endif
197  } catch (const std::exception& e) {
198  cerr << "\nTest harness failed with std::exception: " << e.what()
199  << endl;
200  return 1;
201  } catch (const Xapian::Error &e) {
202  cerr << "\nTest harness failed with " << e.get_description() << endl;
203  return 1;
204  } catch (const std::string &e) {
205  cerr << "\nTest harness failed with \"" << e << "\"" << endl;
206  return 1;
207  } catch (const char * e) {
208  cout << e << endl;
209  return 1;
210  }
211  return result_so_far;
212 }
Run multiple tests for different backends.
const char * backend_name(int code)
Definition: backends.h:33
static void parse_command_line(int argc, char **argv)
Parse the command line arguments.
Definition: testsuite.cc:799
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:128
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:788
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:137
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:46
BackendManager subclass for glass databases.
BackendManager subclass for remotetcp databases.
virtual std::string get_dbtype() const
Get the database type currently in use.
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.