< prev index next >

test/native/logging/test_logConfiguration.cpp

Print this page
rev 12483 : 8172098: A lot of gtests uses TEST instead of TEST_VM
Reviewed-by: duke


 280   // Verify that it's possible to configure each individual tag
 281   for (size_t t = 1 /* Skip _NO_TAG */; t < LogTag::Count; t++) {
 282     const LogTagType tag = static_cast<LogTagType>(t);
 283     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stdout", LogTag::name(tag), "", "", &ss));
 284   }
 285   // Same for each level
 286   for (size_t l = 0; l < LogLevel::Count; l++) {
 287     const LogLevelType level = static_cast<LogLevelType>(l);
 288     char expected_buf[256];
 289     int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "all=%s", LogLevel::name(level));
 290     ASSERT_NE(-1, ret);
 291     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stderr", expected_buf, "", "", &ss));
 292   }
 293   // And for each decorator
 294   for (size_t d = 0; d < LogDecorators::Count; d++) {
 295     const LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
 296     EXPECT_TRUE(LogConfiguration::parse_log_arguments("#0", "", LogDecorators::name(decorator), "", &ss));
 297   }
 298 }
 299 
 300 TEST_F(LogConfigurationTest, configure_stdout) {
 301   // Start out with all logging disabled
 302   LogConfiguration::disable_logging();
 303 
 304   // Enable 'logging=info', verifying it has been set
 305   LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
 306   EXPECT_TRUE(log_is_enabled(Info, logging));
 307   EXPECT_FALSE(log_is_enabled(Debug, logging));
 308   EXPECT_FALSE(log_is_enabled(Info, gc));
 309   LogTagSet* logging_ts = &LogTagSetMapping<LOG_TAGS(logging)>::tagset();
 310   EXPECT_EQ(LogLevel::Info, logging_ts->level_for(&StdoutLog));
 311 
 312   // Enable 'gc=debug' (no wildcard), verifying no other tags are enabled
 313   LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
 314   EXPECT_TRUE(log_is_enabled(Debug, gc));
 315   EXPECT_TRUE(log_is_enabled(Info, logging));
 316   EXPECT_FALSE(log_is_enabled(Debug, gc, heap));
 317   for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
 318     if (ts->contains(PREFIX_LOG_TAG(gc))) {
 319       if (ts->ntags() == 1) {
 320         EXPECT_EQ(LogLevel::Debug, ts->level_for(&StdoutLog));


 338       EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
 339     }
 340   }
 341 
 342   // Disable 'gc*' and 'logging', verifying all logging is properly disabled
 343   LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging));
 344   EXPECT_FALSE(log_is_enabled(Error, logging));
 345   LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc));
 346   EXPECT_FALSE(log_is_enabled(Error, gc));
 347   EXPECT_FALSE(log_is_enabled(Error, gc, heap));
 348   for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
 349     EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
 350   }
 351 }
 352 
 353 static int Test_logconfiguration_subscribe_triggered = 0;
 354 static void Test_logconfiguration_subscribe_helper() {
 355   Test_logconfiguration_subscribe_triggered++;
 356 }
 357 
 358 TEST_F(LogConfigurationTest, subscribe) {
 359   ResourceMark rm;
 360   Log(logging) log;
 361   set_log_config("stdout", "logging*=trace");
 362 
 363   LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper);
 364 
 365   LogConfiguration::parse_log_arguments("stdout", "logging=trace", NULL, NULL, log.error_stream());
 366   ASSERT_EQ(1, Test_logconfiguration_subscribe_triggered);
 367 
 368   LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
 369   ASSERT_EQ(2, Test_logconfiguration_subscribe_triggered);
 370 
 371   LogConfiguration::disable_logging();
 372   ASSERT_EQ(3, Test_logconfiguration_subscribe_triggered);
 373 }
 374 
 375 TEST_VM_F(LogConfigurationTest, parse_invalid_tagset) {
 376   static const char* invalid_tagset = "logging+start+exit+safepoint+gc"; // Must not exist for test to function.
 377 
 378   // Make sure warning is produced if one or more configured tagsets are invalid




 280   // Verify that it's possible to configure each individual tag
 281   for (size_t t = 1 /* Skip _NO_TAG */; t < LogTag::Count; t++) {
 282     const LogTagType tag = static_cast<LogTagType>(t);
 283     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stdout", LogTag::name(tag), "", "", &ss));
 284   }
 285   // Same for each level
 286   for (size_t l = 0; l < LogLevel::Count; l++) {
 287     const LogLevelType level = static_cast<LogLevelType>(l);
 288     char expected_buf[256];
 289     int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "all=%s", LogLevel::name(level));
 290     ASSERT_NE(-1, ret);
 291     EXPECT_TRUE(LogConfiguration::parse_log_arguments("stderr", expected_buf, "", "", &ss));
 292   }
 293   // And for each decorator
 294   for (size_t d = 0; d < LogDecorators::Count; d++) {
 295     const LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
 296     EXPECT_TRUE(LogConfiguration::parse_log_arguments("#0", "", LogDecorators::name(decorator), "", &ss));
 297   }
 298 }
 299 
 300 TEST_VM_F(LogConfigurationTest, configure_stdout) {
 301   // Start out with all logging disabled
 302   LogConfiguration::disable_logging();
 303 
 304   // Enable 'logging=info', verifying it has been set
 305   LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
 306   EXPECT_TRUE(log_is_enabled(Info, logging));
 307   EXPECT_FALSE(log_is_enabled(Debug, logging));
 308   EXPECT_FALSE(log_is_enabled(Info, gc));
 309   LogTagSet* logging_ts = &LogTagSetMapping<LOG_TAGS(logging)>::tagset();
 310   EXPECT_EQ(LogLevel::Info, logging_ts->level_for(&StdoutLog));
 311 
 312   // Enable 'gc=debug' (no wildcard), verifying no other tags are enabled
 313   LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
 314   EXPECT_TRUE(log_is_enabled(Debug, gc));
 315   EXPECT_TRUE(log_is_enabled(Info, logging));
 316   EXPECT_FALSE(log_is_enabled(Debug, gc, heap));
 317   for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
 318     if (ts->contains(PREFIX_LOG_TAG(gc))) {
 319       if (ts->ntags() == 1) {
 320         EXPECT_EQ(LogLevel::Debug, ts->level_for(&StdoutLog));


 338       EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
 339     }
 340   }
 341 
 342   // Disable 'gc*' and 'logging', verifying all logging is properly disabled
 343   LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging));
 344   EXPECT_FALSE(log_is_enabled(Error, logging));
 345   LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc));
 346   EXPECT_FALSE(log_is_enabled(Error, gc));
 347   EXPECT_FALSE(log_is_enabled(Error, gc, heap));
 348   for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
 349     EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
 350   }
 351 }
 352 
 353 static int Test_logconfiguration_subscribe_triggered = 0;
 354 static void Test_logconfiguration_subscribe_helper() {
 355   Test_logconfiguration_subscribe_triggered++;
 356 }
 357 
 358 TEST_VM_F(LogConfigurationTest, subscribe) {
 359   ResourceMark rm;
 360   Log(logging) log;
 361   set_log_config("stdout", "logging*=trace");
 362 
 363   LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper);
 364 
 365   LogConfiguration::parse_log_arguments("stdout", "logging=trace", NULL, NULL, log.error_stream());
 366   ASSERT_EQ(1, Test_logconfiguration_subscribe_triggered);
 367 
 368   LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
 369   ASSERT_EQ(2, Test_logconfiguration_subscribe_triggered);
 370 
 371   LogConfiguration::disable_logging();
 372   ASSERT_EQ(3, Test_logconfiguration_subscribe_triggered);
 373 }
 374 
 375 TEST_VM_F(LogConfigurationTest, parse_invalid_tagset) {
 376   static const char* invalid_tagset = "logging+start+exit+safepoint+gc"; // Must not exist for test to function.
 377 
 378   // Make sure warning is produced if one or more configured tagsets are invalid


< prev index next >