Skip to content

Commit ec71e34

Browse files
committed
8216532: tools/launcher/Test7029048.java fails (Solaris)
Backport-of: be44ced
1 parent 8434e33 commit ec71e34

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

test/jdk/tools/launcher/Test7029048.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,16 +24,12 @@
2424
/*
2525
* @test
2626
* @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
2829
* @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java
2930
* @run main Test7029048
3031
*/
3132

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-
*/
3733
import java.io.File;
3834
import java.io.IOException;
3935
import java.nio.file.Files;
@@ -67,7 +63,6 @@ public class Test7029048 extends TestHelper {
6763

6864
private static final Map<String, String> env = new HashMap<>();
6965

70-
7166
static String getValue(String name, List<String> in) {
7267
for (String x : in) {
7368
String[] s = x.split("=");
@@ -99,37 +94,34 @@ static void analyze(TestResult tr, int nLLPComponents, String caseID) {
9994
* print a "null" string.
10095
*/
10196
if (envValue == null) {
102-
System.out.println(tr);
10397
throw new RuntimeException("NPE, likely a program crash ??");
10498
}
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");
108103
passes++;
109104
} else {
110105
System.out.println("FAIL: test7029048, " + caseID);
111106
System.out.println(" expected " + nLLPComponents
112-
+ " but got " + values.length);
107+
+ " but got " + len);
113108
System.out.println(envValue);
114-
System.out.println(tr);
115109
errors++;
116110
}
117111
}
118112

119113
/*
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.
126118
*/
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
131123
private final int value;
132-
LLP_VAR(int i) {
124+
TestCase(int i) {
133125
this.value = i;
134126
}
135127
}
@@ -139,16 +131,16 @@ private static enum LLP_VAR {
139131
*/
140132
static void test7029048() throws IOException {
141133
String desc = null;
142-
for (LLP_VAR v : LLP_VAR.values()) {
134+
for (TestCase v : TestCase.values()) {
143135
switch (v) {
144-
case LLP_SET_WITH_JVM:
136+
case LIBJVM:
145137
// copy the files into the directory structures
146138
copyFile(srcLibjvmSo, dstServerLibjvm);
147139
// does not matter if it is client or a server
148140
copyFile(srcLibjvmSo, dstClientLibjvm);
149141
desc = "LD_LIBRARY_PATH should be set";
150142
break;
151-
case LLP_SET_EMPTY_PATH:
143+
case NO_LIBJVM:
152144
if (!dstClientDir.exists()) {
153145
Files.createDirectories(dstClientDir.toPath());
154146
} else {
@@ -161,13 +153,13 @@ static void test7029048() throws IOException {
161153
Files.deleteIfExists(dstServerLibjvm.toPath());
162154
}
163155

164-
desc = "LD_LIBRARY_PATH should not be set";
156+
desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)";
165157
break;
166-
case LLP_SET_NON_EXISTENT_PATH:
158+
case NO_DIR:
167159
if (dstLibDir.exists()) {
168160
recursiveDelete(dstLibDir);
169161
}
170-
desc = "LD_LIBRARY_PATH should not be set";
162+
desc = "LD_LIBRARY_PATH should not be set (no directory)";
171163
break;
172164
default:
173165
throw new RuntimeException("unknown case");
@@ -178,14 +170,18 @@ static void test7029048() throws IOException {
178170
*/
179171
env.clear();
180172
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);
182176

183177
/*
184178
* Case 2: repeat with client path
185179
*/
186180
env.clear();
187181
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);
189185

190186
if (isSolaris) {
191187
/*
@@ -194,7 +190,10 @@ static void test7029048() throws IOException {
194190
*/
195191
env.clear();
196192
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);
198197
}
199198
}
200199
return;
@@ -227,4 +226,5 @@ public static void main(String... args) throws Exception {
227226
System.out.println("Test7029048: PASS " + passes);
228227
}
229228
}
229+
230230
}

0 commit comments

Comments
 (0)