Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
8e473890
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
11 个月 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8e473890
编写于
10月 06, 2022
作者:
M
Maxim Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix test-malloc-stats-print and test-malloc-info
Signed-off-by:
N
Maxim Polyakov
<
polyakov.maksim@huawei.com
>
上级
fc2b8ddd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
26 deletion
+69
-26
libc-test/src/functional/test-malloc-info-stats-print.h
libc-test/src/functional/test-malloc-info-stats-print.h
+5
-3
libc-test/src/functional/test-malloc-info.c
libc-test/src/functional/test-malloc-info.c
+24
-13
libc-test/src/functional/test-malloc-stats-print.c
libc-test/src/functional/test-malloc-stats-print.c
+40
-10
未找到文件。
libc-test/src/functional/test-malloc-info-stats-print.h
浏览文件 @
8e473890
...
...
@@ -40,9 +40,11 @@ typedef struct
static
void
stderr_stats_cb
(
void
);
static
int
populate_thread_stats
(
const
char
*
in
put
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
);
static
int
populate_thread_stats
(
const
char
*
out
put
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
);
static
int
populate_total_free_heap_space
(
const
char
*
input
,
long
long
*
total_free_heap_space
);
static
int
populate_total_free_heap_space
(
const
char
*
output
,
long
long
*
total_free_heap_space
);
static
int
is_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
);
static
void
print_to_file
(
void
*
fp
,
const
char
*
s
)
{
...
...
@@ -190,7 +192,7 @@ static int validate_different_threads_test_results(test_results_t *test_results)
malloc_thread_stats_t
thread_stats
;
result
&=
populate_thread_stats
(
test_results
->
stats_after_allocations
,
test_results
->
threads
[
i
],
&
thread_stats
);
result
&=
validate_allocated_size
(
sizes
[
i
],
&
thread_stats
);
if
(
strstr
(
test_results
->
stats_after_free
,
test_results
->
threads
[
i
])
!=
NULL
)
if
(
is_thread_in_output
(
test_results
->
stats_after_free
,
test_results
->
threads
[
i
])
)
{
t_error
(
"Thread %s did not disappear from output
\n
"
,
test_results
->
threads
[
i
]);
result
=
0
;
...
...
libc-test/src/functional/test-malloc-info.c
浏览文件 @
8e473890
...
...
@@ -103,24 +103,24 @@ static long long parse_amount(const char *s)
return
result
;
}
static
int
populate_thread_stats
(
const
char
*
input
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
)
static
xmlNodePtr
find_thread_in_document
(
xmlDocPtr
doc_ptr
,
const
char
*
thread_id
)
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
input
);
if
(
doc_ptr
==
NULL
)
{
return
0
;
}
xmlNodePtr
root_element
=
xmlDocGetRootElement
(
doc_ptr
);
xmlNodePtr
thread_root
;
if
(
strcmp
(
thread_id
,
"abandoned"
)
==
0
)
{
thread_root
=
find_child_node
(
"abandoned"
,
root_element
);
return
find_child_node
(
"abandoned"
,
root_element
);
}
else
return
find_child_node_with_attr
(
"thread"
,
"id"
,
thread_id
,
find_child_node
(
"threads"
,
root_element
));
}
static
int
populate_thread_stats
(
const
char
*
output
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
)
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
if
(
doc_ptr
==
NULL
)
{
xmlNodePtr
threads
=
find_child_node
(
"threads"
,
root_element
);
thread_root
=
find_child_node_with_attr
(
"thread"
,
"id"
,
thread_id
,
threads
);
return
0
;
}
xmlNodePtr
thread_root
=
find_thread_in_document
(
doc_ptr
,
thread_id
);
long
long
total_allocated_memory
=
parse_amount
(
get_node_text
(
find_child_node
(
"total_allocated_memory"
,
thread_root
)));
long
long
total_mmapped_memory
=
...
...
@@ -139,9 +139,9 @@ static int populate_thread_stats(const char *input, const char *thread_id, mallo
return
1
;
}
static
int
populate_total_free_heap_space
(
const
char
*
in
put
,
long
long
*
total_free_heap_space
)
static
int
populate_total_free_heap_space
(
const
char
*
out
put
,
long
long
*
total_free_heap_space
)
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
in
put
);
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
out
put
);
if
(
doc_ptr
==
NULL
)
{
return
0
;
...
...
@@ -156,4 +156,15 @@ static int populate_total_free_heap_space(const char *input, long long *total_fr
}
*
total_free_heap_space
=
total_free_heap_space_parsed
;
return
1
;
}
static
int
is_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
if
(
doc_ptr
==
NULL
)
{
return
0
;
}
int
result
=
find_thread_in_document
(
doc_ptr
,
thread_id
)
!=
NULL
;
xmlFreeDoc
(
doc_ptr
);
return
result
;
}
\ No newline at end of file
libc-test/src/functional/test-malloc-stats-print.c
浏览文件 @
8e473890
...
...
@@ -13,14 +13,18 @@
* limitations under the License.
*/
#include <regex.h>
#include "test-malloc-info-stats-print.h"
#define THREAD_DATA_REGEX_LEN (MAX_TID_LEN + 43)
#define REGEX_NMATCH 1
static
void
stderr_stats_cb
(
void
)
{
malloc_stats_print
(
print_to_file
,
stderr
,
""
);
}
static
int
parse_amount
(
char
**
s
,
long
long
*
destination
)
static
int
parse_amount
(
c
onst
c
har
**
s
,
long
long
*
destination
)
{
char
*
end_ptr
=
NULL
;
long
long
result
=
strtoll
(
*
s
,
&
end_ptr
,
10
);
...
...
@@ -35,27 +39,53 @@ static int parse_amount(char **s, long long *destination)
return
1
;
}
static
int
populate_thread_stats
(
const
char
*
input
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
)
static
const
char
*
find_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
{
char
thread_data_regex_s
[
THREAD_DATA_REGEX_LEN
+
1
];
snprintf
(
thread_data_regex_s
,
THREAD_DATA_REGEX_LEN
,
"^%s([[:space:]]+[[:digit:]]+){3}[[:space:]]*$"
,
thread_id
);
regex_t
thread_data_regex
;
if
(
regcomp
(
&
thread_data_regex
,
thread_data_regex_s
,
REG_EXTENDED
|
REG_NEWLINE
)
!=
0
)
{
t_error
(
"Failed to compile regex %s"
,
thread_data_regex_s
);
return
NULL
;
}
regmatch_t
pmatch
[
REGEX_NMATCH
];
int
match_result
=
regexec
(
&
thread_data_regex
,
output
,
REGEX_NMATCH
,
pmatch
,
0
);
regfree
(
&
thread_data_regex
);
if
(
match_result
!=
0
)
{
return
NULL
;
}
return
output
+
pmatch
[
0
].
rm_so
;
}
static
int
populate_thread_stats
(
const
char
*
output
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
)
{
char
*
thread_id_start
=
strstr
(
input
,
thread_id
);
if
(
thread_id_start
==
NULL
)
{
const
char
*
thread_data_start
=
find_thread_in_output
(
output
,
thread_id
);
if
(
thread_data_start
==
NULL
)
{
t_error
(
"Failed to find thread id %s in output"
,
thread_id
);
return
0
;
}
thread_id_start
+=
strlen
(
thread_id
);
thread_data_start
+=
strlen
(
thread_id
);
int
result
=
1
;
result
&=
parse_amount
(
&
thread_
id
_start
,
&
stats
->
total_allocated_memory
);
result
&=
parse_amount
(
&
thread_
id
_start
,
&
stats
->
total_mmapped_memory
);
result
&=
parse_amount
(
&
thread_
id
_start
,
&
stats
->
mmapped_regions
);
result
&=
parse_amount
(
&
thread_
data
_start
,
&
stats
->
total_allocated_memory
);
result
&=
parse_amount
(
&
thread_
data
_start
,
&
stats
->
total_mmapped_memory
);
result
&=
parse_amount
(
&
thread_
data
_start
,
&
stats
->
mmapped_regions
);
return
result
;
}
static
int
populate_total_free_heap_space
(
const
char
*
in
put
,
long
long
*
total_free_heap_space
)
static
int
populate_total_free_heap_space
(
const
char
*
out
put
,
long
long
*
total_free_heap_space
)
{
c
har
*
free_heap_space_start
=
strstr
(
in
put
,
"total free heap space:"
);
c
onst
char
*
free_heap_space_start
=
strstr
(
out
put
,
"total free heap space:"
);
if
(
free_heap_space_start
==
NULL
)
{
return
0
;
}
free_heap_space_start
+=
strlen
(
"total free heap space:"
);
return
parse_amount
(
&
free_heap_space_start
,
total_free_heap_space
);
}
static
int
is_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
{
return
find_thread_in_output
(
output
,
thread_id
)
!=
NULL
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录