jdk/test/com/sun/jdi/FilterNoMatch.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 20184 a2c4b7079eb6
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 4331522
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary addClassFilter("Foo") acts like "Foo*"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  @author Robert Field/Jim Holmlund
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @library scaffold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run build JDIScaffold VMConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run compile -g HelloWorld.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  @run main/othervm FilterNoMatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/* This tests the patternMatch function in JDK file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *    .../src/share/back/eventHandler.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This test verifies that patterns that do not match really don't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * See also testcase FilterMatch.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class FilterNoMatch extends JDIScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static boolean listenCalled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        new FilterNoMatch().startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public FilterNoMatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private void listen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        TargetAdapter adapter = new TargetAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            EventSet set = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            public boolean eventSetReceived(EventSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                this.set = set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            // This gets called if no patterns match.  If any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            // pattern is erroneously matched, then this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // will not get called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            public boolean stepCompleted(StepEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                listenCalled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                System.out.println("listen: line#=" + event.location().lineNumber()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                   + " event=" + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                // disable the step and then run to completion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                StepRequest str= (StepRequest)event.request();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                str.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                set.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        listenCalled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        addListener(adapter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        String[] args = new String[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        args[0] = "-connect";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        args[1] = "com.sun.jdi.CommandLineLaunch:main=HelloWorld";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        connect(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        waitForVMStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // VM has started, but hasn't started running the test program yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        EventRequestManager requestManager = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        ReferenceType referenceType = resumeToPrepareOf("HelloWorld").referenceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // The debuggee is stopped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // I don't think we really have to set a bkpt and then do a step,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // we should just be able to do a step.  Problem is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // createStepRequest call needs a thread and I don't know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // yet where to get one other than from the bkpt handling :-(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        Location location = findLocation(referenceType, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        BreakpointRequest request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            = requestManager.createBreakpointRequest(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        request.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // This does a resume, so we shouldn't come back to it until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // the debuggee has run and hit the bkpt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        BreakpointEvent event = (BreakpointEvent)waitForRequestedEvent(request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // The bkpt was hit; remove it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        requestManager.deleteEventRequest(request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        StepRequest request1 = requestManager.createStepRequest(event.thread(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                  StepRequest.STEP_LINE,StepRequest.STEP_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // We have to filter out all these so that they don't cause the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // listener to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        request1.addClassExclusionFilter( "java.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        request1.addClassExclusionFilter( "com.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        request1.addClassExclusionFilter( "sun.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // We want our listener to be called if a pattern does not match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // So, here we want patterns that do not match HelloWorld.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // If any pattern here erroneously matches, then our listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // will not get called and the test will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        request1.addClassExclusionFilter("H");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        request1.addClassExclusionFilter("HelloWorl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        request1.addClassExclusionFilter("HelloWorldx");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        request1.addClassExclusionFilter("xHelloWorld");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        request1.addClassExclusionFilter("*elloWorldx");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        request1.addClassExclusionFilter("*elloWorl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        request1.addClassExclusionFilter("*xHelloWorld");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        request1.addClassExclusionFilter("elloWorld*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        request1.addClassExclusionFilter("HelloWorldx*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        request1.addClassExclusionFilter("xHelloWorld*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // As a test, uncomment this line and this test should fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        //request1.addClassExclusionFilter("*elloWorld");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        request1.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        listen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        vm().resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        waitForVMDeath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if ( !listenCalled){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new Exception( "Failed: .");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        System.out.println( "Passed: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}