2008-12-02 18:53:05 +01:00
|
|
|
// dbtests.cpp : Runs db unit tests.
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
2008-12-11 17:08:28 +01:00
|
|
|
* Copyright (C) 2008 10gen Inc.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-12-11 17:08:28 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-12-11 17:08:28 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-12-11 17:08:28 +01:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2008-12-02 18:53:05 +01:00
|
|
|
|
2008-12-03 19:25:06 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2009-09-18 18:14:48 +02:00
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
2009-05-12 22:37:23 +02:00
|
|
|
#include "../db/instance.h"
|
2009-04-16 17:14:06 +02:00
|
|
|
#include "../util/file_allocator.h"
|
2009-02-03 06:05:49 +01:00
|
|
|
|
2009-05-11 20:10:15 +02:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
#include <sys/file.h>
|
|
|
|
#endif
|
|
|
|
|
2009-05-12 22:54:07 +02:00
|
|
|
#include "dbtests.h"
|
|
|
|
|
2008-12-02 18:53:05 +01:00
|
|
|
using namespace std;
|
2009-09-18 18:14:48 +02:00
|
|
|
namespace po = boost::program_options;
|
2008-12-02 18:53:05 +01:00
|
|
|
|
2009-01-15 00:40:19 +01:00
|
|
|
namespace mongo {
|
2009-08-11 20:29:03 +02:00
|
|
|
extern string dbpath;
|
2009-05-12 22:37:23 +02:00
|
|
|
}
|
|
|
|
|
2009-09-18 18:14:48 +02:00
|
|
|
void show_help_text(const char* name, po::options_description options) {
|
|
|
|
cout << "usage: " << name << " [options] [suite]..." << endl
|
|
|
|
<< options << "suite: run the specified test suite(s) only" << endl;
|
2008-12-03 19:25:06 +01:00
|
|
|
}
|
2008-12-02 18:53:05 +01:00
|
|
|
|
|
|
|
int main( int argc, char** argv ) {
|
2009-01-17 16:25:56 +01:00
|
|
|
unsigned long long seed = time( 0 );
|
2009-09-18 18:14:48 +02:00
|
|
|
string dbpathSpec;
|
|
|
|
|
|
|
|
po::options_description shell_options("options");
|
|
|
|
po::options_description hidden_options("Hidden options");
|
|
|
|
po::options_description cmdline_options("Command line options");
|
|
|
|
po::positional_options_description positional_options;
|
|
|
|
|
|
|
|
shell_options.add_options()
|
|
|
|
("help,h", "show this usage information")
|
|
|
|
("dbpath", po::value<string>(&dbpathSpec)->default_value("/tmp/unittest/"),
|
|
|
|
"db data path for this test run")
|
|
|
|
("debug", "run tests with verbose output")
|
|
|
|
("list,l", "list available test suites")
|
|
|
|
("seed", po::value<unsigned long long>(&seed), "random number seed")
|
|
|
|
;
|
|
|
|
|
|
|
|
hidden_options.add_options()
|
|
|
|
("suites", po::value< vector<string> >(), "test suites to run")
|
|
|
|
;
|
|
|
|
|
|
|
|
positional_options.add("suites", -1);
|
|
|
|
|
|
|
|
cmdline_options.add(shell_options).add(hidden_options);
|
|
|
|
|
|
|
|
po::variables_map params;
|
|
|
|
int command_line_style = (((po::command_line_style::unix_style ^
|
|
|
|
po::command_line_style::allow_guessing) |
|
|
|
|
po::command_line_style::allow_long_disguise) ^
|
|
|
|
po::command_line_style::allow_sticky);
|
|
|
|
|
|
|
|
try {
|
|
|
|
po::store(po::command_line_parser(argc, argv).options(cmdline_options).
|
|
|
|
positional(positional_options).
|
|
|
|
style(command_line_style).run(), params);
|
|
|
|
po::notify(params);
|
|
|
|
} catch (po::error &e) {
|
|
|
|
cout << "ERROR: " << e.what() << endl << endl;
|
|
|
|
show_help_text(argv[0], shell_options);
|
|
|
|
return EXIT_BADOPTIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.count("help")) {
|
|
|
|
show_help_text(argv[0], shell_options);
|
|
|
|
return EXIT_CLEAN;
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( dbpathSpec[ dbpathSpec.length() - 1 ] != '/' )
|
|
|
|
dbpathSpec += "/";
|
|
|
|
dbpath = dbpathSpec.c_str();
|
|
|
|
|
2009-05-20 17:39:12 +02:00
|
|
|
acquirePathLock();
|
2009-09-18 18:14:48 +02:00
|
|
|
|
2009-01-16 22:40:46 +01:00
|
|
|
srand( seed );
|
2009-03-31 21:59:14 +02:00
|
|
|
printGitVersion();
|
|
|
|
printSysInfo();
|
2009-01-17 16:25:56 +01:00
|
|
|
out() << "random seed: " << seed << endl;
|
2009-02-03 06:05:49 +01:00
|
|
|
|
2009-04-16 17:14:06 +02:00
|
|
|
theFileAllocator().start();
|
2009-09-17 23:23:38 +02:00
|
|
|
|
2009-09-18 18:14:48 +02:00
|
|
|
vector<string> suites;
|
|
|
|
if (params.count("suites")) {
|
|
|
|
suites = params["suites"].as< vector<string> >();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = mongo::regression::Suite::run(params.count("debug"),
|
|
|
|
params.count("list"),
|
|
|
|
suites);
|
2009-09-17 23:23:38 +02:00
|
|
|
|
2009-05-11 20:01:09 +02:00
|
|
|
#if !defined(_WIN32) && !defined(__sunos__)
|
|
|
|
flock( lockFile, LOCK_UN );
|
2009-09-18 18:14:48 +02:00
|
|
|
#endif
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-08-06 17:32:35 +02:00
|
|
|
dbexit( (ExitCode)ret ); // so everything shuts down cleanly
|
2009-05-11 20:01:09 +02:00
|
|
|
return ret;
|
2008-12-02 18:53:05 +01:00
|
|
|
}
|