[LTP] [PATCH v2 2/3] syscalls/setgroups02: Convert to new API

Yang Xu (Fujitsu) xuyang2018.jy@fujitsu.com
Mon Aug 14 13:18:39 CEST 2023


Hi Cyril

Hi!


+static GID_T groups_get[NGROUPS];
+static GID_T groups_set[NGROUPS];



Since you are using the guarded buffers these two has to be just
pointers, i.e.

static GID_T *groups_get;


ok

-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- *  Make sure the test process uid is root.
- *  Get the supplimentrary group id of test user from /etc/passwd file.
- */
-void setup(void)
+static void verify_setgroups(void)
 {
+       int gidsetsize = 1;



There is no point in passing the value via variable, we can as well pass
1 directly to the getgroups/setgroups calls.


Agree

-       tst_require_root();
-
-       tst_sig(NOFORK, DEF_HANDLER, cleanup);
+       groups_set[0] = 42;



We have to clear the groups_get[0] here as well, in the case that we are
looping with the -i parameter, i.e.

        groups_get[0] = 0;


I forgot this, I'll update it

-       TEST_PAUSE;
+       TST_EXP_PASS(SETGROUPS(gidsetsize, groups_set));

-       /* Get the group id info. of TESTUSER from /etc/passwd */
-       if ((user_info = getpwnam(TESTUSER)) == NULL) {
-               tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER);
-       }
+       TST_EXP_VAL(GETGROUPS(gidsetsize, groups_get), 1);

-       if (!GID_SIZE_CHECK(user_info->pw_gid)) {
-               tst_brkm(TBROK,
-                        cleanup,
-                        "gid returned from getpwnam is too large for testing setgroups16");
-       }
-
-       groups_list[0] = user_info->pw_gid;
+       TST_EXP_EQ_LI(groups_get[0], groups_set[0]);
 }

-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *            completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+       .test_all = verify_setgroups,
+       .bufs = (struct tst_buffers []) {
+               {&groups_get, .size = sizeof(groups_get)},
+               {&groups_set, .size = sizeof(groups_set)},


                                          ^
                                          Since we are using arrays of
                                          size 1 with elements of a size
                                          GID_T this should be just
                                          sizeof(GID_T)

If it was array of size 2 it would have been 2 * sizeof(GID_T) etc.


The rest of the changes looks good.

ok, I'll update it




Best Regards

Yang Xu





More information about the ltp mailing list