Skip to content

Commit d9541c5

Browse files
jdksjolentstuefe
authored andcommitted
8276202: LogFileOutput.invalid_file_vm asserts when being executed from a read only working directory
Reviewed-by: dholmes, stuefe
1 parent df7fba1 commit d9541c5

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

test/hotspot/gtest/logging/logTestFixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void LogTestFixture::clear_snapshot() {
113113
if (_configuration_snapshot == NULL) {
114114
return;
115115
}
116-
assert(_n_snapshots > 0, "non-null array should have at least 1 element");
116+
ASSERT_GT(_n_snapshots, size_t(0)) << "non-null array should have at least 1 element";
117117
for (size_t i = 0; i < _n_snapshots; i++) {
118118
os::free(_configuration_snapshot[i]);
119119
}

test/hotspot/gtest/logging/logTestUtils.inline.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ static inline void delete_file(const char* filename) {
5757
}
5858

5959
static inline void create_directory(const char* name) {
60-
assert(!file_exists(name), "can't create directory: %s already exists", name);
60+
ASSERT_FALSE(file_exists(name)) << "can't create directory: " << name << " already exists";
6161
bool failed;
6262
#ifdef _WINDOWS
6363
failed = !CreateDirectory(name, NULL);
6464
#else
6565
failed = mkdir(name, 0777);
6666
#endif
67-
assert(!failed, "failed to create directory %s", name);
67+
ASSERT_FALSE(failed) << "failed to create directory " << name;
6868
}
6969

7070
static inline void delete_empty_directory(const char* name) {

test/hotspot/gtest/logging/test_logFileOutput.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,26 @@ TEST_VM(LogFileOutput, invalid_file) {
169169
ResourceMark rm;
170170
stringStream ss;
171171

172+
// Generate sufficiently unique directory path and log spec for that path
173+
ss.print("%s%s%s%d", os::get_temp_directory(), os::file_separator(), "tmplogdir", os::current_process_id());
174+
char* path = ss.as_string();
175+
ss.reset();
176+
177+
ss.print("%s%s", "file=", path);
178+
char* log_spec = ss.as_string();
179+
ss.reset();
180+
181+
ss.print("%s is not a regular file", path);
182+
char* expected_output_substring = ss.as_string();
183+
ss.reset();
184+
172185
// Attempt to log to a directory (existing log not a regular file)
173-
create_directory("tmplogdir");
174-
LogFileOutput bad_file("file=tmplogdir");
186+
create_directory(path);
187+
LogFileOutput bad_file(log_spec);
175188
EXPECT_FALSE(bad_file.initialize("", &ss))
176189
<< "file was initialized when there was an existing directory with the same name";
177-
EXPECT_TRUE(string_contains_substring(ss.as_string(), "tmplogdir is not a regular file"))
178-
<< "missing expected error message, received msg: %s" << ss.as_string();
179-
delete_empty_directory("tmplogdir");
190+
char* logger_output = ss.as_string();
191+
EXPECT_TRUE(string_contains_substring(logger_output, expected_output_substring))
192+
<< "missing expected error message, received msg: %s" << logger_output;
193+
delete_empty_directory(path);
180194
}

0 commit comments

Comments
 (0)