!643 FIX:修改静态告警

Merge pull request !643 from cheng_jinsong/0525_codeCheck
This commit is contained in:
openharmony_ci 2023-05-26 13:26:10 +00:00 committed by Gitee
commit 9cdcd21fe9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 135 additions and 128 deletions

View File

@ -187,7 +187,7 @@ void RecordRenderProcessExitedStatus(pid_t pid, int status)
DumpRenderProcessExitedMap();
}
int GetRenderProcessTerminationStatus(int32_t pid, int *status)
static int GetRenderProcessTerminationStatus(int32_t pid, int *status)
{
if (status == nullptr) {
return -1;

View File

@ -78,7 +78,7 @@ int main(int argc, char *const argv[])
bundleName = argv[i];
} else if (strcmp(argv[i], "-C") == 0 && ((i + 1) < argc)) {
i++;
cmd= argv[i];
cmd = argv[i];
}
}

View File

@ -1088,13 +1088,6 @@ HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_33, TestSize.Level0)
SUCCEED();
}
/**
* @tc.name: App_Spawn_Sandbox_34
* @tc.desc: parse and mount HspList
* @tc.type: FUNC
* @tc.require:issueI6798L
* @tc.author:
*/
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_34, TestSize.Level0)
{
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_34 start";
@ -1127,114 +1120,128 @@ HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_34, TestSize.Level0)
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_34 end";
}
/**
* @tc.name: App_Spawn_Sandbox_35
* @tc.desc: validate json format of HspList
* @tc.type: FUNC
* @tc.require:issueI6798L
* @tc.author:
*/
static void InvalidJsonTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void NoBundleTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{ \
\"modules\":[\"module1\", \"module2\"], \
\"versions\":[\"v10001\", \"v10002\"] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void NoModulesTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"versions\":[\"v10001\", \"v10002\"] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void NoVersionsTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void ListSizeNotSameTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\"], \
\"versions\":[\"v10001\", \"v10002\"] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void ValueTypeIsNotArraryTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": 1001 \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void ElementTypeIsNotStringTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": [1001, 1002] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void ElementTypeIsNotSameTestSN(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
// element type is not same, string + number
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": [\"v10001\", 1002] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
static void ElementTypeIsNotSameTestNS(ClientSocket::AppProperty* appProperty, std::string &testBundle)
{
// element type is not same, number + string
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": [1001, \"v10002\"] \
}";
appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
EXPECT_NE(0, ret);
}
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_35, TestSize.Level0)
{
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_35 start";
ClientSocket::AppProperty *m_appProperty = GetAppProperty();
ClientSocket::AppProperty *appProperty = GetAppProperty();
const char *strl1 = "/mnt/sandbox/test.bundle1";
std::string testBundle = strl1;
{ // invalid json
char hspListStr[] = "{";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // no bundles
char hspListStr[] = "{ \
\"modules\":[\"module1\", \"module2\"], \
\"versions\":[\"v10001\", \"v10002\"] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // no modules
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"versions\":[\"v10001\", \"v10002\"] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // no versions
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // list size not same
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\"], \
\"versions\":[\"v10001\", \"v10002\"] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // value type is not arrary
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": 1001 \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // element type is not string
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": [1001, 1002] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // element type is not same, string + number
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": [\"v10001\", 1002] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
{ // element type is not same, number + string
char hspListStr[] = "{ \
\"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
\"modules\":[\"module1\", \"module2\"], \
\"versions\": [1001, \"v10002\"] \
}";
m_appProperty->hspList = {strlen(hspListStr), 0, hspListStr};
int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
EXPECT_NE(0, ret);
}
m_appProperty->hspList = {};
InvalidJsonTest(appProperty, testBundle);
NoBundleTest(appProperty, testBundle);
NoModulesTest(appProperty, testBundle);
NoVersionsTest(appProperty, testBundle);
ListSizeNotSameTest(appProperty, testBundle);
ValueTypeIsNotArraryTest(appProperty, testBundle);
ElementTypeIsNotStringTest(appProperty, testBundle);
ElementTypeIsNotSameTestSN(appProperty, testBundle);
ElementTypeIsNotSameTestNS(appProperty, testBundle);
appProperty->hspList = {};
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_35 end";
}
/**
* @tc.name: App_Spawn_Sandbox_36
* @tc.desc: validate bundlemodule and version in hspList
* @tc.type: FUNC
* @tc.require:issueI6798L
* @tc.author:
*/
HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0)
{
GTEST_LOG_(INFO) << "App_Spawn_Sandbox_36 start";
@ -1352,4 +1359,4 @@ HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_38, TestSize.Level0)
EXPECT_EQ(0, ret);
APPSPAWN_LOGI("App_Spawn_Sandbox_38 end");
}
} // namespace OHOS
} // namespace OHOS

View File

@ -58,10 +58,10 @@ void SignalHandler(const struct signalfd_siginfo *siginfo);
}
#endif
int MakeDir(const char *dir, mode_t mode)
static int MakeDir(const char *dir, mode_t mode)
{
int rc = -1;
if (dir == NULL || *dir == '\0') {
if (dir == nullptr || *dir == '\0') {
errno = EINVAL;
return rc;
}
@ -72,18 +72,18 @@ int MakeDir(const char *dir, mode_t mode)
return 0;
}
int MakeDirRecursive(const char *dir, mode_t mode)
static int MakeDirRecursive(const char *dir, mode_t mode)
{
int rc = -1;
char buffer[PATH_MAX] = {0};
const char *p = NULL;
if (dir == NULL || *dir == '\0') {
const char *p = nullptr;
if (dir == nullptr || *dir == '\0') {
errno = EINVAL;
return rc;
}
p = dir;
const char *slash = strchr(dir, '/');
while (slash != NULL) {
while (slash != nullptr) {
int gap = slash - p;
p = slash + 1;
if (gap == 0) {
@ -97,7 +97,7 @@ int MakeDirRecursive(const char *dir, mode_t mode)
return -1;
}
rc = MakeDir(buffer, mode);
if (rc < 0){
if (rc < 0) {
return rc;
}
slash = strchr(p, '/');
@ -105,14 +105,14 @@ int MakeDirRecursive(const char *dir, mode_t mode)
return MakeDir(dir, mode);
}
void CheckAndCreateDir(const char *fileName)
static void CheckAndCreateDir(const char *fileName)
{
printf("create path %s\n", fileName);
if (fileName == NULL || *fileName == '\0') {
if (fileName == nullptr || *fileName == '\0') {
return;
}
char *path = strndup(fileName, strrchr(fileName, '/') - fileName);
if (path == NULL) {
if (path == nullptr) {
return;
}
if (access(path, F_OK) == 0) {
@ -195,7 +195,7 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_002, TestSize.Level0)
if (strcpy_s(client->property.renderCmd, APP_RENDER_CMD_MAX_LEN, "xxx") != 0) {
GTEST_LOG_(INFO) << "strcpy_s failed";
}
client->property.hspList = {0, 0, NULL};
client->property.hspList = {0, 0, nullptr};
AppSpawnContent *content = AppSpawnCreateContent("AppSpawn", longProcName, longProcNameLen, 1);
content->loadExtendLib = LoadExtendLib;
@ -301,7 +301,7 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_003_1, TestSize.Level0)
int argc = sizeof(argv)/sizeof(argv[0]);
EXPECT_EQ(0, GetAppSpawnClientFromArg(argc, argv, &client));
}
{ // hsp length is null
{ // hsp length is nullptr
char arg4[] = "1:1:1:1:1:1:1:1:1:2:1000:1000:ohos.samples:ohos.samples.ecg:"
"default:671201800:system_core:default:0:671201800";
char arg6[] = "0123456789";
@ -317,7 +317,7 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_003_1, TestSize.Level0)
int argc = sizeof(argv)/sizeof(argv[0]);
EXPECT_EQ(-1, GetAppSpawnClientFromArg(argc, argv, &client));
}
{ // hsp length is non-zero, but content is null
{ // hsp length is non-zero, but content is nullptr
char arg4[] = "1:1:1:1:1:1:1:1:1:2:1000:1000:ohos.samples:ohos.samples.ecg:"
"default:671201800:system_core:default:0:671201800";
char arg5[] = "10";
@ -519,7 +519,7 @@ static AppSpawnContentExt *TestClient(int flags,
content->content.loadExtendLib = LoadExtendLib;
content->content.runChildProcessor = RunChildProcessor;
content->flags |= (flags & APP_COLD_BOOT) ? FLAGS_ON_DEMAND : 0;
// test null
// test nullptr
StreamServerTask *task = reinterpret_cast<StreamServerTask *>(content->server);
task->incommingConnect(nullptr, nullptr);
task->incommingConnect(LE_GetDefaultLoop(), nullptr);
@ -675,7 +675,7 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_08, TestSize.Level0)
GTEST_LOG_(INFO) << "App_Spawn_Standard_08 start";
AppSpawnClientExt client = {};
AppParameter param = {};
{ // buff is null
{ // buff is nullptr
bool ret = ReceiveRequestData(nullptr, &client, nullptr, sizeof(param));
EXPECT_FALSE(ret);
}

View File

@ -72,7 +72,7 @@ void *DlsymStub(void *handle, const char *symbol)
{
UNUSED(handle);
if (strcmp(symbol, "InitEnvironmentParam") == 0) {
return (void *)InitEnvironmentParamStub;
return reinterpret_cast<void *>(InitEnvironmentParamStub);
}
return nullptr;
}

View File

@ -16,7 +16,7 @@
#include "json_utils.h"
#include "appspawn_server.h"
#include <errno.h>
#include <cerrno>
#include <sstream>
#include <fstream>

View File

@ -116,7 +116,7 @@ nlohmann::json SandboxUtils::GetNamespaceJsonConfig(void)
void SandboxUtils::StoreJsonConfig(nlohmann::json &appSandboxConfig)
{
SandboxUtils::appSandboxConfig_.push_back(appSandboxConfig);;
SandboxUtils::appSandboxConfig_.push_back(appSandboxConfig);
}
std::vector<nlohmann::json> &SandboxUtils::GetJsonConfig()