1 /*
2  * Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 
25 /*
26  * @test
27  *
28  * @summary converted from VM Testbase nsk/jdb/options/connect/connect001.
29  * VM Testbase keywords: [quick, jpda, jdb]
30  * VM Testbase readme:
31  * DESCRIPTION
32  *  This is a test for '-connect' option with 'com.sun.jdi.CommandLineLaunch"
33  *  connector.
34  *  Jdb is started with particular connector argument.
35  *  The 'run' command is issued in the superclass of test driver class.
36  *  The test is passed if "run nsk.jdb.options.connect.connect001a" string
37  *  is found in jdb's output stream:
38  *  The test consists of two parts:
39  *   connect001.java  - test driver, i.e. launches jdb and debuggee,
40  *                  writes commands to jdb, reads the jdb output,
41  *   connect001a.java - the debugged application.
42  * COMMENTS
43  *  The test is similar to nsk/jdb/run/run002, but uses particular connector
44  *  overriding settings in ini-file.
45  *
46  * @library /vmTestbase
47  *          /test/lib
48  * @build nsk.jdb.options.connect.connect001.connect001
49  *        nsk.jdb.options.connect.connect001.connect001a
50  * @run main/othervm PropertyResolvingWrapper nsk.jdb.options.connect.connect001.connect001
51  *      -arch=${os.family}-${os.simpleArch}
52  *      -waittime=5
53  *      -debugee.vmkind=java
54  *      -transport.address=dynamic
55  *      -connector=launching
56  *      -transport=default
57  *      -jdb=${test.jdk}/bin/jdb
58  *      -java.options="${test.vm.opts} ${test.java.opts}"
59  *      -workdir=.
60  *      -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
61  */
62 
63 package nsk.jdb.options.connect.connect001;
64 
65 import nsk.share.*;
66 import nsk.share.jdb.*;
67 
68 import java.io.*;
69 import java.util.*;
70 
71 public class connect001 extends JdbTest {
72 
main(String argv[])73     public static void main (String argv[]) {
74         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
75     }
76 
run(String argv[], PrintStream out)77     public static int run(String argv[], PrintStream out) {
78         debuggeeClass =  DEBUGGEE_CLASS;
79         firstBreak = FIRST_BREAK;
80         lastBreak = LAST_BREAK;
81         return new connect001().runTest(argv, out);
82     }
83 
84     static final String PACKAGE_NAME = "nsk.jdb.options.connect.connect001";
85     static final String TEST_CLASS = PACKAGE_NAME + ".connect001";
86     static final String DEBUGGEE_CLASS = TEST_CLASS + "a";
87     static final String FIRST_BREAK        = DEBUGGEE_CLASS + ".main";
88     static final String LAST_BREAK         = DEBUGGEE_CLASS + ".lastBreak";
89 
shouldPass()90     protected boolean shouldPass() {
91         String feature = "com.sun.jdi.CommandLineLaunch";
92         if (argumentHandler.shouldPass(feature)) {
93             log.println("Test passes because of not implemented feature: " + feature);
94             return true;
95         }
96         return super.shouldPass();
97     }
98 
runCases()99     protected void runCases() {
100         String[] reply;
101         Paragrep grep;
102         int count;
103         Vector v;
104         String found;
105 
106         jdb.contToExit(1);
107 
108         if (argumentHandler.isLaunchingConnector()) {
109             reply = jdb.getTotalReply();
110             grep = new Paragrep(reply);
111             v = new Vector();
112             v.add(JdbCommand.run);
113             v.add(DEBUGGEE_CLASS);
114             if (grep.find(v) != 1) {
115                 failure("jdb failed to run debugged application.");
116             }
117         }
118     }
119 }
120