|
From: <ro...@us...> - 2002-12-30 20:21:08
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/dup2
In directory sc8-pr-cvs1:/tmp/cvs-serv11854
Modified Files:
Makefile dup202.c
Added Files:
dup205.c
Log Message:
Added ported test from Airong Zhang <zh...@us...> and cleaned up some other files.
--- NEW FILE: dup205.c ---
/*
*
* Copyright (c) International Business Machines Corp., 2002
*
* 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
*/
/* Ported from SPIE, section2/iosuite/dup6.c, by Airong Zhang */
/*======================================================================
=================== TESTPLAN SEGMENT ===================
>KEYS: < dup2()
>WHAT: < Does dup return -1 on the 21st file?
>HOW: < Create up to _NFILE files and check for -1 return on the
< next attempt
< Should check NOFILE as well as _NFILE. 19-Jun-84 Dale.
>BUGS: <
======================================================================*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "test.h"
#include "usctest.h"
char *TCID = "dup205";
int TST_TOTAL = 1;
extern int Tst_count;
int local_flag;
#define PASSED 1
#define FAILED 0
/*--------------------------------------------------------------------*/
int main(ac, av)
int ac;
char *av[];
{
int *fildes ;
int ifile ;
char pfilname[40] ;
int min;
char *strcpy();
int serrno;
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
/*
* parse standard options
*/
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg);
tst_exit();
/*NOTREACHED*/
}
/*--------------------------------------------------------------------*/
local_flag = PASSED;
for (lc = 0; TEST_LOOPING(lc); lc++) {
min = getdtablesize(); /* get number of files allowed open */
fildes = (int*) malloc( (min+10)*sizeof(int) );
if( fildes == (int*) 0 ) {
tst_resm(TBROK,"malloc error\n");
tst_exit();
}
sprintf(pfilname, "./dup205.%d\n", getpid());
unlink(pfilname) ;
serrno = 0;
if( (fildes[0] = creat( pfilname, 0666 )) == -1 ) {
tst_resm(TBROK, "Cannot open first file\n" );
tst_exit();
} else {
fildes[fildes[0]] = fildes[0];
for( ifile = fildes[0] + 1 ; ifile < min + 10 ; ifile++ ) {
if( (fildes[ifile] = dup2( fildes[ifile-1], ifile )) == -1 ) {
serrno = errno;
break ;
} else {
if (fildes[ifile] != ifile) {
tst_resm(TFAIL,"got wrong descriptor number back: %d != %d",fildes[ifile], ifile);
tst_exit();
}
}
} /* end for */
if( ifile < min ) {
tst_resm(TFAIL, "Not enough files duped");
local_flag = FAILED ;
} else if ( ifile > min ) {
tst_resm(TFAIL, "Too many files duped");
local_flag = FAILED ;
}
if ((serrno != EBADF) && (serrno != EMFILE) && (serrno != EINVAL) ) {
tst_resm(TFAIL, "bad errno on dup2 failure");
local_flag = FAILED ;
}
}
/*--------------------------------------------------------------------*/
unlink(pfilname) ;
if (local_flag == PASSED) {
tst_resm(TPASS, "Test passed.\n");
} else {
tst_resm(TFAIL, "Test failed.\n");
}
} /* end for */
tst_exit();
return(0);
}
Index: Makefile
===================================================================
RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/dup2/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Makefile 7 Feb 2002 01:32:02 -0000 1.3
--- Makefile 30 Dec 2002 20:21:04 -0000 1.4
***************
*** 21,25 ****
# description : make(1) description file for the send(2) tests. #
###########################################################################
! CFLAGS+= -I../../../../include
LOADLIBES+= -L../../../../lib -lltp
--- 21,25 ----
# description : make(1) description file for the send(2) tests. #
###########################################################################
! CFLAGS+= -I../../../../include -Wall -g
LOADLIBES+= -L../../../../lib -lltp
Index: dup202.c
===================================================================
RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/dup2/dup202.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** dup202.c 27 Aug 2001 22:15:13 -0000 1.1
--- dup202.c 30 Dec 2002 20:21:05 -0000 1.2
***************
*** 54,57 ****
--- 54,58 ----
#include <usctest.h>
#include <errno.h>
+ #include <fcntl.h>
char *TCID = "dup202";
|