Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
364f53a6
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
364f53a6
编写于
5月 29, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generic test suite helpers for OOM testing
上级
18da6991
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
198 addition
and
15 deletion
+198
-15
ChangeLog
ChangeLog
+7
-0
tests/Makefile.am
tests/Makefile.am
+1
-0
tests/oomtrace.pl
tests/oomtrace.pl
+41
-0
tests/testutils.c
tests/testutils.c
+140
-15
tests/testutils.h
tests/testutils.h
+9
-0
未找到文件。
ChangeLog
浏览文件 @
364f53a6
Thu May 29 11:12:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* tests/testutils.c, tests/testutils.h: Add generic main()
impl for test programs to leverage OOM testing
* tests/Makefile.am, tests/oomtrace.pl: post-processor for
generating file/line number backtraces from OOM reports.
Thu May 29 11:12:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/memory.c, src/memory.h, configure.ac: Add generics hooks
...
...
tests/Makefile.am
浏览文件 @
364f53a6
...
...
@@ -33,6 +33,7 @@ LDADDS = \
$(COVERAGE_LDFLAGS)
EXTRA_DIST
=
\
oomtrace.pl
\
test-lib.sh
\
xmlrpcserver.py
\
test_conf.sh
\
...
...
tests/oomtrace.pl
0 → 100644
浏览文件 @
364f53a6
#!/usr/bin/perl
use
strict
;
use
warnings
;
(
my
$ME
=
$
0
)
=~
s|.*/||
;
# use File::Coda; # http://meyering.net/code/Coda/
END
{
defined
fileno
STDOUT
or
return
;
close
STDOUT
and
return
;
warn
"
$ME
: failed to close standard output: $!
\n
";
$?
||=
1
;
}
my
@data
=
<>
;
my
%trace
;
my
%lines
;
foreach
(
@data
)
{
if
(
/^\s*TRACE:\s+(\S+?)(?:\(.*\))?\s+\[0x(.*)\]\s*$/
)
{
$trace
{
$
2
}
=
$
1
;
}
}
foreach
my
$key
(
keys
%trace
)
{
my
$val
=
$trace
{
$key
};
my
$info
=
$val
=~
/\?\?/
?
$val
:
`
addr2line -e
$val
$key
`;
$lines
{
$key
}
=
$info
;
}
foreach
(
@data
)
{
if
(
/^\s*TRACE:\s+(\S+?)(?:\(.*\))?\s+\[0x(.*)\]\s*$/
)
{
print
$lines
{
$
2
};
}
else
{
print
;
}
}
tests/testutils.c
浏览文件 @
364f53a6
...
...
@@ -24,6 +24,12 @@
#include <limits.h>
#include "testutils.h"
#include "internal.h"
#include "memory.h"
#include "util.h"
#if TEST_OOM_TRACE
#include <execinfo.h>
#endif
#ifdef HAVE_PATHS_H
#include <paths.h>
...
...
@@ -38,6 +44,10 @@
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
static
unsigned
int
testOOM
=
0
;
static
unsigned
int
testDebug
=
0
;
static
unsigned
int
testCounter
=
0
;
double
virtTestCountAverage
(
double
*
items
,
int
nitems
)
{
...
...
@@ -60,12 +70,13 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
{
int
i
,
ret
=
0
;
double
*
ts
=
NULL
;
static
int
counter
=
0
;
c
ounter
++
;
testC
ounter
++
;
fprintf
(
stderr
,
"%2d) %-65s ... "
,
counter
,
title
);
fflush
(
stderr
);
if
(
testOOM
<
2
)
{
fprintf
(
stderr
,
"%2d) %-65s ... "
,
testCounter
,
title
);
fflush
(
stderr
);
}
if
(
nloops
>
1
&&
(
ts
=
calloc
(
nloops
,
sizeof
(
double
)))
==
NULL
)
...
...
@@ -83,13 +94,15 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
ts
[
i
]
=
DIFF_MSEC
(
&
after
,
&
before
);
}
}
if
(
ret
==
0
&&
ts
)
fprintf
(
stderr
,
"OK [%.5f ms]
\n
"
,
virtTestCountAverage
(
ts
,
nloops
));
else
if
(
ret
==
0
)
fprintf
(
stderr
,
"OK
\n
"
);
else
fprintf
(
stderr
,
"FAILED
\n
"
);
if
(
testOOM
<
2
)
{
if
(
ret
==
0
&&
ts
)
fprintf
(
stderr
,
"OK [%.5f ms]
\n
"
,
virtTestCountAverage
(
ts
,
nloops
));
else
if
(
ret
==
0
)
fprintf
(
stderr
,
"OK
\n
"
);
else
fprintf
(
stderr
,
"FAILED
\n
"
);
}
free
(
ts
);
return
ret
;
...
...
@@ -232,13 +245,14 @@ int virtTestDifference(FILE *stream,
const
char
*
expectEnd
=
expect
+
(
strlen
(
expect
)
-
1
);
const
char
*
actualStart
=
actual
;
const
char
*
actualEnd
=
actual
+
(
strlen
(
actual
)
-
1
);
const
char
*
debug
;
if
(
(
debug
=
getenv
(
"DEBUG_TESTS"
))
==
NULL
)
if
(
testOOM
<
2
)
return
0
;
if
(
STREQ
(
debug
,
""
)
||
STREQ
(
debug
,
"1"
))
{
if
(
!
testDebug
)
return
0
;
if
(
testDebug
<
2
)
{
/* Skip to first character where they differ */
while
(
*
expectStart
&&
*
actualStart
&&
*
actualStart
==
*
expectStart
)
{
...
...
@@ -272,3 +286,114 @@ int virtTestDifference(FILE *stream,
return
0
;
}
static
void
virtTestErrorFuncQuiet
(
void
*
data
ATTRIBUTE_UNUSED
,
virErrorPtr
err
ATTRIBUTE_UNUSED
)
{
}
static
void
virtTestErrorHook
(
void
*
data
ATTRIBUTE_UNUSED
)
{
#if TEST_OOM_TRACE
void
*
trace
[
30
];
int
ntrace
=
ARRAY_CARDINALITY
(
trace
);
int
i
;
char
**
symbols
=
NULL
;
ntrace
=
backtrace
(
trace
,
ntrace
);
symbols
=
backtrace_symbols
(
trace
,
ntrace
);
if
(
symbols
)
{
fprintf
(
stderr
,
"Failing an allocation at:
\n
"
);
for
(
i
=
0
;
i
<
ntrace
;
i
++
)
{
if
(
symbols
[
i
])
fprintf
(
stderr
,
" TRACE: %s
\n
"
,
symbols
[
i
]);
}
free
(
symbols
);
}
#endif
}
int
virtTestMain
(
int
argc
,
char
**
argv
,
int
(
*
func
)(
int
,
char
**
))
{
#if TEST_OOM
int
ret
;
int
approxAlloc
=
0
;
int
n
;
char
*
oomStr
=
NULL
,
*
debugStr
;
int
oomCount
;
if
((
debugStr
=
getenv
(
"VIR_TEST_DEBUG"
))
!=
NULL
)
{
if
(
virStrToLong_i
(
debugStr
,
NULL
,
10
,
&
testDebug
)
<
0
)
testDebug
=
0
;
if
(
testDebug
<
0
)
testDebug
=
0
;
}
if
((
oomStr
=
getenv
(
"VIR_TEST_OOM"
))
!=
NULL
)
{
if
(
virStrToLong_i
(
oomStr
,
NULL
,
10
,
&
oomCount
)
<
0
)
oomCount
=
0
;
if
(
oomCount
<
0
)
oomCount
=
0
;
if
(
oomCount
)
testOOM
=
1
;
}
if
(
testOOM
)
virAllocTestInit
();
/* Run once to count allocs, and ensure it passes :-) */
ret
=
(
func
)(
argc
,
argv
);
if
(
ret
!=
EXIT_SUCCESS
)
return
EXIT_FAILURE
;
if
(
testDebug
)
virAllocTestHook
(
virtTestErrorHook
,
NULL
);
if
(
testOOM
)
{
/* Makes next test runs quiet... */
testOOM
++
;
virSetErrorFunc
(
NULL
,
virtTestErrorFuncQuiet
);
approxAlloc
=
virAllocTestCount
();
testCounter
++
;
if
(
testDebug
)
fprintf
(
stderr
,
"%d) OOM...
\n
"
,
testCounter
);
else
fprintf
(
stderr
,
"%d) OOM of %d allocs "
,
testCounter
,
approxAlloc
);
/* Run once for each alloc, failing a different one
and validating that the test case failed */
for
(
n
=
0
;
n
<
approxAlloc
;
n
++
)
{
if
(
!
testDebug
)
{
fprintf
(
stderr
,
"."
);
fflush
(
stderr
);
}
virAllocTestOOM
(
n
+
1
,
oomCount
);
if
(((
func
)(
argc
,
argv
))
!=
EXIT_FAILURE
)
{
ret
=
EXIT_FAILURE
;
break
;
}
}
if
(
testDebug
)
fprintf
(
stderr
,
" ... OOM of %d allocs"
,
approxAlloc
);
if
(
ret
==
EXIT_SUCCESS
)
fprintf
(
stderr
,
" OK
\n
"
);
else
fprintf
(
stderr
,
" FAILED
\n
"
);
}
return
ret
;
#else
return
(
func
)(
argc
,
argv
);
#endif
}
tests/testutils.h
浏览文件 @
364f53a6
...
...
@@ -37,6 +37,15 @@ extern "C" {
const
char
*
expect
,
const
char
*
actual
);
int
virtTestMain
(
int
argc
,
char
**
argv
,
int
(
*
func
)(
int
,
char
**
));
#define VIRT_TEST_MAIN(func) \
int main(int argc, char **argv) { \
return virtTestMain(argc,argv, func); \
}
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录