1
0
Fork 0

TestSuite: Addition of the --log-level option for setting the logging priority.

This option mimics the fgfs option of the same name.  However for the test suite
option, additionally the SG_POPUP, SG_DEV_WARN and SG_DEV_ALERT priorities are
supported.

The default test suite output has been modified to only show the interleaved log
with the logging priority set to the command line supplied value or defaulting
to SG_INFO.
This commit is contained in:
Edward d'Auvergne 2019-07-30 13:19:23 +02:00
parent d448b8ceb4
commit 8b777a74c9
7 changed files with 89 additions and 30 deletions

View file

@ -65,12 +65,12 @@ void fgCompilerOutputter::printFailureDetail(CppUnit::TestFailure *failure)
test_io = *test_iter; test_io = *test_iter;
// SG_LOG IO streams. // SG_LOG IO streams.
fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_BULK priority", test_io.sg_bulk, true); fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, "+test_io.log_priority+" priority", test_io.sg_interleaved, true);
fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_BULK only priority", test_io.sg_bulk_only); //fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_BULK only priority", test_io.sg_bulk_only);
fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_DEBUG only priority", test_io.sg_debug_only); //fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_DEBUG only priority", test_io.sg_debug_only);
fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_INFO only priority", test_io.sg_info_only); //fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_INFO only priority", test_io.sg_info_only);
fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_WARN only priority", test_io.sg_warn_only); //fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_WARN only priority", test_io.sg_warn_only);
fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_ALERT only priority", test_io.sg_alert_only); //fgCompilerOutputter::printIOStreamMessages("SG_LOG, SG_ALL class, SG_ALERT only priority", test_io.sg_alert_only);
// Default IO streams. // Default IO streams.
fgCompilerOutputter::printIOStreamMessages("STDOUT and STDERR", test_io.stdio); fgCompilerOutputter::printIOStreamMessages("STDOUT and STDERR", test_io.stdio);
@ -96,7 +96,7 @@ void fgCompilerOutputter::printFailureReport()
} }
void fgCompilerOutputter::printIOStreamMessages(const char *heading, string messages, bool empty) void fgCompilerOutputter::printIOStreamMessages(string heading, string messages, bool empty)
{ {
// Silence. // Silence.
if (!empty && messages.size() == 0) if (!empty && messages.size() == 0)

View file

@ -81,8 +81,8 @@ class fgCompilerOutputter : public CppUnit::CompilerOutputter
bool debug; bool debug;
// Simgear logstream IO printout. // Simgear logstream IO printout.
void printIOStreamMessages(const char *heading, std::string messages, bool empty); void printIOStreamMessages(std::string heading, std::string messages, bool empty);
void printIOStreamMessages(const char *heading, std::string messages) {printIOStreamMessages(heading, messages, false);} void printIOStreamMessages(std::string heading, std::string messages) {printIOStreamMessages(heading, messages, false);}
}; };

View file

@ -88,7 +88,8 @@ void fgTestListener::endTest(CppUnit::Test *test)
// The simgear logstreams. // The simgear logstreams.
capturedIO &obj = getIOstreams(); capturedIO &obj = getIOstreams();
test_io.sg_bulk = obj.sg_bulk.str(); test_io.log_priority = obj.log_priority;
test_io.sg_interleaved = obj.sg_interleaved.str();
test_io.sg_bulk_only = obj.sg_bulk_only.str(); test_io.sg_bulk_only = obj.sg_bulk_only.str();
test_io.sg_debug_only = obj.sg_debug_only.str(); test_io.sg_debug_only = obj.sg_debug_only.str();
test_io.sg_info_only = obj.sg_info_only.str(); test_io.sg_info_only = obj.sg_info_only.str();
@ -100,7 +101,6 @@ void fgTestListener::endTest(CppUnit::Test *test)
} }
} }
// Override the base class function to capture IO streams. // Override the base class function to capture IO streams.
void fgTestListener::startTest(CppUnit::Test *test) void fgTestListener::startTest(CppUnit::Test *test)
{ {
@ -108,7 +108,7 @@ void fgTestListener::startTest(CppUnit::Test *test)
if (!debug) { if (!debug) {
// Clear the simgear logstream buffers. // Clear the simgear logstream buffers.
capturedIO &obj = getIOstreams(); capturedIO &obj = getIOstreams();
obj.sg_bulk.str(""); obj.sg_interleaved.str("");
obj.sg_bulk_only.str(""); obj.sg_bulk_only.str("");
obj.sg_debug_only.str(""); obj.sg_debug_only.str("");
obj.sg_info_only.str(""); obj.sg_info_only.str("");

View file

@ -31,8 +31,9 @@
// Data structure for holding the captured IO for a failed test. // Data structure for holding the captured IO for a failed test.
struct TestIOCapt { struct TestIOCapt {
std::string name; std::string name;
std::string log_priority;
std::string stdio; std::string stdio;
std::string sg_bulk; std::string sg_interleaved;
std::string sg_bulk_only; std::string sg_bulk_only;
std::string sg_debug_only; std::string sg_debug_only;
std::string sg_info_only; std::string sg_info_only;

View file

@ -28,21 +28,39 @@ static capturedIO *_iostreams = NULL;
// capturedIO constructor. // capturedIO constructor.
capturedIO::capturedIO() capturedIO::capturedIO(sgDebugPriority p)
{ {
callback_bulk = new StreamLogCallback(sg_bulk, SG_ALL, SG_BULK, false); callback_interleaved = new StreamLogCallback(sg_interleaved, SG_ALL, p, false);
callback_bulk_only = new StreamLogCallback(sg_bulk_only, SG_ALL, SG_BULK, true); callback_bulk_only = new StreamLogCallback(sg_bulk_only, SG_ALL, SG_BULK, true);
callback_debug_only = new StreamLogCallback(sg_debug_only, SG_ALL, SG_DEBUG, true); callback_debug_only = new StreamLogCallback(sg_debug_only, SG_ALL, SG_DEBUG, true);
callback_info_only = new StreamLogCallback(sg_info_only, SG_ALL, SG_INFO, true); callback_info_only = new StreamLogCallback(sg_info_only, SG_ALL, SG_INFO, true);
callback_warn_only = new StreamLogCallback(sg_warn_only, SG_ALL, SG_WARN, true); callback_warn_only = new StreamLogCallback(sg_warn_only, SG_ALL, SG_WARN, true);
callback_alert_only = new StreamLogCallback(sg_alert_only, SG_ALL, SG_ALERT, true); callback_alert_only = new StreamLogCallback(sg_alert_only, SG_ALL, SG_ALERT, true);
// Store the priority as a string.
if (p == SG_BULK)
log_priority = "SG_BULK";
else if (p == SG_DEBUG)
log_priority = "SG_DEBUG";
else if (p == SG_INFO)
log_priority = "SG_INFO";
else if (p == SG_WARN)
log_priority = "SG_WARN";
else if (p == SG_ALERT)
log_priority = "SG_ALERT";
else if (p == SG_POPUP)
log_priority = "SG_POPUP";
else if (p == SG_DEV_WARN)
log_priority = "SG_DEV_WARN";
else if (p == SG_DEV_ALERT)
log_priority = "SG_DEV_ALERT";
} }
// capturedIO destructor. // capturedIO destructor.
capturedIO::~capturedIO() capturedIO::~capturedIO()
{ {
// Destroy the callback objects. // Destroy the callback objects.
delete callback_bulk; delete callback_interleaved;
delete callback_bulk_only; delete callback_bulk_only;
delete callback_debug_only; delete callback_debug_only;
delete callback_info_only; delete callback_info_only;
@ -52,11 +70,11 @@ capturedIO::~capturedIO()
// Return the global stream capture data structure, creating it if needed. // Return the global stream capture data structure, creating it if needed.
capturedIO & getIOstreams() capturedIO & getIOstreams(sgDebugPriority p)
{ {
// Initialise the global stream capture data structure, if needed. // Initialise the global stream capture data structure, if needed.
if (!_iostreams) if (!_iostreams)
_iostreams = new capturedIO(); _iostreams = new capturedIO(p);
// Return a pointer to the global object. // Return a pointer to the global object.
return *_iostreams; return *_iostreams;
@ -64,7 +82,7 @@ capturedIO & getIOstreams()
// Set up to capture all the simgear logging priorities as separate streams. // Set up to capture all the simgear logging priorities as separate streams.
void setupLogging() void setupLogging(sgDebugPriority p)
{ {
// Get the single logstream instance. // Get the single logstream instance.
logstream &log = sglog(); logstream &log = sglog();
@ -76,8 +94,8 @@ void setupLogging()
osg::setNotifyHandler(new NotifyLogger); osg::setNotifyHandler(new NotifyLogger);
// IO capture. // IO capture.
capturedIO &obj = getIOstreams(); capturedIO &obj = getIOstreams(p);
log.addCallback(obj.callback_bulk); log.addCallback(obj.callback_interleaved);
log.addCallback(obj.callback_bulk_only); log.addCallback(obj.callback_bulk_only);
log.addCallback(obj.callback_debug_only); log.addCallback(obj.callback_debug_only);
log.addCallback(obj.callback_info_only); log.addCallback(obj.callback_info_only);
@ -94,7 +112,7 @@ void stopLogging()
// IO decapture. // IO decapture.
capturedIO &obj = getIOstreams(); capturedIO &obj = getIOstreams();
log.removeCallback(obj.callback_bulk); log.removeCallback(obj.callback_interleaved);
log.removeCallback(obj.callback_bulk_only); log.removeCallback(obj.callback_bulk_only);
log.removeCallback(obj.callback_debug_only); log.removeCallback(obj.callback_debug_only);
log.removeCallback(obj.callback_info_only); log.removeCallback(obj.callback_info_only);

View file

@ -62,11 +62,11 @@ class capturedIO
{ {
public: public:
// Constructor and destructor. // Constructor and destructor.
capturedIO(); capturedIO(sgDebugPriority);
~capturedIO(); ~capturedIO();
// The IO streams. // The IO streams.
std::ostringstream sg_bulk; std::ostringstream sg_interleaved;
std::ostringstream sg_bulk_only; std::ostringstream sg_bulk_only;
std::ostringstream sg_debug_only; std::ostringstream sg_debug_only;
std::ostringstream sg_info_only; std::ostringstream sg_info_only;
@ -74,20 +74,23 @@ class capturedIO
std::ostringstream sg_alert_only; std::ostringstream sg_alert_only;
// The callback objects. // The callback objects.
StreamLogCallback *callback_bulk; StreamLogCallback *callback_interleaved;
StreamLogCallback *callback_bulk_only; StreamLogCallback *callback_bulk_only;
StreamLogCallback *callback_debug_only; StreamLogCallback *callback_debug_only;
StreamLogCallback *callback_info_only; StreamLogCallback *callback_info_only;
StreamLogCallback *callback_warn_only; StreamLogCallback *callback_warn_only;
StreamLogCallback *callback_alert_only; StreamLogCallback *callback_alert_only;
// The logging priority text.
std::string log_priority;
}; };
// Return the global stream capture data structure, creating it if needed. // Return the global stream capture data structure, creating it if needed.
capturedIO & getIOstreams(); capturedIO & getIOstreams(sgDebugPriority p=SG_BULK);
// Set up to capture all the simgear logging priorities as separate streams. // Set up to capture all the simgear logging priorities as separate streams.
void setupLogging(); void setupLogging(sgDebugPriority);
// Deactivate all the simgear logging priority IO captures. // Deactivate all the simgear logging priority IO captures.
void stopLogging(); void stopLogging();

View file

@ -93,7 +93,11 @@ int main(int argc, char **argv)
bool verbose=false, ctest_output=false, debug=false, printSummary=true, help=false; bool verbose=false, ctest_output=false, debug=false, printSummary=true, help=false;
char *subset_system=NULL, *subset_unit=NULL, *subset_gui=NULL, *subset_simgear=NULL, *subset_fgdata=NULL; char *subset_system=NULL, *subset_unit=NULL, *subset_gui=NULL, *subset_simgear=NULL, *subset_fgdata=NULL;
char firstchar; char firstchar;
std::string arg, fgRoot; std::string arg, fgRoot, logLevel;
size_t delimPos;
// The default logging priority to show.
sgDebugPriority logPriority=SG_INFO;
// Argument parsing. // Argument parsing.
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
@ -133,6 +137,35 @@ int main(int argc, char **argv)
if (firstchar != '-') if (firstchar != '-')
subset_fgdata = argv[i+1]; subset_fgdata = argv[i+1];
// Log level.
} else if (arg.find( "--log-level" ) == 0) {
// Process the command line level.
delimPos = arg.find('=');
logLevel = arg.substr(delimPos + 1);
// Convert.
if (logLevel == "bulk")
logPriority = SG_BULK;
else if (logLevel == "debug")
logPriority = SG_DEBUG;
else if (logLevel == "info")
logPriority = SG_INFO;
else if (logLevel == "warn")
logPriority = SG_WARN;
else if (logLevel == "alert")
logPriority = SG_ALERT;
else if (logLevel == "popup")
logPriority = SG_POPUP;
else if (logLevel == "dev_warn")
logPriority = SG_DEV_WARN;
else if (logLevel == "dev_alert")
logPriority = SG_DEV_ALERT;
else {
std::cout << "The log level setting of \"" << logLevel << "\" must be one of {bulk,debug,info,warn,alert,popup,dev_warn,dev_alert}.\n\n";
std::cout.flush();
return 1;
}
// Verbose output. // Verbose output.
} else if (arg == "-v" || arg == "--verbose") { } else if (arg == "-v" || arg == "--verbose") {
verbose = true; verbose = true;
@ -181,6 +214,10 @@ int main(int argc, char **argv)
std::cout << " the individual test name. The test names can revealed with the verbose" << std::endl; std::cout << " the individual test name. The test names can revealed with the verbose" << std::endl;
std::cout << " option." << std::endl; std::cout << " option." << std::endl;
std::cout << std::endl; std::cout << std::endl;
std::cout << " Logging options:" << std::endl;
std::cout << " --log-level={bulk,debug,info,warn,alert,popup,dev_warn,dev_alert}" << std::endl;
std::cout << " specify the minimum logging level to output" << std::endl;
std::cout << std::endl;
std::cout << " Verbosity options:" << std::endl; std::cout << " Verbosity options:" << std::endl;
std::cout << " -v, --verbose verbose output including names and timings for all" << std::endl; std::cout << " -v, --verbose verbose output including names and timings for all" << std::endl;
std::cout << " tests." << std::endl; std::cout << " tests." << std::endl;
@ -212,9 +249,9 @@ int main(int argc, char **argv)
// Set up logging. // Set up logging.
sglog().setDeveloperMode(true); sglog().setDeveloperMode(true);
if (debug) if (debug)
sglog().setLogLevels(SG_ALL, SG_BULK); sglog().setLogLevels(SG_ALL, logPriority);
else else
setupLogging(); setupLogging(logPriority);
// Execute each of the test suite categories. // Execute each of the test suite categories.
if (run_system) if (run_system)