1/*
2 * Copyright (c) 2001, 2002, 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/**
25 *  @ test:it only runs from SparcToSparcV9Test.sh
26 *  @bug 4478312
27 *  @summary Test debugging with mixed 32/64bit VMs.
28 *
29 *  @author Tim Bell
30 *
31 *  The basic version of this test (32-bit to 32-bit) should pass
32 *  on all platforms.  The SparcToSparcv9Test.sh script uses this
33 *  test to exercise other combinations on SPARC v9 platforms only.
34 *
35 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
36 *  @run compile -g DataModelTest.java
37 *  @run driver DataModelTest
38 */
39import com.sun.jdi.*;
40import com.sun.jdi.event.*;
41import com.sun.jdi.request.*;
42
43import java.util.*;
44
45    /********** target program **********/
46
47class DataModelTarg {
48    static String dataModel;
49    public DataModelTarg () {
50        dataModel = System.getProperty("sun.arch.data.model");
51    }
52    public void ready () {
53        System.out.println("sun.arch.data.model is: " + dataModel);
54    }
55    public static void main(String[] args){
56        System.out.println("Howdy!");
57        DataModelTarg my = new DataModelTarg();
58        my.ready();
59        System.out.println("Goodbye from DataModelTarg!");
60    }
61}
62
63    /********** test program **********/
64
65public class DataModelTest extends TestScaffold {
66
67    DataModelTest (String args[]) {
68        super(args);
69    }
70
71    public static void main(String[] args)      throws Exception {
72        new DataModelTest(args).startTests();
73    }
74
75    protected void runTests() throws Exception {
76        /*
77         * Get to the top of ready()
78         */
79        BreakpointEvent bpe = startTo("DataModelTarg", "ready", "()V");
80
81        ObjectReference targetObject = bpe.thread().frame(0).thisObject();
82        ReferenceType rt = targetObject.referenceType();
83        Field field = rt.fieldByName("dataModel");
84        Value v = targetObject.getValue(field);
85        StringReference sv = (StringReference) v;
86        String expectedValue = System.getProperty("EXPECTED", "32");
87        if (!expectedValue.equals(sv.value())) {
88            failure("Expecting sun.arch.data.model = " + expectedValue +
89                    " but got " + sv.value() + " instead.");
90        }
91        /*
92         * resume the target listening for events
93         */
94        listenUntilVMDisconnect();
95
96        /*
97         * deal with results of test
98         * if anything has called failure("foo") testFailed will be true
99         */
100        if (!testFailed) {
101            println("DataModelTest: passed");
102        } else {
103            throw new Exception("DataModelTest: failed");
104        }
105    }
106}
107