4141
4242public class Test7029048 extends TestHelper {
4343
44- static int passes = 0 ;
45- static int errors = 0 ;
46-
4744 private static final String LIBJVM = ExecutionEnvironment .LIBJVM ;
4845 private static final String LD_LIBRARY_PATH =
4946 ExecutionEnvironment .LD_LIBRARY_PATH ;
@@ -62,8 +59,6 @@ public class Test7029048 extends TestHelper {
6259 private static final File dstClientDir = new File (dstLibDir , "client" );
6360 private static final File dstClientLibjvm = new File (dstClientDir , LIBJVM );
6461
65- private static final Map <String , String > env = new HashMap <>();
66-
6762 static String getValue (String name , List <String > in ) {
6863 for (String x : in ) {
6964 String [] s = x .split ("=" );
@@ -74,8 +69,10 @@ static String getValue(String name, List<String> in) {
7469 return null ;
7570 }
7671
77- static void run (Map <String , String > env ,
78- int nLLPComponents , String caseID ) {
72+ static boolean run (int nLLPComponents , File variantDir , String caseID ) {
73+
74+ Map <String , String > env = new HashMap <>();
75+ env .put (LD_LIBRARY_PATH , variantDir .getAbsolutePath ());
7976 env .put (ExecutionEnvironment .JLDEBUG_KEY , "true" );
8077 List <String > cmdsList = new ArrayList <>();
8178 cmdsList .add (javaCmd );
@@ -85,10 +82,18 @@ static void run(Map<String, String> env,
8582 String [] cmds = new String [cmdsList .size ()];
8683 TestResult tr = doExec (env , cmdsList .toArray (cmds ));
8784 System .out .println (tr );
88- analyze (tr , nLLPComponents , caseID );
85+ int len = getLLPComponents (tr );
86+ if (len == nLLPComponents ) {
87+ System .out .printf ("Test7029048 OK %s%n" , caseID );
88+ return true ;
89+ } else {
90+ System .out .printf ("Test7029048 FAIL %s: expected %d but got %d%n" ,
91+ caseID , nLLPComponents , len );
92+ return false ;
93+ }
8994 }
9095
91- static void analyze (TestResult tr , int nLLPComponents , String caseID ) {
96+ static int getLLPComponents (TestResult tr ) {
9297 String envValue = getValue (LD_LIBRARY_PATH , tr .testOutput );
9398 /*
9499 * the envValue can never be null, since the test code should always
@@ -97,18 +102,12 @@ static void analyze(TestResult tr, int nLLPComponents, String caseID) {
97102 if (envValue == null ) {
98103 throw new RuntimeException ("NPE, likely a program crash ??" );
99104 }
100- int len = (envValue .equals ("null" )
101- ? 0 : envValue .split (File .pathSeparator ).length );
102- if (len == nLLPComponents ) {
103- System .out .println (caseID + ": OK" );
104- passes ++;
105- } else {
106- System .out .println ("FAIL: test7029048, " + caseID );
107- System .out .println (" expected " + nLLPComponents
108- + " but got " + len );
109- System .out .println (envValue );
110- errors ++;
105+
106+ if (envValue .equals ("null" )) {
107+ return 0 ;
111108 }
109+
110+ return envValue .split (File .pathSeparator ).length ;
112111 }
113112
114113 /*
@@ -130,8 +129,9 @@ private static enum TestCase {
130129 /*
131130 * test for 7029048
132131 */
133- static void test7029048 () throws IOException {
132+ static boolean runTest () throws IOException {
134133 String desc = null ;
134+ boolean pass = true ;
135135 for (TestCase v : TestCase .values ()) {
136136 switch (v ) {
137137 case LIBJVM :
@@ -156,8 +156,7 @@ static void test7029048() throws IOException {
156156
157157 desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)" ;
158158 if (TestHelper .isAIX ) {
159- System .out .println ("Skipping test case \" " + desc +
160- "\" because the Aix launcher adds the paths in any case." );
159+ printSkipMessage (desc );
161160 continue ;
162161 }
163162 break ;
@@ -167,34 +166,35 @@ static void test7029048() throws IOException {
167166 }
168167 desc = "LD_LIBRARY_PATH should not be set (no directory)" ;
169168 if (TestHelper .isAIX ) {
170- System .out .println ("Skipping test case \" " + desc +
171- "\" because the Aix launcher adds the paths in any case." );
169+ printSkipMessage (desc );
172170 continue ;
173171 }
174172 break ;
175173 default :
176174 throw new RuntimeException ("unknown case" );
177175 }
178176
177+ // Add one to account for our setting
178+ int nLLPComponents = v .value + 1 ;
179+
179180 /*
180181 * Case 1: set the server path
181182 */
182- env .clear ();
183- env .put (LD_LIBRARY_PATH , dstServerDir .getAbsolutePath ());
184- run (env ,
185- v .value + 1 , // Add one to account for our setting
186- "Case 1: " + desc );
183+ boolean pass1 = run (nLLPComponents , dstServerDir , "Case 1: " + desc );
187184
188185 /*
189186 * Case 2: repeat with client path
190187 */
191- env .clear ();
192- env .put (LD_LIBRARY_PATH , dstClientDir .getAbsolutePath ());
193- run (env ,
194- v .value + 1 , // Add one to account for our setting
195- "Case 2: " + desc );
188+ boolean pass2 = run (nLLPComponents , dstClientDir , "Case 2: " + desc );
189+
190+ pass &= pass1 && pass2 ;
196191 }
197- return ;
192+ return pass ;
193+ }
194+
195+ private static void printSkipMessage (String description ) {
196+ System .out .printf ("Skipping test case '%s' because the Aix launcher" +
197+ " adds the paths in any case.%n" , description );
198198 }
199199
200200 public static void main (String ... args ) throws Exception {
@@ -209,16 +209,8 @@ public static void main(String... args) throws Exception {
209209 // create our test jar first
210210 ExecutionEnvironment .createTestJar ();
211211
212- // run the tests
213- test7029048 ();
214- if (errors > 0 ) {
215- throw new Exception ("Test7029048: FAIL: with "
216- + errors + " errors and passes " + passes );
217- } else if (isLinux && passes < 6 ) {
218- throw new Exception ("Test7029048: FAIL: " +
219- "all tests did not run, expected " + 6 + " got " + passes );
220- } else {
221- System .out .println ("Test7029048: PASS " + passes );
212+ if (!runTest ()) {
213+ throw new Exception ("Test7029048 fails" );
222214 }
223215 }
224216}
0 commit comments