Path: blob/master/test/hotspot/jtreg/serviceability/logging/TestFullNames.java
64474 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test TestFullNames25* @bug 821539826* @summary Ensure proper parsing of unquoted full output names for -Xlog arguments.27* @requires vm.flagless28* @modules java.base/jdk.internal.misc29* @library /test/lib30* @run driver TestFullNames31*/3233import java.io.File;34import java.nio.file.Path;35import java.nio.file.Paths;3637import jdk.test.lib.Asserts;38import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.process.OutputAnalyzer;4041public class TestFullNames {4243public static void main(String[] args) throws Exception {44// Ensure log files can be specified with full path.45// On windows, this means that the file name will contain46// a colon ('C:\log.txt' for example), which is used to47// separate -Xlog: options (-Xlog:tags:filename:decorators).48// Try to log to a file in our current directory, using its absolute path.49String baseName = "testfile.log";50Path filePath = Paths.get(baseName).toAbsolutePath();51String fileName = filePath.toString();52File file = filePath.toFile();5354// In case the file already exists, attempt to delete it before running the test55file.delete();5657// Test full pathnames without quotes.58String[] validOutputs = new String[] {59"file=" + fileName,60fileName61};62for (String logOutput : validOutputs) {63Asserts.assertFalse(file.exists());64// Run with logging=trace on stdout so that we can verify the log configuration afterwards.65ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:logging=trace",66"-Xlog:all=trace:" + logOutput,67"-version");68OutputAnalyzer output = new OutputAnalyzer(pb.start());69output.shouldHaveExitValue(0);70Asserts.assertTrue(file.exists());71file.delete();72output.shouldMatch("\\[logging *\\].*" + baseName); // Expect to see the log output listed73}74}75}76777879