Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
73b064c9
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
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看板
未验证
提交
73b064c9
编写于
9月 23, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1300 添加init单元测试用例
Merge pull request !1300 from cheng_jinsong/master_cc_add_ut
上级
e770b632
dd9e2a07
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
99 addition
and
157 deletion
+99
-157
test/unittest/BUILD.gn
test/unittest/BUILD.gn
+4
-0
test/unittest/init/group_unittest.cpp
test/unittest/init/group_unittest.cpp
+6
-0
test/unittest/init/loopevent_unittest.cpp
test/unittest/init/loopevent_unittest.cpp
+13
-0
test/unittest/init/service_unittest.cpp
test/unittest/init/service_unittest.cpp
+5
-1
test/unittest/init/utils_unittest.cpp
test/unittest/init/utils_unittest.cpp
+2
-0
test/unittest/innerkits/hookmgr_unittest.cpp
test/unittest/innerkits/hookmgr_unittest.cpp
+8
-0
test/unittest/innerkits/innerkits_unittest.cpp
test/unittest/innerkits/innerkits_unittest.cpp
+43
-0
test/unittest/param/trigger_unittest.cpp
test/unittest/param/trigger_unittest.cpp
+2
-1
test/unittest/param/watcher_agent_unittest.cpp
test/unittest/param/watcher_agent_unittest.cpp
+15
-0
test/unittest/syspara/syspara_unittest.cpp
test/unittest/syspara/syspara_unittest.cpp
+1
-0
test/unittest/test_data/system/etc/param/ohos.para
test/unittest/test_data/system/etc/param/ohos.para
+0
-40
test/unittest/test_data/system/etc/param/ohos.para.dac
test/unittest/test_data/system/etc/param/ohos.para.dac
+0
-34
test/unittest/test_data/system/etc/param/ohos.para.selinux
test/unittest/test_data/system/etc/param/ohos.para.selinux
+0
-29
test/unittest/test_data/trigger_test.cfg
test/unittest/test_data/trigger_test.cfg
+0
-52
未找到文件。
test/unittest/BUILD.gn
浏览文件 @
73b064c9
...
...
@@ -160,6 +160,10 @@ ohos_unittest("init_unittest") {
"//base/startup/init/interfaces/innerkits/hookmgr/hookmgr.c",
"//base/startup/init/interfaces/innerkits/init_module_engine/init_modulemgr.c",
"//base/startup/init/interfaces/innerkits/modulemgr/modulemgr.c",
"//base/startup/init/interfaces/innerkits/service_control/service_control.c",
"//base/startup/init/interfaces/innerkits/service_watcher/service_watcher.c",
"//base/startup/init/interfaces/innerkits/syscap/init_syscap.c",
"//base/startup/init/interfaces/innerkits/syspara/param_wrapper.cpp",
"innerkits/hookmgr_unittest.cpp",
"innerkits/modulemgr_unittest.cpp",
]
...
...
test/unittest/init/group_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -302,7 +302,13 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1)
ParseAllServices
(
fileRoot
);
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
);
Service
*
service
=
GetServiceByName
(
"test-service6"
);
ASSERT_NE
(
service
,
nullptr
);
workspace
->
groupMode
=
GROUP_BOOT
;
...
...
test/unittest/init/loopevent_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -297,4 +297,17 @@ HWTEST_F(LoopEventUnittest, ProcessWatcherTask, TestSize.Level1)
LoopEventUnittest
loopevtest
=
LoopEventUnittest
();
loopevtest
.
ProcessWatcherTask
();
}
HWTEST_F
(
LoopEventUnittest
,
CloseTackUnittest
,
TestSize
.
Level1
)
{
LoopHandle
loop
=
nullptr
;
LE_GetSendResult
(
nullptr
);
ASSERT_EQ
(
LE_CreateLoop
(
&
loop
),
0
);
((
EventLoop
*
)
loop
)
->
runLoop
(
nullptr
);
((
EventLoop
*
)
loop
)
->
runLoop
=
[](
const
struct
EventLoop_
*
loop
)
->
LE_STATUS
{
return
LE_SUCCESS
;};
LE_RunLoop
(
loop
);
LE_StopLoop
(
loop
);
LE_CloseLoop
(
loop
);
}
}
// namespace init_ut
test/unittest/init/service_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -307,9 +307,12 @@ HWTEST_F(ServiceUnitTest, TestServiceBootEventHook, TestSize.Level1)
SystemWriteParam
(
"bootevent.bootevent1"
,
"true"
);
SystemWriteParam
(
"bootevent.bootevent1"
,
"true"
);
SystemWriteParam
(
"bootevent.bootevent2"
,
"true"
);
SystemSetParameter
(
"ohos.servicectrl.save.bootevent"
,
"save.bootevent"
);
const
char
*
initBootevent
[]
=
{
"init"
,
"test"
};
PluginExecCmd
(
"bootevent"
,
ARRAY_LENGTH
(
initBootevent
),
initBootevent
);
PluginExecCmd
(
"save.bootevent"
,
0
,
nullptr
);
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_DUMP
,
(
void
*
)(
&
serviceInfoContext
),
NULL
);
(
void
)
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_CLEAR
,
(
void
*
)(
&
serviceInfoContext
),
NULL
);
PluginExecCmd
(
"clear"
,
0
,
nullptr
);
cJSON_Delete
(
fileRoot
);
}
...
...
@@ -330,6 +333,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
caps
[
0
]
=
FULL_CAP
;
service
->
servPerm
.
caps
=
caps
;
service
->
servPerm
.
capsCnt
=
1
;
IsEnableSandbox
();
EnterServiceSandbox
(
service
);
int
ret
=
ServiceExec
(
service
);
EXPECT_EQ
(
ret
,
0
);
...
...
test/unittest/init/utils_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -73,5 +73,7 @@ HWTEST_F(UtilsUnitTest, TestUtilsApi, TestSize.Level0)
mode_t
mode
=
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
|
S_IXOTH
;
CheckAndCreatFile
(
"/data/init_ut/testcreatfile"
,
mode
);
CheckAndCreatFile
(
"/data/init_ut/nodir/testcreatfile"
,
mode
);
char
testStr
[]
=
".trim"
;
EXPECT_STREQ
(
TrimHead
(
testStr
,
'.'
),
"trim"
);
}
}
// namespace init_ut
test/unittest/innerkits/hookmgr_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -16,6 +16,7 @@
#include <cinttypes>
#include <gtest/gtest.h>
#include "hookmgr.h"
#include "bootstage.h"
using
namespace
testing
::
ext
;
using
namespace
std
;
...
...
@@ -299,4 +300,11 @@ HWTEST_F(HookMgrUnitTest, HookMgrExecute_unitest, TestSize.Level1)
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ctx
.
result
,
1
);
}
HWTEST_F
(
HookMgrUnitTest
,
HookMgrExecuteInit_unitest
,
TestSize
.
Level1
)
{
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
nullptr
,
nullptr
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_PRE_CFG_LOAD
,
nullptr
,
nullptr
);
InitAddClearServiceHook
([](
SERVICE_INFO_CTX
*
serviceCtx
)
{
return
;});
}
}
// namespace init_ut
test/unittest/innerkits/innerkits_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -14,11 +14,21 @@
*/
#include <cinttypes>
#include <string>
#include <sys/mount.h>
#include "fs_manager/fs_manager.h"
#include "init_log.h"
#include "param_stub.h"
#include "securec.h"
#include "systemcapability.h"
#include "service_control.h"
#include "param_wrapper.h"
#include "param_manager.h"
#include "parameters.h"
#include "param_persist.h"
#include "sys_param.h"
#include "init_module_engine.h"
#include "init_control_fd_service.h"
using
namespace
testing
::
ext
;
using
namespace
std
;
...
...
@@ -210,4 +220,37 @@ HWTEST_F(InnerkitsUnitTest, MountAllWithFstabFile_unittest, TestSize.Level1)
{
EXPECT_NE
(
MountAllWithFstabFile
(
"/etc/fstab.required"
,
0
),
1
);
}
HWTEST_F
(
InnerkitsUnitTest
,
others_unittest
,
TestSize
.
Level1
)
{
InitParameterClient
();
CheckAndSavePersistParam
();
ClosePersistParamWorkSpace
();
InitModuleMgrInstall
(
"testModule"
);
InitModuleMgrDump
();
InitModuleMgrUnInstall
(
"testModule"
);
EXPECT_EQ
(
HasSystemCapability
(
"test.cap"
),
0
);
HasSystemCapability
(
nullptr
);
EXPECT_EQ
(
ServiceSetReady
(
"testservice"
),
0
);
EXPECT_EQ
(
StartServiceByTimer
(
"testservice"
,
1
),
0
);
EXPECT_EQ
(
StartServiceByTimer
(
"deviceinfoservice"
,
0
),
0
);
const
char
*
extArgv
[]
=
{
"testarg"
};
EXPECT_EQ
(
ServiceControlWithExtra
(
"deviceinfoservice"
,
START
,
extArgv
,
1
),
0
);
EXPECT_EQ
(
ServiceControlWithExtra
(
"deviceinfoservice"
,
RESTART
,
extArgv
,
1
),
0
);
EXPECT_EQ
(
ServiceControlWithExtra
(
"deviceinfoservice"
,
STOP
,
extArgv
,
1
),
0
);
EXPECT_EQ
(
ServiceControlWithExtra
(
"deviceinfoservice"
,
RESTART
,
extArgv
,
1
),
0
);
EXPECT_EQ
(
StopServiceTimer
(
"testservice"
),
0
);
std
::
string
value
(
"10"
);
std
::
string
param
(
"test.param"
);
EXPECT_EQ
(
OHOS
::
system
::
SetParameter
(
"test.param"
,
value
),
true
);
EXPECT_EQ
(
OHOS
::
system
::
GetStringParameter
(
"test.param"
,
value
),
0
);
EXPECT_EQ
(
OHOS
::
system
::
GetIntParameter
(
param
,
0
),
0
);
OHOS
::
system
::
GetUintParameter
(
param
,
std
::
numeric_limits
<
uint8_t
>::
min
(),
std
::
numeric_limits
<
uint8_t
>::
max
());
EXPECT_EQ
(
OHOS
::
system
::
GetParameter
(
param
,
""
),
""
);
EXPECT_EQ
(
OHOS
::
system
::
GetBoolParameter
(
param
,
false
),
false
);
OHOS
::
system
::
GetDeviceType
();
EXPECT_EQ
(
LoadParamsFile
(
"/path/to/test"
,
0
),
0
);
UmountAllWithFstabFile
(
"/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable"
);
}
}
// namespace init_ut
test/unittest/param/trigger_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -266,7 +266,8 @@ public:
JobNode
*
node
=
AddTrigger
(
TRIGGER_PARAM
,
triggerName
,
buffer
,
0
);
JobNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
EXPECT_EQ
(
trigger
,
node
);
DoJobNow
(
triggerName
);
ClearTrigger
(
nullptr
,
0
);
g_matchTrigger
=
0
;
SystemWriteParam
(
param1
,
"1"
);
ret
=
sprintf_s
(
buffer
,
sizeof
(
buffer
),
"%s=%s"
,
param1
,
"1"
);
...
...
test/unittest/param/watcher_agent_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -26,6 +26,7 @@
#include "system_ability_definition.h"
#include "watcher.h"
#include "watcher_manager_kits.h"
#include "service_watcher.h"
using
namespace
testing
::
ext
;
using
namespace
std
;
...
...
@@ -36,6 +37,10 @@ void TestParameterChange(const char *key, const char *value, void *context)
{
printf
(
"TestParameterChange key:%s %s"
,
key
,
value
);
}
void
TestWatcherCallBack
(
const
char
*
key
,
ServiceStatus
status
)
{
printf
(
"TestWatcherCallBack key:%s %d"
,
key
,
status
);
}
class
WatcherAgentUnitTest
:
public
::
testing
::
Test
{
public:
...
...
@@ -167,4 +172,14 @@ HWTEST_F(WatcherAgentUnitTest, TestResetService, TestSize.Level0)
{
WatcherAgentUnitTest
test
;
test
.
TestResetService
();
}
HWTEST_F
(
WatcherAgentUnitTest
,
TestWatcherService
,
TestSize
.
Level0
)
{
const
char
*
errstr
=
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
;
ServiceWatchForStatus
(
"param_watcher"
,
TestWatcherCallBack
);
ServiceWaitForStatus
(
"param_watcher"
,
SERVICE_STARTED
,
1
);
EXPECT_EQ
(
ServiceWatchForStatus
(
errstr
,
TestWatcherCallBack
),
-
1
);
EXPECT_EQ
(
ServiceWatchForStatus
(
NULL
,
TestWatcherCallBack
),
-
1
);
WatchParameter
(
"testParam"
,
nullptr
,
nullptr
);
}
\ No newline at end of file
test/unittest/syspara/syspara_unittest.cpp
浏览文件 @
73b064c9
...
...
@@ -276,6 +276,7 @@ HWTEST_F(SysparaUnitTest, parameterTest0013, TestSize.Level0)
EXPECT_EQ
(
ret
,
0
);
GetParameter_
(
nullptr
,
nullptr
,
nullptr
,
0
);
EXPECT_EQ
(
GetIntParameter
(
key1
,
0
),
0
);
EXPECT_EQ
(
GetUintParameter
(
key1
,
0
),
0
);
EXPECT_EQ
(
IsValidParamValue
(
nullptr
,
0
),
0
);
EXPECT_EQ
(
IsValidParamValue
(
"testvalue"
,
strlen
(
"testvalue"
)
+
1
),
1
);
EXPECT_EQ
(
StringToLL
(
"0x11"
,
&
out
),
0
);
...
...
test/unittest/test_data/system/etc/param/ohos.para
已删除
100755 → 0
浏览文件 @
e770b632
# Copyright (c) 2021 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.
build_version = 2.0
# whether ohos is enabled.
hw_sc.build.os.enable=true
# ohos API version number.
hw_sc.build.os.apiversion=6
# ohos system version.
hw_sc.build.os.version=2.2.0
# ohos device type please use hw_sc.build.os.devicetype
# ohos release type
hw_sc.build.os.releasetype=Canary1
const.hardware=Hi3516DV300
const.actionable_compatible_property.enabled=false
const.postinstall.fstab.prefix=/system
const.secure=1
security.perf_harden=1
const.allow.mock.location=0
const.debuggable=1
const.build.characteristics="default"
const.product.model="ohos"
const.product.name="OpenHarmony 2.0 Canary"
persist.sys.usb.config=hdc
test/unittest/test_data/system/etc/param/ohos.para.dac
已删除
100755 → 0
浏览文件 @
e770b632
# Copyright (c) 2021 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.
build_version root:root:0777
hw_sc.build.os.enable root:root:0777
hw_sc.build.os.apiversion root:root:0777
hw_sc.build.os.version root:root:0777
hw_sc.build.os.releasetype root:root:0777
const.actionable_compatible_property.enabled root:root:0777
const.postinstall.fstab.prefix root:root:0777
const.secure root:root:0777
security.perf_harden root:root:0777
const.allow.mock.location root:root:0777
const.debuggable root:root:0777
persist.sys.usb.config root:root:0777
# default forbid other user to start service
ohos.servicectrl. root:root:0777
test.permission. root:root:0770
test.permission.read. root:root:0774
test.permission.write. root:root:0772
test.permission.watcher. root:root:0771
test/unittest/test_data/system/etc/param/ohos.para.selinux
已删除
100755 → 0
浏览文件 @
e770b632
# Copyright (c) 2021 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.
build_version root:root:0777
hw_sc.build.os.enable root:root:0777
hw_sc.build.os.apiversion root:root:0777
hw_sc.build.os.version root:root:0777
hw_sc.build.os.releasetype root:root:0777
const.actionable_compatible_property.enabled root:root:0777
const.postinstall.fstab.prefix root:root:0777
const.secure root:root:0777
security.perf_harden root:root:0777
const.allow.mock.location root:root:0777
const.debuggable root:root:0777
persist.sys.usb.config root:root:0777
# default forbid other user to start service
ohos.servicectrl. root:root:0777
test/unittest/test_data/trigger_test.cfg
已删除
100755 → 0
浏览文件 @
e770b632
{
"jobs" : [{
"name" : "early-init",
"cmds" : [
" write '/proc/sys/kernel/sysrq 0'",
" load_persist_params ",
" load_persist_params ",
" # load_persist_params ",
" restorecon /postinstall",
"mkdir /acct/uid",
"chown root system /dev/memcg/memory.pressure_level",
"chmod 0040 /dev/memcg/memory.pressure_level",
"mkdir /dev/memcg/apps/ 0755 system system",
"mkdir /dev/memcg/system 0550 system system",
"start ueventd",
"exec_start apexd-bootstrap",
"setparam sys.usb.config ${persist.sys.usb.config}"
]
},
{
"name" : "param:trigger_test_1",
"condition" : "test.sys.boot_from_charger_mode=5",
"cmds" : [
"class_stop charger",
"trigger late-init"
]
},
{
"name" : "param:trigger_test_2",
"condition" : "test.sys.boot_from_charger_mode=1 || test.sys.boot_from_charger_mode=2 || test.sys.boot_from_charger_mode=3",
"cmds" : [
"class_stop charger",
"trigger late-init"
]
},
{
"name" : "load_persist_params_action",
"cmds" : [
"load_persist_params",
"start logd",
"start logd-reinit"
]
},
{
"name" : "firmware_mounts_complete",
"cmds" : [
"rm /dev/.booting"
]
}
]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录