1
1
/*
2
- * Copyright (c) 2011, 2017 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2019 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
24
24
/*
25
25
* @test
26
26
* @bug 7029048
27
- * @summary Checks for LD_LIBRARY_PATH on *nixes
27
+ * @summary Ensure that the launcher defends against user settings of the
28
+ * LD_LIBRARY_PATH environment variable on Unixes
28
29
* @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java
29
30
* @run main Test7029048
30
31
*/
31
32
32
- /*
33
- * 7029048: test for LD_LIBRARY_PATH set to different paths which may or
34
- * may not contain a libjvm.so, but we test to ensure that the launcher
35
- * behaves correctly in all cases.
36
- */
37
33
import java .io .File ;
38
34
import java .io .IOException ;
39
35
import java .nio .file .Files ;
@@ -67,7 +63,6 @@ public class Test7029048 extends TestHelper {
67
63
68
64
private static final Map <String , String > env = new HashMap <>();
69
65
70
-
71
66
static String getValue (String name , List <String > in ) {
72
67
for (String x : in ) {
73
68
String [] s = x .split ("=" );
@@ -99,37 +94,34 @@ static void analyze(TestResult tr, int nLLPComponents, String caseID) {
99
94
* print a "null" string.
100
95
*/
101
96
if (envValue == null ) {
102
- System .out .println (tr );
103
97
throw new RuntimeException ("NPE, likely a program crash ??" );
104
98
}
105
- String values [] = envValue .split (File .pathSeparator );
106
- if (values .length == nLLPComponents ) {
107
- System .out .println (caseID + " :OK" );
99
+ int len = (envValue .equals ("null" )
100
+ ? 0 : envValue .split (File .pathSeparator ).length );
101
+ if (len == nLLPComponents ) {
102
+ System .out .println (caseID + ": OK" );
108
103
passes ++;
109
104
} else {
110
105
System .out .println ("FAIL: test7029048, " + caseID );
111
106
System .out .println (" expected " + nLLPComponents
112
- + " but got " + values . length );
107
+ + " but got " + len );
113
108
System .out .println (envValue );
114
- System .out .println (tr );
115
109
errors ++;
116
110
}
117
111
}
118
112
119
113
/*
120
- * A crucial piece, specifies what we should expect, given the conditions.
121
- * That is for a given enum type, the value indicates how many absolute
122
- * environment variables that can be expected. This value is used to base
123
- * the actual expected values by adding the set environment variable usually
124
- * it is 1, but it could be more if the test wishes to set more paths in
125
- * the future.
114
+ * Describe the cases that we test. Each case sets the environment
115
+ * variable LD_LIBRARY_PATH to a different value. The value associated
116
+ * with a case is the number of path elements that we expect the launcher
117
+ * to add to that variable.
126
118
*/
127
- private static enum LLP_VAR {
128
- LLP_SET_NON_EXISTENT_PATH (0 ), // env set, but the path does not exist
129
- LLP_SET_EMPTY_PATH (0 ), // env set, with a path but no libjvm.so
130
- LLP_SET_WITH_JVM (3 ); // env set , with a libjvm.so
119
+ private static enum TestCase {
120
+ NO_DIR (0 ), // Directory does not exist
121
+ NO_LIBJVM (0 ), // Directory exists, but no libjvm.so
122
+ LIBJVM (3 ); // Directory exists , with a libjvm.so
131
123
private final int value ;
132
- LLP_VAR (int i ) {
124
+ TestCase (int i ) {
133
125
this .value = i ;
134
126
}
135
127
}
@@ -139,16 +131,16 @@ private static enum LLP_VAR {
139
131
*/
140
132
static void test7029048 () throws IOException {
141
133
String desc = null ;
142
- for (LLP_VAR v : LLP_VAR .values ()) {
134
+ for (TestCase v : TestCase .values ()) {
143
135
switch (v ) {
144
- case LLP_SET_WITH_JVM :
136
+ case LIBJVM :
145
137
// copy the files into the directory structures
146
138
copyFile (srcLibjvmSo , dstServerLibjvm );
147
139
// does not matter if it is client or a server
148
140
copyFile (srcLibjvmSo , dstClientLibjvm );
149
141
desc = "LD_LIBRARY_PATH should be set" ;
150
142
break ;
151
- case LLP_SET_EMPTY_PATH :
143
+ case NO_LIBJVM :
152
144
if (!dstClientDir .exists ()) {
153
145
Files .createDirectories (dstClientDir .toPath ());
154
146
} else {
@@ -161,13 +153,13 @@ static void test7029048() throws IOException {
161
153
Files .deleteIfExists (dstServerLibjvm .toPath ());
162
154
}
163
155
164
- desc = "LD_LIBRARY_PATH should not be set" ;
156
+ desc = "LD_LIBRARY_PATH should not be set (no libjvm.so) " ;
165
157
break ;
166
- case LLP_SET_NON_EXISTENT_PATH :
158
+ case NO_DIR :
167
159
if (dstLibDir .exists ()) {
168
160
recursiveDelete (dstLibDir );
169
161
}
170
- desc = "LD_LIBRARY_PATH should not be set" ;
162
+ desc = "LD_LIBRARY_PATH should not be set (no directory) " ;
171
163
break ;
172
164
default :
173
165
throw new RuntimeException ("unknown case" );
@@ -178,14 +170,18 @@ static void test7029048() throws IOException {
178
170
*/
179
171
env .clear ();
180
172
env .put (LD_LIBRARY_PATH , dstServerDir .getAbsolutePath ());
181
- run (env , v .value + 1 , "Case 1: " + desc );
173
+ run (env ,
174
+ v .value + 1 , // Add one to account for our setting
175
+ "Case 1: " + desc );
182
176
183
177
/*
184
178
* Case 2: repeat with client path
185
179
*/
186
180
env .clear ();
187
181
env .put (LD_LIBRARY_PATH , dstClientDir .getAbsolutePath ());
188
- run (env , v .value + 1 , "Case 2: " + desc );
182
+ run (env ,
183
+ v .value + 1 , // Add one to account for our setting
184
+ "Case 2: " + desc );
189
185
190
186
if (isSolaris ) {
191
187
/*
@@ -194,7 +190,10 @@ static void test7029048() throws IOException {
194
190
*/
195
191
env .clear ();
196
192
env .put (LD_LIBRARY_PATH_64 , dstServerDir .getAbsolutePath ());
197
- run (env , v .value + 1 , "Case 3: " + desc );
193
+ run (env ,
194
+ v .value , // Do not add one, since we didn't set
195
+ // LD_LIBRARY_PATH here
196
+ "Case 3: " + desc );
198
197
}
199
198
}
200
199
return ;
@@ -227,4 +226,5 @@ public static void main(String... args) throws Exception {
227
226
System .out .println ("Test7029048: PASS " + passes );
228
227
}
229
228
}
229
+
230
230
}
0 commit comments