Пример #1
0
int HarnessTestExecutor :: createLogger (void)
{
	assert (_ie.log_file.length () > 0);
	bfs::remove (_ie.log_file);	

	log4cxx :: LayoutPtr layout (new log4cxx :: PatternLayout ("%d %p %x - %m%n"));
	log4cxx :: FileAppenderPtr appender (new log4cxx :: FileAppender (layout, _ie.log_file, true));
	_logger = log4cxx :: Logger :: getLogger (_ie.logger_name);
	_logger->addAppender (appender);

    _executorTag = LOGGER_TAG_HARNESSEXECUTOR;
    _executorTag += '[' + _ie.logger_name + ']';
    LOGGER_PUSH_NDCTAG (_executorTag);

	_loggerEnabled = true;
	LOG4CXX_INFO (_logger, "logger SYSTEM ENABLED");

	switch (_ie.debugLevel)
	{
		case DEBUGLEVEL_FATAL : _logger->setLevel (log4cxx :: Level :: getFatal ()); break;
		case DEBUGLEVEL_ERROR : _logger->setLevel (log4cxx :: Level :: getError ()); break;
		case DEBUGLEVEL_WARN  : _logger->setLevel (log4cxx :: Level :: getWarn ()); break;
		case DEBUGLEVEL_INFO  : _logger->setLevel (log4cxx :: Level :: getInfo ()); break;
		case DEBUGLEVEL_DEBUG : _logger->setLevel (log4cxx :: Level :: getDebug ()); break;
		case DEBUGLEVEL_TRACE : _logger->setLevel (log4cxx :: Level :: getTrace ()); break;
		default               : return FAILURE;
	}

	return SUCCESS;
}
/* ________________________________________________________________ */
int REPORTER :: writeFinalInfo (const struct ExecutionStats &harness_execution_stats)
{
    LogString saved_context;
	LOGGER_PUSH_NDCTAG (LOGGER_TAG_REPORTER);

	LOG4CXX_INFO (_logger, "Writing Final Info to report file.");
	_xa->seekp (_prevStoredPosition);
	_xa->putEndTagNOIndent ("TestResults");
	_xa->putStartTag ("FinalStats");
    _xa->save (harness_execution_stats);
	_xa->putEndTag ("FinalStats");
	_xa->putEndTagNOIndent ("SciDBTestReport");
	//_xa->putEndTagNOIndent ("boost_serialization"); /* not required because it's internally put when _xa is deleted */
	_xa->flush ();

	LOGGER_POP_NDCTAG;
	return SUCCESS;
}
int REPORTER :: writeInitialInfo (const struct HarnessCommandLineOptions &SciDBHarnessEnv)
{
    LogString saved_context;
	LOGGER_PUSH_NDCTAG (LOGGER_TAG_REPORTER);

	LOG4CXX_INFO (_logger, "Writing Initial Info to report file.");
	_xa->putStartTag ("SciDBHarnessEnv");
	_xa->save (SciDBHarnessEnv);
	_xa->putEndTag ("SciDBHarnessEnv");

	_xa->putStartTagNOIndent ("TestResults");
	_xa->flush ();
	if ((_prevStoredPosition = _xa->tellp ()) == FAILURE)
	{
		LOGGER_POP_NDCTAG;
		return FAILURE;
	}

	LOGGER_POP_NDCTAG;
	return SUCCESS;
}
/* runs all subsuites including suiteid */
int Suite :: run (const string root_dir, string skiptestfname, const vector<string> &skip_tclist, const string regex_expr, RegexType regex_flag,
                  MANAGER &M, int no_parallel_testcases, int *testcases_total, int *testcases_skipped, REPORTER *rptr, int *suitesSkipped)
{
	int rv=SUCCESS;
	LogString saved_context;
	LOGGER_PUSH_NDCTAG (LOGGER_TAG_SUITE);

	try
	{
		LOG4CXX_INFO (_logger, "Running a suite [" << _suiteId << "] with [" << _subSuites.size () << "] subsuite(s) ... (including itself)");
		print_vector (_subSuites);

		/* if --skip-tests=<some_file_name> then collectSkippedTestCases() only once */
		if (skip_tclist.size() > 0 && strcasecmp(skiptestfname.c_str(), DEFAULT_SKIP_TEST_OPTION) != 0)
		{
# if 0
			bfs::path p (skiptestfname);

			string under_dir = DEFAULT_TEST_CASE_DIR;
			under_dir = under_dir + p.parent_path ().string ();
			skiptestfname = p.filename();
			_skiptcList.clear ();

			/* collect skipped testcases */
			if (collectSkippedTestCases (root_dir, under_dir, skiptestfname, _skiptcList) <= -1)
			{
				LOGGER_POP_NDCTAG;
				return FAILURE;
			}
# endif

			for (unsigned int i=0; i<skip_tclist.size(); i++)
			{
				_skiptcList.push_back (skip_tclist[i]);
			}

			int filteredoutsuites = filterSkippedTestSuites (_subSuites, _skiptcList);
			if (filteredoutsuites > 0)
			{
				if (_subSuites.size() == 0)
				{
					LOG4CXX_INFO (_logger, "After filtering there remains no suite to run...");
				}
				else
				{
					LOG4CXX_INFO (_logger, "After filtering, Running a suite [" << _suiteId << "] with [" << _subSuites.size ()
                                                                                                          << "] subsuite(s) ... (including itself)");
					print_vector (_subSuites);
				}
			}
			*suitesSkipped += filteredoutsuites;
		}

		sort (_subSuites.begin (), _subSuites.end ());
		for (unsigned int i=0; i<_subSuites.size (); i++)
		{
			int thissuite_total_tc=0, thissuite_runable_tc=0, thissuite_skipped_tc=0;

			_tcList.clear ();

			/* collect all the testcases for this subsuite */
			if (collectTestCases (root_dir, _subSuites[i], regex_expr, regex_flag, _tcList) == -1)
			{
				LOGGER_POP_NDCTAG;
				return FAILURE;
			}

			thissuite_total_tc = _tcList.size ();
			*testcases_total += thissuite_total_tc;

			/* if it is "yes" */
			if (strcasecmp (skiptestfname.c_str(), DEFAULT_SKIP_TEST_OPTION) == 0)
			{
				/* then use disable.tests as a file name */
				skiptestfname = DEFAULT_SKIP_TEST_FILE_NAME;

				_skiptcList.clear ();
				/* collect skipped testcases, ignore "file does not exist" error i.e. -2 */
				if (collectSkippedTestCases (root_dir, _subSuites[i], skiptestfname, _skiptcList) == -1)
				{
					LOGGER_POP_NDCTAG;
					return FAILURE;
				}
				skiptestfname = DEFAULT_SKIP_TEST_OPTION;
			}

			/* filter out skipped testcases */
			thissuite_skipped_tc = filterSkippedTestCases (_tcList, _skiptcList);
			*testcases_skipped += thissuite_skipped_tc;

			thissuite_runable_tc = _tcList.size ();
			LOG4CXX_INFO (_logger, "Running a suite [" << _subSuites[i] << "] : with total[" << thissuite_total_tc << "], runable[" << thissuite_runable_tc << "], skipped[" << thissuite_skipped_tc << "] test case(s)...");

			if (thissuite_runable_tc > 0)
			{
				M.createWorkgroup (no_parallel_testcases);
				sort (_tcList.begin (), _tcList.end ());
				if ((rv = M.runJob (_tcList, rptr)) == FAILURE)
					break;
			}
		}
	}

	catch (harnessexceptions :: ERROR &e)
	{
		LOGGER_POP_NDCTAG;
		throw;
	}
	LOGGER_POP_NDCTAG;
	return rv;
}
/* recursively collects only the names of the subdirectories (i.e. sub suites)
 * and also .suite file names mentioned on the commandline
 * and any directories (i.e. suite names) and .suite file names mentioned in this file
 * and puts it into the vector '_subSuites'
 */
int Suite :: collectSubSuites (string parentdir, string sid)
{
	LogString saved_context;
	LOGGER_PUSH_NDCTAG (LOGGER_TAG_SUITE);

	string converted_sid = converttopath (sid);
	string suite_dir_fullpath = parentdir + "/" + converted_sid;
	string suite_file_fullpath = parentdir + "/" + converted_sid + ".suite";

	/* check directory after 'sid' conversion */
	if (!bfs::exists (suite_dir_fullpath) || !bfs::is_directory (suite_dir_fullpath))
	{
		/* check .suite file after 'sid' conversion */
		if (!bfs::exists (suite_file_fullpath) || !bfs::is_regular (suite_file_fullpath))
		{
			LOG4CXX_WARN (_logger, "suiteid [" << sid << "] is a not a valid directory ID or .suite file path before/after conversion. A '.' is not allowed in a file/directory name under basic test case directory t/");
			LOGGER_POP_NDCTAG;
			return FAILURE;
		}
		else
			LOG4CXX_DEBUG (_logger, "suiteid [" << sid << "] is a valid .suite file path after conversion.");
	}
	else
		LOG4CXX_DEBUG (_logger, "suiteid [" << sid << "] is a valid directory path after conversion.");

	/* check if it is a directory */
	if (bfs::exists (suite_dir_fullpath) && bfs::is_directory (suite_dir_fullpath))
	{
		/* if there exists a directory t/abc/ and also the file t/abc.suite
         * and we specify --suite-id=abc then that will be ambiguous
         */
		if (bfs::exists (suite_file_fullpath) && bfs::is_regular (suite_file_fullpath))
		{
			LOGGER_POP_NDCTAG;
			throw ConfigError (FILE_LINE_FUNCTION, ERR_CONFIG_AMBIGUOUS_SUITEID);
		}

		_subSuites.push_back (suite_dir_fullpath);

		bfs::directory_iterator end_iter;
		for (bfs::directory_iterator dir_iter(suite_dir_fullpath); dir_iter != end_iter; dir_iter++)
		{
			bfs::path p (dir_iter->path ());

			/* ignore hidden files and directories (e.g. ".svn") */
			if (p.stem () == "")
				continue;

			/* if it is a non-empty directory then traverse recursively */
			if (bfs :: is_directory (p))
			{
				if (!bfs :: is_empty (p))
#if (BOOST_FS_VER==2)
					collectSubSuites ("", p.directory_string ());
#else
					collectSubSuites ("", p.string ());
#endif
			}
		}
	}
	/* check if it is a .suite file */
	else
	{
		if (!bfs::exists (suite_file_fullpath) || !bfs::is_regular (suite_file_fullpath))
		{
			LOGGER_POP_NDCTAG;
			stringstream ss;
			ss << "Suite [" << suite_dir_fullpath << "] does not exist and also Suite [" << suite_file_fullpath << "] either does not exist or is not a regular file";
			throw SystemError (FILE_LINE_FUNCTION, ss.str());
		}

		ifstream f(suite_file_fullpath.c_str());
		if (!f.is_open ())
		{
			LOGGER_POP_NDCTAG;
			stringstream ss;
			ss << "Could not open suite file [" << suite_file_fullpath << "]";
			throw SystemError (FILE_LINE_FUNCTION, ss.str());
		}

		_subSuites.push_back (suite_file_fullpath);

		string line;
		/* read the file */
		while (!f.eof ())
		{
			getline (f, line);

			/* if blank line */
			if (line.empty())
				continue;

			{
				bfs::path p (suite_file_fullpath);
				string parent_dir = p.parent_path().string();
				string pathstring = converttopath (line);
				string linefullpath = parent_dir + "/" + pathstring;
				string suitefile = linefullpath + ".suite";
				string testfile = linefullpath + ".test";

				/* if it is a directory then it must be a subsuite-id */
				if (bfs::is_directory (linefullpath))
				{
					/* if there is a line "abc" in the .suite file and
                     * there exists a directory abc/ as well as file abc.suite
                     * then it will be ambiguous
                     */
					if (bfs::exists (suitefile) && bfs::is_regular (suitefile))
					{
						LOGGER_POP_NDCTAG;
						stringstream ss;
						ss << "Ambiguous mention of suite id [" << line << "] in the file " << suite_file_fullpath;
						throw SystemError (FILE_LINE_FUNCTION, ss.str());
					}
					/* if there is a line "abc" in the .suite file and
                     * there exists a directory "abc" as well as file abc.test
                     * then it will be ambiguous
                     */
					else if (bfs::exists (testfile) && bfs::is_regular (testfile))
					{
						LOGGER_POP_NDCTAG;
						stringstream ss;
						ss << "Ambiguous mention of test/suite id [" << line << "] in the file " << suite_file_fullpath;
						throw SystemError (FILE_LINE_FUNCTION, ss.str());
					}

					if (!bfs::is_empty (linefullpath))
						collectSubSuites ("", linefullpath);
				}
				else
				{
					/* if it is a regular file with ".suite" extension */
					if (bfs::exists (suitefile) && bfs :: is_regular (suitefile))
					{
						/* if there is a line "abc" in the .suite file and
						 * there exists a file abc.suite as well as file abc.test
						 * then it will be ambiguous
						 */
						if (bfs::exists (testfile) && bfs::is_regular (testfile))
						{
							LOGGER_POP_NDCTAG;
							stringstream ss;
							ss << "Ambiguous mention of test/suite id [" << line << "] in the file " << suite_file_fullpath;
							throw SystemError (FILE_LINE_FUNCTION, ss.str());
						}

						collectSubSuites ("", linefullpath); /* .suite extension is being attached at the beginning of this function */
					}

					/* if it is a regular file with ".test" extension
					 * then ignore it as it will be collected in collectTestCases()
					 */
				}
			}
		} //END while(!eof)
	} //END else .suite file
	
	LOGGER_POP_NDCTAG;
	return _subSuites.size ();
}