提交 b0807d7b 编写于 作者: L laiguizhong

clean codecheck

Signed-off-by: Nlaiguizhong <laiguizhong@huawei.com>
Change-Id: I8b90c2438bc64636e3a5e5e6075ba801d554ada0
上级 371f660c
......@@ -13,8 +13,8 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <cerrno>
#include <cstdio>
#include "init_unittest.h"
#include "init.h"
#include "loop_event.h"
......
......@@ -71,6 +71,9 @@ HWTEST_F(CmdsUnitTest, TestCmdExecByName, TestSize.Level1)
DoCmdByName("mksandbox ", "system");
DoCmdByName("mksandbox ", "notsupport");
DoCmdByName("mksandbox ", "");
}
HWTEST_F(CmdsUnitTest, TestCmdExecByName1, TestSize.Level1)
{
DoCmdByName("timer_start ", "media_service|5000");
DoCmdByName("timer_stop ", "media_service");
DoCmdByName("exec ", "media_service");
......
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <cstdlib>
#include "init_cmds.h"
#include "init_group_manager.h"
#include "init_hashmap.h"
......@@ -397,6 +397,5 @@ HWTEST_F(InitGroupManagerUnitTest, TestProcessWatchEvent, TestSize.Level1)
ASSERT_EQ(ret, 0);
uint32_t event;
((WatcherTask *)watcher)->processEvent((WatcherHandle)watcher, 0, &event, service);
}
} // namespace init_ut
......@@ -52,6 +52,5 @@ HWTEST_F(InitRebootUnitTest, TestInitReboot, TestSize.Level1)
EXPECT_EQ(ret, 0);
ret = DoReboot(DEVICE_CMD_FREEZE);
EXPECT_EQ(ret, 0);
}
} // namespace init_ut
......@@ -73,6 +73,5 @@ HWTEST_F(MountUnitTest, TestGetBlockDevicePath, TestSize.Level1)
EXPECT_EQ(ret, -1);
ret = GetBlockDeviceByMountPoint("mountPoint", &fstab, devicename, sizeof(devicename));
EXPECT_EQ(ret, 0);
}
} // namespace init_ut
......@@ -16,7 +16,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <cstdlib>
#include "init_cmds.h"
#include "init_service.h"
#include "init_service_manager.h"
......@@ -24,6 +24,7 @@
#include "param_stub.h"
#include "init_utils.h"
#include "securec.h"
#include "init_group_manager.h"
using namespace testing::ext;
using namespace std;
......@@ -286,5 +287,6 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
HWTEST_F(ServiceUnitTest, TestClientDeinit, TestSize.Level1)
{
ClientDeinit();
HashMapDestory(GetInitWorkspace()->hashMap[0]);
}
} // namespace init_ut
......@@ -20,7 +20,6 @@
#include "param_stub.h"
#include "securec.h"
#define TEST_PATH_MOUNTCFG "/data/init_ut/mount_unitest/"
using namespace testing::ext;
using namespace std;
......@@ -39,7 +38,7 @@ HWTEST_F(InnerkitsUnitTest, ReadFstabFromFile_unitest, TestSize.Level1)
const std::string fstabFile1 = "/data/fstab.updater1";
fstab = ReadFstabFromFile(fstabFile1.c_str(), false);
EXPECT_EQ(fstab, nullptr);
const std::string fstabFile2 = TEST_PATH_MOUNTCFG"ReadFstabFromFile1.fstable";
const std::string fstabFile2 = "/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable";
fstab = ReadFstabFromFile(fstabFile2.c_str(), false);
EXPECT_NE(fstab, nullptr);
ParseFstabPerLine(const_cast<char *>("test"), fstab, true, nullptr);
......@@ -48,7 +47,7 @@ HWTEST_F(InnerkitsUnitTest, ReadFstabFromFile_unitest, TestSize.Level1)
HWTEST_F(InnerkitsUnitTest, FindFstabItemForPath_unitest, TestSize.Level1)
{
const std::string fstabFile1 = TEST_PATH_MOUNTCFG"ReadFstabFromFile1.fstable";
const std::string fstabFile1 = "/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable";
Fstab *fstab = nullptr;
fstab = ReadFstabFromFile(fstabFile1.c_str(), false);
ASSERT_NE(fstab, nullptr);
......@@ -79,7 +78,7 @@ HWTEST_F(InnerkitsUnitTest, FindFstabItemForPath_unitest, TestSize.Level1)
HWTEST_F(InnerkitsUnitTest, FindFstabItemForMountPoint_unitest, TestSize.Level1)
{
const std::string fstabFile1 = TEST_PATH_MOUNTCFG"ReadFstabFromFile1.fstable";
const std::string fstabFile1 = "/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable";
Fstab *fstab = nullptr;
fstab = ReadFstabFromFile(fstabFile1.c_str(), false);
ASSERT_NE(fstab, nullptr);
......@@ -101,7 +100,7 @@ HWTEST_F(InnerkitsUnitTest, FindFstabItemForMountPoint_unitest, TestSize.Level1)
HWTEST_F(InnerkitsUnitTest, GetMountFlags_unitest, TestSize.Level1)
{
const std::string fstabFile1 = TEST_PATH_MOUNTCFG"ReadFstabFromFile1.fstable";
const std::string fstabFile1 = "/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable";
Fstab *fstab = nullptr;
fstab = ReadFstabFromFile(fstabFile1.c_str(), true);
ASSERT_NE(fstab, nullptr);
......
......@@ -115,7 +115,11 @@ static void TestPermission()
if ((GetParamSecurityLabel() != nullptr)) {
GetParamSecurityLabel()->flags[0] = LABEL_CHECK_IN_ALL_PROCESS;
ret = SystemSetParameter(testName, "22202");
#ifdef PARAM_SUPPORT_SELINUX
EXPECT_EQ(ret, 0);
#else
EXPECT_EQ(ret, DAC_RESULT_FORBIDED);
#endif
}
paramSecurityOps->securityFreeLabel = TestFreeLocalSecurityLabel;
paramSecurityOps->securityCheckParamPermission = TestCheckParamPermission;
......@@ -126,9 +130,12 @@ static void TestPermission()
const int testResult = 201;
SetTestPermissionResult(testResult);
// 禁止写/读
ret = SystemSetParameter(testName, "3333");
#ifdef PARAM_SUPPORT_SELINUX
EXPECT_EQ(ret, 0);
#else
EXPECT_EQ(ret, testResult);
#endif
u_int32_t len = sizeof(tmp);
ret = SystemGetParameter(testName, tmp, &len);
EXPECT_EQ(ret, testResult);
......@@ -220,6 +227,6 @@ HWTEST_F(ClientUnitTest, TestClient_04, TestSize.Level0)
HWTEST_F(ClientUnitTest, TestClient_05, TestSize.Level0)
{
TestForMultiThread();
// TestForMultiThread
}
} // namespace init_ut
\ No newline at end of file
......@@ -13,8 +13,8 @@
* limitations under the License.
*/
#include <dirent.h>
#include "param_stub.h"
#include <dirent.h>
#include "beget_ext.h"
#include "init_param.h"
#include "param_manager.h"
......@@ -24,9 +24,6 @@
#include "param_cfg.h"
#endif
#define TEST_PATH_UEVENT "/data/ueventd_ut"
#define TEST_PATH_MOUNTCFG "/data/init_ut/mount_unitest/"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
......@@ -185,8 +182,8 @@ static void PrepareUeventdcfg(void)
"/dev/testbinder2 0666 1000 1000 const.dev.binder\n"
"[device]\n"
"/dev/testbinder3 0666 1000 1000 const.dev.binder\n";
mkdir(TEST_PATH_UEVENT, S_IRWXU | S_IRWXG | S_IRWXO);
CreateTestFile(TEST_PATH_UEVENT"/valid.config", ueventdcfg);
mkdir("/data/ueventd_ut", S_IRWXU | S_IRWXG | S_IRWXO);
CreateTestFile("/data/ueventd_ut/valid.config", ueventdcfg);
}
static void PrepareModCfg(void)
{
......@@ -209,7 +206,7 @@ static void PrepareInnerKitsCfg()
"aa aa aa\n"
"aa aa aa aa\n";
mkdir("/data/init_ut/mount_unitest/", S_IRWXU | S_IRWXG | S_IRWXO);
CreateTestFile(TEST_PATH_MOUNTCFG"ReadFstabFromFile1.fstable", innerKitsCfg);
CreateTestFile("/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable", innerKitsCfg);
}
static bool IsDir(const std::string &path)
{
......@@ -227,7 +224,6 @@ static bool DeleteDir(const std::string &path)
}
struct dirent *dp = nullptr;
if (pDir != nullptr) {
while ((dp = readdir(pDir.get())) != nullptr) {
std::string currentName(dp->d_name);
if (currentName[0] != '.') {
......@@ -239,7 +235,8 @@ static bool DeleteDir(const std::string &path)
remove(tmpName.c_str());
}
}
remove(path.c_str());
if (remove(path.c_str()) != 0) {
return false;
}
return true;
}
......@@ -321,7 +318,7 @@ void PrepareInitUnitTestEnv(void)
PrepareUeventdcfg();
PrepareInnerKitsCfg();
PrepareModCfg();
SetInitLogLevel(INIT_DEBUG);
SetInitLogLevel(INIT_FATAL);
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
// for cmdline
......
......@@ -29,8 +29,6 @@ extern "C" {
#endif
#endif
#define TEST_PATH "/data/ueventd_ut"
void PrepareInitUnitTestEnv(void);
void TestSetSelinuxOps(void);
void SetTestPermissionResult(int result);
......
......@@ -510,7 +510,7 @@ HWTEST_F(ParamServiceUnitTest, TestServiceCtrl, TestSize.Level0)
{
ParamServiceUnitTest test;
int ret = test.TestServiceCtrl("server1", 0770);
EXPECT_NE(ret, 0);
EXPECT_EQ(ret, 0);
ret = test.TestServiceCtrl("server2", 0772);
EXPECT_EQ(ret, 0);
}
......@@ -519,19 +519,19 @@ HWTEST_F(ParamServiceUnitTest, TestPowerCtrl, TestSize.Level0)
{
ParamServiceUnitTest test;
int ret = test.TestPowerCtrl("reboot,shutdown", 0770);
EXPECT_NE(ret, 0);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot,shutdown", 0772);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot,updater", 0770);
EXPECT_NE(ret, 0);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot,updater", 0772);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot,flash", 0770);
EXPECT_NE(ret, 0);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot,flash", 0772);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot", 0770);
EXPECT_NE(ret, 0);
EXPECT_EQ(ret, 0);
ret = test.TestPowerCtrl("reboot", 0772);
EXPECT_EQ(ret, 0);
}
......
......@@ -31,9 +31,7 @@ bool IsMatch(const char *target, const char *pattern);
using namespace std;
using namespace testing::ext;
#define TEST_PATH "/data/ueventd_ut"
namespace ueventd_ut {
class UeventdConfigUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
......@@ -44,7 +42,7 @@ void TearDown() {};
HWTEST_F(UeventdConfigUnitTest, TestSectionConfigParse, TestSize.Level0)
{
ParseUeventdConfigFile(TEST_PATH"/valid.config");
ParseUeventdConfigFile("/data/ueventd_ut/valid.config");
uid_t uid = 0;
gid_t gid = 0;
mode_t mode = 0;
......@@ -86,7 +84,7 @@ HWTEST_F(UeventdConfigUnitTest, TestConfigEntry, TestSize.Level0)
HWTEST_F(UeventdConfigUnitTest, TestParameter, TestSize.Level0)
{
ParseUeventdConfigFile(TEST_PATH"/valid.config");
ParseUeventdConfigFile("/data/ueventd_ut/valid.config");
SetUeventDeviceParameter("/dev/testbinder1", 0);
SetUeventDeviceParameter("/dev/testbinder2", 0);
SetUeventDeviceParameter("/dev/testbinder3", 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册