jdk/test/com/sun/jdi/FilterMatch.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 24973 8c4bc3fa4c4e
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 FilterMatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/* Look at patternMatch 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  This test tests patterns passed to addClassFilter that do match
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  the classname of the event.  See also testcase FilterNoMatch.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class FilterMatch extends JDIScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static boolean listenCalled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        new FilterMatch().startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public FilterMatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private void listen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        TargetAdapter adapter = new TargetAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            EventSet set = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            public boolean eventSetReceived(EventSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                this.set = set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // This gets called if all filters match.
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);  // remove BP
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
        // These patterns all match HelloWorld.  Since they all match, our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // listener should get called and the test will pass.  If any of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // are erroneously determined to _not_ match, then our listener will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // not get called and the test will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        request1.addClassFilter("*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        request1.addClassFilter("H*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        request1.addClassFilter("He*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        request1.addClassFilter("HelloWorld*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        request1.addClassFilter("*d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        request1.addClassFilter("*ld");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        request1.addClassFilter("*HelloWorld");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        request1.addClassFilter("HelloWorld");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // As a test, uncomment this line and the test should fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        //request1.addClassFilter("x");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        request1.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        listen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        vm().resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        waitForVMDeath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if ( !listenCalled){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new Exception( "Failed: Event filtered out.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        System.out.println( "Passed: Event not filtered out.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}