diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-07-01 17:26:37 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-07-01 17:26:37 +0000 |
commit | 1fe4042000bb5daea3b4914106869e53c79d3671 (patch) | |
tree | f6a016403b5621d3b7f39a4d63fddca4700b0218 /testsuites/psxtests/psxpasswd02 | |
parent | 2010-07-01 Vinu Rajashekhar <vinutheraj@gmail.com> (diff) | |
download | rtems-1fe4042000bb5daea3b4914106869e53c79d3671.tar.bz2 |
2010-07-01 Bharath Suri <bharath.s.jois@gmail.com>
PR 1598/testing
* Makefile.am, configure.ac, psxpasswd01/init.c,
psxpasswd01/psxpasswd01.doc, psxpasswd01/psxpasswd01.scn: Add testing
for POSIX user database (e.g. /etc/group and /etc/passwd) access
routines which are implemented in libcsupport/src/getpwent.c.
* psxpasswd02/.cvsignore, psxpasswd02/Makefile.am, psxpasswd02/init.c,
psxpasswd02/psxpasswd02.doc, psxpasswd02/psxpasswd02.scn: New files.
Diffstat (limited to 'testsuites/psxtests/psxpasswd02')
-rw-r--r-- | testsuites/psxtests/psxpasswd02/.cvsignore | 2 | ||||
-rw-r--r-- | testsuites/psxtests/psxpasswd02/Makefile.am | 27 | ||||
-rw-r--r-- | testsuites/psxtests/psxpasswd02/init.c | 182 | ||||
-rw-r--r-- | testsuites/psxtests/psxpasswd02/psxpasswd02.doc | 26 | ||||
-rw-r--r-- | testsuites/psxtests/psxpasswd02/psxpasswd02.scn | 24 |
5 files changed, 261 insertions, 0 deletions
diff --git a/testsuites/psxtests/psxpasswd02/.cvsignore b/testsuites/psxtests/psxpasswd02/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/testsuites/psxtests/psxpasswd02/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/testsuites/psxtests/psxpasswd02/Makefile.am b/testsuites/psxtests/psxpasswd02/Makefile.am new file mode 100644 index 0000000000..22f179c1e1 --- /dev/null +++ b/testsuites/psxtests/psxpasswd02/Makefile.am @@ -0,0 +1,27 @@ +## +## $Id$ +## + +MANAGERS = all + +rtems_tests_PROGRAMS = psxpasswd02 +psxpasswd02_SOURCES = init.c ../include/pmacros.h + +dist_rtems_tests_DATA = psxpasswd02.scn + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + + +AM_CPPFLAGS += -I$(top_srcdir)/include +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(psxpasswd02_OBJECTS) $(psxpasswd02_LDADD) +LINK_LIBS = $(psxpasswd02_LDLIBS) + +psxpasswd02$(EXEEXT): $(psxpasswd02_OBJECTS) $(psxpasswd02_DEPENDENCIES) + @rm -f psxpasswd02$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/psxtests/psxpasswd02/init.c b/testsuites/psxtests/psxpasswd02/init.c new file mode 100644 index 0000000000..48b66196b1 --- /dev/null +++ b/testsuites/psxtests/psxpasswd02/init.c @@ -0,0 +1,182 @@ +/* + * COPYRIGHT (c) 1989-2010. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include <bsp.h> +#include <pmacros.h> +#include <sys/types.h> +#include <pwd.h> +#include <grp.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> + +void print_passwd( + struct passwd *pw +) +{ + printf( + " username: %s\n" + " user password: %s\n" + " user ID: %d\n" + " group ID: %d\n" + " real name: %s\n" + " home directory: %s\n" + " shell program: %s\n", + pw->pw_name, + pw->pw_passwd, + pw->pw_uid, + pw->pw_gid, + pw->pw_gecos, + pw->pw_dir, + pw->pw_shell + ); +} + +void print_group( + struct group *gr +) +{ + printf( + " group name: %s\n" + " group password: %s\n" + " group ID: %d\n", + gr->gr_name, + gr->gr_passwd, + gr->gr_gid + ); + + /* TBD print users in group */ +} + +rtems_task Init( + rtems_task_argument ignored +) +{ + struct passwd *pw; + struct group *gr; + int status = -1; + + FILE *fp = NULL; + + puts( "*** PASSWORD/GROUP TEST - 02 ***" ); + + puts( "Init - Creating /etc" ); + status = mkdir( "/etc", 0777 ); + rtems_test_assert( status == 0 ); + + puts( "Init - Creating /etc/passwd" ); + status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL ); + rtems_test_assert( status != -1 ); + + fp = fopen( "/etc/passwd", "w" ); + rtems_test_assert( fp != NULL ); + fprintf( fp, "bharath:x:-1:-a:Dummy::/:/bin/bash\n" ); + fclose( fp ); + + puts( "Init - Creating /etc/group" ); + status = mknod( "/etc/group", (S_IFREG | S_IRWXU), 0LL ); + rtems_test_assert( status != -1); + + fp = fopen( "/etc/group", "w" ); + rtems_test_assert( fp != NULL ); + fprintf( fp, "admin::1:root,su,super-user\n" ); + fclose( fp ); + + puts( "Init - setpwent() -- OK" ); + setpwent(); + + puts( "Init - setpwent() -- OK" ); + setpwent(); + + puts( "Init - setgrent() -- OK" ); + setgrent(); + + puts( "Init - setgrent() -- OK" ); + setgrent(); + + puts( "Init - getpwnam(\"root\") -- expected EINVAL" ); + pw = getpwnam( "root" ); + rtems_test_assert( !pw ); + rtems_test_assert( errno == EINVAL ); + + fp = fopen( "/etc/passwd", "w" ); + rtems_test_assert( fp != NULL ); + fprintf( fp, "rtems:x:1:1:dummy::/:/bin/bash:" ); + fclose( fp ); + + puts( "Init - getpwnam(\"root\") -- expected EINVAL" ); + pw = getpwnam( "root" ); + rtems_test_assert( !pw ); + rtems_test_assert( errno == EINVAL ); + + fp = fopen( "/etc/passwd", "w" ); + rtems_test_assert( fp != NULL ); + fprintf( fp, "user\n:x:2:2:dummy::/:/bin/sh\n" ); + fclose( fp ); + + puts( "Init - getpwnam(\"root\") -- expected EINVAL" ); + pw = getpwnam( "root" ); + rtems_test_assert( !pw ); + rtems_test_assert( errno == EINVAL ); + + puts( "Init - getgrent() -- OK" ); + gr = getgrent(); + rtems_test_assert( gr != NULL ); + print_group( gr ); + + puts( "Init - endpwent() -- OK" ); + endpwent(); + + puts( "Init - endpwent() -- OK" ); + endpwent(); + + puts( "Init - endgrent() -- OK" ); + endgrent(); + + puts( "Init - endgrent() -- OK" ); + endgrent(); + + puts( "Removing /etc/passwd" ); + status = unlink( "/etc/passwd" ); + rtems_test_assert( status == 0 ); + + puts( "Removing /etc/group" ); + status = unlink( "/etc/group" ); + rtems_test_assert( status == 0 ); + + puts( "Init - getpwnam(\"root\") -- expected EINVAL" ); + pw = getpwnam( "root" ); + rtems_test_assert( !pw ); + rtems_test_assert( errno == EINVAL ); + + puts( "Init - getgrnam(\"root\") -- expected EINVAL" ); + gr = getgrnam( "root" ); + rtems_test_assert( !gr ); + rtems_test_assert( errno == EINVAL ); + + puts( "*** END OF PASSWORD/GROUP TEST - 02 ***" ); + rtems_test_exit( 0 ); +} + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6 + +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT +#include <rtems/confdefs.h> +/* end of file */ diff --git a/testsuites/psxtests/psxpasswd02/psxpasswd02.doc b/testsuites/psxtests/psxpasswd02/psxpasswd02.doc new file mode 100644 index 0000000000..4322eabace --- /dev/null +++ b/testsuites/psxtests/psxpasswd02/psxpasswd02.doc @@ -0,0 +1,26 @@ +# +# $Id$ +# +# COPYRIGHT (c) 1989-2010. +# On-Line Applications Research Corporation (OAR). +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + +This file describes the directives and concepts tested by this test set. + +test set name: POSIX PASSWD/GROUP TEST + +directives: + ++ setpwent ++ setgrent ++ getpwnam ++ endpwent ++ endgrent + +concepts: + ++ Exercise error paths in /etc/passwd and /etc/group. diff --git a/testsuites/psxtests/psxpasswd02/psxpasswd02.scn b/testsuites/psxtests/psxpasswd02/psxpasswd02.scn new file mode 100644 index 0000000000..21b661d391 --- /dev/null +++ b/testsuites/psxtests/psxpasswd02/psxpasswd02.scn @@ -0,0 +1,24 @@ +*** PASSWORD/GROUP TEST - 02 *** +Init - Creating /etc +Init - Creating /etc/passwd +Init - Creating /etc/group +Init - setpwent() -- OK +Init - setpwent() -- OK +Init - setgrent() -- OK +Init - setgrent() -- OK +Init - getpwnam("root") -- expected EINVAL +Init - getpwnam("root") -- expected EINVAL +Init - getpwnam("root") -- expected EINVAL +Init - getgrent() -- OK + group name: admin + group password: + group ID: 1 +Init - endpwent() -- OK +Init - endpwent() -- OK +Init - endgrent() -- OK +Init - endgrent() -- OK +Removing /etc/passwd +Removing /etc/group +Init - getpwnam("root") -- expected EINVAL +Init - getgrnam("root") -- expected EINVAL +*** END OF PASSWORD/GROUP TEST - 02 *** |