xapian-core  1.4.20
soaktest.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2010 Richard Boulton
5  * Copyright (C) 2011,2013 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 // random() and srandom() aren't in <cstdlib> with Sun's compiler.
32 #include <stdlib.h>
33 
34 using namespace std;
35 
36 unsigned int g_random_seed;
37 
38 extern unsigned int initrand()
39 {
40  tout << "Setting random seed to " << g_random_seed << "\n";
41 #if defined HAVE_SRANDOM && defined HAVE_RANDOM
42  srandom(g_random_seed);
43 #else
44  srand(g_random_seed);
45 #endif
46  return g_random_seed;
47 }
48 
49 extern unsigned int randint(unsigned int s)
50 {
51 #if defined HAVE_SRANDOM && defined HAVE_RANDOM
52  unsigned long int r = static_cast<unsigned long int>(random());
53  r = r % static_cast<unsigned long int>(s);
54  return static_cast<unsigned int>(r);
55 #else
56  unsigned int r = static_cast<unsigned long int>(rand());
57  // The low order bits have lousy randomness on some platforms.
58  r = r / (RAND_MAX / s);
59  return r;
60 #endif
61 }
62 
63 class SoakTestRunner : public TestRunner
64 {
65  string seed_str;
66  public:
67  SoakTestRunner() : seed_str("42") {
68  test_driver::add_command_line_option("seed", 's', &seed_str);
69  }
70 
71  int run() const {
72  int result = 0;
73  g_random_seed = atoi(seed_str.c_str());
75  return result;
76  }
77 };
78 
79 int main(int argc, char **argv)
80 {
81  SoakTestRunner runner;
82  return runner.run_tests(argc, argv);
83 }
Run multiple tests for different backends.
string seed_str
Definition: soaktest.cc:65
a generic test suite engine
STL namespace.
int main(int argc, char **argv)
Definition: soaktest.cc:79
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
int run_tests(int argc, char **argv)
Run all the tests.
Definition: testrunner.cc:137
unsigned int g_random_seed
Definition: soaktest.cc:36
std::ostringstream tout
The debug printing stream.
Definition: testsuite.cc:103
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:71
unsigned int randint(unsigned int s)
Return a random integer in the range 0 to s-1.
Definition: soaktest.cc:49
Long-running "soak" tests for Xapian.
unsigned int initrand()
Initialise the random number generator with the seed.
Definition: soaktest.cc:38