Path: blob/master/test/functional/cmdline_options_tester/src/MainTester.java
6004 views
/*******************************************************************************1* Copyright (c) 2004, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122import com.oti.j9.exclude.ExcludeList;2324/**25* This is the entry point for the command-line testing application. It is not meant to be26* initialized; simply run.27*/28public class MainTester {29/**30* The main method parses the arguments and checks them for validity. If they are not valid,31* it displays usage information and exits. If they are valid, the command-line testing32* application is initialized with the given configuration settings and run.33* @param args Command-line arguments34*/35public static void main( String[] args ) {36// variables to read arguments into37String configFile = null;38String excludeFile = null;39String excludes = null;40boolean explain = false;41boolean debugCmdOnTimeout = true;42String platforms = null;43boolean verbose = false;44boolean nonZeroExitCodeWhenError = false;45String outputLimitString = null;46String modeHints = null;47int outputLimit = -1;4849for (int i = 0; i < args.length; i++) {50if (args[i].equalsIgnoreCase("-explainExcludes")) {51explain = true;52} else if (args[i].equalsIgnoreCase("-verbose")) {53verbose = true;54} else if (args[i].equalsIgnoreCase("-nonZeroExitWhenError")) {55nonZeroExitCodeWhenError = true;56} else if (args[i].equalsIgnoreCase("-disableDebugOnTimeout")) {57debugCmdOnTimeout = false;58} else if (i < args.length - 1) {59if (args[i].equalsIgnoreCase("-config")) {60configFile = args[++i];61} else if (args[i].equalsIgnoreCase("-xlist")) {62excludeFile = args[++i];63} else if (args[i].equalsIgnoreCase("-xids")) {64excludes = args[++i];65} else if (args[i].equalsIgnoreCase("-plats")) {66platforms = args[++i];67} else if (args[i].equalsIgnoreCase("-outputLimit")) {68outputLimitString = args[++i];69}70}71}7273if (configFile == null) {74// error75System.out.println( "ERROR: The required -config parameter was not found\n" );76displayHelp();77return;78}7980if (null != outputLimitString) {81try {82outputLimit = Integer.parseInt(outputLimitString);83} catch(NumberFormatException e) {84System.out.println("ERROR: Invalid -outputLimit value : " + outputLimitString +", integer is expected");85displayHelp();86return;87}88}8990// all good - set up and run the suite91if (excludes == null) {92excludes = "";93}94ExcludeList excludeList = null;95if (excludeFile != null) {96excludeList = ExcludeList.readFrom( excludeFile, excludes );97if (explain) {98excludeList.explain( System.out );99}100}101modeHints = (String)System.getProperties().get("MODE_HINTS");102TestConfigParser parser = new TestConfigParser();103parser.setVerbose( verbose );104parser.setOutputLimit(outputLimit);105TestSuite suite = parser.runTests( configFile, excludeList, platforms, debugCmdOnTimeout, modeHints);106suite.printResults();107/* If there were test failures exit with a non-zero return code to force an error in the makefiles.108* Otherwise just die naturally.109*/110if ((true == nonZeroExitCodeWhenError) && (0 < suite.getFailureCount())) {111System.exit(2);112}113}114115/**116* Display usage information.117*/118private static void displayHelp() {119System.out.println( "Usage: MainTester -config xxx [options]" );120System.out.println( " xxx: The configuration file from which to read test cases" );121System.out.println( "[options]:" );122System.out.println( " -xlist yyy The exclude file from which to read which test cases" );123System.out.println( " are excluded" );124System.out.println( " -xids zzz The comma-delimited list of platforms whose excludes" );125System.out.println( " should be taken into account (if -xlist is specified)" );126System.out.println( " -explainExcludes Print out the details of excluded test cases" );127System.out.println( " Default: disabled" );128System.out.println( " -plats ppp The platforms to enable conditional tests on. Comma-");129System.out.println( " separated values are allowed (e.g. -plats j9win,j9lnx)");130System.out.println( " Default: none; enable only tests with no platform");131System.out.println( " dependency" );132System.out.println( " -outputLimit n Max number of lines to be printed for each test case.");133System.out.println( " By default, all of the output from test case is printed,");134System.out.println( " unless max number of lines specified by this option.");135System.out.println( "Examples:" );136System.out.println( " MainTester -config j2jcmdlineopts.xml -xlist j2jexcludes.xml -xids all,j9lnx" );137System.out.println( " MainTester -config j9.xml" );138System.out.println( " MainTester -config a.xml -xlist b.xml -xids all -plats a,b,c\n" );139System.out.println( " MainTester -config a.xml -xlist b.xml -xids all -plats a,b,c\n -outputLimit 300" );140}141}142143144