test/jdk/com/sun/jdi/StringConvertTest.sh
author iignatyev
Fri, 14 Sep 2018 14:02:57 -0700
changeset 51754 594919232b8f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8210732: remove jdk.testlibrary.Utils Reviewed-by: alanb, jcbeyler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/bin/sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
#
23046
0b0407b1e2a5 6946101: ShellScaffold.sh based tests can issue "write error: Broken pipe" messages
iignatyev
parents: 5506
diff changeset
     4
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
# questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
23057
c67ddf10398e 8036132: Tab characters in test/com/sun/jdi files
sla
parents: 23046
diff changeset
    26
#  @test
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#  @bug 4511950 4843082
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#  @summary 1. jdb's expression evaluation doesn't perform string conversion properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#           2. TTY: run on expression evaluation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#  @author jim/suvasis mukherjee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#
32018
91c91b3d50a0 8132094: Mark intermittently failuring core-svc tests
ykantser
parents: 31909
diff changeset
    32
#  @key intermittent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#  @run shell StringConvertTest.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#  Run this script to see the bug.  See comments at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#  of the .java file for info on what the bug looks like.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
# These are variables that can be set to control execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#pkg=untitled7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
classname=StringConvertTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
compileOptions=-g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#java=java_g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#mode=-Xcomp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#jdbOptions=-dbgtrace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
createJavaFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    cat <<EOF > $1.java.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
class $classname {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    String me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static JJ1 x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static JJ2 x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static JJ2[] x3 = new JJ2[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static String x4 = "abc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static int ii = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static String grower = "grower";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static StringBuffer sbGrower = new StringBuffer("sbGrower");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int ivar = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    $classname(String xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        me = xx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static String fred() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return "a static method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    void  gus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        int gusLoc = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        StringBuffer sbTim = new StringBuffer("tim");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        int kk = 1;                          //@1 breakpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static String growit(String extra) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        grower += extra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return grower;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static String sbGrowit(String extra) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        sbGrower.append(extra);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return sbGrower.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        x1 = new JJ1("first JJ1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        x2 = new JJ2("first JJ2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        x3[0] = new JJ2("array0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        x3[1] = new JJ2("array1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        $classname  loc1 = new $classname("first me");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // These just show what output should look like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        System.out.println("x1 = " + x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        System.out.println("x2 = " + x2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        System.out.println("x3.toString = " + x3.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        System.out.println("x4.toString = " + x4.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // Dont want to call growit since it would change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        System.out.println("loc1 = " + loc1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        System.out.println("-" + loc1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        loc1.gus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  // This does not have a toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  static class JJ1 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    String me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    JJ1(String whoAmI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        me = whoAmI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  // This has a toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  static class JJ2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    String me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    JJ2(String whoAmI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        me = whoAmI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public int meth1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
# This is called to feed cmds to jdb.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
dojdbCmds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    setBkpts @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    runToBkpt @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    # Each print without the 'toString()' should print the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    # same thing as the following print with the toString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    # The print 1s are just spacers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    cmd print $classname.x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    cmd print "$classname.x1.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    cmd print $classname.x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    cmd print "$classname.x2.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    # An unreported bug: this isn't handled correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    # If we uncomment this line, we will get an 'instance of...'  line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    # which will cause the test to fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    #cmd print "(Object)($classname.x3)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    cmd print "((Object)$classname.x3).toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    cmd print $classname.x4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    cmd print "$classname.x4.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    # Make sure jdb doesn't call a method multiple times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    cmd print "$classname.growit(\"xyz\")"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    cmd eval  "$classname.sbGrower.append(\"xyz\")"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    cmd print 1
23046
0b0407b1e2a5 6946101: ShellScaffold.sh based tests can issue "write error: Broken pipe" messages
iignatyev
parents: 5506
diff changeset
   168
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    cmd eval "sbTim.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    cmd print this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    cmd print "this.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    # A possible bug is that this ends up with multiple "s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    cmd print '"--" + '$classname.x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    # This too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    cmd print "$classname.x4 + 2"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    cmd print "this.ivar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    cmd print gusLoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
mysetup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    if [ -z "$TESTSRC" ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        TESTSRC=.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    for ii in . $TESTSRC $TESTSRC/.. ; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if [ -r "$ii/ShellScaffold.sh" ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            . $ii/ShellScaffold.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
# You could replace this next line with the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
# of ShellScaffold.sh and this script will run just the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
mysetup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
runit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
jdbFailIfPresent '""'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
jdbFailIfPresent 'instance of'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
jdbFailIfPresent 'xyzxyz'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
pass