Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/equals/equals005.java
41161 views
/*1* Copyright (c) 2000, 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*/222324package nsk.jdi.Field.equals;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.util.*;32import java.io.*;3334public class equals005 {35private static Log log;36private final static String prefix = "nsk.jdi.Field.equals.";37private final static String className = "equals005";38private final static String debugerName = prefix + className;39private final static String debugeeName = debugerName + "a";4041public static void main(String argv[]) {42System.exit(95 + run(argv, System.out));43}4445public static int run(String argv[], PrintStream out) {46ArgumentHandler argHandler = new ArgumentHandler(argv);47log = new Log(out, argHandler);48Binder binder = new Binder(argHandler, log);49Debugee debugee = binder.bindToDebugee(debugeeName50+ (argHandler.verbose() ? " -verbose" : ""));51IOPipe pipe = new IOPipe(debugee);52boolean testFailed = false;53List fields;5455// Connect with debugee and resume it56debugee.redirectStderr(out);57debugee.resume();58String line = pipe.readln();59if (line == null) {60log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");61return 2;62}63if (!line.equals("ready")) {64log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "65+ line);66return 2;67}68else {69log.display("debuger> debugee's \"ready\" signal recieved.");70}7172// Get all fields from debugee73ReferenceType refType = debugee.classByName(debugeeName);74if (refType == null) {75log.complain("debuger FAILURE> Class " + debugeeName76+ " not found.");77return 2;78}79try {80fields = refType.allFields();81} catch (Exception e) {82log.complain("debuger FAILURE> Can't get fields from class");83log.complain("debuger FAILURE> Exception: " + e);84return 2;85}86int totalFields = fields.size();87if (totalFields < 1) {88log.complain("debuger FAILURE> Total number of fields read "89+ totalFields);90return 2;91}92log.display("debuger> Total fields found: " + totalFields);93Iterator fieldsIterator = fields.iterator();94for (int i = 0; fieldsIterator.hasNext(); i++) {95Field srcField = (Field)fieldsIterator.next();96String name = srcField.name();97Field checkField;98boolean fieldsEqual;99100if (name == null) {101log.complain("debuger FAILURE 1> Name is null for " + i102+ " field");103testFailed = true;104continue;105}106try {107checkField = refType.fieldByName(name);108} catch (Exception e) {109log.complain("debuger FAILURE 2> Can't create field to check "110+ "for field " + name);111testFailed = true;112continue;113}114fieldsEqual = srcField.equals(checkField);115log.display("debuger> Fields " + name + " and " + checkField.name()116+ " compared, result " + fieldsEqual);117if (!fieldsEqual) {118// Fields declared in the same class and mirror the same119// fields are equal120log.complain("debuger FAILURE 3> Same fields with name " + name121+ " are not equal. Expected result: equal.");122testFailed = true;123continue;124}125}126pipe.println("quit");127debugee.waitFor();128int status = debugee.getStatus();129if (testFailed) {130log.complain("debuger FAILURE> TEST FAILED");131return 2;132} else {133if (status == 95) {134log.display("debuger> expected Debugee's exit "135+ "status - " + status);136return 0;137} else {138log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "139+ "status (not 95) - " + status);140return 2;141}142}143}144}145146147