From: Cyril H. <su...@li...> - 2013-04-04 15:21:32
|
The branch, master, has been updated via c515be23194f988533259dff450ff8da0c7f6ae5 (commit) via be0d9d6a42bee938fbda50685e578a73ca75116d (commit) via 2c8bb90b91cc35edba900f2fd2e777ce0722497b (commit) via 750a46adf9c8bd5ba986adfc32b3775c20e74c4d (commit) from 74500f984c2e2b926650367f6a55f3ee9b33c617 (commit) - Log ----------------------------------------------------------------- commit c515be23194f988533259dff450ff8da0c7f6ae5 Author: Cyril Hrubis <ch...@su...> Date: Thu Apr 4 16:46:39 2013 +0200 testcases/.../syscalls/getgroups03: Cleanup. * Remove useless commets * Shuffle the code a little to make it more readable Signed-off-by: Cyril Hrubis <ch...@su...> commit be0d9d6a42bee938fbda50685e578a73ca75116d Author: Cyril Hrubis <ch...@su...> Date: Thu Apr 4 15:57:18 2013 +0200 testcases/.../syscalls/getgroups{02,04}: Remove. Each of these testcases do one of the tests from getgroups01. There is no point in cleaning and fixing their code. Signed-off-by: Cyril Hrubis <ch...@su...> commit 2c8bb90b91cc35edba900f2fd2e777ce0722497b Author: Cyril Hrubis <ch...@su...> Date: Thu Apr 4 15:45:02 2013 +0200 testcases/.../syscalls/getgroups01: Fix. Fix the memset() and memcmp() sizes to match the array sizes. Signed-off-by: Cyril Hrubis <ch...@su...> commit 750a46adf9c8bd5ba986adfc32b3775c20e74c4d Author: Cyril Hrubis <ch...@su...> Date: Thu Mar 14 15:36:51 2013 +0100 testcases/.../syscalls/getgroups01: Cleanup. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/getgroups/getgroups01.c | 124 +++++-------- testcases/kernel/syscalls/getgroups/getgroups02.c | 176 ------------------ testcases/kernel/syscalls/getgroups/getgroups03.c | 198 ++++++++------------- testcases/kernel/syscalls/getgroups/getgroups04.c | 170 ------------------ 4 files changed, 122 insertions(+), 546 deletions(-) delete mode 100644 testcases/kernel/syscalls/getgroups/getgroups02.c delete mode 100644 testcases/kernel/syscalls/getgroups/getgroups04.c diff --git a/testcases/kernel/syscalls/getgroups/getgroups01.c b/testcases/kernel/syscalls/getgroups/getgroups01.c index 75f2f63..1d58109 100644 --- a/testcases/kernel/syscalls/getgroups/getgroups01.c +++ b/testcases/kernel/syscalls/getgroups/getgroups01.c @@ -28,52 +28,22 @@ * For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * */ -/* $Id: getgroups01.c,v 1.7 2009/08/28 13:03:01 vapier Exp $ */ -/*********************************************************************** -TEST IDENTIFIER: getgroups01 : Getgroups system call critical test - -PARENT DOCUMENT: ggrtds01: Getgroups system call test design spec - -AUTHOR: Barrie Kletscher - Rewrote : 11-92 by Richard Logan - -CO-PILOT: Dave Baumgartner - -TEST ITEMS: - 1. Check to see if getgroups(-1, gidset) fails and sets errno to EINVAL - 2. Check to see if getgroups(0, gidset) does not return -1 and gidset is - not modified. - 3. Check to see if getgroups(x, gigset) fails and sets errno to EINVAL, - where x is one less then what is returned by getgroups(0, gidset). - 4. Check to see if getgroups() succeeds and gidset contains - group id returned from getgid(). - -INPUT SPECIFICATIONS: - NONE - -OUTPUT SPECIFICATIONS: - Standard tst_res output format - -ENVIRONMENTAL NEEDS: - NONE. - -SPECIAL PROCEDURAL REQUIREMENTS: - None - -INTERCASE DEPENDENCIES: - Test case #3 depends on test case #2. - -DETAILED DESCRIPTION: - Set up the signal handling capabilities. - execute tests - exit -BUGS: - None known. - -************************************************************/ +/* + AUTHOR: Barrie Kletscher + Rewrote : 11-92 by Richard Logan + CO-PILOT: Dave Baumgartner + + TEST ITEMS: + 1. Check to see if getgroups(-1, gidset) fails and sets errno to EINVAL + 2. Check to see if getgroups(0, gidset) does not return -1 and gidset is + not modified. + 3. Check to see if getgroups(x, gigset) fails and sets errno to EINVAL, + where x is one less then what is returned by getgroups(0, gidset). + 4. Check to see if getgroups() succeeds and gidset contains + group id returned from getgid(). +*/ #include <unistd.h> #include <signal.h> @@ -85,28 +55,27 @@ BUGS: #include "test.h" #include "usctest.h" -void setup(); -void cleanup(); +static void setup(void); +static void cleanup(void); -char *TCID = "getgroups01"; /* Test program identifier. */ -int TST_TOTAL = 4; /* Total number of test cases. */ +char *TCID = "getgroups01"; +int TST_TOTAL = 4; -gid_t gidset[NGROUPS]; /* storage for all group ids */ -gid_t cmpset[NGROUPS]; +static gid_t gidset[NGROUPS]; +static gid_t cmpset[NGROUPS]; int main(int ac, char **av) { int lc; - char *ptr; /* message returned from parse_opts */ - + char *msg; gid_t group; - int i; - int entries; /* number of group entries */ + int entries; initgroups("root", 0); - if ((ptr = parse_opts(ac, av, NULL, NULL)) != NULL) - tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", ptr); + + if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); @@ -116,9 +85,9 @@ int main(int ac, char **av) TEST(getgroups(-1, gidset)); - if (TEST_RETURN == 0) + if (TEST_RETURN == 0) { tst_resm(TFAIL, "getgroups succeeded unexpectedly"); - else if (STD_FUNCTIONAL_TEST) { + } else if (STD_FUNCTIONAL_TEST) { if (errno == EINVAL) tst_resm(TPASS, "getgroups failed as expected with EINVAL"); @@ -132,15 +101,14 @@ int main(int ac, char **av) * return and the the gidset array is not modified. * This is a POSIX special case. */ - - memset(gidset, 052, NGROUPS); - memset(cmpset, 052, NGROUPS); + memset(gidset, 052, NGROUPS * sizeof(gid_t)); + memset(cmpset, 052, NGROUPS * sizeof(gid_t)); TEST(getgroups(0, gidset)); - if (TEST_RETURN == -1) - tst_resm(TFAIL | TTERRNO, "getgroups failed"); - else if (STD_FUNCTIONAL_TEST) { - if (memcmp(cmpset, gidset, NGROUPS) != 0) + if (TEST_RETURN == -1) { + tst_resm(TFAIL | TTERRNO, "getgroups failed unexpectedly"); + } else if (STD_FUNCTIONAL_TEST) { + if (memcmp(cmpset, gidset, NGROUPS * sizeof(gid_t)) != 0) tst_resm(TFAIL, "getgroups modified the gidset array"); else @@ -153,12 +121,11 @@ int main(int ac, char **av) * Check to see that is -1 is returned and errno is set to * EINVAL when ngroups is not big enough to hold all groups. */ - - if (TEST_RETURN <= 1) + if (TEST_RETURN <= 1) { tst_resm(TCONF, "getgroups returned %ld; unable to test that using ngrps >=1 but less than number of grps", TEST_RETURN); - else { + } else { TEST(getgroups(TEST_RETURN - 1, gidset)); if (TEST_RETURN == -1) { if (STD_FUNCTIONAL_TEST) { @@ -171,21 +138,22 @@ int main(int ac, char **av) "getgroups didn't fail " "with EINVAL"); } - } else + } else { tst_resm(TFAIL, "getgroups succeeded unexpectedly with %ld", TEST_RETURN); + } } TEST(getgroups(NGROUPS, gidset)); - if ((entries = TEST_RETURN) == -1) + if ((entries = TEST_RETURN) == -1) { tst_resm(TFAIL | TTERRNO, "getgroups failed unexpectedly"); - else if (STD_FUNCTIONAL_TEST) { + } else if (STD_FUNCTIONAL_TEST) { group = getgid(); - for (i = 0; i < entries; i++) + for (i = 0; i < entries; i++) { if (gidset[i] == group) { tst_resm(TPASS, "getgroups(NGROUPS,gidset) " @@ -194,30 +162,30 @@ int main(int ac, char **av) entries, group); break; } + } - if (i == entries) + if (i == entries) { tst_resm(TFAIL, "getgroups(NGROUPS,gidset) ret %d, does " "not contain gid %d (from getgid)", entries, group); + } } } - cleanup(); + cleanup(); tst_exit(); } -void setup() +static void setup(void) { - tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; - } -void cleanup() +static void cleanup(void) { TEST_CLEANUP; } diff --git a/testcases/kernel/syscalls/getgroups/getgroups02.c b/testcases/kernel/syscalls/getgroups/getgroups02.c deleted file mode 100644 index 977996c..0000000 --- a/testcases/kernel/syscalls/getgroups/getgroups02.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * - */ -/* $Id: getgroups02.c,v 1.6 2009/08/28 13:05:36 vapier Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : getgroups02 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for getgroups(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) getgroups(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - *$ - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the getgroups(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * getgroups(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/fcntl.h> -#include <errno.h> -#include <string.h> -#include <signal.h> -#include "test.h" -#include "usctest.h" - -void setup(); -void cleanup(); - -char *TCID = "getgroups02"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test cases. */ - -int exp_enos[] = { 0, 0 }; - -/* define array size for gids */ -#define GID_ARRAY_SIZE 100 - -gid_t gidset[GID_ARRAY_SIZE]; /* array of gids */ - -int main(int ac, char **av) -{ - int lc; - char *msg; - - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) - tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - - setup(); - - TEST_EXP_ENOS(exp_enos); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - TEST(getgroups(GID_ARRAY_SIZE, gidset)); - - if (TEST_RETURN == -1) - tst_resm(TFAIL | TTERRNO, "getgroups failed"); - else if (STD_FUNCTIONAL_TEST) - tst_resm(TPASS, "getgroups returned %ld", TEST_RETURN); - - } - - cleanup(); - - tst_exit(); -} - -void setup() -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; -} - -void cleanup() -{ - TEST_CLEANUP; - -} diff --git a/testcases/kernel/syscalls/getgroups/getgroups03.c b/testcases/kernel/syscalls/getgroups/getgroups03.c index 5950fc4..1e25756 100644 --- a/testcases/kernel/syscalls/getgroups/getgroups03.c +++ b/testcases/kernel/syscalls/getgroups/getgroups03.c @@ -1,25 +1,24 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * Ported by Wayne Boyer + * Copyright (c) Cyril Hrubis <ch...@su...> 2013 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* - * Test Name: getgroups03 - * * Test Description: * Verify that, getgroups() system call gets the supplementary group IDs * of the calling process. @@ -27,40 +26,6 @@ * Expected Result: * The call succeeds in getting all the supplementary group IDs of the * calling process. The effective group ID may or may not be returned. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * - * Usage: <for command-line> - * getgroups01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * */ #include <stdio.h> @@ -77,28 +42,24 @@ #include "test.h" #include "usctest.h" -#define TESTUSER "root" -#define PRESENT 1 -#define NOT_PRESENT 0 +#define TESTUSER "root" -char *TCID = "getgroups03"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test conditions */ -int ngroups; /* No. of groups */ -gid_t groups_list[NGROUPS]; /* Array to hold gids for getgroups() */ -gid_t groups[NGROUPS]; /* Array to hold gids read fr. /etc/group */ -int fflag; /* functionality flag variable */ +char *TCID = "getgroups03"; +int TST_TOTAL = 1; -int verify_groups(int); /* function to verify groups returned */ -int readgroups(gid_t *); /* function to read gids of testuser */ -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ +static int ngroups; +static gid_t groups_list[NGROUPS]; +static gid_t groups[NGROUPS]; + +static void verify_groups(int ret_ngroups); +static void setup(void); +static void cleanup(void); int main(int ac, char **av) { int lc; char *msg; - int ret_val; - int gidsetsize = NGROUPS; /* total groups */ + int gidsetsize = NGROUPS; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); @@ -111,59 +72,31 @@ int main(int ac, char **av) TEST(getgroups(gidsetsize, groups_list)); - if ((ret_val = TEST_RETURN) == -1) { + if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "getgroups failed"); continue; } - if (STD_FUNCTIONAL_TEST) { - fflag = verify_groups(ret_val); - if (fflag) - tst_resm(TPASS, - "getgroups functionality correct"); - } else - tst_resm(TPASS, "call succeeded"); + + if (STD_FUNCTIONAL_TEST) + verify_groups(TEST_RETURN); + else + tst_resm(TPASS, "getgroups succeeded"); } cleanup(); - tst_exit(); } -void setup() -{ - - tst_require_root(NULL); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* - * Get the IDs of all the groups of "root" - * from /etc/group file - */ - ngroups = readgroups(groups); - - /* Setgroups is called by the login(1) process - * if the testcase is executed via an ssh session this - * testcase will fail. So execute setgroups() before executing - * getgroups() - */ - if (setgroups(ngroups, groups) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "setgroups failed"); - -} - /* * readgroups(gid_t *) - Read supplimentary group ids of "root" user * Scans the /etc/group file to get IDs of all the groups to which TESTUSER * belongs and puts them into the array passed. * Returns the no of gids read. */ -int readgroups(gid_t groups[NGROUPS]) +static int readgroups(gid_t groups[NGROUPS]) { - struct group *grp; /* To hold the group entry */ - int ngrps = 0; /* No of groups */ + struct group *grp; + int ngrps = 0; int i; int found; gid_t g; @@ -196,7 +129,30 @@ int readgroups(gid_t groups[NGROUPS]) groups[ngrps++] = g; endgrent(); - return (ngrps); + return ngrps; +} + +static void setup(void) +{ + tst_require_root(NULL); + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + TEST_PAUSE; + + /* + * Get the IDs of all the groups of "root" + * from /etc/group file + */ + ngroups = readgroups(groups); + + /* Setgroups is called by the login(1) process + * if the testcase is executed via an ssh session this + * testcase will fail. So execute setgroups() before executing + * getgroups() + */ + if (setgroups(ngroups, groups) == -1) + tst_brkm(TBROK | TERRNO, cleanup, "setgroups failed"); } /* @@ -206,14 +162,12 @@ int readgroups(gid_t groups[NGROUPS]) * This function returns flag value which indicates success or failure * of verification. */ -int verify_groups(int ret_val) +static void verify_groups(int ret_ngroups) { - int i, j; /* counter variables */ - gid_t egid; /* Effective gid of the process */ - int egid_flag = PRESENT; /* egid present or not */ - - /* Set the functionality flag */ - fflag = 1; + int i, j; + gid_t egid; + int egid_flag = 1; + int fflag = 1; /* * Loop through the array to verify the gids @@ -222,7 +176,7 @@ int verify_groups(int ret_val) * returned by getgroups() with that read from * group file. */ - for (i = 0; i < ret_val; i++) { + for (i = 0; i < ret_ngroups; i++) { for (j = 0; j < ngroups; j++) { if (groups_list[i] != groups[j]) { /* If loop ends and gids are not matching */ @@ -234,23 +188,23 @@ int verify_groups(int ret_val) } else { continue; } - } else { /* if equal, continue the outer loop */ + } else { break; } } } /* Now do the reverse comparison */ - egid = getegid(); /* get egid */ + egid = getegid(); for (i = 0; i < ngroups; i++) { - for (j = 0; j < ret_val; j++) { + for (j = 0; j < ret_ngroups; j++) { if (groups[i] != groups_list[j]) { /* * If the loop ends & gids are not matching * if gid is not egid, exit with error * else egid is returned by getgroups() */ - if (j == (ret_val - 1)) { + if (j == (ret_ngroups - 1)) { if (groups[i] != egid) { tst_resm(TFAIL, "getgroups " "didn't return %d one " @@ -263,10 +217,10 @@ int verify_groups(int ret_val) * group_list. * Reset the egid flag */ - egid_flag = NOT_PRESENT; + egid_flag = 0; } } - } else { /* if equal, continue the outer loop */ + } else { break; } } @@ -279,20 +233,20 @@ int verify_groups(int ret_val) * Now, if ngroups matches ret_val, as above comparisons of the array * are successful, this implies that the array contents match. */ - if (egid_flag == 0) /* If egid is not returned */ + if (egid_flag == 0) ngroups--; - if (ngroups != ret_val) { + if (ngroups != ret_ngroups) { tst_resm(TFAIL, "getgroups(2) returned incorrect no. of gids %d " - "(expected %d)", ret_val, ngroups); + "(expected %d)", ret_ngroups, ngroups); fflag = 0; } - return (fflag); + if (fflag) + tst_resm(TPASS, "getgroups functionality correct"); } -void cleanup() +static void cleanup(void) { TEST_CLEANUP; - } diff --git a/testcases/kernel/syscalls/getgroups/getgroups04.c b/testcases/kernel/syscalls/getgroups/getgroups04.c deleted file mode 100644 index e1beaff..0000000 --- a/testcases/kernel/syscalls/getgroups/getgroups04.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * Test Name: getgroups04 - * - * Test Description: - * Verify that, - * getgroups() fails with -1 and sets errno to EINVAL if the size - * argument value is -ve. - * - * Expected Result: - * getgroups() should fail with return value -1 and set expected errno. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * if errno set == expected errno - * Issue sys call fails with expected return value and errno. - * Otherwise, - * Issue sys call fails with unexpected errno. - * Otherwise, - * Issue sys call returns unexpected value. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * Usage: <for command-line> - * getgroups04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be executed by non-super-user only. - */ - -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <signal.h> -#include <grp.h> -#include <sys/stat.h> -#include <sys/param.h> - -#include "test.h" -#include "usctest.h" - -char *TCID = "getgroups04"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test conditions */ -int exp_enos[] = { EINVAL, 0 }; - -gid_t groups_list[NGROUPS]; /* buffer to hold user group list */ - -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -struct test_case_t { /* test case struct. to hold ref. test cond's */ - size_t gsize; - gid_t list; - char *desc; - int exp_errno; - int (*setupfunc) (); -} test_cases[] = { - { --1, 1, "Size is < no. suppl. gids", EINVAL},}; - -int main(int ac, char **av) -{ - int lc; - char *msg; - int gidsetsize; /* total no. of groups */ - int i; - char *test_desc; /* test specific error message */ - - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) - tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - - setup(); - - TEST_EXP_ENOS(exp_enos); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - gidsetsize = test_cases[i].gsize; - test_desc = test_cases[i].desc; - - TEST(getgroups(gidsetsize, groups_list)); - - if (TEST_RETURN == -1) { - if (TEST_ERRNO == test_cases[i].exp_errno) - tst_resm(TPASS | TTERRNO, - "getgroups failed as expected"); - else - tst_resm(TFAIL | TTERRNO, - "getgroups failed unexpectedly; " - "expected: %d - %s", - test_cases[i].exp_errno, - strerror(test_cases[i]. - exp_errno)); - } else - tst_resm(TFAIL, - "getgroups succeeded unexpectedly"); - } - - } - - cleanup(); - - tst_exit(); -} - -/* - * void - * setup() - performs all ONE TIME setup for this test. - */ -void setup() -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - -} - -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup() -{ - /* - * print timing stats if that option was specified. - */ - TEST_CLEANUP; - -} hooks/post-receive -- ltp |