1/* 2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @summary -Xlog:module should emit logging output 27 * @library /test/lib 28 * @modules java.base/jdk.internal.misc 29 * java.management 30 * @run main ModulesTest 31 */ 32 33import jdk.test.lib.process.OutputAnalyzer; 34import jdk.test.lib.process.ProcessTools; 35 36public class ModulesTest { 37 public static void main(String[] args) throws Exception { 38 testModuleTrace("-Xlog:module=trace", "-version"); 39 testModuleLoad("-Xlog:module+load", "-version"); 40 testModuleUnload("-Xlog:module+unload", "-version"); 41 42 // same as -Xlog:module+load -Xlog:module+unload 43 testModuleLoad("-verbose:module", "-version"); 44 } 45 46 static void testModuleTrace(String... args) throws Exception { 47 OutputAnalyzer output = run(args); 48 output.shouldContain("define_javabase_module(): Definition of module:"); 49 output.shouldContain("define_javabase_module(): creation of package"); 50 output.shouldContain("define_module(): creation of module"); 51 output.shouldContain("define_module(): creation of package"); 52 output.shouldContain("set_bootloader_unnamed_module(): recording unnamed"); 53 output.shouldContain("add_module_exports(): package"); 54 output.shouldContain("add_reads_module(): Adding read from module"); 55 output.shouldContain("Setting package: class:"); 56 output.shouldHaveExitValue(0); 57 } 58 59 static void testModuleLoad(String... args) throws Exception { 60 OutputAnalyzer output = run(args); 61 output.shouldContain("java.base location:"); 62 output.shouldContain("java.management location:"); 63 output.shouldHaveExitValue(0); 64 } 65 66 static void testModuleUnload(String... args) throws Exception { 67 OutputAnalyzer output = run(args); 68 output.shouldHaveExitValue(0); 69 } 70 71 static OutputAnalyzer run(String... args) throws Exception { 72 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); 73 return new OutputAnalyzer(pb.start()); 74 } 75} 76 77