// Define main function as an entry to these tests.
// These test functions cannot use the main() defined for unittests because they
// call runGlobalInitializers(). The embedded C API calls mongoDbMain() which
// calls runGlobalInitializers().
int main(int argc, char** argv, char** envp) {

    moe::OptionsParser parser;
    moe::Environment environment;
    moe::OptionSection options;
    std::map<std::string, std::string> env;

    options.addOptionChaining(
        "tempPath", "tempPath", moe::String, "directory to place mongo::TempDir subdirectories");
    std::vector<std::string> argVector(argv, argv + argc);
    mongo::Status ret = parser.run(options, argVector, env, &environment);
    if (!ret.isOK()) {
        std::cerr << options.helpString();
        return EXIT_FAILURE;
    }
    if (environment.count("tempPath")) {
        ::mongo::unittest::TempDir::setTempPath(environment["tempPath"].as<std::string>());
    }

    ::mongo::clearSignalMask();
    ::mongo::setupSynchronousSignalHandlers();
    ::mongo::serverGlobalParams.noUnixSocket = true;
    ::mongo::unittest::setupTestLogger();
    auto result = ::mongo::unittest::Suite::run(std::vector<std::string>(), "", 1);
    globalTempDir.reset();
    mongo::quickExit(result);
}
Example #2
0
bool IsSubprocess(int & argc, char ** argv)
{
    std::vector<std::string> argVector(argv, argv + argc);

    for (auto i = 0; i < argc; ++i) {
        if (argVector[i].find("--type") != std::string::npos) {
            return true;
        }
    }

    return false;
}
Example #3
0
int main(int argc, char** argv)
{
	try
	{
		// store required reports in vector
		std::vector<Report*> reports;

		// put build array out of command line args and process
		{
			std::vector<std::string> argVector(argv+1, argv + argc);
			if (argVector.empty())
			{
				throw std::runtime_error("invalide number of arguements (" + boost::lexical_cast<std::string>(argVector.size()) + ")\n");
			}
			CommandLine::ParseCommandLineInstructions(argVector, reports);
		}

		// read data file into store
		ReadInputFile(inputDataFile);

		// run reports
		std::string output;
		for (auto report : reports)
		{
			output += report->Generate() + "\n";
		}
		// output to standard out and file
		std::cout << output; 
		std::ofstream output_file(outputDataFile);
		std::ostream_iterator<char> output_iterator(output_file);
		std::copy(output.begin(), output.end(), output_iterator);
		output_file.close();	
    }
	catch (std::logic_error& ex)
	{
		std::cerr << "A systematic error has occured: " << ex.what() << "\nExiting...\n" << std::endl;
	}
	catch (std::runtime_error& ex)
	{
		std::cerr << "A runtime error has occured: " << ex.what() << "\nExiting...\n" << std::endl;
	}
	catch (std::exception& ex)
	{
		std::cerr << "A unexpected error has occured: " << ex.what() << "\nExiting...\n" << std::endl;
	}
	catch (...)
	{
		std::cerr << "An unexpected error occured: Exiting...\n" << std::endl;
	}

	return 0;
}
// Define main function as an entry to these tests.
// These test functions cannot use the main() defined for unittests because they
// call runGlobalInitializers(). The embedded C API calls mongoDbMain() which
// calls runGlobalInitializers().
int main(int argc, char** argv, char** envp) {

    moe::OptionsParser parser;
    moe::Environment environment;
    moe::OptionSection options;
    std::map<std::string, std::string> env;

    options.addOptionChaining(
        "tempPath", "tempPath", moe::String, "directory to place mongo::TempDir subdirectories");
    std::vector<std::string> argVector(argv, argv + argc);
    mongo::Status ret = parser.run(options, argVector, env, &environment);
    if (!ret.isOK()) {
        std::cerr << options.helpString();
        return EXIT_FAILURE;
    }
    if (environment.count("tempPath")) {
        ::mongo::unittest::TempDir::setTempPath(environment["tempPath"].as<std::string>());
    }

    ::mongo::clearSignalMask();
    ::mongo::setupSynchronousSignalHandlers();
    ::mongo::serverGlobalParams.noUnixSocket = true;
    ::mongo::unittest::setupTestLogger();

    StatusPtr status(mongo_embedded_v1_status_create());
    mongoc_init();

    global_lib_handle = mongo_embedded_v1_lib_init(nullptr, status.get());
    if (global_lib_handle == nullptr) {
        std::cerr << "Error: " << mongo_embedded_v1_status_get_explanation(status.get());
        return EXIT_FAILURE;
    }

    auto result = ::mongo::unittest::Suite::run(std::vector<std::string>(), "", 1);

    if (mongo_embedded_v1_lib_fini(global_lib_handle, status.get()) != MONGO_EMBEDDED_V1_SUCCESS) {
        std::cerr << "Error: " << mongo_embedded_v1_status_get_explanation(status.get());
        return EXIT_FAILURE;
    }

    mongoc_cleanup();
    globalTempDir.reset();
    mongo::quickExit(result);
}
Example #5
0
// Define main function as an entry to these tests.
// These test functions cannot use the main() defined for unittests because they
// call runGlobalInitializers(). The embedded C API calls mongoDbMain() which
// calls runGlobalInitializers().
int main(int argc, char** argv, char** envp) {

    moe::OptionsParser parser;
    moe::Environment environment;
    moe::OptionSection options;
    std::map<std::string, std::string> env;

    auto ret = mongo::embedded::addMongocEmbeddedTestOptions(&options);
    if (!ret.isOK()) {
        std::cerr << ret << std::endl;
        return EXIT_FAILURE;
    }

    std::vector<std::string> argVector(argv, argv + argc);
    ret = parser.run(options, argVector, env, &environment);
    if (!ret.isOK()) {
        std::cerr << options.helpString();
        return EXIT_FAILURE;
    }
    if (environment.count("tempPath")) {
        ::mongo::unittest::TempDir::setTempPath(environment["tempPath"].as<std::string>());
    }

    ::mongo::clearSignalMask();
    ::mongo::setupSynchronousSignalHandlers();
    ::mongo::serverGlobalParams.noUnixSocket = true;

    // See comment by the same code block in mongo_embedded_test.cpp
    const char* null_argv[1] = {nullptr};
    ret = mongo::runGlobalInitializers(0, null_argv, nullptr);
    if (!ret.isOK()) {
        std::cerr << "Global initilization failed";
        return EXIT_FAILURE;
    }

    ret = mongo::runGlobalDeinitializers();
    if (!ret.isOK()) {
        std::cerr << "Global deinitilization failed";
        return EXIT_FAILURE;
    }

    StatusPtr status(mongo_embedded_v1_status_create());
    mongoc_init();

    mongo_embedded_v1_init_params params;
    params.log_flags = MONGO_EMBEDDED_V1_LOG_STDOUT;
    params.log_callback = nullptr;
    params.log_user_data = nullptr;

    global_lib_handle = mongo_embedded_v1_lib_init(&params, status.get());
    if (global_lib_handle == nullptr) {
        std::cerr << "Error: " << mongo_embedded_v1_status_get_explanation(status.get());
        return EXIT_FAILURE;
    }

    auto result = ::mongo::unittest::Suite::run(std::vector<std::string>(), "", 1);

    if (mongo_embedded_v1_lib_fini(global_lib_handle, status.get()) != MONGO_EMBEDDED_V1_SUCCESS) {
        std::cerr << "Error: " << mongo_embedded_v1_status_get_explanation(status.get());
        return EXIT_FAILURE;
    }

    mongoc_cleanup();
    globalTempDir.reset();
    mongo::quickExit(result);
}
Example #6
0
int main(int argc, char *argv[])
{
    try{
        if(argc != 4)
        {
            badArgNum.raise();
        }
    }
    catch(argError &badArgNum)
    {
        qFatal("Error: Need three filenames");
    }
    QString fileA = (QString) argv[1];
    QString fileB = (QString) argv[2];
    QString fileC = (QString) argv[3];

//Fill matrix A and B
    //prepare arguments
    matrix_args argsA;
    argsA.pMat = matrixA;
    argsA.fileName = fileA;

    matrix_args argsB;
    argsB.pMat = matrixB;
    argsB.fileName = fileB;

    pthread_t threadCreateA;
    pthread_t threadCreateB;
    try{
        if (pthread_create(&threadCreateA, NULL, createMatrix, (void*) &argsA))
        {
            badCreate.raise();
        }

        if (pthread_create(&threadCreateB, NULL, createMatrix, (void*) &argsB))
        {
             badCreate.raise();
        }
    }
    catch(threadCreationFail &badCreate)
    {
        qFatal("Could not create thread.");
    }

    pthread_join(threadCreateA, NULL);

    pthread_join(threadCreateB,NULL);
//Matrix A and B made


    //Start making the product
    pthread_t threadProductMake;

    try{
        if(pthread_create(&threadProductMake, NULL, prepareProduct, NULL))
        {
            badCreate.raise();
        }
    }
    catch(threadCreationFail &badCreate)
    {
        qFatal("Could not create product thread.");
    }

    pthread_join(threadProductMake, NULL);

    //find number of elements in the product matrix;
    int elementNum = matrixA->getRowNum()*matrixB->getColNum();


    QVector<pthread_t> threadProductCalc(elementNum);   //create a vector of threads w/ size of number of product elements
    QVector<calc_args> argVector(elementNum);           //create a vector of arguments w/ the size of the number of product elements

    int threadInd = 0;  //tracks which thread currently dealing with
    for(int i = 0; i < matrixC->getColNum(); i++)
    {
        for(int j = 0; j < matrixC->getRowNum(); j++)
        {
            argVector[threadInd].col = i;
            argVector[threadInd].row = j;
            pthread_create(&threadProductCalc[threadInd], NULL, calculateProductElement, &argVector[threadInd]);
            try{
                if(pthread_create(&threadProductCalc[threadInd], NULL, calculateProductElement, &argVector[threadInd]))
                {
                    badCreate.raise();
                }
            }
            catch(threadCreationFail &badCreate)
            {
                qFatal("Could not create calculation thread of element %d", threadInd);
            }
            threadInd++;
        }
    }


    for(threadInd = 0; threadInd < elementNum; threadInd++)
    {
        pthread_join(threadProductCalc[threadInd], NULL);
    }

    matrixC->copyToFile(fileC);


    return 0;
}