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-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
|
|
|
|
2008-12-02 18:53:05 +01:00
|
|
|
#include <unittest/Registry.hpp>
|
|
|
|
|
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-01-15 00:40:19 +01:00
|
|
|
namespace mongo {
|
2009-01-15 16:17:11 +01:00
|
|
|
extern const char* dbpath;
|
2009-01-15 00:40:19 +01:00
|
|
|
} // namespace mongo
|
2008-12-03 19:25:06 +01:00
|
|
|
string dbpathSpec = "/tmp/unittest/";
|
|
|
|
|
2009-05-12 22:37:23 +02:00
|
|
|
Suite::~Suite() {
|
|
|
|
DBDirectClient c;
|
|
|
|
c.dropDatabase( "unittests" );
|
|
|
|
}
|
|
|
|
|
2008-12-03 19:25:06 +01:00
|
|
|
void usage() {
|
2008-12-29 02:28:49 +01:00
|
|
|
string instructions =
|
|
|
|
"dbtests usage:\n"
|
|
|
|
" -help show this message\n"
|
|
|
|
" -dbpath <path> configure db data path for this test run\n"
|
|
|
|
" (default is /tmp/unittest/)\n"
|
|
|
|
" -debug run tests with verbose output\n"
|
|
|
|
" -list list available test suites\n"
|
2009-01-17 16:25:56 +01:00
|
|
|
" -seed <seed> random number seed\n"
|
2008-12-29 02:28:49 +01:00
|
|
|
" <suite> run the specified test suite only";
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << instructions << endl;
|
2008-12-03 19:25:06 +01:00
|
|
|
}
|
2008-12-02 18:53:05 +01:00
|
|
|
|
|
|
|
int main( int argc, char** argv ) {
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-01-17 16:25:56 +01:00
|
|
|
unsigned long long seed = time( 0 );
|
|
|
|
|
2008-12-29 02:28:49 +01:00
|
|
|
int offset = 0;
|
|
|
|
for ( int i = 1; i < argc; ++i ) {
|
|
|
|
if ( argv[ i ] == string( "-dbpath" ) ) {
|
|
|
|
if ( i == argc - 1 ) {
|
|
|
|
usage();
|
2009-01-25 18:40:11 +01:00
|
|
|
dbexit( -1 );
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
|
|
|
dbpathSpec = argv[ ++i ];
|
|
|
|
offset += 2;
|
2009-01-17 16:25:56 +01:00
|
|
|
} else if ( argv[ i ] == string( "-seed" ) ) {
|
|
|
|
if ( i == argc - 1 ) {
|
|
|
|
usage();
|
2009-01-25 18:40:11 +01:00
|
|
|
dbexit( -1 );
|
2009-01-17 16:25:56 +01:00
|
|
|
}
|
|
|
|
// Don't bother checking for conversion error
|
|
|
|
seed = strtoll( argv[ ++i ], 0, 10 );
|
|
|
|
offset += 2;
|
2008-12-29 02:28:49 +01:00
|
|
|
} else if ( argv[ i ] == string( "-help" ) ) {
|
|
|
|
usage();
|
2009-01-25 18:40:11 +01:00
|
|
|
dbexit( 0 );
|
2008-12-29 02:28:49 +01:00
|
|
|
} else if ( offset ) {
|
|
|
|
argv[ i - offset ] = argv[ i ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= offset;
|
|
|
|
|
|
|
|
if ( dbpathSpec[ dbpathSpec.length() - 1 ] != '/' )
|
|
|
|
dbpathSpec += "/";
|
|
|
|
dbpath = dbpathSpec.c_str();
|
|
|
|
|
2009-05-11 20:01:09 +02:00
|
|
|
#if !defined(_WIN32) && !defined(__sunos__)
|
|
|
|
string name = ( boost::filesystem::path( dbpath ) / "mongod.lock" ).native_file_string();
|
|
|
|
int lockFile = open( name.c_str(), O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO );
|
|
|
|
massert( "Unable to create / open lock file for dbpath: " + name, lockFile > 0 );
|
|
|
|
massert( "Unable to acquire lock for dbpath: " + name, flock( lockFile, LOCK_EX | LOCK_NB ) == 0 );
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
#if !defined(_WIN32)
|
|
|
|
theFileAllocator().start();
|
|
|
|
#endif
|
|
|
|
|
2008-12-29 02:28:49 +01:00
|
|
|
UnitTest::Registry tests;
|
|
|
|
|
2009-02-03 17:50:30 +01:00
|
|
|
// NOTE Starting JNI changes global state (for example, locale and FPU precision);
|
|
|
|
// make sure all tests run with this setup, by running javajs tests first.
|
2009-04-24 04:44:19 +02:00
|
|
|
tests.add( jsTests(), "js" );
|
2009-02-03 17:50:30 +01:00
|
|
|
|
2009-04-28 16:11:39 +02:00
|
|
|
tests.add( basicTests(), "basic" );
|
2009-02-03 17:50:30 +01:00
|
|
|
tests.add( btreeTests(), "btree" );
|
2009-05-11 16:49:30 +02:00
|
|
|
tests.add( cursorTests(), "cursor" );
|
2008-12-29 02:28:49 +01:00
|
|
|
tests.add( jsobjTests(), "jsobj" );
|
2009-01-17 14:57:27 +01:00
|
|
|
tests.add( jsonTests(), "json" );
|
2009-01-20 21:44:40 +01:00
|
|
|
tests.add( matcherTests(), "matcher" );
|
2009-02-03 05:42:34 +01:00
|
|
|
tests.add( namespaceTests(), "namespace" );
|
2008-12-29 04:16:58 +01:00
|
|
|
tests.add( pairingTests(), "pairing" );
|
2009-02-03 05:42:34 +01:00
|
|
|
tests.add( pdfileTests(), "pdfile" );
|
2009-01-20 22:54:57 +01:00
|
|
|
tests.add( queryTests(), "query" );
|
2009-02-17 21:53:19 +01:00
|
|
|
tests.add( queryOptimizerTests(), "queryoptimizer" );
|
2009-01-23 16:17:29 +01:00
|
|
|
tests.add( replTests(), "repl" );
|
2009-01-21 21:50:49 +01:00
|
|
|
tests.add( sockTests(), "sock" );
|
2009-03-23 23:32:05 +01:00
|
|
|
tests.add( updateTests(), "update" );
|
2009-05-11 20:01:09 +02:00
|
|
|
|
|
|
|
int ret = tests.run( argc, argv );
|
|
|
|
|
|
|
|
#if !defined(_WIN32) && !defined(__sunos__)
|
|
|
|
flock( lockFile, LOCK_UN );
|
|
|
|
#endif
|
2008-12-29 02:28:49 +01:00
|
|
|
|
2009-05-11 20:01:09 +02:00
|
|
|
return ret;
|
2008-12-02 18:53:05 +01:00
|
|
|
}
|