Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
18da6991
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
18da6991
编写于
5月 29, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generic OOM testing hooks
上级
a9d4944f
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
112 addition
and
5 deletion
+112
-5
ChangeLog
ChangeLog
+5
-0
configure.in
configure.in
+27
-2
src/memory.c
src/memory.c
+70
-2
src/memory.h
src/memory.h
+10
-1
未找到文件。
ChangeLog
浏览文件 @
18da6991
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
for out-of-memory testing
Thu May 29 10:55:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
Thu May 29 10:55:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/virsh.c: Don't add trailing blanks in dominfo output
* src/virsh.c: Don't add trailing blanks in dominfo output
...
...
configure.in
浏览文件 @
18da6991
...
@@ -889,8 +889,9 @@ AC_ARG_ENABLE([test-coverage],
...
@@ -889,8 +889,9 @@ AC_ARG_ENABLE([test-coverage],
*) AC_MSG_ERROR([bad value ${enableval} for test-coverage option]) ;;
*) AC_MSG_ERROR([bad value ${enableval} for test-coverage option]) ;;
esac],
esac],
[enableval=no])
[enableval=no])
enable_coverage=$enableval
if test "${enable
val
}" = yes; then
if test "${enable
_coverage
}" = yes; then
gl_COMPILER_FLAGS(-fprofile-arcs)
gl_COMPILER_FLAGS(-fprofile-arcs)
gl_COMPILER_FLAGS(-ftest-coverage)
gl_COMPILER_FLAGS(-ftest-coverage)
AC_SUBST([COVERAGE_CFLAGS], [$COMPILER_FLAGS])
AC_SUBST([COVERAGE_CFLAGS], [$COMPILER_FLAGS])
...
@@ -898,6 +899,25 @@ if test "${enableval}" = yes; then
...
@@ -898,6 +899,25 @@ if test "${enableval}" = yes; then
COMPILER_FLAGS=
COMPILER_FLAGS=
fi
fi
AC_ARG_ENABLE([test-oom],
[ --enable-test-oom memory allocation failure checking],
[case "${enableval}" in
yes|no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for test-oom option]) ;;
esac],
[enableval=no])
enable_oom=$enableval
if test "${enable_oom}" = yes; then
have_trace=yes
AC_CHECK_HEADER([execinfo.h],[],[have_trace=no])
AC_CHECK_FUNC([backtrace],[],[have_trace=no])
if test "$have_trace" = "yes"; then
AC_DEFINE([TEST_OOM_TRACE], 1, [Whether backtrace() is available])
fi
AC_DEFINE([TEST_OOM], 1, [Whether malloc OOM checking is enabled])
fi
dnl Enable building the proxy?
dnl Enable building the proxy?
AC_ARG_WITH([xen-proxy],
AC_ARG_WITH([xen-proxy],
...
@@ -1042,6 +1062,11 @@ else
...
@@ -1042,6 +1062,11 @@ else
AC_MSG_NOTICE([ numactl: no])
AC_MSG_NOTICE([ numactl: no])
fi
fi
AC_MSG_NOTICE([])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([Test suite])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([ Coverage: $enable_coverage])
AC_MSG_NOTICE([ Alloc OOM: $enable_oom])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([Miscellaneous])
AC_MSG_NOTICE([Miscellaneous])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([ Debug: $enable_debug])
AC_MSG_NOTICE([ Debug: $enable_debug])
...
...
src/memory.c
浏览文件 @
18da6991
...
@@ -26,6 +26,57 @@
...
@@ -26,6 +26,57 @@
#include "memory.h"
#include "memory.h"
#if TEST_OOM
static
int
testMallocNext
=
0
;
static
int
testMallocFailFirst
=
0
;
static
int
testMallocFailLast
=
0
;
static
void
(
*
testMallocHook
)(
void
*
)
=
NULL
;
static
void
*
testMallocHookData
=
NULL
;
void
virAllocTestInit
(
void
)
{
testMallocNext
=
1
;
testMallocFailFirst
=
0
;
testMallocFailLast
=
0
;
}
int
virAllocTestCount
(
void
)
{
return
testMallocNext
-
1
;
}
void
virAllocTestHook
(
void
(
*
func
)(
void
*
),
void
*
data
)
{
testMallocHook
=
func
;
testMallocHookData
=
data
;
}
void
virAllocTestOOM
(
int
n
,
int
m
)
{
testMallocNext
=
1
;
testMallocFailFirst
=
n
;
testMallocFailLast
=
n
+
m
-
1
;
}
static
int
virAllocTestFail
(
void
)
{
int
fail
=
0
;
if
(
testMallocNext
==
0
)
return
0
;
fail
=
testMallocNext
>=
testMallocFailFirst
&&
testMallocNext
<=
testMallocFailLast
;
if
(
fail
&&
testMallocHook
)
(
testMallocHook
)(
testMallocHookData
);
testMallocNext
++
;
return
fail
;
}
#endif
/* Return 1 if an array of N objects, each of size S, cannot exist due
/* Return 1 if an array of N objects, each of size S, cannot exist due
to size arithmetic overflow. S must be positive and N must be
to size arithmetic overflow. S must be positive and N must be
nonnegative. This is a macro, not an inline function, so that it
nonnegative. This is a macro, not an inline function, so that it
...
@@ -55,13 +106,18 @@
...
@@ -55,13 +106,18 @@
*/
*/
int
virAlloc
(
void
*
ptrptr
,
size_t
size
)
int
virAlloc
(
void
*
ptrptr
,
size_t
size
)
{
{
#if TEST_OOM
if
(
virAllocTestFail
())
{
*
(
void
**
)
ptrptr
=
NULL
;
return
-
1
;
}
#endif
if
(
size
==
0
)
{
if
(
size
==
0
)
{
*
(
void
**
)
ptrptr
=
NULL
;
*
(
void
**
)
ptrptr
=
NULL
;
return
0
;
return
0
;
}
}
*
(
void
**
)
ptrptr
=
calloc
(
1
,
size
);
*
(
void
**
)
ptrptr
=
calloc
(
1
,
size
);
if
(
*
(
void
**
)
ptrptr
==
NULL
)
if
(
*
(
void
**
)
ptrptr
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -83,6 +139,13 @@ int virAlloc(void *ptrptr, size_t size)
...
@@ -83,6 +139,13 @@ int virAlloc(void *ptrptr, size_t size)
*/
*/
int
virAllocN
(
void
*
ptrptr
,
size_t
size
,
size_t
count
)
int
virAllocN
(
void
*
ptrptr
,
size_t
size
,
size_t
count
)
{
{
#if TEST_OOM
if
(
virAllocTestFail
())
{
*
(
void
**
)
ptrptr
=
NULL
;
return
-
1
;
}
#endif
if
(
size
==
0
||
count
==
0
)
{
if
(
size
==
0
||
count
==
0
)
{
*
(
void
**
)
ptrptr
=
NULL
;
*
(
void
**
)
ptrptr
=
NULL
;
return
0
;
return
0
;
...
@@ -111,6 +174,11 @@ int virAllocN(void *ptrptr, size_t size, size_t count)
...
@@ -111,6 +174,11 @@ int virAllocN(void *ptrptr, size_t size, size_t count)
int
virReallocN
(
void
*
ptrptr
,
size_t
size
,
size_t
count
)
int
virReallocN
(
void
*
ptrptr
,
size_t
size
,
size_t
count
)
{
{
void
*
tmp
;
void
*
tmp
;
#if TEST_OOM
if
(
virAllocTestFail
())
return
-
1
;
#endif
if
(
size
==
0
||
count
==
0
)
{
if
(
size
==
0
||
count
==
0
)
{
free
(
*
(
void
**
)
ptrptr
);
free
(
*
(
void
**
)
ptrptr
);
*
(
void
**
)
ptrptr
=
NULL
;
*
(
void
**
)
ptrptr
=
NULL
;
...
...
src/memory.h
浏览文件 @
18da6991
...
@@ -31,7 +31,6 @@ int virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
...
@@ -31,7 +31,6 @@ int virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
int
virReallocN
(
void
*
ptrptr
,
size_t
size
,
size_t
count
)
ATTRIBUTE_RETURN_CHECK
;
int
virReallocN
(
void
*
ptrptr
,
size_t
size
,
size_t
count
)
ATTRIBUTE_RETURN_CHECK
;
void
virFree
(
void
*
ptrptr
);
void
virFree
(
void
*
ptrptr
);
/**
/**
* VIR_ALLOC:
* VIR_ALLOC:
* @ptr: pointer to hold address of allocated memory
* @ptr: pointer to hold address of allocated memory
...
@@ -79,4 +78,14 @@ void virFree(void *ptrptr);
...
@@ -79,4 +78,14 @@ void virFree(void *ptrptr);
*/
*/
#define VIR_FREE(ptr) virFree(&(ptr));
#define VIR_FREE(ptr) virFree(&(ptr));
#if TEST_OOM
void
virAllocTestInit
(
void
);
int
virAllocTestCount
(
void
);
void
virAllocTestOOM
(
int
n
,
int
m
);
void
virAllocTestHook
(
void
(
*
func
)(
void
*
),
void
*
data
);
#endif
#endif
/* __VIR_MEMORY_H_ */
#endif
/* __VIR_MEMORY_H_ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录