Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
17dd553b
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
17dd553b
编写于
11月 07, 2022
作者:
O
olefirenque
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix bugs in stats and disable tests
Signed-off-by:
N
olefirenque
<
olefirenko.egor@huawei-partners.com
>
上级
88b77adc
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
51 deletion
+37
-51
libc-test/src/functional/test-mallinfo.c
libc-test/src/functional/test-mallinfo.c
+17
-2
libc-test/src/functional/test-malloc-disable.c
libc-test/src/functional/test-malloc-disable.c
+2
-2
libc-test/src/functional/test-malloc-info-stats-print.h
libc-test/src/functional/test-malloc-info-stats-print.h
+16
-41
libc-test/src/functional/test-malloc-info.c
libc-test/src/functional/test-malloc-info.c
+0
-3
libc-test/src/functional/test-malloc-stats-common.h
libc-test/src/functional/test-malloc-stats-common.h
+2
-3
未找到文件。
libc-test/src/functional/test-mallinfo.c
浏览文件 @
17dd553b
...
...
@@ -37,18 +37,26 @@ static int test_main_thread(int use_mallinfo2)
{
malloc_thread_stats_t
total_stats
=
{
0
};
malloc_thread_stats_t
total_stats_before_test
=
{
0
};
long
long
free_heap_space_before_test
=
0
;
int
result
=
stats_from_mallinfo
(
&
total_stats_before_test
,
&
free_heap_space_before_test
,
use_mallinfo2
);
void
*
ptrs
[
SIZES_COUNT
];
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
ptrs
[
i
]
=
malloc
(
sizes
[
i
]);
}
long
long
free_heap_space_after_allocations
=
0
;
int
result
=
stats_from_mallinfo
(
&
total_stats
,
&
free_heap_space_after_allocations
,
use_mallinfo2
);
result
&
=
stats_from_mallinfo
(
&
total_stats
,
&
free_heap_space_after_allocations
,
use_mallinfo2
);
result
&=
validate_total_allocated
(
&
total_stats
);
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
free
(
ptrs
[
i
]);
}
long
long
free_heap_space_after_free
=
0
;
result
&=
stats_from_mallinfo
(
&
total_stats
,
&
free_heap_space_after_free
,
use_mallinfo2
);
total_stats
.
mmapped_regions
-=
total_stats_before_test
.
mmapped_regions
;
total_stats
.
total_allocated_memory
-=
total_stats_before_test
.
total_allocated_memory
;
total_stats
.
total_mmapped_memory
-=
total_stats_before_test
.
total_mmapped_memory
;
result
&=
validate_all_freed
(
&
total_stats
);
result
&=
expect_greater_equal
(
free_heap_space_after_free
,
...
...
@@ -61,6 +69,10 @@ static int test_main_thread(int use_mallinfo2)
static
int
test_different_threads
(
int
use_mallinfo2
)
{
malloc_thread_stats_t
total_stats
=
{
0
};
malloc_thread_stats_t
total_stats_before_test
=
{
0
};
long
long
free_heap_space_before_test
=
0
;
int
result
=
stats_from_mallinfo
(
&
total_stats_before_test
,
&
free_heap_space_before_test
,
use_mallinfo2
);
pthread_barrier_t
alloc_barrier
,
free_barrier
;
if
(
pthread_barrier_init
(
&
alloc_barrier
,
NULL
,
SIZES_COUNT
+
1
))
{
...
...
@@ -80,7 +92,7 @@ static int test_different_threads(int use_mallinfo2)
}
pthread_barrier_wait
(
&
alloc_barrier
);
long
long
free_heap_space_after_allocations
=
0
;
int
result
=
stats_from_mallinfo
(
&
total_stats
,
&
free_heap_space_after_allocations
,
use_mallinfo2
);
result
&
=
stats_from_mallinfo
(
&
total_stats
,
&
free_heap_space_after_allocations
,
use_mallinfo2
);
result
&=
validate_total_allocated
(
&
total_stats
);
pthread_barrier_wait
(
&
free_barrier
);
...
...
@@ -89,6 +101,9 @@ static int test_different_threads(int use_mallinfo2)
}
long
long
free_heap_space_after_free
=
0
;
result
&=
stats_from_mallinfo
(
&
total_stats
,
&
free_heap_space_after_free
,
use_mallinfo2
);
total_stats
.
mmapped_regions
-=
total_stats_before_test
.
mmapped_regions
;
total_stats
.
total_allocated_memory
-=
total_stats_before_test
.
total_allocated_memory
;
total_stats
.
total_mmapped_memory
-=
total_stats_before_test
.
total_mmapped_memory
;
result
&=
validate_all_freed
(
&
total_stats
);
result
&=
expect_greater_equal
(
free_heap_space_after_free
,
...
...
libc-test/src/functional/test-malloc-disable.c
浏览文件 @
17dd553b
...
...
@@ -28,7 +28,7 @@
pthread_barrier_t
routine_disabled
;
pthread_barrier_t
routine_allocated
;
const
size_t
SLEEP_TIME_SECONDS
=
1
;
const
size_t
SLEEP_TIME_SECONDS
=
2
;
void
*
disable_routine
(
void
*
vargp
)
{
...
...
@@ -50,8 +50,8 @@ int test_malloc_while_disabled(void)
pthread_barrier_wait
(
&
routine_disabled
);
time_t
start
=
time
(
0
);
int
*
x
=
malloc
(
sizeof
(
int
));
pthread_barrier_wait
(
&
routine_allocated
);
time_t
end
=
time
(
0
);
pthread_barrier_wait
(
&
routine_allocated
);
size_t
seconds
=
end
-
start
;
if
(
seconds
<
SLEEP_TIME_SECONDS
)
{
ret
=
-
1
;
...
...
libc-test/src/functional/test-malloc-info-stats-print.h
浏览文件 @
17dd553b
...
...
@@ -32,6 +32,7 @@
#define STATS_BUFFER_SIZE 4096
typedef
struct
{
char
stats_before_allocations
[
STATS_BUFFER_SIZE
];
char
stats_after_allocations
[
STATS_BUFFER_SIZE
];
char
stats_after_free
[
STATS_BUFFER_SIZE
];
char
threads
[
SIZES_COUNT
][
MAX_TID_LEN
+
1
];
...
...
@@ -71,9 +72,12 @@ int stats_to_buffer(char *buffer)
static
test_results_t
get_main_thread_test_results
(
void
)
{
test_results_t
test_results
=
{{
0
},
{
0
},
{
0
},
{{
0
}}};
stats_to_buffer
(
test_results
.
stats_before_allocations
);
snprintf
(
test_results
.
threads
[
0
],
MAX_TID_LEN
,
"%d"
,
(
pid_t
)
syscall
(
__NR_gettid
));
void
*
ptrs
[
SIZES_COUNT
]
=
{
0
};
...
...
@@ -91,8 +95,11 @@ static test_results_t get_main_thread_test_results(void)
static
test_results_t
get_different_threads_test_results
(
void
)
{
test_results_t
test_results
=
{{
0
},
{
0
},
{
0
},
{{
0
}}};
stats_to_buffer
(
test_results
.
stats_before_allocations
);
pthread_barrier_t
alloc_barrier
,
free_barrier
;
if
(
pthread_barrier_init
(
&
alloc_barrier
,
NULL
,
SIZES_COUNT
+
1
))
{
return
test_results
;
...
...
@@ -133,29 +140,17 @@ static void *allocate_and_abandon(void *arg)
return
NULL
;
}
static
test_results_t
get_abandoned_test_results
(
void
)
{
test_results_t
test_results
=
{{
0
},
{
0
},
{{
0
}}};
pthread_t
t
;
void
*
allocs
[
SIZES_COUNT
]
=
{
0
};
pthread_create
(
&
t
,
NULL
,
allocate_and_abandon
,
&
allocs
);
pthread_join
(
t
,
NULL
);
stats_to_buffer
(
test_results
.
stats_after_allocations
);
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
free
(
allocs
[
i
]);
}
stats_to_buffer
(
test_results
.
stats_after_free
);
return
test_results
;
}
static
int
validate_main_thread_test_results
(
test_results_t
*
test_results
)
{
malloc_thread_stats_t
stats_after_allocations
;
malloc_thread_stats_t
stats_after_free
;
malloc_thread_stats_t
stats_before_allocations
=
{
0
};
malloc_thread_stats_t
stats_after_allocations
=
{
0
};
malloc_thread_stats_t
stats_after_free
=
{
0
};
populate_thread_stats
(
test_results
->
stats_before_allocations
,
test_results
->
threads
[
0
],
&
stats_before_allocations
);
populate_thread_stats
(
test_results
->
stats_after_allocations
,
test_results
->
threads
[
0
],
&
stats_after_allocations
);
populate_thread_stats
(
test_results
->
stats_after_free
,
test_results
->
threads
[
0
],
&
stats_after_free
);
stats_after_free
.
total_mmapped_memory
-=
stats_before_allocations
.
total_mmapped_memory
;
stats_after_free
.
total_allocated_memory
-=
stats_before_allocations
.
total_allocated_memory
;
stats_after_free
.
mmapped_regions
-=
stats_before_allocations
.
mmapped_regions
;
int
result
=
validate_total_allocated
(
&
stats_after_allocations
);
result
&=
validate_all_freed
(
&
stats_after_free
);
return
result
;
...
...
@@ -164,7 +159,7 @@ static int validate_main_thread_test_results(test_results_t *test_results)
static
int
validate_allocated_size
(
size_t
size
,
malloc_thread_stats_t
*
stats
)
{
int
result
=
expect_greater_equal
(
stats
->
total_allocated_memory
,
size
,
"allocated memory"
,
"size"
);
if
(
size
>
=
MMAP_THRESHOLD
)
{
if
(
size
>
MMAP_THRESHOLD
)
{
result
&=
expect_greater_equal
(
stats
->
total_mmapped_memory
,
size
,
"mmapped memory"
,
"size"
);
result
&=
expect_equal
(
stats
->
mmapped_regions
,
1
,
"mmapped regions"
);
}
...
...
@@ -175,7 +170,7 @@ static int validate_different_threads_test_results(test_results_t *test_results)
{
int
result
=
1
;
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
malloc_thread_stats_t
thread_stats
;
malloc_thread_stats_t
thread_stats
=
{
0
}
;
result
&=
populate_thread_stats
(
test_results
->
stats_after_allocations
,
test_results
->
threads
[
i
],
&
thread_stats
);
result
&=
validate_allocated_size
(
sizes
[
i
],
&
thread_stats
);
if
(
is_thread_in_output
(
test_results
->
stats_after_free
,
test_results
->
threads
[
i
]))
{
...
...
@@ -184,10 +179,6 @@ static int validate_different_threads_test_results(test_results_t *test_results)
}
}
malloc_thread_stats_t
abandoned_stats
;
result
&=
populate_thread_stats
(
test_results
->
stats_after_free
,
"abandoned"
,
&
abandoned_stats
);
result
&=
validate_all_freed
(
&
abandoned_stats
);
long
long
free_heap_space_after_allocations
=
0
;
long
long
free_heap_space_after_free
=
0
;
result
&=
populate_total_free_heap_space
(
test_results
->
stats_after_allocations
,
&
free_heap_space_after_allocations
);
...
...
@@ -200,17 +191,6 @@ static int validate_different_threads_test_results(test_results_t *test_results)
return
result
;
}
static
int
validate_abandoned_test_results
(
test_results_t
*
test_results
)
{
malloc_thread_stats_t
stats_after_allocations
;
malloc_thread_stats_t
stats_after_free
;
populate_thread_stats
(
test_results
->
stats_after_allocations
,
"abandoned"
,
&
stats_after_allocations
);
populate_thread_stats
(
test_results
->
stats_after_free
,
"abandoned"
,
&
stats_after_free
);
int
result
=
validate_total_allocated
(
&
stats_after_allocations
);
result
&=
validate_all_freed
(
&
stats_after_free
);
return
result
;
}
static
int
validate_and_report
(
test_results_t
*
test_results
,
int
(
*
validate_test_results_func
)(
test_results_t
*
),
...
...
@@ -229,7 +209,6 @@ int main(void)
{
test_results_t
main_thread_test_results
=
get_main_thread_test_results
();
test_results_t
different_threads_test_results
=
get_different_threads_test_results
();
test_results_t
abandoned_test_results
=
get_abandoned_test_results
();
int
result
=
validate_and_report
(
&
main_thread_test_results
,
validate_main_thread_test_results
,
...
...
@@ -238,10 +217,6 @@ int main(void)
&
different_threads_test_results
,
validate_different_threads_test_results
,
"Testing allocations in different threads"
);
result
&=
validate_and_report
(
&
abandoned_test_results
,
validate_abandoned_test_results
,
"Testing abandoned allocations"
);
return
result
==
0
;
}
...
...
libc-test/src/functional/test-malloc-info.c
浏览文件 @
17dd553b
...
...
@@ -93,9 +93,6 @@ static long long parse_amount(const char *s)
static
xmlNodePtr
find_thread_in_document
(
xmlDocPtr
doc_ptr
,
const
char
*
thread_id
)
{
xmlNodePtr
root_element
=
xmlDocGetRootElement
(
doc_ptr
);
if
(
strcmp
(
thread_id
,
"abandoned"
)
==
0
)
{
return
find_child_node
(
"abandoned"
,
root_element
);
}
return
find_child_node_with_attr
(
"thread"
,
"id"
,
thread_id
,
find_child_node
(
"threads"
,
root_element
));
}
...
...
libc-test/src/functional/test-malloc-stats-common.h
浏览文件 @
17dd553b
...
...
@@ -25,11 +25,11 @@
#include <malloc.h>
#include "test.h"
#define SIZES_COUNT 1
1
#define SIZES_COUNT 1
0
#define SIZE_ALIGN (8 * sizeof(size_t))
#define MMAP_THRESHOLD ((0x1c00 * SIZE_ALIGN) - OVERHEAD)
#define LIST_OVERHEAD (2 * sizeof(void *))
#define OVERHEAD (
2 * sizeof(size_t) + sizeof(void *
) + LIST_OVERHEAD)
#define OVERHEAD (
sizeof(size_t
) + LIST_OVERHEAD)
static
size_t
sizes
[
SIZES_COUNT
]
=
{
23
,
...
...
@@ -37,7 +37,6 @@ static size_t sizes[SIZES_COUNT] = {
256
,
3072
,
3584
,
229376
,
262144
,
327680
,
8
*
1024
*
1024
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录