xapian-core  1.4.26
soaktest.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2010 Richard Boulton
5  * Copyright (C) 2011,2013,2022 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 "soaktest/soaktest.h"
26 
27 #include "soaktest/soaktest_all.h"
28 #include "testrunner.h"
29 #include "testsuite.h"
30 
31 #include <random>
32 
33 using namespace std;
34 
35 static unsigned int g_random_seed;
36 
37 static mt19937 gen;
38 
39 extern unsigned int initrand()
40 {
41  tout << "Setting random seed to " << g_random_seed << "\n";
42  gen.seed(g_random_seed);
43  return g_random_seed;
44 }
45 
46 extern unsigned int randint(unsigned int s)
47 {
48  uniform_int_distribution<> distribution(0, s - 1);
49  return static_cast<unsigned int>(distribution(gen));
50 }
51 
52 class SoakTestRunner : public TestRunner
53 {
54  string seed_str;
55  public:
56  SoakTestRunner() : seed_str("42") {
57  test_driver::add_command_line_option("seed", 's', &seed_str);
58  }
59 
60  int run() const {
61  int result = 0;
62  g_random_seed = atoi(seed_str.c_str());
64  return result;
65  }
66 };
67 
68 int main(int argc, char **argv)
69 {
70  SoakTestRunner runner;
71  return runner.run_tests(argc, argv);
72 }
Run multiple tests for different backends.
string seed_str
Definition: soaktest.cc:54
a generic test suite engine
STL namespace.
int main(int argc, char **argv)
Definition: soaktest.cc:68
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
int run_tests(int argc, char **argv)
Run all the tests.
Definition: testrunner.cc:136
static unsigned int g_random_seed
Definition: soaktest.cc:35
std::ostringstream tout
The debug printing stream.
Definition: testsuite.cc:104
A test runner, which runs the tests (implemented by subclassing it) with a variety of backends...
Definition: testrunner.h:36
int run() const
Run the tests with a particular backend.
Definition: soaktest.cc:60
static mt19937 gen
Definition: soaktest.cc:37
unsigned int randint(unsigned int s)
Return a random integer in the range 0 to s-1.
Definition: soaktest.cc:46
Long-running "soak" tests for Xapian.
unsigned int initrand()
Initialise the random number generator with the seed.
Definition: soaktest.cc:39