2015-04-27 09:12:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, Wesley Shields
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2015-04-29 19:36:24 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2015-04-29 19:36:24 +00:00
|
|
|
#include "osquery/core/test_util.h"
|
2015-05-24 01:52:42 +00:00
|
|
|
#include "osquery/database/db_handle.h"
|
2015-04-29 19:36:24 +00:00
|
|
|
|
2015-05-23 19:40:36 +00:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2015-04-29 19:36:24 +00:00
|
|
|
namespace osquery {
|
|
|
|
DECLARE_string(database_path);
|
|
|
|
DECLARE_string(extensions_socket);
|
|
|
|
DECLARE_string(modules_autoload);
|
|
|
|
DECLARE_string(extensions_autoload);
|
|
|
|
DECLARE_bool(disable_logging);
|
|
|
|
|
|
|
|
void initTesting() {
|
|
|
|
// Seed the random number generator, some tests generate temporary files
|
|
|
|
// ports, sockets, etc using random numbers.
|
|
|
|
std::chrono::milliseconds ms =
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
srand(ms.count());
|
|
|
|
|
|
|
|
// Set safe default values for path-based flags.
|
|
|
|
// Specific unittests may edit flags temporarily.
|
2015-05-23 19:40:36 +00:00
|
|
|
fs::remove_all(kTestWorkingDirectory);
|
|
|
|
fs::create_directories(kTestWorkingDirectory);
|
2015-04-29 19:36:24 +00:00
|
|
|
FLAGS_database_path = kTestWorkingDirectory + "unittests.db";
|
|
|
|
FLAGS_extensions_socket = kTestWorkingDirectory + "unittests.em";
|
|
|
|
FLAGS_extensions_autoload = kTestWorkingDirectory + "unittests-ext.load";
|
|
|
|
FLAGS_modules_autoload = kTestWorkingDirectory + "unittests-mod.load";
|
|
|
|
FLAGS_disable_logging = true;
|
|
|
|
|
|
|
|
// Create a default DBHandle instance before unittests.
|
|
|
|
(void)DBHandle::getInstance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
int main(int argc, char* argv[]) {
|
2015-05-23 19:40:36 +00:00
|
|
|
// Allow unit test execution from anywhere in the osquery source/build tree.
|
|
|
|
while (osquery::kTestDataPath != "/") {
|
|
|
|
if (!fs::exists(osquery::kTestDataPath)) {
|
|
|
|
osquery::kTestDataPath =
|
|
|
|
osquery::kTestDataPath.substr(3, osquery::kTestDataPath.size());
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 19:36:24 +00:00
|
|
|
osquery::initTesting();
|
2015-04-27 09:12:58 +00:00
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
// Optionally enable Goggle Logging
|
|
|
|
// google::InitGoogleLogging(argv[0]);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|