mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 07:00:17 +00:00
lite UT
Signed-off-by: xlei1030 <xionglei6@huawei.com>
This commit is contained in:
parent
f7b7dddb2b
commit
91a7458f7d
@ -81,3 +81,9 @@ executable("appspawn") {
|
||||
include_dirs += []
|
||||
}
|
||||
}
|
||||
|
||||
if (ohos_build_type == "debug") {
|
||||
group("unittest") {
|
||||
deps = [ "//base/startup/appspawn_standard/test/unittest/app_spawn_lite_test:unittest" ]
|
||||
}
|
||||
}
|
||||
|
@ -167,10 +167,12 @@ static void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)
|
||||
appProperty->message.bundleName, appProperty->message.identityID, appProperty->message.uID,
|
||||
appProperty->message.gID);
|
||||
|
||||
#ifndef APPSPAWN_TEST
|
||||
if (AbilityMain(appProperty->message.identityID) != 0) {
|
||||
APPSPAWN_LOGE("[appspawn] AbilityMain execute failed, pid %d.", getpid());
|
||||
exit(0x7f); // 0x7f: user specified
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetContentFunction(AppSpawnContent *content)
|
||||
|
@ -38,6 +38,9 @@
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/startup/appspawn_standard/lite:appspawn_lite"
|
||||
],
|
||||
"test": [
|
||||
"//base/startup/appspawn_standard/test/unittest/app_spawn_lite_test:unittest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -23,24 +23,52 @@ unittest("AppSpawnLiteTest") {
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//base/startup/appspawn_standard/interfaces/innerkits/include",
|
||||
"//base/startup/appspawn_standard/common/",
|
||||
"//base/startup/appspawn_standard/lite/",
|
||||
"//base/startup/init_lite/interfaces/innerkits/include",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/registry",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
"//third_party/cJSON",
|
||||
"${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"//base/startup/appspawn_standard/common/appspawn_server.c",
|
||||
"//base/startup/appspawn_standard/lite/appspawn_message.c",
|
||||
"//base/startup/appspawn_standard/lite/appspawn_process.c",
|
||||
"//base/startup/appspawn_standard/lite/appspawn_service.c",
|
||||
"app_spawn_lite_test.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//build/lite/config/component/cJSON:cjson_shared",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
}
|
||||
defines = [ "APPSPAWN_TEST" ]
|
||||
|
||||
group("unittest") {
|
||||
deps = [ ":appspawn_test" ]
|
||||
deps = [
|
||||
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//build/lite/config/component/cJSON:cjson_shared",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//utils/native/lite/kv_store:kv_store",
|
||||
]
|
||||
|
||||
deps += [
|
||||
"//foundation/ace/ace_engine_lite/frameworks:ace_lite",
|
||||
"//foundation/graphic/surface:lite_surface",
|
||||
"//foundation/graphic/ui:lite_ui",
|
||||
"//foundation/graphic/utils:lite_graphic_utils",
|
||||
]
|
||||
|
||||
if (ohos_kernel_type == "liteos_a") {
|
||||
deps += [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
deps = [ ":AppSpawnLiteTest" ]
|
||||
}
|
@ -15,12 +15,14 @@
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include "gtest/gtest.h"
|
||||
#include "appspawn_message.h"
|
||||
#include "appspawn_service.h"
|
||||
#include "appspawn_msg.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
@ -46,17 +48,28 @@ public:
|
||||
g_badStrings.push_back(std::string("\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""));
|
||||
g_badStrings.push_back(std::string("............................................."));
|
||||
g_badStrings.push_back(std::string("....%%%....^..***@##.../*--++......$$&&....."));
|
||||
StructuralFormatErrJson();
|
||||
StructuralFieldMisJson();
|
||||
StructuralFieldInvalidJson();
|
||||
printf("[----------] AppSpawnLiteTest, message func test setup.\n");
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
g_badStrings.clear();
|
||||
g_goodStrings.clear();
|
||||
printf("[----------] AppSpawnLiteTest, message func test teardown.\n");
|
||||
}
|
||||
void SetUp() {}
|
||||
void TearDown() {}
|
||||
|
||||
static void StructuralFormatErrJson(void)
|
||||
{
|
||||
// looks like json but format error
|
||||
g_badStrings.push_back(std::string(
|
||||
"{bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName:\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV,\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID:\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
@ -67,12 +80,6 @@ public:
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID:10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID:10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability:[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
@ -91,12 +98,6 @@ public:
|
||||
"{\"bundleName\":\"nameV\"\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\"\"1\",\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\"\"uID\":10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\"10,\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10\"gID\":10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\"10,\"capability\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
@ -109,6 +110,10 @@ public:
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0],}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1\",\"uID\":10,\"gID\":10,\"capability\":[0,]}"));
|
||||
}
|
||||
|
||||
static void StructuralFieldMisJson(void)
|
||||
{
|
||||
// json format correct but fields missing
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1234\",\"uID\":1000,\"gID\":1000,\"capability\":[0]}"));
|
||||
@ -132,6 +137,10 @@ public:
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1234\",\"uID\":1000,\"gID\":1000,\"\":[0]}"));
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"nameV\",\"identityID\":\"1234\",\"uID\":1000,\"gID\":1000}"));
|
||||
}
|
||||
|
||||
static void StructuralFieldInvalidJson(void)
|
||||
{
|
||||
// field value invalid
|
||||
g_badStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"\",\"identityID\":\"1234\",\"uID\":1000,\"gID\":1000,\"capability\":[0]}"));
|
||||
@ -167,17 +176,7 @@ public:
|
||||
"{\"bundleName\":\"testvalid3\",\"identityID\":\"999\",\"uID\":1002,\"gID\":1002,\"capability\":[]}"));
|
||||
g_goodStrings.push_back(std::string(
|
||||
"{\"bundleName\":\"testvalid3\",\"identityID\":\"3\",\"uID\":1002,\"gID\":1002,\"capability\":[1,2]}"));
|
||||
printf("[----------] AppSpawnLiteTest, message func test setup.\n");
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
g_badStrings.clear();
|
||||
g_goodStrings.clear();
|
||||
printf("[----------] AppSpawnLiteTest, message func test teardown.\n");
|
||||
}
|
||||
void SetUp() {}
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -217,7 +216,7 @@ HWTEST_F(AppSpawnLiteTest, msgFuncFreeTest_002, TestSize.Level1)
|
||||
msgSt.capsCnt = MALLOC_TEST_LENGTH;
|
||||
FreeMessageSt(&msgSt);
|
||||
EXPECT_EQ(msgSt.capsCnt, 0);
|
||||
|
||||
|
||||
msgSt.uID = TEST_UID;
|
||||
FreeMessageSt(&msgSt);
|
||||
EXPECT_EQ(msgSt.uID, -1);
|
||||
@ -317,7 +316,7 @@ HWTEST_F(AppSpawnLiteTest, msgFuncSplitTest_001, TestSize.Level1)
|
||||
HWTEST_F(AppSpawnLiteTest, msgFuncSplitTest_002, TestSize.Level1)
|
||||
{
|
||||
MessageSt msgSt = {0};
|
||||
|
||||
|
||||
struct timespec tmStart = {0};
|
||||
GetCurrentTime(&tmStart);
|
||||
|
||||
@ -337,7 +336,7 @@ HWTEST_F(AppSpawnLiteTest, msgFuncSplitTest_002, TestSize.Level1)
|
||||
long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * NANOSECONDS_PER_SECOND + (tmEnd.tv_nsec - tmStart.tv_nsec);
|
||||
printf("[----------] AppSpawnLiteTest, msgFuncSplitTest_002, total time %ld ns, strCnt %u.\n", \
|
||||
timeUsed, g_goodStrings.size());
|
||||
|
||||
|
||||
// parse one good string and check all results
|
||||
std::string validStr =
|
||||
"{\"bundleName\":\"validName\",\"identityID\":\"135\",\"uID\":999,\"gID\":888,\"capability\":[0, 1, 5]}";
|
||||
@ -368,32 +367,27 @@ HWTEST_F(AppSpawnLiteTest, SetContentFunctionTest_001, TestSize.Level0)
|
||||
GTEST_LOG_(INFO) << "SetContentFunctionTest_001 start";
|
||||
AppSpawnContent *content = AppSpawnCreateContent("AppSpawn", NULL, 0, 0);
|
||||
SetContentFunction(content);
|
||||
char *longProcName = "SetContentFunctionTest_001";
|
||||
int64_t longProcNameLen = 1024;
|
||||
|
||||
std::unique_ptr<AppSpawnClientExt> clientExt = std::make_unique<AppSpawnClientExt>();
|
||||
clientExt->client.id = 1;
|
||||
clientExt->client.flag = 0;
|
||||
clientExt->fd[0] = 123;
|
||||
clientExt->fd[1] = 456;
|
||||
clientExt->property.uid = 10002;
|
||||
clientExt->property.gid = 1000;
|
||||
clientExt->property.gidCount = 1;
|
||||
strcpy_s(clientExt->property.processName, APP_LEN_PROC_NAME, "com.ohos.settingsdata");
|
||||
strcpy_s(clientExt->property.bundleName, APP_LEN_BUNDLE_NAME, "com.ohos.settingsdata");
|
||||
strcpy_s(clientExt->property.soPath, APP_LEN_SO_PATH, " ");
|
||||
clientExt->property.accessTokenId = 671201800;
|
||||
strcpy_s(clientExt->property.apl, APP_APL_MAX_LEN, "system_core");
|
||||
strcpy_s(clientExt->property.renderCmd, APP_RENDER_CMD_MAX_LEN, " ");
|
||||
string longProcName = "SetContentFunctionTest_001";
|
||||
int64_t longProcNameLen = longProcName.length();
|
||||
|
||||
clientExt->property.flags = 0;
|
||||
AppSpawnClientLite *liteClient = (AppSpawnClientLite *)malloc(sizeof(AppSpawnClientLite));
|
||||
EXPECT_TRUE(liteClient);
|
||||
liteClient->client.id = 1;
|
||||
liteClient->client.flags = 0;
|
||||
|
||||
content->setProcessName(content, clientExt->client, longProcName, longProcNameLen);
|
||||
content->setKeepCapabilities(content, clientExt->client);
|
||||
content->setUidGid(content, clientExt->client);
|
||||
content->setCapabilities(content, clientExt->client);
|
||||
content->runChildProcessor(content, clientExt->client);
|
||||
std::string validStr =
|
||||
"{\"bundleName\":\"validName\",\"identityID\":\"135\",\"uID\":999,\"gID\":888,\"capability\":[0, 1, 5]}";
|
||||
int ret = SplitMessage(validStr.c_str(), validStr.length(), &liteClient->message);
|
||||
EXPECT_EQ(ret, 0);
|
||||
|
||||
EXPECT_EQ(content->setProcessName(content, &liteClient->client, (char*)longProcName.c_str(),
|
||||
longProcNameLen), 0);
|
||||
EXPECT_EQ(content->setKeepCapabilities(content, &liteClient->client), 0);
|
||||
EXPECT_EQ(content->setUidGid(content, &liteClient->client), 0);
|
||||
EXPECT_EQ(content->setCapabilities(content, &liteClient->client), 0);
|
||||
content->runChildProcessor(content, &liteClient->client);
|
||||
free(liteClient);
|
||||
GTEST_LOG_(INFO) << "SetContentFunctionTest_001 end";
|
||||
}
|
||||
} // namespace OHOS
|
@ -179,7 +179,7 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_004, TestSize.Level0)
|
||||
}
|
||||
client->property.flags = 0;
|
||||
|
||||
char* argv[] = {(char*)"AppSpawnStandardTest4", (char*)"test4"};
|
||||
char* argv[] = {const_cast<char*>("AppSpawnStandardTest4"), const_cast<char*>("test4")};
|
||||
int argc = sizeof(argv)/sizeof(argv[0]);
|
||||
|
||||
EXPECT_EQ(GetAppSpawnClientFromArg(argc, argv, client), -1);
|
||||
|
Loading…
Reference in New Issue
Block a user