diff --git a/README.md b/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..3f36b4e256ebd1f263105fd89e1096a406a226a8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# Startup
+
+- [Introduction](#section11660541593)
+- [Directory Structure](#section161941989596)
+- [Repositories Involved](#section1371113476307)
+
+## Introduction
+
+Appspawn is responsible for creating application process and setting process information function.
+
+## Directory Structure
+
+```
+base/startup/appspawn_standard
+├── include # include directory
+├── parameter # system parameters
+├── src # source code
+│ └── socket # encapsulation of socket basic library
+└── test # test code
+```
+
+## Repositories Involved
+
+Startup subsystem
+
+hmf/startup/syspara\_lite
+
+**hmf/startup/appspawn_standard**
+
+hmf/startup/appspawn\_lite
+
+hmf/startup/bootstrap\_lite
+
+hmf/startup/startup
+
+hmf/startup/systemrestore
+
diff --git a/include/appspawn_server.h b/include/appspawn_server.h
index f914d45ed41888fc78f6eb42a3498bbaf5acf8bf..c73cf79fa9fa00cf026a1a9e3f403ae67b695ce2 100644
--- a/include/appspawn_server.h
+++ b/include/appspawn_server.h
@@ -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,18 +128,32 @@ 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_{};
+ std::string socketName_ {};
std::shared_ptr socket_ = nullptr;
- std::mutex mut_{};
- mutable std::condition_variable dataCond_{};
- std::queue> appQueue_{};
+ std::mutex mut_ {};
+ mutable std::condition_variable dataCond_ {};
+ std::queue> appQueue_ {};
std::function propertyHandler_ = nullptr;
std::function errHandlerHook_ = nullptr;
- bool isRunning_{};
+ bool isRunning_ {};
};
-
} // namespace AppSpawn
} // namespace OHOS
diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp
index 8dd64868a4f897f8bdd70a0dc1a981553fbe902d..c5071b053ba84e05256d964d8e1b3dc8fa4fac79 100644
--- a/src/appspawn_server.cpp
+++ b/src/appspawn_server.cpp
@@ -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);
- msg->Response(-EINVAL);
- continue;
- }
-
- if (strlen(appProperty->processName) == 0) {
- HiLog::Error(LABEL, "process name length is 0");
+ if (!CheckAppProperty(appProperty)) {
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
diff --git a/src/main.cpp b/src/main.cpp
index b6bb8a587e4f5e70c1dabc31ba1ad7246059bb4d..905bfec6243470c831daa686f4df0b6595b8a16f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -18,7 +18,7 @@
#include "appspawn_server.h"
#include "hilog/log.h"
-int main(int argc, char *const argv[])
+int main(int argc, char* const argv[])
{
if (argc > 0) {
// calculate child process long name size
diff --git a/src/socket/appspawn_socket.cpp b/src/socket/appspawn_socket.cpp
index 2e11106fd3acf8884f20f6817133f7dd16d24d89..1eb2362b413d74d9ba8b958f6640268758f1cf23 100755
--- a/src/socket/appspawn_socket.cpp
+++ b/src/socket/appspawn_socket.cpp
@@ -130,7 +130,7 @@ int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len)
ssize_t written = 0;
ssize_t remain = static_cast(len);
const uint8_t *offset = reinterpret_cast(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)) {
diff --git a/test/mock/include/main_thread.h b/test/mock/include/main_thread.h
index 6c503be051555fb68cfc33349391d76bb8f3bd92..1ebc490e244433613ec2c2b1493e48290163ab8c 100644
--- a/test/mock/include/main_thread.h
+++ b/test/mock/include/main_thread.h
@@ -18,9 +18,7 @@
namespace OHOS {
namespace AppExecFwk {
-
-class MainThread {
-
+class MainThread {
public:
MainThread() = default;
virtual ~MainThread() = default;
diff --git a/test/mock/include/mock_client_socket.h b/test/mock/include/mock_client_socket.h
index 659087568c1a5da8ac023ff08845d69782157dbc..0a9bb3a183248f723e7605cae6e3103905fb7111 100644
--- a/test/mock/include/mock_client_socket.h
+++ b/test/mock/include/mock_client_socket.h
@@ -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
diff --git a/test/mock/include/mock_server_socket.h b/test/mock/include/mock_server_socket.h
index 5e16784157c8e6ec129114bdd3d445e41e8fee1c..3cdbf36fac9cf36db77dbe32f3d5aa5707100842 100644
--- a/test/mock/include/mock_server_socket.h
+++ b/test/mock/include/mock_server_socket.h
@@ -164,6 +164,5 @@ public:
private:
std::mutex mutex_;
};
-
} // namespace AppSpawn
} // namespace OHOS
diff --git a/test/mock/src/main_thread.cpp b/test/mock/src/main_thread.cpp
index 8ca7af851cdc87b2f3a3ebd473818b80e8297065..da611e2f8efff728ba4cdbc43f3b2b410e05213a 100644
--- a/test/mock/src/main_thread.cpp
+++ b/test/mock/src/main_thread.cpp
@@ -25,6 +25,5 @@ void MainThread::Start()
{
HiLog::Info(LABEL, "Start");
}
-
} // namespace AppExecFwk
} // namespace OHOS
diff --git a/test/mock/src/server_socket.cpp b/test/mock/src/server_socket.cpp
index 4f443907abffda8d7da987656a4784838cfc7524..2ffd30e4ff84d19c976eaf1e685a0bfb15dc7b12 100644
--- a/test/mock/src/server_socket.cpp
+++ b/test/mock/src/server_socket.cpp
@@ -89,6 +89,5 @@ int ServerSocket::WaitForConnection()
HiLog::Info(LABEL, "WaitForConnection");
return 0;
}
-
} // namespace AppSpawn
} // namespace OHOS
diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn
index f23568715f0ec133b510da0989cf73765f2a4e58..6a8bd078ca4114f0cfed122b530d4d49de3e75ee 100644
--- a/test/moduletest/BUILD.gn
+++ b/test/moduletest/BUILD.gn
@@ -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",
diff --git a/test/moduletest/appspawn_mst_test.cpp b/test/moduletest/appspawn_module_test.cpp
similarity index 89%
rename from test/moduletest/appspawn_mst_test.cpp
rename to test/moduletest/appspawn_module_test.cpp
index 78a665e777b2cd57da1f6b4c528633db5f40d502..ff487b825094f403190d307c1eb10dbd9a7d2aa6 100644
--- a/test/moduletest/appspawn_mst_test.cpp
+++ b/test/moduletest/appspawn_module_test.cpp
@@ -13,21 +13,23 @@
* limitations under the License.
*/
-#include "gtest/gtest.h"
-#include "hilog/log.h"
-#include
-#include
#include
+#include
+#include
+#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 &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 &gids)
bool checkGids(const int32_t &pid, const AppSpawnStartMsg ¶ms)
{
-
// Get Gids
std::vector gids;
std::size_t gCount = getGids(pid, gids);
@@ -184,7 +184,6 @@ bool checkGids(const int32_t &pid, const AppSpawnStartMsg ¶ms)
bool checkGidsCount(const int32_t &pid, const AppSpawnStartMsg ¶ms)
{
-
// Get GidsCount
std::vector gids;
std::size_t gCount = getGids(pid, gids);
@@ -224,11 +223,9 @@ bool checkProcName(const int32_t &pid, const AppSpawnStartMsg ¶ms)
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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 = std::make_shared();
- std::shared_ptr appSpawnSocket = std::make_shared();
+ std::unique_ptr appSpawnClient = std::make_unique();
+ std::shared_ptr appSpawnSocket = std::make_shared();
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
diff --git a/test/unittest/app_spawn_server_test/app_spawn_server_mock_test.cpp b/test/unittest/app_spawn_server_test/app_spawn_server_mock_test.cpp
index 2827cfffedef7af72f78aece3a52b176ef41bf45..ebe9962049719481ac1279aae9d49a2351c81206 100644
--- a/test/unittest/app_spawn_server_test/app_spawn_server_mock_test.cpp
+++ b/test/unittest/app_spawn_server_test/app_spawn_server_mock_test.cpp
@@ -40,17 +40,15 @@ public:
public:
static constexpr int TEST_WAIT_TIME = 50 * 1000; // 50 ms
protected:
- std::unique_ptr appSpawnServer_;
- std::shared_ptr mockServerSocket_;
+ std::unique_ptr appSpawnServer_ = nullptr;
+ std::shared_ptr mockServerSocket_ = nullptr;
};
void AppSpawnServerMockTest::SetUpTestCase()
-{
-}
+{}
void AppSpawnServerMockTest::TearDownTestCase()
-{
-}
+{}
void AppSpawnServerMockTest::SetUp()
{
diff --git a/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp b/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp
index f0f4ffc3ff15c8622e4b9b5c93f7f0747e03202d..7deb9969d1615c4c6a92a010642c2345522acf23 100644
--- a/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp
+++ b/test/unittest/app_spawn_server_test/app_spawn_server_override_test.cpp
@@ -38,16 +38,14 @@ public:
public:
static constexpr int TEST_WAIT_TIME = 50 * 1000; // 50 ms
protected:
- std::unique_ptr appSpawnServer_;
+ std::unique_ptr 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));