Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
0da55118
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
10 个月 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0da55118
编写于
7月 26, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 26, 2023
浏览文件
操作
浏览文件
下载
差异文件
!2104 init 覆盖率
Merge pull request !2104 from cheng_jinsong/init_cov
上级
5bf846de
c18a3a12
变更
54
隐藏空白更改
内联
并排
Showing
54 changed file
with
1000 addition
and
431 deletion
+1000
-431
interfaces/innerkits/control_fd/control_fd_service.c
interfaces/innerkits/control_fd/control_fd_service.c
+1
-4
interfaces/innerkits/fd_holder/fd_holder.c
interfaces/innerkits/fd_holder/fd_holder.c
+21
-37
interfaces/innerkits/fd_holder/fd_holder_internal.c
interfaces/innerkits/fd_holder/fd_holder_internal.c
+6
-14
interfaces/innerkits/fs_manager/fstab_mount.c
interfaces/innerkits/fs_manager/fstab_mount.c
+31
-58
interfaces/innerkits/include/beget_ext.h
interfaces/innerkits/include/beget_ext.h
+8
-0
interfaces/innerkits/modulemgr/modulemgr.c
interfaces/innerkits/modulemgr/modulemgr.c
+11
-13
interfaces/innerkits/syscap/init_syscap.c
interfaces/innerkits/syscap/init_syscap.c
+3
-4
services/include/init_utils.h
services/include/init_utils.h
+0
-8
services/init/standard/init.c
services/init/standard/init.c
+2
-1
services/loopevent/loop/le_loop.c
services/loopevent/loop/le_loop.c
+5
-0
services/modules/bootevent/bootevent.c
services/modules/bootevent/bootevent.c
+27
-41
services/modules/init_context/init_context.c
services/modules/init_context/init_context.c
+48
-36
services/modules/init_context/init_context.h
services/modules/init_context/init_context.h
+6
-1
services/modules/init_context/init_context_static.c
services/modules/init_context/init_context_static.c
+8
-0
services/modules/init_eng/init_eng.c
services/modules/init_eng/init_eng.c
+1
-1
services/modules/init_eng/init_eng_static.c
services/modules/init_eng/init_eng_static.c
+2
-0
services/modules/reboot/reboot.c
services/modules/reboot/reboot.c
+5
-5
services/modules/sysevent/startup_time_event.c
services/modules/sysevent/startup_time_event.c
+5
-7
services/modules/sysevent/sys_event.c
services/modules/sysevent/sys_event.c
+1
-3
services/modules/trace/init_trace.c
services/modules/trace/init_trace.c
+15
-33
services/modules/udid/udid.h
services/modules/udid/udid.h
+8
-2
services/modules/udid/udid_adp.c
services/modules/udid/udid_adp.c
+3
-3
test/unittest/BUILD.gn
test/unittest/BUILD.gn
+2
-0
test/unittest/begetctl/begetctl_unittest.cpp
test/unittest/begetctl/begetctl_unittest.cpp
+45
-0
test/unittest/init/cmds_unittest.cpp
test/unittest/init/cmds_unittest.cpp
+17
-1
test/unittest/init/group_unittest.cpp
test/unittest/init/group_unittest.cpp
+13
-12
test/unittest/init/init_reboot_unittest.cpp
test/unittest/init/init_reboot_unittest.cpp
+17
-0
test/unittest/init/init_unittest.cpp
test/unittest/init/init_unittest.cpp
+3
-1
test/unittest/init/service_file_unittest.cpp
test/unittest/init/service_file_unittest.cpp
+1
-1
test/unittest/init/service_unittest.cpp
test/unittest/init/service_unittest.cpp
+7
-7
test/unittest/init/utils_unittest.cpp
test/unittest/init/utils_unittest.cpp
+42
-0
test/unittest/innerkits/hookmgr_unittest.cpp
test/unittest/innerkits/hookmgr_unittest.cpp
+55
-55
test/unittest/innerkits/innerkits_unittest.cpp
test/unittest/innerkits/innerkits_unittest.cpp
+19
-12
test/unittest/innerkits/modulemgr_unittest.cpp
test/unittest/innerkits/modulemgr_unittest.cpp
+16
-5
test/unittest/lite/cmd_func_test.cpp
test/unittest/lite/cmd_func_test.cpp
+1
-1
test/unittest/loopevent/loopevent_unittest.cpp
test/unittest/loopevent/loopevent_unittest.cpp
+22
-10
test/unittest/modules/context_unittest.cpp
test/unittest/modules/context_unittest.cpp
+108
-4
test/unittest/modules/eng_unittest.cpp
test/unittest/modules/eng_unittest.cpp
+21
-15
test/unittest/modules/modules_unittest.cpp
test/unittest/modules/modules_unittest.cpp
+5
-2
test/unittest/modules/sysevent_unittest.cpp
test/unittest/modules/sysevent_unittest.cpp
+10
-3
test/unittest/modules/trace_unittest.cpp
test/unittest/modules/trace_unittest.cpp
+34
-3
test/unittest/modules/udid_unittest.cpp
test/unittest/modules/udid_unittest.cpp
+60
-0
test/unittest/param/client_unittest.cpp
test/unittest/param/client_unittest.cpp
+10
-1
test/unittest/param/param_stub.cpp
test/unittest/param/param_stub.cpp
+14
-4
test/unittest/param/param_stub.h
test/unittest/param/param_stub.h
+28
-0
test/unittest/param/param_unittest.cpp
test/unittest/param/param_unittest.cpp
+17
-11
test/unittest/param/paramservice_unittest.cpp
test/unittest/param/paramservice_unittest.cpp
+3
-2
test/unittest/param/trigger_unittest.cpp
test/unittest/param/trigger_unittest.cpp
+3
-3
test/unittest/param/watcher_agent_unittest.cpp
test/unittest/param/watcher_agent_unittest.cpp
+1
-1
test/unittest/seccomp/seccomp_unittest.cpp
test/unittest/seccomp/seccomp_unittest.cpp
+10
-1
test/unittest/syspara/syspara_unittest.cpp
test/unittest/syspara/syspara_unittest.cpp
+16
-0
test/unittest/ueventd/ueventd_event_unittest.cpp
test/unittest/ueventd/ueventd_event_unittest.cpp
+170
-0
ueventd/include/ueventd_firmware_handler.h
ueventd/include/ueventd_firmware_handler.h
+12
-0
ueventd/ueventd.c
ueventd/ueventd.c
+1
-5
未找到文件。
interfaces/innerkits/control_fd/control_fd_service.c
浏览文件 @
0da55118
...
...
@@ -67,10 +67,7 @@ CONTROL_FD_STATIC void CmdOnRecvMessage(const TaskHandle task, const uint8_t *bu
return
;
}
if
(
CheckSocketPermission
(
task
)
<
0
)
{
BEGET_LOGE
(
"Check socket permission failed, err = %d"
,
errno
);
return
;
}
BEGET_ERROR_CHECK
(
CheckSocketPermission
(
task
)
>=
0
,
return
,
"Check socket permission failed, err = %d"
,
errno
);
#ifndef STARTUP_INIT_TEST
agent
->
pid
=
fork
();
...
...
interfaces/innerkits/fd_holder/fd_holder.c
浏览文件 @
0da55118
...
...
@@ -26,26 +26,21 @@ static int BuildClientSocket(void)
{
int
sockFd
;
sockFd
=
socket
(
AF_UNIX
,
SOCK_DGRAM
|
SOCK_CLOEXEC
,
0
);
if
(
sockFd
<
0
)
{
BEGET_LOGE
(
"Failed to build socket, err = %d"
,
errno
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
sockFd
>=
0
,
return
-
1
,
"Failed to build socket, err = %d"
,
errno
);
struct
sockaddr_un
addr
;
(
void
)
memset_s
(
&
addr
,
sizeof
(
addr
),
0
,
sizeof
(
addr
));
addr
.
sun_family
=
AF_UNIX
;
if
(
strncpy_s
(
addr
.
sun_path
,
sizeof
(
addr
.
sun_path
),
INIT_HOLDER_SOCKET_PATH
,
strlen
(
INIT_HOLDER_SOCKET_PATH
))
!=
0
)
{
BEGET_LOGE
(
"Failed to build socket path"
);
close
(
sockFd
);
return
-
1
;
}
int
ret
=
strncpy_s
(
addr
.
sun_path
,
sizeof
(
addr
.
sun_path
),
INIT_HOLDER_SOCKET_PATH
,
strlen
(
INIT_HOLDER_SOCKET_PATH
));
BEGET_ERROR_CHECK
(
ret
==
0
,
close
(
sockFd
);
return
-
1
,
"Failed to build socket path"
);
socklen_t
len
=
(
socklen_t
)(
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
strlen
(
addr
.
sun_path
)
+
1
);
if
(
connect
(
sockFd
,
(
struct
sockaddr
*
)
&
addr
,
len
)
<
0
)
{
BEGET_LOGE
(
"Failed to connect to socket, err = %d"
,
errno
);
close
(
sockFd
);
return
-
1
;
}
ret
=
connect
(
sockFd
,
(
struct
sockaddr
*
)
&
addr
,
len
);
BEGET_ERROR_CHECK
(
ret
>=
0
,
close
(
sockFd
);
return
-
1
,
"Failed to connect to socket, err = %d"
,
errno
);
return
sockFd
;
}
...
...
@@ -79,9 +74,8 @@ STATIC int BuildSendData(char *buffer, size_t size, const char *serviceName, boo
static
int
ServiceSendFds
(
const
char
*
serviceName
,
int
*
fds
,
int
fdCount
,
bool
doPoll
)
{
int
sock
=
BuildClientSocket
();
if
(
sock
<
0
)
{
return
-
1
;
}
BEGET_CHECK
(
sock
>=
0
,
return
-
1
);
struct
iovec
iovec
=
{};
struct
msghdr
msghdr
=
{
.
msg_iov
=
&
iovec
,
...
...
@@ -89,11 +83,9 @@ static int ServiceSendFds(const char *serviceName, int *fds, int fdCount, bool d
};
char
sendBuffer
[
MAX_FD_HOLDER_BUFFER
]
=
{};
if
(
BuildSendData
(
sendBuffer
,
sizeof
(
sendBuffer
),
serviceName
,
true
,
doPoll
)
<
0
)
{
BEGET_LOGE
(
"Failed to build send data"
);
close
(
sock
);
return
-
1
;
}
int
ret
=
BuildSendData
(
sendBuffer
,
sizeof
(
sendBuffer
),
serviceName
,
true
,
doPoll
);
BEGET_ERROR_CHECK
(
ret
>=
0
,
close
(
sock
);
return
-
1
,
"Failed to build send data"
);
BEGET_LOGV
(
"Send data: [%s]"
,
sendBuffer
);
iovec
.
iov_base
=
sendBuffer
;
...
...
@@ -171,28 +163,20 @@ int *ServiceGetFd(const char *serviceName, size_t *outfdCount)
BEGET_LOGV
(
"fds = %s"
,
fdBuffer
);
int
fdCount
=
0
;
char
**
fdList
=
SplitStringExt
(
fdBuffer
,
" "
,
&
fdCount
,
MAX_HOLD_FDS
);
if
(
fdList
==
NULL
)
{
BEGET_LOGE
(
"Cannot get fd list"
);
return
NULL
;
}
BEGET_ERROR_CHECK
(
fdList
!=
NULL
,
return
NULL
,
"Cannot get fd list"
);
int
*
fds
=
calloc
((
size_t
)
fdCount
,
sizeof
(
int
));
if
(
fds
==
NULL
)
{
BEGET_LOGE
(
"Allocate memory for fd failed. err = %d"
,
errno
);
FreeStringVector
(
fdList
,
fdCount
);
BEGET_ERROR_CHECK
(
fds
!=
NULL
,
FreeStringVector
(
fdList
,
fdCount
);
*
outfdCount
=
0
;
return
NULL
;
}
return
NULL
,
"Allocate memory for fd failed. err = %d"
,
errno
);
bool
encounterError
=
false
;
for
(
int
i
=
0
;
i
<
fdCount
;
i
++
)
{
errno
=
0
;
fds
[
i
]
=
(
int
)
strtol
(
fdList
[
i
],
NULL
,
DECIMAL_BASE
);
if
(
errno
!=
0
)
{
BEGET_LOGE
(
"Failed to convert
\'
%s
\'
to fd number"
,
fdList
[
i
]);
encounterError
=
true
;
break
;
}
BEGET_ERROR_CHECK
(
errno
==
0
,
encounterError
=
true
;
break
,
"Failed to convert
\'
%s
\'
to fd number"
,
fdList
[
i
]);
}
if
(
encounterError
)
{
...
...
interfaces/innerkits/fd_holder/fd_holder_internal.c
浏览文件 @
0da55118
...
...
@@ -41,10 +41,7 @@ int BuildControlMessage(struct msghdr *msghdr, int *fds, int fdCount, bool send
}
msghdr
->
msg_control
=
calloc
(
1
,
((
msghdr
->
msg_controllen
==
0
)
?
1
:
msghdr
->
msg_controllen
));
if
(
msghdr
->
msg_control
==
NULL
)
{
BEGET_LOGE
(
"Failed to build control message"
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
msghdr
->
msg_control
!=
NULL
,
return
-
1
,
"Failed to build control message"
);
struct
cmsghdr
*
cmsg
=
NULL
;
cmsg
=
CMSG_FIRSTHDR
(
msghdr
);
...
...
@@ -54,21 +51,16 @@ int BuildControlMessage(struct msghdr *msghdr, int *fds, int fdCount, bool send
cmsg
->
cmsg_type
=
SCM_RIGHTS
;
cmsg
->
cmsg_len
=
CMSG_LEN
(
sizeof
(
int
)
*
fdCount
);
int
ret
=
memcpy_s
(
CMSG_DATA
(
cmsg
),
cmsg
->
cmsg_len
,
fds
,
sizeof
(
int
)
*
fdCount
);
if
(
ret
!=
0
)
{
BEGET_LOGE
(
"Control message is not valid"
);
free
(
msghdr
->
msg_control
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
ret
==
0
,
free
(
msghdr
->
msg_control
);
return
-
1
,
"Control message is not valid"
);
// build ucred info
cmsg
=
CMSG_NXTHDR
(
msghdr
,
cmsg
);
}
if
(
sendUcred
)
{
if
(
cmsg
==
NULL
)
{
BEGET_LOGE
(
"Control message is not valid"
);
free
(
msghdr
->
msg_control
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
cmsg
!=
NULL
,
free
(
msghdr
->
msg_control
);
return
-
1
,
"Control message is not valid"
);
struct
ucred
*
ucred
;
cmsg
->
cmsg_level
=
SOL_SOCKET
;
cmsg
->
cmsg_type
=
SCM_CREDENTIALS
;
...
...
interfaces/innerkits/fs_manager/fstab_mount.c
浏览文件 @
0da55118
...
...
@@ -76,15 +76,12 @@ bool IsSupportedFilesystem(const char *fsType)
static
int
ExecCommand
(
int
argc
,
char
**
argv
)
{
if
(
argc
==
0
||
argv
==
NULL
||
argv
[
0
]
==
NULL
)
{
return
-
1
;
}
BEGET_CHECK
(
!
(
argc
==
0
||
argv
==
NULL
||
argv
[
0
]
==
NULL
),
return
-
1
);
BEGET_LOGI
(
"Execute %s begin"
,
argv
[
0
]);
pid_t
pid
=
fork
();
if
(
pid
<
0
)
{
BEGET_LOGE
(
"Fork new process to format failed: %d"
,
errno
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
pid
>=
0
,
return
-
1
,
"Fork new process to format failed: %d"
,
errno
);
if
(
pid
==
0
)
{
execv
(
argv
[
0
],
argv
);
exit
(
-
1
);
...
...
@@ -112,10 +109,9 @@ int DoFormat(const char *devPath, const char *fsType)
if
(
strcmp
(
fsType
,
"ext4"
)
==
0
)
{
char
blockSizeBuffer
[
BLOCK_SIZE_BUFFER
]
=
{
0
};
const
unsigned
int
blockSize
=
4096
;
if
(
snprintf_s
(
blockSizeBuffer
,
BLOCK_SIZE_BUFFER
,
BLOCK_SIZE_BUFFER
-
1
,
"%u"
,
blockSize
)
==
-
1
)
{
BEGET_LOGE
(
"Failed to build block size buffer"
);
return
-
1
;
}
ret
=
snprintf_s
(
blockSizeBuffer
,
BLOCK_SIZE_BUFFER
,
BLOCK_SIZE_BUFFER
-
1
,
"%u"
,
blockSize
);
BEGET_ERROR_CHECK
(
ret
!=
-
1
,
return
-
1
,
"Failed to build block size buffer"
);
char
*
formatCmds
[]
=
{
"/bin/mke2fs"
,
"-F"
,
"-t"
,
(
char
*
)
fsType
,
"-b"
,
blockSizeBuffer
,
(
char
*
)
devPath
,
NULL
};
...
...
@@ -152,9 +148,8 @@ MountStatus GetMountStatusForMountPoint(const char *mp)
bool
found
=
false
;
FILE
*
fp
=
fopen
(
"/proc/mounts"
,
"r"
);
if
(
fp
==
NULL
)
{
return
status
;
}
BEGET_CHECK
(
fp
!=
NULL
,
return
status
);
while
(
fgets
(
buffer
,
sizeof
(
buffer
)
-
1
,
fp
)
!=
NULL
)
{
size_t
n
=
strlen
(
buffer
);
if
(
buffer
[
n
-
1
]
==
'\n'
)
{
...
...
@@ -184,10 +179,7 @@ MountStatus GetMountStatusForMountPoint(const char *mp)
static
int
DoResizeF2fs
(
const
char
*
device
,
const
unsigned
long
long
size
)
{
char
*
file
=
"/system/bin/resize.f2fs"
;
if
(
access
(
file
,
F_OK
)
!=
0
)
{
BEGET_LOGE
(
"resize.f2fs is not exists."
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
access
(
file
,
F_OK
)
==
0
,
return
-
1
,
"resize.f2fs is not exists."
);
int
ret
=
0
;
if
(
size
==
0
)
{
...
...
@@ -218,10 +210,7 @@ static int DoResizeF2fs(const char* device, const unsigned long long size)
static
int
DoFsckF2fs
(
const
char
*
device
)
{
char
*
file
=
"/system/bin/fsck.f2fs"
;
if
(
access
(
file
,
F_OK
)
!=
0
)
{
BEGET_LOGE
(
"fsck.f2fs is not exists."
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
access
(
file
,
F_OK
)
==
0
,
return
-
1
,
"fsck.f2fs is not exists."
);
char
*
cmd
[]
=
{
file
,
"-a"
,
(
char
*
)
device
,
NULL
...
...
@@ -234,10 +223,7 @@ static int DoFsckF2fs(const char* device)
static
int
DoResizeExt
(
const
char
*
device
,
const
unsigned
long
long
size
)
{
char
*
file
=
"/system/bin/resize2fs"
;
if
(
access
(
file
,
F_OK
)
!=
0
)
{
BEGET_LOGE
(
"resize2fs is not exists."
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
access
(
file
,
F_OK
)
==
0
,
return
-
1
,
"resize2fs is not exists."
);
int
ret
=
0
;
if
(
size
==
0
)
{
...
...
@@ -266,10 +252,7 @@ static int DoResizeExt(const char* device, const unsigned long long size)
static
int
DoFsckExt
(
const
char
*
device
)
{
char
*
file
=
"/system/bin/e2fsck"
;
if
(
access
(
file
,
F_OK
)
!=
0
)
{
BEGET_LOGE
(
"e2fsck is not exists."
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
access
(
file
,
F_OK
)
==
0
,
return
-
1
,
"e2fsck is not exists."
);
char
*
cmd
[]
=
{
file
,
"-y"
,
(
char
*
)
device
,
NULL
...
...
@@ -285,22 +268,16 @@ static int Mount(const char *source, const char *target, const char *fsType,
struct
stat
st
=
{};
int
rc
=
-
1
;
if
(
source
==
NULL
||
target
==
NULL
||
fsType
==
NULL
)
{
BEGET_LOGE
(
"Invalid argument for mount."
);
return
-
1
;
}
if
(
stat
(
target
,
&
st
)
!=
0
&&
errno
!=
ENOENT
)
{
BEGET_LOGE
(
"Cannot get stat of
\"
%s
\"
, err = %d"
,
target
,
errno
);
return
-
1
;
}
if
((
st
.
st_mode
&
S_IFMT
)
==
S_IFLNK
)
{
// link, delete it.
unlink
(
target
);
}
bool
isTrue
=
source
==
NULL
||
target
==
NULL
||
fsType
==
NULL
;
BEGET_ERROR_CHECK
(
!
isTrue
,
return
-
1
,
"Invalid argument for mount."
);
isTrue
=
stat
(
target
,
&
st
)
!=
0
&&
errno
!=
ENOENT
;
BEGET_ERROR_CHECK
(
!
isTrue
,
return
-
1
,
"Cannot get stat of
\"
%s
\"
, err = %d"
,
target
,
errno
);
BEGET_CHECK
((
st
.
st_mode
&
S_IFMT
)
!=
S_IFLNK
,
unlink
(
target
));
// link, delete it.
if
(
mkdir
(
target
,
S_IRWXU
|
S_IRWXG
|
S_IROTH
|
S_IXOTH
)
<
0
)
{
if
(
errno
!=
EEXIST
)
{
BEGET_LOGE
(
"Failed to create dir
\"
%s
\"
, err = %d"
,
target
,
errno
);
return
-
1
;
}
BEGET_ERROR_CHECK
(
errno
==
EEXIST
,
return
-
1
,
"Failed to create dir
\"
%s
\"
, err = %d"
,
target
,
errno
);
}
errno
=
0
;
if
((
rc
=
mount
(
source
,
target
,
fsType
,
flags
,
data
))
!=
0
)
{
...
...
@@ -468,9 +445,7 @@ static int CheckRequiredAndMount(FstabItem *item, bool required)
int
MountAllWithFstab
(
const
Fstab
*
fstab
,
bool
required
)
{
if
(
fstab
==
NULL
)
{
return
-
1
;
}
BEGET_CHECK
(
fstab
!=
NULL
,
return
-
1
);
FstabItem
*
item
=
NULL
;
int
rc
=
-
1
;
...
...
@@ -501,9 +476,9 @@ int MountAllWithFstab(const Fstab *fstab, bool required)
int
MountAllWithFstabFile
(
const
char
*
fstabFile
,
bool
required
)
{
if
(
fstabFile
==
NULL
||
*
fstabFile
==
'\0'
)
{
return
-
1
;
}
bool
isFile
=
fstabFile
==
NULL
||
*
fstabFile
==
'\0'
;
BEGET_CHECK
(
!
isFile
,
return
-
1
)
;
Fstab
*
fstab
=
NULL
;
if
((
fstab
=
ReadFstabFromFile
(
fstabFile
,
false
))
==
NULL
)
{
BEGET_LOGE
(
"[fs_manager][error] Read fstab file
\"
%s
\"
failed
\n
"
,
fstabFile
);
...
...
@@ -518,14 +493,12 @@ int MountAllWithFstabFile(const char *fstabFile, bool required)
int
UmountAllWithFstabFile
(
const
char
*
fstabFile
)
{
if
(
fstabFile
==
NULL
||
*
fstabFile
==
'\0'
)
{
return
-
1
;
}
bool
isFile
=
fstabFile
==
NULL
||
*
fstabFile
==
'\0'
;
BEGET_CHECK
(
!
isFile
,
return
-
1
)
;
Fstab
*
fstab
=
NULL
;
if
((
fstab
=
ReadFstabFromFile
(
fstabFile
,
false
))
==
NULL
)
{
BEGET_LOGE
(
"Read fstab file
\"
%s
\"
failed."
,
fstabFile
);
return
-
1
;
}
fstab
=
ReadFstabFromFile
(
fstabFile
,
false
);
BEGET_ERROR_CHECK
(
fstab
!=
NULL
,
return
-
1
,
"Read fstab file
\"
%s
\"
failed."
,
fstabFile
);
FstabItem
*
item
=
NULL
;
int
rc
=
-
1
;
...
...
interfaces/innerkits/include/beget_ext.h
浏览文件 @
0da55118
...
...
@@ -57,6 +57,14 @@ typedef enum InitLogLevel {
#define STATIC static
#endif
#ifndef STARTUP_INIT_UT_PATH
#ifdef STARTUP_INIT_TEST // ut
#define STARTUP_INIT_UT_PATH "/data/init_ut"
#else
#define STARTUP_INIT_UT_PATH ""
#endif
#endif
INIT_PUBLIC_API
void
StartupLog
(
InitLogLevel
logLevel
,
uint32_t
domain
,
const
char
*
tag
,
const
char
*
fmt
,
...);
INIT_PUBLIC_API
void
SetInitLogLevel
(
InitLogLevel
level
);
INIT_PUBLIC_API
InitLogLevel
GetInitLogLevel
(
void
);
...
...
interfaces/innerkits/modulemgr/modulemgr.c
浏览文件 @
0da55118
...
...
@@ -100,21 +100,20 @@ static void *ModuleInstall(MODULE_ITEM *module, int argc, const char *argv[])
{
void
*
handle
;
char
path
[
PATH_MAX
];
int
rc
;
module
->
moduleMgr
->
installArgs
.
argc
=
argc
;
module
->
moduleMgr
->
installArgs
.
argv
=
argv
;
BEGET_LOGV
(
"Module install name %s"
,
module
->
name
);
if
(
module
->
name
[
0
]
==
'/'
)
{
if
(
snprintf_s
(
path
,
sizeof
(
path
),
sizeof
(
path
)
-
1
,
"%s"
MODULE_SUFFIX_D
,
module
->
name
)
<
0
)
{
return
NULL
;
}
rc
=
snprintf_s
(
path
,
sizeof
(
path
),
sizeof
(
path
)
-
1
,
STARTUP_INIT_UT_PATH
"%s"
MODULE_SUFFIX_D
,
module
->
name
);
BEGET_CHECK
(
rc
>=
0
,
return
NULL
);
}
else
{
const
char
*
fmt
=
(
InUpdaterMode
()
==
0
)
?
"/system/"
MODULE_LIB_NAME
:
"/"
MODULE_LIB_NAME
;
if
(
snprintf_s
(
path
,
sizeof
(
path
),
sizeof
(
path
)
-
1
,
"%s/%s/lib%s"
MODULE_SUFFIX_D
,
fmt
,
module
->
moduleMgr
->
name
,
module
->
name
)
<
0
)
{
return
NULL
;
}
rc
=
snprintf_s
(
path
,
sizeof
(
path
),
sizeof
(
path
)
-
1
,
STARTUP_INIT_UT_PATH
"%s/%s/lib%s"
MODULE_SUFFIX_D
,
fmt
,
module
->
moduleMgr
->
name
,
module
->
name
);
BEGET_CHECK
(
rc
>=
0
,
return
NULL
);
}
BEGET_LOGV
(
"Module install path %s"
,
path
);
char
*
realPath
=
GetRealPath
(
path
);
...
...
@@ -162,19 +161,18 @@ int ModuleMgrInstall(MODULE_MGR *moduleMgr, const char *moduleName,
module
->
moduleMgr
=
moduleMgr
;
module
->
name
=
strdup
(
moduleName
);
if
(
module
->
name
==
NULL
)
{
ModuleDestroy
((
ListNode
*
)
module
);
return
-
1
;
}
BEGET_CHECK
(
module
->
name
!=
NULL
,
free
(
module
);
return
-
1
);
// Install
module
->
handle
=
ModuleInstall
(
module
,
argc
,
argv
);
#ifndef STARTUP_INIT_TEST
if
(
module
->
handle
==
NULL
)
{
BEGET_LOGE
(
"Failed to install module %s"
,
module
->
name
);
ModuleDestroy
((
ListNode
*
)
module
);
return
-
1
;
}
#endif
// Add to list
OH_ListAddTail
(
&
(
moduleMgr
->
modules
),
(
ListNode
*
)
module
);
...
...
@@ -240,7 +238,7 @@ MODULE_MGR *ModuleMgrScan(const char *modulePath)
{
MODULE_MGR
*
moduleMgr
;
char
path
[
PATH_MAX
];
BEGET_LOGV
(
"ModuleMgrScan moduleName %s"
,
modulePath
);
moduleMgr
=
ModuleMgrCreate
(
modulePath
);
BEGET_CHECK
(
moduleMgr
!=
NULL
,
return
NULL
);
...
...
interfaces/innerkits/syscap/init_syscap.c
浏览文件 @
0da55118
...
...
@@ -32,6 +32,7 @@ bool HasSystemCapability(const char *cap)
char
capName
[
SYSCAP_MAX_SIZE
]
=
{
0
};
char
paramValue
[
PARAM_VALUE_LEN_MAX
]
=
{
0
};
unsigned
int
valueLen
=
PARAM_VALUE_LEN_MAX
;
int
rc
=
-
1
;
if
(
cap
==
NULL
)
{
BEGET_LOGE
(
"cap input is null."
);
...
...
@@ -39,10 +40,8 @@ bool HasSystemCapability(const char *cap)
}
if
(
strncmp
(
SYSCAP_PREFIX_NAME
,
cap
,
sizeof
(
SYSCAP_PREFIX_NAME
)
-
1
)
==
0
)
{
if
(
snprintf_s
(
capName
,
SYSCAP_MAX_SIZE
,
SYSCAP_MAX_SIZE
-
1
,
"const.%s"
,
cap
)
==
-
1
)
{
BEGET_LOGE
(
"Failed snprintf_s err=%d"
,
errno
);
return
false
;
}
rc
=
snprintf_s
(
capName
,
SYSCAP_MAX_SIZE
,
SYSCAP_MAX_SIZE
-
1
,
"const.%s"
,
cap
);
BEGET_ERROR_CHECK
(
rc
!=
0
,
return
false
,
"Failed snprintf_s err=%d"
,
errno
);
}
else
if
(
snprintf_s
(
capName
,
SYSCAP_MAX_SIZE
,
SYSCAP_MAX_SIZE
-
1
,
CONST_SYSCAP_PREFIX_NAME
".%s"
,
cap
)
==
-
1
)
{
BEGET_LOGE
(
"Failed snprintf_s err=%d"
,
errno
);
return
false
;
...
...
services/include/init_utils.h
浏览文件 @
0da55118
...
...
@@ -45,14 +45,6 @@ typedef struct {
#define CMDLINE_VALUE_LEN_MAX 512
#define STDERR_HANDLE 2
#define ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0]))
#ifndef STARTUP_INIT_UT_PATH
#ifdef STARTUP_INIT_TEST // ut
#define STARTUP_INIT_UT_PATH "/data/init_ut"
#else
#define STARTUP_INIT_UT_PATH ""
#endif
#endif
#define BOOT_CMD_LINE STARTUP_INIT_UT_PATH"/proc/cmdline"
uid_t
DecodeUid
(
const
char
*
name
);
...
...
services/init/standard/init.c
浏览文件 @
0da55118
...
...
@@ -93,9 +93,10 @@ static int FdHolderSockInit(void)
void
SystemInit
(
void
)
{
#ifndef STARTUP_INIT_TEST
// Set up a session keyring that all processes will have access to.
KeyCtrlGetKeyringId
(
KEY_SPEC_SESSION_KEYRING
,
1
);
#endif
// umask call always succeeds and return the previous mask value which is not needed here
(
void
)
umask
(
DEFAULT_UMASK_INIT
);
MakeDirRecursive
(
"/dev/unix/socket"
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
|
S_IXOTH
);
...
...
services/loopevent/loop/le_loop.c
浏览文件 @
0da55118
...
...
@@ -103,7 +103,12 @@ LE_STATUS AddTask(EventLoop *loop, BaseTask *task)
LoopMutexLock
(
&
loop
->
mutex
);
int
ret
=
OH_HashMapAdd
(
loop
->
taskMap
,
&
task
->
hashNode
);
LoopMutexUnlock
(
&
loop
->
mutex
);
#ifndef STARTUP_INIT_TEST
return
ret
;
#else
ret
=
0
;
return
ret
;
#endif
}
BaseTask
*
GetTaskByFd
(
EventLoop
*
loop
,
int
fd
)
...
...
services/modules/bootevent/bootevent.c
浏览文件 @
0da55118
...
...
@@ -70,9 +70,9 @@ static int AddServiceBootEvent(const char *serviceName, const char *paramName)
break
;
}
}
if
(
extData
==
NULL
)
{
return
-
1
;
}
INIT_CHECK
(
extData
!=
NULL
,
return
-
1
)
;
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
extData
->
data
;
OH_ListInit
(
&
item
->
node
);
for
(
int
i
=
0
;
i
<
BOOTEVENT_MAX
;
i
++
)
{
...
...
@@ -95,25 +95,21 @@ static void AddInitBootEvent(const char *bootEventName)
ListNode
*
found
=
NULL
;
found
=
OH_ListFind
(
&
bootEventList
,
(
void
*
)
bootEventName
,
ParseBooteventCompareProc
);
if
(
found
!=
NULL
)
{
INIT_CHECK_ONLY_RETURN
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
(((
BOOT_EVENT_PARAM_ITEM
*
)
found
)
->
timestamp
[
BOOTEVENT_READY
]))
==
0
);
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
(((
BOOT_EVENT_PARAM_ITEM
*
)
found
)
->
timestamp
[
BOOTEVENT_READY
]));
return
;
}
BOOT_EVENT_PARAM_ITEM
*
item
=
calloc
(
1
,
sizeof
(
BOOT_EVENT_PARAM_ITEM
));
if
(
item
==
NULL
)
{
return
;
}
INIT_CHECK
(
item
!=
NULL
,
return
);
OH_ListInit
(
&
item
->
node
);
if
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
item
->
timestamp
[
BOOTEVENT_FORK
]))
!=
0
)
{
free
(
item
);
return
;
}
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
item
->
timestamp
[
BOOTEVENT_FORK
]));
item
->
paramName
=
strdup
(
bootEventName
);
if
(
item
->
paramName
==
NULL
)
{
free
(
item
);
return
;
}
INIT_CHECK
(
item
->
paramName
!=
NULL
,
free
(
item
);
return
);
item
->
flags
=
BOOTEVENT_TYPE_JOB
;
OH_ListAddTail
(
&
bootEventList
,
(
ListNode
*
)
&
item
->
node
);
return
;
...
...
@@ -170,9 +166,7 @@ static int BootEventTraversal(ListNode *node, void *root)
static
int
SaveServiceBootEvent
()
{
if
(
!
GetBootEventEnable
())
{
return
0
;
}
INIT_CHECK
(
GetBootEventEnable
(),
return
0
);
time_t
nowTime
=
time
(
NULL
);
INIT_CHECK_RETURN_VALUE
(
nowTime
>
0
,
-
1
);
struct
tm
*
p
=
localtime
(
&
nowTime
);
...
...
@@ -185,10 +179,9 @@ static int SaveServiceBootEvent()
FILE
*
tmpFile
=
fopen
(
bootEventFileName
,
"wr"
);
INIT_CHECK_RETURN_VALUE
(
tmpFile
!=
NULL
,
-
1
);
cJSON
*
root
=
cJSON_CreateArray
();
if
(
root
==
NULL
)
{
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
INIT_CHECK
(
root
!=
NULL
,
(
void
)
fclose
(
tmpFile
);
return
-
1
);
OH_ListTraversal
(
&
bootEventList
,
(
void
*
)
root
,
BootEventTraversal
,
0
);
char
*
buff
=
cJSON_Print
(
root
);
if
(
buff
==
NULL
)
{
...
...
@@ -206,11 +199,11 @@ static int SaveServiceBootEvent()
static
void
ReportSysEvent
(
void
)
{
if
(
!
GetBootEventEnable
())
{
return
;
}
INIT_CHECK
(
GetBootEventEnable
(),
return
);
#ifndef STARTUP_INIT_TEST
InitModuleMgrInstall
(
"eventmodule"
);
InitModuleMgrUnInstall
(
"eventmodule"
);
#endif
return
;
}
...
...
@@ -229,18 +222,17 @@ static void BootEventParaFireByName(const char *paramName)
{
ListNode
*
found
=
NULL
;
char
*
bootEventValue
=
strrchr
(
paramName
,
'.'
);
if
(
bootEventValue
==
NULL
)
{
return
;
}
INIT_CHECK
(
bootEventValue
!=
NULL
,
return
);
bootEventValue
[
0
]
=
'\0'
;
found
=
OH_ListFind
(
&
bootEventList
,
(
void
*
)
paramName
,
BootEventParaListCompareProc
);
if
(
found
==
NULL
)
{
return
;
}
i
f
(((
BOOT_EVENT_PARAM_ITEM
*
)
found
)
->
timestamp
[
BOOTEVENT_READY
].
tv_sec
!=
0
)
{
return
;
}
i
nt
ret
=
((
BOOT_EVENT_PARAM_ITEM
*
)
found
)
->
timestamp
[
BOOTEVENT_READY
].
tv_sec
;
INIT_CHECK
(
ret
==
0
,
return
)
;
INIT_CHECK_ONLY_RETURN
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
(((
BOOT_EVENT_PARAM_ITEM
*
)
found
)
->
timestamp
[
BOOTEVENT_READY
]))
==
0
);
g_bootEventNum
--
;
...
...
@@ -269,9 +261,7 @@ static void BootEventParaFireByName(const char *paramName)
#define BOOT_EVENT_FIELD_NAME "bootevents"
static
void
ServiceParseBootEventHook
(
SERVICE_PARSE_CTX
*
serviceParseCtx
)
{
if
(
g_bootEventEnable
==
0
)
{
return
;
}
INIT_CHECK
(
g_bootEventEnable
!=
0
,
return
);
int
cnt
;
cJSON
*
bootEvents
=
cJSON_GetObjectItem
(
serviceParseCtx
->
serviceNode
,
BOOT_EVENT_FIELD_NAME
);
...
...
@@ -315,9 +305,7 @@ static void AddCmdBootEvent(int argc, const char **argv)
}
BOOT_EVENT_PARAM_ITEM
*
item
=
calloc
(
1
,
sizeof
(
BOOT_EVENT_PARAM_ITEM
));
if
(
item
==
NULL
)
{
return
;
}
INIT_CHECK
(
item
!=
NULL
,
return
);
OH_ListInit
(
&
item
->
node
);
item
->
timestamp
[
BOOTEVENT_FORK
]
=
((
INIT_TIMING_STAT
*
)
argv
[
3
])
->
startTime
;
// 3 args
item
->
timestamp
[
BOOTEVENT_READY
]
=
((
INIT_TIMING_STAT
*
)
argv
[
3
])
->
endTime
;
// 3 args
...
...
@@ -399,9 +387,7 @@ static void ClearServiceBootEvent(SERVICE_INFO_CTX *serviceCtx)
static
void
SetServiceBootEventFork
(
SERVICE_INFO_CTX
*
serviceCtx
)
{
if
(
g_bootEventEnable
==
0
)
{
return
;
}
INIT_CHECK
(
g_bootEventEnable
!=
0
,
return
);
for
(
int
i
=
HOOK_ID_BOOTEVENT
;
i
<
HOOK_ID_BOOTEVENT_MAX
;
i
++
)
{
ServiceExtData
*
extData
=
GetServiceExtData
(
serviceCtx
->
serviceName
,
i
);
if
(
extData
==
NULL
)
{
...
...
services/modules/init_context/init_context.c
浏览文件 @
0da55118
...
...
@@ -46,6 +46,33 @@ static void HandleRecvMessage(SubInitInfo *subInfo, char *buffer, uint32_t size)
static
int
CreateSocketPair
(
int
socket
[
2
]);
static
int
SubInitSetSelinuxContext
(
InitContextType
type
);
static
int
SubInitRun
(
const
SubInitForkArg
*
arg
)
{
PLUGIN_LOGW
(
"SubInitRun %d "
,
arg
->
type
);
SubInitSetSelinuxContext
(
arg
->
type
);
#ifndef STARTUP_INIT_TEST
close
(
arg
->
socket
[
0
]);
#endif
SubInitMain
(
arg
->
type
,
arg
->
socket
[
1
],
arg
->
socket
[
1
]);
close
(
arg
->
socket
[
1
]);
#ifndef STARTUP_INIT_TEST
_exit
(
PROCESS_EXIT_CODE
);
#else
return
0
;
#endif
}
#ifndef STARTUP_INIT_TEST
pid_t
SubInitFork
(
int
(
*
childFunc
)(
const
SubInitForkArg
*
arg
),
const
SubInitForkArg
*
args
)
{
pid_t
pid
=
fork
();
if
(
pid
==
0
)
{
childFunc
(
args
);
}
return
pid
;
}
#endif
static
int
SubInitStart
(
InitContextType
type
)
{
PLUGIN_CHECK
(
type
<
INIT_CONTEXT_MAIN
,
return
-
1
,
"Invalid type %d"
,
type
);
...
...
@@ -53,28 +80,24 @@ static int SubInitStart(InitContextType type)
if
(
subInfo
->
state
!=
SUB_INIT_STATE_IDLE
)
{
return
0
;
}
int
socket
[
2
]
=
{
0
};
int
ret
=
CreateSocketPair
(
socket
);
SubInitForkArg
arg
=
{
0
};
arg
.
type
=
type
;
int
ret
=
CreateSocketPair
(
arg
.
socket
);
PLUGIN_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to create socket for %d"
,
type
);
subInfo
->
state
=
SUB_INIT_STATE_STARTING
;
pid_t
pid
=
fork
(
);
pid_t
pid
=
SubInitFork
(
SubInitRun
,
&
arg
);
if
(
pid
<
0
)
{
close
(
socket
[
0
]);
close
(
socket
[
1
]);
close
(
arg
.
socket
[
0
]);
close
(
arg
.
socket
[
1
]);
subInfo
->
state
=
SUB_INIT_STATE_IDLE
;
return
-
1
;
}
if
(
pid
==
0
)
{
SubInitSetSelinuxContext
(
type
);
close
(
socket
[
0
]);
SubInitMain
(
type
,
socket
[
1
],
socket
[
1
]);
close
(
socket
[
1
]);
_exit
(
PROCESS_EXIT_CODE
);
}
close
(
socket
[
1
]);
subInfo
->
sendFd
=
socket
[
0
];
subInfo
->
recvFd
=
socket
[
0
];
#ifndef STARTUP_INIT_TEST
close
(
arg
.
socket
[
1
]);
#endif
subInfo
->
sendFd
=
arg
.
socket
[
0
];
subInfo
->
recvFd
=
arg
.
socket
[
0
];
subInfo
->
state
=
SUB_INIT_STATE_RUNNING
;
subInfo
->
subPid
=
pid
;
return
0
;
...
...
@@ -85,7 +108,6 @@ static void SubInitStop(pid_t pid)
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
g_subInitInfo
);
i
++
)
{
if
(
g_subInitInfo
[
i
].
subPid
==
pid
)
{
close
(
g_subInitInfo
[
i
].
sendFd
);
close
(
g_subInitInfo
[
i
].
recvFd
);
g_subInitInfo
[
i
].
subPid
=
0
;
g_subInitInfo
[
i
].
state
=
SUB_INIT_STATE_IDLE
;
}
...
...
@@ -98,10 +120,8 @@ static int SubInitExecuteCmd(InitContextType type, const char *name, const char
PLUGIN_CHECK
(
type
<
INIT_CONTEXT_MAIN
,
return
-
1
,
"Invalid type %d"
,
type
);
PLUGIN_CHECK
(
name
!=
NULL
,
return
-
1
,
"Invalid cmd name"
);
SubInitInfo
*
subInfo
=
&
g_subInitInfo
[
type
];
if
(
subInfo
->
state
!=
SUB_INIT_STATE_RUNNING
)
{
PLUGIN_LOGW
(
"Sub init %d is not running "
,
type
);
return
-
1
;
}
PLUGIN_CHECK
(
subInfo
->
state
==
SUB_INIT_STATE_RUNNING
,
return
-
1
,
"Sub init %d is not running "
,
type
);
int
len
=
0
;
if
(
cmdContent
!=
NULL
)
{
len
=
snprintf_s
(
buffer
,
sizeof
(
buffer
),
sizeof
(
buffer
)
-
1
,
"%s %s"
,
name
,
cmdContent
);
...
...
@@ -124,12 +144,7 @@ static int SubInitExecuteCmd(InitContextType type, const char *name, const char
// change to result
buffer
[
rLen
]
=
'\0'
;
PLUGIN_LOGV
(
"recv cmd result %s"
,
buffer
);
errno
=
0
;
ret
=
atoi
(
buffer
);
if
(
errno
!=
0
)
{
return
errno
;
}
return
ret
;
return
atoi
(
buffer
);
}
static
int
CreateSocketPair
(
int
socket
[
2
])
...
...
@@ -158,12 +173,9 @@ static int CheckSocketPermission(const SubInitInfo *subInfo)
{
struct
ucred
uc
=
{
-
1
,
-
1
,
-
1
};
socklen_t
len
=
sizeof
(
uc
);
if
(
getsockopt
(
subInfo
->
recvFd
,
SOL_SOCKET
,
SO_PEERCRED
,
&
uc
,
&
len
)
<
0
)
{
INIT_LOGE
(
"Failed to get socket option. err = %d"
,
errno
);
return
-
1
;
}
// Only root is permitted to use control fd of init.
if
(
uc
.
uid
!=
0
)
{
// non-root user
if
(
getsockopt
(
subInfo
->
recvFd
,
SOL_SOCKET
,
SO_PEERCRED
,
&
uc
,
&
len
)
<
0
||
uc
.
uid
!=
0
)
{
INIT_LOGE
(
"Failed to get socket option. err = %d"
,
errno
);
errno
=
EPERM
;
return
-
1
;
}
...
...
@@ -202,16 +214,16 @@ static void HandleRecvMessage(SubInitInfo *subInfo, char *buffer, uint32_t size)
static
void
SubInitMain
(
InitContextType
type
,
int
readFd
,
int
writeFd
)
{
PLUGIN_LOGI
(
"SubInitMain, sub init %s[%d] enter"
,
g_subContext
[
type
],
getpid
());
char
buffer
[
MAX_CMD_LEN
]
=
{
0
};
(
void
)
prctl
(
PR_SET_NAME
,
"chipset_init"
);
struct
pollfd
pfd
=
{};
pfd
.
events
=
POLLIN
;
pfd
.
fd
=
readFd
;
#ifndef STARTUP_INIT_TEST
(
void
)
prctl
(
PR_SET_NAME
,
"chipset_init"
);
const
int
timeout
=
30000
;
// 30000 30s
#else
const
int
timeout
=
1000
;
// 1000 1s
#endif
char
buffer
[
MAX_CMD_LEN
]
=
{
0
};
struct
pollfd
pfd
=
{};
pfd
.
events
=
POLLIN
;
pfd
.
fd
=
readFd
;
SubInitInfo
subInfo
=
{};
subInfo
.
type
=
type
;
subInfo
.
recvFd
=
readFd
;
...
...
services/modules/init_context/init_context.h
浏览文件 @
0da55118
...
...
@@ -27,7 +27,6 @@ extern "C" {
#endif
#define MAX_CMD_LEN 512
typedef
enum
{
SUB_INIT_STATE_IDLE
,
SUB_INIT_STATE_STARTING
,
...
...
@@ -56,6 +55,12 @@ int InitSubInitContext(InitContextType type, const SubInitContext *context);
SubInitInfo
*
GetSubInitInfo
(
InitContextType
type
);
#endif
typedef
struct
{
int
socket
[
2
];
InitContextType
type
;
}
SubInitForkArg
;
pid_t
SubInitFork
(
int
(
*
childFunc
)(
const
SubInitForkArg
*
arg
),
const
SubInitForkArg
*
args
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/modules/init_context/init_context_static.c
浏览文件 @
0da55118
...
...
@@ -96,3 +96,11 @@ int CheckExecuteInSubInit(const ConfigContext *context)
return
0
;
#endif
}
#ifdef STARTUP_INIT_TEST
SubInitContext
*
GetSubInitContext
(
InitContextType
type
)
{
PLUGIN_CHECK
(
type
<
INIT_CONTEXT_MAIN
,
return
NULL
,
"Invalid type %d"
,
type
);
return
&
g_subInitContext
[
type
];
}
#endif
services/modules/init_eng/init_eng.c
浏览文件 @
0da55118
...
...
@@ -113,7 +113,7 @@ ENG_STATIC void BindMountFile(const char *source, const char *target)
return
;
}
if
(
q
==
end
-
1
)
{
if
(
*
(
end
-
1
)
==
'/'
)
{
PLUGIN_LOGI
(
"path
\'
%s
\'
ends with slash, ignore it"
,
source
);
return
;
}
...
...
services/modules/init_eng/init_eng_static.c
浏览文件 @
0da55118
...
...
@@ -23,8 +23,10 @@ static int InitEngEarlyHook(const HOOK_INFO *info, void *cookie)
char
value
[
MAX_BUFFER_LEN
]
=
{
0
};
int
ret
=
GetParameterFromCmdLine
(
"ohos.boot.eng_mode"
,
value
,
MAX_BUFFER_LEN
);
if
(
ret
==
0
&&
strcmp
(
value
,
"on"
)
==
0
)
{
#ifndef STARTUP_INIT_TEST
InitModuleMgrInstall
(
"init_eng"
);
InitModuleMgrUnInstall
(
"init_eng"
);
#endif
PLUGIN_LOGI
(
"eng_mode enable."
);
}
return
0
;
...
...
services/modules/reboot/reboot.c
浏览文件 @
0da55118
...
...
@@ -24,7 +24,7 @@
#include "plugin_adapter.h"
#include "securec.h"
static
int
DoRoot_
(
const
char
*
jobName
,
int
type
)
PLUGIN_STATIC
int
DoRoot_
(
const
char
*
jobName
,
int
type
)
{
// by job to stop service and unmount
if
(
jobName
!=
NULL
)
{
...
...
@@ -72,7 +72,7 @@ static int DoRebootPanic(int id, const char *name, int argc, const char **argv)
return
0
;
}
static
int
DoRebootShutdown
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
PLUGIN_STATIC
int
DoRebootShutdown
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
UNUSED
(
name
);
...
...
@@ -110,7 +110,7 @@ static int DoRebootUpdater(int id, const char *name, int argc, const char **argv
return
ret
;
}
static
int
DoRebootFlashed
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
PLUGIN_STATIC
int
DoRebootFlashed
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
PLUGIN_LOGI
(
"DoRebootFlashed argc %d %s"
,
argc
,
name
);
...
...
@@ -123,7 +123,7 @@ static int DoRebootFlashed(int id, const char *name, int argc, const char **argv
return
ret
;
}
static
int
DoRebootCharge
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
PLUGIN_STATIC
int
DoRebootCharge
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
UNUSED
(
name
);
...
...
@@ -145,7 +145,7 @@ static int DoRebootSuspend(int id, const char *name, int argc, const char **argv
return
DoRoot_
(
"suspend"
,
RB_AUTOBOOT
);
}
static
int
DoRebootOther
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
PLUGIN_STATIC
int
DoRebootOther
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
UNUSED
(
id
);
UNUSED
(
name
);
...
...
services/modules/sysevent/startup_time_event.c
浏览文件 @
0da55118
...
...
@@ -36,9 +36,7 @@ static int GetServiceName(const char *paramName, char *buffer, size_t buffSize)
size_t
len
=
strlen
(
paramName
);
size_t
i
=
0
;
for
(
size_t
index
=
strlen
(
"bootevent."
);
index
<
len
;
index
++
)
{
if
(
i
>
buffSize
)
{
return
-
1
;
}
PLUGIN_CHECK
(
i
<=
buffSize
,
return
-
1
);
if
(
*
(
paramName
+
index
)
==
'.'
)
{
break
;
}
...
...
@@ -74,9 +72,9 @@ PLUGIN_STATIC void ReportBootEventComplete(ListNode *events)
{
PLUGIN_CHECK
(
events
!=
NULL
,
return
,
"Invalid events"
);
struct
timespec
curr
=
{
0
};
i
f
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
curr
)
!=
0
)
{
return
;
}
i
nt
ret
=
clock_gettime
(
CLOCK_MONOTONIC
,
&
curr
);
PLUGIN_CHECK
(
ret
==
0
,
return
)
;
char
*
buffer
=
(
char
*
)
calloc
(
MAX_BUFFER_FOR_EVENT
+
PARAM_VALUE_LEN_MAX
,
1
);
PLUGIN_CHECK
(
buffer
!=
NULL
,
return
,
"Failed to get memory for sys event "
);
EventArgs
args
=
{
buffer
,
MAX_BUFFER_FOR_EVENT
,
0
};
...
...
@@ -93,7 +91,7 @@ PLUGIN_STATIC void ReportBootEventComplete(ListNode *events)
startupTime
.
detailTime
=
buffer
;
char
*
reason
=
buffer
+
MAX_BUFFER_FOR_EVENT
;
uint32_t
size
=
PARAM_VALUE_LEN_MAX
;
int
ret
=
SystemReadParam
(
"ohos.boot.bootreason"
,
reason
,
&
size
);
ret
=
SystemReadParam
(
"ohos.boot.bootreason"
,
reason
,
&
size
);
if
(
ret
==
0
)
{
startupTime
.
reason
=
reason
;
startupTime
.
firstStart
=
1
;
...
...
services/modules/sysevent/sys_event.c
浏览文件 @
0da55118
...
...
@@ -56,9 +56,7 @@ static void ReportStartupTimeEvent(const StartupTimeEvent *startupTime)
};
int
ret
=
OH_HiSysEvent_Write
(
STARTUP_DOMAIN
,
"STARTUP_TIME"
,
HISYSEVENT_BEHAVIOR
,
params
,
sizeof
(
params
)
/
sizeof
(
params
[
0
]));
if
(
ret
!=
0
)
{
PLUGIN_LOGE
(
"Failed to write event ret %d"
,
ret
);
}
PLUGIN_ONLY_LOG
(
ret
==
0
,
"Failed to write event ret %d"
,
ret
);
}
void
ReportSysEvent
(
const
StartupEvent
*
event
)
...
...
services/modules/trace/init_trace.c
浏览文件 @
0da55118
...
...
@@ -232,9 +232,7 @@ static bool RefreshServices()
static
cJSON
*
GetArrayItem
(
const
cJSON
*
fileRoot
,
int
*
arrSize
,
const
char
*
arrName
)
{
cJSON
*
arrItem
=
cJSON_GetObjectItemCaseSensitive
(
fileRoot
,
arrName
);
if
(
!
cJSON_IsArray
(
arrItem
))
{
return
NULL
;
}
PLUGIN_CHECK
(
cJSON_IsArray
(
arrItem
),
return
NULL
);
*
arrSize
=
cJSON_GetArraySize
(
arrItem
);
return
*
arrSize
>
0
?
arrItem
:
NULL
;
}
...
...
@@ -282,9 +280,7 @@ static bool SetKernelTraceEnabled(const TraceWorkspace *workspace, bool enabled)
PLUGIN_LOGV
(
"Kernel tag name: %s sys-files %d"
,
name
,
pathCount
);
for
(
int
j
=
0
;
j
<
pathCount
;
j
++
)
{
char
*
path
=
cJSON_GetStringValue
(
cJSON_GetArrayItem
(
paths
,
j
));
if
(
path
==
NULL
)
{
continue
;
}
PLUGIN_CHECK
(
path
!=
NULL
,
continue
);
if
(
!
IsWritableFile
(
path
))
{
PLUGIN_LOGW
(
"Path %s is not writable for %s"
,
path
,
name
);
continue
;
...
...
@@ -367,11 +363,8 @@ static void DumpCompressedTrace(int traceFd, int outFd)
PLUGIN_CHECK
(
ret
!=
Z_STREAM_ERROR
,
break
,
"Error: deflate trace, errno: %d
\n
"
,
errno
);
size_t
have
=
CHUNK_SIZE
-
zs
.
avail_out
;
size_t
bytesWritten
=
(
size_t
)
TEMP_FAILURE_RETRY
(
write
(
outFd
,
outBuffer
,
have
));
if
(
bytesWritten
<
have
)
{
PLUGIN_LOGE
(
"Error: writing deflated trace, errno: %d
\n
"
,
errno
);
flush
=
Z_FINISH
;
// finish
break
;
}
PLUGIN_CHECK
(
bytesWritten
>=
have
,
flush
=
Z_FINISH
;
break
,
"Error: writing deflated trace, errno: %d
\n
"
,
errno
);
}
while
(
zs
.
avail_out
==
0
);
}
while
(
flush
!=
Z_FINISH
);
...
...
@@ -449,29 +442,21 @@ static int InitStartTrace(void)
{
TraceWorkspace
*
workspace
=
GetTraceWorkspace
();
PLUGIN_CHECK
(
workspace
!=
NULL
,
return
0
,
"Failed to get trace workspace"
);
if
(
workspace
->
traceState
!=
TRACE_STATE_IDLE
)
{
PLUGIN_LOGE
(
"Invalid state for trace %d"
,
workspace
->
traceState
);
return
0
;
}
PLUGIN_CHECK
(
workspace
->
traceState
==
TRACE_STATE_IDLE
,
return
0
,
"Invalid state for trace %d"
,
workspace
->
traceState
);
InitTraceWorkspace
(
workspace
);
if
(
!
IsTraceMounted
(
workspace
))
{
return
-
1
;
}
PLUGIN_CHECK
(
IsTraceMounted
(
workspace
),
return
-
1
);
PLUGIN_CHECK
(
workspace
->
traceRootPath
!=
NULL
&&
workspace
->
jsonRootNode
!=
NULL
,
return
-
1
,
"No trace root path or config"
);
// load json init_trace.cfg
if
(
!
SetKernelSpaceSettings
())
{
if
(
!
SetKernelSpaceSettings
()
||
!
SetTraceEnabled
(
TRACING_ON_PATH
,
true
)
)
{
PLUGIN_LOGE
(
"Failed to enable kernel space setting"
);
ClearKernelSpaceSettings
();
return
-
1
;
}
if
(
!
SetTraceEnabled
(
TRACING_ON_PATH
,
true
))
{
PLUGIN_LOGE
(
"Failed to enable trace"
);
ClearKernelSpaceSettings
();
return
-
1
;
}
ClearTrace
();
PLUGIN_LOGI
(
"capturing trace..."
);
if
(
!
SetUserSpaceSettings
())
{
...
...
@@ -489,10 +474,8 @@ static int InitStopTrace(void)
PLUGIN_LOGI
(
"Stop trace now ..."
);
TraceWorkspace
*
workspace
=
GetTraceWorkspace
();
PLUGIN_CHECK
(
workspace
!=
NULL
,
return
0
,
"Failed to get trace workspace"
);
if
(
workspace
->
traceState
!=
TRACE_STATE_STARTED
)
{
PLUGIN_LOGE
(
"Invalid state for trace %d"
,
workspace
->
traceState
);
return
0
;
}
PLUGIN_CHECK
(
workspace
->
traceState
==
TRACE_STATE_STARTED
,
return
0
,
"Invalid state for trace %d"
,
workspace
->
traceState
);
workspace
->
traceState
=
TRACE_STATE_STOPED
;
MarkOthersClockSync
();
...
...
@@ -524,10 +507,9 @@ static int InitInterruptTrace(void)
PLUGIN_LOGI
(
"Interrupt trace now ..."
);
TraceWorkspace
*
workspace
=
GetTraceWorkspace
();
PLUGIN_CHECK
(
workspace
!=
NULL
,
return
0
,
"Failed to get trace workspace"
);
if
(
workspace
->
traceState
!=
TRACE_STATE_STARTED
)
{
PLUGIN_LOGE
(
"Invalid state for trace %d"
,
workspace
->
traceState
);
return
0
;
}
PLUGIN_CHECK
(
workspace
->
traceState
==
TRACE_STATE_STARTED
,
return
0
,
"Invalid state for trace %d"
,
workspace
->
traceState
);
workspace
->
traceState
=
TRACE_STATE_INTERRUPT
;
MarkOthersClockSync
();
// clear user tags first and sleep a little to let apps already be notified.
...
...
services/modules/udid/udid.h
浏览文件 @
0da55118
...
...
@@ -18,7 +18,13 @@
#include "beget_ext.h"
INIT_LOCAL_API
int
GetUdidFromParam
(
char
*
udid
,
uint32_t
size
);
INIT_LOCAL_API
int
CalcDevUdid
(
char
*
udid
,
uint32_t
size
);
#ifdef STARTUP_INIT_TEST
#define INIT_UDID_LOCAL_API
#else
#define INIT_UDID_LOCAL_API INIT_LOCAL_API
#endif
INIT_UDID_LOCAL_API
int
GetUdidFromParam
(
char
*
udid
,
uint32_t
size
);
INIT_UDID_LOCAL_API
int
CalcDevUdid
(
char
*
udid
,
uint32_t
size
);
#endif
/* PLUGIN_UDID_H */
services/modules/udid/udid_adp.c
浏览文件 @
0da55118
...
...
@@ -23,7 +23,7 @@
#include "mbedtls/sha256.h"
static
int
GetSha256Value
(
const
char
*
input
,
char
*
udid
,
uint32_t
udidSize
)
INIT_UDID_LOCAL_API
int
GetSha256Value
(
const
char
*
input
,
char
*
udid
,
uint32_t
udidSize
)
{
if
(
input
==
NULL
)
{
return
EC_FAILURE
;
...
...
@@ -48,7 +48,7 @@ static int GetSha256Value(const char *input, char *udid, uint32_t udidSize)
return
EC_SUCCESS
;
}
INIT_LOCAL_API
int
CalcDevUdid
(
char
*
udid
,
uint32_t
size
)
INIT_
UDID_
LOCAL_API
int
CalcDevUdid
(
char
*
udid
,
uint32_t
size
)
{
char
*
tmp
=
NULL
;
BEGET_ERROR_CHECK
((
tmp
=
(
char
*
)
calloc
(
1
,
DEV_BUF_MAX_LENGTH
))
!=
NULL
,
return
-
1
,
"calloc memory failed!"
);
...
...
@@ -74,7 +74,7 @@ INIT_LOCAL_API int CalcDevUdid(char *udid, uint32_t size)
}
#ifndef OHOS_LITE
static
void
SetDevUdid
()
INIT_UDID_LOCAL_API
void
SetDevUdid
()
{
BEGET_LOGI
(
"Begin calculate udid"
);
char
udid
[
UDID_LEN
]
=
{
0
};
...
...
test/unittest/BUILD.gn
浏览文件 @
0da55118
...
...
@@ -185,6 +185,7 @@ ohos_unittest("init_unittest") {
"loopevent/loopsignal_unittest.cpp",
"modules/eng_unittest.cpp",
"modules/modules_unittest.cpp",
"modules/udid_unittest.cpp",
"param/client_unittest.cpp",
"param/dac_unittest.cpp",
"param/param_shell_unittest.cpp",
...
...
@@ -292,6 +293,7 @@ ohos_unittest("init_unittest") {
"PARAMWORKSPACE_NEED_MUTEX",
"PARAM_SUPPORT_REAL_CHECK",
"DISABLE_INIT_TWO_STAGES",
"INIT_SUPPORT_CHIPSET_INIT",
]
defines += [ "_GNU_SOURCE" ]
...
...
test/unittest/begetctl/begetctl_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -398,6 +398,11 @@ HWTEST_F(BegetctlUnitTest, TestModulectl_5, TestSize.Level1)
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestModulectl_6
,
TestSize
.
Level1
)
{
BShellEnvDirectExecute
(
GetShellHandle
(),
0
,
nullptr
);
}
HWTEST_F
(
BegetctlUnitTest
,
TestServiceControl_1
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
...
...
@@ -510,6 +515,14 @@ HWTEST_F(BegetctlUnitTest, TestSetLogLevel_4, TestSize.Level1)
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestSetLogLevel_5
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
"setloglevel"
};
BShellEnvDirectExecute
(
GetShellHandle
(),
0
,
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestSandbox
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
...
...
@@ -589,4 +602,36 @@ HWTEST_F(BegetctlUnitTest, TestReboot_9, TestSize.Level1)
};
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestGid_1
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
"dac"
,
"gid"
,
"logd"
};
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestGid_2
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
"dac"
};
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestUid_1
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
"dac"
,
"uid"
,
""
};
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
HWTEST_F
(
BegetctlUnitTest
,
TestUid_2
,
TestSize
.
Level1
)
{
const
char
*
args
[]
=
{
"dac"
,
"uid"
,
""
};
BShellEnvDirectExecute
(
GetShellHandle
(),
sizeof
(
args
)
/
sizeof
(
args
[
0
]),
const_cast
<
char
**>
(
args
));
}
}
// namespace init_ut
test/unittest/init/cmds_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -28,7 +28,7 @@ static void DoCmdByName(const char *name, const char *cmdContent)
{
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
name
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
cmdContent
,
NULL
);
DoCmdByIndex
(
cmdIndex
,
cmdContent
,
nullptr
);
}
namespace
init_ut
{
...
...
@@ -46,15 +46,18 @@ public:
HWTEST_F
(
CmdsUnitTest
,
TestCmdExecByName1
,
TestSize
.
Level1
)
{
DoCmdByName
(
"timer_start "
,
"media_service|5000"
);
DoCmdByName
(
"timer_start "
,
"|5000"
);
DoCmdByName
(
"timer_stop "
,
"media_service"
);
DoCmdByName
(
"exec "
,
"media_service"
);
DoCmdByName
(
"syncexec "
,
"/system/bin/toybox"
);
DoCmdByName
(
"load_access_token_id "
,
"media_service"
);
DoCmdByName
(
"load_access_token_id "
,
""
);
DoCmdByName
(
"stopAllServices "
,
"false"
);
DoCmdByName
(
"stopAllServices "
,
"true"
);
DoCmdByName
(
"umount "
,
"/2222222"
);
DoCmdByName
(
"mount "
,
"/2222222"
);
DoCmdByName
(
"mount "
,
"ext4 /2222222 /data wait filecrypt=555"
);
DoCmdByName
(
"umount "
,
"/2222222"
);
DoCmdByName
(
"init_global_key "
,
"/data"
);
DoCmdByName
(
"init_global_key "
,
"arg0 arg1"
);
DoCmdByName
(
"init_main_user "
,
"testUser"
);
...
...
@@ -67,6 +70,19 @@ HWTEST_F(CmdsUnitTest, TestCmdExecByName1, TestSize.Level1)
DoCmdByName
(
"suspend "
,
""
);
DoCmdByName
(
"wait "
,
"1"
);
DoCmdByName
(
"wait "
,
"aaa 1"
);
DoCmdByName
(
"mksandbox"
,
"/sandbox"
);
DoCmdByName
(
"mount_fstab "
,
"/2222222"
);
DoCmdByName
(
"umount_fstab "
,
"/2222222"
);
DoCmdByName
(
"mknode "
,
"node1 node1 node1 node1 node1"
);
DoCmdByName
(
"makedev "
,
"/device1 device2"
);
DoCmdByName
(
"symlink "
,
"/xxx/xxx/xxx1 /xxx/xxx/xxx2"
);
DoCmdByName
(
"load_param "
,
"aaa onlyadd"
);
DoCmdByName
(
"load_persist_params "
,
""
);
DoCmdByName
(
"load_param "
,
""
);
DoCmdByName
(
"setparam "
,
"bbb 0"
);
DoCmdByName
(
"ifup "
,
"aaa, bbb"
);
DoCmdByName
(
"insmod "
,
"a b"
);
DoCmdByName
(
"insmod "
,
"/data /data"
);
}
HWTEST_F
(
CmdsUnitTest
,
TestCommonMkdir
,
TestSize
.
Level1
)
...
...
test/unittest/init/group_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -94,7 +94,7 @@ static void DoCmdByName(const char *name, const char *cmdContent)
{
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
name
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
cmdContent
,
NULL
);
DoCmdByIndex
(
cmdIndex
,
cmdContent
,
nullptr
);
}
namespace
init_ut
{
...
...
@@ -152,7 +152,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap001, TestSize.Level1)
}
OH_HashMapIsEmpty
(
handle
);
OH_HashMapTraverse
(
handle
,
[](
const
HashNode
*
node
,
const
void
*
context
)
{
return
;},
nullptr
);
OH_HashMapDestory
(
handle
,
NULL
);
OH_HashMapDestory
(
handle
,
nullptr
);
}
HWTEST_F
(
InitGroupManagerUnitTest
,
TestHashMap002
,
TestSize
.
Level1
)
...
...
@@ -162,7 +162,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap002, TestSize.Level1)
TestHashNode
*
node4
=
TestCreateHashNode
(
"pre-init"
);
OH_HashMapAdd
(
handle
,
&
node4
->
node
);
OH_HashMapRemove
(
handle
,
"pre-init"
);
TestHashNodeFree
(
&
node4
->
node
,
NULL
);
TestHashNodeFree
(
&
node4
->
node
,
nullptr
);
const
char
*
act
=
"load_persist_props_action"
;
TestHashNode
*
node5
=
TestCreateHashNode
(
act
);
...
...
@@ -175,7 +175,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap002, TestSize.Level1)
}
OH_HashMapIsEmpty
(
handle
);
OH_HashMapTraverse
(
handle
,
[](
const
HashNode
*
node
,
const
void
*
context
)
{
return
;},
nullptr
);
OH_HashMapDestory
(
handle
,
NULL
);
OH_HashMapDestory
(
handle
,
nullptr
);
}
HWTEST_F
(
InitGroupManagerUnitTest
,
TestInitGroupMgrInit
,
TestSize
.
Level1
)
...
...
@@ -186,7 +186,8 @@ HWTEST_F(InitGroupManagerUnitTest, TestInitGroupMgrInit, TestSize.Level1)
workspace
->
groupMode
=
GROUP_BOOT
;
if
(
strcpy_s
(
workspace
->
groupModeStr
,
GROUP_NAME_MAX_LENGTH
,
"device.boot.group"
)
!=
EOK
)
{
EXPECT_EQ
(
1
,
0
);
}
// test read cfgfile
}
// test read cfgfile
int
ret
=
InitParseGroupCfg
();
EXPECT_EQ
(
ret
,
0
);
}
...
...
@@ -323,12 +324,12 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1)
cJSON_Delete
(
fileRoot
);
char
cmdStr
[]
=
"all#bootevent"
;
char
cmdStr1
[]
=
"parameter_service"
;
ProcessControlFd
(
ACTION_DUMP
,
"all"
,
NULL
);
ProcessControlFd
(
ACTION_DUMP
,
cmdStr
,
NULL
);
ProcessControlFd
(
ACTION_DUMP
,
cmdStr1
,
NULL
);
ProcessControlFd
(
ACTION_SANDBOX
,
cmdStr
,
NULL
);
ProcessControlFd
(
ACTION_MODULEMGR
,
cmdStr
,
NULL
);
ProcessControlFd
(
ACTION_MAX
,
cmdStr
,
NULL
);
ProcessControlFd
(
ACTION_DUMP
,
"all"
,
nullptr
);
ProcessControlFd
(
ACTION_DUMP
,
cmdStr
,
nullptr
);
ProcessControlFd
(
ACTION_DUMP
,
cmdStr1
,
nullptr
);
ProcessControlFd
(
ACTION_SANDBOX
,
cmdStr
,
nullptr
);
ProcessControlFd
(
ACTION_MODULEMGR
,
cmdStr
,
nullptr
);
ProcessControlFd
(
ACTION_MAX
,
cmdStr
,
nullptr
);
Service
*
service
=
GetServiceByName
(
"test-service6"
);
ASSERT_NE
(
service
,
nullptr
);
workspace
->
groupMode
=
GROUP_BOOT
;
...
...
@@ -386,7 +387,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestProcessWatchEvent, TestSize.Level1)
ASSERT_EQ
(
ret
,
0
);
uint32_t
event
;
((
WatcherTask
*
)
watcher
)
->
processEvent
((
WatcherHandle
)
watcher
,
0
,
&
event
,
service
);
service
->
socketCfg
=
NULL
;
service
->
socketCfg
=
nullptr
;
}
HWTEST_F
(
InitGroupManagerUnitTest
,
TestCheckNodeValid
,
TestSize
.
Level1
)
...
...
test/unittest/init/init_reboot_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -112,6 +112,8 @@ HWTEST_F(InitRebootUnitTest, TestRebootCmdExec, TestSize.Level1)
PluginExecCmdByName
(
"reboot.updater"
,
"reboot,updater:2222222"
);
PluginExecCmdByName
(
"reboot.flashd"
,
"reboot,flashd"
);
PluginExecCmdByName
(
"reboot.flashd"
,
"reboot,flashd:1000000"
);
PluginExecCmdByName
(
"reboot.panic"
,
"reboot,panic"
);
PluginExecCmdByName
(
"reboot.stop"
,
"reboot,stop"
);
PluginExecCmdByName
(
"reboot.other"
,
"reboot,other"
);
PARAM_LOGE
(
"TestRebootCmdExec end"
);
int
ret
=
UpdateMiscMessage
(
"charge:wwwwwwwwwww"
,
"charge"
,
"charge:"
,
"boot_charge"
);
...
...
@@ -146,4 +148,19 @@ HWTEST_F(InitRebootUnitTest, TestInitReboot, TestSize.Level1)
ret
=
DoRebootExt
(
"shutdown"
,
DEVICE_CMD_FREEZE
);
EXPECT_EQ
(
ret
,
0
);
}
HWTEST_F
(
InitRebootUnitTest
,
TestAbnormalReboot
,
TestSize
.
Level1
)
{
int
ret
=
DoRoot_
(
nullptr
,
0
);
EXPECT_EQ
(
ret
,
0
);
ret
=
DoRebootShutdown
(
0
,
nullptr
,
0
,
nullptr
);
EXPECT_EQ
(
ret
,
-
1
);
ret
=
DoRebootFlashed
(
0
,
nullptr
,
0
,
nullptr
);
EXPECT_EQ
(
ret
,
-
1
);
ret
=
DoRebootOther
(
0
,
nullptr
,
0
,
nullptr
);
EXPECT_EQ
(
ret
,
-
1
);
}
}
// namespace init_ut
test/unittest/init/init_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -86,6 +86,8 @@ HWTEST_F(InitUnitTest, TestSystemExecRcs, TestSize.Level1)
SystemExecuteRcs
();
int
ret
=
KeepCapability
();
EXPECT_EQ
(
ret
,
0
);
ret
=
SetAmbientCapability
(
34
);
// CAP_SYSLOG
EXPECT_EQ
(
ret
,
0
);
}
static
void
TestProcessTimer
(
const
TimerHandle
taskHandle
,
void
*
context
)
...
...
@@ -125,7 +127,7 @@ HWTEST_F(InitUnitTest, TestFdHoldService, TestSize.Level1)
TimerHandle
timer
=
nullptr
;
int
ret
=
LE_CreateTimer
(
LE_GetDefaultLoop
(),
&
timer
,
TestProcessTimer
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
ret
=
LE_StartTimer
(
LE_GetDefaultLoop
(),
timer
,
500
,
2
);
ret
=
LE_StartTimer
(
LE_GetDefaultLoop
(),
timer
,
500
,
4
);
EXPECT_EQ
(
ret
,
0
);
SystemRun
();
}
...
...
test/unittest/init/service_file_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -40,7 +40,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
const
char
*
fileName
=
"/data/filetest"
;
ServiceFile
*
fileOpt
=
(
ServiceFile
*
)
calloc
(
1
,
sizeof
(
ServiceFile
)
+
strlen
(
fileName
)
+
1
);
ASSERT_NE
(
fileOpt
,
nullptr
);
fileOpt
->
next
=
NULL
;
fileOpt
->
next
=
nullptr
;
fileOpt
->
flags
=
O_RDWR
;
fileOpt
->
uid
=
1000
;
fileOpt
->
gid
=
1000
;
...
...
test/unittest/init/service_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -34,7 +34,7 @@ static void DoCmdByName(const char *name, const char *cmdContent)
{
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
name
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
cmdContent
,
NULL
);
DoCmdByIndex
(
cmdIndex
,
cmdContent
,
nullptr
);
}
using
namespace
testing
::
ext
;
...
...
@@ -316,15 +316,15 @@ HWTEST_F(ServiceUnitTest, TestServiceBootEventHook, TestSize.Level1)
serviceInfoContext
.
serviceName
=
"test-service2"
;
serviceInfoContext
.
reserved
=
"bootevent"
;
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
nullptr
,
nullptr
);
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_DUMP
,
(
void
*
)(
&
serviceInfoContext
),
NULL
);
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_DUMP
,
(
void
*
)(
&
serviceInfoContext
),
nullptr
);
cJSON
*
fileRoot
=
cJSON_Parse
(
serviceStr
);
ASSERT_NE
(
nullptr
,
fileRoot
);
PluginExecCmd
(
"clear"
,
0
,
nullptr
);
ConfigContext
context
=
{
INIT_CONTEXT_MAIN
};
ParseAllServices
(
fileRoot
,
&
context
);
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_FORK_BEFORE
,
(
void
*
)(
&
serviceInfoContext
),
NULL
);
serviceInfoContext
.
reserved
=
NULL
;
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_FORK_BEFORE
,
(
void
*
)(
&
serviceInfoContext
),
NULL
);
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_FORK_BEFORE
,
(
void
*
)(
&
serviceInfoContext
),
nullptr
);
serviceInfoContext
.
reserved
=
nullptr
;
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_FORK_BEFORE
,
(
void
*
)(
&
serviceInfoContext
),
nullptr
);
const
char
*
initBootevent
[]
=
{
"init"
,
"test"
};
PluginExecCmd
(
"bootevent"
,
ARRAY_LENGTH
(
initBootevent
),
initBootevent
);
const
char
*
initBooteventDup
[]
=
{
"init"
,
"test"
};
...
...
@@ -335,13 +335,13 @@ HWTEST_F(ServiceUnitTest, TestServiceBootEventHook, TestSize.Level1)
SystemWriteParam
(
"bootevent.bootevent2"
,
"true"
);
SystemWriteParam
(
"bootevent.bootevent2"
,
"true"
);
SystemWriteParam
(
"persist.init.bootevent.enable"
,
"false"
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
NULL
,
NULL
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
nullptr
,
nullptr
);
cJSON_Delete
(
fileRoot
);
}
HWTEST_F
(
ServiceUnitTest
,
TestSetServiceContent
,
TestSize
.
Level1
)
{
(
void
)
WatchConsoleDevice
(
NULL
);
(
void
)
WatchConsoleDevice
(
nullptr
);
Service
service
;
(
void
)
WatchConsoleDevice
(
&
service
);
int
fd
=
open
(
"/dev/console"
,
O_RDWR
);
...
...
test/unittest/init/utils_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -26,6 +26,7 @@ using namespace testing::ext;
extern
"C"
{
float
ConvertMicrosecondToSecond
(
int
x
);
}
#define MAX_BUFFER_FOR_TEST 128
namespace
init_ut
{
class
UtilsUnitTest
:
public
testing
::
Test
{
...
...
@@ -76,4 +77,45 @@ HWTEST_F(UtilsUnitTest, TestUtilsApi, TestSize.Level0)
char
testStr
[]
=
".trim"
;
EXPECT_STREQ
(
TrimHead
(
testStr
,
'.'
),
"trim"
);
}
void
TestOpenConsole
(
void
)
{
// Save current stdin, stdout, stderr
int
fd0
=
dup
(
STDIN_FILENO
);
EXPECT_GT
(
fd0
,
0
);
int
fd1
=
dup
(
STDOUT_FILENO
);
EXPECT_GT
(
fd1
,
0
);
int
fd2
=
dup
(
STDERR_FILENO
);
EXPECT_GT
(
fd2
,
0
);
// test start
OpenConsole
();
char
buffer
[
MAX_BUFFER_FOR_TEST
];
ssize_t
ret
=
readlink
(
"/proc/self/fd/0"
,
buffer
,
MAX_BUFFER_FOR_TEST
-
1
);
EXPECT_NE
(
ret
,
-
1
);
auto
n
=
strcmp
(
buffer
,
"/dev/console"
);
EXPECT_EQ
(
n
,
0
);
(
void
)
memset_s
(
buffer
,
sizeof
(
buffer
),
0
,
MAX_BUFFER_FOR_TEST
);
ret
=
readlink
(
"/proc/self/fd/1"
,
buffer
,
MAX_BUFFER_FOR_TEST
-
1
);
EXPECT_NE
(
ret
,
-
1
);
n
=
strcmp
(
buffer
,
"/dev/console"
);
EXPECT_EQ
(
n
,
0
);
(
void
)
memset_s
(
buffer
,
sizeof
(
buffer
),
0
,
MAX_BUFFER_FOR_TEST
);
ret
=
readlink
(
"/proc/self/fd/2"
,
buffer
,
MAX_BUFFER_FOR_TEST
-
1
);
EXPECT_NE
(
ret
,
-
1
);
n
=
strcmp
(
buffer
,
"/dev/console"
);
EXPECT_EQ
(
n
,
0
);
// test done
// restore stdin, stdout, stderr
dup2
(
fd0
,
0
);
dup2
(
fd1
,
1
);
dup2
(
fd2
,
2
);
// 2 stderr
close
(
fd0
);
close
(
fd1
);
close
(
fd2
);
}
HWTEST_F
(
UtilsUnitTest
,
TestUtilsOpenConsole
,
TestSize
.
Level0
)
{
TestOpenConsole
();
}
}
// namespace init_ut
test/unittest/innerkits/hookmgr_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -38,7 +38,7 @@ static int OhosHookTestCommon(void *executionContext, int result)
{
struct
HookExecCtx
*
ctx
;
if
(
executionContext
==
NULL
)
{
if
(
executionContext
==
nullptr
)
{
return
0
;
}
...
...
@@ -73,7 +73,7 @@ static void OhosHookPrint(const HOOK_INFO *hookInfo, void *traversalCookie)
static
void
dumpAllHooks
(
HOOK_MGR
*
hookMgr
)
{
printf
(
"----------All Hooks---------------
\n
"
);
HookMgrTraversal
(
hookMgr
,
NULL
,
OhosHookPrint
);
HookMgrTraversal
(
hookMgr
,
nullptr
,
OhosHookPrint
);
printf
(
"----------------------------------
\n\n
"
);
}
...
...
@@ -84,101 +84,101 @@ HWTEST_F(HookMgrUnitTest, HookMgrAdd_one_stage_unitest, TestSize.Level1)
int
ret
;
int
cnt
;
cnt
=
HookMgrGetStagesCnt
(
NULL
);
cnt
=
HookMgrGetStagesCnt
(
nullptr
);
EXPECT_EQ
(
cnt
,
0
);
// Add the first hook
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
1
);
cnt
=
HookMgrGetStagesCnt
(
NULL
);
cnt
=
HookMgrGetStagesCnt
(
nullptr
);
EXPECT_EQ
(
cnt
,
1
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Add the same hook with the same priority again
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
1
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Add the same hook with different priority
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
2
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Add the another hook
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOKEx
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOKEx
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
3
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Add the same hook with the same priority again
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
3
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Add the same hook with the same priority again
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
3
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Add the another hook
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOKEx
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
10
,
OhosTestHookRetOKEx
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
3
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Insert to the end of already exist prio
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOKEx
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOKEx
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
4
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Insert to the end of already exist prio
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOKEx2
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOKEx2
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
5
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Insert a new prio hook
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
5
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
5
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
6
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// Insert a new prio hook to the beginning
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
-
5
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
-
5
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
STAGE_TEST_ONE
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
STAGE_TEST_ONE
);
EXPECT_EQ
(
cnt
,
7
);
dumpAllHooks
(
NULL
);
dumpAllHooks
(
nullptr
);
// All hooks are in the same stage
cnt
=
HookMgrGetStagesCnt
(
NULL
);
cnt
=
HookMgrGetStagesCnt
(
nullptr
);
EXPECT_EQ
(
cnt
,
1
);
// Delete all hooks in stage 0
HookMgrDel
(
NULL
,
STAGE_TEST_ONE
,
NULL
);
cnt
=
HookMgrGetHooksCnt
(
NULL
,
0
);
HookMgrDel
(
nullptr
,
STAGE_TEST_ONE
,
nullptr
);
cnt
=
HookMgrGetHooksCnt
(
nullptr
,
0
);
EXPECT_EQ
(
cnt
,
0
);
cnt
=
HookMgrGetStagesCnt
(
NULL
);
cnt
=
HookMgrGetStagesCnt
(
nullptr
);
EXPECT_EQ
(
cnt
,
0
);
dumpAllHooks
(
NULL
);
HookMgrDestroy
(
NULL
);
dumpAllHooks
(
nullptr
);
HookMgrDestroy
(
nullptr
);
}
HWTEST_F
(
HookMgrUnitTest
,
HookMgrDel_unitest
,
TestSize
.
Level1
)
...
...
@@ -258,45 +258,45 @@ HWTEST_F(HookMgrUnitTest, HookMgrExecute_unitest, TestSize.Level1)
ctx
.
retErr
=
0
;
options
.
flags
=
0
;
options
.
preHook
=
NULL
;
options
.
postHook
=
NULL
;
options
.
preHook
=
nullptr
;
options
.
postHook
=
nullptr
;
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOK
);
EXPECT_EQ
(
ret
,
0
);
ret
=
HookMgrExecute
(
NULL
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
NULL
);
ret
=
HookMgrExecute
(
nullptr
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
1
);
// Check ignore error
ctx
.
retErr
=
1
;
ret
=
HookMgrExecute
(
NULL
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
NULL
);
ret
=
HookMgrExecute
(
nullptr
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
1
);
// Do not ignore return errors
ctx
.
retErr
=
1
;
options
.
flags
=
HOOK_EXEC_EXIT_WHEN_ERROR
;
ret
=
HookMgrExecute
(
NULL
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
&
options
);
ret
=
HookMgrExecute
(
nullptr
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
&
options
);
ASSERT_NE
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
1
);
options
.
flags
=
0
;
// Add another hook with same priority
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOKEx
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
0
,
OhosTestHookRetOKEx
);
EXPECT_EQ
(
ret
,
0
);
ret
=
HookMgrExecute
(
NULL
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
NULL
);
ret
=
HookMgrExecute
(
nullptr
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
2
);
// Add another hook with higher priority
ret
=
HookMgrAdd
(
NULL
,
STAGE_TEST_ONE
,
-
1
,
OhosTestHookRetOKEx
);
ret
=
HookMgrAdd
(
nullptr
,
STAGE_TEST_ONE
,
-
1
,
OhosTestHookRetOKEx
);
EXPECT_EQ
(
ret
,
0
);
ret
=
HookMgrExecute
(
NULL
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
NULL
);
ret
=
HookMgrExecute
(
nullptr
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
2
);
HookMgrDel
(
NULL
,
STAGE_TEST_ONE
,
OhosTestHookRetOKEx
);
ret
=
HookMgrExecute
(
NULL
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
NULL
);
HookMgrDel
(
nullptr
,
STAGE_TEST_ONE
,
OhosTestHookRetOKEx
);
ret
=
HookMgrExecute
(
nullptr
,
STAGE_TEST_ONE
,
(
void
*
)
&
ctx
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
1
);
}
...
...
test/unittest/innerkits/innerkits_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -48,6 +48,7 @@ int SendCmdMessage(const CmdAgent *agent, uint16_t type, const char *cmd, const
int
SendMessage
(
LoopHandle
loop
,
TaskHandle
task
,
const
char
*
message
);
int
*
GetFdsFromMsg
(
size_t
*
outFdCount
,
pid_t
*
requestPid
,
struct
msghdr
msghdr
);
int
BuildSendData
(
char
*
buffer
,
size_t
size
,
const
char
*
serviceName
,
bool
hold
,
bool
poll
);
int
CheckSocketPermission
(
const
TaskHandle
task
);
}
class
InnerkitsUnitTest
:
public
testing
::
Test
{
...
...
@@ -194,7 +195,7 @@ HWTEST_F(InnerkitsUnitTest, GetSlotInfo_unittest, TestSize.Level1)
*/
HWTEST_F
(
InnerkitsUnitTest
,
LoadFstabFromCommandLine_unittest
,
TestSize
.
Level1
)
{
EXPECT_NE
(
LoadFstabFromCommandLine
(),
(
Fstab
*
)
NULL
);
EXPECT_NE
(
LoadFstabFromCommandLine
(),
(
Fstab
*
)
nullptr
);
}
/**
...
...
@@ -363,16 +364,16 @@ HWTEST_F(InnerkitsUnitTest, TestControlFdServer, TestSize.Level1)
UNUSED
(
context
);
},
LE_GetDefaultLoop
());
TaskHandle
testServer
=
NULL
;
TaskHandle
testServer
=
nullptr
;
LE_StreamServerInfo
info
=
{};
info
.
baseInfo
.
flags
=
TASK_STREAM
|
TASK_SERVER
|
TASK_PIPE
|
TASK_TEST
;
info
.
server
=
(
char
*
)
"/data/testSock1"
;
info
.
socketId
=
-
1
;
info
.
baseInfo
.
close
=
NULL
;
info
.
disConnectComplete
=
NULL
;
info
.
baseInfo
.
close
=
nullptr
;
info
.
disConnectComplete
=
nullptr
;
info
.
incommingConnect
=
TestIncommingConnect
;
info
.
sendMessageComplete
=
NULL
;
info
.
recvMessage
=
NULL
;
info
.
sendMessageComplete
=
nullptr
;
info
.
recvMessage
=
nullptr
;
(
void
)
LE_CreateStreamServer
(
LE_GetDefaultLoop
(),
&
testServer
,
&
info
);
CmdOnIncommingConnect
(
LE_GetDefaultLoop
(),
testServer
);
...
...
@@ -390,6 +391,12 @@ HWTEST_F(InnerkitsUnitTest, TestControlFdServer, TestSize.Level1)
free
(
cmdMsg
);
}
HWTEST_F
(
InnerkitsUnitTest
,
TestHoldFd_1
,
TestSize
.
Level1
)
{
CheckSocketPermission
(
nullptr
);
CmdServiceProcessDestroyClient
();
}
HWTEST_F
(
InnerkitsUnitTest
,
TestHoldFd
,
TestSize
.
Level1
)
{
int
fds1
[]
=
{
1
,
0
};
...
...
@@ -418,19 +425,19 @@ HWTEST_F(InnerkitsUnitTest, TestHoldFd, TestSize.Level1)
struct
msghdr
msghdr
=
{};
BuildControlMessage
(
nullptr
,
nullptr
,
1
,
0
);
BuildControlMessage
(
&
msghdr
,
nullptr
,
1
,
0
);
if
(
msghdr
.
msg_control
!=
NULL
)
{
if
(
msghdr
.
msg_control
!=
nullptr
)
{
free
(
msghdr
.
msg_control
);
msghdr
.
msg_control
=
NULL
;
msghdr
.
msg_control
=
nullptr
;
}
BuildControlMessage
(
&
msghdr
,
fds
,
-
1
,
0
);
if
(
msghdr
.
msg_control
!=
NULL
)
{
if
(
msghdr
.
msg_control
!=
nullptr
)
{
free
(
msghdr
.
msg_control
);
msghdr
.
msg_control
=
NULL
;
msghdr
.
msg_control
=
nullptr
;
}
BuildControlMessage
(
&
msghdr
,
fds
,
-
1
,
1
);
if
(
msghdr
.
msg_control
!=
NULL
)
{
if
(
msghdr
.
msg_control
!=
nullptr
)
{
free
(
msghdr
.
msg_control
);
msghdr
.
msg_control
=
NULL
;
msghdr
.
msg_control
=
nullptr
;
}
if
(
fds
!=
nullptr
)
{
...
...
test/unittest/innerkits/modulemgr_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -81,6 +81,8 @@ HWTEST_F(ModuleMgrUnitTest, PluginAddCmd, TestSize.Level1)
// del
RemoveCmdExecutor
(
"testCmd4"
,
cmdExecId4
);
AddCareContextCmdExecutor
(
""
,
nullptr
);
RemoveCmdExecutor
(
"testCmd4"
,
-
1
);
}
static
void
TestModuleDump
(
const
MODULE_INFO
*
moduleInfo
)
...
...
@@ -96,27 +98,36 @@ HWTEST_F(ModuleMgrUnitTest, ModuleTraversalTest, TestSize.Level1)
int
cnt
=
ModuleMgrGetCnt
(
moduleMgr
);
ASSERT_EQ
(
cnt
,
0
);
// Install one module
int
ret
=
ModuleMgrInstall
(
moduleMgr
,
"
bootchart"
,
0
,
NULL
);
int
ret
=
ModuleMgrInstall
(
moduleMgr
,
"
libbootchart"
,
0
,
nullptr
);
ASSERT_EQ
(
ret
,
0
);
cnt
=
ModuleMgrGetCnt
(
moduleMgr
);
ASSERT_EQ
(
cnt
,
1
);
ModuleMgrTraversal
(
nullptr
,
nullptr
,
nullptr
);
ModuleMgrTraversal
(
moduleMgr
,
NULL
,
TestModuleDump
);
ModuleMgrTraversal
(
moduleMgr
,
nullptr
,
TestModuleDump
);
InitModuleMgrDump
();
InitModuleMgrInstall
(
"/"
);
// Scan all modules
ModuleMgrScan
(
nullptr
);
moduleMgr
=
ModuleMgrScan
(
"init/autorun"
);
ModuleMgrScan
(
"/"
);
moduleMgr
=
ModuleMgrScan
(
"init"
);
moduleMgr
=
ModuleMgrScan
(
STARTUP_INIT_UT_PATH
MODULE_LIB_NAME
"/autorun"
);
ASSERT_NE
(
moduleMgr
,
nullptr
);
cnt
=
ModuleMgrGetCnt
(
moduleMgr
);
ASSERT_GE
(
cnt
,
0
);
ModuleMgrUninstall
(
moduleMgr
,
NULL
);
ModuleMgrUninstall
(
moduleMgr
,
nullptr
);
cnt
=
ModuleMgrGetCnt
(
moduleMgr
);
ASSERT_EQ
(
cnt
,
0
);
ModuleMgrGetArgs
();
ModuleMgrDestroy
(
moduleMgr
);
}
HWTEST_F
(
ModuleMgrUnitTest
,
ModuleAbnormalTest
,
TestSize
.
Level1
)
{
int
ret
=
InitModuleMgrInstall
(
nullptr
);
ASSERT_EQ
(
ret
,
-
1
);
}
}
// namespace init_ut
test/unittest/lite/cmd_func_test.cpp
浏览文件 @
0da55118
...
...
@@ -159,7 +159,7 @@ void DoCmd(const TestCmdLine *resCmd)
}
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
resCmd
->
name
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
resCmd
->
cmdContent
,
NULL
);
DoCmdByIndex
(
cmdIndex
,
resCmd
->
cmdContent
,
nullptr
);
}
/*
...
...
test/unittest/loopevent/loopevent_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -95,8 +95,8 @@ public:
CheckTaskFlags
(
nullptr
,
Event_Write
);
ParamStreamInfo
info
=
{};
info
.
server
=
const_cast
<
char
*>
(
PIPE_NAME
);
info
.
close
=
NULL
;
info
.
recvMessage
=
NULL
;
info
.
close
=
nullptr
;
info
.
recvMessage
=
nullptr
;
info
.
incomingConnect
=
OnIncomingConnect
;
return
ParamServerCreate
(
&
serverTask_
,
&
info
);
}
...
...
@@ -137,7 +137,7 @@ public:
LE_StreamServerInfo
info
=
{};
info
.
baseInfo
.
flags
=
TASK_STREAM
|
TASK_PIPE
|
TASK_SERVER
|
TASK_TEST
;
info
.
server
=
(
char
*
)
"/data/testpipe"
;
info
.
baseInfo
.
close
=
NULL
;
info
.
baseInfo
.
close
=
nullptr
;
info
.
incommingConnect
=
IncomingConnect
;
LE_CreateStreamServer
(
LE_GetDefaultLoop
(),
&
serverTask_
,
&
info
);
if
(
serverTask_
==
nullptr
)
{
...
...
@@ -148,11 +148,11 @@ public:
uint64_t
eventId
=
0
;
ParamStreamInfo
paramStreamInfo
=
{};
paramStreamInfo
.
flags
=
PARAM_TEST_FLAGS
;
paramStreamInfo
.
server
=
NULL
;
paramStreamInfo
.
close
=
NULL
;
paramStreamInfo
.
server
=
nullptr
;
paramStreamInfo
.
close
=
nullptr
;
paramStreamInfo
.
recvMessage
=
ProcessMessage
;
paramStreamInfo
.
incomingConnect
=
NULL
;
ParamTaskPtr
client
=
NULL
;
paramStreamInfo
.
incomingConnect
=
nullptr
;
ParamTaskPtr
client
=
nullptr
;
int
ret
=
ParamStreamCreate
(
&
client
,
serverTask_
,
&
paramStreamInfo
,
sizeof
(
ParamWatcher
));
PARAM_CHECK
(
ret
==
0
,
return
,
"Failed to create client"
);
...
...
@@ -177,7 +177,7 @@ public:
void
ProcessEventTest
()
{
ProcessEvent
((
EventLoop
*
)
LE_GetDefaultLoop
(),
1
,
Event_Read
);
LE_BaseInfo
info
=
{
TASK_EVENT
,
NULL
};
LE_BaseInfo
info
=
{
TASK_EVENT
,
nullptr
};
int
testfd
=
65535
;
// 65535 is not exist fd
BaseTask
*
task
=
CreateTask
(
LE_GetDefaultLoop
(),
testfd
,
&
info
,
sizeof
(
StreamClientTask
));
if
(
task
!=
nullptr
)
{
...
...
@@ -220,7 +220,7 @@ public:
LE_StreamServerInfo
info
=
{};
info
.
baseInfo
.
flags
=
TASK_PIPE
|
TASK_CONNECT
|
TASK_TEST
;
info
.
server
=
(
char
*
)
"/data/testpipe"
;
info
.
baseInfo
.
close
=
NULL
;
info
.
baseInfo
.
close
=
nullptr
;
info
.
incommingConnect
=
IncomingConnect
;
info
.
socketId
=
1111
;
// 1111 is test fd
LE_CreateStreamServer
(
LE_GetDefaultLoop
(),
&
serverTask
,
&
info
);
...
...
@@ -237,7 +237,7 @@ public:
}
private:
ParamTaskPtr
serverTask_
=
NULL
;
ParamTaskPtr
serverTask_
=
nullptr
;
};
HWTEST_F
(
LoopEventUnittest
,
LeTaskTest
,
TestSize
.
Level1
)
...
...
@@ -305,4 +305,16 @@ HWTEST_F(LoopEventUnittest, LoopRunTest, TestSize.Level1)
LE_RunLoop
(
g_loop
);
LE_CloseLoop
(
g_loop
);
}
HWTEST_F
(
LoopEventUnittest
,
LoopAbnormalTest
,
TestSize
.
Level1
)
{
LE_StartWatcher
(
nullptr
,
nullptr
,
nullptr
,
nullptr
);
LE_WatchInfo
info
=
{};
info
.
fd
=
-
1
;
info
.
flags
=
WATCHER_ONCE
;
info
.
events
=
Event_Read
;
info
.
processEvent
=
nullptr
;
LE_StartWatcher
(
LE_GetDefaultLoop
(),
nullptr
,
&
info
,
nullptr
);
LE_StartWatcher
(
LE_GetDefaultLoop
(),
nullptr
,
nullptr
,
nullptr
);
}
}
// namespace init_ut
test/unittest/modules/context_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -20,6 +20,48 @@
using
namespace
std
;
using
namespace
testing
::
ext
;
extern
"C"
{
struct
ForkArgs
{
int
(
*
childFunc
)(
const
SubInitForkArg
*
arg
);
SubInitForkArg
args
;
};
static
pid_t
g_pid
=
1000
;
static
pthread_t
g_thread
=
0
;
static
void
*
ThreadFunc
(
void
*
arg
)
{
printf
(
"Create thread %d
\n
"
,
gettid
());
struct
ForkArgs
*
forkArg
=
static_cast
<
struct
ForkArgs
*>
(
arg
);
forkArg
->
childFunc
(
&
forkArg
->
args
);
printf
(
"Exit thread %d %d
\n
"
,
forkArg
->
args
.
type
,
gettid
());
free
(
forkArg
);
g_thread
=
0
;
return
nullptr
;
}
pid_t
SubInitFork
(
int
(
*
childFunc
)(
const
SubInitForkArg
*
arg
),
const
SubInitForkArg
*
args
)
{
if
(
g_pid
>=
0
)
{
struct
ForkArgs
*
forkArg
=
static_cast
<
struct
ForkArgs
*>
(
malloc
(
sizeof
(
struct
ForkArgs
)));
if
(
forkArg
==
nullptr
)
{
return
-
1
;
}
forkArg
->
childFunc
=
childFunc
;
forkArg
->
args
.
socket
[
0
]
=
args
->
socket
[
0
];
forkArg
->
args
.
socket
[
1
]
=
args
->
socket
[
1
];
forkArg
->
args
.
type
=
args
->
type
;
int
ret
=
pthread_create
(
&
g_thread
,
nullptr
,
ThreadFunc
,
forkArg
);
if
(
ret
!=
0
)
{
printf
(
"Failed to create thread %d
\n
"
,
errno
);
return
-
1
;
}
usleep
(
100
);
// 100 wait
}
g_pid
++
;
return
g_pid
;
}
}
namespace
init_ut
{
class
InitContextUnitTest
:
public
testing
::
Test
{
public:
...
...
@@ -31,10 +73,12 @@ public:
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_01
,
TestSize
.
Level1
)
{
g_pid
=
-
3
;
// -3 test data
int
ret
=
StartSubInit
(
INIT_CONTEXT_CHIPSET
);
EXPECT_
EQ
(
ret
,
0
);
EXPECT_
NE
(
ret
,
0
);
ret
=
StartSubInit
(
INIT_CONTEXT_MAIN
);
EXPECT_NE
(
ret
,
0
);
g_pid
=
100
;
// 100 test data
}
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_02
,
TestSize
.
Level1
)
...
...
@@ -46,30 +90,50 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_02, TestSize.Level1)
EXPECT_EQ
(
ret
,
0
);
ret
=
ExecuteCmdInSubInit
(
&
context
,
"mkdir"
,
STARTUP_INIT_UT_PATH
"/testsubcontext2"
);
EXPECT_EQ
(
ret
,
0
);
ret
=
ExecuteCmdInSubInit
(
&
context
,
"mkdir"
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
context
.
type
=
INIT_CONTEXT_MAIN
;
ret
=
ExecuteCmdInSubInit
(
&
context
,
"mkdir"
,
STARTUP_INIT_UT_PATH
"/testsubcontext"
);
EXPECT_NE
(
ret
,
0
);
// fail
ret
=
ExecuteCmdInSubInit
(
nullptr
,
"mkdir"
,
STARTUP_INIT_UT_PATH
"/testsubcontext"
);
EXPECT_EQ
(
ret
,
-
1
);
ret
=
ExecuteCmdInSubInit
(
&
context
,
nullptr
,
STARTUP_INIT_UT_PATH
"/testsubcontext"
);
EXPECT_EQ
(
ret
,
-
1
);
}
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_03
,
TestSize
.
Level1
)
{
int
ret
=
StartSubInit
(
INIT_CONTEXT_CHIPSET
);
EXPECT_EQ
(
ret
,
0
);
if
(
g_thread
!=
0
)
{
pthread_join
(
g_thread
,
nullptr
);
g_thread
=
0
;
}
SubInitInfo
*
subInfo
=
GetSubInitInfo
(
INIT_CONTEXT_CHIPSET
);
if
(
subInfo
==
NULL
)
{
if
(
subInfo
==
nullptr
)
{
EXPECT_EQ
(
1
,
0
);
}
else
{
EXPECT_EQ
(
2
,
subInfo
->
state
);
StopSubInit
(
subInfo
->
subPid
);
}
subInfo
=
GetSubInitInfo
(
INIT_CONTEXT_MAIN
);
if
(
subInfo
!=
nullptr
)
{
EXPECT_EQ
(
1
,
0
);
}
}
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_04
,
TestSize
.
Level1
)
{
int
ret
=
StartSubInit
(
INIT_CONTEXT_CHIPSET
);
EXPECT_EQ
(
ret
,
0
);
if
(
g_thread
!=
0
)
{
pthread_join
(
g_thread
,
nullptr
);
g_thread
=
0
;
}
SubInitInfo
*
subInfo
=
GetSubInitInfo
(
INIT_CONTEXT_CHIPSET
);
if
(
subInfo
!=
NULL
)
{
if
(
subInfo
!=
nullptr
)
{
EXPECT_EQ
(
2
,
subInfo
->
state
);
StopSubInit
(
subInfo
->
subPid
);
}
else
{
...
...
@@ -77,9 +141,17 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_04, TestSize.Level1)
}
// close
subInfo
=
GetSubInitInfo
(
INIT_CONTEXT_CHIPSET
);
if
(
subInfo
!=
NULL
)
{
if
(
subInfo
!=
nullptr
)
{
EXPECT_EQ
(
0
,
subInfo
->
state
);
}
SubInitContext
*
subContext
=
GetSubInitContext
(
INIT_CONTEXT_CHIPSET
);
if
(
subContext
==
nullptr
)
{
EXPECT_EQ
(
0
,
-
1
);
return
;
}
ret
=
subContext
->
executeCmdInSubInit
(
INIT_CONTEXT_CHIPSET
,
"mkdir-2"
,
STARTUP_INIT_UT_PATH
"/testsubcontext"
);
EXPECT_NE
(
ret
,
0
);
}
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_05
,
TestSize
.
Level1
)
...
...
@@ -112,4 +184,36 @@ HWTEST_F(InitContextUnitTest, InitSubContextTest_07, TestSize.Level1)
}
DoCmdByIndex
(
index
,
STARTUP_INIT_UT_PATH
"/testsubcontext"
,
&
context
);
}
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_09
,
TestSize
.
Level1
)
{
int
ret
=
SetSubInitContext
(
nullptr
,
"serviceName"
);
EXPECT_EQ
(
ret
,
-
1
);
ConfigContext
context
=
{
INIT_CONTEXT_MAIN
};
ret
=
SetSubInitContext
(
&
context
,
"serviceName"
);
EXPECT_EQ
(
ret
,
0
);
context
=
{
INIT_CONTEXT_CHIPSET
};
ret
=
SetSubInitContext
(
&
context
,
"serviceName"
);
EXPECT_EQ
(
ret
,
0
);
}
HWTEST_F
(
InitContextUnitTest
,
InitSubContextTest_10
,
TestSize
.
Level1
)
{
int
ret
=
InitSubInitContext
(
INIT_CONTEXT_MAIN
,
nullptr
);
EXPECT_EQ
(
ret
,
-
1
);
ret
=
InitSubInitContext
(
INIT_CONTEXT_CHIPSET
,
nullptr
);
EXPECT_EQ
(
ret
,
-
1
);
SubInitContext
*
subContext
=
GetSubInitContext
(
INIT_CONTEXT_CHIPSET
);
if
(
subContext
==
nullptr
)
{
EXPECT_EQ
(
0
,
-
1
);
return
;
}
ret
=
subContext
->
startSubInit
(
INIT_CONTEXT_MAIN
);
EXPECT_NE
(
ret
,
0
);
ret
=
subContext
->
executeCmdInSubInit
(
INIT_CONTEXT_CHIPSET
,
nullptr
,
nullptr
);
EXPECT_NE
(
ret
,
0
);
ret
=
subContext
->
executeCmdInSubInit
(
INIT_CONTEXT_MAIN
,
nullptr
,
nullptr
);
EXPECT_NE
(
ret
,
0
);
}
}
// namespace init_ut
test/unittest/modules/eng_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -30,15 +30,6 @@ using namespace std;
using
namespace
testing
::
ext
;
namespace
init_ut
{
extern
"C"
{
void
EngineerOverlay
(
void
);
void
DebugFilesOverlay
(
const
char
*
source
,
const
char
*
target
);
void
BindMountFile
(
const
char
*
source
,
const
char
*
target
);
void
MountEngPartitions
(
void
);
void
BuildMountCmd
(
char
*
buffer
,
size_t
len
,
const
char
*
mp
,
const
char
*
dev
,
const
char
*
fstype
);
bool
IsFileExistWithType
(
const
char
*
file
,
FileType
type
);
}
static
const
std
::
string
SRC_FILE_PATH
=
STARTUP_INIT_UT_PATH
"/eng/source/test.txt"
;
static
const
std
::
string
TARGET_PATH
=
STARTUP_INIT_UT_PATH
"/eng/link_name"
;
static
const
std
::
string
ENG_ROOT_PATH
=
STARTUP_INIT_UT_PATH
"/eng/"
;
...
...
@@ -151,6 +142,8 @@ HWTEST_F(EngUnitTest, TestBindMountFile, TestSize.Level1)
BindMountFile
(
"data"
,
"target"
);
BindMountFile
(
"/data/init_ut//"
,
"/"
);
BindMountFile
(
"/data/init_ut"
,
"/"
);
BindMountFile
(
"/data"
,
"/"
);
BindMountFile
(
"/data/"
,
"/"
);
bool
isExist
=
false
;
if
(
!
IsFileExist
(
SRC_FILE_PATH
.
c_str
()))
{
...
...
@@ -159,6 +152,7 @@ HWTEST_F(EngUnitTest, TestBindMountFile, TestSize.Level1)
EXPECT_EQ
(
isExist
,
true
);
BindMountFile
(
SRC_FILE_PATH
.
c_str
(),
"/"
);
}
BindMountFile
(
SRC_FILE_PATH
.
c_str
(),
"/"
);
if
(
IsFileExist
(
SRC_FILE_PATH
.
c_str
()))
{
RemoveDir
(
STARTUP_INIT_UT_PATH
"/eng/source"
);
...
...
@@ -180,11 +174,7 @@ HWTEST_F(EngUnitTest, TestBindMountFile, TestSize.Level1)
isLinkFile
=
IsFileExistWithType
(
TARGET_PATH
.
c_str
(),
TYPE_LINK
);
EXPECT_EQ
(
isLinkFile
,
true
);
BindMountFile
(
SRC_FILE_PATH
.
c_str
(),
TARGET_PATH
.
c_str
());
if
(
!
IsDirExist
(
ENG_ROOT_PATH
.
c_str
()))
{
CheckAndCreateDir
(
STARTUP_INIT_UT_PATH
"/eng/"
);
}
BindMountFile
(
ENG_ROOT_PATH
.
c_str
(),
TARGET_PATH
.
c_str
());
BindMountFile
(
TARGET_PATH
.
c_str
(),
SRC_FILE_PATH
.
c_str
());
}
HWTEST_F
(
EngUnitTest
,
TestMountCmd
,
TestSize
.
Level1
)
...
...
@@ -192,6 +182,7 @@ HWTEST_F(EngUnitTest, TestMountCmd, TestSize.Level1)
char
mountCmd
[
MOUNT_CMD_MAX_LEN
]
=
{};
MountEngPartitions
();
BuildMountCmd
(
mountCmd
,
MOUNT_CMD_MAX_LEN
,
"/eng/source"
,
"/eng/target"
,
"ext4"
);
BuildMountCmd
(
mountCmd
,
0
,
"/eng/source"
,
"/eng/target"
,
"ext4"
);
}
HWTEST_F
(
EngUnitTest
,
TestFileType
,
TestSize
.
Level1
)
...
...
@@ -206,8 +197,13 @@ HWTEST_F(EngUnitTest, TestFileType, TestSize.Level1)
EXPECT_EQ
(
isExist
,
true
);
}
EXPECT_EQ
(
IsFileExistWithType
(
STARTUP_INIT_UT_PATH
"/eng"
,
TYPE_DIR
),
true
);
EXPECT_EQ
(
IsFileExistWithType
(
SRC_FILE_PATH
.
c_str
(),
TYPE_REG
),
true
);
EXPECT_EQ
(
IsFileExistWithType
(
STARTUP_INIT_UT_PATH
"/eng"
,
TYPE_DIR
),
true
);
EXPECT_EQ
(
IsFileExistWithType
(
STARTUP_INIT_UT_PATH
"/eng"
,
TYPE_LINK
),
false
);
EXPECT_EQ
(
IsFileExistWithType
(
STARTUP_INIT_UT_PATH
"/eng"
,
TYPE_REG
),
false
);
EXPECT_EQ
(
IsFileExistWithType
(
STARTUP_INIT_UT_PATH
"/eng"
,
TYPE_ANY
),
true
);
EXPECT_EQ
(
IsFileExistWithType
(
SRC_FILE_PATH
.
c_str
(),
TYPE_DIR
),
false
);
if
(
IsFileExist
(
targetFile
))
{
if
(
unlink
(
targetFile
.
c_str
())
<
0
)
{
...
...
@@ -243,4 +239,14 @@ HWTEST_F(EngUnitTest, TestFileType, TestSize.Level1)
isFileExist
=
IsFileExistWithType
(
"/eng/target"
,
TYPE_REG
);
EXPECT_EQ
(
isFileExist
,
false
);
}
HWTEST_F
(
EngUnitTest
,
TestHook
,
TestSize
.
Level1
)
{
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
nullptr
,
nullptr
);
PrepareCmdLineData
();
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
nullptr
,
nullptr
);
const
char
*
cmdLine
=
"ohos.boot.eng_mode=off "
;
CreateTestFile
(
BOOT_CMD_LINE
,
cmdLine
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
nullptr
,
nullptr
);
}
}
// namespace init_ut
test/unittest/modules/modules_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -61,6 +61,9 @@ HWTEST_F(ModulesUnitTest, TestReadFileToBuffer, TestSize.Level1)
const
char
*
fileName
=
"ModulesTest"
;
char
buffer
[
MAX_BUFFER_LEN
]
=
{
0
};
EXPECT_EQ
(
ReadFileToBuffer
(
fileName
,
buffer
,
MAX_BUFFER_LEN
),
nullptr
);
buffer
[
1
]
=
'a'
;
EXPECT_EQ
(
ReadFileToBuffer
(
nullptr
,
buffer
,
MAX_BUFFER_LEN
),
nullptr
);
EXPECT_EQ
(
ReadFileToBuffer
(
nullptr
,
nullptr
,
MAX_BUFFER_LEN
),
nullptr
);
}
HWTEST_F
(
ModulesUnitTest
,
TestBootchartLogFile
,
TestSize
.
Level1
)
...
...
@@ -78,7 +81,7 @@ HWTEST_F(ModulesUnitTest, TestBootchartLogProcessStat, TestSize.Level1)
{
FILE
*
log
=
fopen
(
"/data/init_ut/ModulesTest.log"
,
"w"
);
pid_t
selfPid
=
getpid
();
if
(
log
!=
NULL
)
{
if
(
log
!=
nullptr
)
{
BootchartLogProcessStat
(
log
,
selfPid
);
(
void
)
fflush
(
log
);
(
void
)
fclose
(
log
);
...
...
@@ -110,6 +113,6 @@ HWTEST_F(ModulesUnitTest, TestDoBootchartInsall, TestSize.Level1)
SystemWriteParam
(
"persist.init.debug.dump.trigger"
,
"1"
);
SystemWriteParam
(
"persist.init.debug.loglevel"
,
"6"
);
SystemWriteParam
(
"ohos.servicectrl.cmd"
,
"setloglevel 10"
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
NULL
,
NULL
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
nullptr
,
nullptr
);
}
}
// namespace init_ut
test/unittest/modules/sysevent_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -17,6 +17,7 @@
#include <sys/time.h>
#include "bootevent.h"
#include "init_param.h"
#include "init_utils.h"
#include "list.h"
#include "param_stub.h"
...
...
@@ -32,12 +33,12 @@ extern void ReportBootEventComplete(ListNode *events);
static
void
AddBootEvent
(
ListNode
*
events
,
const
char
*
name
,
int32_t
type
)
{
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
calloc
(
1
,
sizeof
(
BOOT_EVENT_PARAM_ITEM
));
if
(
item
==
NULL
)
{
if
(
item
==
nullptr
)
{
return
;
}
OH_ListInit
(
&
item
->
node
);
item
->
paramName
=
strdup
(
name
);
if
(
item
->
paramName
==
NULL
)
{
if
(
item
->
paramName
==
nullptr
)
{
free
(
item
);
return
;
}
...
...
@@ -49,7 +50,7 @@ static void AddBootEvent(ListNode *events, const char *name, int32_t type)
static
void
BootEventDestroyProc
(
ListNode
*
node
)
{
if
(
node
==
NULL
)
{
if
(
node
==
nullptr
)
{
return
;
}
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
node
;
...
...
@@ -89,6 +90,7 @@ HWTEST_F(SysEventUnitTest, SysEventTest_003, TestSize.Level1)
AddBootEvent
(
&
events
,
"bootevent.33333333333.xxxx"
,
BOOTEVENT_TYPE_SERVICE
);
AddBootEvent
(
&
events
,
"bootevent.44444444444444"
,
BOOTEVENT_TYPE_SERVICE
);
AddBootEvent
(
&
events
,
"bootevent.44444444444444.6666666666.777777"
,
BOOTEVENT_TYPE_SERVICE
);
SystemWriteParam
(
"ohos.boot.bootreason"
,
"-1"
);
ReportBootEventComplete
(
&
events
);
OH_ListRemoveAll
(
&
events
,
BootEventDestroyProc
);
}
...
...
@@ -126,4 +128,9 @@ HWTEST_F(SysEventUnitTest, SysEventTest_005, TestSize.Level1)
startupTime
.
firstStart
=
1
;
ReportSysEvent
(
&
startupTime
.
event
);
}
HWTEST_F
(
SysEventUnitTest
,
SysEventTest_006
,
TestSize
.
Level1
)
{
ReportSysEvent
(
nullptr
);
}
}
// namespace init_ut
test/unittest/modules/trace_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -52,6 +52,14 @@ static const char *g_content =
"
\"
sys-files
\"
: ["
"
\"
events/mmc/enable
\"
"
"]"
"},"
"{"
"
\"
name
\"
:
\"
test
\"
,"
"
\"
description
\"
:
\"
test
\"
,"
"
\"
tag
\"
: 0,"
"
\"
type
\"
:
\"
KERNEL
\"
,"
"
\"
sys-files
\"
: ["
"]"
"}"
"],"
"
\"
USER
\"
: ["
...
...
@@ -107,10 +115,10 @@ HWTEST_F(TraceUnitTest, TraceTest_001, TestSize.Level1)
// open switch for trace
uint32_t
dataIndex
=
0
;
WriteParam
(
"persist.init.bootevent.enable"
,
"true"
,
&
dataIndex
,
0
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
NULL
,
NULL
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
nullptr
,
nullptr
);
// close switch for trace
WriteParam
(
"persist.init.bootevent.enable"
,
"false"
,
&
dataIndex
,
0
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
NULL
,
NULL
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_PERSIST_PARAM_LOAD
,
nullptr
,
nullptr
);
}
HWTEST_F
(
TraceUnitTest
,
TraceTest_002
,
TestSize
.
Level1
)
...
...
@@ -141,7 +149,7 @@ HWTEST_F(TraceUnitTest, TraceTest_004, TestSize.Level1)
cmdArgs
+=
STARTUP_INIT_UT_PATH
"/system/etc/init_trace.cfg"
;
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
"copy "
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
cmdArgs
.
c_str
(),
NULL
);
DoCmdByIndex
(
cmdIndex
,
cmdArgs
.
c_str
(),
nullptr
);
// start trace
PluginExecCmdByName
(
"init_trace"
,
"start"
);
...
...
@@ -160,4 +168,27 @@ HWTEST_F(TraceUnitTest, TraceTest_005, TestSize.Level1)
// interrupt trace
PluginExecCmdByName
(
"init_trace"
,
"1"
);
}
HWTEST_F
(
TraceUnitTest
,
TraceTest_006
,
TestSize
.
Level1
)
{
std
::
string
cmdArgs
=
"/bin/test "
;
cmdArgs
+=
STARTUP_INIT_UT_PATH
"/bin/test"
;
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
"copy "
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
cmdArgs
.
c_str
(),
nullptr
);
// start trace
PluginExecCmdByName
(
"init_trace"
,
"start"
);
// for run 1 s
sleep
(
1
);
// stop trace
PluginExecCmdByName
(
"init_trace"
,
"stop"
);
}
HWTEST_F
(
TraceUnitTest
,
TraceTest_007
,
TestSize
.
Level1
)
{
CreateInitTraceConfig
(
0
);
// other case
PluginExecCmdByName
(
"init_trace"
,
"other"
);
}
}
// namespace init_ut
test/unittest/modules/udid_unittest.cpp
0 → 100755
浏览文件 @
0da55118
/*
* 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 <iostream>
#include "udid.h"
#include "param_stub.h"
#include "sysparam_errno.h"
#include "securec.h"
using
namespace
std
;
using
namespace
testing
::
ext
;
namespace
init_ut
{
extern
"C"
{
int
GetSha256Value
(
const
char
*
input
,
char
*
udid
,
uint32_t
udidSize
);
void
SetDevUdid
();
int
CalcDevUdid
(
char
*
udid
,
uint32_t
size
);
}
class
UdidUnitTest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
(
void
)
{};
static
void
TearDownTestCase
(
void
)
{};
void
SetUp
()
{};
void
TearDown
()
{};
};
HWTEST_F
(
UdidUnitTest
,
TestUDID_001
,
TestSize
.
Level1
)
{
SetDevUdid
();
}
HWTEST_F
(
UdidUnitTest
,
TestUDID_002
,
TestSize
.
Level1
)
{
int
ret
=
GetSha256Value
(
nullptr
,
nullptr
,
0
);
EXPECT_EQ
(
ret
,
EC_FAILURE
);
}
HWTEST_F
(
UdidUnitTest
,
TestUDID_003
,
TestSize
.
Level1
)
{
char
udid
[
66
]
=
{
0
};
int
ret
=
CalcDevUdid
(
udid
,
6
);
EXPECT_EQ
(
ret
,
EC_FAILURE
);
ret
=
CalcDevUdid
(
udid
,
66
);
EXPECT_EQ
(
ret
,
EC_SUCCESS
);
}
}
// namespace init_ut
test/unittest/param/client_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -198,6 +198,10 @@ HWTEST_F(ClientUnitTest, TestClient_01, TestSize.Level0)
// wait
SystemWaitParameter
(
name
.
c_str
(),
value
.
c_str
(),
1
);
SystemWaitParameter
(
name
.
c_str
(),
nullptr
,
0
);
// error
SystemWaitParameter
(
nullptr
,
nullptr
,
0
);
SystemWaitParameter
(
"@@@@"
,
value
.
c_str
(),
1
);
}
HWTEST_F
(
ClientUnitTest
,
TestClient_02
,
TestSize
.
Level0
)
...
...
@@ -212,7 +216,7 @@ HWTEST_F(ClientUnitTest, TestClient_03, TestSize.Level0)
{
// 3 Traversal test
TestParamTraversal
();
SystemDumpParameters
(
1
,
-
1
,
NULL
);
SystemDumpParameters
(
1
,
-
1
,
nullptr
);
}
HWTEST_F
(
ClientUnitTest
,
TestClient_04
,
TestSize
.
Level0
)
...
...
@@ -224,6 +228,11 @@ HWTEST_F(ClientUnitTest, TestClient_04, TestSize.Level0)
#endif
ret
=
WatchParamCheck
(
"&&&&&.test.tttt"
);
EXPECT_NE
(
ret
,
0
);
ret
=
WatchParamCheck
(
nullptr
);
#ifndef OHOS_LITE
EXPECT_EQ
(
ret
,
100
);
#endif
// test permission
TestPermission
();
}
...
...
test/unittest/param/param_stub.cpp
浏览文件 @
0da55118
...
...
@@ -416,7 +416,7 @@ void PrepareCmdLineData()
"ohos.required_mount.vendor="
"/dev/block/platform/fe310000.sdhci/by-name/vendor@/vendor@ext4@ro,barrier=1@wait,required "
"ohos.required_mount.misc="
"/dev/block/platform/fe310000.sdhci/by-name/misc@none@none@none@wait,required "
;
"/dev/block/platform/fe310000.sdhci/by-name/misc@none@none@none@wait,required
ohos.boot.eng_mode=on
"
;
CreateTestFile
(
BOOT_CMD_LINE
,
cmdLine
);
}
...
...
@@ -575,6 +575,13 @@ static __attribute__((constructor(101))) void ParamTestStubInit(void)
// prepare data
mkdir
(
STARTUP_INIT_UT_PATH
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
CheckAndCreateDir
(
STARTUP_INIT_UT_PATH
MODULE_LIB_NAME
"/autorun/"
);
int
cmdIndex
=
0
;
(
void
)
GetMatchCmd
(
"copy "
,
&
cmdIndex
);
DoCmdByIndex
(
cmdIndex
,
MODULE_LIB_NAME
"/libbootchart.z.so "
STARTUP_INIT_UT_PATH
MODULE_LIB_NAME
"/libbootchart.z.so"
,
nullptr
);
DoCmdByIndex
(
cmdIndex
,
MODULE_LIB_NAME
"/libbootchart.z.so "
STARTUP_INIT_UT_PATH
MODULE_LIB_NAME
"/autorun/libbootchart.z.so"
,
nullptr
);
PrepareUeventdcfg
();
PrepareInnerKitsCfg
();
PrepareModCfg
();
...
...
@@ -583,10 +590,13 @@ static __attribute__((constructor(101))) void ParamTestStubInit(void)
CreateTestFile
(
STARTUP_INIT_UT_PATH
"/trigger_test.cfg"
,
g_triggerData
);
PrepareAreaSizeFile
();
PrepareTestGroupFile
();
PrepareCmdLineData
();
#ifndef OHOS_LITE
TestBeforeInit
();
SystemPrepare
();
SystemInit
();
SystemConfig
();
#endif
PrepareCmdLineData
();
// init service open
InitServiceSpace
();
// param service open
...
...
@@ -603,7 +613,7 @@ __attribute__((destructor)) static void ParamTestStubExit(void)
#ifndef OHOS_LITE
StopParamService
();
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_BOOT_COMPLETE
,
NULL
,
NULL
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_BOOT_COMPLETE
,
nullptr
,
nullptr
);
CloseUeventConfig
();
const
char
*
clearBootEventArgv
[]
=
{
"bootevent"
};
PluginExecCmd
(
"clear"
,
ARRAY_LENGTH
(
clearBootEventArgv
),
clearBootEventArgv
);
...
...
@@ -748,7 +758,7 @@ ParamLabelIndex *TestGetParamLabelIndex(const char *name)
}
#endif
labelIndex
.
workspace
=
paramWorkspace
->
workSpace
[
index
];
PARAM_CHECK
(
labelIndex
.
workspace
!=
NULL
,
return
NULL
,
"Invalid workSpace"
);
PARAM_CHECK
(
labelIndex
.
workspace
!=
nullptr
,
return
nullptr
,
"Invalid workSpace"
);
labelIndex
.
selinuxLabelIndex
=
labelIndex
.
workspace
->
spaceIndex
;
(
void
)
FindTrieNode
(
paramWorkspace
->
workSpace
[
0
],
name
,
strlen
(
name
),
&
labelIndex
.
dacLabelIndex
);
return
&
labelIndex
;
...
...
test/unittest/param/param_stub.h
浏览文件 @
0da55118
...
...
@@ -21,6 +21,10 @@
#include <sys/socket.h>
#include <sys/types.h>
#ifndef OHOS_LITE
#include "init_eng.h"
#include "init_context.h"
#endif
#include "param_manager.h"
#include "param_security.h"
#include "param_utils.h"
...
...
@@ -32,6 +36,12 @@ extern "C" {
#endif
#endif
#ifdef SUPPORT_64BIT
#define MODULE_LIB_NAME "/system/lib64/init"
#else
#define MODULE_LIB_NAME "/system/lib/init"
#endif
#define DEFAULT_ERROR (-65535)
#ifndef PARAM_SUPPORT_SELINUX
...
...
@@ -71,6 +81,24 @@ void SetStubResult(STUB_TYPE type, int result);
void
PrepareCmdLineData
();
ParamLabelIndex
*
TestGetParamLabelIndex
(
const
char
*
name
);
// for test
void
HandleUevent
(
const
struct
Uevent
*
uevent
);
#ifndef OHOS_LITE
void
EngineerOverlay
(
void
);
void
DebugFilesOverlay
(
const
char
*
source
,
const
char
*
target
);
void
BindMountFile
(
const
char
*
source
,
const
char
*
target
);
void
MountEngPartitions
(
void
);
void
BuildMountCmd
(
char
*
buffer
,
size_t
len
,
const
char
*
mp
,
const
char
*
dev
,
const
char
*
fstype
);
bool
IsFileExistWithType
(
const
char
*
file
,
FileType
type
);
int
DoRoot_
(
const
char
*
jobName
,
int
type
);
int
DoRebootShutdown
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
);
int
DoRebootFlashed
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
);
int
DoRebootOther
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
);
SubInitContext
*
GetSubInitContext
(
InitContextType
type
);
#endif
#ifdef __cplusplus
#if __cplusplus
}
...
...
test/unittest/param/param_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -299,7 +299,7 @@ public:
int
TestDumpParamMemory
()
{
SystemDumpParameters
(
1
,
-
1
,
NULL
);
SystemDumpParameters
(
1
,
-
1
,
nullptr
);
return
0
;
}
...
...
@@ -307,8 +307,8 @@ public:
{
#ifdef PARAM_SUPPORT_SELINUX
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
(
uint32_t
)
-
1
,
"Invalid paramSpace"
);
return
(
paramSpace
->
selinuxSpace
.
getParamLabelIndex
!=
NULL
)
?
PARAM_CHECK
(
paramSpace
!=
nullptr
,
return
(
uint32_t
)
-
1
,
"Invalid paramSpace"
);
return
(
paramSpace
->
selinuxSpace
.
getParamLabelIndex
!=
nullptr
)
?
paramSpace
->
selinuxSpace
.
getParamLabelIndex
(
name
)
+
WORKSPACE_INDEX_BASE
:
(
uint32_t
)
-
1
;
#else
return
0
;
...
...
@@ -443,7 +443,7 @@ HWTEST_F(ParamUnitTest, TestWorkSpace2, TestSize.Level0)
return
;
}
workSpace
->
flags
=
0
;
workSpace
->
area
=
NULL
;
workSpace
->
area
=
nullptr
;
int
ret
=
PARAM_STRCPY
(
workSpace
->
fileName
,
size
,
spaceName
);
EXPECT_EQ
(
ret
,
0
);
CloseWorkSpace
(
workSpace
);
...
...
@@ -496,19 +496,19 @@ HWTEST_F(ParamUnitTest, TestParamValueType2, TestSize.Level0)
HWTEST_F
(
ParamUnitTest
,
TestGetServiceCtlName
,
TestSize
.
Level0
)
{
ServiceCtrlInfo
*
serviceInfo
=
NULL
;
ServiceCtrlInfo
*
serviceInfo
=
nullptr
;
GetServiceCtrlInfo
(
"ohos.startup.powerctrl"
,
"reboot,updater"
,
&
serviceInfo
);
if
(
serviceInfo
!=
NULL
)
{
if
(
serviceInfo
!=
nullptr
)
{
EXPECT_STREQ
(
serviceInfo
->
realKey
,
"ohos.servicectrl.reboot.updater.reboot,updater"
);
free
(
serviceInfo
);
}
GetServiceCtrlInfo
(
"ohos.ctl.stop"
,
"test"
,
&
serviceInfo
);
if
(
serviceInfo
!=
NULL
)
{
if
(
serviceInfo
!=
nullptr
)
{
EXPECT_STREQ
(
serviceInfo
->
realKey
,
"ohos.servicectrl.stop.test"
);
free
(
serviceInfo
);
}
GetServiceCtrlInfo
(
"ohos.servicectrl.stop"
,
"test"
,
&
serviceInfo
);
if
(
serviceInfo
!=
NULL
)
{
if
(
serviceInfo
!=
nullptr
)
{
EXPECT_STREQ
(
serviceInfo
->
realKey
,
"ohos.servicectrl.stop.test"
);
free
(
serviceInfo
);
}
...
...
@@ -610,10 +610,11 @@ HWTEST_F(ParamUnitTest, TestStreamTaskFail, TestSize.Level0)
ParamTaskPtr
client
=
nullptr
;
ParamStreamInfo
info
=
{};
info
.
flags
=
PARAM_TEST_FLAGS
;
info
.
server
=
NULL
;
info
.
server
=
nullptr
;
info
.
close
=
OnClose
;
info
.
recvMessage
=
ProcessMessage
;
info
.
incomingConnect
=
NULL
;
info
.
incomingConnect
=
nullptr
;
int
ret
=
ParamStreamCreate
(
&
client
,
nullptr
,
&
info
,
sizeof
(
ParamWatcher
));
EXPECT_NE
(
ret
,
0
);
ret
=
ParamStreamCreate
(
&
client
,
GetParamService
()
->
serverTask
,
nullptr
,
sizeof
(
ParamWatcher
));
...
...
@@ -625,6 +626,8 @@ HWTEST_F(ParamUnitTest, TestStreamTaskFail, TestSize.Level0)
info
.
recvMessage
=
nullptr
;
ret
=
ParamStreamCreate
(
&
client
,
GetParamService
()
->
serverTask
,
&
info
,
sizeof
(
ParamWatcher
));
EXPECT_NE
(
ret
,
0
);
ret
=
ParamStreamCreate
(
&
client
,
nullptr
,
nullptr
,
sizeof
(
ParamWatcher
));
EXPECT_NE
(
ret
,
0
);
void
*
data
=
ParamGetTaskUserData
(
client
);
EXPECT_EQ
(
data
,
nullptr
);
...
...
@@ -637,10 +640,12 @@ HWTEST_F(ParamUnitTest, TestStreamTaskFail, TestSize.Level0)
HWTEST_F
(
ParamUnitTest
,
TestParamCache
,
TestSize
.
Level0
)
{
const
char
*
value
=
CachedParameterGet
(
nullptr
);
EXPECT_EQ
(
value
,
nullptr
);
const
char
*
name
=
"test.write.1111111.222222"
;
CachedHandle
cacheHandle
=
CachedParameterCreate
(
name
,
"true"
);
EXPECT_NE
(
cacheHandle
,
nullptr
);
const
char
*
value
=
CachedParameterGet
(
cacheHandle
);
value
=
CachedParameterGet
(
cacheHandle
);
EXPECT_EQ
(
strcmp
(
value
,
"true"
),
0
);
uint32_t
dataIndex
=
0
;
int
ret
=
WriteParam
(
name
,
"false"
,
&
dataIndex
,
0
);
...
...
@@ -660,6 +665,7 @@ HWTEST_F(ParamUnitTest, TestParamCache, TestSize.Level0)
value
=
CachedParameterGetChanged
(
cacheHandle3
,
&
valueChange
);
EXPECT_EQ
(
strcmp
(
value
,
"2222222"
),
0
);
EXPECT_EQ
(
valueChange
,
1
);
CachedParameterGetChanged
(
cacheHandle3
,
nullptr
);
CachedParameterDestroy
(
cacheHandle3
);
}
#endif
...
...
test/unittest/param/paramservice_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -315,7 +315,7 @@ public:
return
0
;
}
ParamSecurityOps
*
paramSecurityOps
=
GetParamSecurityOps
(
0
);
if
(
userLabel
&&
paramSecurityOps
!=
NULL
)
{
if
(
userLabel
&&
paramSecurityOps
!=
nullptr
)
{
paramSecurityOps
->
securityFreeLabel
=
TestFreeLocalSecurityLabel
;
paramSecurityOps
->
securityCheckParamPermission
=
TestCheckParamPermission
;
}
...
...
@@ -441,12 +441,13 @@ public:
int
TestCloseTriggerWatch
()
{
#ifdef PARAM_SUPPORT_TRIGGER
SystemDumpTriggers
(
1
,
NULL
);
SystemDumpTriggers
(
1
,
nullptr
);
#endif
ParamWatcher
*
watcher
=
(
ParamWatcher
*
)
ParamGetTaskUserData
(
g_worker
);
ClearWatchTrigger
(
watcher
,
TRIGGER_PARAM_WAIT
);
ParamTaskClose
(
g_worker
);
g_worker
=
nullptr
;
ParamTaskClose
(
g_worker
);
SystemWriteParam
(
"init.svc.param_watcher"
,
"stopped"
);
return
0
;
}
...
...
test/unittest/param/trigger_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -43,11 +43,11 @@ static void BootStateChange(int start, const char *content)
static
int
TestCmdExec
(
const
TriggerNode
*
trigger
,
const
char
*
content
,
uint32_t
size
)
{
PARAM_CHECK
(
trigger
!=
NULL
,
return
-
1
,
"Invalid trigger"
);
PARAM_CHECK
(
trigger
!=
nullptr
,
return
-
1
,
"Invalid trigger"
);
PARAM_LOGI
(
"DoTriggerExecute_ trigger type: %d %s"
,
trigger
->
type
,
GetTriggerName
(
trigger
));
PARAM_CHECK
(
trigger
->
type
<=
TRIGGER_UNKNOW
,
return
-
1
,
"Invalid trigger type %d"
,
trigger
->
type
);
CommandNode
*
cmd
=
GetNextCmdNode
(
reinterpret_cast
<
const
JobNode
*>
(
trigger
),
NULL
);
while
(
cmd
!=
NULL
)
{
CommandNode
*
cmd
=
GetNextCmdNode
(
reinterpret_cast
<
const
JobNode
*>
(
trigger
),
nullptr
);
while
(
cmd
!=
nullptr
)
{
g_execCmdId
=
cmd
->
cmdKeyIndex
;
cmd
=
GetNextCmdNode
(
reinterpret_cast
<
const
JobNode
*>
(
trigger
),
cmd
);
}
...
...
test/unittest/param/watcher_agent_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -278,7 +278,7 @@ HWTEST_F(WatcherAgentUnitTest, TestWatcherService, TestSize.Level0)
ServiceWatchForStatus
(
"param_watcher"
,
TestWatcherCallBack
);
ServiceWaitForStatus
(
"param_watcher"
,
SERVICE_STARTED
,
1
);
EXPECT_NE
(
ServiceWatchForStatus
(
errstr
,
TestWatcherCallBack
),
0
);
EXPECT_NE
(
ServiceWatchForStatus
(
NULL
,
TestWatcherCallBack
),
0
);
EXPECT_NE
(
ServiceWatchForStatus
(
nullptr
,
TestWatcherCallBack
),
0
);
WatchParameter
(
"testParam"
,
nullptr
,
nullptr
);
WatchParameter
(
nullptr
,
nullptr
,
nullptr
);
}
...
...
test/unittest/seccomp/seccomp_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -156,7 +156,7 @@ public:
#if defined __aarch64__
static
bool
CheckGetMempolicy
()
{
int
ret
=
syscall
(
__NR_get_mempolicy
,
NULL
,
NULL
,
0
,
NULL
,
0
);
int
ret
=
syscall
(
__NR_get_mempolicy
,
nullptr
,
nullptr
,
0
,
nullptr
,
0
);
if
(
ret
<
0
)
{
return
false
;
}
...
...
@@ -224,6 +224,15 @@ public:
// system allowlist
ret
=
CheckSyscall
(
SYSTEM_SA
,
SYSTEM_NAME
,
CheckGetpid
,
true
);
EXPECT_EQ
(
ret
,
0
);
// failed
ret
=
CheckSyscall
(
SYSTEM_SA
,
nullptr
,
CheckGetMempolicy
,
false
);
EXPECT_EQ
(
ret
,
0
);
ret
=
SystemWriteParam
(
"persist.init.debug.seccomp.enable"
,
"-1"
);
EXPECT_EQ
(
ret
,
0
);
ret
=
CheckSyscall
(
SYSTEM_SA
,
SYSTEM_NAME
,
CheckGetMempolicy
,
false
);
EXPECT_EQ
(
ret
,
0
);
}
void
TestSetUidGidFilter
()
...
...
test/unittest/syspara/syspara_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -115,6 +115,8 @@ HWTEST_F(SysparaUnitTest, parameterTest002, TestSize.Level0)
char
value1
[]
=
"set read only key"
;
int
ret
=
SetParameter
(
key1
,
value1
);
EXPECT_EQ
(
ret
,
EC_SUCCESS
);
ret
=
SetParameter
(
nullptr
,
nullptr
);
EXPECT_EQ
(
ret
,
EC_INVALID
);
}
HWTEST_F
(
SysparaUnitTest
,
parameterTest003
,
TestSize
.
Level0
)
...
...
@@ -271,6 +273,10 @@ HWTEST_F(SysparaUnitTest, parameterTest0012, TestSize.Level0)
EXPECT_EQ
(
ret
,
SYSPARAM_NOT_FOUND
);
ret
=
GetParameterName
(
handle
,
nameGet1
,
32
);
EXPECT_EQ
(
ret
,
SYSPARAM_NOT_FOUND
);
ret
=
GetParameterValue
(
handle
,
nullptr
,
32
);
EXPECT_EQ
(
ret
,
EC_INVALID
);
ret
=
GetParameterCommitId
(
handle
);
EXPECT_EQ
(
ret
,
-
1
);
}
HWTEST_F
(
SysparaUnitTest
,
parameterTest0013
,
TestSize
.
Level0
)
...
...
@@ -293,6 +299,8 @@ HWTEST_F(SysparaUnitTest, parameterTest0013, TestSize.Level0)
char
udid
[
UDID_LEN
]
=
{
0
};
GetDevUdid
(
udid
,
UDID_LEN
);
EXPECT_NE
(
GetMajorVersion
(),
0
);
int
ret
=
GetDevUdid
(
nullptr
,
UDID_LEN
);
EXPECT_EQ
(
ret
,
EC_FAILURE
);
GetSeniorVersion
();
GetFeatureVersion
();
GetBuildVersion
();
...
...
@@ -367,5 +375,13 @@ HWTEST_F(SysparaUnitTest, parameterTest0016, TestSize.Level0)
ret
=
OHOS
::
system
::
GetBoolParameter
(
key3
,
false
);
EXPECT_EQ
(
ret
,
false
);
}
HWTEST_F
(
SysparaUnitTest
,
parameterTest0017
,
TestSize
.
Level0
)
{
GetDistributionOSName
();
GetDistributionOSVersion
();
GetDistributionOSApiVersion
();
GetDistributionOSReleaseType
();
}
#endif
}
// namespace OHOS
test/unittest/ueventd/ueventd_event_unittest.cpp
浏览文件 @
0da55118
...
...
@@ -22,11 +22,14 @@
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#include "param_stub.h"
#include "ueventd.h"
#include "ueventd_device_handler.h"
#include "ueventd_socket.h"
using
namespace
testing
::
ext
;
namespace
UeventdUt
{
namespace
{
std
::
string
g_testRoot
{
"/data/ueventd"
};
...
...
@@ -262,6 +265,7 @@ HWTEST_F(UeventdEventUnitTest, TestParseUeventdEvent, TestSize.Level1)
EXPECT_STREQ
(
outEvent
.
syspath
,
"/block/mmc/test"
);
EXPECT_EQ
(
outEvent
.
ug
.
gid
,
0
);
EXPECT_EQ
(
outEvent
.
ug
.
uid
,
0
);
HandleUevent
(
&
outEvent
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestUeventActions
,
TestSize
.
Level1
)
...
...
@@ -279,6 +283,7 @@ HWTEST_F(UeventdEventUnitTest, TestUeventActions, TestSize.Level1)
struct
Uevent
outEvent
;
ParseUeventMessage
(
ueventBuffer
.
data
(),
ueventBuffer
.
length
(),
&
outEvent
);
EXPECT_EQ
(
outEvent
.
action
,
ACTION_UNKNOWN
);
HandleUevent
(
&
outEvent
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestUeventHandleBlockDevicesInvalidParameters
,
TestSize
.
Level1
)
...
...
@@ -477,4 +482,169 @@ HWTEST_F(UeventdEventUnitTest, TestUeventHandleUsbDevicesWithBusNo, TestSize.Lev
auto
exist
=
IsFileExist
(
"/dev/bus/usb/003/004"
);
EXPECT_TRUE
(
exist
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestUeventHandle
,
TestSize
.
Level1
)
{
char
path
[]
=
{
"/data/ueventd"
};
RetriggerUeventByPath
(
g_oldRootFd
,
path
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestFirmwareUevent
,
TestSize
.
Level1
)
{
struct
Uevent
uevent
=
{
.
subsystem
=
"firmware"
,
.
syspath
=
"/block/mmc/test"
,
.
deviceName
=
"test"
,
.
partitionName
=
"userdata"
,
.
firmware
=
""
,
.
action
=
ACTION_ADD
,
.
partitionNum
=
3
,
.
major
=
1
,
.
minor
=
2
,
.
ug
=
{
.
uid
=
0
,
.
gid
=
0
,
},
.
busNum
=
1
,
.
devNum
=
2
,
};
std
::
vector
<
std
::
string
>
extraData
{};
auto
ueventBuffer
=
GenerateUeventBuffer
(
uevent
,
extraData
);
struct
Uevent
outEvent
;
ParseUeventMessage
(
ueventBuffer
.
data
(),
ueventBuffer
.
length
(),
&
outEvent
);
EXPECT_EQ
(
outEvent
.
action
,
ACTION_ADD
);
EXPECT_EQ
(
outEvent
.
busNum
,
1
);
EXPECT_STREQ
(
outEvent
.
subsystem
,
"firmware"
);
EXPECT_STREQ
(
outEvent
.
deviceName
,
"test"
);
EXPECT_EQ
(
outEvent
.
devNum
,
2
);
EXPECT_EQ
(
outEvent
.
major
,
1
);
EXPECT_EQ
(
outEvent
.
minor
,
2
);
EXPECT_EQ
(
outEvent
.
partitionNum
,
3
);
EXPECT_STREQ
(
outEvent
.
partitionName
,
"userdata"
);
EXPECT_STREQ
(
outEvent
.
syspath
,
"/block/mmc/test"
);
EXPECT_EQ
(
outEvent
.
ug
.
gid
,
0
);
EXPECT_EQ
(
outEvent
.
ug
.
uid
,
0
);
HandleUevent
(
&
outEvent
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestUeventPlatformEvent
,
TestSize
.
Level1
)
{
struct
Uevent
uevent
=
{
.
subsystem
=
"platform"
,
.
syspath
=
"/block/mmc/test"
,
.
deviceName
=
"test"
,
.
partitionName
=
"userdata"
,
.
firmware
=
""
,
.
action
=
ACTION_ADD
,
.
partitionNum
=
3
,
.
major
=
1
,
.
minor
=
2
,
.
ug
=
{
.
uid
=
0
,
.
gid
=
0
,
},
.
busNum
=
1
,
.
devNum
=
2
,
};
std
::
vector
<
std
::
string
>
extraData
{};
auto
ueventBuffer
=
GenerateUeventBuffer
(
uevent
,
extraData
);
struct
Uevent
outEvent
;
ParseUeventMessage
(
ueventBuffer
.
data
(),
ueventBuffer
.
length
(),
&
outEvent
);
EXPECT_EQ
(
outEvent
.
action
,
ACTION_ADD
);
EXPECT_EQ
(
outEvent
.
busNum
,
1
);
EXPECT_STREQ
(
outEvent
.
subsystem
,
"platform"
);
EXPECT_STREQ
(
outEvent
.
deviceName
,
"test"
);
EXPECT_EQ
(
outEvent
.
devNum
,
2
);
EXPECT_EQ
(
outEvent
.
major
,
1
);
EXPECT_EQ
(
outEvent
.
minor
,
2
);
EXPECT_EQ
(
outEvent
.
partitionNum
,
3
);
EXPECT_STREQ
(
outEvent
.
partitionName
,
"userdata"
);
EXPECT_STREQ
(
outEvent
.
syspath
,
"/block/mmc/test"
);
EXPECT_EQ
(
outEvent
.
ug
.
gid
,
0
);
EXPECT_EQ
(
outEvent
.
ug
.
uid
,
0
);
HandleUevent
(
&
outEvent
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestUeventPlatformEventUsb
,
TestSize
.
Level1
)
{
struct
Uevent
uevent
=
{
.
subsystem
=
"usb"
,
.
syspath
=
"/block/mmc/test"
,
.
deviceName
=
"test"
,
.
partitionName
=
"userdata"
,
.
firmware
=
""
,
.
action
=
ACTION_ADD
,
.
partitionNum
=
3
,
.
major
=
1
,
.
minor
=
2
,
.
ug
=
{
.
uid
=
0
,
.
gid
=
0
,
},
.
busNum
=
1
,
.
devNum
=
2
,
};
std
::
vector
<
std
::
string
>
extraData
{};
auto
ueventBuffer
=
GenerateUeventBuffer
(
uevent
,
extraData
);
struct
Uevent
outEvent
;
ParseUeventMessage
(
ueventBuffer
.
data
(),
ueventBuffer
.
length
(),
&
outEvent
);
EXPECT_EQ
(
outEvent
.
action
,
ACTION_ADD
);
EXPECT_EQ
(
outEvent
.
busNum
,
1
);
EXPECT_STREQ
(
outEvent
.
subsystem
,
"usb"
);
EXPECT_STREQ
(
outEvent
.
deviceName
,
"test"
);
EXPECT_EQ
(
outEvent
.
devNum
,
2
);
EXPECT_EQ
(
outEvent
.
major
,
1
);
EXPECT_EQ
(
outEvent
.
minor
,
2
);
EXPECT_EQ
(
outEvent
.
partitionNum
,
3
);
EXPECT_STREQ
(
outEvent
.
partitionName
,
"userdata"
);
EXPECT_STREQ
(
outEvent
.
syspath
,
"/block/mmc/test"
);
EXPECT_EQ
(
outEvent
.
ug
.
gid
,
0
);
EXPECT_EQ
(
outEvent
.
ug
.
uid
,
0
);
HandleUevent
(
&
outEvent
);
}
static
void
TestUeventAction
(
ACTION
action
)
{
struct
Uevent
uevent
=
{
.
subsystem
=
"block"
,
.
syspath
=
"/block/mmc/test"
,
.
deviceName
=
"test"
,
.
partitionName
=
"userdata"
,
.
firmware
=
""
,
.
action
=
action
,
.
partitionNum
=
3
,
.
major
=
1
,
.
minor
=
2
,
.
ug
=
{
.
uid
=
0
,
.
gid
=
0
,
},
.
busNum
=
1
,
.
devNum
=
2
,
};
std
::
vector
<
std
::
string
>
extraData
{};
auto
ueventBuffer
=
GenerateUeventBuffer
(
uevent
,
extraData
);
struct
Uevent
outEvent
;
ParseUeventMessage
(
ueventBuffer
.
data
(),
ueventBuffer
.
length
(),
&
outEvent
);
EXPECT_EQ
(
outEvent
.
action
,
action
);
HandleUevent
(
&
outEvent
);
}
HWTEST_F
(
UeventdEventUnitTest
,
TestUeventActionAdd
,
TestSize
.
Level1
)
{
TestUeventAction
(
ACTION_ADD
);
TestUeventAction
(
ACTION_REMOVE
);
TestUeventAction
(
ACTION_CHANGE
);
TestUeventAction
(
ACTION_MOVE
);
TestUeventAction
(
ACTION_ONLINE
);
TestUeventAction
(
ACTION_OFFLINE
);
TestUeventAction
(
ACTION_BIND
);
TestUeventAction
(
ACTION_UNBIND
);
TestUeventAction
(
ACTION_UNKNOWN
);
}
}
// UeventdUt
\ No newline at end of file
ueventd/include/ueventd_firmware_handler.h
浏览文件 @
0da55118
...
...
@@ -16,5 +16,17 @@
#ifndef BASE_STARTUP_INITLITE_UEVENTD_FIRMWARE_HANDLER_H
#define BASE_STARTUP_INITLITE_UEVENTD_FIRMWARE_HANDLER_H
#include "ueventd.h"
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
#endif
#endif
void
HandleFimwareDeviceEvent
(
const
struct
Uevent
*
uevent
);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
/* MODULE_REBOOT_ADP_H */
#endif // BASE_STARTUP_INITLITE_UEVENTD_FIRMWARE_HANDLER_H
ueventd/ueventd.c
浏览文件 @
0da55118
...
...
@@ -101,7 +101,7 @@ static ACTION GetUeventAction(const char *action)
}
}
static
void
HandleUevent
(
const
struct
Uevent
*
uevent
)
STATIC
void
HandleUevent
(
const
struct
Uevent
*
uevent
)
{
if
(
uevent
->
action
==
ACTION_ADD
||
uevent
->
action
==
ACTION_CHANGE
||
uevent
->
action
==
ACTION_ONLINE
)
{
ChangeSysAttributePermissions
(
uevent
->
syspath
);
...
...
@@ -214,10 +214,6 @@ static void HandleUeventRequired(const struct Uevent *uevent, char **devices, in
static
void
AddUevent
(
struct
Uevent
*
uevent
,
const
char
*
event
,
size_t
len
)
{
if
(
uevent
==
NULL
||
event
==
NULL
||
len
==
0
)
{
return
;
}
if
(
STARTSWITH
(
event
,
"DEVPATH="
))
{
uevent
->
syspath
=
event
+
strlen
(
"DEVPATH="
);
}
else
if
(
STARTSWITH
(
event
,
"SUBSYSTEM="
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录