hotspot/src/share/vm/logging/log.cpp
changeset 41679 6008faaa396d
parent 41678 d51adf949bcd
equal deleted inserted replaced
41678:d51adf949bcd 41679:6008faaa396d
   268 void Test_logtarget() {
   268 void Test_logtarget() {
   269   Test_logtarget_on();
   269   Test_logtarget_on();
   270   Test_logtarget_off();
   270   Test_logtarget_off();
   271 }
   271 }
   272 
   272 
   273 
       
   274 static void Test_logstream_helper(outputStream* stream) {
       
   275   TestLogFile log_file("log_stream");
       
   276   TestLogSavedConfig tlsc(log_file.name(), "gc=debug");
       
   277 
       
   278   // Try to log, but expect this to be filtered out.
       
   279   stream->print("%d ", 3); stream->print("workers"); stream->cr();
       
   280 
       
   281   FILE* fp = fopen(log_file.name(), "r");
       
   282   assert(fp != NULL, "File read error");
       
   283 
       
   284   char output[256 /* Large enough buffer */];
       
   285   char* res = fgets(output, sizeof(output), fp);
       
   286   assert(res != NULL, "assert");
       
   287 
       
   288   assert(strstr(output, "3 workers") != NULL, "log line missing");
       
   289 
       
   290   fclose(fp);
       
   291 }
       
   292 
       
   293 static void Test_logstream_log() {
       
   294   Log(gc) log;
       
   295   LogStream stream(log.debug());
       
   296 
       
   297   Test_logstream_helper(&stream);
       
   298 }
       
   299 
       
   300 static void Test_logstream_logtarget() {
       
   301   LogTarget(Debug, gc) log;
       
   302   LogStream stream(log);
       
   303 
       
   304   Test_logstream_helper(&stream);
       
   305 }
       
   306 
       
   307 static void Test_logstream_logstreamhandle() {
       
   308   LogStreamHandle(Debug, gc) stream;
       
   309 
       
   310   Test_logstream_helper(&stream);
       
   311 }
       
   312 
       
   313 static void Test_logstream_no_rm() {
       
   314   ResourceMark rm;
       
   315   outputStream* stream = LogTarget(Debug, gc)::stream();
       
   316 
       
   317   Test_logstream_helper(stream);
       
   318 }
       
   319 
       
   320 static void Test_logstreamcheap_log() {
       
   321   Log(gc) log;
       
   322   LogStreamCHeap stream(log.debug());
       
   323 
       
   324   Test_logstream_helper(&stream);
       
   325 }
       
   326 
       
   327 static void Test_logstreamcheap_logtarget() {
       
   328   LogTarget(Debug, gc) log;
       
   329   LogStreamCHeap stream(log);
       
   330 
       
   331   Test_logstream_helper(&stream);
       
   332 }
       
   333 
       
   334 void Test_logstream() {
       
   335   // Test LogStreams with embedded ResourceMark.
       
   336   Test_logstream_log();
       
   337   Test_logstream_logtarget();
       
   338   Test_logstream_logstreamhandle();
       
   339 
       
   340   // Test LogStreams without embedded ResourceMark.
       
   341   Test_logstream_no_rm();
       
   342 
       
   343   // Test LogStreams backed by CHeap memory.
       
   344   Test_logstreamcheap_log();
       
   345   Test_logstreamcheap_logtarget();
       
   346 }
       
   347 
       
   348 void Test_loghandle_on() {
   273 void Test_loghandle_on() {
   349   TestLogFile log_file("log_handle");
   274   TestLogFile log_file("log_handle");
   350   TestLogSavedConfig tlsc(log_file.name(), "gc=debug");
   275   TestLogSavedConfig tlsc(log_file.name(), "gc=debug");
   351 
   276 
   352   Log(gc) log;
   277   Log(gc) log;