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