1 /*
   2  * Copyright (c) 2015, 2017, 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             if (mode == FINGERPRINT_MODE) {
  59                 // fingerprint mode -- no need to use the "loader:" option.
  60                 int id = i + 2;
  61                 cust_list[i] = cust_classes[i] + " id: " + id + " super: " + super_id + " source: " + customJarPath;
  62             } else {
  63                 throw new RuntimeException("Only FINGERPRINT_MODE is supported");
  64             }
  65         }
  66 
  67         String app_list[];
  68         String mainClass;
  69         String appJar;
  70 
  71         if (mode == FINGERPRINT_MODE) {
  72             appJar = JarBuilder.build("parallel_fp",
  73                                       "ParallelLoad",
  74                                       "ParallelLoadThread",
  75                                       "ParallelLoadWatchdog");
  76             app_list = new String[] {
  77                 "java/lang/Object id: 1",
  78                 "ParallelLoad",
  79                 "ParallelLoadThread",
  80                 "ParallelLoadWatchdog"
  81             };
  82             mainClass = "ParallelLoad";
  83         } else {
  84             throw new RuntimeException("Currently only FINGERPRINT_MODE is supported");
  85         }
  86 
  87         OutputAnalyzer output;
  88         TestCommon.testDump(appJar, TestCommon.concat(app_list, cust_list));
  89 
  90         String loaderTypeArg = (loaderType == SINGLE_CUSTOM_LOADER) ? "SINGLE_CUSTOM_LOADER" : "MULTI_CUSTOM_LOADER";
  91         String modeArg = "FINGERPRINT_MODE";
  92 
  93         output = TestCommon.exec(appJar,
  94                                  // command-line arguments ...
  95                                  "--add-opens=java.base/java.security=ALL-UNNAMED",
  96                                  mainClass, loaderTypeArg, modeArg, customJarPath);
  97         TestCommon.checkExec(output);
  98     }
  99 }