1 /*
  2  * Copyright (c) 2015, 2019, 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 import jdk.test.lib.process.OutputAnalyzer;
 26 
 27 /*
 28  * This is a base class for the following test cases:
 29  *   ParallelTestMultiFP.java
 30  *   ParallelTestSingleFP.java
 31  */
 32 public class ParallelTestBase {
 33     public static final int MAX_CLASSES = 40; // must match ../test-classes/ParallelLoad.java
 34     public static int NUM_THREADS = 4;        // must match ../test-classes/ParallelLoad.java
 35 
 36     public static final int SINGLE_CUSTOM_LOADER = 1;
 37     public static final int MULTI_CUSTOM_LOADER  = 2;
 38 
 39     public static final int FINGERPRINT_MODE = 1;
 40 
 41     public static void run(String[] args, int loaderType, int mode) throws Exception {
 42         String[] cust_classes = new String[MAX_CLASSES];
 43         String[] cust_list;
 44 
 45         if (mode == FINGERPRINT_MODE) {
 46             cust_list = new String[MAX_CLASSES];
 47         } else {
 48             cust_list = new String[MAX_CLASSES * NUM_THREADS];
 49         }
 50 
 51         for (int i = 0; i<MAX_CLASSES; i++) {
 52             cust_classes[i] = "ParallelClass" + i;
 53         }
 54         String customJarPath = JarBuilder.build("ParallelTestBase", cust_classes);
 55 
 56         for (int i = 0, n=0; i<MAX_CLASSES; i++) {
 57             int super_id = 1;
 58             int identity_object_interf_id = 2;
 59             if (mode == FINGERPRINT_MODE) {
 60                 // fingerprint mode -- no need to use the "loader:" option.
 61                 int id = i + 3;
 62                 cust_list[i] = cust_classes[i] + " id: " + id + " super: " + super_id + " interfaces: " + identity_object_interf_id + " source: " + customJarPath;
 63             } else {
 64                 throw new RuntimeException("Only FINGERPRINT_MODE is supported");
 65             }
 66         }
 67 
 68         String app_list[];
 69         String mainClass;
 70         String appJar;
 71 
 72         if (mode == FINGERPRINT_MODE) {
 73             appJar = JarBuilder.build("parallel_fp",
 74                                       "ParallelLoad",
 75                                       "ParallelLoadThread",
 76                                       "ParallelLoadWatchdog");
 77             app_list = new String[] {
 78                 "java/lang/Object id: 1",
 79                 "java/lang/IdentityObject id: 2",
 80                 "ParallelLoad",
 81                 "ParallelLoadThread",
 82                 "ParallelLoadWatchdog"
 83             };
 84             mainClass = "ParallelLoad";
 85         } else {
 86             throw new RuntimeException("Currently only FINGERPRINT_MODE is supported");
 87         }
 88 
 89         OutputAnalyzer output;
 90         TestCommon.testDump(appJar, TestCommon.concat(app_list, cust_list));
 91 
 92         String loaderTypeArg = (loaderType == SINGLE_CUSTOM_LOADER) ? "SINGLE_CUSTOM_LOADER" : "MULTI_CUSTOM_LOADER";
 93         String modeArg = "FINGERPRINT_MODE";
 94 
 95         output = TestCommon.exec(appJar,
 96                                  // command-line arguments ...
 97                                  "--add-opens=java.base/java.security=ALL-UNNAMED",
 98                                  mainClass, loaderTypeArg, modeArg, customJarPath);
 99         TestCommon.checkExec(output);
100     }
101 }