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