Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
a27422b5
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
接近 2 年 前同步成功
通知
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看板
提交
a27422b5
编写于
10月 06, 2022
作者:
M
Maxim Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reformat tests
Signed-off-by:
N
Maxim Polyakov
<
polyakov.maksim@huawei.com
>
上级
8e473890
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
433 addition
and
492 deletion
+433
-492
libc-test/src/functional/test-iterate.c
libc-test/src/functional/test-iterate.c
+107
-119
libc-test/src/functional/test-mallinfo.c
libc-test/src/functional/test-mallinfo.c
+82
-85
libc-test/src/functional/test-malloc-api-common.h
libc-test/src/functional/test-malloc-api-common.h
+8
-11
libc-test/src/functional/test-malloc-backtrace.c
libc-test/src/functional/test-malloc-backtrace.c
+2
-2
libc-test/src/functional/test-malloc-disable.c
libc-test/src/functional/test-malloc-disable.c
+1
-2
libc-test/src/functional/test-malloc-info-stats-print.h
libc-test/src/functional/test-malloc-info-stats-print.h
+156
-172
libc-test/src/functional/test-malloc-info.c
libc-test/src/functional/test-malloc-info.c
+25
-43
libc-test/src/functional/test-malloc-stats-common.h
libc-test/src/functional/test-malloc-stats-common.h
+6
-12
libc-test/src/functional/test-malloc-stats-print.c
libc-test/src/functional/test-malloc-stats-print.c
+46
-46
未找到文件。
libc-test/src/functional/test-iterate.c
浏览文件 @
a27422b5
...
@@ -26,16 +26,14 @@
...
@@ -26,16 +26,14 @@
#define ALLOCATIONS_NUMBER 8
#define ALLOCATIONS_NUMBER 8
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
typedef
struct
iterate_arg_s
typedef
struct
iterate_arg_s
{
{
uintptr_t
allocs
[
ALLOCATIONS_NUMBER
];
uintptr_t
allocs
[
ALLOCATIONS_NUMBER
];
size_t
allocs_reported_number
[
ALLOCATIONS_NUMBER
];
size_t
allocs_reported_number
[
ALLOCATIONS_NUMBER
];
size_t
allocs_actual_sizes
[
ALLOCATIONS_NUMBER
];
size_t
allocs_actual_sizes
[
ALLOCATIONS_NUMBER
];
size_t
reported_sizes
[
ALLOCATIONS_NUMBER
];
size_t
reported_sizes
[
ALLOCATIONS_NUMBER
];
}
iterate_arg_t
;
}
iterate_arg_t
;
typedef
struct
typedef
struct
{
{
uintptr_t
*
base
;
uintptr_t
*
base
;
size_t
size
;
size_t
size
;
}
allocations_info_t
;
}
allocations_info_t
;
...
@@ -53,17 +51,14 @@ static const size_t allocs_sizes[ALLOCATIONS_NUMBER] = {
...
@@ -53,17 +51,14 @@ static const size_t allocs_sizes[ALLOCATIONS_NUMBER] = {
void
iterate_callback
(
void
*
base
,
size_t
size
,
void
*
data
)
void
iterate_callback
(
void
*
base
,
size_t
size
,
void
*
data
)
{
{
iterate_arg_t
*
iterate_arg
=
(
iterate_arg_t
*
)
data
;
iterate_arg_t
*
iterate_arg
=
(
iterate_arg_t
*
)
data
;
uintptr_t
end
;
uintptr_t
end
;
if
(
__builtin_add_overflow
((
uintptr_t
)
base
,
size
,
&
end
))
if
(
__builtin_add_overflow
((
uintptr_t
)
base
,
size
,
&
end
))
{
{
return
;
return
;
}
}
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
{
{
if
(
iterate_arg
->
allocs
[
i
]
>=
(
uintptr_t
)
base
&&
iterate_arg
->
allocs
[
i
]
<
end
)
{
if
(
iterate_arg
->
allocs
[
i
]
>=
(
uintptr_t
)
base
&&
iterate_arg
->
allocs
[
i
]
<
end
)
{
iterate_arg
->
allocs_reported_number
[
i
]
++
;
iterate_arg
->
allocs_reported_number
[
i
]
++
;
uintptr_t
max_size
=
end
-
iterate_arg
->
allocs
[
i
];
uintptr_t
max_size
=
end
-
iterate_arg
->
allocs
[
i
];
iterate_arg
->
reported_sizes
[
i
]
=
MIN
(
size
,
max_size
);
iterate_arg
->
reported_sizes
[
i
]
=
MIN
(
size
,
max_size
);
...
@@ -78,21 +73,18 @@ void fill_allocations_info(const iterate_arg_t *iterate_arg, allocations_info_t
...
@@ -78,21 +73,18 @@ void fill_allocations_info(const iterate_arg_t *iterate_arg, allocations_info_t
const
uintptr_t
*
allocs
=
iterate_arg
->
allocs
;
const
uintptr_t
*
allocs
=
iterate_arg
->
allocs
;
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
{
{
if
(
allocs
[
i
]
>
max_val
)
{
if
(
allocs
[
i
]
>
max_val
)
{
max_val
=
allocs
[
i
];
max_val
=
allocs
[
i
];
max_idx
=
i
;
max_idx
=
i
;
}
}
if
(
allocs
[
i
]
<
min_val
)
if
(
allocs
[
i
]
<
min_val
)
{
{
min_val
=
allocs
[
i
];
min_val
=
allocs
[
i
];
min_idx
=
i
;
min_idx
=
i
;
}
}
}
}
allocations_info
->
base
=
(
void
*
)
allocs
[
min_idx
];
allocations_info
->
base
=
(
void
*
)
allocs
[
min_idx
];
allocations_info
->
size
=
allocs
[
max_idx
]
-
allocs
[
min_idx
]
+
allocs_sizes
[
max_idx
];
allocations_info
->
size
=
allocs
[
max_idx
]
-
allocs
[
min_idx
]
+
allocs_sizes
[
max_idx
];
}
}
...
@@ -101,10 +93,9 @@ void make_allocations(iterate_arg_t *iterate_arg)
...
@@ -101,10 +93,9 @@ void make_allocations(iterate_arg_t *iterate_arg)
uintptr_t
*
allocs
=
iterate_arg
->
allocs
;
uintptr_t
*
allocs
=
iterate_arg
->
allocs
;
size_t
*
allocs_actual_sizes
=
iterate_arg
->
allocs_actual_sizes
;
size_t
*
allocs_actual_sizes
=
iterate_arg
->
allocs_actual_sizes
;
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
{
{
allocs
[
i
]
=
(
uintptr_t
)
malloc
(
allocs_sizes
[
i
]);
allocs
[
i
]
=
(
uintptr_t
)
malloc
(
allocs_sizes
[
i
]);
allocs_actual_sizes
[
i
]
=
malloc_usable_size
((
void
*
)
allocs
[
i
]);
allocs_actual_sizes
[
i
]
=
malloc_usable_size
((
void
*
)
allocs
[
i
]);
}
}
}
}
...
@@ -112,9 +103,8 @@ void free_allocations(iterate_arg_t *iterate_arg)
...
@@ -112,9 +103,8 @@ void free_allocations(iterate_arg_t *iterate_arg)
{
{
uintptr_t
*
allocs
=
iterate_arg
->
allocs
;
uintptr_t
*
allocs
=
iterate_arg
->
allocs
;
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
{
{
free
((
void
*
)
allocs
[
i
]);
free
((
void
*
)
allocs
[
i
]);
}
}
}
}
...
@@ -125,10 +115,8 @@ int iterate_wrapper(iterate_arg_t *iterate_arg)
...
@@ -125,10 +115,8 @@ int iterate_wrapper(iterate_arg_t *iterate_arg)
fill_allocations_info
(
iterate_arg
,
&
allocations_info
);
fill_allocations_info
(
iterate_arg
,
&
allocations_info
);
malloc_iterate
(
allocations_info
.
base
,
allocations_info
.
size
,
iterate_callback
,
iterate_arg
);
malloc_iterate
(
allocations_info
.
base
,
allocations_info
.
size
,
iterate_callback
,
iterate_arg
);
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
for
(
size_t
i
=
0
;
i
<
ALLOCATIONS_NUMBER
;
++
i
)
{
{
if
(
iterate_arg
->
allocs_reported_number
[
i
]
!=
1
)
{
if
(
iterate_arg
->
allocs_reported_number
[
i
]
!=
1
)
{
ret
=
-
1
;
ret
=
-
1
;
}
}
}
}
...
@@ -140,7 +128,7 @@ pthread_barrier_t routine_iterated;
...
@@ -140,7 +128,7 @@ pthread_barrier_t routine_iterated;
void
*
allocate_routine
(
void
*
vargp
)
void
*
allocate_routine
(
void
*
vargp
)
{
{
iterate_arg_t
*
iterate_arg
=
(
iterate_arg_t
*
)
vargp
;
iterate_arg_t
*
iterate_arg
=
(
iterate_arg_t
*
)
vargp
;
make_allocations
(
iterate_arg
);
make_allocations
(
iterate_arg
);
pthread_barrier_wait
(
&
routine_allocated
);
pthread_barrier_wait
(
&
routine_allocated
);
pthread_barrier_wait
(
&
routine_iterated
);
pthread_barrier_wait
(
&
routine_iterated
);
...
@@ -149,7 +137,7 @@ void *allocate_routine(void *vargp)
...
@@ -149,7 +137,7 @@ void *allocate_routine(void *vargp)
void
*
abandoned_allocate_routine
(
void
*
vargp
)
void
*
abandoned_allocate_routine
(
void
*
vargp
)
{
{
iterate_arg_t
*
iterate_arg
=
(
iterate_arg_t
*
)
vargp
;
iterate_arg_t
*
iterate_arg
=
(
iterate_arg_t
*
)
vargp
;
make_allocations
(
iterate_arg
);
make_allocations
(
iterate_arg
);
return
NULL
;
return
NULL
;
}
}
...
@@ -171,7 +159,7 @@ int test_iterate_another_thread(void)
...
@@ -171,7 +159,7 @@ int test_iterate_another_thread(void)
pthread_barrier_init
(
&
routine_allocated
,
NULL
,
BARRIER_HEIGHT
);
pthread_barrier_init
(
&
routine_allocated
,
NULL
,
BARRIER_HEIGHT
);
pthread_barrier_init
(
&
routine_iterated
,
NULL
,
BARRIER_HEIGHT
);
pthread_barrier_init
(
&
routine_iterated
,
NULL
,
BARRIER_HEIGHT
);
pthread_t
thread_id
;
pthread_t
thread_id
;
pthread_create
(
&
thread_id
,
NULL
,
allocate_routine
,
(
void
*
)
&
iterate_arg_routine
);
pthread_create
(
&
thread_id
,
NULL
,
allocate_routine
,
(
void
*
)
&
iterate_arg_routine
);
pthread_barrier_wait
(
&
routine_allocated
);
pthread_barrier_wait
(
&
routine_allocated
);
ret
=
iterate_wrapper
(
&
iterate_arg_routine
);
ret
=
iterate_wrapper
(
&
iterate_arg_routine
);
free_allocations
(
&
iterate_arg_routine
);
free_allocations
(
&
iterate_arg_routine
);
...
@@ -184,7 +172,7 @@ int test_iterate_over_abandoned_allocs(void)
...
@@ -184,7 +172,7 @@ int test_iterate_over_abandoned_allocs(void)
int
ret
;
int
ret
;
iterate_arg_t
iterate_arg_routine
=
{{
0
},
{
0
},
{
0
},
{
0
}};
iterate_arg_t
iterate_arg_routine
=
{{
0
},
{
0
},
{
0
},
{
0
}};
pthread_t
thread_id
;
pthread_t
thread_id
;
pthread_create
(
&
thread_id
,
NULL
,
abandoned_allocate_routine
,
(
void
*
)
&
iterate_arg_routine
);
pthread_create
(
&
thread_id
,
NULL
,
abandoned_allocate_routine
,
(
void
*
)
&
iterate_arg_routine
);
pthread_join
(
thread_id
,
NULL
);
pthread_join
(
thread_id
,
NULL
);
ret
=
iterate_wrapper
(
&
iterate_arg_routine
);
ret
=
iterate_wrapper
(
&
iterate_arg_routine
);
free_allocations
(
&
iterate_arg_routine
);
free_allocations
(
&
iterate_arg_routine
);
...
...
libc-test/src/functional/test-mallinfo.c
浏览文件 @
a27422b5
...
@@ -54,8 +54,7 @@ static int test_main_thread(int use_mallinfo2)
...
@@ -54,8 +54,7 @@ static int test_main_thread(int use_mallinfo2)
free_heap_space_after_free
,
free_heap_space_after_free
,
free_heap_space_after_allocations
,
free_heap_space_after_allocations
,
"free heap space after free"
,
"free heap space after free"
,
"free heap space after allocations"
"free heap space after allocations"
);
);
return
result
;
return
result
;
}
}
...
@@ -95,16 +94,14 @@ static int test_different_threads(int use_mallinfo2)
...
@@ -95,16 +94,14 @@ static int test_different_threads(int use_mallinfo2)
free_heap_space_after_free
,
free_heap_space_after_free
,
free_heap_space_after_allocations
,
free_heap_space_after_allocations
,
"free heap space after free"
,
"free heap space after free"
,
"free heap space after allocations"
"free heap space after allocations"
);
);
return
result
;
return
result
;
}
}
static
int
test_and_report
(
static
int
test_and_report
(
int
(
*
test_func
)(
int
),
int
(
*
test_func
)(
int
),
int
test_func_arg
,
int
test_func_arg
,
const
char
*
message
const
char
*
message
)
)
{
{
t_printf
(
"%s..."
,
message
);
t_printf
(
"%s..."
,
message
);
if
(
!
test_func
(
test_func_arg
))
{
if
(
!
test_func
(
test_func_arg
))
{
...
...
libc-test/src/functional/test-malloc-api-common.h
浏览文件 @
a27422b5
...
@@ -22,12 +22,9 @@ int check_and_report(const char *message, int (*check_func)(void))
...
@@ -22,12 +22,9 @@ int check_and_report(const char *message, int (*check_func)(void))
{
{
t_printf
(
"%s..."
,
message
);
t_printf
(
"%s..."
,
message
);
int
ret
=
check_func
();
int
ret
=
check_func
();
if
(
ret
==
0
)
if
(
ret
==
0
)
{
{
t_printf
(
"Success
\n
"
);
t_printf
(
"Success
\n
"
);
}
}
else
{
else
{
t_error
(
"Failed
\n
"
);
t_error
(
"Failed
\n
"
);
}
}
return
ret
;
return
ret
;
...
...
libc-test/src/functional/test-malloc-backtrace.c
浏览文件 @
a27422b5
libc-test/src/functional/test-malloc-disable.c
浏览文件 @
a27422b5
...
@@ -53,8 +53,7 @@ int test_malloc_while_disabled(void)
...
@@ -53,8 +53,7 @@ int test_malloc_while_disabled(void)
pthread_barrier_wait
(
&
routine_allocated
);
pthread_barrier_wait
(
&
routine_allocated
);
time_t
end
=
time
(
0
);
time_t
end
=
time
(
0
);
size_t
seconds
=
end
-
start
;
size_t
seconds
=
end
-
start
;
if
(
seconds
<
SLEEP_TIME_SECONDS
)
if
(
seconds
<
SLEEP_TIME_SECONDS
)
{
{
ret
=
-
1
;
ret
=
-
1
;
}
}
free
(
x
);
free
(
x
);
...
...
libc-test/src/functional/test-malloc-info-stats-print.h
浏览文件 @
a27422b5
...
@@ -31,8 +31,7 @@
...
@@ -31,8 +31,7 @@
#define MAX_TID_LEN 32
#define MAX_TID_LEN 32
#define STATS_BUFFER_SIZE 4096
#define STATS_BUFFER_SIZE 4096
typedef
struct
typedef
struct
{
{
char
stats_after_allocations
[
STATS_BUFFER_SIZE
];
char
stats_after_allocations
[
STATS_BUFFER_SIZE
];
char
stats_after_free
[
STATS_BUFFER_SIZE
];
char
stats_after_free
[
STATS_BUFFER_SIZE
];
char
threads
[
SIZES_COUNT
][
MAX_TID_LEN
+
1
];
char
threads
[
SIZES_COUNT
][
MAX_TID_LEN
+
1
];
...
@@ -56,8 +55,7 @@ int stats_to_buffer(char *buffer)
...
@@ -56,8 +55,7 @@ int stats_to_buffer(char *buffer)
fflush
(
stderr
);
fflush
(
stderr
);
int
err_pipe
[
2
];
int
err_pipe
[
2
];
int
saved_stderr
=
dup
(
STDERR_FILENO
);
int
saved_stderr
=
dup
(
STDERR_FILENO
);
if
(
pipe
(
err_pipe
)
!=
0
)
if
(
pipe
(
err_pipe
)
!=
0
)
{
{
perror
(
"Can't create pipe"
);
perror
(
"Can't create pipe"
);
return
0
;
return
0
;
}
}
...
@@ -76,16 +74,14 @@ static test_results_t get_main_thread_test_results(void)
...
@@ -76,16 +74,14 @@ static test_results_t get_main_thread_test_results(void)
{
0
},
{
0
},
{{
0
}}};
{{
0
}}};
snprintf
(
test_results
.
threads
[
0
],
MAX_TID_LEN
,
"%d"
,
(
pid_t
)
syscall
(
__NR_gettid
));
snprintf
(
test_results
.
threads
[
0
],
MAX_TID_LEN
,
"%d"
,
(
pid_t
)
syscall
(
__NR_gettid
));
void
*
ptrs
[
SIZES_COUNT
]
=
{
0
};
void
*
ptrs
[
SIZES_COUNT
]
=
{
0
};
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
ptrs
[
i
]
=
malloc
(
sizes
[
i
]);
ptrs
[
i
]
=
malloc
(
sizes
[
i
]);
}
}
stats_to_buffer
(
test_results
.
stats_after_allocations
);
stats_to_buffer
(
test_results
.
stats_after_allocations
);
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
free
(
ptrs
[
i
]);
free
(
ptrs
[
i
]);
}
}
stats_to_buffer
(
test_results
.
stats_after_free
);
stats_to_buffer
(
test_results
.
stats_after_free
);
...
@@ -98,36 +94,30 @@ static test_results_t get_different_threads_test_results(void)
...
@@ -98,36 +94,30 @@ static test_results_t get_different_threads_test_results(void)
{
0
},
{
0
},
{{
0
}}};
{{
0
}}};
pthread_barrier_t
alloc_barrier
,
free_barrier
;
pthread_barrier_t
alloc_barrier
,
free_barrier
;
if
(
pthread_barrier_init
(
&
alloc_barrier
,
NULL
,
SIZES_COUNT
+
1
))
if
(
pthread_barrier_init
(
&
alloc_barrier
,
NULL
,
SIZES_COUNT
+
1
))
{
{
return
test_results
;
return
test_results
;
}
}
if
(
pthread_barrier_init
(
&
free_barrier
,
NULL
,
SIZES_COUNT
+
1
))
if
(
pthread_barrier_init
(
&
free_barrier
,
NULL
,
SIZES_COUNT
+
1
))
{
{
return
test_results
;
return
test_results
;
}
}
thread_data_t
thread_data
[
SIZES_COUNT
];
thread_data_t
thread_data
[
SIZES_COUNT
];
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
thread_data
[
i
]
=
(
thread_data_t
)
{
sizes
[
i
],
&
alloc_barrier
,
&
free_barrier
,
0
};
thread_data
[
i
]
=
(
thread_data_t
){
sizes
[
i
],
&
alloc_barrier
,
&
free_barrier
,
0
};
}
}
pthread_t
threads
[
SIZES_COUNT
];
pthread_t
threads
[
SIZES_COUNT
];
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
pthread_create
(
&
threads
[
i
],
NULL
,
allocate_wait_free
,
&
thread_data
[
i
]);
pthread_create
(
&
threads
[
i
],
NULL
,
allocate_wait_free
,
&
thread_data
[
i
]);
}
}
pthread_barrier_wait
(
&
alloc_barrier
);
pthread_barrier_wait
(
&
alloc_barrier
);
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
snprintf
(
test_results
.
threads
[
i
],
MAX_TID_LEN
,
"%d"
,
thread_data
[
i
].
self_id
);
snprintf
(
test_results
.
threads
[
i
],
MAX_TID_LEN
,
"%d"
,
thread_data
[
i
].
self_id
);
}
}
stats_to_buffer
(
test_results
.
stats_after_allocations
);
stats_to_buffer
(
test_results
.
stats_after_allocations
);
pthread_barrier_wait
(
&
free_barrier
);
pthread_barrier_wait
(
&
free_barrier
);
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
pthread_join
(
threads
[
i
],
NULL
);
pthread_join
(
threads
[
i
],
NULL
);
}
}
stats_to_buffer
(
test_results
.
stats_after_free
);
stats_to_buffer
(
test_results
.
stats_after_free
);
...
@@ -137,8 +127,7 @@ static test_results_t get_different_threads_test_results(void)
...
@@ -137,8 +127,7 @@ static test_results_t get_different_threads_test_results(void)
static
void
*
allocate_and_abandon
(
void
*
arg
)
static
void
*
allocate_and_abandon
(
void
*
arg
)
{
{
void
**
allocs
=
arg
;
void
**
allocs
=
arg
;
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
allocs
[
i
]
=
malloc
(
sizes
[
i
]);
allocs
[
i
]
=
malloc
(
sizes
[
i
]);
}
}
return
NULL
;
return
NULL
;
...
@@ -154,8 +143,7 @@ static test_results_t get_abandoned_test_results(void)
...
@@ -154,8 +143,7 @@ static test_results_t get_abandoned_test_results(void)
pthread_create
(
&
t
,
NULL
,
allocate_and_abandon
,
&
allocs
);
pthread_create
(
&
t
,
NULL
,
allocate_and_abandon
,
&
allocs
);
pthread_join
(
t
,
NULL
);
pthread_join
(
t
,
NULL
);
stats_to_buffer
(
test_results
.
stats_after_allocations
);
stats_to_buffer
(
test_results
.
stats_after_allocations
);
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
free
(
allocs
[
i
]);
free
(
allocs
[
i
]);
}
}
stats_to_buffer
(
test_results
.
stats_after_free
);
stats_to_buffer
(
test_results
.
stats_after_free
);
...
@@ -176,8 +164,7 @@ static int validate_main_thread_test_results(test_results_t *test_results)
...
@@ -176,8 +164,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
)
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"
);
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_greater_equal
(
stats
->
total_mmapped_memory
,
size
,
"mmapped memory"
,
"size"
);
result
&=
expect_equal
(
stats
->
mmapped_regions
,
1
,
"mmapped regions"
);
result
&=
expect_equal
(
stats
->
mmapped_regions
,
1
,
"mmapped regions"
);
}
}
...
@@ -187,13 +174,11 @@ static int validate_allocated_size(size_t size, malloc_thread_stats_t *stats)
...
@@ -187,13 +174,11 @@ static int validate_allocated_size(size_t size, malloc_thread_stats_t *stats)
static
int
validate_different_threads_test_results
(
test_results_t
*
test_results
)
static
int
validate_different_threads_test_results
(
test_results_t
*
test_results
)
{
{
int
result
=
1
;
int
result
=
1
;
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
malloc_thread_stats_t
thread_stats
;
malloc_thread_stats_t
thread_stats
;
result
&=
populate_thread_stats
(
test_results
->
stats_after_allocations
,
test_results
->
threads
[
i
],
&
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
);
result
&=
validate_allocated_size
(
sizes
[
i
],
&
thread_stats
);
if
(
is_thread_in_output
(
test_results
->
stats_after_free
,
test_results
->
threads
[
i
]))
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
]);
t_error
(
"Thread %s did not disappear from output
\n
"
,
test_results
->
threads
[
i
]);
result
=
0
;
result
=
0
;
}
}
...
@@ -232,8 +217,7 @@ static int validate_and_report(
...
@@ -232,8 +217,7 @@ static int validate_and_report(
const
char
*
message
)
const
char
*
message
)
{
{
t_printf
(
"%s..."
,
message
);
t_printf
(
"%s..."
,
message
);
if
(
!
validate_test_results_func
(
test_results
))
if
(
!
validate_test_results_func
(
test_results
))
{
{
t_error
(
"Failed!
\n
"
);
t_error
(
"Failed!
\n
"
);
return
0
;
return
0
;
}
}
...
...
libc-test/src/functional/test-malloc-info.c
浏览文件 @
a27422b5
...
@@ -20,10 +20,8 @@
...
@@ -20,10 +20,8 @@
static
const
xmlChar
*
get_text_from_children
(
xmlNodePtr
children
)
static
const
xmlChar
*
get_text_from_children
(
xmlNodePtr
children
)
{
{
for
(
xmlNodePtr
child_node
=
children
;
child_node
!=
NULL
;
child_node
=
child_node
->
next
)
for
(
xmlNodePtr
child_node
=
children
;
child_node
!=
NULL
;
child_node
=
child_node
->
next
)
{
{
if
(
child_node
->
type
==
XML_TEXT_NODE
)
{
if
(
child_node
->
type
==
XML_TEXT_NODE
)
{
return
child_node
->
content
;
return
child_node
->
content
;
}
}
}
}
...
@@ -32,10 +30,8 @@ static const xmlChar *get_text_from_children(xmlNodePtr children)
...
@@ -32,10 +30,8 @@ static const xmlChar *get_text_from_children(xmlNodePtr children)
static
const
xmlChar
*
get_attribute
(
const
char
*
attr_name
,
xmlNodePtr
node
)
static
const
xmlChar
*
get_attribute
(
const
char
*
attr_name
,
xmlNodePtr
node
)
{
{
for
(
xmlAttrPtr
curr_attr
=
node
->
properties
;
curr_attr
!=
NULL
;
curr_attr
=
curr_attr
->
next
)
for
(
xmlAttrPtr
curr_attr
=
node
->
properties
;
curr_attr
!=
NULL
;
curr_attr
=
curr_attr
->
next
)
{
{
if
(
xmlStrEqual
(
curr_attr
->
name
,
(
const
xmlChar
*
)
attr_name
))
{
if
(
xmlStrEqual
(
curr_attr
->
name
,
(
const
xmlChar
*
)
attr_name
))
{
return
get_text_from_children
(
curr_attr
->
children
);
return
get_text_from_children
(
curr_attr
->
children
);
}
}
}
}
...
@@ -44,20 +40,15 @@ static const xmlChar *get_attribute(const char *attr_name, xmlNodePtr node)
...
@@ -44,20 +40,15 @@ static const xmlChar *get_attribute(const char *attr_name, xmlNodePtr node)
static
xmlNodePtr
find_child_node_with_attr
(
const
char
*
name
,
const
char
*
attr_name
,
const
char
*
attr_value
,
xmlNodePtr
parent
)
static
xmlNodePtr
find_child_node_with_attr
(
const
char
*
name
,
const
char
*
attr_name
,
const
char
*
attr_value
,
xmlNodePtr
parent
)
{
{
if
(
parent
==
NULL
)
if
(
parent
==
NULL
)
{
{
return
NULL
;
return
NULL
;
}
}
for
(
xmlNodePtr
curr_node
=
parent
->
children
;
curr_node
!=
NULL
;
curr_node
=
curr_node
->
next
)
for
(
xmlNodePtr
curr_node
=
parent
->
children
;
curr_node
!=
NULL
;
curr_node
=
curr_node
->
next
)
{
{
if
(
curr_node
->
type
==
XML_ELEMENT_NODE
&&
xmlStrEqual
(
curr_node
->
name
,
(
xmlChar
*
)
name
))
{
if
(
curr_node
->
type
==
XML_ELEMENT_NODE
&&
xmlStrEqual
(
curr_node
->
name
,
(
xmlChar
*
)
name
))
if
(
attr_name
==
NULL
)
{
{
if
(
attr_name
==
NULL
)
{
return
curr_node
;
return
curr_node
;
}
}
if
(
xmlStrEqual
(
get_attribute
(
attr_name
,
curr_node
),
(
const
xmlChar
*
)
attr_value
))
if
(
xmlStrEqual
(
get_attribute
(
attr_name
,
curr_node
),
(
const
xmlChar
*
)
attr_value
))
{
{
return
curr_node
;
return
curr_node
;
}
}
}
}
...
@@ -72,11 +63,10 @@ static xmlNodePtr find_child_node(const char *name, xmlNodePtr parent)
...
@@ -72,11 +63,10 @@ static xmlNodePtr find_child_node(const char *name, xmlNodePtr parent)
static
const
char
*
get_node_text
(
xmlNodePtr
node_ptr
)
static
const
char
*
get_node_text
(
xmlNodePtr
node_ptr
)
{
{
if
(
node_ptr
==
NULL
)
if
(
node_ptr
==
NULL
)
{
{
return
NULL
;
return
NULL
;
}
}
return
(
const
char
*
)
get_text_from_children
(
node_ptr
->
children
);
return
(
const
char
*
)
get_text_from_children
(
node_ptr
->
children
);
}
}
static
void
stderr_stats_cb
(
void
)
static
void
stderr_stats_cb
(
void
)
...
@@ -86,18 +76,15 @@ static void stderr_stats_cb(void)
...
@@ -86,18 +76,15 @@ static void stderr_stats_cb(void)
static
long
long
parse_amount
(
const
char
*
s
)
static
long
long
parse_amount
(
const
char
*
s
)
{
{
if
(
s
==
NULL
)
if
(
s
==
NULL
)
{
{
return
-
1
;
return
-
1
;
}
}
char
*
end_ptr
;
char
*
end_ptr
;
long
long
result
=
strtoll
(
s
,
&
end_ptr
,
10
);
long
long
result
=
strtoll
(
s
,
&
end_ptr
,
10
);
if
(
end_ptr
!=
s
+
strlen
(
s
))
if
(
end_ptr
!=
s
+
strlen
(
s
))
{
{
return
-
1
;
return
-
1
;
}
}
if
(
result
<
0
)
if
(
result
<
0
)
{
{
return
-
1
;
return
-
1
;
}
}
return
result
;
return
result
;
...
@@ -106,8 +93,7 @@ static long long parse_amount(const char *s)
...
@@ -106,8 +93,7 @@ static long long parse_amount(const char *s)
static
xmlNodePtr
find_thread_in_document
(
xmlDocPtr
doc_ptr
,
const
char
*
thread_id
)
static
xmlNodePtr
find_thread_in_document
(
xmlDocPtr
doc_ptr
,
const
char
*
thread_id
)
{
{
xmlNodePtr
root_element
=
xmlDocGetRootElement
(
doc_ptr
);
xmlNodePtr
root_element
=
xmlDocGetRootElement
(
doc_ptr
);
if
(
strcmp
(
thread_id
,
"abandoned"
)
==
0
)
if
(
strcmp
(
thread_id
,
"abandoned"
)
==
0
)
{
{
return
find_child_node
(
"abandoned"
,
root_element
);
return
find_child_node
(
"abandoned"
,
root_element
);
}
}
return
find_child_node_with_attr
(
"thread"
,
"id"
,
thread_id
,
find_child_node
(
"threads"
,
root_element
));
return
find_child_node_with_attr
(
"thread"
,
"id"
,
thread_id
,
find_child_node
(
"threads"
,
root_element
));
...
@@ -115,9 +101,8 @@ static xmlNodePtr find_thread_in_document(xmlDocPtr doc_ptr, const char *thread_
...
@@ -115,9 +101,8 @@ static xmlNodePtr find_thread_in_document(xmlDocPtr doc_ptr, const char *thread_
static
int
populate_thread_stats
(
const
char
*
output
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
)
static
int
populate_thread_stats
(
const
char
*
output
,
const
char
*
thread_id
,
malloc_thread_stats_t
*
stats
)
{
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
if
(
doc_ptr
==
NULL
)
if
(
doc_ptr
==
NULL
)
{
{
return
0
;
return
0
;
}
}
xmlNodePtr
thread_root
=
find_thread_in_document
(
doc_ptr
,
thread_id
);
xmlNodePtr
thread_root
=
find_thread_in_document
(
doc_ptr
,
thread_id
);
...
@@ -129,8 +114,7 @@ static int populate_thread_stats(const char *output, const char *thread_id, mall
...
@@ -129,8 +114,7 @@ static int populate_thread_stats(const char *output, const char *thread_id, mall
parse_amount
(
get_node_text
(
find_child_node
(
"mmapped_regions"
,
thread_root
)));
parse_amount
(
get_node_text
(
find_child_node
(
"mmapped_regions"
,
thread_root
)));
xmlFreeDoc
(
doc_ptr
);
xmlFreeDoc
(
doc_ptr
);
if
(
total_allocated_memory
==
-
1
||
total_mmapped_memory
==
-
1
||
mmapped_regions
==
-
1
)
if
(
total_allocated_memory
==
-
1
||
total_mmapped_memory
==
-
1
||
mmapped_regions
==
-
1
)
{
{
return
0
;
return
0
;
}
}
stats
->
total_allocated_memory
=
total_allocated_memory
;
stats
->
total_allocated_memory
=
total_allocated_memory
;
...
@@ -141,27 +125,25 @@ static int populate_thread_stats(const char *output, const char *thread_id, mall
...
@@ -141,27 +125,25 @@ static int populate_thread_stats(const char *output, const char *thread_id, mall
static
int
populate_total_free_heap_space
(
const
char
*
output
,
long
long
*
total_free_heap_space
)
static
int
populate_total_free_heap_space
(
const
char
*
output
,
long
long
*
total_free_heap_space
)
{
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
if
(
doc_ptr
==
NULL
)
if
(
doc_ptr
==
NULL
)
{
{
return
0
;
return
0
;
}
}
xmlNodePtr
heap_space_root
=
find_child_node
(
"total_free_heap_space"
,
xmlDocGetRootElement
(
doc_ptr
));
xmlNodePtr
heap_space_root
=
find_child_node
(
"total_free_heap_space"
,
xmlDocGetRootElement
(
doc_ptr
));
long
long
total_free_heap_space_parsed
=
parse_amount
(
get_node_text
(
heap_space_root
));
long
long
total_free_heap_space_parsed
=
parse_amount
(
get_node_text
(
heap_space_root
));
xmlFreeDoc
(
doc_ptr
);
xmlFreeDoc
(
doc_ptr
);
if
(
total_free_heap_space_parsed
==
-
1
)
if
(
total_free_heap_space_parsed
==
-
1
)
{
{
return
0
;
return
0
;
}
}
*
total_free_heap_space
=
total_free_heap_space_parsed
;
*
total_free_heap_space
=
total_free_heap_space_parsed
;
return
1
;
return
1
;
}
}
static
int
is_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
static
int
is_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
{
{
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
xmlDocPtr
doc_ptr
=
xmlParseDoc
((
const
xmlChar
*
)
output
);
if
(
doc_ptr
==
NULL
)
if
(
doc_ptr
==
NULL
)
{
{
return
0
;
return
0
;
}
}
int
result
=
find_thread_in_document
(
doc_ptr
,
thread_id
)
!=
NULL
;
int
result
=
find_thread_in_document
(
doc_ptr
,
thread_id
)
!=
NULL
;
...
...
libc-test/src/functional/test-malloc-stats-common.h
浏览文件 @
a27422b5
...
@@ -45,15 +45,13 @@ static size_t sizes[SIZES_COUNT] = {
...
@@ -45,15 +45,13 @@ static size_t sizes[SIZES_COUNT] = {
32
*
1024
*
1024
32
*
1024
*
1024
};
};
typedef
struct
typedef
struct
{
{
long
long
mmapped_regions
;
long
long
mmapped_regions
;
long
long
total_mmapped_memory
;
long
long
total_mmapped_memory
;
long
long
total_allocated_memory
;
long
long
total_allocated_memory
;
}
malloc_thread_stats_t
;
}
malloc_thread_stats_t
;
typedef
struct
typedef
struct
{
{
size_t
alloc_size
;
size_t
alloc_size
;
pthread_barrier_t
*
alloc_barrier
;
pthread_barrier_t
*
alloc_barrier
;
pthread_barrier_t
*
free_barrier
;
pthread_barrier_t
*
free_barrier
;
...
@@ -63,10 +61,8 @@ typedef struct
...
@@ -63,10 +61,8 @@ typedef struct
static
malloc_thread_stats_t
get_total_from_test_sizes
()
static
malloc_thread_stats_t
get_total_from_test_sizes
()
{
{
malloc_thread_stats_t
total_stats
=
{
0
};
malloc_thread_stats_t
total_stats
=
{
0
};
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
for
(
size_t
i
=
0
;
i
<
SIZES_COUNT
;
i
++
)
{
{
if
(
sizes
[
i
]
>
MMAP_THRESHOLD
)
{
if
(
sizes
[
i
]
>
MMAP_THRESHOLD
)
{
total_stats
.
total_mmapped_memory
+=
sizes
[
i
];
total_stats
.
total_mmapped_memory
+=
sizes
[
i
];
total_stats
.
mmapped_regions
++
;
total_stats
.
mmapped_regions
++
;
}
}
...
@@ -77,8 +73,7 @@ static malloc_thread_stats_t get_total_from_test_sizes()
...
@@ -77,8 +73,7 @@ static malloc_thread_stats_t get_total_from_test_sizes()
static
int
expect_greater_equal
(
long
long
amt1
,
long
long
amt2
,
const
char
*
amt1_name
,
const
char
*
amt2_name
)
static
int
expect_greater_equal
(
long
long
amt1
,
long
long
amt2
,
const
char
*
amt1_name
,
const
char
*
amt2_name
)
{
{
if
(
amt1
>=
amt2
)
if
(
amt1
>=
amt2
)
{
{
return
1
;
return
1
;
}
}
t_error
(
"Expected %s(value: %lld) to be >= %s(value: %lld)
\n
"
,
amt1_name
,
amt1
,
amt2_name
,
amt2
);
t_error
(
"Expected %s(value: %lld) to be >= %s(value: %lld)
\n
"
,
amt1_name
,
amt1
,
amt2_name
,
amt2
);
...
@@ -87,8 +82,7 @@ static int expect_greater_equal(long long amt1, long long amt2, const char *amt1
...
@@ -87,8 +82,7 @@ static int expect_greater_equal(long long amt1, long long amt2, const char *amt1
static
int
expect_equal
(
long
long
amt
,
long
long
value
,
const
char
*
amt_name
)
static
int
expect_equal
(
long
long
amt
,
long
long
value
,
const
char
*
amt_name
)
{
{
if
(
amt
==
value
)
if
(
amt
==
value
)
{
{
return
1
;
return
1
;
}
}
t_error
(
"Expected %s(value: %lld) to be %lld
\n
"
,
amt_name
,
amt
,
value
);
t_error
(
"Expected %s(value: %lld) to be %lld
\n
"
,
amt_name
,
amt
,
value
);
...
...
libc-test/src/functional/test-malloc-stats-print.c
浏览文件 @
a27422b5
...
@@ -39,7 +39,7 @@ static int parse_amount(const char **s, long long *destination)
...
@@ -39,7 +39,7 @@ static int parse_amount(const char **s, long long *destination)
return
1
;
return
1
;
}
}
static
const
char
*
find_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
static
const
char
*
find_thread_in_output
(
const
char
*
output
,
const
char
*
thread_id
)
{
{
char
thread_data_regex_s
[
THREAD_DATA_REGEX_LEN
+
1
];
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
);
snprintf
(
thread_data_regex_s
,
THREAD_DATA_REGEX_LEN
,
"^%s([[:space:]]+[[:digit:]]+){3}[[:space:]]*$"
,
thread_id
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录