Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
48455914
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,发现更多精彩内容 >>
提交
48455914
编写于
4月 18, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test script helper for printing string differences
上级
2d206f1d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
3 deletion
+74
-3
ChangeLog
ChangeLog
+5
-0
tests/testutils.c
tests/testutils.c
+64
-3
tests/testutils.h
tests/testutils.h
+5
-0
未找到文件。
ChangeLog
浏览文件 @
48455914
Fri Apr 18 11:04:24 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* tests/testutils.h, tests/testutils.c: Add virtTestDifference
for printing out trimmed string differences
Fri Apr 18 11:24:24 CEST 2008 Jim Meyering <meyering@redhat.com>
avoid compile error when <pthread.h> is absent
...
...
tests/testutils.c
浏览文件 @
48455914
...
...
@@ -19,6 +19,7 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <limits.h>
#include "testutils.h"
...
...
@@ -58,6 +59,12 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
{
int
i
,
ret
=
0
;
double
*
ts
=
NULL
;
static
int
counter
=
0
;
counter
++
;
fprintf
(
stderr
,
"%2d) %-65s ... "
,
counter
,
title
);
fflush
(
stderr
);
if
(
nloops
>
1
&&
(
ts
=
calloc
(
nloops
,
sizeof
(
double
)))
==
NULL
)
...
...
@@ -76,12 +83,12 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
}
}
if
(
ret
==
0
&&
ts
)
fprintf
(
stderr
,
"
%-50s ... OK [%.5f ms]
\n
"
,
title
,
fprintf
(
stderr
,
"
OK [%.5f ms]
\n
"
,
virtTestCountAverage
(
ts
,
nloops
));
else
if
(
ret
==
0
)
fprintf
(
stderr
,
"
%-50s ... OK
\n
"
,
title
);
fprintf
(
stderr
,
"
OK
\n
"
);
else
fprintf
(
stderr
,
"
%-50s ... FAILED
\n
"
,
title
);
fprintf
(
stderr
,
"
FAILED
\n
"
);
free
(
ts
);
return
ret
;
...
...
@@ -206,3 +213,57 @@ int virtTestCaptureProgramOutput(const char *const argv[],
}
}
}
/**
* @param stream: output stream write to differences to
* @param expect: expected output text
* @param actual: actual output text
*
* Display expected and actual output text, trimmed to
* first and last characters at which differences occur
*/
int
virtTestDifference
(
FILE
*
stream
,
const
char
*
expect
,
const
char
*
actual
)
{
const
char
*
expectStart
=
expect
;
const
char
*
expectEnd
=
expect
+
(
strlen
(
expect
)
-
1
);
const
char
*
actualStart
=
actual
;
const
char
*
actualEnd
=
actual
+
(
strlen
(
actual
)
-
1
);
if
(
getenv
(
"DEBUG_TESTS"
)
==
NULL
)
return
0
;
/* Skip to first character where they differ */
while
(
*
expectStart
&&
*
actualStart
&&
*
actualStart
==
*
expectStart
)
{
actualStart
++
;
expectStart
++
;
}
/* Work backwards to last character where they differ */
while
(
actualEnd
>
actualStart
&&
expectEnd
>
expectStart
&&
*
actualEnd
==
*
expectEnd
)
{
actualEnd
--
;
expectEnd
--
;
}
/* Show the trimmed differences */
fprintf
(
stream
,
"
\n
Expect ["
);
if
((
expectEnd
-
expectStart
+
1
)
&&
fwrite
(
expectStart
,
(
expectEnd
-
expectStart
+
1
),
1
,
stream
)
!=
1
)
return
-
1
;
fprintf
(
stream
,
"]
\n
"
);
fprintf
(
stream
,
"Actual ["
);
if
((
actualEnd
-
actualStart
+
1
)
&&
fwrite
(
actualStart
,
(
actualEnd
-
actualStart
+
1
),
1
,
stream
)
!=
1
)
return
-
1
;
fprintf
(
stream
,
"]
\n
"
);
/* Pad to line up with test name ... in virTestRun */
fprintf
(
stream
,
" ... "
);
return
0
;
}
tests/testutils.h
浏览文件 @
48455914
...
...
@@ -32,6 +32,11 @@ extern "C" {
char
**
buf
,
int
buflen
);
int
virtTestDifference
(
FILE
*
stream
,
const
char
*
expect
,
const
char
*
actual
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录