18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 /////////////// Unit tests ///////////////
28
29 #ifndef PRODUCT
30
31 #include "gc/shared/gcTraceTime.inline.hpp"
32 #include "logging/log.hpp"
33 #include "logging/logConfiguration.hpp"
34 #include "logging/logFileOutput.hpp"
35 #include "logging/logOutput.hpp"
36 #include "logging/logTagLevelExpression.hpp"
37 #include "logging/logTagSet.hpp"
38 #include "logging/logStream.inline.hpp"
39 #include "memory/resourceArea.hpp"
40
41 #define assert_str_eq(s1, s2) \
42 assert(strcmp(s1, s2) == 0, "Expected '%s' to equal '%s'", s1, s2)
43
44 #define assert_char_in(c, s) \
45 assert(strchr(s, c) != NULL, "Expected '%s' to contain character '%c'", s, c)
46
47 #define assert_char_not_in(c, s) \
48 assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c)
49
50 void Test_log_tag_combinations_limit() {
51 assert(LogTagLevelExpression::MaxCombinations > LogTagSet::ntagsets(),
52 "Combination limit (" SIZE_FORMAT ") not sufficient "
53 "for configuring all available tag sets (" SIZE_FORMAT ")",
54 LogTagLevelExpression::MaxCombinations, LogTagSet::ntagsets());
55 }
56
57 class TestLogFile {
866 Test_log_gctracetime_no_cause();
867 Test_log_gctracetime_no_heap_no_cause();
868 }
869
870 void Test_invalid_log_file() {
871 ResourceMark rm;
872 stringStream ss;
873 const char* target_name = "tmplogdir";
874
875 // Attempt to log to a directory (existing log not a regular file)
876 create_directory(target_name);
877 LogFileOutput bad_file("tmplogdir");
878 assert(bad_file.initialize("", &ss) == false, "file was initialized "
879 "when there was an existing directory with the same name");
880 assert(strstr(ss.as_string(), "tmplogdir is not a regular file") != NULL,
881 "missing expected error message, received msg: %s", ss.as_string());
882 ss.reset();
883 remove(target_name);
884 }
885
886 #endif // PRODUCT
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 /////////////// Unit tests ///////////////
28
29 #ifndef PRODUCT
30
31 #include "gc/shared/gcTraceTime.inline.hpp"
32 #include "logging/log.hpp"
33 #include "logging/logConfiguration.hpp"
34 #include "logging/logFileOutput.hpp"
35 #include "logging/logOutput.hpp"
36 #include "logging/logTagLevelExpression.hpp"
37 #include "logging/logTagSet.hpp"
38 #include "logging/logTagSetDescriptions.inline.hpp"
39 #include "logging/logStream.inline.hpp"
40 #include "memory/resourceArea.hpp"
41
42 #define assert_str_eq(s1, s2) \
43 assert(strcmp(s1, s2) == 0, "Expected '%s' to equal '%s'", s1, s2)
44
45 #define assert_char_in(c, s) \
46 assert(strchr(s, c) != NULL, "Expected '%s' to contain character '%c'", s, c)
47
48 #define assert_char_not_in(c, s) \
49 assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c)
50
51 void Test_log_tag_combinations_limit() {
52 assert(LogTagLevelExpression::MaxCombinations > LogTagSet::ntagsets(),
53 "Combination limit (" SIZE_FORMAT ") not sufficient "
54 "for configuring all available tag sets (" SIZE_FORMAT ")",
55 LogTagLevelExpression::MaxCombinations, LogTagSet::ntagsets());
56 }
57
58 class TestLogFile {
867 Test_log_gctracetime_no_cause();
868 Test_log_gctracetime_no_heap_no_cause();
869 }
870
871 void Test_invalid_log_file() {
872 ResourceMark rm;
873 stringStream ss;
874 const char* target_name = "tmplogdir";
875
876 // Attempt to log to a directory (existing log not a regular file)
877 create_directory(target_name);
878 LogFileOutput bad_file("tmplogdir");
879 assert(bad_file.initialize("", &ss) == false, "file was initialized "
880 "when there was an existing directory with the same name");
881 assert(strstr(ss.as_string(), "tmplogdir is not a regular file") != NULL,
882 "missing expected error message, received msg: %s", ss.as_string());
883 ss.reset();
884 remove(target_name);
885 }
886
887 // Ensure -Xlog:help and LogConfiguration::describe contain tagset descriptions
888 void Test_logtagset_descriptions() {
889 for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
890 char expected[1024];
891 d->tagset->label(expected, sizeof(expected), "+");
892 jio_snprintf(expected + strlen(expected),
893 sizeof(expected) - strlen(expected),
894 ": %s", d->descr);
895
896 ResourceMark rm;
897 stringStream ss;
898 LogConfiguration::describe(&ss);
899 assert(strstr(ss.as_string(), expected) != NULL,
900 "missing log tag set descriptions in LogConfiguration::describe");
901
902 TestLogFile file("log_tagset_descriptions");
903 FILE* fp = fopen(file.name(), "w+");
904 assert(fp != NULL, "File open error");
905 LogConfiguration::print_command_line_help(fp);
906 fclose(fp);
907 assert(number_of_lines_with_substring_in_file(file.name(), expected) > 0,
908 "missing log tag set descriptions in -Xlog:help output");
909 }
910 }
911 #endif // PRODUCT
|