Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
27d8dc3f
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
27d8dc3f
编写于
11月 13, 2013
作者:
Y
ykantser
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
Reviewed-by: sla
上级
332bce5b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
583 addition
and
81 deletion
+583
-81
test/lib/testlibrary/AssertsTest.java
test/lib/testlibrary/AssertsTest.java
+237
-0
test/lib/testlibrary/OutputAnalyzerReportingTest.java
test/lib/testlibrary/OutputAnalyzerReportingTest.java
+122
-0
test/lib/testlibrary/jdk/testlibrary/InputArguments.java
test/lib/testlibrary/jdk/testlibrary/InputArguments.java
+88
-0
test/lib/testlibrary/jdk/testlibrary/JcmdBase.java
test/lib/testlibrary/jdk/testlibrary/JcmdBase.java
+14
-33
test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java
test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java
+115
-42
test/lib/testlibrary/jdk/testlibrary/ProcessTools.java
test/lib/testlibrary/jdk/testlibrary/ProcessTools.java
+7
-5
test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java
...un/management/jmxremote/bootstrap/CustomLauncherTest.java
+0
-1
未找到文件。
test/lib/testlibrary/AssertsTest.java
0 → 100644
浏览文件 @
27d8dc3f
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
static
jdk
.
testlibrary
.
Asserts
.*;
/* @test
* @summary Tests the different assertions in the Assert class
* @library /testlibrary
*/
public
class
AssertsTest
{
private
static
class
Foo
implements
Comparable
<
Foo
>
{
final
int
id
;
public
Foo
(
int
id
)
{
this
.
id
=
id
;
}
public
int
compareTo
(
Foo
f
)
{
return
new
Integer
(
id
).
compareTo
(
new
Integer
(
f
.
id
));
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
testLessThan
();
testLessThanOrEqual
();
testEquals
();
testGreaterThanOrEqual
();
testGreaterThan
();
testNotEquals
();
testNull
();
testNotNull
();
testTrue
();
testFalse
();
}
private
static
void
testLessThan
()
throws
Exception
{
expectPass
(
Assertion
.
LT
,
1
,
2
);
expectFail
(
Assertion
.
LT
,
2
,
2
);
expectFail
(
Assertion
.
LT
,
2
,
1
);
expectFail
(
Assertion
.
LT
,
null
,
2
);
expectFail
(
Assertion
.
LT
,
2
,
null
);
}
private
static
void
testLessThanOrEqual
()
throws
Exception
{
expectPass
(
Assertion
.
LTE
,
1
,
2
);
expectPass
(
Assertion
.
LTE
,
2
,
2
);
expectFail
(
Assertion
.
LTE
,
3
,
2
);
expectFail
(
Assertion
.
LTE
,
null
,
2
);
expectFail
(
Assertion
.
LTE
,
2
,
null
);
}
private
static
void
testEquals
()
throws
Exception
{
expectPass
(
Assertion
.
EQ
,
1
,
1
);
expectPass
(
Assertion
.
EQ
,
null
,
null
);
Foo
f1
=
new
Foo
(
1
);
expectPass
(
Assertion
.
EQ
,
f1
,
f1
);
Foo
f2
=
new
Foo
(
1
);
expectFail
(
Assertion
.
EQ
,
f1
,
f2
);
expectFail
(
Assertion
.
LTE
,
null
,
2
);
expectFail
(
Assertion
.
LTE
,
2
,
null
);
}
private
static
void
testGreaterThanOrEqual
()
throws
Exception
{
expectPass
(
Assertion
.
GTE
,
1
,
1
);
expectPass
(
Assertion
.
GTE
,
2
,
1
);
expectFail
(
Assertion
.
GTE
,
1
,
2
);
expectFail
(
Assertion
.
GTE
,
null
,
2
);
expectFail
(
Assertion
.
GTE
,
2
,
null
);
}
private
static
void
testGreaterThan
()
throws
Exception
{
expectPass
(
Assertion
.
GT
,
2
,
1
);
expectFail
(
Assertion
.
GT
,
1
,
1
);
expectFail
(
Assertion
.
GT
,
1
,
2
);
expectFail
(
Assertion
.
GT
,
null
,
2
);
expectFail
(
Assertion
.
GT
,
2
,
null
);
}
private
static
void
testNotEquals
()
throws
Exception
{
expectPass
(
Assertion
.
NE
,
null
,
1
);
expectPass
(
Assertion
.
NE
,
1
,
null
);
Foo
f1
=
new
Foo
(
1
);
Foo
f2
=
new
Foo
(
1
);
expectPass
(
Assertion
.
NE
,
f1
,
f2
);
expectFail
(
Assertion
.
NE
,
null
,
null
);
expectFail
(
Assertion
.
NE
,
f1
,
f1
);
expectFail
(
Assertion
.
NE
,
1
,
1
);
}
private
static
void
testNull
()
throws
Exception
{
expectPass
(
Assertion
.
NULL
,
null
);
expectFail
(
Assertion
.
NULL
,
1
);
}
private
static
void
testNotNull
()
throws
Exception
{
expectPass
(
Assertion
.
NOTNULL
,
1
);
expectFail
(
Assertion
.
NOTNULL
,
null
);
}
private
static
void
testTrue
()
throws
Exception
{
expectPass
(
Assertion
.
TRUE
,
true
);
expectFail
(
Assertion
.
TRUE
,
false
);
}
private
static
void
testFalse
()
throws
Exception
{
expectPass
(
Assertion
.
FALSE
,
false
);
expectFail
(
Assertion
.
FALSE
,
true
);
}
private
static
<
T
extends
Comparable
<
T
>>
void
expectPass
(
Assertion
assertion
,
T
...
args
)
throws
Exception
{
Assertion
.
run
(
assertion
,
args
);
}
private
static
<
T
extends
Comparable
<
T
>>
void
expectFail
(
Assertion
assertion
,
T
...
args
)
throws
Exception
{
try
{
Assertion
.
run
(
assertion
,
args
);
}
catch
(
RuntimeException
e
)
{
return
;
}
throw
new
Exception
(
"Expected "
+
Assertion
.
format
(
assertion
,
(
Object
[])
args
)
+
" to throw a RuntimeException"
);
}
}
enum
Assertion
{
LT
,
LTE
,
EQ
,
GTE
,
GT
,
NE
,
NULL
,
NOTNULL
,
FALSE
,
TRUE
;
public
static
<
T
extends
Comparable
<
T
>>
void
run
(
Assertion
assertion
,
T
...
args
)
{
String
msg
=
"Expected "
+
format
(
assertion
,
args
)
+
" to pass"
;
switch
(
assertion
)
{
case
LT:
assertLessThan
(
args
[
0
],
args
[
1
],
msg
);
break
;
case
LTE:
assertLessThanOrEqual
(
args
[
0
],
args
[
1
],
msg
);
break
;
case
EQ:
assertEquals
(
args
[
0
],
args
[
1
],
msg
);
break
;
case
GTE:
assertGreaterThanOrEqual
(
args
[
0
],
args
[
1
],
msg
);
break
;
case
GT:
assertGreaterThan
(
args
[
0
],
args
[
1
],
msg
);
break
;
case
NE:
assertNotEquals
(
args
[
0
],
args
[
1
],
msg
);
break
;
case
NULL:
assertNull
(
args
==
null
?
args
:
args
[
0
],
msg
);
break
;
case
NOTNULL:
assertNotNull
(
args
==
null
?
args
:
args
[
0
],
msg
);
break
;
case
FALSE:
assertFalse
((
Boolean
)
args
[
0
],
msg
);
break
;
case
TRUE:
assertTrue
((
Boolean
)
args
[
0
],
msg
);
break
;
default
:
// do nothing
}
}
public
static
String
format
(
Assertion
assertion
,
Object
...
args
)
{
switch
(
assertion
)
{
case
LT:
return
asString
(
"assertLessThan"
,
args
);
case
LTE:
return
asString
(
"assertLessThanOrEqual"
,
args
);
case
EQ:
return
asString
(
"assertEquals"
,
args
);
case
GTE:
return
asString
(
"assertGreaterThanOrEquals"
,
args
);
case
GT:
return
asString
(
"assertGreaterThan"
,
args
);
case
NE:
return
asString
(
"assertNotEquals"
,
args
);
case
NULL:
return
asString
(
"assertNull"
,
args
);
case
NOTNULL:
return
asString
(
"assertNotNull"
,
args
);
case
FALSE:
return
asString
(
"assertFalse"
,
args
);
case
TRUE:
return
asString
(
"assertTrue"
,
args
);
default
:
return
""
;
}
}
private
static
String
asString
(
String
assertion
,
Object
...
args
)
{
if
(
args
==
null
)
{
return
String
.
format
(
"%s(null)"
,
assertion
);
}
if
(
args
.
length
==
1
)
{
return
String
.
format
(
"%s(%s)"
,
assertion
,
args
[
0
]);
}
else
{
return
String
.
format
(
"%s(%s, %s)"
,
assertion
,
args
[
0
],
args
[
1
]);
}
}
}
test/lib/testlibrary/OutputAnalyzerReportingTest.java
0 → 100644
浏览文件 @
27d8dc3f
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @summary Test the OutputAnalyzer reporting functionality,
* such as printing additional diagnostic info
* (exit code, stdout, stderr, command line, etc.)
* @library /testlibrary
*/
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
jdk.testlibrary.OutputAnalyzer
;
public
class
OutputAnalyzerReportingTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Create the output analyzer under test
String
stdout
=
"aaaaaa"
;
String
stderr
=
"bbbbbb"
;
OutputAnalyzer
output
=
new
OutputAnalyzer
(
stdout
,
stderr
);
// Expected summary values should be the same for all cases,
// since the outputAnalyzer object is the same
String
expectedExitValue
=
"-1"
;
String
expectedSummary
=
" stdout: ["
+
stdout
+
"];\n"
+
" stderr: ["
+
stderr
+
"]\n"
+
" exitValue = "
+
expectedExitValue
+
"\n"
;
DiagnosticSummaryTestRunner
testRunner
=
new
DiagnosticSummaryTestRunner
();
// should have exit value
testRunner
.
init
(
expectedSummary
);
int
unexpectedExitValue
=
2
;
try
{
output
.
shouldHaveExitValue
(
unexpectedExitValue
);
}
catch
(
RuntimeException
e
)
{
}
testRunner
.
closeAndCheckResults
();
// should not contain
testRunner
.
init
(
expectedSummary
);
try
{
output
.
shouldNotContain
(
stdout
);
}
catch
(
RuntimeException
e
)
{
}
testRunner
.
closeAndCheckResults
();
// should contain
testRunner
.
init
(
expectedSummary
);
try
{
output
.
shouldContain
(
"unexpected-stuff"
);
}
catch
(
RuntimeException
e
)
{
}
testRunner
.
closeAndCheckResults
();
// should not match
testRunner
.
init
(
expectedSummary
);
try
{
output
.
shouldNotMatch
(
"[a]"
);
}
catch
(
RuntimeException
e
)
{
}
testRunner
.
closeAndCheckResults
();
// should match
testRunner
.
init
(
expectedSummary
);
try
{
output
.
shouldMatch
(
"[qwerty]"
);
}
catch
(
RuntimeException
e
)
{
}
testRunner
.
closeAndCheckResults
();
}
private
static
class
DiagnosticSummaryTestRunner
{
private
ByteArrayOutputStream
byteStream
=
new
ByteArrayOutputStream
(
10000
);
private
String
expectedSummary
=
""
;
private
PrintStream
errStream
;
public
void
init
(
String
expectedSummary
)
{
this
.
expectedSummary
=
expectedSummary
;
byteStream
.
reset
();
errStream
=
new
PrintStream
(
byteStream
);
System
.
setErr
(
errStream
);
}
public
void
closeAndCheckResults
()
{
// check results
errStream
.
close
();
String
stdErrStr
=
byteStream
.
toString
();
if
(!
stdErrStr
.
contains
(
expectedSummary
))
{
throw
new
RuntimeException
(
"The output does not contain "
+
"the diagnostic message, or the message is incorrect"
);
}
}
}
}
test/lib/testlibrary/jdk/testlibrary/
JdkFinder
.java
→
test/lib/testlibrary/jdk/testlibrary/
InputArguments
.java
浏览文件 @
27d8dc3f
...
...
@@ -23,56 +23,66 @@
package
jdk.testlibrary
;
import
java.io.File
;
import
java.lang.management.RuntimeMXBean
;
import
java.lang.management.ManagementFactory
;
import
java.util.List
;
public
final
class
JdkFinder
{
private
JdkFinder
()
{
}
private
static
String
getExecutable
(
String
executable
,
String
property
)
{
String
binPath
=
System
.
getProperty
(
property
);
if
(
binPath
==
null
)
{
throw
new
RuntimeException
(
"System property '"
+
property
+
"' not set"
);
}
binPath
+=
File
.
separatorChar
+
"bin"
+
File
.
separatorChar
+
executable
;
/**
* This class provides access to the input arguments to the VM.
*/
public
class
InputArguments
{
private
static
final
List
<
String
>
args
;
return
binPath
;
static
{
RuntimeMXBean
runtimeMxBean
=
ManagementFactory
.
getRuntimeMXBean
();
args
=
runtimeMxBean
.
getInputArguments
();
}
/**
* Returns the full path to a java launcher in jdk/bin based on system
* property.
* Returns true if {@code arg} is an input argument to the VM.
*
* This is useful for checking boolean flags such as -XX:+UseSerialGC or
* -XX:-UsePerfData.
*
* @param
stableJdk
*
see {@link #getTool(String, boolean)}
*
@return Full path to a java launcher in jdk/bin
.
* @param
arg The name of the argument.
*
@return {@code true} if the given argument is an input argument,
*
otherwise {@code false}
.
*/
public
static
String
getJavaLauncher
(
boolean
stableJdk
)
{
return
getTool
(
"java"
,
stableJdk
);
public
static
boolean
contains
(
String
arg
)
{
return
args
.
contains
(
arg
);
}
/**
* Returns the full path to an executable in jdk/bin based on system
* property. Depending on value of {@code stableJdk} the method will look for
* either 'compile.jdk' or 'test.jdk' system properties.
* 'test.jdk' is normally set by jtreg. When running test separately,
* set this property using '-Dtest.jdk=/path/to/jdk'.
* Returns true if {@code prefix} is the start of an input argument to the
* VM.
*
* @param stableJdk
* If {@code true} the {@code tool} will be retrieved
* from the compile (stable) JDK.
* If {@code false} the {@code tool} will be retrieved
* from the test JDK.
* @return Full path to an executable in jdk/bin.
* This is useful for checking if flags describing a quantity, such as
* -XX:+MaxMetaspaceSize=100m, is set without having to know the quantity.
* To check if the flag -XX:MaxMetaspaceSize is set, use
* {@code InputArguments.containsPrefix("-XX:MaxMetaspaceSize")}.
*
* @param prefix The start of the argument.
* @return {@code true} if the given argument is the start of an input
* argument, otherwise {@code false}.
*/
public
static
String
getTool
(
String
tool
,
boolean
stableJdk
)
{
if
(
stableJdk
)
{
return
getExecutable
(
tool
,
"compile.jdk"
);
}
else
{
return
getExecutable
(
tool
,
"test.jdk"
);
public
static
boolean
containsPrefix
(
String
prefix
)
{
for
(
String
arg
:
args
)
{
if
(
arg
.
startsWith
(
prefix
))
{
return
true
;
}
}
return
false
;
}
/**
* Get the string containing input arguments passed to the VM
*/
public
static
String
getInputArguments
()
{
StringBuilder
result
=
new
StringBuilder
();
for
(
String
arg
:
args
)
result
.
append
(
arg
).
append
(
' '
);
return
result
.
toString
();
}
}
test/lib/testlibrary/jdk/testlibrary/JcmdBase.java
浏览文件 @
27d8dc3f
...
...
@@ -23,8 +23,11 @@
package
jdk.testlibrary
;
import
java.util.Array
List
;
import
java.util.Array
s
;
/**
* Super class for tests which need to attach jcmd to the current process.
*/
public
class
JcmdBase
{
private
static
ProcessBuilder
processBuilder
=
new
ProcessBuilder
();
...
...
@@ -32,46 +35,24 @@ public class JcmdBase {
/**
* Attach jcmd to the current process
*
* @param
command
Args
* jcmd command line parameters, e.g.
JFR.start
* @param
tool
Args
* jcmd command line parameters, e.g.
VM.flags
* @return jcmd output
* @throws Exception
*/
public
final
static
OutputAnalyzer
jcmd
(
String
...
command
Args
)
public
final
static
OutputAnalyzer
jcmd
(
String
...
tool
Args
)
throws
Exception
{
ArrayList
<
String
>
cmd
=
new
ArrayList
<
String
>();
String
cmdString
=
""
;
// jcmd from the jdk to be tested
String
jcmdPath
=
JdkFinder
.
getTool
(
"jcmd"
,
false
);
cmd
.
add
(
jcmdPath
);
cmdString
+=
jcmdPath
;
String
pid
=
Integer
.
toString
(
ProcessTools
.
getProcessId
());
cmd
.
add
(
pid
);
cmdString
+=
" "
+
pid
;
for
(
int
i
=
0
;
i
<
commandArgs
.
length
;
i
++)
{
cmd
.
add
(
commandArgs
[
i
]);
cmdString
+=
" "
+
commandArgs
[
i
];
JDKToolLauncher
launcher
=
JDKToolLauncher
.
createUsingTestJDK
(
"jcmd"
);
launcher
.
addToolArg
(
Integer
.
toString
(
ProcessTools
.
getProcessId
()));
for
(
String
toolArg
:
toolArgs
)
{
launcher
.
addToolArg
(
toolArg
);
}
// Log command line for debugging purpose
System
.
out
.
println
(
"Command line:"
);
System
.
out
.
println
(
cmdString
);
processBuilder
.
command
(
cmd
);
processBuilder
.
command
(
launcher
.
getCommand
());
System
.
out
.
println
(
Arrays
.
toString
(
processBuilder
.
command
().
toArray
()).
replace
(
","
,
""
));
OutputAnalyzer
output
=
new
OutputAnalyzer
(
processBuilder
.
start
());
// Log output for debugging purpose
System
.
out
.
println
(
"Command output:"
);
System
.
out
.
println
(
output
.
getOutput
());
if
(
output
.
getExitValue
()
!=
0
)
{
throw
new
Exception
(
processBuilder
.
command
()
+
" resulted in exit value "
+
output
.
getExitValue
()
+
" , expected to get 0"
);
}
output
.
shouldHaveExitValue
(
0
);
return
output
;
}
...
...
test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java
浏览文件 @
27d8dc3f
...
...
@@ -27,6 +27,9 @@ import java.io.IOException;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* Utility class for verifying output and exit value from a {@code Process}.
*/
public
final
class
OutputAnalyzer
{
private
final
String
stdout
;
...
...
@@ -85,9 +88,9 @@ public final class OutputAnalyzer {
public
void
shouldContain
(
String
expectedString
)
{
if
(!
stdout
.
contains
(
expectedString
)
&&
!
stderr
.
contains
(
expectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
expectedString
+
"' missing from stdout/stderr: ["
+
stdout
+
stderr
+
"]\n"
);
+
"' missing from stdout/stderr \n"
);
}
}
...
...
@@ -101,8 +104,9 @@ public final class OutputAnalyzer {
*/
public
void
stdoutShouldContain
(
String
expectedString
)
{
if
(!
stdout
.
contains
(
expectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
expectedString
+
"' missing from stdout
: ["
+
stdout
+
"]
\n"
);
+
"' missing from stdout
\n"
);
}
}
...
...
@@ -116,8 +120,9 @@ public final class OutputAnalyzer {
*/
public
void
stderrShouldContain
(
String
expectedString
)
{
if
(!
stderr
.
contains
(
expectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
expectedString
+
"' missing from stderr
: ["
+
stderr
+
"]
\n"
);
+
"' missing from stderr
\n"
);
}
}
...
...
@@ -132,12 +137,14 @@ public final class OutputAnalyzer {
*/
public
void
shouldNotContain
(
String
notExpectedString
)
{
if
(
stdout
.
contains
(
notExpectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
notExpectedString
+
"' found in stdout
: ["
+
stdout
+
"]
\n"
);
+
"' found in stdout
\n"
);
}
if
(
stderr
.
contains
(
notExpectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
notExpectedString
+
"' found in stderr
: ["
+
stderr
+
"]
\n"
);
+
"' found in stderr
\n"
);
}
}
...
...
@@ -152,8 +159,9 @@ public final class OutputAnalyzer {
*/
public
void
stdoutShouldNotContain
(
String
notExpectedString
)
{
if
(
stdout
.
contains
(
notExpectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
notExpectedString
+
"' found in stdout
: ["
+
stdout
+
"]
\n"
);
+
"' found in stdout
\n"
);
}
}
...
...
@@ -168,55 +176,63 @@ public final class OutputAnalyzer {
*/
public
void
stderrShouldNotContain
(
String
notExpectedString
)
{
if
(
stderr
.
contains
(
notExpectedString
))
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
notExpectedString
+
"' found in stderr
: ["
+
stderr
+
"]
\n"
);
+
"' found in stderr
\n"
);
}
}
/**
* Verify that the stdout and stderr contents of output buffer matches
*
the
pattern
* Verify that the stdout and stderr contents of output buffer matches
the
* pattern
*
* @param pattern
* @throws RuntimeException If the pattern was not found
* @throws RuntimeException
* If the pattern was not found
*/
public
void
shouldMatch
(
String
pattern
)
{
Matcher
stdoutMatcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
Matcher
stderrMatcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stderr
);
Matcher
stdoutMatcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
)
.
matcher
(
stdout
);
Matcher
stderrMatcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
)
.
matcher
(
stderr
);
if
(!
stdoutMatcher
.
find
()
&&
!
stderrMatcher
.
find
())
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' missing from stdout/stderr: ["
+
stdout
+
stderr
+
"]\n"
);
+
"' missing from stdout/stderr \n"
);
}
}
/**
* Verify that the stdout contents of output buffer matches the
* pattern
* Verify that the stdout contents of output buffer matches the pattern
*
* @param pattern
* @throws RuntimeException If the pattern was not found
* @throws RuntimeException
* If the pattern was not found
*/
public
void
stdoutShouldMatch
(
String
pattern
)
{
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
if
(!
matcher
.
find
())
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' missing from stdout
: ["
+
stdout
+
"]
\n"
);
+
"' missing from stdout
\n"
);
}
}
/**
* Verify that the stderr contents of output buffer matches the
* pattern
* Verify that the stderr contents of output buffer matches the pattern
*
* @param pattern
* @throws RuntimeException If the pattern was not found
* @throws RuntimeException
* If the pattern was not found
*/
public
void
stderrShouldMatch
(
String
pattern
)
{
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stderr
);
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stderr
);
if
(!
matcher
.
find
())
{
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' missing from stderr
: ["
+
stderr
+
"]
\n"
);
+
"' missing from stderr
\n"
);
}
}
...
...
@@ -225,18 +241,22 @@ public final class OutputAnalyzer {
* match the pattern
*
* @param pattern
* @throws RuntimeException If the pattern was found
* @throws RuntimeException
* If the pattern was found
*/
public
void
shouldNotMatch
(
String
pattern
)
{
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
if
(
matcher
.
find
())
{
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stdout: ["
+
stdout
+
"]\n"
);
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stdout: '"
+
matcher
.
group
()
+
"' \n"
);
}
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stderr
);
if
(
matcher
.
find
())
{
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stderr: ["
+
stderr
+
"]\n"
);
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stderr: '"
+
matcher
.
group
()
+
"' \n"
);
}
}
...
...
@@ -245,13 +265,15 @@ public final class OutputAnalyzer {
* pattern
*
* @param pattern
* @throws RuntimeException If the pattern was found
* @throws RuntimeException
* If the pattern was found
*/
public
void
stdoutShouldNotMatch
(
String
pattern
)
{
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stdout
);
if
(
matcher
.
find
())
{
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stdout: ["
+
stdout
+
"]
\n"
);
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stdout
\n"
);
}
}
...
...
@@ -260,18 +282,56 @@ public final class OutputAnalyzer {
* pattern
*
* @param pattern
* @throws RuntimeException If the pattern was found
* @throws RuntimeException
* If the pattern was found
*/
public
void
stderrShouldNotMatch
(
String
pattern
)
{
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stderr
);
Matcher
matcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
).
matcher
(
stderr
);
if
(
matcher
.
find
())
{
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stderr: ["
+
stderr
+
"]
\n"
);
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"'"
+
pattern
+
"' found in stderr
\n"
);
}
}
/**
* Verifiy the exit value of the process
* Get the captured group of the first string matching the pattern. stderr
* is searched before stdout.
*
* @param pattern
* The multi-line pattern to match
* @param group
* The group to capture
* @return The matched string or null if no match was found
*/
public
String
firstMatch
(
String
pattern
,
int
group
)
{
Matcher
stderrMatcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
)
.
matcher
(
stderr
);
Matcher
stdoutMatcher
=
Pattern
.
compile
(
pattern
,
Pattern
.
MULTILINE
)
.
matcher
(
stdout
);
if
(
stderrMatcher
.
find
())
{
return
stderrMatcher
.
group
(
group
);
}
if
(
stdoutMatcher
.
find
())
{
return
stdoutMatcher
.
group
(
group
);
}
return
null
;
}
/**
* Get the first string matching the pattern. stderr is searched before
* stdout.
*
* @param pattern
* The multi-line pattern to match
* @return The matched string or null if no match was found
*/
public
String
firstMatch
(
String
pattern
)
{
return
firstMatch
(
pattern
,
0
);
}
/**
* Verify the exit value of the process
*
* @param expectedExitValue
* Expected exit value from process
...
...
@@ -281,11 +341,24 @@ public final class OutputAnalyzer {
*/
public
void
shouldHaveExitValue
(
int
expectedExitValue
)
{
if
(
getExitValue
()
!=
expectedExitValue
)
{
throw
new
RuntimeException
(
"Exit value "
+
getExitValue
()
+
" , expected to get "
+
expectedExitValue
);
reportDiagnosticSummary
();
throw
new
RuntimeException
(
"Expected to get exit value of ["
+
expectedExitValue
+
"]\n"
);
}
}
/**
* Report summary that will help to diagnose the problem Currently includes:
* - standard input produced by the process under test - standard output -
* exit code Note: the command line is printed by the ProcessTools
*/
private
void
reportDiagnosticSummary
()
{
String
msg
=
" stdout: ["
+
stdout
+
"];\n"
+
" stderr: ["
+
stderr
+
"]\n"
+
" exitValue = "
+
getExitValue
()
+
"\n"
;
System
.
err
.
println
(
msg
);
}
/**
* Get the contents of the output buffer (stdout and stderr)
*
...
...
test/lib/testlibrary/jdk/testlibrary/ProcessTools.java
浏览文件 @
27d8dc3f
...
...
@@ -25,10 +25,7 @@ package jdk.testlibrary;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintStream
;
import
java.io.PrintWriter
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.RuntimeMXBean
;
import
java.lang.reflect.Field
;
...
...
@@ -237,15 +234,20 @@ public final class ProcessTools {
*/
public
static
ProcessBuilder
createJavaProcessBuilder
(
String
...
command
)
throws
Exception
{
String
javapath
=
J
dkFinder
.
getJavaLauncher
(
false
);
String
javapath
=
J
DKToolFinder
.
getJDKTool
(
"java"
);
ArrayList
<
String
>
args
=
new
ArrayList
<>();
args
.
add
(
javapath
);
Collections
.
addAll
(
args
,
getPlatformSpecificVMArgs
());
Collections
.
addAll
(
args
,
command
);
return
new
ProcessBuilder
(
args
.
toArray
(
new
String
[
args
.
size
()]));
// Reporting
StringBuilder
cmdLine
=
new
StringBuilder
();
for
(
String
cmd
:
args
)
cmdLine
.
append
(
cmd
).
append
(
' '
);
System
.
out
.
println
(
"Command line: ["
+
cmdLine
.
toString
()
+
"]"
);
return
new
ProcessBuilder
(
args
.
toArray
(
new
String
[
args
.
size
()]));
}
}
test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java
浏览文件 @
27d8dc3f
...
...
@@ -29,7 +29,6 @@ import java.nio.file.Path;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicReference
;
import
jdk.testlibrary.JdkFinder
;
import
jdk.testlibrary.ProcessTools
;
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录