< prev index next >

test/com/sun/jdi/GetSetLocalTest.java

Print this page
rev 16922 : 8177507: line number sensitive tests for jdi should be unified
Reviewed-by: duke
   1 /** hard coded linenumbers in other tests - DO NOT CHANGE
   2  *  @test/nodynamiccopyright/

























   3  *  @bug 4300412
   4  *  @summary Test GetLocal* and SetLocal* functions
   5  *
   6  *  @author Serguei Spitsyn
   7  *
   8  *  @run build TestScaffold VMConnection TargetListener TargetAdapter
   9  *  @run compile -g GetSetLocalTest.java
  10  *  @run driver GetSetLocalTest
  11  */
  12 import com.sun.jdi.*;
  13 import com.sun.jdi.event.*;
  14 import com.sun.jdi.request.*;
  15 
  16 import java.util.*;
  17 
  18     /********** target program **********/
  19 
  20 class GetSetLocalTarg {
  21     public static void main(String[] args){
  22         int intVar = 10;
  23         System.out.println("GetSetLocalTarg: Started");
  24         intVar = staticMeth(intVar);
  25         System.out.println("GetSetLocalTarg: Finished");
  26     }
  27 
  28     /*
  29      * The line numbers of this method *MUST NOT* be changed
  30      * because the testing algorithm counts on this layout!
  31      * It's in calls to resumeTo("GetSetLocalTarg", line).
  32      */
  33     public static int staticMeth(int intArg) {
  34         System.out.println("staticMeth: Started");
  35         int result;
  36         {
  37              { boolean bool_1 = false;
  38                intArg++;
  39              }
  40 
  41              boolean bool_2 = true;
  42              intArg++;
  43         }
  44         {
  45              { byte byte_1 = 1;
  46                intArg++;
  47              }
  48 
  49              byte byte_2 = 2;
  50              intArg++;
  51         }
  52         {
  53              { char   char_1 = '1';
  54                intArg++;
  55              }
  56 
  57              char   char_2 = '2';
  58              intArg++;


  94                intArg++;
  95              }
  96 
  97              double double_2 = 2;
  98              intArg++;
  99         }
 100         {
 101              { String string_1 = "1";
 102                intArg++;
 103              }
 104 
 105              String string_2 = "2";
 106              intArg++;
 107         }
 108         {
 109              { Object obj_1 = new Object();
 110                intArg++;
 111              }
 112 
 113              Object obj_2 = new Object();
 114              intArg++;  // <-- Last stop is at this point.
 115                         //     Only obj_2 and intArg are valid
 116                         // Note: even result is not valid here!
 117         }
 118         result = 10;    // <- This is first init of result var
 119         System.out.println("staticMeth: Finished");
 120         return result;
 121     }
 122 }
 123 
 124 
 125     /********** test program **********/
 126 
 127 public class GetSetLocalTest extends TestScaffold {


 128     ReferenceType targetClass;
 129     ThreadReference mainThread;
 130 
 131     GetSetLocalTest (String args[]) {
 132         super(args);
 133     }
 134 
 135     public static void main(String[] args) throws Exception {
 136         new GetSetLocalTest(args).startTests();
 137     }
 138 
 139     /********** test assist **********/
 140 
 141     Method getMethod(String className, String methodName) {
 142         List refs = vm().classesByName(className);
 143         if (refs.size() != 1) {
 144             failure(" Failure: " + refs.size() +
 145                     " ReferenceTypes named: " + className);
 146             return null;
 147         }


 618     protected void runTests() throws Exception {
 619 
 620         /*
 621          * Get to the top of main() to determine targetClass and mainThread
 622          */
 623         BreakpointEvent bpe = startToMain("GetSetLocalTarg");
 624         println("startToMain(GetSetLocalTarg)");
 625 
 626         List localVars = printAllVariables("GetSetLocalTarg", "staticMeth");
 627 
 628         targetClass = bpe.location().declaringType();
 629         println("targetClass");
 630 
 631         mainThread = bpe.thread();
 632         println("mainThread");
 633 
 634         EventRequestManager erm = vm().eventRequestManager();
 635         println("EventRequestManager");
 636         StackFrame frame = null;
 637 
 638         for (int line = 38; line < 118; line += 4) {
 639             println("\n resumeTo(GetSetLocalTarg, " + line + ")");
 640             bpe = resumeTo("GetSetLocalTarg", line);
 641             frame = bpe.thread().frame(0);
 642             printFrameVariables(frame);
 643             checkSetFrameVariables(frame);
 644         }
 645         // Check if we can Get/Set all local vars using last frame state
 646         checkGetSetAllVariables(localVars, frame);
 647 
 648         /*
 649          * resume until the end
 650          */
 651         listenUntilVMDisconnect();
 652 
 653         /*
 654          * deal with results of test
 655          * if anything has called failure("foo") testFailed will be true
 656          */
 657         if (!testFailed) {
 658             println("GetSetLocalTest: passed");
   1 /*
   2  * Copyright (c) 2007, 2017, 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 //    THIS TEST IS LINE NUMBER SENSITIVE
  25 
  26 /**
  27  * @test
  28  * @bug 4300412
  29  * @summary Test GetLocal* and SetLocal* functions

  30  * @author Serguei Spitsyn
  31  *
  32  * @run build TestScaffold VMConnection TargetListener TargetAdapter
  33  * @run compile -g GetSetLocalTest.java
  34  * @run driver GetSetLocalTest
  35  */
  36 import com.sun.jdi.*;
  37 import com.sun.jdi.event.*;
  38 import com.sun.jdi.request.*;
  39 
  40 import java.util.*;
  41 
  42     /********** target program **********/
  43 
  44 class GetSetLocalTarg {
  45     public static void main(String[] args){
  46         int intVar = 10;
  47         System.out.println("GetSetLocalTarg: Started");
  48         intVar = staticMeth(intVar);
  49         System.out.println("GetSetLocalTarg: Finished");
  50     }
  51 
  52     /*
  53      * The line numbers of this method *MUST NOT* be changed
  54      * because the testing algorithm counts on this layout!
  55      * It's in calls to resumeTo("GetSetLocalTarg", line).
  56      */
  57     public static int staticMeth(int intArg) {
  58         System.out.println("staticMeth: Started");
  59         int result;
  60         {
  61              { boolean bool_1 = false;
  62                intArg++; // START_LINE
  63              }
  64 
  65              boolean bool_2 = true;
  66              intArg++;
  67         }
  68         {
  69              { byte byte_1 = 1;
  70                intArg++;
  71              }
  72 
  73              byte byte_2 = 2;
  74              intArg++;
  75         }
  76         {
  77              { char   char_1 = '1';
  78                intArg++;
  79              }
  80 
  81              char   char_2 = '2';
  82              intArg++;


 118                intArg++;
 119              }
 120 
 121              double double_2 = 2;
 122              intArg++;
 123         }
 124         {
 125              { String string_1 = "1";
 126                intArg++;
 127              }
 128 
 129              String string_2 = "2";
 130              intArg++;
 131         }
 132         {
 133              { Object obj_1 = new Object();
 134                intArg++;
 135              }
 136 
 137              Object obj_2 = new Object();
 138              intArg++;  // STOP_LINE. Last stop is at this point.
 139                         //     Only obj_2 and intArg are valid
 140                         // Note: even result is not valid here!
 141         }
 142         result = 10;    // <- This is first init of result var
 143         System.out.println("staticMeth: Finished");
 144         return result;
 145     }
 146 }
 147 
 148 
 149     /********** test program **********/
 150 
 151 public class GetSetLocalTest extends TestScaffold {
 152     static final int START_LINE = 62;
 153     static final int STOP_LINE = 138;
 154     ReferenceType targetClass;
 155     ThreadReference mainThread;
 156 
 157     GetSetLocalTest (String args[]) {
 158         super(args);
 159     }
 160 
 161     public static void main(String[] args) throws Exception {
 162         new GetSetLocalTest(args).startTests();
 163     }
 164 
 165     /********** test assist **********/
 166 
 167     Method getMethod(String className, String methodName) {
 168         List refs = vm().classesByName(className);
 169         if (refs.size() != 1) {
 170             failure(" Failure: " + refs.size() +
 171                     " ReferenceTypes named: " + className);
 172             return null;
 173         }


 644     protected void runTests() throws Exception {
 645 
 646         /*
 647          * Get to the top of main() to determine targetClass and mainThread
 648          */
 649         BreakpointEvent bpe = startToMain("GetSetLocalTarg");
 650         println("startToMain(GetSetLocalTarg)");
 651 
 652         List localVars = printAllVariables("GetSetLocalTarg", "staticMeth");
 653 
 654         targetClass = bpe.location().declaringType();
 655         println("targetClass");
 656 
 657         mainThread = bpe.thread();
 658         println("mainThread");
 659 
 660         EventRequestManager erm = vm().eventRequestManager();
 661         println("EventRequestManager");
 662         StackFrame frame = null;
 663 
 664         for (int line = START_LINE; line <= STOP_LINE; line += 4) {
 665             println("\n resumeTo(GetSetLocalTarg, " + line + ")");
 666             bpe = resumeTo("GetSetLocalTarg", line);
 667             frame = bpe.thread().frame(0);
 668             printFrameVariables(frame);
 669             checkSetFrameVariables(frame);
 670         }
 671         // Check if we can Get/Set all local vars using last frame state
 672         checkGetSetAllVariables(localVars, frame);
 673 
 674         /*
 675          * resume until the end
 676          */
 677         listenUntilVMDisconnect();
 678 
 679         /*
 680          * deal with results of test
 681          * if anything has called failure("foo") testFailed will be true
 682          */
 683         if (!testFailed) {
 684             println("GetSetLocalTest: passed");
< prev index next >