Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Interrupt/interrupt001a.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdwp.ThreadReference.Interrupt;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;3031/**32* This class represents debuggee part in the test.33*/34public class interrupt001a {3536// name for the tested thread37public static final String THREAD_NAME = "TestedThreadName";38public static final String FIELD_NAME = "thread";3940public static volatile boolean interrupted = false;4142// notification object to notify debuggee that thread is started43private static Object threadStarting = new Object();44// object which thread will wait for before being interruted45private static Object threadWaiting = new Object();4647// scaffold objects48private static volatile ArgumentHandler argumentHandler = null;49private static volatile Log log = null;5051public static void main(String args[]) {52interrupt001a _interrupt001a = new interrupt001a();53System.exit(interrupt001.JCK_STATUS_BASE + _interrupt001a.runIt(args, System.err));54}5556public int runIt(String args[], PrintStream out) {57//make log for debugee messages58argumentHandler = new ArgumentHandler(args);59log = new Log(out, argumentHandler);60long timeout = argumentHandler.getWaitTime() * 60 * 1000; // milliseconds6162// make communication pipe to debugger63log.display("Creating pipe");64IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6566// load tested class and create tested thread67log.display("Creating object of tested class");68TestedClass.thread = new TestedClass(THREAD_NAME);6970// start the thread and wait for notification from it71synchronized (threadStarting) {72TestedClass.thread.start();73try {74threadStarting.wait();75} catch (InterruptedException e) {76log.complain("Interruption while waiting for thread started:\n\t" + e);77pipe.println(interrupt001.ERROR);78log.display("Debugee FAILED");79return interrupt001.FAILED;80}8182// send debugger signal READY83log.display("Sending signal to debugger: " + interrupt001.READY);84pipe.println(interrupt001.READY);85}8687// wait for signal RUN from debugeer88log.display("Waiting for signal from debugger: " + interrupt001.RUN);89String signal = pipe.readln();90log.display("Received signal from debugger: " + signal);9192// check received signal93if (signal == null || !signal.equals(interrupt001.RUN)) {94log.complain("Unexpected communication signal from debugee: " + signal95+ " (expected: " + interrupt001.RUN + ")");96log.display("Debugee FAILED");97return interrupt001.FAILED;98}99100// wait for thread finished in a waittime interval101if (TestedClass.thread.isAlive()) {102log.display("Waiting for tested thread finished for timeout: " + timeout);103try {104TestedClass.thread.join(timeout);105} catch (InterruptedException e) {106log.complain("Interruption while waiting for tested thread finished:\n\t" + e);107pipe.println(interrupt001.ERROR);108log.display("Debugee FAILED");109return interrupt001.FAILED;110}111}112113// test if thread was interrupted by debugger114if (interrupt001a.interrupted) {115log.display("Sending signal to debugger: " + interrupt001.INTERRUPTED_TRUE);116pipe.println(interrupt001.INTERRUPTED_TRUE);117} else {118log.display("Sending signal to debugger: " + interrupt001.INTERRUPTED_FALSE);119pipe.println(interrupt001.INTERRUPTED_FALSE);120}121122// wait for signal QUIT from debugeer123log.display("Waiting for signal from debugger: " + interrupt001.QUIT);124signal = pipe.readln();125log.display("Received signal from debugger: " + signal);126127// check received signal128if (signal == null || !signal.equals(interrupt001.QUIT)) {129log.complain("Unexpected communication signal from debugee: " + signal130+ " (expected: " + interrupt001.QUIT + ")");131log.display("Debugee FAILED");132return interrupt001.FAILED;133}134135// exit debugee136log.display("Debugee PASSED");137return interrupt001.PASSED;138}139140// tested thread class141public static class TestedClass extends Thread {142143// field with the tested Thread value144public static volatile TestedClass thread = null;145146TestedClass(String name) {147super(name);148}149150// start the thread and recursive invoke makeFrames()151public void run() {152log.display("Tested thread started");153154synchronized (threadWaiting) {155156// notify debuggee that thread started157synchronized (threadStarting) {158threadStarting.notifyAll();159}160161// wait infinitely for notification object162try {163threadWaiting.wait();164log.complain("Tested thread NOT interrupted");165} catch (InterruptedException e) {166log.display("Tested thread interrupted");167interrupt001a.interrupted = true;168}169}170171log.display("Tested thread finished");172}173174}175176}177178179