/* * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// Test for overflows with filesize
TEST_VM(LogFileOutput, filesize_overflow) { char buf[256]; int ret = jio_snprintf(buf, sizeof(buf), "filesize=" SIZE_FORMAT "K", SIZE_MAX);
ASSERT_GT(ret, 0) << "Buffer too small";
for (size_t i = 0; i < rotations; i++) {
size_t len = strlen(filename) + 3;
rotated_file[i] = NEW_RESOURCE_ARRAY(char, len); int ret = jio_snprintf(rotated_file[i], len, "%s." SIZE_FORMAT, filename, i);
ASSERT_NE(-1, ret);
delete_file(rotated_file[i]);
}
delete_file(filename);
init_log_file(filename);
ASSERT_TRUE(file_exists(filename))
<< "configured logging to file '" << filename << "' but file was not found";
// Initialize the same file a bunch more times to trigger rotations for (size_t i = 0; i < rotations; i++) {
init_log_file(filename);
EXPECT_TRUE(file_exists(rotated_file[i]));
}
// Remove a file and expect its slot to be re-used
delete_file(rotated_file[1]);
init_log_file(filename);
EXPECT_TRUE(file_exists(rotated_file[1]));
// Clean up after test
delete_file(filename); for (size_t i = 0; i < rotations; i++) {
delete_file(rotated_file[i]);
}
}
// Use the same log file twice and expect it to be overwritten/truncated
init_log_file(filename, "filecount=0");
ASSERT_TRUE(file_exists(filename))
<< "configured logging to file '" << filename << "' but file was not found";
init_log_file(filename, "filecount=0");
ASSERT_TRUE(file_exists(filename))
<< "configured logging to file '" << filename << "' but file was not found";
EXPECT_FALSE(file_exists(archived_filename))
<< "existing log file was not properly truncated when filecount was 0";
// Verify that the file was really truncated and not just appended
EXPECT_TRUE(file_contains_substring(filename, LOG_TEST_STRING_LITERAL)); constchar* repeated[] = { LOG_TEST_STRING_LITERAL, LOG_TEST_STRING_LITERAL };
EXPECT_FALSE(file_contains_substrings_in_order(filename, repeated))
<< "log file " << filename << " appended rather than truncated";
ss.print("%s is not a regular file", path); char* expected_output_substring = ss.as_string();
ss.reset();
// Attempt to log to a directory (existing log not a regular file)
create_directory(path);
LogFileOutput bad_file(log_spec);
EXPECT_FALSE(bad_file.initialize("", &ss))
<< "file was initialized when there was an existing directory with the same name"; char* logger_output = ss.as_string();
EXPECT_TRUE(string_contains_substring(logger_output, expected_output_substring))
<< "missing expected error message, received msg: %s" << logger_output;
delete_empty_directory(path);
}
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.