test/jdk/com/sun/jdi/Vars.java
author psomashe
Fri, 16 Feb 2018 11:22:53 -0800
changeset 49009 1ecb986334cb
parent 47216 71c04702a3d5
permissions -rw-r--r--
4916621: Update those still using JDIScaffold to use TestScaffold instead. Summary: update remaining tests using JDIScaffold to using TestScaffold instead. Reviewed-by: sspitsyn, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, 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
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    26
 * @summary Test Method.variables() and the like.
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    27
 * @author Robert Field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
    29
 * @run build TestScaffold VMConnection
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    30
 * @run compile -g Vars.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    31
 * @run driver Vars
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class is internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
abstract class AbstractTestVars {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    abstract float test1(String blah, int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    native int test2(double k, boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    String test3(short sh, long lo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        String st = "roses";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        return st;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * This class is internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
class TestVars extends AbstractTestVars {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    float test1(String blah, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return (float)1.1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    void hi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        new TestVars().hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * "Vars" test runs TestVars and makes LocalVariable queries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
    71
public class Vars extends TestScaffold {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    Vars(String args[]) {
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
    76
        super(args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new Vars(args).runTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static final int VARIABLES = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static final int BYNAME = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static final int ARGUMENTS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    String testCase(Method method, int which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            List vars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            switch (which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                case VARIABLES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    vars = method.variables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                case BYNAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    vars = method.variablesByName("st");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                case ARGUMENTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    vars = method.arguments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    throw new InternalException("should not happen");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            for (Iterator it = vars.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                LocalVariable lv = (LocalVariable)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                if (sb.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                sb.append(lv.name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            String st = exc.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            int inx = st.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return st.substring(inx+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Sets failed if fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    void test(Method method, int which, String name, String expected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        String got = testCase(method, which);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (got.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            System.out.println(name + ": got expected: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            System.out.println(name + ": ERROR expected: " + expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            System.out.println("      got: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    void test2(Method method, int which, String name, String expected, String expected2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        String got = testCase(method, which);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (got.equals(expected) || got.equals(expected2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            System.out.println(name + ": got expected: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            System.out.println(name + ": ERROR expected: " + expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.out.println("      got: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * Get to a point where the classes are loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         */
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
   148
        BreakpointEvent bp = startTo("TestVars", "hi", "()V");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * These classes should have no line numbers, except for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * one in the implicit constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        ReferenceType rt = findReferenceType("AbstractTestVars");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new Exception("AbstractTestVars: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        Method method = findMethod(rt, "test1", "(Ljava/lang/String;I)F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw new Exception("Method not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        test(method, VARIABLES, "abstract/variables",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        test(method, BYNAME, "abstract/variablesByName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        test(method, ARGUMENTS, "abstract/arguments",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        method = findMethod(rt, "test2", "(DZ)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new Exception("Method not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        test(method, VARIABLES, "native/variables",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        test(method, BYNAME, "native/variablesByName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        test(method, ARGUMENTS, "native/arguments",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        method = findMethod(rt, "test3", "(SJ)Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new Exception("Method not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // javac can put these in whatever order it desires.  hopper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // does it one way and mantis another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        test2(method, VARIABLES, "normal/variables", "sh,lo,st", "st,sh,lo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        test(method, BYNAME, "normal/variablesByName", "st");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        test(method, ARGUMENTS, "normal/arguments", "sh,lo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // Allow application to complete
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
   191
        resumeToVMDisconnect();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new Exception("Vars: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            System.out.println("Vars: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}