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