提交 6a011683 编写于 作者: O openharmony_ci 提交者: Gitee

!332 【kernel_lite】【master】修改groups用例引起的相关问题

Merge pull request !332 from limeng/kernel_lite_20210716_03
......@@ -640,11 +640,15 @@ HWTEST_F(UidGidTest, testGetgroups, Function | MediumTest | Level1)
const int testSize = 10;
gid_t gidList[testSize] = {0};
int n = getgroups(0, gidList);
ASSERT_EQ(n, 1);
ASSERT_EQ(gidList[0], 0);
ASSERT_EQ(n, 2);
int rt = getgroups(n, gidList);
ASSERT_EQ(gidList[0], SHELL_GID);
ASSERT_EQ(gidList[1], 0);
ASSERT_EQ(rt, n);
n = getgroups(testSize, gidList);
ASSERT_EQ(n, 1);
ASSERT_EQ(n, 2);
ASSERT_EQ(gidList[0], SHELL_GID);
ASSERT_EQ(gidList[1], 0);
}
/**
......@@ -705,12 +709,15 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1)
gid_t gidListOut[4] = {0};
LOG("Init: make sure groups not changed by other test.");
int n = getgroups(1, gidListOut);
EXPECT_EQ(n, 1);
int n = getgroups(0, gidListOut);
EXPECT_EQ(n, 2);
int rt = getgroups(n, gidListOut);
EXPECT_EQ(gidListOut[0], SHELL_GID);
EXPECT_EQ(gidListOut[1], 0);
EXPECT_EQ(rt, n);
LOG("add 2 groups");
int rt = setgroups(2, gidListIn);
rt = setgroups(2, gidListIn);
EXPECT_EQ(rt, 0);
n = getgroups(4, gidListOut);
EXPECT_EQ(n, 3);
......@@ -721,8 +728,10 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1)
LOG("clear groups");
rt = setgroups(0, NULL);
EXPECT_EQ(rt, 0);
n = getgroups(2, gidListOut);
n = getgroups(0, gidListOut);
EXPECT_EQ(n, 1);
rt = getgroups(n, gidListOut);
EXPECT_EQ(rt, n);
EXPECT_EQ(gidListOut[0], SHELL_GID);
}
......
......@@ -23,6 +23,9 @@
// max test number of uid/gid, not actual max number
const int MAX_UGID = 100000;
static int groupNum = -1;
const int ARRAY_SIZE = 10;
static gid_t groupsArray[ARRAY_SIZE] = {0};
// Assert all uid == expectUid
#define AssertAllUid(expectUid) do { \
......@@ -54,14 +57,30 @@ public:
return id;
}
protected:
static void SetUpTestCase()
{
for (int i = 0; i < ARRAY_SIZE; i++) {
groupsArray[i] = -1;
}
groupNum = getgroups(0, groupsArray);
EXPECT_NE(groupNum, -1);
int rt = getgroups(groupNum, groupsArray);
EXPECT_EQ(rt, groupNum);
}
void TearDown()
{
LOG("TearDown: reset uid and gid");
gid_t groupIds[groupNum];
LOG("TearDown: reset uid and gid %d", sizeof(groupIds) / sizeof(gid_t));
for (int i = 0; i < groupNum; i++) {
groupIds[i] = groupsArray[i];
}
setuid(SHELL_UID);
setgid(SHELL_GID);
AssertAllUid(SHELL_UID);
AssertAllGid(SHELL_GID);
int rt = setgroups(0, NULL);
int rt = setgroups(groupNum, groupIds);
EXPECT_EQ(rt, 0);
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册