Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/exclude/exclude001/exclude001.java
40951 views
/*1* Copyright (c) 2002, 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*/222324/*25* @test26*27* @summary converted from VM Testbase nsk/jdb/exclude/exclude001.28* VM Testbase keywords: [jpda, jdb, quarantine]29* VM Testbase comments: 819103730* VM Testbase readme:31* DECSRIPTION32* A positive test for the 'exclude' command.33* The debuggee program (exclude001a.java) starts three34* addional threads of MyThread class. The 'run' method of these35* threads invokes java.lang.System.currentTimeMillis() and36* sun.util.calendar.Gregorian() methods.37* There are three test cases:38* - block all exclude filter;39* - modified exclude filter allowing tracing events for java.* methods,40* which is set with 'exclude javax.*,sun.*,com.sun.*,jdk.*' command;41* - modified exclude filter allowing tracing events for sun.* methods,42* which is set with 'exclude java.*,javax.*,com.sun.*,jdk.*' command.43* - non-modified, predefined exclude filter;44* - modified exclude filter allowing tracing events for java.* methods,45* which is set with 'exclude javax.*,sun.*,com.sun.*' command;46* - modified exclude filter allowing tracing events for all system methods,47* which is set with 'exclude none' command.48* For each test case the correspondent MyThread thread is started and49* suspended at a breakpoint. Then method tracing is turned on with50* 'trace methods <thread id>' command with correspondent exclude filtering.51* The test passes if debuggee suspends on method enter/exit of only52* filtered classes, i.e. in comply with exclude filter previously set.53* The test consists of two program:54* exclude001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,55* exclude001a.java - the debugged application.56* COMMENTS57*58* @library /vmTestbase59* /test/lib60* @build nsk.jdb.exclude.exclude001.exclude001a61* @run main/othervm/timeout=60062* nsk.jdb.exclude.exclude001.exclude00163* -arch=${os.family}-${os.simpleArch}64* -waittime=1065* -debugee.vmkind=java66* -transport.address=dynamic67* -jdb=${test.jdk}/bin/jdb68* -java.options="${test.vm.opts} ${test.java.opts}"69* -workdir=.70* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"71*/7273package nsk.jdb.exclude.exclude001;7475import nsk.share.*;76import nsk.share.jdb.*;7778import java.io.*;79import java.util.*;8081public class exclude001 extends JdbTest {8283public static void main (String argv[]) {84System.exit(run(argv, System.out) + JCK_STATUS_BASE);85}8687public static int run(String argv[], PrintStream out) {88debuggeeClass = DEBUGGEE_CLASS;89firstBreak = FIRST_BREAK;90lastBreak = LAST_BREAK;91return new exclude001().runTest(argv, out);92}9394static final String PACKAGE_NAME = "nsk.jdb.exclude.exclude001";95static final String TEST_CLASS = PACKAGE_NAME + ".exclude001";96static final String DEBUGGEE_CLASS = TEST_CLASS + "a";97static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";98static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";99static final String MYTHREAD = "MyThread";100static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;101102static final String JAVA_CORE_METHOD = "java.lang.System.currentTimeMillis";103static final String SUN_METHOD = "sun.util.calendar.Gregorian";104105protected void runCases() {106String[] reply;107Paragrep grep;108int count;109Vector v;110String found;111String[] threads;112113String oldExclude = "";114boolean javaTraced = false;115boolean comTraced = false;116boolean nskTraced = false;117118jdb.setBreakpointInMethod(LAST_BREAK);119120// getting predefined 'exclude' value121reply = jdb.receiveReplyFor(JdbCommand.exclude);122if (reply.length == 0) {123log.complain("Predefined excluded lists of classes is empty");124success = false;125} else {126127oldExclude = reply[0];128129for (int testCase = 0; testCase < exclude001a.numThreads; testCase++) {130String expectedPrompt = MYTHREAD + "-" + testCase + "[1]";131reply = jdb.receiveReplyFor(JdbCommand.cont);132133if (jdb.isAtBreakpoint(reply, LAST_BREAK)) {134135threads = jdb.getThreadIds(DEBUGGEE_THREAD);136137if (threads.length != 1) {138log.complain("jdb should report 1 instance of " + DEBUGGEE_THREAD);139log.complain("Found: " + threads.length);140success = false;141} else {142143reply = jdb.receiveReplyFor(JdbCommand.step); // to get out of lastBreak;144145switch (testCase) {146case 0: // block all147reply = jdb.receiveReplyFor(JdbCommand.exclude + "java.*,javax.*,sun.*,com.sun.*,jdk.*");148149break;150case 1: // allow java.*151reply = jdb.receiveReplyFor(JdbCommand.exclude + "javax.*,sun.*,com.sun.*,jdk.*");152break;153case 2: // allow sun.*154reply = jdb.receiveReplyFor(JdbCommand.exclude + "java.*,javax.*,com.sun.*,jdk.*");155break;156}157158reply = jdb.receiveReplyFor(JdbCommand.trace + "methods " + threads[0]);159160while (true) {161reply = jdb.receiveReplyForWithMessageWait(JdbCommand.cont, expectedPrompt);162163grep = new Paragrep(reply);164count = grep.find(JAVA_CORE_METHOD);165if (count > 0) {166if (testCase != 0) {167javaTraced = true;168} else {169log.complain("Trace message for excluded method: " + JAVA_CORE_METHOD);170}171}172173count = grep.find(SUN_METHOD);174if (count > 0) {175if (testCase == 2) {176comTraced = true;177} else {178log.complain("Trace message for excluded method: " + SUN_METHOD);179}180}181182count = grep.find(DEBUGGEE_THREAD + ".run");183if (count > 0) {184nskTraced = true;185186reply = jdb.receiveReplyFor(JdbCommand.exclude + oldExclude);187reply = jdb.receiveReplyFor(JdbCommand.untrace + "methods "+ threads[0]);188break;189}190}191}192}193}194}195196jdb.contToExit(2);197198if (!javaTraced) {199log.complain("There were no tracing events for " + JAVA_CORE_METHOD + "() method while turned off filter");200success = false;201}202if (!comTraced) {203log.complain("There were no tracing events for " + SUN_METHOD + "() method while turned off filter");204success = false;205}206if (!nskTraced) {207log.complain("There were no tracing events for " + DEBUGGEE_THREAD + ".run() method ");208success = false;209}210}211}212213214