Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001a.java
41162 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.ArrayReference.SetValues;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;3031public class setvalues001a {3233// name of the static field with the tested array object34public static final String ARRAY_FIELD_NAME = "array";3536// length, first index and number of array components to get37public static final int ARRAY_LENGTH = 16;38public static final int ARRAY_FIRST_INDEX = 4;39public static final int ARRAY_ITEMS_COUNT = 10;4041private static ArgumentHandler argumentHandler = null;42private static Log log = null;4344public static void main(String args[]) {45setvalues001a _setvalues001a = new setvalues001a();46System.exit(setvalues001.JCK_STATUS_BASE + _setvalues001a.runIt(args, System.err));47}4849public int runIt(String args[], PrintStream out) {50//make log for debugee messages51argumentHandler = new ArgumentHandler(args);52log = new Log(out, argumentHandler);5354// meke communication pipe to debugger55log.display("Creating pipe");56IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);5758// ensure tested class loaded59log.display("Creating and initializing tested array");60TestedClass.initArrayValues();6162// send debugger signal READY63log.display("Sending signal to debugger: " + setvalues001.READY);64pipe.println(setvalues001.READY);6566// wait for signal RUN from debugeer67log.display("Waiting for signal from debugger: " + setvalues001.RUN);68String signal = pipe.readln();69log.display("Received signal from debugger: " + signal);70// check received signal71if (signal == null || !signal.equals(setvalues001.RUN)) {72log.complain("Unexpected communication signal from debugee: " + signal73+ " (expected: " + setvalues001.RUN + ")");74log.display("Debugee FAILED");75return setvalues001.FAILED;76}7778// check assigned values79log.display("Checking new array values");80if (TestedClass.checkArrayValues()) {81log.display("Sending signal to debugger: " + setvalues001.DONE);82pipe.println(setvalues001.DONE);83} else {84log.display("Sending signal to debugger: " + setvalues001.ERROR);85pipe.println(setvalues001.ERROR);86}8788// wait for signal QUIT from debugeer89log.display("Waiting for signal from debugger: " + setvalues001.QUIT);90signal = pipe.readln();91log.display("Received signal from debugger: " + signal);9293// check received signal94if (! signal.equals(setvalues001.QUIT)) {95log.complain("Unexpected communication signal from debugee: " + signal96+ " (expected: " + setvalues001.QUIT + ")");97log.display("Debugee FAILED");98return setvalues001.FAILED;99}100101// exit debugee102log.display("Debugee PASSED");103return setvalues001.PASSED;104}105106// tested class with own static fields values107public static class TestedClass {108109// static field with tested array110public static int array[] = null;111112public static void initArrayValues() {113array = new int[ARRAY_LENGTH];114for (int i = 0; i < ARRAY_LENGTH; i++) {115array[i] = i * 10;116}117}118119public static boolean checkArrayValues() {120if (array == null) {121log.complain("Checked array == null after setting values: " + array);122return false;123}124125boolean success = true;126if (array.length != ARRAY_LENGTH) {127log.complain("Unexpected array length after setting values: "128+ array.length + " (expected: " + ARRAY_LENGTH + ")");129success = false;130}131132for (int i = 0; i < array.length; i++) {133int initial = i * 10;134int changed = i * 100 + 1;135if (i < ARRAY_FIRST_INDEX || i >= ARRAY_FIRST_INDEX + ARRAY_ITEMS_COUNT) {136log.display(" " + i + " (not changed): " + initial + " -> " + array[i]);137if (array[i] != initial) {138log.complain("Changed value of " + i + " component which is out of changed region: "139+ array[i] + "(initial: " + initial + ")");140success = false;141}142} else {143log.display(" " + i + " (changed): " + initial + " -> " + array[i]);144if (array[i] != changed) {145if (array[i] == initial) {146log.complain("Value of " + i + " component not changed: "147+ array[i] + "(expected: " + changed + ")");148success = false;149} else {150log.complain("Value of " + i + " component changed incorrectly: "151+ array[i] + "(expected: " + changed + ")");152success = false;153}154}155}156}157158return success;159}160161}162}163164165