From 2c74868244ea52ce7e20b2a03e2e044bd8d69f3a Mon Sep 17 00:00:00 2001 From: limeng151 Date: Fri, 16 Jul 2021 14:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9groups=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: limeng151 Change-Id: I9c45dadcd362a5dc68abbba522eb002e183604be --- kernel_lite/process_posix/src/UidGidTest.cpp | 15 +++++++++------ kernel_lite/process_posix/src/UidGidTest.h | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/kernel_lite/process_posix/src/UidGidTest.cpp b/kernel_lite/process_posix/src/UidGidTest.cpp index cde442313..bd70bfc11 100755 --- a/kernel_lite/process_posix/src/UidGidTest.cpp +++ b/kernel_lite/process_posix/src/UidGidTest.cpp @@ -640,10 +640,11 @@ 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); + getgroups(n, gidList); + ASSERT_EQ(gidList[0], SHELL_GID); n = getgroups(testSize, gidList); - ASSERT_EQ(n, 1); + ASSERT_EQ(n, 2); ASSERT_EQ(gidList[0], SHELL_GID); } @@ -705,8 +706,9 @@ 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); + getgroups(n, gidListOut); EXPECT_EQ(gidListOut[0], SHELL_GID); LOG("add 2 groups"); @@ -721,8 +723,9 @@ 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); + getgroups(n, gidListOut); EXPECT_EQ(gidListOut[0], SHELL_GID); } diff --git a/kernel_lite/process_posix/src/UidGidTest.h b/kernel_lite/process_posix/src/UidGidTest.h index fc3a11313..598574489 100755 --- a/kernel_lite/process_posix/src/UidGidTest.h +++ b/kernel_lite/process_posix/src/UidGidTest.h @@ -57,11 +57,14 @@ protected: void TearDown() { LOG("TearDown: reset uid and gid"); + gid_t gidList[2]; + gidList[0] = SHELL_UID; + gidList[1] = 0; setuid(SHELL_UID); setgid(SHELL_GID); AssertAllUid(SHELL_UID); AssertAllGid(SHELL_GID); - int rt = setgroups(0, NULL); + int rt = setgroups(2, gidList); } }; -- GitLab