int TestBackgroundLogger() { int failed = 0, line; StringLogger slogger; string expectedValue; cout << "Testing BackgroundLogger... "; // Scoped, such that when the object is destructed we wait for the log // messages to be flushed to the StringLogger. { BackgroundLogger blog(slogger); LOG_WARN(blog) << "Background message here." << endl; line = __LINE__; // Stop the logger... blog.Stop(); // And send another message that doesn't get logged. LOG_WARN(blog) << "This message will not get logged." << endl; } getLogHeader(expectedValue, LL_WARN, __FILE__, line); expectedValue += "Background message here.\n"; if( expectedValue != slogger.getString() ) { cerr << "Mismatch detected at " << cpplog::helpers::fileNameFromPath(__FILE__) << "(" << line << ")" << endl; failed++; } cout << "done!" << endl; return failed; }
void * JitBuilder::buildProgram(Code &code, RuntimeEnvironment & runtime_environment) { X86Assembler assembler(&runtime_); #ifdef JIT_LOG StringLogger logger; assembler.setLogger(&logger); #endif BuildingContext buildingContext(code, assembler, runtime_environment); buildingContext.emitAll(); #ifdef JIT_LOG ofstream of("jit.log"); of<< logger.getString() << endl; of.close(); #endif return assembler.make(); }
void X86TestSuite::run() { size_t i; size_t testCount = testList.getLength(); for (i = 0; i < testCount; i++) { X86Compiler compiler; StringLogger logger; logger.setLogBinary(true); compiler.setLogger(&logger); X86Test* test = testList[i]; test->compile(compiler); void *func = compiler.make(); // In case that compilation fails uncomment this section to log immediately // after "compiler.make()". // // fprintf(stdout, "%s\n", logger.getString()); // fflush(stdout); if (func != NULL) { StringBuilder output; StringBuilder expected; if (test->run(func, output, expected)) { fprintf(stdout, "[Success] %s.\n", test->getName()); } else { fprintf(stdout, "[Failure] %s.\n", test->getName()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); fprintf(stdout, "%s", logger.getString()); fprintf(stdout, "\n"); fprintf(stdout, "Result : %s\n", output.getData()); fprintf(stdout, "Expected: %s\n", expected.getData()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); } MemoryManager::getGlobal()->free(func); } else { fprintf(stdout, "[Failure] %s.\n", test->getName()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); fprintf(stdout, "%s\n", logger.getString()); fprintf(stdout, "-------------------------------------------------------------------------------\n"); } fflush(stdout); } fputs("\n", stdout); fputs(testOutput.getData(), stdout); fflush(stdout); }
int TestDebugLogLevels() { int failed = 0; string expectedValue; StringLogger log; cout << "Testing debug-logging macros... "; #ifdef _DEBUG #define TEST_EXPECTED(str, level) \ if( level >= CPPLOG_FILTER_LEVEL ) \ { \ expectedValue.clear(); \ getLogHeader(expectedValue, level, __FILE__, __LINE__); \ expectedValue += str; \ expectedValue += "\n"; \ } else \ { \ expectedValue = ""; \ } \ if( expectedValue != log.getString() ) \ { \ cerr << "Mismatch detected at " << cpplog::helpers::fileNameFromPath(__FILE__) \ << "(" << __LINE__ << "): \"" << log.getString() << "\" != \"" \ << expectedValue << "\"" << endl; \ failed++; \ } \ log.clear() #else #define TEST_EXPECTED(str, level) \ expectedValue = ""; \ if( expectedValue != log.getString() ) \ { \ cerr << "Mismatch detected at " << cpplog::helpers::fileNameFromPath(__FILE__) \ << "(" << __LINE__ << "): \"" << log.getString() << "\" != \"" \ << expectedValue << "\"" << endl; \ failed++; \ } \ log.clear() #endif // Note: All these are on the same line so that the __LINE__ macro will match. DLOG_TRACE(log) << "Trace message"; TEST_EXPECTED("Trace message", LL_TRACE); DLOG_DEBUG(log) << "Debug message"; TEST_EXPECTED("Debug message", LL_DEBUG); DLOG_INFO(log) << "Info message"; TEST_EXPECTED("Info message", LL_INFO); DLOG_WARN(log) << "Warning message"; TEST_EXPECTED("Warning message", LL_WARN); DLOG_ERROR(log) << "Error message"; TEST_EXPECTED("Error message", LL_ERROR); DLOG(LL_DEBUG, log) << "Short specified debug message"; TEST_EXPECTED("Short specified debug message", LL_DEBUG); // Fatal messages are always logged. We have to handle this manually. DLOG_FATAL(log) << "Fatal message"; int line = __LINE__; expectedValue.clear(); getLogHeader(expectedValue, LL_FATAL, __FILE__, line); expectedValue += "Fatal message\n"; if( expectedValue != log.getString() ) { cerr << "Mismatch detected at " << cpplog::helpers::fileNameFromPath(__FILE__) << "(" << line << "): \"" << log.getString() << "\" != \"" << expectedValue << "\"" << endl; failed++; } log.clear(); #undef TEST_EXPECTED cout << "done!" << endl; return failed; }