!20 fix appspawn codex

Merge pull request !20 from blackleon/master_check
This commit is contained in:
openharmony_ci 2021-09-10 10:20:27 +00:00 committed by Gitee
commit 4510edecbd
13 changed files with 186 additions and 171 deletions

37
README.md Normal file
View File

@ -0,0 +1,37 @@
# Startup<a name="EN-US_TOPIC_0000001078883578"></a>
- [Introduction](#section11660541593)
- [Directory Structure](#section161941989596)
- [Repositories Involved](#section1371113476307)
## Introduction<a name="section11660541593"></a>
Appspawn is responsible for creating application process and setting process information function.
## Directory Structure<a name="section161941989596"></a>
```
base/startup/appspawn_standard
├── include # include directory
├── parameter # system parameters
├── src # source code
│ └── socket # encapsulation of socket basic library
└── test # test code
```
## Repositories Involved<a name="section1371113476307"></a>
Startup subsystem
hmf/startup/syspara\_lite
**hmf/startup/appspawn_standard**
hmf/startup/appspawn\_lite
hmf/startup/bootstrap\_lite
hmf/startup/startup
hmf/startup/systemrestore

View File

@ -25,7 +25,6 @@
namespace OHOS {
namespace AppSpawn {
class AppSpawnServer {
public:
/**
@ -101,7 +100,7 @@ private:
/**
* Sets keep capabilities.
*/
int32_t SetKeepCapabilities();
int32_t SetKeepCapabilities(uint32_t uid);
/**
* Sets the uid and gid of an application process.
@ -129,6 +128,21 @@ private:
bool SetAppProcProperty(int connectFd, const ClientSocket::AppProperty *appProperty, char *longProcName,
int64_t longProcNameLen, const int32_t fd[FDLEN2]);
/**
* Notify
*/
void NotifyResToParentProc(const int32_t fd, const int32_t value);
/**
* Special app process property.
*/
void SpecialHandle(ClientSocket::AppProperty *appProperty);
/**
* Check app process property.
*/
bool CheckAppProperty(const ClientSocket::AppProperty *appProperty);
private:
const std::string deviceNull_ = "/dev/null";
std::string socketName_{};
@ -140,7 +154,6 @@ private:
std::function<void(const std::string &)> errHandlerHook_ = nullptr;
bool isRunning_{};
};
} // namespace AppSpawn
} // namespace OHOS

View File

@ -32,7 +32,6 @@
namespace OHOS {
namespace AppSpawn {
namespace {
constexpr int32_t ERR_PIPE_FAIL = -100;
constexpr int32_t MAX_LEN_SHORT_NAME = 16;
@ -51,7 +50,7 @@ static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "AppSpawnServer"};
extern "C" {
#endif
static void SignalHandler(int) /* signal_number */
static void SignalHandler([[maybe_unused]] int sig)
{
pid_t pid;
int status;
@ -154,7 +153,6 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen)
HiLog::Error(LABEL, "AppSpawnServer::Failed to register server socket");
return false;
}
std::thread(&AppSpawnServer::ConnectionPeer, this).detach();
while (isRunning_) {
@ -164,82 +162,41 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen)
appQueue_.pop();
int connectFd = msg->GetConnectFd();
ClientSocket::AppProperty *appProperty = msg->GetMsg();
// check appProperty
if (appProperty == nullptr) {
HiLog::Error(LABEL, "appProperty is nullptr");
continue;
}
if (appProperty->gidCount > ClientSocket::MAX_GIDS) {
HiLog::Error(LABEL, "gidCount error: %{public}u", appProperty->gidCount);
if (!CheckAppProperty(appProperty)) {
msg->Response(-EINVAL);
continue;
}
if (strlen(appProperty->processName) == 0) {
HiLog::Error(LABEL, "process name length is 0");
msg->Response(-EINVAL);
continue;
}
InstallSigHandler();
int32_t fd[FDLEN2] = {FD_INIT_VALUE, FD_INIT_VALUE};
int32_t buff = 0;
if (pipe(fd) == -1) {
HiLog::Error(LABEL, "create pipe fail");
HiLog::Error(LABEL, "create pipe fail, errno = %{public}d", errno);
msg->Response(ERR_PIPE_FAIL);
continue;
}
InstallSigHandler();
pid_t pid = fork();
if (pid < 0) {
HiLog::Error(LABEL, "AppSpawnServer::Failed to fork new process, errno = %{public}d", errno);
// close pipe fds
close(fd[0]);
close(fd[1]);
msg->Response(-errno);
continue;
}
if (pid == 0) {
// special handle bundle name "com.ohos.photos" and "com.ohos.camera"
if ((strcmp(appProperty->processName, BUNDLE_NAME_CAMERA.data()) == 0) ||
(strcmp(appProperty->processName, BUNDLE_NAME_PHOTOS.data()) == 0)) {
if (appProperty->gidCount < MAX_GIDS) {
appProperty->gidTable[appProperty->gidCount] = GID_MEDIA;
appProperty->gidCount++;
} else {
HiLog::Info(LABEL, "gidCount out of bounds !");
}
}
} else if (pid == 0) {
SpecialHandle(appProperty);
return SetAppProcProperty(connectFd, appProperty, longProcName, longProcNameLen, fd);
}
// parent process
// close write end
close(fd[1]);
// wait child process result
read(fd[0], &buff, sizeof(buff));
// close read end
read(fd[0], &buff, sizeof(buff)); // wait child process resutl
close(fd[0]);
close(fd[1]);
HiLog::Info(LABEL, "child process init %{public}s", (buff == ERR_OK) ? "success" : "fail");
if (buff == ERR_OK) {
// send pid to AppManagerService
msg->Response(pid);
} else {
// send error code to AppManagerService
msg->Response(buff);
}
// close socket connection
socket_->CloseConnection(connectFd);
(buff == ERR_OK) ? msg->Response(pid) : msg->Response(buff); // response to AppManagerService
socket_->CloseConnection(connectFd); // close socket connection
HiLog::Debug(LABEL, "AppSpawnServer::parent process create app finish, pid = %{public}d", pid);
}
return false;
}
@ -291,19 +248,6 @@ int32_t AppSpawnServer::SetProcessName(
return ERR_OK;
}
/**
* Set keep capabilities.
*/
int32_t AppSpawnServer::SetKeepCapabilities()
{
// keep capabilities when uid changed.
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) {
HiLog::Error(LABEL, "set keepcaps failed: %{public}s", strerror(errno));
return (-errno);
}
return ERR_OK;
}
int32_t AppSpawnServer::SetUidGid(
const uint32_t uid, const uint32_t gid, const uint32_t *gitTable, const uint32_t gidCount)
{
@ -421,73 +365,103 @@ bool AppSpawnServer::SetAppProcProperty(int connectFd, const ClientSocket::AppPr
{
pid_t newPid = getpid();
HiLog::Debug(LABEL, "AppSpawnServer::Success to fork new process, pid = %{public}d", newPid);
// close socket connection in child process
// close socket connection and peer socket in child process
socket_->CloseConnection(connectFd);
// close peer socket
socket_->CloseServerMonitor();
// close read end
close(fd[0]);
close(fd[0]); // close read fd
UninstallSigHandler();
// set process name
int32_t ret = ERR_OK;
ret = SetProcessName(longProcName, longProcNameLen, appProperty->processName, strlen(appProperty->processName) + 1);
ret = SetKeepCapabilities(appProperty->uid);
if (FAILED(ret)) {
HiLog::Error(LABEL, "SetProcessName error, ret %{public}d", ret);
write(fd[1], &ret, sizeof(ret));
close(fd[1]);
NotifyResToParentProc(fd[1], ret);
return false;
}
// set keep capabilities when user not root.
if (appProperty->uid != 0) {
ret = SetKeepCapabilities();
if (FAILED(ret)) {
HiLog::Error(LABEL, "SetKeepCapabilities error, ret %{public}d", ret);
write(fd[1], &ret, sizeof(ret));
close(fd[1]);
return false;
}
ret = SetProcessName(longProcName, longProcNameLen, appProperty->processName, strlen(appProperty->processName) + 1);
if (FAILED(ret)) {
NotifyResToParentProc(fd[1], ret);
return false;
}
#ifdef GRAPHIC_PERMISSION_CHECK
// set uid gid
ret = SetUidGid(appProperty->uid, appProperty->gid, appProperty->gidTable, appProperty->gidCount);
if (FAILED(ret)) {
HiLog::Error(LABEL, "SetUidGid error, ret %{public}d", ret);
write(fd[1], &ret, sizeof(ret));
close(fd[1]);
NotifyResToParentProc(fd[1], ret);
return false;
}
#endif
// set file descriptors
ret = SetFileDescriptors();
if (FAILED(ret)) {
HiLog::Error(LABEL, "SetFileDescriptors error, ret %{public}d", ret);
write(fd[1], &ret, sizeof(ret));
close(fd[1]);
NotifyResToParentProc(fd[1], ret);
return false;
}
// set capabilities
ret = SetCapabilities();
if (FAILED(ret)) {
HiLog::Error(LABEL, "SetCapabilities error, ret %{public}d", ret);
write(fd[1], &ret, sizeof(ret));
close(fd[1]);
NotifyResToParentProc(fd[1], ret);
return false;
}
// child process init success, send to father process
write(fd[1], &ret, sizeof(ret));
close(fd[1]);
// start app process
// notify success to father process and start app process
NotifyResToParentProc(fd[1], ret);
AppExecFwk::MainThread::Start();
HiLog::Error(LABEL, "Failed to start process, pid = %{public}d", newPid);
return false;
}
void AppSpawnServer::NotifyResToParentProc(const int32_t fd, const int32_t value)
{
write(fd, &value, sizeof(value));
close(fd);
}
void AppSpawnServer::SpecialHandle(ClientSocket::AppProperty *appProperty)
{
// special handle bundle name "com.ohos.photos" and "com.ohos.camera"
if ((strcmp(appProperty->processName, BUNDLE_NAME_CAMERA.data()) == 0) ||
(strcmp(appProperty->processName, BUNDLE_NAME_PHOTOS.data()) == 0)) {
if (appProperty->gidCount < MAX_GIDS) {
appProperty->gidTable[appProperty->gidCount] = GID_MEDIA;
appProperty->gidCount++;
} else {
HiLog::Info(LABEL, "gidCount out of bounds !");
}
}
}
int32_t AppSpawnServer::SetKeepCapabilities(uint32_t uid)
{
// set keep capabilities when user not root.
if (uid != 0) {
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) {
HiLog::Error(LABEL, "set keepcaps failed: %{public}s", strerror(errno));
return (-errno);
}
}
return ERR_OK;
}
bool AppSpawnServer::CheckAppProperty(const ClientSocket::AppProperty *appProperty)
{
if (appProperty == nullptr) {
HiLog::Error(LABEL, "appProperty is nullptr");
return false;
}
if (appProperty->gidCount > ClientSocket::MAX_GIDS) {
HiLog::Error(LABEL, "gidCount error: %{public}u", appProperty->gidCount);
return false;
}
if (strlen(appProperty->processName) == 0) {
HiLog::Error(LABEL, "process name length is 0");
return false;
}
return true;
}
} // namespace AppSpawn
} // namespace OHOS

View File

@ -130,7 +130,7 @@ int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len)
ssize_t written = 0;
ssize_t remain = static_cast<ssize_t>(len);
const uint8_t *offset = reinterpret_cast<const uint8_t *>(buf);
for (ssize_t wLen; remain > 0; offset += wLen, remain -= wLen, written += wLen) {
for (ssize_t wLen = 0; remain > 0; offset += wLen, remain -= wLen, written += wLen) {
wLen = write(socketFd, offset, remain);
HiLog::Debug(LABEL, "socket fd %d, wLen %zd", socketFd, wLen);
if ((wLen <= 0) && (errno != EINTR)) {

View File

@ -18,9 +18,7 @@
namespace OHOS {
namespace AppExecFwk {
class MainThread {
class MainThread {
public:
MainThread() = default;
virtual ~MainThread() = default;

View File

@ -18,7 +18,6 @@
namespace OHOS {
namespace AppSpawn {
class MockClientSocket : public ClientSocket {
public:
virtual ~MockClientSocket() = default;
@ -31,6 +30,5 @@ public:
MOCK_METHOD2(WriteSocketMessage, int32_t(const void *buf, int32_t len));
MOCK_METHOD2(ReadSocketMessage, int32_t(void *buf, int32_t len));
};
} // namespace AppSpawn
} // namespace OHOS

View File

@ -164,6 +164,5 @@ public:
private:
std::mutex mutex_;
};
} // namespace AppSpawn
} // namespace OHOS

View File

@ -25,6 +25,5 @@ void MainThread::Start()
{
HiLog::Info(LABEL, "Start");
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -89,6 +89,5 @@ int ServerSocket::WaitForConnection()
HiLog::Info(LABEL, "WaitForConnection");
return 0;
}
} // namespace AppSpawn
} // namespace OHOS

View File

@ -17,7 +17,7 @@ import("//build/test.gni")
ohos_moduletest("AppSpawnModuleTest") {
module_out_path = "${module_output_path}"
sources = [ "${appspawn_path}/test/moduletest/appspawn_mst_test.cpp" ]
sources = [ "${appspawn_path}/test/moduletest/appspawn_module_test.cpp" ]
include_dirs = [
"//utils/native/base/include",

View File

@ -13,21 +13,23 @@
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "hilog/log.h"
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdio>
#include "gtest/gtest.h"
#include "securec.h"
#include "app_spawn_client.h"
#include "hilog/log.h"
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::AppExecFwk;
using namespace OHOS::HiviewDFX;
namespace OHOS {
namespace AppSpawn {
static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "AppSpawnMST"};
namespace {
@ -49,7 +51,6 @@ const char *DELIMITER_NEWLINE = "\n";
char buffer[BUFFER_SIZE];
int32_t newPid = 0;
int32_t retryCount = 0;
} // namespace
bool checkFileIsExists(const char *filepath)
@ -152,7 +153,7 @@ std::size_t getGids(const int32_t &pid, std::vector<int32_t> &gids)
groupsPtr = groupsPtr + GROUPS_POSITION_MOVE;
}
// Get the row content of Groups
char *saveptr = NULL;
char *saveptr = nullptr;
char *line = strtok_r(groupsPtr, DELIMITER_NEWLINE, &saveptr);
if (line == nullptr || strlen(line) > BUFFER_SIZE) {
HiLog::Error(LABEL, "get Groups line info failed.");
@ -171,7 +172,6 @@ std::size_t getGids(const int32_t &pid, std::vector<int32_t> &gids)
bool checkGids(const int32_t &pid, const AppSpawnStartMsg &params)
{
// Get Gids
std::vector<int32_t> gids;
std::size_t gCount = getGids(pid, gids);
@ -184,7 +184,6 @@ bool checkGids(const int32_t &pid, const AppSpawnStartMsg &params)
bool checkGidsCount(const int32_t &pid, const AppSpawnStartMsg &params)
{
// Get GidsCount
std::vector<int32_t> gids;
std::size_t gCount = getGids(pid, gids);
@ -224,11 +223,9 @@ bool checkProcName(const int32_t &pid, const AppSpawnStartMsg &params)
return CHECK_OK;
}
HiLog::Error(LABEL, " procName=%{public}s, params.procName=%{public}s.", procName, params.procName.c_str());
} else {
HiLog::Error(LABEL, "Getting procName failed.");
}
pclose(fp);
return CHECK_ERROR;
@ -323,7 +320,10 @@ void AppSpawnModuleTest::TearDownTestCase()
void AppSpawnModuleTest::SetUp()
{
newPid = 0;
EXPECT_EQ(memset_s(buffer, sizeof(buffer), 0x00, BUFFER_SIZE), EOK);
auto ret = memset_s(buffer, sizeof(buffer), 0x00, BUFFER_SIZE);
if (ret != EOK) {
HiLog::Error(LABEL, "memset_s is failed.");
}
}
void AppSpawnModuleTest::TearDown()
@ -359,8 +359,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_listen_001, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_listen_002, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_listen_002 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
@ -384,8 +384,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_listen_002, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_fork_001, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_fork_001 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-fork_001", "soPath"};
@ -414,8 +414,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_fork_001, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_fork_002, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_fork_002 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-fork_002", "soPath"};
@ -444,8 +444,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_fork_002, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_001, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_001 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_001", "soPath"};
@ -476,8 +476,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_001, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_002, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_002 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_002", "soPath"};
@ -508,8 +508,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_002, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_003, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_003 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_003", "soPath"};
@ -540,8 +540,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_003, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_004, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_004 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_004", "soPath"};
@ -572,8 +572,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_004, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_005, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_005 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_005", "soPath"};
@ -604,8 +604,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_005, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_006, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_006 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_006", "soPath"};
@ -636,8 +636,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_006, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_007, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_007 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_007", "soPath"};
@ -668,8 +668,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_007, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_008, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setUid_008 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setUid_008", "soPath"};
@ -700,8 +700,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setUid_008, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setProcName_001, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setProcName_001 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setProcName_001", "soPath"};
@ -733,8 +733,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setProcName_001, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setProcName_002, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_setProcName_002 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-setProcName_002", "soPath"};
@ -764,8 +764,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_setProcName_002, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_recycleProc_001, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_recycleProc_001 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-recycleProc_001", "soPath"};
@ -798,8 +798,8 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_recycleProc_001, TestSize.Level0)
HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_recycleProc_002, TestSize.Level0)
{
HiLog::Info(LABEL, "AppSpawn_HF_recycleProc_002 start");
std::shared_ptr<AppSpawnClient> appSpawnClient = std::make_shared<AppSpawnClient>();
std::shared_ptr<AppSpawnSocket> appSpawnSocket = std::make_shared<AppSpawnSocket>();
std::unique_ptr<AppSpawnClient> appSpawnClient = std::make_unique<AppSpawnClient>();
std::shared_ptr<AppExecFwk::AppSpawnSocket> appSpawnSocket = std::make_shared<AppExecFwk::AppSpawnSocket>();
appSpawnClient->SetSocket(appSpawnSocket);
EXPECT_EQ(ERR_OK, appSpawnClient->OpenConnection());
AppSpawnStartMsg params = {10003, 10004, {10003, 10004}, "processName-recycleProc_002", "soPath"};
@ -820,3 +820,5 @@ HWTEST_F(AppSpawnModuleTest, AppSpawn_HF_recycleProc_002, TestSize.Level0)
EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appSpawnClient->QueryConnectionState());
HiLog::Info(LABEL, "AppSpawn_HF_recycleProc_002 end");
}
} // namespace AppSpawn
} // namespace OHOS

View File

@ -40,17 +40,15 @@ public:
public:
static constexpr int TEST_WAIT_TIME = 50 * 1000; // 50 ms
protected:
std::unique_ptr<AppSpawnServer> appSpawnServer_;
std::shared_ptr<MockServerSocket> mockServerSocket_;
std::unique_ptr<AppSpawnServer> appSpawnServer_ = nullptr;
std::shared_ptr<MockServerSocket> mockServerSocket_ = nullptr;
};
void AppSpawnServerMockTest::SetUpTestCase()
{
}
{}
void AppSpawnServerMockTest::TearDownTestCase()
{
}
{}
void AppSpawnServerMockTest::SetUp()
{

View File

@ -38,16 +38,14 @@ public:
public:
static constexpr int TEST_WAIT_TIME = 50 * 1000; // 50 ms
protected:
std::unique_ptr<AppSpawnServer> appSpawnServer_;
std::unique_ptr<AppSpawnServer> appSpawnServer_ = nullptr;
};
void AppSpawnServerOverrideTest::SetUpTestCase()
{
}
{}
void AppSpawnServerOverrideTest::TearDownTestCase()
{
}
{}
void AppSpawnServerOverrideTest::SetUp()
{
@ -98,11 +96,11 @@ HWTEST_F(AppSpawnServerOverrideTest, App_Spawn_Server_Override_002, TestSize.Lev
{
GTEST_LOG_(INFO) << "App_Spawn_Server_Override_002 start";
char* longProcName = nullptr;
char *longProcName = nullptr;
int64_t longProcNameLen = sizeof(longProcName);
char processName[16] = "LongNameTest";
int32_t len = sizeof(processName);
EXPECT_EQ(-EINVAL, appSpawnServer_->SetProcessName(longProcName, longProcNameLen, processName, len));
GTEST_LOG_(INFO) << "App_Spawn_Server_Override_002 end";
@ -122,7 +120,7 @@ HWTEST_F(AppSpawnServerOverrideTest, App_Spawn_Server_Override_003, TestSize.Lev
char longProcName[20] = "longProcName";
int64_t longProcNameLen = sizeof(longProcName);
char* processName = nullptr;
char *processName = nullptr;
int32_t len = sizeof(processName);
EXPECT_EQ(-EINVAL, appSpawnServer_->SetProcessName(longProcName, longProcNameLen, processName, len));