Path: blob/master/test/hotspot/jtreg/serviceability/logging/TestFullNames.java
41152 views
/*1* Copyright (c) 2019, 2020, 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* @summary Ensure proper parsing of unquoted full output names for -Xlog arguments.26* @bug 821539827* @modules java.base/jdk.internal.misc28* @library /test/lib29* @run driver TestFullNames30*/3132import java.io.File;33import java.nio.file.Path;34import java.nio.file.Paths;3536import jdk.test.lib.Asserts;37import jdk.test.lib.process.ProcessTools;38import jdk.test.lib.process.OutputAnalyzer;3940public class TestFullNames {4142public static void main(String[] args) throws Exception {43// Ensure log files can be specified with full path.44// On windows, this means that the file name will contain45// a colon ('C:\log.txt' for example), which is used to46// separate -Xlog: options (-Xlog:tags:filename:decorators).47// Try to log to a file in our current directory, using its absolute path.48String baseName = "testfile.log";49Path filePath = Paths.get(baseName).toAbsolutePath();50String fileName = filePath.toString();51File file = filePath.toFile();5253// In case the file already exists, attempt to delete it before running the test54file.delete();5556// Test full pathnames without quotes.57String[] validOutputs = new String[] {58"file=" + fileName,59fileName60};61for (String logOutput : validOutputs) {62// Run with logging=trace on stdout so that we can verify the log configuration afterwards.63ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:logging=trace",64"-Xlog:all=trace:" + logOutput,65"-version");66OutputAnalyzer output = new OutputAnalyzer(pb.start());67output.shouldHaveExitValue(0);68Asserts.assertTrue(file.exists());69file.deleteOnExit(); // Clean up after test70output.shouldMatch("\\[logging *\\].*" + baseName); // Expect to see the log output listed71}72}73}74757677