提交 dd9e2a07 编写于 作者: C cheng_jinsong

add unittest cases

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
Change-Id: Ifbd6923f273f167d78e514cc24c04a3e275e321a
上级 dada4574
......@@ -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",
]
......
......@@ -300,7 +300,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;
......
......@@ -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
......@@ -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);
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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");
......
......@@ -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:
......@@ -168,3 +173,13 @@ 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
......@@ -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);
......
# 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
# 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
# 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
{
"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.
先完成此消息的编辑!
想要评论请 注册