summaryrefslogtreecommitdiff
path: root/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopTest.java
blob: 49ec7c6584b1040219aaf64316cd846084ad341e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * @author Vitaly A. Provodin
 */

/**
 * Created on 22.02.2005
 */
package org.apache.harmony.jpda.tests.jdwp.ThreadReference;

import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
import org.apache.harmony.jpda.tests.framework.jdwp.Value;
import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;


/**
 * JDWP Unit test for ThreadReference.Stop command.
 */
public class StopTest extends JDWPSyncTestCase {

    static String SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee;";

    @Override
    protected String getDebuggeeClassName() {
        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StopDebuggee";
    }

    /**
     * This testcase exercises ThreadReference.Stop command.
     * <BR>At first the test starts StopDebuggee which runs
     * the tested thread 'TESTED_THREAD'.
     * <BR>After the tested thread starts, the test performs ThreadReference.Stop command
     * for the tested thread and waits for Debuggee message if the tested thread
     * is interrupted with NullPointerException.
     * <BR>If so the test PASSED, otherwise FAILED.
     */
    public void testStop001() {
        logWriter.println("testStop001: STARTED...");
        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        // getting ID of the tested thread
        logWriter.println("testStop001: get threadID to Stop...");
        long threadID =
            debuggeeWrapper.vmMirror.getThreadID(StopDebuggee.TESTED_THREAD);
        logWriter.println("testStop001: ID of the tested thread to Stop = " + threadID);

        long classID =
            debuggeeWrapper.vmMirror.getClassID(SIGNATURE);

        long fieldID =
            debuggeeWrapper.vmMirror.getFieldID(classID, StopDebuggee.FIELD_NAME);

        // getting throwable
        logWriter.println("testStop001: get throwable for Stop command...");
        CommandPacket packet = new CommandPacket(
                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
                JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
        packet.setNextValueAsReferenceTypeID(classID);
        packet.setNextValueAsInt(1);
        packet.setNextValueAsFieldID(fieldID);
        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "ReferenceType::GetValues command");

        int values = reply.getNextValueAsInt();
        if (values != 1) {
            logWriter.println("## testStop001: Unexpected number of values = " + values);
            logWriter.println("## Expected number of values = 1");
            fail("Unexpected number of values: " + values + ", expected: 1");
        }
        Value fieldValue = reply.getNextValueAsValue();
        logWriter.println("testStop001: throwable = " + fieldValue);

        packet = new CommandPacket(
                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
                JDWPCommands.ThreadReferenceCommandSet.StopCommand);
        packet.setNextValueAsThreadID(threadID);
        packet.setNextValueAsObjectID(fieldValue.getLongValue());
        logWriter.println("testStop001: send \"Stop\" command");
        reply = debuggeeWrapper.vmMirror.performCommand(packet);
        checkReplyPacket(reply, "ThreadReference::Stop command");

        logWriter.println("testStop001: wait for Debuggee message about test status...");
        String testStatus = synchronizer.receiveMessage();
        logWriter.println("testStop001: Received from Debuggee test status = " + testStatus);
        if ( ! testStatus.equals("PASSED") ) {
            logWriter.println("## testStop001: FAILED");
            fail("Bad message received from debuggee: " + testStatus);
        } else {
            logWriter.println("testStop001: PASSED");
        }
    }
}