I've extended setgroup test cases can test setgroups16 old system calls. To test, please put attached compat_16.h to ltp/testcases/kernel/syscalls/setgroups; and apply the patch. Signed-off-by: Masatake YAMATO <yamato@redhat.com>.
diff --git a/testcases/kernel/syscalls/setgroups/Makefile b/testcases/kernel/syscalls/setgroups/Makefile
index 6706403..b59851c 100644
--- a/testcases/kernel/syscalls/setgroups/Makefile
+++ b/testcases/kernel/syscalls/setgroups/Makefile
@@ -19,8 +19,10 @@
CFLAGS += -I../../../../include -Wall
LDLIBS += -L../../../../lib -lltp
+include ../utils/compat_16.mk
+
SRCS = $(wildcard *.c)
-TARGETS = $(patsubst %.c,%,$(SRCS))
+TARGETS += $(patsubst %.c,%,$(SRCS))
all: $(TARGETS)
diff --git a/testcases/kernel/syscalls/setgroups/compat_16.h b/testcases/kernel/syscalls/setgroups/compat_16.h
new file mode 100644
index 0000000..58cab5c
--- /dev/null
+++ b/testcases/kernel/syscalls/setgroups/compat_16.h
@@ -0,0 +1,101 @@
+/*
+ *
+ * Copyright (c) Red Hat Inc., 2008
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* Author: Masatake YAMATO <yamato@redhat.com> */
+
+#ifndef __SETGROUPS_COMPAT_16_H__
+#define __SETGROUPS_COMPAT_16_H__
+
+#include <asm/posix_types.h>
+#include "linux_syscall_numbers.h"
+
+/* For avoiding circular dependency. */
+extern void cleanup(void);
+
+#ifdef TST_USE_COMPAT16_SYSCALL
+typedef __kernel_old_gid_t GID_T;
+
+int
+COMPAT_SIZE_CHECK(gid_t gid)
+{
+ /* See high2lowgid in linux/highuid.h
+ Return 0 if gid is too large to store
+ it to __kernel_old_gid_t. */
+ return ((gid) & ~0xFFFF)? 0: 1;
+}
+
+long
+SETGROUPS(int gidsetsize, GID_T *list)
+{
+ return syscall(__NR_setgroups, gidsetsize, list);
+}
+
+int
+GETGROUPS(size_t size16, GID_T *list16)
+{
+ int r;
+ int i;
+
+ gid_t *list32;
+
+ list32 = malloc(size16 * sizeof(gid_t));
+ if (list32 == NULL)
+ tst_brkm(TBROK, NULL, "malloc failed to alloc %d errno "
+ " %d ", size16 * sizeof(gid_t), errno);
+
+ r = getgroups(size16, list32);
+ if (r < 0)
+ goto out;
+
+ for (i = 0; i < size16; i++) {
+ if (!COMPAT_SIZE_CHECK(list32[i]))
+ tst_brkm(TBROK,
+ cleanup,
+ "gid returned from getgroups is too large for testing setgroups32");
+ list16[i] = (GID_T)list32[i];
+ }
+
+ out:
+ free(list32);
+ return r;
+}
+
+#else
+typedef gid_t GID_T;
+
+int
+SETGROUPS(size_t size, const GID_T *list)
+{
+ return setgroups(size, list);
+}
+
+int
+GETGROUPS(size_t size, GID_T *list)
+{
+ return getgroups(size, list);
+}
+
+int
+COMPAT_SIZE_CHECK(gid_t gid)
+{
+ return 1;
+}
+#endif /* TST_USE_COMPAT16_SYSCALL */
+
+#endif /* __SETGROUPS_COMPAT_16_H__ */
diff --git a/testcases/kernel/syscalls/setgroups/setgroups01.c b/testcases/kernel/syscalls/setgroups/setgroups01.c
index f45637b..49b8629 100644
--- a/testcases/kernel/syscalls/setgroups/setgroups01.c
+++ b/testcases/kernel/syscalls/setgroups/setgroups01.c
@@ -30,7 +30,7 @@
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/
*
*/
-/* $Id: setgroups01.c,v 1.1 2001/08/27 22:15:15 plars Exp $ */
+/* $Id: setgroups01.c,v 1.2 2008/08/27 12:02:42 subrata_modak Exp $ */
/**********************************************************
*
* OS Test - Silicon Graphics, Inc.
@@ -119,17 +119,19 @@
#include "test.h"
#include "usctest.h"
+#include "compat_16.h"
+
void setup();
void cleanup();
-char *TCID="setgroups01"; /* Test program identifier. */
+TCID_DEFINE(setgroups01); /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
extern int Tst_count; /* Test Case counter for tst_* routines */
int len = NGROUPS;
-gid_t list[NGROUPS];
+GID_T list[NGROUPS];
int
main(int ac, char **av)
@@ -161,7 +163,7 @@
/*
* Call setgroups(2)
*/
- TEST(setgroups(len, list));
+ TEST(SETGROUPS(len, list));
/* check return code */
if ( TEST_RETURN == -1 ) {
@@ -203,7 +205,7 @@
/* Pause if that option was specified */
TEST_PAUSE;
- if (getgroups(len, list) == -1) {
+ if (GETGROUPS(len, list) == -1) {
tst_brkm(TBROK, cleanup,
"getgroups(%d, list) Failure. errno=%d : %s",
len, errno, strerror(errno));
diff --git a/testcases/kernel/syscalls/setgroups/setgroups02.c b/testcases/kernel/syscalls/setgroups/setgroups02.c
index 9b4b6b8..b694ee5 100644
--- a/testcases/kernel/syscalls/setgroups/setgroups02.c
+++ b/testcases/kernel/syscalls/setgroups/setgroups02.c
@@ -73,12 +73,14 @@
#include "test.h"
#include "usctest.h"
+#include "compat_16.h"
+
#define TESTUSER "nobody"
-char *TCID="setgroups02"; /* Test program identifier. */
+TCID_DEFINE(setgroups02); /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test conditions */
extern int Tst_count; /* Test Case counter for tst_* routines */
-gid_t groups_list[NGROUPS]; /* Array to hold gids for getgroups() */
+GID_T groups_list[NGROUPS]; /* Array to hold gids for getgroups() */
struct passwd *user_info; /* struct. to hold test user info */
void setup(); /* setup function for the test */
@@ -111,7 +113,7 @@
* Call setgroups() to set supplimentary group IDs of
* the calling super-user process to gid of TESTUSER.
*/
- TEST(setgroups(gidsetsize, groups_list));
+ TEST(SETGROUPS(gidsetsize, groups_list));
/* check return code of setgroups(2) */
if (TEST_RETURN == -1) {
@@ -132,7 +134,7 @@
* supp. gids of TESTUSER.
*/
groups_list[0] = '\0';
- if (getgroups(gidsetsize, groups_list) < 0) {
+ if (GETGROUPS(gidsetsize, groups_list) < 0) {
tst_brkm(TFAIL, cleanup, "getgroups() Fails, "
"error=%d", errno);
}
@@ -185,6 +187,12 @@
tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER);
}
+ if (!COMPAT_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;
}
diff --git a/testcases/kernel/syscalls/setgroups/setgroups03.c b/testcases/kernel/syscalls/setgroups/setgroups03.c
index a3a53e2..65a4754 100644
--- a/testcases/kernel/syscalls/setgroups/setgroups03.c
+++ b/testcases/kernel/syscalls/setgroups/setgroups03.c
@@ -75,19 +75,21 @@
#include "test.h"
#include "usctest.h"
+#include "compat_16.h"
+
#define TESTUSER "nobody"
char nobody_uid[] = "nobody";
struct passwd *ltpuser;
-char *TCID="setgroups03"; /* Test program identifier. */
+TCID_DEFINE(setgroups03); /* Test program identifier. */
int TST_TOTAL=2; /* Total number of test conditions */
extern int Tst_count; /* Test Case counter for tst_* routines */
int exp_enos[] = {EINVAL, EPERM, 0};
-gid_t *groups_list; /* Array to hold gids for getgroups() */
+GID_T *groups_list; /* Array to hold gids for getgroups() */
int setup1(); /* setup function to test error EPERM */
void setup(); /* setup function for the test */
@@ -120,10 +122,10 @@
tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
}
- groups_list = malloc(ngroups_max * sizeof(gid_t));
+ groups_list = malloc(ngroups_max * sizeof(GID_T));
if (groups_list == NULL) {
tst_brkm(TBROK, NULL, "malloc failed to alloc %d errno "
- " %d ", ngroups_max * sizeof(gid_t), errno);
+ " %d ", ngroups_max * sizeof(GID_T), errno);
}
/* Perform global setup for test */
@@ -151,7 +153,7 @@
* verify that it fails with -1 return value and
* sets appropriate errno.
*/
- TEST(setgroups(gidsetsize, groups_list));
+ TEST(SETGROUPS(gidsetsize, groups_list));
/* check return code of setgroups(2) */
if (TEST_RETURN != -1) {
@@ -229,6 +231,12 @@
if ((user_info = getpwnam(TESTUSER)) == NULL) {
tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER);
}
+
+ if (!COMPAT_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;
return 0;
}
diff --git a/testcases/kernel/syscalls/setgroups/setgroups04.c b/testcases/kernel/syscalls/setgroups/setgroups04.c
index f311d17..fc8c24b 100644
--- a/testcases/kernel/syscalls/setgroups/setgroups04.c
+++ b/testcases/kernel/syscalls/setgroups/setgroups04.c
@@ -70,11 +70,13 @@
#include "test.h"
#include "usctest.h"
-char *TCID="setgroups04"; /* Test program identifier. */
+#include "compat_16.h"
+
+TCID_DEFINE(setgroups04); /* Test program identifier. */
int TST_TOTAL = 1;
extern int Tst_count; /* Test Case counter for tst_* routines */
-gid_t groups_list[NGROUPS]; /* Array to hold gids for getgroups() */
+GID_T groups_list[NGROUPS]; /* Array to hold gids for getgroups() */
int exp_enos[] = {EFAULT, 0};
void setup(); /* setup function for the test */
@@ -116,7 +118,7 @@
* verify that it fails with -1 return value and
* sets appropriate errno.
*/
- TEST(setgroups(gidsetsize,sbrk(0)));
+ TEST(SETGROUPS(gidsetsize,sbrk(0)));
/* check return code of setgroups */
if (TEST_RETURN != -1) {
tst_resm(TFAIL, "setgroups() returned %d, "