Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Accessible/modifiers/modifiers001.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*/2223package nsk.jdi.Accessible.modifiers;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import java.util.*;31import java.io.*;3233/**34* The modifiers001 test checks the method <code>modifiers()</code>35* of the JDI interface <code>Accessible</code> of com.sun.jdi package36* for ClassType, InterfaceType37*/3839public class modifiers001 extends Log {40static java.io.PrintStream out_stream;41static boolean verbose_mode = false;4243/** The main class names of the debugger & debugee applications. */44private final static String45package_prefix = "nsk.jdi.Accessible.modifiers.",46// package_prefix = "", // for DEBUG without package47thisClassName = package_prefix + "modifiers001",48debugeeName = thisClassName + "a";495051static ArgumentHandler argsHandler;52private static Log logHandler;535455/** Debugee's classes for check **/56private final static String classes_for_check[][] = {5758{"java.lang.Boolean" , "public, final", "class"},59{"java.lang.Byte" , "public, final", "class"},60{"java.lang.Character", "public, final", "class"},61{"java.lang.Double" , "public, final", "class"},62{"java.lang.Float" , "public, final", "class"},63{"java.lang.Integer" , "public, final", "class"},64{"java.lang.Long" , "public, final", "class"},65{"java.lang.String" , "public, final", "class"},66{"java.lang.Object" , "public ", "class"},6768{thisClassName, "public", "class"},69{thisClassName+"a", "public", "class"},7071{debugeeName+"$fin_s_cls", "final, static", "class"},72{debugeeName+"$abs_s_cls", "abstract, static", "class"},73{debugeeName+"$s_interf", "abstract, static, interface", "interface"},7475{package_prefix + "simple_class", "<no modifiers>", "class"},76{package_prefix + "abstract_class", "abstract", "class"},77{package_prefix + "final_class", "final", "class"},78{package_prefix + "interf", "abstract, interface", "interface"}79};8081/**82* Re-call to <code>run(args,out)</code>, and exit with83* either status 95 or 97 (JCK-like exit status).84*/85public static void main (String argv[]) {86int exitCode = run(argv,System.out);87System.exit(exitCode + 95/*STATUS_TEMP*/);88}8990/**91* JCK-like entry point to the test: perform testing, and92* return exit code 0 (PASSED) or either 2 (FAILED).93*/94public static int run (String argv[], PrintStream out) {95out_stream = out;9697int v_test_result = new modifiers001().runThis(argv,out_stream);98if ( v_test_result == 2/*STATUS_FAILED*/ ) {99logHandler.complain("\n==> nsk/jdi/Accessible/modifiers/modifiers001 test FAILED");100}101else {102logHandler.display("\n==> nsk/jdi/Accessible/modifiers/modifiers001 test PASSED");103}104return v_test_result;105}106107private void print_log_on_verbose(String message) {108logHandler.display(message);109}110111/**112* Non-static variant of the method <code>run(args,out)</code>113*/114private int runThis (String argv[], PrintStream out) {115if ( out_stream == null ) {116out_stream = out;117}118119120Debugee debugee;121122argsHandler = new ArgumentHandler(argv);123logHandler = new Log(out, argsHandler);124Binder binder = new Binder(argsHandler, logHandler);125126127if (argsHandler.verbose()) {128debugee = binder.bindToDebugee(debugeeName + " -vbs");129} else {130debugee = binder.bindToDebugee(debugeeName);131}132133IOPipe pipe = new IOPipe(debugee);134135136logHandler.display("==> nsk/jdi/Accessible/modifiers/modifiers001 test LOG:");137logHandler.display("==> test checks the modifiers() method of Accessible interface");138logHandler.display(" of the com.sun.jdi package for ClassType, InterfaceType\n");139140141debugee.redirectStderr(out);142print_log_on_verbose("--> modifiers001: modifiers001a debugee launched");143debugee.resume();144145String line = pipe.readln();146if (line == null) {147logHandler.complain148("##> modifiers001: UNEXPECTED debugee's signal (not \"ready\") - " + line);149return 2/*STATUS_FAILED*/;150}151if (!line.equals("ready")) {152logHandler.complain153("##> modifiers001: UNEXPECTED debugee's signal (not \"ready\") - " + line);154return 2/*STATUS_FAILED*/;155}156else {157print_log_on_verbose("--> modifiers001: debugee's \"ready\" signal recieved!");158}159160logHandler.display161("--> modifiers001: checking debugee's classes by Accessible.modifiers() method...\n");162int all_classes_count = 0;163int class_not_found_errors = 0;164int class_not_found_exceptions = 0;165int modifiers_method_errors = 0;166// modifiers001a obj = new modifiers001a();167for (int i=0; i<classes_for_check.length; i++) {168String className = classes_for_check[i][0];169all_classes_count++;170ReferenceType refType = debugee.classByName(className);171if (refType == null) {172logHandler.complain("##> isPublic001: Could NOT FIND class: " + className);173class_not_found_errors++;174continue;175}176Class class_obj;177try {178class_obj = Class.forName(className);179}180catch (ClassNotFoundException e) {181logHandler.complain182("##> modifiers001: Class.forName("+className+") - "+e.toString());183class_not_found_exceptions++;184continue;185}186int expected_modifiers = class_obj.getModifiers();187String s_type = classes_for_check[i][2];188String s_modifiers = classes_for_check[i][1];189int got_modifiers = refType.modifiers();190// Class.getModifiers() will never return ACC_SUPER191// but Accessible.modifers() can, so ignore this bit192got_modifiers &= ~0x20; // 0x20 == ACC_SUPER193logHandler.display("");194if ( got_modifiers != expected_modifiers ) {195logHandler.complain("##> modifiers001: UNEXPECTED modifiers() method result ("196+ "0x" + Integer.toHexString(got_modifiers) + ") for " + s_type + ": " + className197+ "(" + s_modifiers + ")");198logHandler.complain("##> expected modifiers() method result = "199+ "0x" + Integer.toHexString(expected_modifiers));200modifiers_method_errors++;201}202else {203print_log_on_verbose("--> modifiers001: expected modifiers() method result ("204+ "0x" + Integer.toHexString(got_modifiers) + ") for " + s_type + ": " + className205+ "(" + s_modifiers + ")");206}207}208logHandler.display209("--> modifiers001: checking debugee's classes completed!");210logHandler.display211("--> modifiers001: number of checked classes = " + all_classes_count);212if ( class_not_found_errors > 0 ) {213logHandler.complain("##> modifiers001: \"class not found ERRORS\" counter = "214+ class_not_found_errors);215}216if ( class_not_found_exceptions > 0 ) {217logHandler.complain("##> modifiers001: \"class not found EXCEPTIONS\" counter = "218+ class_not_found_exceptions);219}220logHandler.display("##> modifiers001: modifiers() method ERRORS counter = "221+ modifiers_method_errors);222int v_test_result = 0/*STATUS_PASSED*/;223if (class_not_found_errors + class_not_found_exceptions + modifiers_method_errors > 0) {224v_test_result = 2/*STATUS_FAILED*/;225}226227print_log_on_verbose("--> modifiers001: waiting for debugee finish...");228pipe.println("quit");229debugee.waitFor();230231int status = debugee.getStatus();232if (status != 0/*STATUS_PASSED*/ + 95/*STATUS_TEMP*/) {233logHandler.complain234("##> modifiers001: UNEXPECTED Debugee's exit status (not 95) - " + status);235v_test_result = 2/*STATUS_FAILED*/;236}237else {238print_log_on_verbose239("--> modifiers001: expected Debugee's exit status - " + status);240}241242return v_test_result;243}244}245246247