Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Duda <deo@logos-m.ru>2001-09-09 17:38:17 +0400
committerEgor Duda <deo@logos-m.ru>2001-09-09 17:38:17 +0400
commitd961def403a334176adb4c79cb02385bfca230e7 (patch)
tree3863580db025e747aa1a5cf6f69fa0be5894e426 /winsup/testsuite/winsup.api/ltp
parent92ef5188af2deecd2054462bf940f6460d127fe9 (diff)
* winsup.api/ltp/dup03.c: New test.
* winsup.api/ltp/lseek03.c: Ditto. * winsup.api/ltp/mmap001.c: Ditto. * winsup.api/ltp/read01.c: Ditto. * winsup.api/ltp/readdir01.c: Ditto. * winsup.api/ltp/rmdir05.c: Ditto. * winsup.api/ltp/sbrk01.c: Ditto. * winsup.api/ltp/select02.c: Ditto. * winsup.api/ltp/select03.c: Ditto. * winsup.api/ltp/signal03.c: Ditto. * winsup.api/ltp/stat06.c: Ditto. * winsup.api/ltp/unlink08.c: Ditto. * winsup.api/known_bugs.tcl: Update to reflect new test's known failures. * winsup.api/winsup.exp: Don't delete executable in case of unexpected pass, as well as in case of unexpected failure. * README: Update paragraph about expected failures.
Diffstat (limited to 'winsup/testsuite/winsup.api/ltp')
-rw-r--r--winsup/testsuite/winsup.api/ltp/dup03.c292
-rw-r--r--winsup/testsuite/winsup.api/ltp/lseek03.c290
-rw-r--r--winsup/testsuite/winsup.api/ltp/mmap001.c206
-rw-r--r--winsup/testsuite/winsup.api/ltp/read01.c280
-rw-r--r--winsup/testsuite/winsup.api/ltp/readdir01.c351
-rw-r--r--winsup/testsuite/winsup.api/ltp/rmdir05.c448
-rw-r--r--winsup/testsuite/winsup.api/ltp/sbrk01.c275
-rw-r--r--winsup/testsuite/winsup.api/ltp/select02.c268
-rw-r--r--winsup/testsuite/winsup.api/ltp/select03.c282
-rw-r--r--winsup/testsuite/winsup.api/ltp/signal03.c665
-rw-r--r--winsup/testsuite/winsup.api/ltp/stat06.c376
-rw-r--r--winsup/testsuite/winsup.api/ltp/unlink08.c433
12 files changed, 4166 insertions, 0 deletions
diff --git a/winsup/testsuite/winsup.api/ltp/dup03.c b/winsup/testsuite/winsup.api/ltp/dup03.c
new file mode 100644
index 000000000..4870778a7
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/dup03.c
@@ -0,0 +1,292 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : dup03
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Negative test for dup(2) (too many fds)
+ *
+ * PARENT DOCUMENT : usctpl01
+ *
+ * TEST CASE TOTAL : 1
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Richard Logan
+ *
+ * CO-PILOT : William Roske
+ *
+ * DATE STARTED : 06/94
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1.) dup(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
+ *
+ * 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/fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+
+char *TCID="dup03"; /* Test program identifier. */
+int TST_TOTAL=1; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+
+char Fname[255];
+int *Fd = NULL;
+int Nfds=0;
+
+/***********************************************************************
+ * Main
+ ***********************************************************************/
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ /*
+ * Call dup(2)
+ */
+ TEST( dup(Fd[0]) );
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ if ( STD_FUNCTIONAL_TEST ) {
+ if ( TEST_ERRNO == EMFILE ) {
+ tst_resm(TPASS, "dup(%d) Failed, errno=%d : %s", Fd[0],
+ TEST_ERRNO, strerror(TEST_ERRNO));
+ }
+ else {
+ tst_resm(TFAIL, "dup(%d) Failed, errno=%d %s, expected %d (EMFILE)",
+ Fd[0], TEST_ERRNO, strerror(TEST_ERRNO), EMFILE);
+ }
+ }
+ } else {
+ tst_resm(TFAIL, "dup(%d) returned %d, expected -1, errno:%d (EMFILE)",
+ Fd[0], TEST_RETURN, EMFILE);
+
+ /* close the new file so loops do not open too many files */
+ if (close(TEST_RETURN) == -1) {
+ tst_brkm(TBROK, cleanup, "close(%s) Failed, errno=%d : %s",
+ Fname, errno, strerror(errno));
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ long maxfds;
+
+ /*
+ * Initialize Fd in case we get a quick signal
+ */
+ maxfds = sysconf(_SC_OPEN_MAX);
+ if (maxfds < 1) {
+ tst_brkm(TBROK, cleanup,
+ "sysconf(_SC_OPEN_MAX) Failed, errno=%d : %s",
+ errno, strerror(errno));
+ }
+
+ Fd = (int *)malloc(maxfds*sizeof(int));
+ Fd[0]=-1;
+
+ /* capture signals */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+ /*
+ * open the file as many times as it takes to use up all fds
+ */
+ sprintf(Fname, "dupfile");
+ for (Nfds=1; Nfds<=maxfds; Nfds++) {
+ if ((Fd[Nfds-1] = open(Fname,O_RDWR|O_CREAT,0700)) == -1) {
+
+ Nfds--; /* on a open failure, decrement the counter */
+ if ( errno == EMFILE ) {
+ break;
+ }
+ else { /* open failed for some other reason */
+ tst_brkm(TBROK, cleanup,
+ "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
+ Fname, errno, strerror(errno));
+ }
+ }
+ }
+
+ /*
+ * make sure at least one was open and that all fds were opened.
+ */
+ if ( Nfds == 0 ) {
+ tst_brkm(TBROK, cleanup, "Unable to open at least one file");
+ }
+ if ( Nfds > maxfds ) {
+ tst_brkm(TBROK, cleanup,
+ "Unable to open enough files to use all file descriptors, tried %d",
+ maxfds);
+ }
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* close the open file we've been dup'ing */
+ if (Fd) {
+ for (; Nfds >0 ; Nfds--) {
+ if (close(Fd[Nfds-1]) == -1) {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ Fname, errno, strerror(errno));
+ }
+ Fd[Nfds]=-1;
+ }
+ free(Fd);
+ }
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+} /* End cleanup() */
+
+
diff --git a/winsup/testsuite/winsup.api/ltp/lseek03.c b/winsup/testsuite/winsup.api/ltp/lseek03.c
new file mode 100644
index 000000000..03c035cb9
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/lseek03.c
@@ -0,0 +1,290 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : lseek03
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Negative test for lseek(2) whence
+ *
+ * PARENT DOCUMENT : usctpl01
+ *
+ * TEST CASE TOTAL : 2
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Richard Logan
+ *
+ * CO-PILOT : William Roske
+ *
+ * DATE STARTED : 04/25/94
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1.) lseek(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 lseek(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
+ * lseek(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 <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+void rec_sigsys(int);
+
+char *TCID="lseek03"; /* Test program identifier. */
+int TST_TOTAL=3; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+char fname[255];
+int fd;
+int Rec_sigsys = 0;
+
+int Whences[] = { 4, -1, 7 };
+
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+
+ int ind;
+ int whence;
+
+ TST_TOTAL=sizeof(Whences)/sizeof(int);
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+
+ signal(SIGSYS, rec_sigsys);
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ for (ind=0; ind<sizeof(Whences)/sizeof(int); ind++) {
+
+ whence=Whences[ind];
+
+ /*
+ * On IRIX systems, the SIGSYS signal is also sent.
+ */
+ Rec_sigsys=0;
+
+ /*
+ * Call lseek(2)
+ */
+ TEST(lseek(fd, (long)1, whence));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ if ( TEST_ERRNO == EINVAL )
+#if defined(sgi)
+ if ( Rec_sigsys ) {
+ tst_resm(TPASS,
+ "lseek(%s, 1, %d) Failed as expected, errno=%d : %s\n\
+and SIGSYS signal was received.",
+ fname, whence, TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ tst_resm(TFAIL,
+ "lseek(%s, 1, %d) Failed as expected, errno=%d : %s\n\
+But SIGSYS signal was NOT received.",
+ fname, whence, TEST_ERRNO, strerror(TEST_ERRNO));
+ }
+#elif defined(linux) || defined (__CYGWIN__)
+ tst_resm(TPASS,
+ "lseek(%s, 1, %d) Failed, errno=%d : %s",
+ fname, whence, TEST_ERRNO, strerror(TEST_ERRNO));
+#endif
+ else
+ tst_resm(TFAIL,
+ "lseek(%s, 1, %d) Failed, errno=%d %s, expected %d(EINVAL)",
+ fname, whence, TEST_ERRNO, strerror(TEST_ERRNO),
+ EINVAL);
+ }
+
+ else
+ Tst_count++;
+ } else {
+
+ tst_resm(TFAIL, "lseek(%s, 1, %d) returned %d",
+ fname, whence, TEST_RETURN);
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/*
+ * signal handler for the SIGSYS signal.
+ */
+void
+rec_sigsys(int sig)
+{
+ Rec_sigsys++;
+
+ signal(sig, rec_sigsys);
+}
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+ sprintf(fname,"tfile_%d",getpid());
+ if ((fd = open(fname,O_RDWR|O_CREAT,0700)) == -1) {
+ tst_brkm(TBROK, cleanup,
+ "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
+ fname, errno, strerror(errno));
+ }
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* close the file we have open */
+ if (close(fd) == -1) {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, strerror(errno));
+ }
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+} /* End cleanup() */
diff --git a/winsup/testsuite/winsup.api/ltp/mmap001.c b/winsup/testsuite/winsup.api/ltp/mmap001.c
new file mode 100644
index 000000000..8ac1b3716
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/mmap001.c
@@ -0,0 +1,206 @@
+/*
+ * mmap001.c - Tests mmapping a big file and writing it once
+ *
+ * Copyright (C) 2000 Juan Quintela <quintela@fi.udc.es>
+ * Aaron Laffin <alaffin@sgi.com>
+ *
+ * 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.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#include "test.h"
+#include "usctest.h"
+
+char *TCID="mmap001";
+int TST_TOTAL=5;
+extern int Tst_count;
+static char *filename=NULL;
+static int m_opt = 0;
+static char *m_copt;
+
+void cleanup()
+{
+ /*
+ * remove the tmp directory and exit
+ */
+
+ if ( filename )
+ free(filename);
+
+ TEST_CLEANUP;
+
+ tst_rmdir();
+
+ tst_exit();
+}
+
+void setup()
+{
+ char buf[1024];
+ /*
+ * setup a default signal hander and a
+ * temporary working directory.
+ */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ tst_tmpdir();
+
+ TEST_PAUSE;
+
+ snprintf(buf,1024,"testfile.%d",getpid());
+
+ filename = strdup(buf);
+}
+
+void help()
+{
+ printf(" -m x size of mmap in pages (default 1000)\n");
+}
+
+/*
+ * add the -m option whose parameter is the
+ * pages that should be mapped.
+ */
+option_t options[] =
+{
+ { "m:", &m_opt, &m_copt },
+ { NULL, NULL, NULL }
+};
+
+int main(int argc, char * argv[])
+{
+ char *array;
+ const char *msg;
+ int i,lc;
+ int fd;
+ unsigned int pages,memsize;
+
+ if ( (msg=parse_opts(argc, argv, options, help)) != (char *) NULL )
+ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+
+ if ( m_opt )
+ {
+ memsize = pages = atoi( m_copt );
+
+ if (memsize < 1)
+ {
+ tst_brkm(TBROK, cleanup, "Invalid arg for -m: %s",m_copt);
+ }
+
+ memsize *= getpagesize(); /* N PAGES */
+
+ }
+ else
+ {
+ /*
+ * default size 1000 pages;
+ */
+ memsize = pages = 1000;
+ memsize *= getpagesize();
+ }
+
+ tst_resm(TINFO,"mmap()ing file of %u pages or %u bytes", pages,memsize);
+
+ setup();
+
+ for (lc=0; TEST_LOOPING(lc); lc++)
+ {
+ Tst_count=0;
+
+ fd = open(filename, O_RDWR | O_CREAT, 0666);
+ if ((fd == -1))
+ tst_brkm(TBROK, cleanup, "Problems opening files");
+
+ if (lseek(fd, memsize, SEEK_SET) != memsize)
+ {
+ close(fd);
+ tst_brkm(TBROK, cleanup, "Problems doing the lseek: %d: %s",
+ errno,strerror(errno));
+ }
+
+ if (write(fd,"\0",1) !=1)
+ {
+ close(fd);
+ tst_brkm(TBROK, cleanup, "Problems writing: %d: %s",
+ errno,strerror(errno));
+ }
+
+ array = mmap(0, memsize, PROT_WRITE, MAP_SHARED,fd,0);
+ if (array == (char *)MAP_FAILED)
+ {
+ tst_resm(TFAIL, "mmap() failed: %d: %s",
+ errno,strerror(errno));
+ tst_exit();
+ }
+ else
+ {
+ tst_resm(TPASS, "mmap() completed successfully.");
+ }
+
+ if ( STD_FUNCTIONAL_TEST )
+ {
+ tst_resm(TINFO,"touching mmaped memory");
+
+ for(i = 0; i < memsize; i++)
+ {
+ array[i] = (char) i;
+ }
+
+ /*
+ * seems that if the map area was bad, we'd get SEGV, hence we can
+ * indicate a PASS.
+ */
+ tst_resm(TPASS, "we're still here, mmaped area must be good");
+
+ TEST( msync(array, memsize, MS_SYNC) );
+
+ if ( TEST_RETURN == -1 )
+ {
+ tst_resm(TFAIL, "msync() failed: errno: %d: %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+ }
+ else
+ {
+ tst_resm(TPASS, "msync() was successful");
+ }
+
+ } /* STD_FUNCTIONAL_TEST */
+
+ TEST( munmap(array, memsize) );
+
+ if ( TEST_RETURN == -1 )
+ {
+ tst_resm(TFAIL, "munmap() failed: errno: %d: %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+ }
+ else
+ {
+ tst_resm(TPASS, "munmap() was successful");
+ }
+
+ close(fd);
+ unlink(filename);
+ }
+ cleanup();
+ return 0;
+}
diff --git a/winsup/testsuite/winsup.api/ltp/read01.c b/winsup/testsuite/winsup.api/ltp/read01.c
new file mode 100644
index 000000000..1a54afeb0
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/read01.c
@@ -0,0 +1,280 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : read01
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Basic test for read(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.) read(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 read(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
+ * read(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/fcntl.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+/*
+ * Set READ_BLOCK_SIZE to the block size of the system.
+ */
+#ifdef linux
+#define READ_BLOCK_SIZE DEV_BSIZE
+#else
+#ifdef __CYGWIN__
+#define READ_BLOCK_SIZE S_BLKSIZE
+#else
+#define READ_BLOCK_SIZE BSIZE
+#endif
+#endif
+
+extern void setup();
+extern void cleanup();
+
+
+
+char *TCID="read01"; /* Test program identifier. */
+int TST_TOTAL=1; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+int exp_enos[]={0, 0};
+char fname[255], *malloc();
+int fd, i;
+int offset=0;
+char *s;
+
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
+ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /* set the expected errnos... */
+ TEST_EXP_ENOS(exp_enos);
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ if (write(fd, s, READ_BLOCK_SIZE) == -1) {
+ tst_brkm(TBROK, cleanup,
+ "write(%s, %s, %d) Failed, errno=%d : %s",
+ fname, s, READ_BLOCK_SIZE, errno, strerror(errno));
+ }
+ offset+=READ_BLOCK_SIZE;
+ if (lseek(fd, (long)(offset-READ_BLOCK_SIZE), 0) == -1) {
+ tst_brkm(TBROK, cleanup,
+ "lseek(%s, %ld, 0) Failed, errno=%d : %s",
+ fname, (long)(offset-READ_BLOCK_SIZE), errno, strerror(errno));
+ }
+ /*
+ * Call read(2)
+ */
+ TEST(read(fd, s, READ_BLOCK_SIZE));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "read(fd, s, READ_BLOCK_SIZE) Failed, errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "read(pfds) returned %d", TEST_RETURN);
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+ if ((s = malloc(READ_BLOCK_SIZE)) == NULL) {
+ tst_brkm(TBROK, cleanup,
+ "malloc(%d) Failed, errno=%d : %s",
+ READ_BLOCK_SIZE, errno, strerror(errno));
+ }
+ (void) memset(s, '*', READ_BLOCK_SIZE);
+ for (i=0; i < READ_BLOCK_SIZE; i++) {
+ if ( s[i] != '*' ) {
+ tst_brkm(TBROK, cleanup,
+ "File Data pattern not setup correctly : expected * at s[%d] : found %c",
+ i, s[i]);
+ }
+ }
+ sprintf(fname,"./tfile_%d",getpid());
+ if ((fd=open(fname,O_RDWR|O_CREAT,0700)) == -1) {
+ tst_brkm(TBROK, cleanup,
+ "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
+ fname, errno, strerror(errno));
+ }
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ if (close(fd) == -1 ) {
+ tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
+ fname, errno, strerror(errno));
+ }
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+
+} /* End cleanup() */
diff --git a/winsup/testsuite/winsup.api/ltp/readdir01.c b/winsup/testsuite/winsup.api/ltp/readdir01.c
new file mode 100644
index 000000000..e8b5bd5a5
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/readdir01.c
@@ -0,0 +1,351 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : readdir01
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : write multiple files and try to find them with readdir
+ *
+ * TEST CASE TOTAL :
+ *
+ * WALL CLOCK TIME :
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Nate Straz
+ *
+ * CO-PILOT :
+ *
+ * DATE STARTED : 02/16/2001
+ *
+ * INITIAL RELEASE : Linux 2.4.x
+ *
+ * TEST CASES
+ *
+ * 1.) Create n files and check that readdir() finds n files
+ *
+ * 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 readdir(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
+ * readdir(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/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+ /* test.h and usctest.h are the two header files that are required by the
+ * quickhit package. They contain function and macro declarations which you
+ * can use in your test programs
+ */
+#include "test.h"
+#include "usctest.h"
+
+ /* The setup and cleanup functions are basic parts of a test case. These
+ * steps are usually put in separate functions for clarity. The help function
+ * is only needed when you are adding new command line options.
+ */
+void setup();
+void help();
+void cleanup();
+
+char *TCID="readdir01"; /* Test program identifier. */
+int TST_TOTAL=2; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+extern int Tst_nobuf;
+
+int exp_enos[]={0, 0};
+
+#define BASENAME "readdirfile"
+
+char Basename[255];
+char Fname[255];
+int Nfiles=0;
+
+/* To add command line options you need to declare a structure to pass to
+ * parse_opts(). options is the structure used in this example. The format is
+ * the string that should be added to optstring in getopt(3), an integer that
+ * will be used as a flag if the option is given, and a pointer to a string that
+ * should receive the optarg parameter from getopt(3). Here we add a -N
+ * option. Long options are not supported at this time.
+ */
+char *Nfilearg;
+int Nflag=0;
+
+/* for test specific parse_opts options */
+option_t options[] = {
+ { "N:", &Nflag, &Nfilearg }, /* -N #files */
+ { NULL, NULL, NULL }
+};
+
+/***********************************************************************
+ * Main
+ ***********************************************************************/
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+ int cnt;
+ int nfiles, fd;
+ char fname[255];
+ DIR *test_dir;
+ struct dirent *dptr;
+
+ Tst_nobuf=1;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ /* start off by parsing the command line options. We provide a function
+ * that understands many common options to control looping. If you are not
+ * adding any new options, pass NULL in place of options and &help.
+ */
+ if ( (msg=parse_opts(ac, av, options, &help)) ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ if ( Nflag ) {
+ if (sscanf(Nfilearg, "%i", &Nfiles) != 1 ) {
+ tst_brkm(TBROK, NULL, "--N option arg is not a number");
+ tst_exit();
+ }
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ /* Next you should run a setup routine to make sure your environment is
+ * sane.
+ */
+ setup();
+
+ /* set the expected errnos... */
+ TEST_EXP_ENOS(exp_enos);
+
+ /***************************************************************
+ * check looping state
+ ***************************************************************/
+ /* TEST_LOOPING() is a macro that will make sure the test continues
+ * looping according to the standard command line args.
+ */
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ if ( Nfiles )
+ nfiles = Nfiles;
+ else
+ /* min of 10 links and max of a 100 links */
+ nfiles = (lc%90)+10;
+
+ /* create a bunch of files to look at */
+ for(cnt=0; cnt < nfiles; cnt++) {
+
+ sprintf(fname, "%s%d", Basename, cnt);
+ if ((fd = open(fname, O_RDWR|O_CREAT, 0700)) == -1) {
+ tst_brkm(TBROK, cleanup,
+ "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s", fname, errno, strerror(errno));
+ } else if (write(fd, "hello\n", 6) < 0) {
+ tst_brkm(TBROK, cleanup,
+ "write(%s, \"hello\\n\", 6) Failed, errno=%d : %s", fname, errno, strerror(errno));
+ } else if (close(fd) < 0) {
+ tst_res(TWARN, "close(%s) Failed, errno=%d : %s",
+ fname, errno, strerror(errno));
+ }
+ }
+
+ if ((test_dir = opendir(".")) == NULL) {
+ tst_resm(TFAIL, "opendir(\".\") Failed, errno=%d : %s",
+ errno, strerror(errno));
+ } else {
+ /* count the entries we find to see if any are missing */
+ cnt = 0;
+ errno = 0;
+ while ( (dptr = readdir(test_dir)) ) {
+ if (strcmp(dptr->d_name, ".") && strcmp(dptr->d_name, ".."))
+ cnt++;
+ }
+
+ if (errno != 0) {
+ tst_resm(TFAIL, "readir(test_dir) Failed on try %d, errno=%d : %s",
+ cnt, errno, strerror(errno));
+ }
+ if (cnt == nfiles) {
+ tst_resm(TPASS, "found all %d that were created", nfiles);
+ } else if (cnt > nfiles) {
+ tst_resm(TFAIL, "found more files than were created");
+ tst_resm(TINFO, "created: %d, found: %d", nfiles, cnt);
+ } else {
+ tst_resm(TFAIL, "found less files than were created");
+ tst_resm(TINFO, "created: %d, found: %d", nfiles, cnt);
+ }
+ }
+
+ /* Here we clean up after the test case so we can do another iteration.
+ */
+ for(cnt=0; cnt < nfiles; cnt++) {
+
+ sprintf(fname, "%s%d", Basename, cnt);
+
+ if (unlink(fname) == -1) {
+ tst_res(TWARN, "unlink(%s) Failed, errno=%d : %s",
+ Fname, errno, strerror(errno));
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * help
+ ***************************************************************/
+/* The custom help() function is really simple. Just write your help message to
+ * standard out. Your help function will be called after the standard options
+ * have been printed
+ */
+void
+help()
+{
+ printf(" -N #files : create #files files every iteration\n");
+}
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* You will want to enable some signal handling so you can capture
+ * unexpected signals like SIGSEGV.
+ */
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ /* Pause if that option was specified */
+ /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to
+ * fork the test with the -c option. You want to make sure you do this
+ * before you create your temporary directory.
+ */
+ TEST_PAUSE;
+
+ /* If you are doing any file work, you should use a temporary directory. We
+ * provide tst_tmpdir() which will create a uniquely named temporary
+ * directory and cd into it. You can now create files in the current
+ * directory without worrying.
+ */
+ tst_tmpdir();
+
+ sprintf(Basename, "%s_%d.", BASENAME, getpid());
+}
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* If you use a temporary directory, you need to be sure you remove it. Use
+ * tst_rmdir() to do it automatically.
+ */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+}
diff --git a/winsup/testsuite/winsup.api/ltp/rmdir05.c b/winsup/testsuite/winsup.api/ltp/rmdir05.c
new file mode 100644
index 000000000..b363735c0
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/rmdir05.c
@@ -0,0 +1,448 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : rmdir05
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Functionality Tests for rmdir(2)
+ *
+ * PARENT DOCUMENT : rmstds02
+ *
+ * TEST CASE TOTAL : 6
+ *
+ * WALL CLOCK TIME : 2
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Bill Branum
+ *
+ * CO-PILOT : Steve Shaw
+ *
+ * DATE STARTED : 4/23/92
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ * rmdir(2) test for errno(s) EINVAL, EMLINK, EFAULT
+ *
+ * INPUT SPECIFICATIONS
+ * The standard options for system call tests are accepted.
+ * (See the parse_opts(3) man page).
+ *
+ * ENVIRONMENTAL NEEDS
+ * No run-time environmental needs.
+ *
+ * DETAILED DESCRIPTION
+ * Verify that rmdir(2) returns a value of -1 and sets errno
+ * to indicate the error.
+ *
+ * Setup:
+ * Setup signal handling.
+ * Create a temporary directory and make it current.
+ * 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.
+ * If doing functional test
+ * check the errno returned and print result message
+ *
+ * Cleanup:
+ * Print errno log and/or timing stats if options given.
+ * Remove the temporary directory.
+ * Exit.
+ *
+ *
+ *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
+
+#include <errno.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+
+void setup();
+void cleanup();
+
+
+extern char *get_high_address();
+
+char *TCID="rmdir05"; /* Test program identifier. */
+int TST_TOTAL=6; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines. */
+struct stat stat_buf; /* Stat buffer used for verification. */
+char dir_name[256]; /* Array to hold directory name. */
+
+
+int
+main(int argc, char **argv)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ /*
+ * TEST CASE: 1
+ * path points to the current directory
+ */
+
+ /* Call rmdir(2) */
+ TEST(rmdir("."));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ }
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ if ( TEST_RETURN == -1 ) {
+#if defined(sgi)
+ if (TEST_ERRNO == EINVAL) {
+#elif defined(linux) || defined (__CYGWIN__)
+ if (TEST_ERRNO & (EBUSY | ENOTEMPTY)) {
+#endif
+
+ /* For functionality tests, verify that the
+ * directory wasn't removed.
+ */
+ if (stat(".",&stat_buf) == -1){
+ tst_resm(TFAIL,"rmdir(\".\") removed the current working directory when it should have failed.");
+ } else {
+ tst_resm(TPASS,"rmdir(\".\") failed to remove the current working directory. Returned %d : %s",TEST_ERRNO,strerror(TEST_ERRNO));
+ }
+ } else {
+#if defined(sgi)
+ tst_resm(TFAIL,"rmdir(\".\") failed with errno %d : %s but expected %d (EINVAL)",TEST_ERRNO,strerror(TEST_ERRNO),EINVAL);
+#elif defined(linux) || defined (__CYGWIN__)
+ tst_resm(TFAIL,"rmdir(\".\") failed with errno %d : %s but expected %d (EBUSY)",TEST_ERRNO,strerror(TEST_ERRNO),EBUSY);
+#endif
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir(\".\") succeeded unexpectedly.");
+ }
+ }
+
+
+ /*
+ * TEST CASE: 2
+ * path points to the "." (dot) entry of a directory
+ */
+#if defined(linux) || defined (__CYGWIN__)
+ tst_resm(TCONF, "rmdir on \"dir/.\" supported on Linux");
+#elif defined(sgi)
+ /* Call rmdir(2) */
+ TEST(rmdir("dir1/."));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ }
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ if ( TEST_RETURN == -1 ) {
+ if (TEST_ERRNO == EINVAL) {
+
+ /* For functionality tests, verify that the
+ * directory wasn't removed.
+ */
+ if (stat("dir1/.",&stat_buf) == -1){
+ tst_resm(TFAIL,"rmdir(\"dir1/.\") removed the \".\" entry of a directory when it should have failed.");
+ } else {
+ tst_resm(TPASS,"rmdir(\"dir1/.\") failed to remove the \".\" entry of a directory. Returned %d : %s",TEST_ERRNO,strerror(TEST_ERRNO));
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir(\"dir1/.\") failed with errno %d : %s but expected %d (EINVAL)",TEST_ERRNO,strerror(TEST_ERRNO),EINVAL);
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir(\"dir1/.\") - path points to the \".\" entry of a directory succeeded unexpectedly.");
+ }
+ }
+#endif
+
+#if defined(sgi)
+ /*
+ * TEST CASE: 3
+ * the directory has been linked
+ */
+ tst_resm(TCONF, "linked directories not valid on IRIX");
+#elif defined(linux)
+ tst_resm(TCONF, "linked directories test not implemented on Linux");
+#elif defined(CRAY)
+
+
+ /* Call rmdir(2) */
+ TEST(rmdir("dir2"));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ }
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ if ( TEST_RETURN == -1 ) {
+ if (TEST_ERRNO == EMLINK) {
+ /* For functionality tests, verify that the directory wasn't
+ * removed.
+ */
+ if (stat("dir2",&stat_buf) == -1){
+ tst_resm(TFAIL,"rmdir(\"dir2\") removed a directory with multiple links when it should have failed.");
+ } else {
+ tst_resm(TPASS,"rmdir(\"dir2\") failed to remove a directory with multiple links. Returned %d : %s",TEST_ERRNO,strerror(TEST_ERRNO));
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir(\"dir2\") failed with errno %d : %s but expected %d (EMLINK)",TEST_ERRNO,strerror(TEST_ERRNO),EMLINK);
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir(\"dir2\") - the directory has been linked succeeded unexpectedly.");
+ }
+ }
+#endif /* linux */
+
+
+ /*
+ * TEST CASE: 4
+ * path argument points below the minimum allocated address space
+ */
+
+
+ /* Call rmdir(2) */
+ TEST(rmdir((char *)-1));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ }
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ if ( TEST_RETURN == -1 ) {
+ if (TEST_ERRNO == EFAULT) {
+ tst_resm(TPASS,"rmdir() - path argument points below the minimum allocated address space failed as expected with errno %d : %s",TEST_ERRNO,strerror(TEST_ERRNO));
+ } else {
+ tst_resm(TFAIL,"rmdir() - path argument points below the minimum allocated address space failed with errno %d : %s but expected %d (EFAULT)",TEST_ERRNO,strerror(TEST_ERRNO),EFAULT);
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir() - path argument points below the minimum allocated address space succeeded unexpectedly.");
+ }
+ }
+
+ /*
+ * TEST CASE: 5
+ * path argument points above the maximum allocated address space
+ */
+
+
+ /* Call rmdir(2) */
+ TEST(rmdir( get_high_address()));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ }
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ if ( TEST_RETURN == -1 ) {
+ if (TEST_ERRNO == EFAULT) {
+ tst_resm(TPASS,"rmdir() - path argument points above the maximum allocated address space failed as expected with errno %d : %s",TEST_ERRNO,strerror(TEST_ERRNO));
+ } else {
+ tst_resm(TFAIL,"rmdir() - path argument points above the maximum allocated address space failed with errno %d : %s but expected %d (EFAULT)",TEST_ERRNO,strerror(TEST_ERRNO),EFAULT);
+ }
+ } else {
+ tst_resm(TFAIL,"rmdir() - path argument points above the maximum allocated address space succeeded unexpectedly.");
+ }
+ }
+
+ /*
+ * TEST CASE: 6
+ * able to remove a directory
+ */
+
+ /* Create a directory. */
+ if (mkdir(dir_name,0777) != 0){
+ tst_brkm(TBROK,cleanup,"mkdir(\"%s\") failed with errno %d : %s",dir_name,errno,strerror(errno));
+ }
+
+ /* Call rmdir(2) */
+ TEST(rmdir(dir_name));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL,"rmdir(\"%s\") failed when it should have passed. Returned %d : %s",dir_name,TEST_ERRNO,strerror(TEST_ERRNO));
+ } else {
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+
+ /* Verify the directory was removed. */
+ if (stat(dir_name,&stat_buf) != 0){
+ tst_resm(TPASS,"rmdir(\"%s\") removed the directory as expected.",dir_name);
+ } else {
+ tst_resm(TFAIL,"rmdir(\"%s\") returned a zero exit status but failed to remove the directory.",dir_name);
+ }
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void setup()
+{
+ /* capture signals */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ /* Create a temporary directory and make it current. */
+ tst_tmpdir();
+
+ /* Create a directory. */
+ if (mkdir("dir1",0777) == -1){
+ tst_brkm(TBROK,cleanup,"mkdir() failed to create dir1.");
+ }
+
+#if defined(CRAY)
+ /* NOTE: linking directories is NOT valid on IRIX */
+
+ /* Create a directory that has multiple links to it. */
+ if (mkdir("dir2",0777) == -1){
+ tst_brkm(TBROK,cleanup,"mkdir() failed to create dir2.");
+ } else {
+ if (system("runcmd `get_attrib -A link` dir2 mlink_dir > link.out 2>&1") != 0){
+ tst_brk(TBROK,"link.out",cleanup,"link failed to link dir2 and mlink_dir.");
+ }
+ }
+
+#endif
+
+ /* Create a unique directory name. */
+ sprintf(dir_name,"./dir_%d",getpid());
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+#if defined(CRAY)
+ /* NOTE: setup was not done on IRIX */
+ /* Unlink the directory. */
+ if (system("runcmd `get_attrib -A unlink` dir2 > unlink.out 2>&1") != 0){
+ tst_res(TWARN,"unlink.out","unlink failed to unlink dir2.");
+ }
+#endif
+
+ /*
+ * Remove the temporary directory.
+ */
+ tst_rmdir();
+
+ /*
+ * Exit with a return value appropriate for the results.
+ */
+ tst_exit();
+
+} /* End cleanup() */
diff --git a/winsup/testsuite/winsup.api/ltp/sbrk01.c b/winsup/testsuite/winsup.api/ltp/sbrk01.c
new file mode 100644
index 000000000..a302d5d0d
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/sbrk01.c
@@ -0,0 +1,275 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : sbrk01
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : Basic test for sbrk(2)
+ *
+ * PARENT DOCUMENT : usctpl01
+ *
+ * TEST CASE TOTAL : 2
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : William Roske
+ *
+ * CO-PILOT : Dave Fenner
+ *
+ * DATE STARTED : 06/05/92
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1.) sbrk(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 sbrk(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
+ * sbrk(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 <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/types.h>
+
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+
+
+
+char *TCID="sbrk01"; /* Test program identifier. */
+int TST_TOTAL=2; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+int Increment; /* Amount to make change size by */
+
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+ long tret;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit(0);
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+
+ /*
+ * TEST CASE:
+ * Increase by 8192 bytes
+ */
+ Increment = 8192;
+
+ /* Call sbrk(2) */
+#if defined(sgi)
+ tret=(long)sbrk(Increment); /* Remove -64 IRIX compiler warning */
+ TEST_ERRNO=errno;
+#else
+ TEST(sbrk(Increment));
+ tret=TEST_RETURN;
+#endif
+
+ /* check return code */
+ if ( tret == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "sbrk - Increase by 8192 bytes failed, errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "sbrk - Increase by 8192 bytes returned %d",
+ tret);
+ }
+ }
+
+
+ /*
+ * TEST CASE:
+ * Decrease to original size
+ */
+ Increment=(Increment * -1);
+
+ /* Call sbrk(2) */
+#ifdef CRAY
+ TEST(sbrk(Increment));
+ tret=TEST_RETURN;
+#else
+ tret=(long)sbrk(Increment);
+ TEST_ERRNO=errno;
+#endif
+
+ /* check return code */
+ if ( tret == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL, "sbrk - Decrease to original size failed, errno=%d : %s",
+ TEST_ERRNO, strerror(TEST_ERRNO));
+ } else {
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* No Verification test, yet... */
+ tst_resm(TPASS, "sbrk - Decrease to original size returned %d", tret);
+ }
+ }
+
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ /* make a temp dir and cd to it */
+ tst_tmpdir();
+
+
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+
+
+ /* remove files and temp dir */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+} /* End cleanup() */
+
+
diff --git a/winsup/testsuite/winsup.api/ltp/select02.c b/winsup/testsuite/winsup.api/ltp/select02.c
new file mode 100644
index 000000000..8b2669564
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/select02.c
@@ -0,0 +1,268 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : select02
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : select of system pipe fds
+ *
+ * PARENT DOCUMENT : usctpl01
+ *
+ * TEST CASE TOTAL : 1
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Richard Logan
+ *
+ * CO-PILOT : Glen Overby
+ *
+ * DATE STARTED : 02/24/93
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1.) select(2) to fd of system pipe with no I/O and small timeout
+ *
+ * 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 select(2) system call. It is intended
+ * to provide a limited exposure of the system call, for now.
+ *
+ * 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 <errno.h>
+#include <signal.h>
+#include <fcntl.h> /* For open system call parameters. */
+#include <signal.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+
+char *TCID="select02"; /* Test program identifier. */
+int TST_TOTAL=1; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+int Fd[2];
+fd_set saved_Readfds, saved_Writefds;
+fd_set Readfds, Writefds;
+
+/***********************************************************************
+ * MAIN
+ ***********************************************************************/
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+ struct timeval timeout;
+ long test_time = 0; /* in usecs */
+
+
+ /***************************************************************
+ * parse standard options, and exit if there is an error
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ /*
+ * Assigning the specified seconds within the timeval structure.
+ */
+
+ test_time = ((lc%2000)*100000); /* 100 milli-seconds */
+
+ /*
+ * Bound the time to a value less than 60 seconds
+ */
+
+ if ( test_time > 1000000 * 60 )
+ test_time = test_time % (1000000 * 60);
+
+ timeout.tv_sec = test_time / 1000000;
+ timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
+
+ Readfds = saved_Readfds;
+ Writefds = saved_Writefds;
+
+ /* Call the system call being tested. */
+
+ TEST(select(5, &Readfds, &Writefds, 0, &timeout));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL,
+ "%d select(5, &Readfds, &Writefds, 0, &timeout) failed, errno=%d\n",
+ lc, errno);
+ } else {
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* Perform functional verification here */
+ tst_resm(TPASS,
+ "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs",
+ test_time);
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ /* create a temporary directory and go to it */
+ tst_tmpdir();
+
+ if (pipe(Fd) == -1 ) {
+ tst_brkm(TBROK, cleanup, "pipe(&Fd) failed, errno=%d", errno);
+ }
+
+ /*
+ * Initializing and assigning the standard output file descriptor to
+ * fd_set for select.
+ */
+
+ FD_ZERO(&saved_Readfds);
+ FD_ZERO(&saved_Writefds);
+ FD_SET(Fd[0], &saved_Readfds);
+ FD_SET(Fd[1], &saved_Writefds);
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* remove temporary directory and all files in it. */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+} /* End cleanup() */
+
+
diff --git a/winsup/testsuite/winsup.api/ltp/select03.c b/winsup/testsuite/winsup.api/ltp/select03.c
new file mode 100644
index 000000000..d0959cb35
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/select03.c
@@ -0,0 +1,282 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : select03
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : select of fd of a named-pipe (FIFO)
+ *
+ * PARENT DOCUMENT : usctpl01
+ *
+ * TEST CASE TOTAL : 1
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Richard Logan
+ *
+ * CO-PILOT : Glen Overby
+ *
+ * DATE STARTED : 02/24/93
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1.) select(2) of fd of a named-pipe (FIFO) with no I/O and small timeout value
+ *
+ * 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 select(2) system call. It is intended
+ * to provide a limited exposure of the system call, for now.
+ *
+ * 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 <errno.h>
+#include <signal.h>
+#include <fcntl.h> /* For open system call parameters. */
+#include <signal.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+
+
+#include "test.h"
+#include "usctest.h"
+
+#define FILENAME "select03"
+
+extern void setup();
+extern void cleanup();
+
+char *TCID="select03"; /* Test program identifier. */
+int TST_TOTAL=1; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+int Fd;
+fd_set saved_Readfds, saved_Writefds;
+fd_set Readfds, Writefds;
+
+
+/***********************************************************************
+ * MAIN
+ ***********************************************************************/
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+ struct timeval timeout;
+ long test_time = 0; /* in usecs */
+
+
+ /***************************************************************
+ * parse standard options, and exit if there is an error
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ /*
+ * Assigning the specified seconds within the timeval structure.
+ */
+
+ test_time = ((lc%2000)*100000); /* 100 milli-seconds */
+
+ /*
+ * Bound the time to a value less than 60 seconds
+ */
+
+ if ( test_time > 1000000 * 60 )
+ test_time = test_time % (1000000 * 60);
+
+ timeout.tv_sec = test_time / 1000000;
+ timeout.tv_usec = test_time - (timeout.tv_sec * 1000000);
+
+ Readfds = saved_Readfds;
+ Writefds = saved_Writefds;
+
+ /* Call the system call being tested. */
+
+ TEST(select(5, &Readfds, &Writefds, 0, &timeout));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ TEST_ERROR_LOG(TEST_ERRNO);
+ tst_resm(TFAIL,
+ "%d select(5, &Readfds, &Writefds, 0, &timeout) failed errno=%d\n",
+ lc, errno);
+ } else {
+
+ /***************************************************************
+ * only perform functional verification if flag set (-f not given)
+ ***************************************************************/
+ if ( STD_FUNCTIONAL_TEST ) {
+ /* Perform functional verification here */
+ tst_resm(TPASS,
+ "select(5, &Readfds, &Writefds, 0, &timeout) timeout = %ld usecs",
+ test_time);
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ /* create a temporary directory and go to it */
+ tst_tmpdir();
+
+
+ /* make and open FIFO */
+ if ( mkfifo(FILENAME, 0777) == -1 ) {
+ tst_brkm(TBROK, cleanup, "mkfifo(%s, 0777) failed, errno=%d",
+ FILENAME, errno);
+ }
+
+ if ((Fd=open(FILENAME, O_RDWR)) == -1 ) {
+ tst_brkm(TBROK, cleanup, "open(%s, O_RDWR) failed, errno=%d",
+ FILENAME, errno);
+ }
+
+ /*
+ * Initializing and assigning the standard output file descriptor to
+ * fd_set for select.
+ */
+
+ FD_ZERO(&saved_Readfds);
+ FD_ZERO(&saved_Writefds);
+ FD_SET(Fd, &saved_Readfds);
+ FD_SET(Fd, &saved_Writefds);
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* remove temporary directory and all files in it. */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+} /* End cleanup() */
+
+
diff --git a/winsup/testsuite/winsup.api/ltp/signal03.c b/winsup/testsuite/winsup.api/ltp/signal03.c
new file mode 100644
index 000000000..38ba72b3c
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/signal03.c
@@ -0,0 +1,665 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/***********************************************************************************
+ *
+ * OS Test - Silicon Graphics, Inc. Eagan, Minnesota
+ *
+ * TEST IDENTIFIER : signal03 Boundary value and other invalid value checking
+ * of signal setup and signal sending.
+ *
+ * PARENT DOCUMENT : sgntds01 Signal System Call
+ *
+ * AUTHOR : Dave Baumgartner
+ * : Rewrote 12/92 by Richard Logan
+ *
+ * CO-PILOT : Barrie Kletscher
+ *
+ * DATE STARTED : 10/17/85
+ *
+ * TEST ITEMS
+ *
+ * 1. SIGKILL can not be set to be caught, errno:EINVAL (POSIX).
+ * 2. SIGKILL can not be caught.
+ * 3. SIGKILL can not be set to be ignored, errno:EINVAL (POSIX).
+ * 4. SIGKILL can not be ignored.
+ * 5. SIGKILL can not be reset to default, errno:EINVAL (POSIX.
+ *
+ * ENVIRONMENTAL NEEDS
+ *
+ * NONE
+ *
+ * SPECIAL PROCEDURAL REQUIREMENTS
+ *
+ * None
+ *
+ * INTERCASE DEPENDENCIES
+ *
+ * 2 depends on 1 and 4 on 3.
+ *
+ * DETAILED DESCRIPTION
+ *
+ * main()
+ * Call catch_test to test setup and catching of SIGKILL.
+ *
+ *
+ * Call ignore_test to test setup and ignoring of SIGKILL.
+ *
+ *
+ * Call sigdfl_test to test setting SIGKILL to default.
+ *
+ * * END OF MAIN *
+ *
+ *
+ * catch_test()
+ *
+ * fork a child
+ * if this is the parent
+ * sleep to let child start.
+ * send sig to child.
+ * wait for the child to terminate.
+ *
+ * if the termination status of the child equals the signal sent to it
+ * Test item 1 PASSED the child was killed.
+ * else if status equals the exit value of SIG_CAUGHT
+ * Test item 2 FAILED sig was caught.
+ * else
+ * Test item 2 FAILED because the child was not killed
+ * but sig was not caught either.
+ *
+ * else this the child
+ * set exit_val to SIG_NOT_CAUGHT.
+ * set to catch sig, where the interrupt routine just sets
+ * exit_val to SIG_CAUGHT.
+ *
+ * If the return value and errno, after trying to set to catch sig,
+ * do not indicate that an error has occurred.
+ * Test item 1 FAILED bad return, return value:X, errno:X.
+ * else
+ * Test item 1 PASSED sig was not set to be caught.
+ *
+ * pause until the parent sends a signal.
+ * The child should be killed by the signal but if not exit
+ * with exit_val.
+ *
+ * * End of catch_test. *
+ *
+ *
+ * ignore_test()
+ *
+ * fork a child
+ * if this is the parent
+ * sleep to let child start.
+ * send SIGKILL to child.
+ * wait for the child to terminate.
+ *
+ * if the termination status of the child equals SIGKILL
+ * Test item 4 PASSED the child was killed.
+ * else if the status equals the exit value of SIG_IGNORED
+ * Test item 4 FAILED SIGKILL was ignored.
+ *
+ * else this the child
+ *
+ * If the return value and errno, after trying to set to ignore SIGKILL,
+ * do not indicate that an error has occurred.
+ * Test item 3 FAILED bad return, return value:X, errno:X.
+ * else
+ * Test item 3 PASSED SIGKILL was not set to be ignored.
+ *
+ * pause until the parent sends SIGKILL.
+ * The child should be killed by the signal but if not exit
+ * with SIG_IGNORED.
+ *
+ * * End of ignore_test. *
+ *
+ *
+ * sigdfl_test()
+ *
+ * If the return value and errno, after trying to set to SIGKILL to default,
+ * do not indicate that an error has occurred.
+ * Test item 5 FAILED bad return, return value:X, errno:X.
+ * else
+ * Test item 5 PASSED SIGKILL was not set to default.
+ *
+ * * End of sigdfl_test. *
+ *
+ * BUGS/NOTES
+ * Since the system call under test is executed in the child, no
+ * timings on this system call will be reported.
+ *
+***********************************************************************************/
+
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+void do_test();
+void sigdfl_test();
+void update_timings();
+
+#if defined(linux)
+# define SIG_PF sig_t /* This might need to be sighandler_t on some systems */
+#elif defined(__CYGWIN__)
+typedef void (*sighandler_t) (int);
+#define SIG_PF sighandler_t
+#endif
+
+#define SIG_CAUGHT 1
+#define SIG_NOT_CAUGHT 0
+#define SIG_IGNORED 5
+#define TIMED_OUT 99
+
+#define TIMEOUT 20
+
+#define GO_FLAG 1
+#define ERROR_FLAG 2
+#define PASS_FLAG 3
+#define FAIL_FLAG 4
+
+#define IGNORE_TEST 1
+#define CATCH_TEST 2
+
+#define MAXMESG 150 /* The Maximum message that can be created. */
+
+int exit_val; /* Global variable, used to tell whether the */
+ /* child exited instead of being killed. */
+extern int errno; /* errno holds the error value returned by */
+ /* a system call. */
+char mesg[MAXMESG]; /* Holds messages to pass to tst_res. */
+
+struct ipc_t {
+ int status;
+ char mesg[MAXMESG];
+ struct tblock timings;
+} Ipc_info;
+
+char *TCID = "signal03";
+int TST_TOTAL = 5;
+extern int Tst_count; /* count of test items completed */
+
+int Pid; /* Return value from fork. */
+
+long Tret;
+
+/***********************************************************************
+ * M A I N
+ ***********************************************************************/
+int
+main(argc, argv)
+int argc;
+char **argv;
+{
+ int lc;
+ const char *msg;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+ errno=-4;
+
+ /*
+ * Call catch_test to test setup and catching of SIGKILL.
+ */
+ (void) do_test(CATCH_TEST, Tst_count);
+
+ /*
+ * Call ignore_test to test setup and ignoring of SIGKILL.
+ */
+ (void) do_test(IGNORE_TEST, Tst_count);
+
+ /*
+ * Call sigdfl_test to test setting SIGKILL to default.
+ */
+ (void) sigdfl_test();
+
+ }
+
+ cleanup();
+
+ return 0;
+} /*End of main*/
+
+/***********************************************************************
+ *
+ ***********************************************************************/
+void
+do_test(test_case, tst_count)
+int test_case;
+int tst_count;
+{
+ int term_stat; /* Termination status of the child returned to */
+ /* the parent. */
+ char string[30];
+ int fd1[2]; /* ipc */
+ int rd_sz; /* size of read */
+ void p_timeout_handler();
+ void c_timeout_handler();
+ void catchsig();
+
+ Tst_count = tst_count;
+
+ /*
+ * Create a pipe of ipc
+ */
+ if ( pipe(fd1) == -1 ) {
+ sprintf(mesg,
+ "pipe system call failed, Errno: %d, Error message: %s",
+ errno,strerror(errno));
+ tst_resm(TBROK,mesg);
+ tst_resm(TBROK,mesg);
+ return;
+ }
+
+ /*
+ * Cause the read to return 0 once EOF is encountered and the
+ * read to return -1 if pipe is empty.
+ */
+
+ if ( fcntl(fd1[0], F_SETFL, O_NONBLOCK) == -1 ) {
+ sprintf(mesg, "fcntl(fd1[0], F_SETFL, O_NONBLOCK) failed: errno=%d",
+ errno);
+ tst_resm(TBROK,mesg);
+ tst_resm(TBROK,mesg);
+ close(fd1[0]);
+ close(fd1[1]);
+ return;
+ }
+
+ if ((Pid = fork()) > 0) { /* parent */
+
+ signal(SIGALRM, p_timeout_handler);
+
+ alarm(TIMEOUT);
+
+ close(fd1[1]); /* close write side */
+
+ /*
+ * Deal with child's messages.
+ * Only the GO_FLAG status will allow parent to
+ * go on. All pipe io will be in the ipc_t structure sizes
+ * to avoid reading part of next message.
+ */
+ while ( 1 ) {
+
+ while ( (rd_sz=read(fd1[0], (char *)&Ipc_info, sizeof(Ipc_info))) != 0 ) {
+ if ( rd_sz > 0 )
+ break; /* read something */
+ }
+
+ if ( rd_sz == 0 ) { /* if EOF encountered */
+ sprintf(mesg, "child's pipe is closed before 'go' message received");
+ tst_resm(TBROK, Ipc_info.mesg);
+ tst_resm(TBROK, Ipc_info.mesg);
+ close(fd1[0]);
+ return;
+ }
+
+ else if ( Ipc_info.status == GO_FLAG ) {
+ break; /* go on */
+ }
+ else if ( Ipc_info.status == ERROR_FLAG ) {
+ tst_resm(TBROK, "From child: %s", Ipc_info.mesg);
+ tst_resm(TBROK, "From child: %s", Ipc_info.mesg);
+ close(fd1[0]);
+ return;
+ }
+ else if ( Ipc_info.status == PASS_FLAG ) {
+
+ if ( STD_FUNCTIONAL_TEST )
+ tst_resm(TPASS, "From child: %s", Ipc_info.mesg);
+ else
+ Tst_count++;
+ update_timings(Ipc_info.timings);
+ }
+ else if ( Ipc_info.status == FAIL_FLAG ) {
+ tst_resm(TFAIL, "From child: %s", Ipc_info.mesg);
+ update_timings(Ipc_info.timings);
+ }
+ else {
+ tst_resm(TINFO, "Unknown message from child: %s", mesg);
+ }
+ }
+
+ /*
+ * Send the signal SIGKILL to the child.
+ */
+ if (kill(Pid,SIGKILL) == -1)
+ {
+ /*
+ * The kill system call failed.
+ */
+ sprintf(mesg,
+ "kill(Pid,SIGKILL) failed, Errno: %d, Error message: %s",
+ errno,strerror(errno));
+ tst_resm(TBROK,mesg);
+ tst_resm(TBROK,mesg);
+ close(fd1[0]);
+ return;
+ }
+
+ /*
+ * Wait for the child to terminate and check the termination status.
+ */
+ if (wait(&term_stat) == -1) {
+ /*
+ * The wait system call failed.
+ */
+ sprintf(mesg,
+ "Wait system call failed. Errno: %d, Error message: %s",
+ errno,strerror(errno));
+ tst_resm(TBROK,mesg);
+ tst_resm(TBROK,mesg);
+ close(fd1[0]);
+ return;
+ }
+ else if ( STD_FUNCTIONAL_TEST ) {
+ if ((term_stat & 0377) == SIGKILL) {
+ /*
+ * The child was killed by the signal sent,
+ * which is correct.
+ */
+ tst_resm(TPASS,"The child was killed by SIGKILL.");
+ }
+ else if ( (term_stat >> 8) == TIMED_OUT ) {
+ sprintf(mesg, "child exited with a timed out exit status");
+ tst_resm(TBROK,mesg);
+ }
+ else {
+ if ((term_stat >> 8) == SIG_IGNORED && test_case == IGNORE_TEST ) {
+ sprintf(mesg,
+ "SIGKILL was ignored by child after sent by parent.");
+ }
+ else if ((term_stat >> 8) == SIG_CAUGHT && test_case == CATCH_TEST ) {
+ sprintf(mesg,
+ "SIGKILL was caught by child after sent by parent.");
+ }
+ else {
+ sprintf(mesg,
+ "Child's termination status is unexpected. Status: %d (%#o).",
+ term_stat, term_stat);
+ }
+ tst_resm(TFAIL, mesg);
+ }
+ }
+ else {
+ Tst_count++; /* increment test counter */
+ }
+ close(fd1[0]);
+
+ } /* End of parent. */
+ else if (Pid == 0) {
+ /*
+ * This is the child.
+ * Set up to ignore/catch SIGKILL and check the return values.
+ */
+ errno=0;
+ if ( test_case == IGNORE_TEST ) {
+ exit_val = SIG_IGNORED;
+ strcpy(string, "signal(SIGKILL, SIG_IGN)");
+
+ Tret=(long)signal(SIGKILL, SIG_IGN);
+ TEST_ERRNO=errno;
+ }
+ else {
+ exit_val = SIG_NOT_CAUGHT;
+ strcpy(string, "signal(SIGKILL, catchsig)");
+ Tret=(long)signal(SIGKILL, catchsig);
+ TEST_ERRNO=errno;
+ }
+ Ipc_info.timings=tblock;
+
+ if ( (SIG_PF)Tret == SIG_ERR ) {
+ if ( TEST_ERRNO == EINVAL ) {
+ sprintf(Ipc_info.mesg, "%s ret:%ld SIG_ERR (%ld) as expected",
+ string, Tret, (long)SIG_ERR);
+ Ipc_info.status = PASS_FLAG;
+ }
+ else {
+ sprintf(Ipc_info.mesg,
+ "%s ret:%ld, errno:%d expected ret:%ld, errno:%d",
+ string, Tret, TEST_ERRNO, (long)SIG_ERR, EINVAL);
+ Ipc_info.status = FAIL_FLAG;
+ }
+
+ write(fd1[1], (char *)&Ipc_info, sizeof(Ipc_info));
+ }
+ else {
+ /*
+ * The child was not allowed to set the signal to
+ * be ignored and errno was correct.
+ */
+ sprintf(Ipc_info.mesg,
+ "%s ret:%ld, errno:%d expected ret:%ld, errno:%d",
+ string, Tret, TEST_ERRNO, (long)SIG_ERR, EINVAL);
+ Ipc_info.status = FAIL_FLAG;
+ write(fd1[1], (char *)&Ipc_info, sizeof(Ipc_info));
+ }
+
+ /*
+ * tell parent we are ready - setup by child is done
+ */
+ Ipc_info.status = GO_FLAG;
+ write(fd1[1], (char *)&Ipc_info, sizeof(Ipc_info));
+
+ /*
+ * Set the alarm to wake up from the pause below if
+ * the parents signal is ignored.
+ */
+ signal(SIGALRM, p_timeout_handler);
+ alarm(TIMEOUT);
+
+ /*
+ * Pause until the parent sends a signal or until alarm is received.
+ */
+ pause();
+
+ exit(exit_val);
+
+
+ } /* End of child. */
+ else {
+ /*
+ * The fork system call failed.
+ */
+ sprintf(mesg,
+ "Fork system call failed. Errno: %d, Error message: %s",
+ errno,strerror(errno));
+ tst_resm(TBROK,mesg);
+ tst_resm(TBROK,mesg);
+ close(fd1[0]);
+ close(fd1[1]);
+ return;
+ }
+
+} /* End of do_test. */
+
+/***********************************************************************
+ * sigdfl_test - test for attempt to set SIGKILL to default
+ ***********************************************************************/
+void
+sigdfl_test()
+{
+ /*
+ * Try to set SIGKILL to default and check the return values.
+ */
+ errno=-4;
+
+ Tret=(long)signal(SIGKILL,SIG_DFL);
+ TEST_RETURN=Tret;
+ TEST_ERRNO=errno;
+
+
+ if ( (SIG_PF)TEST_RETURN == SIG_ERR ) {
+ if ( STD_FUNCTIONAL_TEST ) {
+ if ( TEST_ERRNO != EINVAL ) {
+ sprintf(mesg,
+ "signal(SIGKILL,SIG_DFL) ret:%d, errno:%d expected ret:-1, errno:%d",
+ TEST_RETURN, TEST_ERRNO, EINVAL);
+ tst_resm(TFAIL, mesg);
+ }
+ else {
+ sprintf(mesg,
+ "signal(SIGKILL,SIG_DFL) ret:%d, errno:%d as expected.",
+ TEST_RETURN, TEST_ERRNO);
+ tst_resm(TPASS, mesg);
+ }
+ }
+ else
+ Tst_count++;
+ }
+ else {
+ sprintf(mesg,
+ "signal(SIGKILL,SIG_DFL) ret:%d, errno:%d expected ret:-1, errno:%d",
+ TEST_RETURN, TEST_ERRNO, EINVAL);
+ tst_resm(TFAIL, mesg);
+ }
+
+} /* End of sigdfl_test. */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ /* capture signals */
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+
+ /* make and change to a temporary directory */
+ tst_tmpdir();
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+} /* End setup() */
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+
+ TEST_CLEANUP;
+
+ /*
+ * remove the temporary directory and exit with
+ * return code appropriate for results
+ */
+
+ tst_rmdir();
+
+ tst_exit();
+
+} /* End cleanup() */
+
+/***********************************************************************
+ * Signal handler routine that used by the parent to handler
+ * a time out situation. It will attempt to kill the child and
+ * call cleanup.
+ ***********************************************************************/
+void
+p_timeout_handler()
+{
+ kill(Pid, SIGKILL);
+ cleanup();
+}
+
+/***********************************************************************
+ * Signal handler routine that used by the child to handle
+ * a time out situation. It will set a global varaible and return
+ * if called.
+ ***********************************************************************/
+void
+c_timeout_handler()
+{
+ exit_val = TIMED_OUT;
+ return;
+}
+
+/***********************************************************************
+ * This signal handling routine will set a global variable and return
+ * if called.
+ ***********************************************************************/
+void
+catchsig()
+{
+ exit_val = SIG_CAUGHT;
+ return;
+}
+
+/***********************************************************************
+ * Update timing information
+ ***********************************************************************/
+void
+update_timings(atblock)
+struct tblock atblock;
+{
+ tblock.tb_max += atblock.tb_max;
+ tblock.tb_min += atblock.tb_min;
+ tblock.tb_total += atblock.tb_total;
+ tblock.tb_count += atblock.tb_count;
+}
diff --git a/winsup/testsuite/winsup.api/ltp/stat06.c b/winsup/testsuite/winsup.api/ltp/stat06.c
new file mode 100644
index 000000000..f9fd0a90f
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/stat06.c
@@ -0,0 +1,376 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : stat06
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : stat(2) negative path testcases
+ *
+ * PARENT DOCUMENT : None
+ *
+ * TEST CASE TOTAL : 7
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Richard Logan
+ *
+ * CO-PILOT : William Roske
+ *
+ * DATE STARTED : 03/30/94
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1-7) See Testcases structure below.
+ *
+ * INPUT SPECIFICATIONS
+ * The standard options for system call tests are accepted.
+ * (See the parse_opts(3) man page).
+ * -h : print help and exit
+ *
+ * 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
+ * The libcuts.a and libsys.a libraries must be included in
+ * the compilation of this test.
+ *
+ * SPECIAL PROCEDURAL REQUIREMENTS
+ * None
+ *
+ * INTERCASE DEPENDENCIES
+ * None
+ *
+ * DETAILED DESCRIPTION
+ * This is a Phase I test for the stat(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
+ * stat(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/fcntl.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <unistd.h>
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+
+char *TCID="stat06"; /* Test program identifier. */
+int TST_TOTAL=8; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+int exp_enos[]={0, 0};
+
+int high_address_setup();
+int longpath_setup();
+int no_setup();
+int filepath_setup();
+char Longpathname[PATH_MAX+2];
+char High_address[64];
+struct stat statbuf;
+jmp_buf sig11_recover;
+void sig11_handler(int sig);
+
+struct test_case_t {
+ char *pathname;
+ struct stat *stbuf;
+ char *desc;
+ int exp_errno;
+ int (*setupfunc)();
+} Test_cases[] = {
+ { "nonexistfile", &statbuf, "non-existent file", ENOENT, no_setup},
+ { "", &statbuf, "path is empty string", ENOENT, no_setup},
+ { "nefile/file", &statbuf, "path contains a non-existent file",
+ ENOENT, no_setup },
+#ifndef __CYGWIN__
+ { "file/file", &statbuf, "path contains a regular file",
+ ENOTDIR, filepath_setup },
+#endif
+ { Longpathname, &statbuf, "pathname too long", ENAMETOOLONG, longpath_setup },
+ { High_address, &statbuf, "address beyond address space", EFAULT, high_address_setup },
+ { (char *)-1, &statbuf, "negative address", EFAULT, no_setup },
+ { "file", (struct stat *)-1, "invalid struct stat address", EFAULT, filepath_setup },
+ { NULL, NULL, NULL, 0, no_setup }
+};
+
+/***********************************************************************
+ * Main
+ ***********************************************************************/
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+ char *fname;
+ char *desc;
+ int ind;
+ struct stat *stbuf;
+ struct sigaction sa, osa;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /* set the expected errnos... */
+ TEST_EXP_ENOS(exp_enos);
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+
+ for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {
+
+ fname = Test_cases[ind].pathname;
+ desc = Test_cases[ind].desc;
+ stbuf = Test_cases[ind].stbuf;
+
+ if (stbuf == (struct stat *)-1) {
+ /* special sig11 case */
+ sa.sa_handler = &sig11_handler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ sigaction(SIGSEGV, NULL, &osa);
+ sigaction(SIGSEGV, &sa, NULL);
+
+ if (setjmp(sig11_recover)) {
+ TEST_RETURN = -1;
+ TEST_ERRNO = EFAULT;
+ } else {
+ TEST(stat(fname, stbuf));
+ }
+ sigaction(SIGSEGV, &osa, NULL);
+ } else {
+ /*
+ * Call stat(2)
+ */
+
+ TEST(stat(fname, stbuf));
+ }
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ if ( STD_FUNCTIONAL_TEST ) {
+ if ( TEST_ERRNO == Test_cases[ind].exp_errno )
+ tst_resm(TPASS, "stat(<%s>, &stbuf) Failed, errno=%d",
+ desc, TEST_ERRNO);
+ else
+ tst_resm(TFAIL,
+ "stat(<%s>, &stbuf) Failed, errno=%d, expected errno:%d",
+ desc, TEST_ERRNO, Test_cases[ind].exp_errno);
+ }
+ else
+ Tst_count++;
+ } else {
+ tst_resm(TFAIL,
+ "stat(<%s>, &stbuf) returned %d, expected -1, errno:%d",
+ desc, TEST_RETURN, Test_cases[ind].exp_errno);
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ int ind;
+
+ /* capture signals */
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+ for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {
+ Test_cases[ind].setupfunc();
+ }
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+
+} /* End cleanup() */
+
+/******************************************************************
+ * no_setup() - does nothing
+ ******************************************************************/
+int
+no_setup()
+{
+ return 0;
+}
+
+/******************************************************************
+ * high_address_setup() - generates an address that should cause a segfault
+ ******************************************************************/
+int
+high_address_setup()
+{
+ int ind;
+
+ for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {
+ if ( Test_cases[ind].pathname == High_address ) {
+ /*if ( strcmp(Test_cases[ind].pathname, HIGH_ADDRESS) == 0 ) { ***/
+ Test_cases[ind].pathname = (char *)(sbrk(0)+5);
+ break;
+ }
+ }
+ return 0;
+
+}
+
+/******************************************************************
+ * longpath_setup() - creates a filename that is too long
+ ******************************************************************/
+int
+longpath_setup()
+{
+ int ind;
+
+ for(ind=0; ind<= PATH_MAX+1; ind++) {
+ Longpathname[ind] = 'a';
+ }
+ return 0;
+
+}
+
+/******************************************************************
+ * filepath_setup() creates a file the exists that we will treat as a directory
+ ******************************************************************/
+int
+filepath_setup()
+{
+ int fd;
+
+ if ( (fd=creat("file", 0777)) == -1 ) {
+ tst_brkm(TBROK, cleanup, "creat(file) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ close(fd);
+ return 0;
+}
+
+/******************************************************************
+ * sig11_handler() - our segfault recover hack
+ ******************************************************************/
+void
+sig11_handler(int sig)
+{
+ longjmp(sig11_recover, 1);
+}
diff --git a/winsup/testsuite/winsup.api/ltp/unlink08.c b/winsup/testsuite/winsup.api/ltp/unlink08.c
new file mode 100644
index 000000000..a426aa03f
--- /dev/null
+++ b/winsup/testsuite/winsup.api/ltp/unlink08.c
@@ -0,0 +1,433 @@
+/*
+ * 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., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, 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$ */
+/**********************************************************
+ *
+ * OS Test - Silicon Graphics, Inc.
+ *
+ * TEST IDENTIFIER : unlink08
+ *
+ * EXECUTED BY : anyone
+ *
+ * TEST TITLE : unlink(2) negative testcases
+ *
+ * PARENT DOCUMENT : usctpl01
+ *
+ * TEST CASE TOTAL : 3
+ *
+ * WALL CLOCK TIME : 1
+ *
+ * CPU TYPES : ALL
+ *
+ * AUTHOR : Richard Logan
+ *
+ * CO-PILOT : William Roske
+ *
+ * DATE STARTED : 03/30/94
+ *
+ * INITIAL RELEASE : UNICOS 7.0
+ *
+ * TEST CASES
+ *
+ * 1-3) See Testcases structure below.
+ *
+ * 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 unlink(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
+ * unlink(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/fcntl.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+void setup();
+void cleanup();
+
+
+
+char *TCID="unlink08"; /* Test program identifier. */
+int TST_TOTAL=3; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+
+int exp_enos[]={0, 0};
+
+int unwrite_dir_setup();
+int unsearch_dir_setup();
+int dir_setup();
+int no_setup();
+
+struct test_case_t {
+ char *pathname;
+ char *desc;
+ int (*setupfunc)();
+ int exp_ret; /* -1 means error, 0 means != -1 */
+ int exp_errno;
+} Test_cases[] = {
+ { "unwrite_dir/file", "unwritable directory", unwrite_dir_setup,
+ -1, EACCES},
+ { "unsearch_dir/file", "unsearchable directory", unsearch_dir_setup,
+ -1, EACCES },
+#ifdef linux
+ { "regdir", "directory", dir_setup, -1, EISDIR},
+#else
+ { "regdir", "directory", dir_setup, -1, EPERM},
+#endif
+
+ { NULL, NULL, no_setup, -1, 0 }
+};
+
+/***********************************************************************
+ * Main
+ ***********************************************************************/
+int
+main(int ac, char **av)
+{
+ int lc; /* loop counter */
+ const char *msg; /* message returned from parse_opts */
+ char *fname;
+ char *desc;
+ int ind;
+
+ /***************************************************************
+ * parse standard options
+ ***************************************************************/
+ if ( (msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *) NULL ) {
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_exit();
+ }
+
+ /***************************************************************
+ * perform global setup for test
+ ***************************************************************/
+ setup();
+
+ /* set the expected errnos... */
+ TEST_EXP_ENOS(exp_enos);
+
+ /***************************************************************
+ * check looping state if -c option given
+ ***************************************************************/
+ for (lc=0; TEST_LOOPING(lc); lc++) {
+
+ /* reset Tst_count in case we are looping. */
+ Tst_count=0;
+
+
+ for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {
+
+ fname = Test_cases[ind].pathname;
+ desc = Test_cases[ind].desc;
+
+ /*
+ * Call unlink(2)
+ */
+ TEST(unlink(fname));
+
+ /* check return code */
+ if ( TEST_RETURN == -1 ) {
+ if ( Test_cases[ind].exp_ret == -1 ) { /* neg test */
+ if ( STD_FUNCTIONAL_TEST ) {
+ if ( TEST_ERRNO == Test_cases[ind].exp_errno )
+ tst_resm(TPASS, "unlink(<%s>) Failed, errno=%d",
+ desc, TEST_ERRNO);
+ else
+ tst_resm(TFAIL,
+ "unlink(<%s>) Failed, errno=%d, expected errno:%d",
+ desc, TEST_ERRNO, Test_cases[ind].exp_errno);
+ }
+ else
+ Tst_count++;
+ }
+ else {
+ tst_resm(TFAIL, "unlink(<%s>) Failed, errno=%d",
+ desc, TEST_ERRNO);
+ }
+ } else {
+ if ( Test_cases[ind].exp_ret == -1 ) {
+ tst_resm(TFAIL,
+ "unlink(<%s>) returned %d, expected -1, errno:%d",
+ desc, TEST_RETURN, Test_cases[ind].exp_errno);
+ }
+ else if ( STD_FUNCTIONAL_TEST ) {
+ tst_resm(TPASS,
+ "unlink(<%s>) returned %d",
+ desc, TEST_RETURN);
+ }
+ else
+ Tst_count++;
+ Test_cases[ind].setupfunc(1);
+ }
+ }
+
+ } /* End for TEST_LOOPING */
+
+ /***************************************************************
+ * cleanup and exit
+ ***************************************************************/
+ cleanup();
+
+ return 0;
+} /* End main */
+
+/***************************************************************
+ * setup() - performs all ONE TIME setup for this test.
+ ***************************************************************/
+void
+setup()
+{
+ int ind;
+ int postest = 0;
+
+ /* capture signals */
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+ /* Pause if that option was specified */
+ TEST_PAUSE;
+
+ if ( geteuid() == 0 ) {
+ postest++;
+ }
+
+ for (ind=0; Test_cases[ind].desc != NULL; ind++ ) {
+ if ( Test_cases[ind].exp_errno == EACCES && postest )
+ Test_cases[ind].exp_ret=0; /* set as a pos test */
+ Test_cases[ind].setupfunc(0);
+ }
+
+} /* End setup() */
+
+
+/***************************************************************
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ ***************************************************************/
+void
+cleanup()
+{
+ chmod("unwrite_dir", 0777);
+ chmod("unsearch_dir", 0777);
+
+ /*
+ * print timing stats if that option was specified.
+ * print errno log if that option was specified.
+ */
+ TEST_CLEANUP;
+
+ /* Remove tmp dir and all files in it */
+ tst_rmdir();
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+
+} /* End cleanup() */
+
+/******************************************************************
+ *
+ ******************************************************************/
+int
+unwrite_dir_setup(flag)
+int flag;
+{
+ int fd;
+
+ if ( ! flag ) { /* initial setup */
+ if (mkdir("unwrite_dir", 0777) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "mkdir(unwrite_dir, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+
+ if ( (fd=creat("unwrite_dir/file", 0777)) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ close(fd);
+
+ if ( chmod("unwrite_dir", 0555) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "chmod(unwrite_dir, 0555) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ }
+ else { /* resetup */
+ if ( chmod("unwrite_dir", 0777) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "chmod(unwrite_dir, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+
+ if ( (fd=creat("unwrite_dir/file", 0777)) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ close(fd);
+
+ if ( chmod("unwrite_dir", 0555) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "chmod(unwrite_dir, 0555) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ }
+ return 0;
+}
+
+/******************************************************************
+ *
+ ******************************************************************/
+int
+unsearch_dir_setup(flag)
+int flag;
+{
+ int fd;
+
+ if ( ! flag ) { /* initial setup */
+ if (mkdir("unsearch_dir", 0777) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "mkdir(unsearch_dir, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+
+ if ( (fd=creat("unsearch_dir/file", 0777)) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ close(fd);
+
+ if ( chmod("unsearch_dir", 0666) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "chmod(unsearch_dir, 0666) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ }
+ else { /* resetup */
+ if ( chmod("unsearch_dir", 0777) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "chmod(unsearch_dir, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+
+ if ( (fd=creat("unsearch_dir/file", 0777)) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ close(fd);
+
+ if ( chmod("unsearch_dir", 0666) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "chmod(unsearch_dir, 0666) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ }
+ return 0;
+}
+
+/******************************************************************
+ *
+ ******************************************************************/
+int
+dir_setup(flag)
+int flag;
+{
+ if (mkdir("regdir", 0777) == -1 ) {
+ tst_brkm(TBROK, cleanup,
+ "mkdir(unwrite_dir, 0777) failed, errno:%d %s",
+ errno, strerror(errno));
+ }
+ return 0;
+}
+
+/******************************************************************
+ *
+ ******************************************************************/
+int
+no_setup(flag)
+int flag;
+{
+ return 0;
+}