Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
21c6fe5f
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
21c6fe5f
编写于
4月 10, 2015
作者:
J
jlaskey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8077506: Simplify test JImageTest
Reviewed-by: alanb Contributed-by: james.laskey@oracle.com
上级
c12c1dd4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
100 deletion
+21
-100
jdk/test/jdk/internal/jimage/JImageTest.java
jdk/test/jdk/internal/jimage/JImageTest.java
+21
-100
未找到文件。
jdk/test/jdk/internal/jimage/JImageTest.java
浏览文件 @
21c6fe5f
...
...
@@ -22,121 +22,41 @@
*/
/*
* @test
* @library /lib/testlibrary
* @build jdk.testlibrary.*
* @summary Test to see if jimage tool extracts and recreates correctly.
* @run main/timeout=360 JImageTest
*/
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
jdk.testlibrary.ProcessTools
;
/**
* Basic test for jimage tool.
*/
public
class
JImageTest
{
private
static
Runtime
runtime
=
Runtime
.
getRuntime
();
private
static
int
errors
=
0
;
static
class
Tool
{
private
int
exit
=
0
;
private
String
out
=
""
;
private
String
err
=
""
;
private
static
void
jimage
(
String
...
jimageArgs
)
throws
Exception
{
ArrayList
<
String
>
args
=
new
ArrayList
<>();
args
.
add
(
"-ms8m"
);
args
.
add
(
"jdk.tools.jimage.Main"
);
args
.
addAll
(
Arrays
.
asList
(
jimageArgs
));
private
void
feedInputStream
(
String
in
,
OutputStream
out
)
{
try
(
OutputStreamWriter
outputStream
=
new
OutputStreamWriter
(
out
))
{
if
(
in
!=
null
)
{
outputStream
.
write
(
in
,
0
,
in
.
length
());
}
}
catch
(
final
IOException
ex
)
{
// Process was not expecting input. May be normal state of affairs.
}
}
private
Thread
getOutputStreamThread
(
InputStream
in
,
StringBuilder
out
)
{
return
new
Thread
(()
->
{
final
char
buffer
[]
=
new
char
[
1024
];
try
(
final
InputStreamReader
inputStream
=
new
InputStreamReader
(
in
))
{
for
(
int
length
;
(
length
=
inputStream
.
read
(
buffer
,
0
,
buffer
.
length
))
!=
-
1
;
)
{
out
.
append
(
buffer
,
0
,
length
);
}
}
catch
(
final
IOException
ex
)
{
out
.
append
(
ex
.
toString
());
}
});
}
ProcessBuilder
builder
=
ProcessTools
.
createJavaProcessBuilder
(
args
.
toArray
(
new
String
[
args
.
size
()]));
int
res
=
builder
.
inheritIO
().
start
().
waitFor
();
Tool
(
String
[]
args
)
{
this
(
null
,
args
);
}
Tool
(
String
in
,
String
[]
args
)
{
ProcessBuilder
processBuilder
=
new
ProcessBuilder
(
args
);
exec
(
processBuilder
,
in
);
}
private
void
exec
(
ProcessBuilder
processBuilder
,
String
in
)
{
StringBuilder
outBuilder
=
new
StringBuilder
();
StringBuilder
errBuilder
=
new
StringBuilder
();
try
{
Process
process
=
processBuilder
.
start
();
Thread
outThread
=
getOutputStreamThread
(
process
.
getInputStream
(),
outBuilder
);
Thread
errThread
=
getOutputStreamThread
(
process
.
getErrorStream
(),
errBuilder
);
outThread
.
start
();
errThread
.
start
();
feedInputStream
(
in
,
process
.
getOutputStream
());
exit
=
process
.
waitFor
();
outThread
.
join
();
errThread
.
join
();
}
catch
(
IOException
|
InterruptedException
ex
)
{
ex
.
printStackTrace
();
exit
=
-
1
;
}
out
=
outBuilder
.
toString
();
err
=
errBuilder
.
toString
();
}
int
getExit
()
{
return
exit
;
}
String
getOut
()
{
return
out
;
}
String
getErr
()
{
return
err
;
if
(
res
!=
0
)
{
throw
new
RuntimeException
(
"JImageTest tool FAILED"
);
}
}
private
static
void
exec
(
String
...
args
)
{
Tool
tool
=
new
Tool
(
args
);
int
exit
=
tool
.
getExit
();
if
(
exit
!=
0
)
{
errors
++;
System
.
err
.
println
(
"----------Tool.out----------"
);
System
.
err
.
append
(
tool
.
getOut
());
System
.
err
.
println
(
"----------Tool.err----------"
);
System
.
err
.
append
(
tool
.
getErr
());
System
.
err
.
println
(
"----------Tool.exit----------"
);
System
.
err
.
println
(
"Error code = "
+
exit
);
throw
new
RuntimeException
(
"JImageTest FAIL"
);
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
String
JAVA_HOME
=
System
.
getProperty
(
"java.home"
);
Path
jimagePath
=
Paths
.
get
(
JAVA_HOME
,
"bin"
,
"jimage"
);
Path
bootimagePath
=
Paths
.
get
(
JAVA_HOME
,
"lib"
,
"modules"
,
"bootmodules.jimage"
);
...
...
@@ -147,12 +67,13 @@ public class JImageTest {
String
extractDir
=
Paths
.
get
(
"."
,
"extract"
).
toAbsolutePath
().
toString
();
String
recreateImage
=
Paths
.
get
(
"."
,
"recreate.jimage"
).
toAbsolutePath
().
toString
();
exec
(
new
String
[]
{
jimage
,
"extract"
,
"--dir"
,
extractDir
,
bootimage
}
);
exec
(
new
String
[]
{
jimage
,
"recreate"
,
"--dir"
,
extractDir
,
recreateImage
}
);
jimage
(
"extract"
,
"--dir"
,
extractDir
,
bootimage
);
jimage
(
"recreate"
,
"--dir"
,
extractDir
,
recreateImage
);
System
.
out
.
println
(
"Test successful"
);
}
else
{
System
.
out
.
println
(
"Test skipped, no module image"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录