1 /* 2 * Copyright (c) 2001, 2015, 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 // TEMPLATE: global replace "Template" with your test name 25 // TEMPLATE: change bug number and fill out <SUMMARY> and <AUTHOR> 26 // TEMPLATE: delete TEMPLATE lines 27 /** 28 * @test 29 * @bug 0000000 30 * @summary <SUMMARY> 31 * 32 * @author <AUTHOR> 33 * 34 * @modules jdk.jdi 35 * @run build TestScaffold VMConnection TargetListener TargetAdapter 36 * @run compile -g TemplateTest.java 37 * @run driver TemplateTest 38 */ 39 import com.sun.jdi.*; 40 import com.sun.jdi.event.*; 41 import com.sun.jdi.request.*; 42 43 import java.util.*; 44 45 /********** target program **********/ 46 47 class TemplateTarg { 48 public static void main(String[] args){ 49 System.out.println("Howdy!"); 50 System.out.println("Goodbye from TemplateTarg!"); 51 } 52 } 53 54 /********** test program **********/ 55 56 public class TemplateTest extends TestScaffold { 57 ReferenceType targetClass; 58 ThreadReference mainThread; 59 60 TemplateTest (String args[]) { 61 super(args); 62 } 63 64 public static void main(String[] args) throws Exception { 65 new TemplateTest(args).startTests(); 66 } 67 68 /********** event handlers **********/ 69 70 // TEMPLATE: delete the handlers you don't need 71 // TEMPLATE: defaults are in TargetAdapter 72 73 public void eventSetReceived(EventSet set) { 74 println("Got event set"); 75 } 76 77 public void eventReceived(Event event) { 78 println("Got event"); 79 } 80 81 public void breakpointReached(BreakpointEvent event) { 82 println("Got BreakpointEvent"); 83 } 84 85 public void exceptionThrown(ExceptionEvent event) { 86 println("Got ExceptionEvent"); 87 } 88 89 public void stepCompleted(StepEvent event) { 90 println("Got StepEvent"); 91 } 92 93 public void classPrepared(ClassPrepareEvent event) { 94 println("Got ClassPrepareEvent"); 95 } 96 97 public void classUnloaded(ClassUnloadEvent event) { 98 println("Got ClassUnloadEvent"); 99 } 100 101 public void methodEntered(MethodEntryEvent event) { 102 println("Got MethodEntryEvent"); 103 } 104 105 public void methodExited(MethodExitEvent event) { 106 println("Got MethodExitEvent"); 107 } 108 109 public void fieldAccessed(AccessWatchpointEvent event) { 110 println("Got AccessWatchpointEvent"); 111 } 112 113 public void fieldModified(ModificationWatchpointEvent event) { 114 println("Got ModificationWatchpointEvent"); 115 } 116 117 public void threadStarted(ThreadStartEvent event) { 118 println("Got ThreadStartEvent"); 119 } 120 121 public void threadDied(ThreadDeathEvent event) { 122 println("Got ThreadDeathEvent"); 123 } 124 125 public void vmStarted(VMStartEvent event) { 126 println("Got VMStartEvent"); 127 } 128 129 public void vmDied(VMDeathEvent event) { 130 println("Got VMDeathEvent"); 131 } 132 133 public void vmDisconnected(VMDisconnectEvent event) { 134 println("Got VMDisconnectEvent"); 135 } 136 137 /********** test core **********/ 138 139 protected void runTests() throws Exception { 140 /* 141 * Get to the top of main() 142 * to determine targetClass and mainThread 143 */ 144 BreakpointEvent bpe = startToMain("TemplateTarg"); 145 targetClass = bpe.location().declaringType(); 146 mainThread = bpe.thread(); 147 EventRequestManager erm = vm().eventRequestManager(); 148 149 // TEMPLATE: set things up 150 151 // TEMPLATE: for example 152 /* 153 * Set event requests 154 */ 155 StepRequest request = erm.createStepRequest(mainThread, 156 StepRequest.STEP_LINE, 157 StepRequest.STEP_OVER); 158 request.enable(); 159 160 /* 161 * resume the target listening for events 162 */ 163 listenUntilVMDisconnect(); 164 165 /* 166 * deal with results of test 167 * if anything has called failure("foo") testFailed will be true 168 */ 169 if (!testFailed) { 170 println("TemplateTest: passed"); 171 } else { 172 throw new Exception("TemplateTest: failed"); 173 } 174 } 175 }