提交 f5e9e153 编写于 作者: L limeng151

修改groups相关用例

Signed-off-by: Nlimeng151 <limeng151@huawei.com>
Change-Id: I0f51066a835463d9431187ab738b3812135010e3
上级 2c748682
...@@ -641,11 +641,14 @@ HWTEST_F(UidGidTest, testGetgroups, Function | MediumTest | Level1) ...@@ -641,11 +641,14 @@ HWTEST_F(UidGidTest, testGetgroups, Function | MediumTest | Level1)
gid_t gidList[testSize] = {0}; gid_t gidList[testSize] = {0};
int n = getgroups(0, gidList); int n = getgroups(0, gidList);
ASSERT_EQ(n, 2); ASSERT_EQ(n, 2);
getgroups(n, gidList); int rt = getgroups(n, gidList);
ASSERT_EQ(gidList[0], SHELL_GID); ASSERT_EQ(gidList[0], SHELL_GID);
ASSERT_EQ(gidList[1], 0);
ASSERT_EQ(rt, n);
n = getgroups(testSize, gidList); n = getgroups(testSize, gidList);
ASSERT_EQ(n, 2); ASSERT_EQ(n, 2);
ASSERT_EQ(gidList[0], SHELL_GID); ASSERT_EQ(gidList[0], SHELL_GID);
ASSERT_EQ(gidList[1], 0);
} }
/** /**
...@@ -708,8 +711,10 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1) ...@@ -708,8 +711,10 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1)
LOG("Init: make sure groups not changed by other test."); LOG("Init: make sure groups not changed by other test.");
int n = getgroups(0, gidListOut); int n = getgroups(0, gidListOut);
EXPECT_EQ(n, 2); EXPECT_EQ(n, 2);
getgroups(n, gidListOut); int rt = getgroups(n, gidListOut);
EXPECT_EQ(gidListOut[0], SHELL_GID); EXPECT_EQ(gidListOut[0], SHELL_GID);
EXPECT_EQ(gidListOut[1], 0);
EXPECT_EQ(rt, n);
LOG("add 2 groups"); LOG("add 2 groups");
int rt = setgroups(2, gidListIn); int rt = setgroups(2, gidListIn);
...@@ -725,7 +730,8 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1) ...@@ -725,7 +730,8 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1)
EXPECT_EQ(rt, 0); EXPECT_EQ(rt, 0);
n = getgroups(0, gidListOut); n = getgroups(0, gidListOut);
EXPECT_EQ(n, 1); EXPECT_EQ(n, 1);
getgroups(n, gidListOut); rt = getgroups(n, gidListOut);
EXPECT_EQ(rt, n);
EXPECT_EQ(gidListOut[0], SHELL_GID); EXPECT_EQ(gidListOut[0], SHELL_GID);
} }
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
// max test number of uid/gid, not actual max number // max test number of uid/gid, not actual max number
const int MAX_UGID = 100000; const int MAX_UGID = 100000;
static int groupNum = -1;
static gid_t groupsArry[10] = {0};
// Assert all uid == expectUid // Assert all uid == expectUid
#define AssertAllUid(expectUid) do { \ #define AssertAllUid(expectUid) do { \
...@@ -54,17 +57,25 @@ public: ...@@ -54,17 +57,25 @@ public:
return id; return id;
} }
protected: protected:
static void SetUpTestCase() {
for (int i = 0; i < 10; i++) {
groupsArry[i] = -1;
}
groupNum = getgroups(0, groupsArry);
EXPECT_NE(groupNum, -1);
}
void TearDown() void TearDown()
{ {
LOG("TearDown: reset uid and gid"); LOG("TearDown: reset uid and gid");
gid_t gidList[2]; // gid_t gidList[2];
gidList[0] = SHELL_UID; // gidList[0] = SHELL_UID;
gidList[1] = 0; // gidList[1] = 0;
setuid(SHELL_UID); setuid(SHELL_UID);
setgid(SHELL_GID); setgid(SHELL_GID);
AssertAllUid(SHELL_UID); AssertAllUid(SHELL_UID);
AssertAllGid(SHELL_GID); AssertAllGid(SHELL_GID);
int rt = setgroups(2, gidList); int rt = setgroups(groupNum, groupsArry);
EXPECT_EQ(rt, 0);
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册