mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-15 16:44:36 +02:00
8167548: [TESTBUG] Logging tests put log files in source tree
Create log files in temp directory, instead of cwd. Reviewed-by: coleenp, dholmes
This commit is contained in:
parent
865c33112c
commit
f4ac0a2e0f
7 changed files with 60 additions and 29 deletions
|
@ -51,6 +51,14 @@ LogFileOutput::LogFileOutput(const char* name)
|
||||||
_file_name = make_file_name(name + strlen(Prefix), _pid_str, _vm_start_time_str);
|
_file_name = make_file_name(name + strlen(Prefix), _pid_str, _vm_start_time_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* LogFileOutput::cur_log_file_name() {
|
||||||
|
if (strlen(_archive_name) == 0) {
|
||||||
|
return _file_name;
|
||||||
|
} else {
|
||||||
|
return _archive_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LogFileOutput::set_file_name_parameters(jlong vm_start_time) {
|
void LogFileOutput::set_file_name_parameters(jlong vm_start_time) {
|
||||||
int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id());
|
int res = jio_snprintf(_pid_str, sizeof(_pid_str), "%d", os::current_process_id());
|
||||||
assert(res > 0, "PID buffer too small");
|
assert(res > 0, "PID buffer too small");
|
||||||
|
@ -234,6 +242,7 @@ bool LogFileOutput::initialize(const char* options, outputStream* errstream) {
|
||||||
_file_count_max_digits = number_of_digits(_file_count - 1);
|
_file_count_max_digits = number_of_digits(_file_count - 1);
|
||||||
_archive_name_len = 2 + strlen(_file_name) + _file_count_max_digits;
|
_archive_name_len = 2 + strlen(_file_name) + _file_count_max_digits;
|
||||||
_archive_name = NEW_C_HEAP_ARRAY(char, _archive_name_len, mtLogging);
|
_archive_name = NEW_C_HEAP_ARRAY(char, _archive_name_len, mtLogging);
|
||||||
|
_archive_name[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_trace(logging)("Initializing logging to file '%s' (filecount: %u"
|
log_trace(logging)("Initializing logging to file '%s' (filecount: %u"
|
||||||
|
|
|
@ -92,6 +92,7 @@ class LogFileOutput : public LogFileStreamOutput {
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* cur_log_file_name();
|
||||||
static const char* const Prefix;
|
static const char* const Prefix;
|
||||||
static void set_file_name_parameters(jlong start_time);
|
static void set_file_name_parameters(jlong start_time);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -33,11 +33,12 @@
|
||||||
#include "utilities/ostream.hpp"
|
#include "utilities/ostream.hpp"
|
||||||
|
|
||||||
LogTestFixture::LogTestFixture() : _n_snapshots(0), _configuration_snapshot(NULL) {
|
LogTestFixture::LogTestFixture() : _n_snapshots(0), _configuration_snapshot(NULL) {
|
||||||
// Set up TestLogFileName to include PID, testcase name and test name
|
|
||||||
int ret = jio_snprintf(_filename, sizeof(_filename), "testlog.pid%d.%s.%s.log",
|
// Set up TestLogFileName to include temp_dir, PID, testcase name and test name.
|
||||||
os::current_process_id(),
|
const testing::TestInfo* test_info = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||||
::testing::UnitTest::GetInstance()->current_test_info()->test_case_name(),
|
int ret = jio_snprintf(_filename, sizeof(_filename), "%s%stestlog.pid%d.%s.%s.log",
|
||||||
::testing::UnitTest::GetInstance()->current_test_info()->name());
|
os::get_temp_directory(), os::file_separator(), os::current_process_id(),
|
||||||
|
test_info->test_case_name(), test_info->name());
|
||||||
EXPECT_GT(ret, 0) << "_filename buffer issue";
|
EXPECT_GT(ret, 0) << "_filename buffer issue";
|
||||||
TestLogFileName = _filename;
|
TestLogFileName = _filename;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -88,6 +88,30 @@ static inline void init_log_file(const char* filename, const char* options = "")
|
||||||
guarantee(success, "Failed to disable logging to file '%s'", filename);
|
guarantee(success, "Failed to disable logging to file '%s'", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* tmp_dir = os::get_temp_directory();
|
||||||
|
static const char* file_sep = os::file_separator();
|
||||||
|
|
||||||
|
// Prepend filename with the temp directory and pid and return the result as a
|
||||||
|
// resource allocated string.
|
||||||
|
static inline char* prepend_temp_dir(const char* filename) {
|
||||||
|
size_t temp_file_len = strlen(tmp_dir) + strlen(file_sep) + strlen(filename) + 28;
|
||||||
|
char* temp_file = NEW_RESOURCE_ARRAY(char, temp_file_len);
|
||||||
|
int ret = jio_snprintf(temp_file, temp_file_len, "%s%spid%d.%s",
|
||||||
|
tmp_dir, file_sep,
|
||||||
|
os::current_process_id(), filename);
|
||||||
|
return temp_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepend filename with specified prefix and the temp directory and return the
|
||||||
|
// result as a malloc allocated string. This is used by test_logFileOutput.cpp.
|
||||||
|
static inline char* prepend_prefix_temp_dir(const char* prefix, const char* filename) {
|
||||||
|
size_t temp_file_len = strlen(prefix) + strlen(tmp_dir) + strlen(file_sep) + strlen(filename) + 1;
|
||||||
|
char* temp_file = (char*)os::malloc(temp_file_len, mtLogging);
|
||||||
|
int ret = jio_snprintf(temp_file, temp_file_len, "%s%s%s%s",
|
||||||
|
prefix, tmp_dir, file_sep, filename);
|
||||||
|
return temp_file;
|
||||||
|
}
|
||||||
|
|
||||||
// Read a complete line from fp and return it as a resource allocated string.
|
// Read a complete line from fp and return it as a resource allocated string.
|
||||||
// Returns NULL on EOF.
|
// Returns NULL on EOF.
|
||||||
static inline char* read_line(FILE* fp) {
|
static inline char* read_line(FILE* fp) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -403,16 +403,15 @@ TEST_VM_F(LogConfigurationTest, output_name_normalization) {
|
||||||
|
|
||||||
// Make sure prefixes are ignored when used within quotes
|
// Make sure prefixes are ignored when used within quotes
|
||||||
// (this should create a log with "file=" in its filename)
|
// (this should create a log with "file=" in its filename)
|
||||||
int ret = jio_snprintf(buf, sizeof(buf), "\"file=%s\"", TestLogFileName);
|
// Note that the filename cannot contain directories because
|
||||||
ASSERT_NE(-1, ret);
|
// it is being prefixed with "file=".
|
||||||
set_log_config(buf, "logging=trace");
|
const char* leafFileName = "\"file=leaf_file_name\"";
|
||||||
|
set_log_config(leafFileName, "logging=trace");
|
||||||
EXPECT_TRUE(is_described("#3: ")) << "prefix within quotes not ignored as it should be";
|
EXPECT_TRUE(is_described("#3: ")) << "prefix within quotes not ignored as it should be";
|
||||||
set_log_config(buf, "all=off");
|
set_log_config(leafFileName, "all=off");
|
||||||
|
|
||||||
// Remove the extra log file created
|
// Remove the extra log file created
|
||||||
ret = jio_snprintf(buf, sizeof(buf), "file=%s", TestLogFileName);
|
delete_file("file=leaf_file_name");
|
||||||
ASSERT_NE(-1, ret);
|
|
||||||
delete_file(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t count_occurrences(const char* haystack, const char* needle) {
|
static size_t count_occurrences(const char* haystack, const char* needle) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
#include "utilities/globalDefinitions.hpp"
|
#include "utilities/globalDefinitions.hpp"
|
||||||
#include "utilities/ostream.hpp"
|
#include "utilities/ostream.hpp"
|
||||||
|
|
||||||
static const char* name = "file=testlog.pid%p.%t.log";
|
static const char* name = prepend_prefix_temp_dir("file=", "testlog.pid%p.%t.log");
|
||||||
|
|
||||||
// Test parsing a bunch of valid file output options
|
// Test parsing a bunch of valid file output options
|
||||||
TEST_VM(LogFileOutput, parse_valid) {
|
TEST_VM(LogFileOutput, parse_valid) {
|
||||||
|
@ -46,11 +46,6 @@ TEST_VM(LogFileOutput, parse_valid) {
|
||||||
|
|
||||||
// Override LogOutput's vm_start time to get predictable file name
|
// Override LogOutput's vm_start time to get predictable file name
|
||||||
LogFileOutput::set_file_name_parameters(0);
|
LogFileOutput::set_file_name_parameters(0);
|
||||||
char expected_filename[1 * K];
|
|
||||||
int ret = jio_snprintf(expected_filename, sizeof(expected_filename),
|
|
||||||
"testlog.pid%d.1970-01-01_01-00-00.log",
|
|
||||||
os::current_process_id());
|
|
||||||
ASSERT_GT(ret, 0) << "Buffer too small";
|
|
||||||
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(valid_options); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(valid_options); i++) {
|
||||||
ResourceMark rm;
|
ResourceMark rm;
|
||||||
|
@ -60,8 +55,8 @@ TEST_VM(LogFileOutput, parse_valid) {
|
||||||
EXPECT_STREQ(name, fo.name());
|
EXPECT_STREQ(name, fo.name());
|
||||||
EXPECT_TRUE(fo.initialize(valid_options[i], &ss))
|
EXPECT_TRUE(fo.initialize(valid_options[i], &ss))
|
||||||
<< "Did not accept valid option(s) '" << valid_options[i] << "': " << ss.as_string();
|
<< "Did not accept valid option(s) '" << valid_options[i] << "': " << ss.as_string();
|
||||||
|
remove(fo.cur_log_file_name());
|
||||||
}
|
}
|
||||||
remove(expected_filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +100,11 @@ TEST_VM(LogFileOutput, filesize_overflow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_VM(LogFileOutput, startup_rotation) {
|
TEST_VM(LogFileOutput, startup_rotation) {
|
||||||
|
ResourceMark rm;
|
||||||
const size_t rotations = 5;
|
const size_t rotations = 5;
|
||||||
const char* filename = "start-rotate-test";
|
const char* filename = prepend_temp_dir("start-rotate-test");
|
||||||
char* rotated_file[rotations];
|
char* rotated_file[rotations];
|
||||||
|
|
||||||
ResourceMark rm;
|
|
||||||
for (size_t i = 0; i < rotations; i++) {
|
for (size_t i = 0; i < rotations; i++) {
|
||||||
size_t len = strlen(filename) + 3;
|
size_t len = strlen(filename) + 3;
|
||||||
rotated_file[i] = NEW_RESOURCE_ARRAY(char, len);
|
rotated_file[i] = NEW_RESOURCE_ARRAY(char, len);
|
||||||
|
@ -142,8 +137,9 @@ TEST_VM(LogFileOutput, startup_rotation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_VM(LogFileOutput, startup_truncation) {
|
TEST_VM(LogFileOutput, startup_truncation) {
|
||||||
const char* filename = "start-truncate-test";
|
ResourceMark rm;
|
||||||
const char* archived_filename = "start-truncate-test.0";
|
const char* filename = prepend_temp_dir("start-truncate-test");
|
||||||
|
const char* archived_filename = prepend_temp_dir("start-truncate-test.0");
|
||||||
|
|
||||||
delete_file(filename);
|
delete_file(filename);
|
||||||
delete_file(archived_filename);
|
delete_file(archived_filename);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -48,7 +48,8 @@ TEST_VM(LogTagSetDescriptions, describe) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_VM(LogTagSetDescriptions, command_line_help) {
|
TEST_VM(LogTagSetDescriptions, command_line_help) {
|
||||||
const char* filename = "logtagset_descriptions";
|
ResourceMark rm;
|
||||||
|
const char* filename = prepend_temp_dir("logtagset_descriptions");
|
||||||
FILE* fp = fopen(filename, "w+");
|
FILE* fp = fopen(filename, "w+");
|
||||||
ASSERT_NE((void*)NULL, fp);
|
ASSERT_NE((void*)NULL, fp);
|
||||||
fileStream stream(fp);
|
fileStream stream(fp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue