Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
423de4bb
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看板
未验证
提交
423de4bb
编写于
3月 30, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 30, 2023
浏览文件
操作
浏览文件
下载
差异文件
!826 Musl TDD用例覆盖
Merge pull request !826 from dhy308/release_tdd_0221
上级
28a305eb
81c6f1b2
变更
37
展开全部
隐藏空白更改
内联
并排
Showing
37 changed file
with
4306 addition
and
109 deletion
+4306
-109
libc-test/src/functionalext/dlns/BUILD.gn
libc-test/src/functionalext/dlns/BUILD.gn
+53
-3
libc-test/src/functionalext/dlns/dlns_dlopen.c
libc-test/src/functionalext/dlns/dlns_dlopen.c
+73
-0
libc-test/src/functionalext/dlns/dlns_dlopen_ext.c
libc-test/src/functionalext/dlns/dlns_dlopen_ext.c
+50
-0
libc-test/src/functionalext/dlns/dlns_test.h
libc-test/src/functionalext/dlns/dlns_test.h
+6
-0
libc-test/src/functionalext/info/application_target_sdk_version_test.c
.../functionalext/info/application_target_sdk_version_test.c
+13
-0
libc-test/src/functionalext/info/fatal_message.c
libc-test/src/functionalext/info/fatal_message.c
+34
-0
libc-test/src/functionalext/legacy/ulimit.c
libc-test/src/functionalext/legacy/ulimit.c
+18
-0
libc-test/src/functionalext/locale/langinfo.c
libc-test/src/functionalext/locale/langinfo.c
+54
-0
libc-test/src/functionalext/relro/dlopen_ext_relro_test.c
libc-test/src/functionalext/relro/dlopen_ext_relro_test.c
+1
-1
libc-test/src/functionalext/sched/sched_getparam.c
libc-test/src/functionalext/sched/sched_getparam.c
+39
-0
libc-test/src/functionalext/sched/sched_scheduler.c
libc-test/src/functionalext/sched/sched_scheduler.c
+41
-0
libc-test/src/functionalext/sched/sched_setparam.c
libc-test/src/functionalext/sched/sched_setparam.c
+29
-3
libc-test/src/functionalext/sched/test_src_functionalext_sched.gni
.../src/functionalext/sched/test_src_functionalext_sched.gni
+5
-1
libc-test/src/functionalext/supplement/network/inet_makeaddr.c
...test/src/functionalext/supplement/network/inet_makeaddr.c
+28
-0
libc-test/src/functionalext/supplement/network/inet_netof.c
libc-test/src/functionalext/supplement/network/inet_netof.c
+13
-0
libc-test/src/functionalext/supplement/passwd/getspnam_r.c
libc-test/src/functionalext/supplement/passwd/getspnam_r.c
+55
-1
libc-test/src/functionalext/time/strftime_ext.c
libc-test/src/functionalext/time/strftime_ext.c
+383
-0
libc-test/src/functionalext/time/strptime_ext.c
libc-test/src/functionalext/time/strptime_ext.c
+487
-0
libc-test/src/functionalext/trace/trace_marker.c
libc-test/src/functionalext/trace/trace_marker.c
+407
-0
libc-test/src/functionalext/unittest/BUILD.gn
libc-test/src/functionalext/unittest/BUILD.gn
+77
-4
libc-test/src/functionalext/unittest/unit_test_fatal_message.c
...test/src/functionalext/unittest/unit_test_fatal_message.c
+65
-0
libc-test/src/functionalext/unittest/unit_test_hilog_adapter.c
...test/src/functionalext/unittest/unit_test_hilog_adapter.c
+1
-1
libc-test/src/functionalext/unittest/unit_test_hilog_vsnprint_f_p.c
...src/functionalext/unittest/unit_test_hilog_vsnprint_f_p.c
+299
-7
libc-test/src/functionalext/unittest/unit_test_ldso_dynlink.c
...-test/src/functionalext/unittest/unit_test_ldso_dynlink.c
+708
-9
libc-test/src/functionalext/unittest/unit_test_ldso_ld_log.c
libc-test/src/functionalext/unittest/unit_test_ldso_ld_log.c
+1
-1
libc-test/src/functionalext/unittest/unit_test_ldso_namespace.c
...est/src/functionalext/unittest/unit_test_ldso_namespace.c
+681
-44
libc-test/src/functionalext/unittest/unit_test_ldso_ns_config.c
...est/src/functionalext/unittest/unit_test_ldso_ns_config.c
+395
-8
libc-test/src/functionalext/unittest/unit_test_ldso_strops.c
libc-test/src/functionalext/unittest/unit_test_ldso_strops.c
+102
-0
libc-test/src/functionalext/unittest/unit_test_mock_dynlink.c
...-test/src/functionalext/unittest/unit_test_mock_dynlink.c
+98
-0
libc-test/src/functionalext/unittest/unit_test_mock_fatal_message.c
...src/functionalext/unittest/unit_test_mock_fatal_message.c
+21
-0
libc-test/test_template.gni
libc-test/test_template.gni
+3
-1
musl_config.gni
musl_config.gni
+5
-0
musl_template.gni
musl_template.gni
+17
-4
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+23
-17
porting/linux/user/ldso/namespace.c
porting/linux/user/ldso/namespace.c
+7
-1
porting/linux/user/ldso/ns_config.c
porting/linux/user/ldso/ns_config.c
+7
-2
porting/linux/user/src/internal/dynlink.h
porting/linux/user/src/internal/dynlink.h
+7
-1
未找到文件。
libc-test/src/functionalext/dlns/BUILD.gn
浏览文件 @
423de4bb
...
...
@@ -16,6 +16,7 @@ import("../../../test_template.gni")
group("dlns_test") {
testonly = true
deps = [
":dlns_dlopen_ext_test",
":dlns_dlopen_test",
":dlns_dlsym_dep_a",
":dlns_dlsym_test",
...
...
@@ -23,6 +24,8 @@ group("dlns_test") {
":dlns_separated_test",
":dlns_set_fun_test",
":dlns_special_scene_test",
":dlopen_fill_random",
":dlopen_hash_sysv",
]
}
...
...
@@ -37,6 +40,8 @@ ohos_executable("dlns_dlopen_test") {
sources = [ "dlns_dlopen.c" ]
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
ldflags = [ "-Wl,-rpath=/data/tests/libc-test/src/" ]
}
ohos_executable("dlns_set_fun_test") {
...
...
@@ -50,7 +55,9 @@ ohos_executable("dlns_set_fun_test") {
sources = [ "dlns_set_fun.c" ]
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
libs = [ "${musl_lib_dir}/libc.a" ]
if (!musl_unit_test_flag) {
libs = [ "${musl_lib_dir}/libc.a" ]
}
}
ohos_executable("dlns_inherit_test") {
...
...
@@ -64,7 +71,9 @@ ohos_executable("dlns_inherit_test") {
sources = [ "dlns_inherit.c" ]
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
libs = [ "${musl_lib_dir}/libc.a" ]
if (!musl_unit_test_flag) {
libs = [ "${musl_lib_dir}/libc.a" ]
}
}
ohos_executable("dlns_separated_test") {
...
...
@@ -78,7 +87,9 @@ ohos_executable("dlns_separated_test") {
sources = [ "dlns_separated.c" ]
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
libs = [ "${musl_lib_dir}/libc.a" ]
if (!musl_unit_test_flag) {
libs = [ "${musl_lib_dir}/libc.a" ]
}
}
ohos_executable("dlns_special_scene_test") {
...
...
@@ -107,6 +118,15 @@ ohos_executable("dlns_dlsym_test") {
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
}
ohos_executable("dlns_dlopen_ext_test") {
subsystem_name = "musl"
part_name = "libc-test"
include_dirs = [ "../common" ]
sources = [ "dlns_dlopen_ext.c" ]
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
}
ohos_shared_library("dlns_dlsym_dep_c") {
include_dirs = [ "." ]
...
...
@@ -149,3 +169,33 @@ ohos_shared_library("dlns_dlsym_dep_a") {
subsystem_name = "musl"
part_name = "libc-test-lib"
}
ohos_shared_library("dlopen_hash_sysv") {
include_dirs = [ "." ]
sources = [ "dlns_dlsym_dep_c.c" ]
output_name = "dlopen_hash_sysv"
output_extension = "so"
subsystem_name = "musl"
part_name = "libc-test-lib"
ldflags = [ "-Wl,--hash-style=sysv" ]
}
ohos_shared_library("dlopen_fill_random") {
include_dirs = [ "." ]
sources = [ "dlns_dlsym_dep_c.c" ]
stack_protector_ret = true
output_name = "dlopen_fill_random"
output_extension = "so"
subsystem_name = "musl"
part_name = "libc-test-lib"
}
libc-test/src/functionalext/dlns/dlns_dlopen.c
浏览文件 @
423de4bb
...
...
@@ -269,6 +269,74 @@ void dlns_get_0400(void)
EXPECT_EQ
(
"dlns_get_0400"
,
dlns_get
(
"dlns_get_0400"
,
&
dlns
),
ENOKEY
);
}
/**
* @tc.name : dlopen_add_reloc
* @tc.desc : Test add_reloc_can_search_dso: not enough memory.
* Dlopen lib whth more than 32 dependent libs.(libace.z.so)
* @tc.level : Level 1
*/
void
dlopen_add_reloc
(
void
)
{
void
*
handle
=
dlopen
(
dllAcePath
,
RTLD_LAZY
);
EXPECT_TRUE
(
"dlopen_add_reloc"
,
handle
);
}
/**
* @tc.name : dlopen_relocation
* @tc.desc : Test dlopen lib relocation type is REL_DTPMOD/REL_DTPOFF.(libstd.dylib.so)
* @tc.level : Level 1
*/
void
dlopen_relocation
(
void
)
{
void
*
handle
=
dlopen
(
dllDylibPath
,
RTLD_LAZY
);
EXPECT_TRUE
(
"dlopen_relocation"
,
handle
);
if
(
handle
){
dlclose
(
handle
);
}
}
/**
* @tc.name : dlopen_hash_type
* @tc.desc : Test dlopen lib hash type is sysv.(libdlopen_hash_sysv.so)
* @tc.level : Level 1
*/
void
dlopen_hash_type
(
void
)
{
void
*
handle
=
dlopen
(
dllHashsysvPath
,
RTLD_LAZY
);
EXPECT_TRUE
(
"dlopen_hash_type"
,
handle
);
if
(
handle
){
dlclose
(
handle
);
}
}
/**
* @tc.name : dlopen_set_rpath
* @tc.desc : Test dlopen lib by set rpath.(libdlopen_hash_sysv.so)
* @tc.level : Level 1
*/
void
dlopen_set_rpath
(
void
)
{
void
*
handle
=
dlopen
(
dllHashsysv
,
RTLD_LAZY
);
EXPECT_TRUE
(
"dlopen_set_rpath"
,
handle
);
if
(
handle
){
dlclose
(
handle
);
}
}
/**
* @tc.name : dlopen_fill_random
* @tc.desc : Test dlopen lib libdlopen_fill_random.so to coverage fill_random_data.
* @tc.level : Level 1
*/
void
dlopen_fill_random
(
void
)
{
void
*
handle
=
dlopen
(
dllFillRandom
,
RTLD_LAZY
);
EXPECT_TRUE
(
"dlopen_fill_random"
,
handle
);
if
(
handle
){
dlclose
(
handle
);
}
}
TEST_FUN
G_Fun_Array
[]
=
{
dlopen_0100
,
dlopen_0200
,
...
...
@@ -288,6 +356,11 @@ TEST_FUN G_Fun_Array[] = {
dlns_get_0200
,
dlns_get_0300
,
dlns_get_0400
,
dlopen_relocation
,
dlopen_hash_type
,
dlopen_set_rpath
,
dlopen_fill_random
,
dlopen_add_reloc
,
};
int
main
(
void
)
...
...
libc-test/src/functionalext/dlns/dlns_dlopen_ext.c
0 → 100644
浏览文件 @
423de4bb
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dlfcn.h>
#include <dlfcn_ext.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "functionalext.h"
#include "dlns_test.h"
/**
* @tc.name : dlopen_ext_0100
* @tc.desc : extinfo flag is 0, call dlopen_ext, return handle is not NULL.
* @tc.level : Level 0
*/
void
dlopen_0100
(
void
)
{
dl_extinfo
extinfo
=
{
.
flag
=
0
,
.
relro_fd
=
-
1
,
};
Dl_namespace
dlns
;
dlns_init
(
&
dlns
,
"dlns_create_0100"
);
void
*
handle
=
dlopen_ns_ext
(
&
dlns
,
dllNamePath
,
RTLD_LAZY
,
&
extinfo
);
EXPECT_PTRNE
(
__FUNCTION__
,
handle
,
NULL
);
if
(
handle
){
dlclose
(
handle
);
};
}
int
main
(){
dlopen_0100
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/dlns/dlns_test.h
浏览文件 @
423de4bb
...
...
@@ -41,6 +41,12 @@ static const char* dllName_inh_007 = "inherit_0700.so";
static
const
char
*
dllName_inh_008
=
"inherit_0800.so"
;
static
const
char
*
dllName_inh_011
=
"inherit_1100.so"
;
static
const
char
*
dllAcePath
=
"/system/lib/libace.z.so"
;
static
const
char
*
dllDylibPath
=
"/system/lib/libstd.dylib.so"
;
static
const
char
*
dllHashsysvPath
=
"/data/tests/libc-test/src/libdlopen_hash_sysv.so"
;
static
const
char
*
dllHashsysv
=
"libdlopen_hash_sysv.so"
;
static
const
char
*
dllFillRandom
=
"/data/tests/libc-test/src/libdlopen_fill_random.so"
;
typedef
void
(
*
TEST_FUN
)(
void
);
static
const
int
EOK
=
0
;
...
...
libc-test/src/functionalext/info/application_target_sdk_version_test.c
浏览文件 @
423de4bb
...
...
@@ -50,9 +50,22 @@ static void get_application_target_sdk_version_0010(void)
EXPECT_EQ
(
target
,
SDK_VERSION_8
);
}
/**
* @tc.name : set_application_target_sdk_version
* @tc.desc : Test the function of set_application_target_sdk_version.
* @tc.level : Level 0
*/
static
void
set_application_target_sdk_version_0020
(
void
)
{
set_application_target_sdk_version
(
0
);
int
target
=
get_application_target_sdk_version
();
EXPECT_EQ
(
target
,
SDK_VERSION_FUTURE
);
}
TEST_FUN
G_Fun_Array
[]
=
{
set_application_target_sdk_version_0010
,
get_application_target_sdk_version_0010
,
set_application_target_sdk_version_0020
};
int
main
(
void
)
...
...
libc-test/src/functionalext/info/fatal_message.c
浏览文件 @
423de4bb
...
...
@@ -251,6 +251,39 @@ static void fatal_message_0060(void)
}
}
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the function of multi call set_fatal_message.
* @tc.level : Level 0
*/
static
void
fatal_message_0070
(
void
)
{
const
char
msg
[
1024
]
=
{
"abcdefghijklmnopqrstuvwxyz1234567890"
};
const
char
msg1
[
1024
]
=
{
"abcdefghijklmnopqr"
};
fatal_msg_t
*
fatal_message
=
NULL
;
int
pidParent
=
0
;
int
pidChild
=
0
;
pid_t
fpid
;
fpid
=
fork
();
if
(
fpid
<
0
)
{
t_printf
(
"error in fork!"
);
}
else
if
(
fpid
==
0
)
{
pidChild
=
getpid
();
set_fatal_message
(
msg
);
fatal_message
=
get_fatal_message
();
EXPECT_TRUE
(
strcmp
(
fatal_message
->
msg
,
msg
)
==
0
);
set_fatal_message
(
msg1
);
fatal_message
=
get_fatal_message
();
EXPECT_TRUE
(
strcmp
(
fatal_message
->
msg
,
msg
)
==
0
);
exit
(
pidChild
);
}
}
TEST_FUN
G_Fun_Array
[]
=
{
fatal_message_0010
,
fatal_message_0020
,
...
...
@@ -258,6 +291,7 @@ TEST_FUN G_Fun_Array[] = {
fatal_message_0040
,
fatal_message_0050
,
fatal_message_0060
,
fatal_message_0070
};
int
main
(
void
)
...
...
libc-test/src/functionalext/legacy/ulimit.c
浏览文件 @
423de4bb
...
...
@@ -53,9 +53,27 @@ static void ulimit_0200(void)
EXPECT_LONGEQ
(
"ulimit_0200"
,
MAX_FILE_SIZE
,
result
);
}
/**
* @tc.name : ulimit_0300
* @tc.desc : Test ulimit() with UL_SETFSIZE and invalid args
* @tc.level : Level 2
*/
static
void
ulimit_0300
(
void
)
{
int
cmd
=
UL_SETFSIZE
;
long
result
=
ulimit
(
cmd
,
-
1
);
if
(
result
>=
0
)
{
EXPECT_PTRNE
(
"ulimit_0300"
,
result
,
0
);
return
;
}
EXPECT_LONGEQ
(
"ulimit_0300"
,
-
1
,
result
);
}
int
main
(
void
)
{
ulimit_0100
();
ulimit_0200
();
ulimit_0300
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/locale/langinfo.c
浏览文件 @
423de4bb
...
...
@@ -144,6 +144,57 @@ void nl_langinfo_0600()
EXPECT_STREQ
(
"nl_langinfo_0600"
,
ptr
,
"C.UTF-8"
);
}
/**
* @tc.name : nl_langinfo_0700
* @tc.desc : Assert whether the return value result is not ""
* when the function nl_langinfo passes in the THOUSEP parameter
* @tc.level : Level 2
*/
void
nl_langinfo_0700
()
{
char
*
lo
=
setlocale
(
LC_ALL
,
""
);
if
(
!
lo
)
{
EXPECT_PTRNE
(
"nl_langinfo_0700"
,
lo
,
NULL
);
return
;
}
char
*
ptr
=
nl_langinfo
(
THOUSEP
);
EXPECT_STREQ
(
"nl_langinfo_0700"
,
ptr
,
""
);
}
/**
* @tc.name : nl_langinfo_0800
* @tc.desc : Assert whether the return value result is not ""
* when the function nl_langinfo passes in the THOUSEP * LC_MONETARY parameter
* @tc.level : Level 2
*/
void
nl_langinfo_0800
()
{
char
*
lo
=
setlocale
(
LC_ALL
,
""
);
if
(
!
lo
)
{
EXPECT_PTRNE
(
"nl_langinfo_0800"
,
lo
,
NULL
);
return
;
}
char
*
ptr
=
nl_langinfo
(
THOUSEP
*
LC_MONETARY
);
EXPECT_STREQ
(
"nl_langinfo_0800"
,
ptr
,
""
);
}
/**
* @tc.name : nl_langinfo_0900
* @tc.desc : Assert whether the return value result is not ""
* when the function nl_langinfo passes in the RADIXCHAR * LC_MONETARY parameter
* @tc.level : Level 2
*/
void
nl_langinfo_0900
()
{
char
*
lo
=
setlocale
(
LC_ALL
,
""
);
if
(
!
lo
)
{
EXPECT_PTRNE
(
"nl_langinfo_0900"
,
lo
,
NULL
);
return
;
}
char
*
ptr
=
nl_langinfo
(
RADIXCHAR
*
LC_MONETARY
);
EXPECT_STREQ
(
"nl_langinfo_0900"
,
ptr
,
""
);
}
int
main
(
void
)
{
langinfo_0100
();
...
...
@@ -152,5 +203,8 @@ int main(void)
nl_langinfo_0400
();
nl_langinfo_0500
();
nl_langinfo_0600
();
nl_langinfo_0700
();
nl_langinfo_0800
();
nl_langinfo_0900
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/relro/dlopen_ext_relro_test.c
浏览文件 @
423de4bb
...
...
@@ -24,7 +24,7 @@
#include "functionalext.h"
#include "test.h"
#define LIB_NAME "
.
/libdlopen_ext_relro_dso.so"
#define LIB_NAME "
/data/tests/libc-test/src
/libdlopen_ext_relro_dso.so"
#define RELRO_FILE_PATH "./TemporaryFile-XXXXXX"
#define RESERVED_ADDRESS_SIZE (64 * 1024 * 1024)
#define MIN_RESERVED_ADDRESS_SIZE 4096
...
...
libc-test/src/functionalext/sched/sched_getparam.c
0 → 100644
浏览文件 @
423de4bb
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <sched.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "functionalext.h"
#include "test.h"
/**
* @tc.name : sched_getparam
* @tc.desc : When param is NULL, call sched_getparam.
* @tc.level : Level 2
*/
static
void
sched_getparam_0010
(
void
)
{
pid_t
pid
;
pid
=
getpid
();
EXPECT_EQ
(
sched_getparam_0010
,
sched_getparam
(
pid
,
NULL
),
-
1
);
}
int
main
(
void
)
{
sched_getparam_0010
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/sched/sched_scheduler.c
0 → 100644
浏览文件 @
423de4bb
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <sched.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "functionalext.h"
#include "test.h"
/**
* @tc.name : sched_setscheduler
* @tc.desc : When param is NULL, call sched_getparam.
* @tc.level : Level 2
*/
static
void
sched_setscheduler_0010
(
void
)
{
pid_t
pid
;
pid
=
getpid
();
int
sched
;
sched
=
SCHED_FIFO
;
EXPECT_EQ
(
sched_setscheduler_0010
,
sched_setscheduler
(
pid
,
sched
,
NULL
),
-
1
);
}
int
main
(
void
)
{
sched_setscheduler_0010
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/sched/sched_setparam.c
浏览文件 @
423de4bb
/*
* Copyright (c) 202
2
Huawei Device Co., Ltd.
* Copyright (c) 202
3
Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
...
...
@@ -22,20 +22,46 @@
typedef
void
(
*
TEST_FUN
)(
void
);
/**
* @tc.name : sched_setparam
* @tc.desc : Test the function of sched_setparam with normal input.
* @tc.level : Level 1
*/
static
void
sched_setparam_0010
(
void
)
{
struct
sched_param
param
;
int
maxpri
,
minpri
;
pid_t
pid
;
int
sched
;
pid
=
getpid
();
sched
=
SCHED_OTHER
;
maxpri
=
sched_get_priority_max
(
sched
);
minpri
=
sched_get_priority_min
(
sched
);
if
(
maxpri
==
-
1
||
minpri
==
-
1
)
{
t_error
(
"get maxpriority or minpriority failed"
);
}
param
.
sched_priority
=
0
;
//取值范围:minpri~maxpri
EXPECT_EQ
(
"sched_setparam_0010"
,
sched_setparam
(
pid
,
&
param
),
0
);
}
/**
* @tc.name : sched_setparam
* @tc.desc : When param is NULL, call sched_setparam.
* @tc.level : Level 2
*/
static
void
sched_setparam_00
1
0
(
void
)
static
void
sched_setparam_00
2
0
(
void
)
{
pid_t
pid
;
pid
=
getpid
();
EXPECT_EQ
(
"sched_setparam_00
1
0"
,
sched_setparam
(
pid
,
NULL
),
-
1
);
EXPECT_EQ
(
"sched_setparam_00
2
0"
,
sched_setparam
(
pid
,
NULL
),
-
1
);
}
TEST_FUN
G_Fun_Array
[]
=
{
sched_setparam_0010
,
sched_setparam_0020
,
};
int
main
(
void
)
...
...
libc-test/src/functionalext/sched/test_src_functionalext_sched.gni
浏览文件 @
423de4bb
...
...
@@ -13,4 +13,8 @@
# limitations under the License.
#
functionalext_sched_list = [ "sched_setparam" ]
functionalext_sched_list = [
"sched_setparam",
"sched_getparam",
"sched_scheduler",
]
libc-test/src/functionalext/supplement/network/inet_makeaddr.c
浏览文件 @
423de4bb
...
...
@@ -32,8 +32,36 @@ void inet_makeaddr_0100(void)
EXPECT_EQ
(
"inet_makeaddr_0100"
,
htonl
(
IP
),
a
.
s_addr
);
}
/**
* @tc.name : inet_makeaddr_0200
* @tc.desc : Test the function of inet_makeaddr, n is 512.(n < 65536)
* @tc.level : Level 0
*/
void
inet_makeaddr_0200
(
void
)
{
const
uint32_t
net
=
0x00000200
;
const
uint32_t
ip
=
0x02000001
;
struct
in_addr
a
=
inet_makeaddr
(
net
,
HOST
);
EXPECT_EQ
(
"inet_makeaddr_0200"
,
htonl
(
ip
),
a
.
s_addr
);
}
/**
* @tc.name : inet_makeaddr_0300
* @tc.desc : Test the function of inet_makeaddr, n is 131072.(n > 65536)
* @tc.level : Level 0
*/
void
inet_makeaddr_0300
(
void
)
{
const
uint32_t
net
=
0x00020000
;
const
uint32_t
ip
=
0x02000001
;
struct
in_addr
a
=
inet_makeaddr
(
net
,
HOST
);
EXPECT_EQ
(
"inet_makeaddr_0200"
,
htonl
(
ip
),
a
.
s_addr
);
}
int
main
(
void
)
{
inet_makeaddr_0100
();
inet_makeaddr_0200
();
inet_makeaddr_0300
();
return
t_status
;
}
libc-test/src/functionalext/supplement/network/inet_netof.c
浏览文件 @
423de4bb
...
...
@@ -31,8 +31,21 @@ void inet_netof_0100(void)
EXPECT_EQ
(
"inet_netof_0100"
,
inet_netof
(
a
),
NET
);
}
/**
* @tc.name : inet_netof_0100
* @tc.desc : Test the function of inet_netof, n is 131072.(n > 65536)
* @tc.level : Level 0
*/
void
inet_netof_0200
(
void
)
{
const
uint32_t
net
=
0x00008000
;
struct
in_addr
a
=
{
htonl
(
0x80000001
)};
EXPECT_EQ
(
"inet_netof_0100"
,
inet_netof
(
a
),
net
);
}
int
main
(
void
)
{
inet_netof_0100
();
inet_netof_0200
();
return
t_status
;
}
libc-test/src/functionalext/supplement/passwd/getspnam_r.c
浏览文件 @
423de4bb
...
...
@@ -28,7 +28,6 @@ void getspnam_r_0100(void)
{
errno
=
0
;
char
buf
[
512
];
gid_t
gid
=
0
;
struct
spwd
*
spwd
;
struct
spwd
spwd_storage
;
...
...
@@ -40,8 +39,63 @@ void getspnam_r_0100(void)
EXPECT_EQ
(
"getspnam_r_0100"
,
strcmp
(
spwd_name
,
spwd
->
sp_namp
),
0
);
}
/**
* @tc.name : getspnam_r_0200
* @tc.desc : Buffer size not be able to hold name.(normal: buffer_size > strlen(name)+100)
* @tc.level : Level 2
*/
void
getspnam_r_0200
(
void
)
{
char
buf
[
10
];
struct
spwd
*
spwd
;
struct
spwd
spwd_storage
;
int
result
=
getspnam_r
(
"bin"
,
&
spwd_storage
,
buf
,
sizeof
(
buf
),
&
spwd
);
EXPECT_NE
(
"getspnam_r_0300"
,
result
,
0
);
EXPECT_PTREQ
(
"getspnam_r_0300"
,
spwd
,
NULL
);
}
/**
* @tc.name : getspnam_r_0300
* @tc.desc : Test the function of getspnam_r with invalid input(name).
* @tc.level : Level 2
*/
void
getspnam_r_0300
(
void
)
{
char
buf
[
512
];
struct
spwd
*
spwd
;
struct
spwd
spwd_storage
;
int
result
=
getspnam_r
(
"bin/"
,
&
spwd_storage
,
buf
,
sizeof
(
buf
),
&
spwd
);
EXPECT_NE
(
"getspnam_r_0400"
,
result
,
0
);
EXPECT_PTREQ
(
"getspnam_r_0400"
,
spwd
,
NULL
);
}
/**
* @tc.name : getspnam_r_0400
* @tc.desc : The length of name is greater than the NAME_MAX.
* @tc.level : Level 2
*/
void
getspnam_r_0400
(
void
)
{
char
buf
[
512
];
struct
spwd
*
spwd
;
struct
spwd
spwd_storage
;
char
name
[
300
]
=
{
0
};
memset
(
name
,
1
,
299
);
name
[
299
]
=
'\0'
;
int
result
=
getspnam_r
(
name
,
&
spwd_storage
,
buf
,
sizeof
(
buf
),
&
spwd
);
EXPECT_NE
(
"getspnam_r_0500"
,
result
,
0
);
EXPECT_PTREQ
(
"getspnam_r_0500"
,
spwd
,
NULL
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
getspnam_r_0100
();
getspnam_r_0200
();
getspnam_r_0300
();
getspnam_r_0400
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/time/strftime_ext.c
浏览文件 @
423de4bb
...
...
@@ -208,6 +208,372 @@ void strftime_0700(void)
EXPECT_STREQ
(
"strftime_0700"
,
buffer
,
"30-Jul-2022"
);
}
/**
* @tc.name : strftime_0800
* @tc.desc : according to different time zones, format date
* @tc.level : Level 0
*/
void
strftime_0800
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_0800 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_0800"
,
timeptr
,
NULL
);
return
;
}
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%j"
,
timeptr
);
EXPECT_TRUE
(
"strftime_0800"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_0800"
,
buffer
,
"211"
);
}
/**
* @tc.name : strftime_0900
* @tc.desc : according to different time zones, format date
* @tc.level : Level 0
*/
void
strftime_0900
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_0900 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_0900"
,
timeptr
,
NULL
);
return
;
}
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%l"
,
timeptr
);
EXPECT_TRUE
(
"strftime_0900"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_0900"
,
buffer
,
" 6"
);
}
/**
* @tc.name : strftime_1000
* @tc.desc : according to different time zones, format date
* @tc.level : Level 0
*/
void
strftime_1000
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_1000 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_1000"
,
timeptr
,
NULL
);
return
;
}
timeptr
->
tm_mday
=
31
;
timeptr
->
tm_mon
=
11
;
timeptr
->
tm_year
=
124
;
timeptr
->
tm_wday
=
2
;
timeptr
->
tm_yday
=
365
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%V"
,
timeptr
);
EXPECT_TRUE
(
"strftime_1000"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1000"
,
buffer
,
"01"
);
}
/**
* @tc.name : strftime_1100
* @tc.desc : according to different time zones, format date
* @tc.level : Level 0
*/
void
strftime_1100
(
void
)
{
struct
tm
tm
=
{
0
};
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%l"
,
&
tm
);
EXPECT_TRUE
(
"strftime_1100"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1100"
,
buffer
,
"12"
);
}
/**
* @tc.name : strftime_1200
* @tc.desc : according to different time zones, format date
* @tc.level : Level 0
*/
void
strftime_1200
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_1200 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_1200"
,
timeptr
,
NULL
);
return
;
}
timeptr
->
tm_mday
=
28
;
timeptr
->
tm_mon
=
12
;
timeptr
->
tm_year
=
200
;
timeptr
->
tm_wday
=
1
;
timeptr
->
tm_yday
=
362
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%G"
,
timeptr
);
EXPECT_TRUE
(
"strftime_1200"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1200"
,
buffer
,
"2101"
);
}
/**
* @tc.name : strftime_1300
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1300
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_1300 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_1300"
,
timeptr
,
NULL
);
return
;
}
timeptr
->
tm_mday
=
28
;
timeptr
->
tm_mon
=
12
;
timeptr
->
tm_year
=
100
;
timeptr
->
tm_wday
=
1
;
timeptr
->
tm_yday
=
362
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%G"
,
timeptr
);
EXPECT_TRUE
(
"strftime_1300"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1300"
,
buffer
,
"2000"
);
}
/**
* @tc.name : strftime_1400
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1400
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_1400 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_1400"
,
timeptr
,
NULL
);
return
;
}
timeptr
->
tm_mday
=
28
;
timeptr
->
tm_mon
=
12
;
timeptr
->
tm_year
=
101
;
timeptr
->
tm_wday
=
1
;
timeptr
->
tm_yday
=
362
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%G"
,
timeptr
);
EXPECT_TRUE
(
"strftime_1400"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1400"
,
buffer
,
"2002"
);
}
/**
* @tc.name : strftime_1500
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1500
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_1500 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_1500"
,
timeptr
,
NULL
);
return
;
}
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%B"
,
timeptr
);
EXPECT_TRUE
(
"strftime_1500"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1500"
,
buffer
,
"July"
);
}
/**
* @tc.name : strftime_1600
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1600
(
void
)
{
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strftime_1600 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strftime_1600"
,
timeptr
,
NULL
);
return
;
}
timeptr
->
tm_mon
=
12
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%B"
,
timeptr
);
EXPECT_TRUE
(
"strftime_1600"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1600"
,
buffer
,
"-"
);
}
/**
* @tc.name : strftime_1700
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1700
(
void
)
{
struct
tm
tm
=
{
0
};
tm
.
tm_hour
=
13
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%l"
,
&
tm
);
EXPECT_TRUE
(
"strftime_1700"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1700"
,
buffer
,
" 1"
);
}
/**
* @tc.name : strftime_1800
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1800
(
void
)
{
struct
tm
tm
=
{
0
};
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%u"
,
&
tm
);
EXPECT_TRUE
(
"strftime_1800"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1800"
,
buffer
,
"7"
);
}
/**
* @tc.name : strftime_1900
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_1900
(
void
)
{
struct
tm
tm
=
{
0
};
tm
.
tm_wday
=
3
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%u"
,
&
tm
);
EXPECT_TRUE
(
"strftime_1900"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_1900"
,
buffer
,
"3"
);
}
/**
* @tc.name : strftime_2000
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_2000
(
void
)
{
struct
tm
tm
=
{
0
};
tm
.
tm_year
=
-
1999
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%-y"
,
&
tm
);
EXPECT_TRUE
(
"strftime_2000"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_2000"
,
buffer
,
"99"
);
}
/**
* @tc.name : strftime_2100
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_2100
(
void
)
{
struct
tm
tm
=
{
0
};
tm
.
tm_isdst
=
-
1
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%z"
,
&
tm
);
EXPECT_TRUE
(
"strftime_2100"
,
count
==
0
);
EXPECT_STREQ
(
"strftime_2100"
,
buffer
,
""
);
}
/**
* @tc.name : strftime_2200
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_2200
(
void
)
{
struct
tm
tm
=
{
0
};
tm
.
tm_isdst
=
-
1
;
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%Z"
,
&
tm
);
EXPECT_TRUE
(
"strftime_2200"
,
count
==
0
);
EXPECT_STREQ
(
"strftime_2200"
,
buffer
,
""
);
}
/**
* @tc.name : strftime_2300
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_2300
(
void
)
{
struct
tm
tm
=
{
0
};
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%E%"
,
&
tm
);
EXPECT_TRUE
(
"strftime_2300"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_2300"
,
buffer
,
"%"
);
}
/**
* @tc.name : strftime_2200
* @tc.desc : according to different time zones, format date
* @tc.level : Level 1
*/
void
strftime_2400
(
void
)
{
struct
tm
tm
=
{
0
};
char
buffer
[
gBufferSize
];
size_t
count
=
strftime
(
buffer
,
sizeof
(
buffer
)
-
1
,
"%O%"
,
&
tm
);
EXPECT_TRUE
(
"strftime_2400"
,
count
>
0
);
EXPECT_STREQ
(
"strftime_2400"
,
buffer
,
"%"
);
}
int
main
(
void
)
{
strftime_0100
();
...
...
@@ -217,5 +583,22 @@ int main(void)
strftime_0500
();
strftime_0600
();
strftime_0700
();
strftime_0800
();
strftime_0900
();
strftime_1000
();
strftime_1100
();
strftime_1200
();
strftime_1300
();
strftime_1400
();
strftime_1500
();
strftime_1600
();
strftime_1700
();
strftime_1800
();
strftime_1900
();
strftime_2000
();
strftime_2100
();
strftime_2200
();
strftime_2300
();
strftime_2400
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/time/strptime_ext.c
浏览文件 @
423de4bb
...
...
@@ -263,6 +263,465 @@ void strptime_1100(void)
EXPECT_STREQ
(
"strptime_1100"
,
"22"
,
buffResult
);
}
/**
* @tc.name : strptime_1200
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 0
*/
void
strptime_1200
(
void
)
{
const
char
*
buffer
=
"am"
;
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strptime_1200 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strptime_1200"
,
timeptr
,
NULL
);
return
;
}
strptime
(
buffer
,
"%P"
,
timeptr
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d"
,
timeptr
->
tm_hour
);
EXPECT_TRUE
(
"strptime_1200"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1200"
,
"6"
,
buffResult
);
}
/**
* @tc.name : strptime_1300
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 0
*/
void
strptime_1300
(
void
)
{
const
char
*
buffer
=
"pm"
;
const
char
*
handlerChar
=
test_handle_path
(
"Asia/Shanghai"
);
if
(
!
handlerChar
)
{
t_error
(
"strptime_1300 failed: handlerChar is NULL
\n
"
);
return
;
}
setenv
(
"TZ"
,
handlerChar
,
1
);
tzset
();
struct
tm
*
timeptr
=
localtime
(
&
gTime
);
if
(
!
timeptr
)
{
EXPECT_PTRNE
(
"strptime_1300"
,
timeptr
,
NULL
);
return
;
}
strptime
(
buffer
,
"%P"
,
timeptr
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d"
,
timeptr
->
tm_hour
);
EXPECT_TRUE
(
"strptime_1300"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1300"
,
"18"
,
buffResult
);
}
/**
* @tc.name : strptime_1400
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 0
*/
void
strptime_1400
(
void
)
{
const
char
*
buffer
=
"30-Oct-2021"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%U"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%s"
,
result
);
EXPECT_TRUE
(
"strptime_1400"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1400"
,
"-Oct-2021"
,
buffResult
);
}
/**
* @tc.name : strptime_1500
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 0
*/
void
strptime_1500
(
void
)
{
const
char
*
buffer
=
"1"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%w"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d"
,
tmTime
.
tm_wday
);
EXPECT_TRUE
(
"strptime_1500"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1500"
,
"1"
,
buffResult
);
}
/**
* @tc.name : strptime_1600
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 0
*/
void
strptime_1600
(
void
)
{
const
char
*
buffer
=
"Oct-30-2021"
;
struct
tm
tmTime
=
{
0
};
strptime
(
buffer
,
"%v"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d-%d-%d"
,
(
tmTime
.
tm_year
+
gYearBase
),
tmTime
.
tm_mon
,
tmTime
.
tm_mday
);
EXPECT_TRUE
(
"strptime_1600"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1600"
,
"1900-0-0"
,
buffResult
);
}
/**
* @tc.name : strptime_1700
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 0
*/
void
strptime_1700
(
void
)
{
const
char
*
buffer
=
"16-Spring"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%V"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%s"
,
result
);
EXPECT_TRUE
(
"strptime_1700"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1700"
,
"-Spring"
,
buffResult
);
}
/**
* @tc.name : strptime_1800
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_1800
(
void
)
{
const
char
*
buffer
=
"+03"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%Z"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%s"
,
tmTime
.
__tm_zone
);
EXPECT_TRUE
(
"strptime_1800"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1800"
,
"+03"
,
buffResult
);
}
/**
* @tc.name : strptime_1900
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_1900
(
void
)
{
const
char
*
buffer
=
"-03"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%Z"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%s"
,
tmTime
.
__tm_zone
);
EXPECT_TRUE
(
"strptime_1900"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_1900"
,
"-03"
,
buffResult
);
}
/**
* @tc.name : strptime_2000
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_2000
(
void
)
{
const
char
*
buffer
=
"Oct-30-2021"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"test"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_2000"
,
result
);
}
/**
* @tc.name : strptime_2100
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_2100
(
void
)
{
const
char
*
buffer
=
"2022-4-10"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%+2F"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d"
,
tmTime
.
tm_mday
);
EXPECT_TRUE
(
"strptime_2100"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_2100"
,
"10"
,
buffResult
);
}
/**
* @tc.name : strptime_2200
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_2200
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%c"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_2200"
,
result
);
}
/**
* @tc.name : strptime_2300
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_2300
(
void
)
{
const
char
*
buffer
=
"2022"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%C"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%s"
,
result
);
EXPECT_TRUE
(
"strptime_2300"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_2300"
,
"22"
,
buffResult
);
}
/**
* @tc.name : strptime_2400
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_2400
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%D"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_2400"
,
result
);
}
/**
* @tc.name : strptime_2500
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_2500
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%F"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_2500"
,
result
);
}
/**
* @tc.name : strptime_2600
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_2600
(
void
)
{
const
char
*
buffer
=
" 1"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%n%t"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%s"
,
result
);
EXPECT_TRUE
(
"strptime_2600"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_2600"
,
"1"
,
buffResult
);
}
/**
* @tc.name : strptime_2700
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_2700
(
void
)
{
const
char
*
buffer
=
"08:38:20"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%r"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d:%d:%d"
,
tmTime
.
tm_hour
,
tmTime
.
tm_min
,
tmTime
.
tm_sec
);
EXPECT_TRUE
(
"strptime_2700"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_2700"
,
"8:38:20"
,
buffResult
);
}
/**
* @tc.name : strptime_2800
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_2800
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%r"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_2800"
,
result
);
}
/**
* @tc.name : strptime_2900
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_2900
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%R"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_2900"
,
result
);
}
/**
* @tc.name : strptime_3000
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3000
(
void
)
{
const
char
*
buffer
=
"+1"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%s"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3000"
,
result
);
}
/**
* @tc.name : strptime_3100
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3100
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%T"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3100"
,
result
);
}
/**
* @tc.name : strptime_3200
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3200
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%u"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3200"
,
result
);
}
/**
* @tc.name : strptime_3300
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3300
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%V"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3300"
,
result
);
}
/**
* @tc.name : strptime_3400
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_3400
(
void
)
{
const
char
*
buffer
=
"04/10/22"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%x"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d/%d/%d"
,
(
tmTime
.
tm_mon
+
1
),
tmTime
.
tm_mday
,
(
tmTime
.
tm_year
+
gYearBase
));
EXPECT_TRUE
(
"strptime_3400"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_3400"
,
"4/10/2022"
,
buffResult
);
}
/**
* @tc.name : strptime_3500
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3500
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%x"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3500"
,
result
);
}
/**
* @tc.name : strptime_3600
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void
strptime_3600
(
void
)
{
const
char
*
buffer
=
"08:10:20"
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%X"
,
&
tmTime
);
char
buffResult
[
gBufferSize
];
int
cnt
=
sprintf
(
buffResult
,
"%d:%d:%d"
,
tmTime
.
tm_hour
,
tmTime
.
tm_min
,
tmTime
.
tm_sec
);
EXPECT_TRUE
(
"strptime_3600"
,
cnt
>
0
);
EXPECT_STREQ
(
"strptime_3600"
,
"8:10:20"
,
buffResult
);
}
/**
* @tc.name : strptime_3700
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3700
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%X"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3700"
,
result
);
}
/**
* @tc.name : strptime_3800
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3800
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%%"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3800"
,
result
);
}
/**
* @tc.name : strptime_3900
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 2
*/
void
strptime_3900
(
void
)
{
const
char
*
buffer
=
""
;
struct
tm
tmTime
=
{
0
};
char
*
result
=
strptime
(
buffer
,
"%&"
,
&
tmTime
);
EXPECT_FALSE
(
"strptime_3900"
,
result
);
}
int
main
(
void
)
{
strptime_0100
();
...
...
@@ -276,5 +735,33 @@ int main(void)
strptime_0900
();
strptime_1000
();
strptime_1100
();
strptime_1200
();
strptime_1300
();
strptime_1400
();
strptime_1500
();
strptime_1600
();
strptime_1700
();
strptime_1800
();
strptime_1900
();
strptime_2000
();
strptime_2100
();
strptime_2200
();
strptime_2300
();
strptime_2400
();
strptime_2500
();
strptime_2600
();
strptime_2700
();
strptime_2800
();
strptime_2900
();
strptime_3000
();
strptime_3100
();
strptime_3200
();
strptime_3300
();
strptime_3400
();
strptime_3500
();
strptime_3600
();
strptime_3700
();
strptime_3800
();
strptime_3900
();
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/trace/trace_marker.c
浏览文件 @
423de4bb
...
...
@@ -800,6 +800,405 @@ static void trace_marker_0090(void)
pthread_join
(
fatalMessageThread2
,
NULL
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_begin and trace_marker_end, value is null.
* @tc.level : Level 2
*/
static
void
trace_marker_0100
(
void
)
{
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
trace_marker_begin
(
"Musl_Trace_Marker_0100"
,
NULL
);
trace_marker_end
();
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_sucess
=
false
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_begin
[
BUFFER_LEN
]
=
{
0
};
char
buf_end
[
BUFFER_LEN
]
=
{
0
};
int
buf_begin_fd
=
snprintf
(
buf_begin
,
BUFFER_LEN
,
"B|%d|%s"
,
getpid
(),
"Musl_Trace_Marker_0100"
);
if
(
buf_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
int
buf_end_fd
=
snprintf
(
buf_end
,
BUFFER_LEN
,
"E|%d"
,
getpid
());
if
(
buf_end_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_begin
)
!=
NULL
&&
strstr
(
buffer
,
buf_end
)
!=
NULL
)
{
trace_sucess
=
true
;
break
;
}
}
EXPECT_TRUE
(
trace_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_begin and trace_marker_end, the size of message is 1026.
* @tc.level : Level 2
*/
static
void
trace_marker_0110
(
void
)
{
char
message
[
1026
]
=
{
0
};
memset
(
message
,
1
,
1025
);
message
[
1025
]
=
'\0'
;
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
trace_marker_begin
(
message
,
""
);
trace_marker_end
();
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_sucess
=
true
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_begin
[
BUFFER_LEN
]
=
{
0
};
char
buf_end
[
BUFFER_LEN
]
=
{
0
};
int
buf_begin_fd
=
snprintf
(
buf_begin
,
BUFFER_LEN
,
"B|%d|%s"
,
getpid
(),
message
);
if
(
buf_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
int
buf_end_fd
=
snprintf
(
buf_end
,
BUFFER_LEN
,
"E|%d"
,
getpid
());
if
(
buf_end_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_begin
)
!=
NULL
&&
strstr
(
buffer
,
buf_end
)
!=
NULL
)
{
trace_sucess
=
false
;
break
;
}
}
EXPECT_TRUE
(
trace_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_begin and trace_marker_end, message is null.
* @tc.level : Level 2
*/
static
void
trace_marker_0120
(
void
)
{
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
trace_marker_begin
(
NULL
,
""
);
trace_marker_end
();
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_sucess
=
false
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_end
[
BUFFER_LEN
]
=
{
0
};
int
buf_end_fd
=
snprintf
(
buf_end
,
BUFFER_LEN
,
"E|%d"
,
getpid
());
if
(
buf_end_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_end
)
!=
NULL
)
{
trace_sucess
=
true
;
break
;
}
}
EXPECT_TRUE
(
trace_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_async_begin and trace_marker_async_end, the value is null.
* @tc.level : Level 2
*/
static
void
trace_marker_0140
(
void
)
{
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
trace_marker_async_begin
(
"async_begin_0200"
,
NULL
,
1
);
trace_marker_async_end
(
"async_end_0200"
,
NULL
,
1
);
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_async_sucess
=
false
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_async_begin
[
BUFFER_LEN
]
=
{
0
};
char
buf_async_end
[
BUFFER_LEN
]
=
{
0
};
int
buf_async_begin_fd
=
snprintf
(
buf_async_begin
,
BUFFER_LEN
,
"S|%d|%s %d"
,
getpid
(),
"async_begin_0200"
,
1
);
if
(
buf_async_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
int
buf_async_end_fd
=
snprintf
(
buf_async_end
,
BUFFER_LEN
,
"F|%d|%s %d"
,
getpid
(),
"async_end_0200"
,
1
);
if
(
buf_async_end_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_async_begin
)
!=
NULL
&&
strstr
(
buffer
,
buf_async_end
)
!=
NULL
)
{
trace_async_sucess
=
true
;
break
;
}
}
EXPECT_TRUE
(
trace_async_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_async_begin and trace_marker_async_end, the size of message
* is 1026.
* @tc.level : Level 2
*/
static
void
trace_marker_0150
(
void
)
{
char
message
[
1026
]
=
{
0
};
memset
(
message
,
1
,
1025
);
message
[
1025
]
=
'\0'
;
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
trace_marker_async_begin
(
message
,
"trace_async"
,
1
);
trace_marker_async_end
(
message
,
"trace_async"
,
1
);
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_async_sucess
=
true
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_async_begin
[
BUFFER_LEN
]
=
{
0
};
char
buf_async_end
[
BUFFER_LEN
]
=
{
0
};
int
buf_async_begin_fd
=
snprintf
(
buf_async_begin
,
BUFFER_LEN
,
"S|%d|%s|%s %d"
,
getpid
(),
message
,
"trace_async"
,
1
);
if
(
buf_async_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
int
buf_async_end_fd
=
snprintf
(
buf_async_end
,
BUFFER_LEN
,
"F|%d|%s|%s %d"
,
getpid
(),
message
,
"trace_async"
,
1
);
if
(
buf_async_end_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_async_begin
)
!=
NULL
&&
strstr
(
buffer
,
buf_async_end
)
!=
NULL
)
{
trace_async_sucess
=
false
;
break
;
}
}
EXPECT_TRUE
(
trace_async_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_async_begin and trace_marker_async_end, message is null.
* @tc.level : Level 2
*/
static
void
trace_marker_0160
(
void
)
{
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
trace_marker_async_begin
(
NULL
,
"trace_async"
,
1
);
trace_marker_async_end
(
NULL
,
"trace_async"
,
1
);
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_async_sucess
=
true
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_async_begin
[
BUFFER_LEN
]
=
{
0
};
char
buf_async_end
[
BUFFER_LEN
]
=
{
0
};
int
buf_async_begin_fd
=
snprintf
(
buf_async_begin
,
BUFFER_LEN
,
"S|%d|%s %d"
,
getpid
(),
"trace_async"
,
1
);
if
(
buf_async_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
int
buf_async_end_fd
=
snprintf
(
buf_async_end
,
BUFFER_LEN
,
"F|%d|%s %d"
,
getpid
(),
"trace_async"
,
1
);
if
(
buf_async_end_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_async_begin
)
!=
NULL
&&
strstr
(
buffer
,
buf_async_end
)
!=
NULL
)
{
trace_async_sucess
=
false
;
break
;
}
}
EXPECT_TRUE
(
trace_async_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_count, the size of messge is 1026.
* @tc.level : Level 2
*/
static
void
trace_marker_0180
(
void
)
{
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
int
traceCount
=
5
;
char
message
[
1026
]
=
{
0
};
memset
(
message
,
1
,
1025
);
message
[
1025
]
=
'\0'
;
trace_marker_count
(
message
,
traceCount
);
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_count_sucess
=
true
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_count
[
BUFFER_LEN
]
=
{
0
};
int
buf_begin_fd
=
snprintf
(
buf_count
,
BUFFER_LEN
,
"C|%d|%s %d"
,
getpid
(),
message
,
traceCount
);
if
(
buf_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_count
)
!=
NULL
)
{
trace_count_sucess
=
false
;
break
;
}
}
EXPECT_TRUE
(
trace_count_sucess
);
close
(
trace_fd
);
}
/**
* @tc.name : trace_marker
* @tc.desc : Test trace_marker_count, message is null.
* @tc.level : Level 2
*/
static
void
trace_marker_0190
(
void
)
{
system
(
"cd /sys/kernel/debug/tracing;echo 1 > tracing_on"
);
int
traceCount
=
5
;
trace_marker_count
(
NULL
,
traceCount
);
system
(
"cd /sys/kernel/debug/tracing;echo 0 > tracing_on"
);
int
trace_fd
=
open
(
"/sys/kernel/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
trace_fd
=
open
(
"/sys/kernel/debug/tracing/trace"
,
O_CLOEXEC
|
O_RDONLY
);
if
(
trace_fd
==
-
1
)
{
return
;
}
}
bool
trace_count_sucess
=
true
;
char
buffer
[
BUFFER_LEN
]
=
{
0
};
char
buf_count
[
BUFFER_LEN
]
=
{
0
};
int
buf_begin_fd
=
snprintf
(
buf_count
,
BUFFER_LEN
,
"C|%d %d"
,
getpid
(),
traceCount
);
if
(
buf_begin_fd
<
0
)
{
close
(
trace_fd
);
return
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
int
read_fd
=
read
(
trace_fd
,
buffer
,
BUFFER_LEN
*
i
);
if
(
read_fd
==
-
1
)
{
close
(
trace_fd
);
return
;
}
if
(
strstr
(
buffer
,
buf_count
)
!=
NULL
)
{
trace_count_sucess
=
false
;
break
;
}
}
EXPECT_TRUE
(
trace_count_sucess
);
close
(
trace_fd
);
}
TEST_FUN
G_Fun_Array
[]
=
{
trace_marker_0010
,
trace_marker_0020
,
...
...
@@ -810,6 +1209,14 @@ TEST_FUN G_Fun_Array[] = {
trace_marker_0070
,
trace_marker_0080
,
trace_marker_0090
,
trace_marker_0100
,
trace_marker_0110
,
trace_marker_0120
,
trace_marker_0140
,
trace_marker_0150
,
trace_marker_0160
,
trace_marker_0180
,
trace_marker_0190
,
};
int
main
(
void
)
...
...
libc-test/src/functionalext/unittest/BUILD.gn
浏览文件 @
423de4bb
...
...
@@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("../../../test_template.gni")
ohos_executable("unittest_ldso_ns_config") {
...
...
@@ -32,7 +33,11 @@ ohos_executable("unittest_ldso_ns_config") {
deps = [ "//third_party/musl:create_porting_src" ]
libs = [ "${musl_lib_dir}/libc.a" ]
if (!musl_unit_test_flag) {
libs = [ "${musl_lib_dir}/libc.a" ]
} else {
defines = [ "UNIT_TEST_STATIC" ]
}
}
ohos_executable("unittest_ldso_namesapce") {
...
...
@@ -58,6 +63,10 @@ ohos_executable("unittest_ldso_namesapce") {
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
if (musl_unit_test_flag) {
defines = [ "UNIT_TEST_STATIC" ]
}
}
ohos_executable("unittest_ldso_ld_log") {
...
...
@@ -93,7 +102,10 @@ ohos_executable("unittest_ldso_dynlink") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [ "unit_test_ldso_dynlink.c" ]
sources = [
"unit_test_ldso_dynlink.c",
"unit_test_mock_dynlink.c",
]
include_dirs = [
"${musl_src_base}/ldso",
...
...
@@ -102,13 +114,24 @@ ohos_executable("unittest_ldso_dynlink") {
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
"${musl_src_base}/arch/${musl_arch}",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
deps = [
"//base/startup/init/services/param/base:parameterbase",
"//third_party/musl:create_porting_src",
]
libs = [ "${musl_lib_dir}/libc.a" ]
if (!musl_unit_test_flag) {
libs = [ "${musl_lib_dir}/libc.a" ]
} else {
defines = [
"UNIT_TEST_STATIC",
"OHOS_ENABLE_PARAMETER",
]
}
}
ohos_executable("unittest_hilog_adapter") {
...
...
@@ -130,6 +153,30 @@ ohos_executable("unittest_hilog_adapter") {
libs = [ "${musl_lib_dir}/libc.a" ]
}
ohos_executable("unittest_ldso_strops") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [
"${musl_src_base}/ldso/strops.c",
"unit_test_ldso_strops.c",
"unit_test_mock_molloc.c",
]
include_dirs = [
"${musl_src_base}/ldso",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
}
ohos_executable("unittest_hilog_vsnprint") {
subsystem_name = "musl"
part_name = "libc-test"
...
...
@@ -149,14 +196,40 @@ ohos_executable("unittest_hilog_vsnprint") {
libs = [ "${musl_lib_dir}/libc.a" ]
}
ohos_executable("unittest_fatal_message") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [
"${musl_src_base}/src/info/fatal_message.c",
"unit_test_fatal_message.c",
"unit_test_mock_fatal_message.c",
]
include_dirs = [
"${musl_src_base}/src/info",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
}
group("functionalext_unittest_test") {
testonly = true
deps = [
":unittest_fatal_message",
":unittest_hilog_adapter",
":unittest_hilog_vsnprint",
":unittest_ldso_dynlink",
":unittest_ldso_ld_log",
":unittest_ldso_namesapce",
":unittest_ldso_ns_config",
":unittest_ldso_strops",
]
}
libc-test/src/functionalext/unittest/unit_test_fatal_message.c
0 → 100644
浏览文件 @
423de4bb
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <info/fatal_message.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <test.h>
#include <pthread.h>
#include <unistd.h>
#include "functionalext.h"
typedef
void
(
*
TEST_FUN
)(
void
);
static
const
int
WAIT_TIME
=
1
;
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the function of set_fatal_message.
* @tc.level : Level 0
*/
static
void
fatal_message_0010
(
void
)
{
const
char
msg
[
1024
]
=
{
"abcdefghijklmnopqrstuvwxyz1234567890"
};
fatal_msg_t
*
fatal_message
=
NULL
;
int
pidChild
=
0
;
pid_t
fpid
;
fpid
=
fork
();
if
(
fpid
<
0
)
{
t_printf
(
"error in fork!"
);
}
else
if
(
fpid
==
0
)
{
pidChild
=
getpid
();
set_fatal_message
(
msg
);
fatal_message
=
get_fatal_message
();
EXPECT_EQ
(
"fatal_message_0010"
,
fatal_message
,
NULL
);
exit
(
pidChild
);
}
}
TEST_FUN
G_Fun_Array
[]
=
{
fatal_message_0010
,
};
int
main
(
void
)
{
int
num
=
sizeof
(
G_Fun_Array
)
/
sizeof
(
TEST_FUN
);
for
(
int
pos
=
0
;
pos
<
num
;
++
pos
)
{
G_Fun_Array
[
pos
]();
}
return
t_status
;
}
libc-test/src/functionalext/unittest/unit_test_hilog_adapter.c
浏览文件 @
423de4bb
...
...
@@ -26,7 +26,7 @@
/**
* @tc.name : reboot_0010
* @tc.desc :
t
est HiLogAdapterPrint after musl_log_reset
* @tc.desc :
T
est HiLogAdapterPrint after musl_log_reset
* @tc.level : Level 2
*/
static
void
HiLogAdapterPrint_0010
(
void
)
...
...
libc-test/src/functionalext/unittest/unit_test_hilog_vsnprint_f_p.c
浏览文件 @
423de4bb
...
...
@@ -516,14 +516,306 @@ static void vsnprintfp_s_0350(void)
EXPECT_TRUE
(
"vsnprintfp_s_0350"
,
ret
<
0
);
}
/**
* @tc.name : vsnprintfp_s_0360
* @tc.desc : test vsnprintf param fmt is "%ld"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0360
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%ld"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
333
);
EXPECT_TRUE
(
"vsnprintfp_s_0360"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0360"
,
buf
,
"333"
);
}
/**
* @tc.name : vsnprintfp_s_0370
* @tc.desc : test vsnprintf param fmt is "%V"
* @tc.level : Level 2
*/
static
void
vsnprintfp_s_0370
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%V"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
9
);
EXPECT_TRUE
(
"vsnprintfp_s_0370"
,
ret
<
0
);
}
/**
* @tc.name : vsnprintfp_s_0380
* @tc.desc : test vsnprintf param fmt is "%{public}wc"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0380
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%{public}wc"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
'a'
);
EXPECT_TRUE
(
"vsnprintfp_s_0380"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0380"
,
buf
,
"a"
);
}
/**
* @tc.name : vsnprintfp_s_0390
* @tc.desc : test vsnprintf param fmt is "%I"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0390
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%I"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
22
);
EXPECT_TRUE
(
"vsnprintfp_s_0390"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0390"
,
buf
,
"I"
);
}
/**
* @tc.name : vsnprintfp_s_0400
* @tc.desc : test vsnprintf param fmt is "%I64d %I32d"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0400
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%I64d %I32d"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
22
,
33
);
EXPECT_TRUE
(
"vsnprintfp_s_0400"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0400"
,
buf
,
"94489280545 942945337"
);
}
/**
* @tc.name : vsnprintfp_s_0410
* @tc.desc : test vsnprintf param fmt is "%Id %Ii %Io %Iu %Ix %IX"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0410
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%Id %Ii %Io %Iu %Ix %IX"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
22
,
33
,
44
,
55
,
66
,
77
);
EXPECT_TRUE
(
"vsnprintfp_s_0410"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0410"
,
buf
,
"22 33 54 55 42 4D"
);
}
/**
* @tc.name : vsnprintfp_s_0420
* @tc.desc : test vsnprintf param fmt is "%0c"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0420
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%0c"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
'c'
);
EXPECT_TRUE
(
"vsnprintfp_s_0420"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0420"
,
buf
,
"c"
);
}
/**
* @tc.name : vsnprintfp_s_0430
* @tc.desc : test vsnprintf param fmt is "%hhd"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0430
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%hhd"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
1024
);
EXPECT_TRUE
(
"vsnprintfp_s_0430"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0430"
,
buf
,
"0"
);
}
/**
* @tc.name : vsnprintfp_s_0440
* @tc.desc : test vsnprintf param fmt is "%#o"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0440
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%#o"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
64
);
EXPECT_TRUE
(
"vsnprintfp_s_0440"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0440"
,
buf
,
"0100"
);
}
/**
* @tc.name : vsnprintfp_s_0450
* @tc.desc : test vsnprintf param fmt is "%#o"
* @tc.level : Level 0
*/
static
void
vsnprintfp_s_0450
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%{public}ws"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
"test"
);
EXPECT_TRUE
(
"vsnprintfp_s_0450"
,
ret
<
0
);
}
/**
* @tc.name : vsnprintfp_s_0460
* @tc.desc : test vsnprintf param fmt is "%123123d"
* @tc.level : Level 2
*/
static
void
vsnprintfp_s_0460
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%123123d"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
1024
);
EXPECT_TRUE
(
"vsnprintfp_s_0460"
,
ret
<
0
);
}
/**
* @tc.name : vsnprintfp_s_0470
* @tc.desc : test vsnprintf param fmt is "%+123123d"
* @tc.level : Level 2
*/
static
void
vsnprintfp_s_0470
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%+123123d"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
1024
);
EXPECT_TRUE
(
"vsnprintfp_s_0470"
,
ret
<
0
);
}
/**
* @tc.name : vsnprintfp_s_0480
* @tc.desc : param count < PRIVATE_STR_LEN(9) and format is {private}
* @tc.level : Level 2
*/
static
void
vsnprintfp_s_0480
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%{private}d"
;
int
ret
=
vsprintf_test
(
buf
,
8
,
7
,
true
,
fmt
,
22
);
EXPECT_TRUE
(
"vsnprintfp_s_0480"
,
ret
<
0
);
}
/**
* @tc.name : vsnprintfp_s_0490
* @tc.desc : test vsnprintf param fmt is "%d" and arg is (char)128
* @tc.level : Level 1
*/
static
void
vsnprintfp_s_0490
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%hhd"
;
char
num
=
128
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
num
);
EXPECT_TRUE
(
"vsnprintfp_s_0490"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0490"
,
buf
,
"-128"
);
}
/**
* @tc.name : vsnprintfp_s_0500
* @tc.desc : test vsnprintf param fmt is "%d" and arg is (char)128
* @tc.level : Level 1
*/
static
void
vsnprintfp_s_0500
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%*d"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
1
,
1024
);
EXPECT_TRUE
(
"vsnprintfp_s_0500"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0500"
,
buf
,
"1024"
);
}
/**
* @tc.name : vsnprintfp_s_0510
* @tc.desc : test vsnprintf param fmt is "%I63d"
* @tc.level : Level 2
*/
static
void
vsnprintfp_s_0510
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%I63d"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
22
);
EXPECT_TRUE
(
"vsnprintfp_s_0510"
,
ret
>
0
);
}
/**
* @tc.name : vsnprintfp_s_0520
* @tc.desc : test vsnprintf param fmt is "%I31d"
* @tc.level : Level 2
*/
static
void
vsnprintfp_s_0520
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%I31d"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
22
);
EXPECT_TRUE
(
"vsnprintfp_s_0520"
,
ret
>
0
);
}
/**
* @tc.name : vsnprintfp_s_0530
* @tc.desc : test vsnprintf param fmt is "%.g"
* @tc.level : Level 1
*/
static
void
vsnprintfp_s_0530
(
void
)
{
char
buf
[
MAX_LOG_LEN
]
=
{
0
};
char
*
fmt
=
"%.g"
;
int
ret
=
vsprintf_test
(
buf
,
MAX_LOG_LEN
,
MAX_LOG_LEN
-
1
,
false
,
fmt
,
0
.
12000
);
EXPECT_TRUE
(
"vsnprintfp_s_0530"
,
ret
>
0
);
EXPECT_STREQ
(
"vsnprintfp_s_0530"
,
buf
,
"0.1"
);
}
TEST_FUN
G_Fun_Array
[]
=
{
vsnprintfp_s_0010
,
vsnprintfp_s_0020
,
vsnprintfp_s_0030
,
vsnprintfp_s_0040
,
vsnprintfp_s_0050
,
vsnprintfp_s_0060
,
vsnprintfp_s_0070
,
vsnprintfp_s_0080
,
vsnprintfp_s_0090
,
vsnprintfp_s_0100
,
vsnprintfp_s_0110
,
vsnprintfp_s_0120
,
vsnprintfp_s_0130
,
vsnprintfp_s_0140
,
vsnprintfp_s_0150
,
vsnprintfp_s_0160
,
vsnprintfp_s_0170
,
vsnprintfp_s_0180
,
vsnprintfp_s_0190
,
vsnprintfp_s_0200
,
vsnprintfp_s_0210
,
vsnprintfp_s_0220
,
vsnprintfp_s_0230
,
vsnprintfp_s_0240
,
vsnprintfp_s_0250
,
vsnprintfp_s_0260
,
vsnprintfp_s_0270
,
vsnprintfp_s_0280
,
vsnprintfp_s_0290
,
vsnprintfp_s_0300
,
vsnprintfp_s_0310
,
vsnprintfp_s_0320
,
vsnprintfp_s_0330
,
vsnprintfp_s_0340
,
vsnprintfp_s_0350
,
vsnprintfp_s_0010
,
vsnprintfp_s_0020
,
vsnprintfp_s_0030
,
vsnprintfp_s_0040
,
vsnprintfp_s_0050
,
vsnprintfp_s_0060
,
vsnprintfp_s_0070
,
vsnprintfp_s_0080
,
vsnprintfp_s_0090
,
vsnprintfp_s_0100
,
vsnprintfp_s_0110
,
vsnprintfp_s_0120
,
vsnprintfp_s_0130
,
vsnprintfp_s_0140
,
vsnprintfp_s_0150
,
vsnprintfp_s_0160
,
vsnprintfp_s_0170
,
vsnprintfp_s_0180
,
vsnprintfp_s_0190
,
vsnprintfp_s_0200
,
vsnprintfp_s_0210
,
vsnprintfp_s_0220
,
vsnprintfp_s_0230
,
vsnprintfp_s_0240
,
vsnprintfp_s_0250
,
vsnprintfp_s_0260
,
vsnprintfp_s_0270
,
vsnprintfp_s_0280
,
vsnprintfp_s_0290
,
vsnprintfp_s_0300
,
vsnprintfp_s_0310
,
vsnprintfp_s_0320
,
vsnprintfp_s_0330
,
vsnprintfp_s_0340
,
vsnprintfp_s_0350
,
vsnprintfp_s_0360
,
vsnprintfp_s_0370
,
vsnprintfp_s_0380
,
vsnprintfp_s_0390
,
vsnprintfp_s_0400
,
vsnprintfp_s_0410
,
vsnprintfp_s_0420
,
vsnprintfp_s_0430
,
vsnprintfp_s_0440
,
vsnprintfp_s_0450
,
vsnprintfp_s_0460
,
vsnprintfp_s_0470
,
vsnprintfp_s_0480
,
vsnprintfp_s_0490
,
vsnprintfp_s_0500
,
vsnprintfp_s_0510
,
vsnprintfp_s_0520
,
vsnprintfp_s_0530
,
};
int
main
(
void
)
...
...
libc-test/src/functionalext/unittest/unit_test_ldso_dynlink.c
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
libc-test/src/functionalext/unittest/unit_test_ldso_ld_log.c
浏览文件 @
423de4bb
...
...
@@ -26,7 +26,7 @@ typedef void (*TEST_FUN)(void);
static
void
ld_log_test_0010
(
void
)
{
ld_log_reset
();
EXPECT_TRUE
(
ld_log_test_0010
,
true
);
EXPECT_TRUE
(
__FUNCTION__
,
true
);
}
TEST_FUN
G_Fun_Array
[]
=
{
...
...
libc-test/src/functionalext/unittest/unit_test_ldso_namespace.c
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
libc-test/src/functionalext/unittest/unit_test_ldso_ns_config.c
浏览文件 @
423de4bb
...
...
@@ -30,7 +30,7 @@ static void ns_config_test_0010(void)
configor
->
set_error_callback
(
NULL
);
configor_free
();
EXPECT_TRUE
(
ns_config_test_0010
,
true
);
EXPECT_TRUE
(
__FUNCTION__
,
true
);
}
int
errorback
(
const
char
*
format
,
...)
...
...
@@ -50,7 +50,22 @@ static void ns_config_test_0020(void)
configor
->
set_error_callback
(
&
errorback
);
configor_free
();
EXPECT_TRUE
(
ns_config_test_0020
,
true
);
EXPECT_TRUE
(
__FUNCTION__
,
true
);
}
/**
* @tc.name : ns_config_0030
* @tc.desc : Test parse with invalid input
* @tc.level : Level 2
*/
static
void
ns_config_test_0030
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
configor
->
set_error_callback
(
NULL
);
int
ret
=
configor
->
parse
(
"ttttttttt.txt"
,
"ttttttttt"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
-
2
);
}
/**
...
...
@@ -64,7 +79,7 @@ static void ns_config_test_0040(void)
configor
=
configor_init
();
strlist
*
ret
=
configor
->
get_namespaces
();
configor_free
();
EXPECT_EQ
(
ns_config_test_0040
,
ret
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
...
...
@@ -85,7 +100,28 @@ static void ns_config_test_0050(void)
configor
->
kvs
=
&
kv
;
strlist
*
ret
=
configor
->
get_namespaces
();
configor_free
();
EXPECT_EQ
(
ns_config_test_0050
,
ret
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0060
* @tc.desc : Test get_namespaces with invalid input
* @tc.level : Level 2
*/
static
void
ns_config_test_0060
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
kvlist
kv
;
kv
.
num
=
1
;
char
*
key
=
"added.nslist"
;
char
*
val
=
"b"
;
kv
.
key
=
&
key
;
kv
.
val
=
&
val
;
configor
->
kvs
=
&
kv
;
strlist
*
ret
=
configor
->
get_namespaces
();
configor_free
();
EXPECT_PTRNE
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
...
...
@@ -99,7 +135,7 @@ static void ns_config_test_0070(void)
configor
=
configor_init
();
char
*
ret
=
configor
->
get_lib_paths
(
NULL
);
configor_free
();
EXPECT_EQ
(
ns_config_test_0070
,
ret
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
...
...
@@ -113,7 +149,7 @@ static void ns_config_test_0080(void)
configor
=
configor_init
();
char
*
ret
=
configor
->
get_lib_paths
(
"test"
);
configor_free
();
EXPECT_EQ
(
ns_config_test_0080
,
ret
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
...
...
@@ -127,7 +163,7 @@ static void ns_config_test_0090(void)
configor
=
configor_init
();
char
*
ret
=
configor
->
get_asan_lib_paths
(
NULL
);
configor_free
();
EXPECT_EQ
(
ns_config_test_0090
,
ret
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
...
...
@@ -141,18 +177,369 @@ static void ns_config_test_0100(void)
configor
=
configor_init
();
char
*
ret
=
configor
->
get_asan_lib_paths
(
"test"
);
configor_free
();
EXPECT_EQ
(
ns_config_test_0100
,
ret
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0110
* @tc.desc : Test get_permitted_paths with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0110
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_permitted_paths
(
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0120
* @tc.desc : Test get_permitted_paths with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0120
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_permitted_paths
(
"test"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0130
* @tc.desc : Test get_inherits with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0130
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
strlist
*
ret
=
configor
->
get_inherits
(
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0140
* @tc.desc : Test get_inherits with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0140
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
strlist
*
ret
=
configor
->
get_inherits
(
"test"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0150
* @tc.desc : Test get_separated with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0150
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
bool
ret
=
configor
->
get_separated
(
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
false
);
}
/**
* @tc.name : ns_config_0160
* @tc.desc : Test get_separated with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0160
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
bool
ret
=
configor
->
get_separated
(
"test"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
false
);
}
/**
* @tc.name : ns_config_0170
* @tc.desc : Test get_allowed_libs with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0170
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_allowed_libs
(
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0180
* @tc.desc : Test get_allowed_libs with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0180
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_allowed_libs
(
"test"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0180
* @tc.desc : Test get_inherit_shared_libs with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0190
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_inherit_shared_libs
(
NULL
,
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0200
* @tc.desc : Test get_inherit_shared_libs with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0200
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_inherit_shared_libs
(
"test"
,
"abc"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0210
* @tc.desc : get_inherit_shared_libs test coverage
* @tc.level : Level 1
*/
void
ns_config_test_0210
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_asan_sys_paths
();
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0220
* @tc.desc : Test get_asan_permitted_paths with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0220
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_asan_permitted_paths
(
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0230
* @tc.desc : Test get_asan_permitted_paths with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0230
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_asan_permitted_paths
(
"test"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0240
* @tc.desc : Test get_inherit_shared_libs with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0240
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_inherit_shared_libs
(
NULL
,
"test"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0250
* @tc.desc : Test get_inherit_shared_libs with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0250
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
char
*
ret
=
configor
->
get_inherit_shared_libs
(
"test"
,
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
NULL
);
}
/**
* @tc.name : ns_config_0260
* @tc.desc : Test parse with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0260
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
configor
->
set_error_callback
(
NULL
);
int
ret
=
configor
->
parse
(
"/etc/ld-musl-namespace-arm-test.ini"
,
"/data/tests/libc-test/src"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
0
);
}
/**
* @tc.name : ns_config_0270
* @tc.desc : Test parse with normal input
* @tc.level : Level 1
*/
void
ns_config_test_0270
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
configor
->
set_error_callback
(
NULL
);
int
ret
=
configor
->
parse
(
NULL
,
"/"
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
0
);
}
/**
* @tc.name : ns_config_0280
* @tc.desc : Test parse with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0280
(
void
)
{
ns_configor
*
configor
=
NULL
;
configor
=
configor_init
();
configor
->
set_error_callback
(
NULL
);
int
ret
=
configor
->
parse
(
"/etc/ld-musl-namespace-arm-test.ini"
,
NULL
);
configor_free
();
EXPECT_EQ
(
__FUNCTION__
,
ret
,
-
1
);
}
// Because below function are static in file and call it difficult through External API, below interfaces are covered by white-box unit testing.
#ifdef UNIT_TEST_STATIC
void
kvlist_realloc
(
kvlist
*
kvs
);
void
sections_realloc
(
section_list
*
sections
);
/**
* @tc.name : ns_config_test_0290
* @tc.desc : Test kvlist_realloc with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0290
(
void
)
{
kvlist_realloc
(
NULL
);
EXPECT_TRUE
(
__FUNCTION__
,
true
);
}
/**
* @tc.name : ns_config_test_0300
* @tc.desc : Test kvlist_realloc with normal input
* @tc.level : Level 0
*/
void
ns_config_test_0300
(
void
)
{
kvlist
kvs
;
kvs
.
size
=
1
;
kvs
.
key
=
(
char
**
)
calloc
(
kvs
.
size
,
sizeof
*
kvs
.
key
);
kvs
.
val
=
(
char
**
)
calloc
(
kvs
.
size
,
sizeof
*
kvs
.
val
);
kvlist_realloc
(
&
kvs
);
EXPECT_EQ
(
__FUNCTION__
,
kvs
.
size
,
2
);
if
(
kvs
.
key
){
free
(
kvs
.
key
);
}
if
(
kvs
.
val
){
free
(
kvs
.
val
);
}
}
/**
* @tc.name : ns_config_test_0310
* @tc.desc : Test sections_realloc with invalid input
* @tc.level : Level 2
*/
void
ns_config_test_0310
(
void
)
{
sections_realloc
(
NULL
);
EXPECT_TRUE
(
__FUNCTION__
,
true
);
}
/**
* @tc.name : ns_config_test_0320
* @tc.desc : Test sections_realloc with normal input
* @tc.level : Level 0
*/
void
ns_config_test_0320
(
void
)
{
section_list
sections
;
sections
.
size
=
1
;
sections
.
names
=
(
char
**
)
calloc
(
sections
.
size
,
sizeof
*
sections
.
names
);
sections
.
kvs
=
(
kvlist
**
)
calloc
(
sections
.
size
,
sizeof
*
sections
.
kvs
);
sections_realloc
(
&
sections
);
EXPECT_EQ
(
__FUNCTION__
,
sections
.
size
,
2
);
if
(
sections
.
names
){
free
(
sections
.
names
);
}
if
(
sections
.
kvs
){
free
(
sections
.
kvs
);
}
}
#endif
TEST_FUN
G_Fun_Array
[]
=
{
ns_config_test_0010
,
ns_config_test_0020
,
ns_config_test_0030
,
ns_config_test_0040
,
ns_config_test_0050
,
ns_config_test_0060
,
ns_config_test_0070
,
ns_config_test_0080
,
ns_config_test_0090
,
ns_config_test_0100
,
ns_config_test_0110
,
ns_config_test_0120
,
ns_config_test_0130
,
ns_config_test_0140
,
ns_config_test_0150
,
ns_config_test_0160
,
ns_config_test_0170
,
ns_config_test_0180
,
ns_config_test_0190
,
ns_config_test_0200
,
ns_config_test_0210
,
ns_config_test_0220
,
ns_config_test_0230
,
ns_config_test_0240
,
ns_config_test_0250
,
ns_config_test_0260
,
ns_config_test_0270
,
ns_config_test_0280
,
#ifdef UNIT_TEST_STATIC
ns_config_test_0290
,
ns_config_test_0300
,
ns_config_test_0310
,
ns_config_test_0320
,
#endif
};
int
main
(
void
)
...
...
libc-test/src/functionalext/unittest/unit_test_ldso_strops.c
0 → 100644
浏览文件 @
423de4bb
/**
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test.h"
#include "strops.h"
#include "functionalext.h"
typedef
void
(
*
TEST_FUN
)(
void
);
/**
* @tc.name : strops_test_0010
* @tc.desc : strlwc test args null
* @tc.level : Level 2
*/
void
strops_test_0010
(
void
)
{
char
*
str
=
NULL
;
strlwc
(
str
);
EXPECT_EQ
(
__FUNCTION__
,
str
,
NULL
);
}
/**
* @tc.name : strops_test_0020
* @tc.desc : Test strlwc with normal input
* @tc.level : Level 0
*/
void
strops_test_0020
(
void
)
{
char
tmp
[
4
]
=
"Abc"
;
tmp
[
3
]
=
'\0'
;
strlwc
(
tmp
);
EXPECT_EQ
(
__FUNCTION__
,
strcmp
(
tmp
,
"abc"
),
0
);
}
/**
* @tc.name : strops_test_0030
* @tc.desc : strlist_set test arg is NULL
* @tc.level : Level 2
*/
void
strops_test_0030
(
void
)
{
char
*
str
=
NULL
;
strlist_set
(
NULL
,
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
str
,
NULL
);
}
/**
* @tc.name : strops_test_0040
* @tc.desc : Test strlist_set with normal input
* @tc.level : Level 0
*/
void
strops_test_0040
(
void
)
{
strlist
list
;
list
.
size
=
1
;
list
.
num
=
1
;
strlist_set
(
&
list
,
"abc"
);
EXPECT_EQ
(
__FUNCTION__
,
list
.
size
,
2
);
}
/**
* @tc.name : strops_test_0050
* @tc.desc : strtrim test arg is NULL
* @tc.level : Level 2
*/
void
strops_test_0050
(
void
)
{
size_t
ret
=
strtrim
(
NULL
);
EXPECT_EQ
(
__FUNCTION__
,
ret
,
0
);
}
TEST_FUN
G_Fun_Array
[]
=
{
strops_test_0010
,
strops_test_0020
,
strops_test_0030
,
strops_test_0040
,
strops_test_0050
};
int
main
(
void
)
{
int
num
=
sizeof
(
G_Fun_Array
)
/
sizeof
(
TEST_FUN
);
for
(
int
pos
=
0
;
pos
<
num
;
++
pos
)
{
G_Fun_Array
[
pos
]();
}
return
t_status
;
}
\ No newline at end of file
libc-test/src/functionalext/unittest/unit_test_mock_dynlink.c
0 → 100644
浏览文件 @
423de4bb
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dynlink_rand.h"
#include <sys/mman.h>
#include <unistd.h>
#ifdef OHOS_ENABLE_PARAMETER
#include "sys_param.h"
#endif
#ifdef UNIT_TEST_STATIC
void
free_task
(
struct
loadtask
*
task
)
{
if
(
task
==
NULL
)
{
return
;
}
if
(
task
->
name
)
{
free
((
void
*
)
task
->
name
);
task
->
name
=
NULL
;
}
if
(
task
->
allocated_buf
)
{
free
(
task
->
allocated_buf
);
task
->
allocated_buf
=
NULL
;
}
if
(
task
->
dyn_map_len
)
{
munmap
(
task
->
dyn_map
,
task
->
dyn_map_len
);
task
->
dyn_map
=
NULL
;
task
->
dyn_map_len
=
0
;
}
if
(
task
->
str_map_len
)
{
munmap
(
task
->
str_map
,
task
->
str_map_len
);
task
->
str_map
=
NULL
;
task
->
str_map_len
=
0
;
}
if
(
task
->
fd
!=
-
1
&&
task
->
fd
)
{
close
(
task
->
fd
);
task
->
fd
=
-
1
;
}
free
(
task
);
}
struct
loadtask
*
get_loadtask
(
struct
loadtasks
*
tasks
,
size_t
index
)
{
if
(
tasks
&&
tasks
->
array
&&
(
index
<
tasks
->
length
))
{
return
tasks
->
array
[
index
];
}
else
{
return
NULL
;
}
}
void
free_loadtasks
(
struct
loadtasks
*
tasks
)
{
if
(
tasks
)
{
if
(
tasks
->
length
)
{
for
(
size_t
i
=
0
;
i
<
tasks
->
length
;
i
++
)
{
free_task
(
get_loadtask
(
tasks
,
i
));
}
tasks
->
length
=
0
;
}
if
(
tasks
->
array
)
{
free
(
tasks
->
array
);
tasks
->
array
=
NULL
;
}
tasks
->
capacity
=
0
;
free
(
tasks
);
}
}
#endif
bool
get_ld_debug_dlclose_value
()
{
#ifdef OHOS_ENABLE_PARAMETER
static
CachedHandle
param_handle
=
NULL
;
if
(
param_handle
==
NULL
)
{
param_handle
=
CachedParameterCreate
(
"musl.ld.debug.dlclose"
,
"false"
);
}
const
char
*
param_value
=
CachedParameterGet
(
param_handle
);
if
(
param_value
!=
NULL
)
{
if
(
strcmp
(
param_value
,
"true"
)
==
0
)
{
return
true
;
}
}
#endif
return
false
;
}
\ No newline at end of file
libc-test/src/functionalext/unittest/unit_test_mock_fatal_message.c
0 → 100644
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
libc-test/test_template.gni
浏览文件 @
423de4bb
...
...
@@ -75,7 +75,9 @@ template("test_unittest") {
ldflags = [ "-nostdlib" ]
libs = [ "//${out_test_dir}/src/common/libtest.a" ]
libs += [ "${musl_lib_dir}/libc.a" ]
if (!musl_unit_test_flag) {
libs += [ "${musl_lib_dir}/libc.a" ]
}
if (target_dir == "math") {
include_dirs += [
...
...
musl_config.gni
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
musl_template.gni
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
porting/linux/user/ldso/dynlink.c
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
porting/linux/user/ldso/namespace.c
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
porting/linux/user/ldso/ns_config.c
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
porting/linux/user/src/internal/dynlink.h
浏览文件 @
423de4bb
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录