|
From: <ro...@us...> - 2002-12-30 20:58:32
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/dup
In directory sc8-pr-cvs1:/tmp/cvs-serv2893/testcases/kernel/syscalls/dup
Modified Files:
Makefile
Added Files:
dup06.c dup07.c
Log Message:
Added ported dup06 and dup07 tests from Airong Zhang <zh...@us...>
--- NEW FILE: dup06.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
*/
/* Pored from SPIE, section2/iosuite/dup1.c, by Airong Zhang */
/*======================================================================
=================== TESTPLAN SEGMENT ===================
>KEYS: < dup()
>WHAT: < Does dup return -1 on the 21st file?
>HOW: < Create up to _NFILE (20) 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 <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include "test.h"
#include "usctest.h"
char *TCID = "dup06";
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, j ;
int ifile ;
char pfilname[40] ;
int min;
char *strcpy();
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*/
}
/* pick up the nofiles */
min = getdtablesize();
fildes = (int *)malloc((min+5) * sizeof(int));
local_flag = PASSED;
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* Initialize fildes[_NFILE+5] - mailbug # 40805 */
for (j=0; j < min+5; j++)
fildes[j] = 0;
sprintf(pfilname, "dup06.%d\n", getpid());
unlink(pfilname) ;
if( (fildes[0] = creat( pfilname, 0666 )) == -1 ) {
tst_resm(TFAIL, "Cannot open first file\n" );
local_flag = FAILED ;
} else {
for( ifile = fildes[0] + 1 ; ifile < min+5 ; ifile++ ) {
if( (fildes[ifile] = dup( fildes[ifile-1] )) == -1 ) {
break ;
}
} /* 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 ;
}
}
/*----- ---------------------------------------------------------------*/
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);
}
--- NEW FILE: dup07.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
*/
/* Pored from SPIE, section2/iosuite/dup3.c, by Airong Zhang */
/*dup3.c*/
/*======================================================================
=================== TESTPLAN SEGMENT ===================
>KEYS: < dup()
>WHAT: < Is the access mode the same for both file descriptors?
< 0: read only?
< 1: write only?
< 2: read/write?
>HOW: < Creat a file with each access mode; dup each file descriptor;
< stat each file descriptor and compare mode of each pair
>BUGS: <
======================================================================*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "test.h"
#include "usctest.h"
char *TCID = "dup07";
int TST_TOTAL = 1;
extern int Tst_count;
int local_flag;
#define PASSED 1
#define FAILED 0
char testfile[40]= "";
/*--------------------------------------------------------------------*/
int main(int ac, char **av)
{
struct stat retbuf ;
struct stat dupbuf ;
int rdoret , wroret, rdwret;
int duprdo , dupwro, duprdwr ;
/*--------------------------------------------------------------------*/
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++) {
sprintf(testfile, "dup07.%d", getpid());
if( (rdoret = creat(testfile, 0444 )) == -1 ) {
tst_resm(TFAIL, "Unable to creat file '%s'\n", testfile) ;
local_flag = FAILED ;
} else {
if( (duprdo = dup( rdoret )) == -1 ) {
tst_resm(TFAIL, "Unable to dup '%s'\n", testfile ) ;
local_flag = FAILED ;
} else {
fstat( rdoret, &retbuf ) ;
fstat( duprdo, &dupbuf ) ;
if( retbuf.st_mode != dupbuf.st_mode )
{
tst_resm(TFAIL, "rdonly and dup do not match\n" ) ;
local_flag = FAILED ;
}
}
}
if (local_flag == PASSED) {
tst_resm(TPASS, "Test passed in read mode.\n");
} else {
tst_resm(TFAIL, "Test failed in read mode.\n");
}
/*--------------------------------------------------------------------*/
unlink(testfile);
if( (wroret = creat( testfile, 0222 )) == -1 ) {
tst_resm(TFAIL, "Unable to creat file '%s'\n", testfile ) ;
local_flag = FAILED ;
} else {
if( (dupwro = dup( wroret )) == -1 ) {
tst_resm(TFAIL, "Unable to dup '%s'\n", testfile ) ;
local_flag = FAILED ;
} else {
fstat( wroret, &retbuf ) ;
fstat( dupwro, &dupbuf ) ;
if( retbuf.st_mode != dupbuf.st_mode ) {
tst_resm(TFAIL, "wronly and dup do not match\n" ) ;
local_flag = FAILED ;
}
}
}
if (local_flag == PASSED) {
tst_resm(TPASS, "Test passed in write mode.\n");
} else {
tst_resm(TFAIL, "Test failed in write mode.\n");
}
/*--------------------------------------------------------------------*/
unlink(testfile);
if( (rdwret = creat(testfile, 0666 )) == -1 ) {
tst_resm(TFAIL, "Unable to creat file '%s'\n", testfile ) ;
local_flag = FAILED ;
} else {
if( (duprdwr = dup( rdwret )) == -1 ) {
tst_resm(TFAIL, "Unable to dup '%s'\n", testfile ) ;
local_flag = FAILED ;
} else {
fstat( rdwret, &retbuf ) ;
fstat( duprdwr, &dupbuf ) ;
if( retbuf.st_mode != dupbuf.st_mode ) {
tst_resm(TFAIL, "rdwr and dup do not match\n" ) ;
local_flag = FAILED ;
}
}
}
if (local_flag == PASSED) {
tst_resm(TPASS, "Test passed in read/write mode.\n");
} else {
tst_resm(TFAIL, "Test failed in read/write mode.\n");
}
/*--------------------------------------------------------------------*/
unlink(testfile);
if (local_flag == PASSED) {
tst_resm(TPASS, "Test passed\n");
} else {
tst_resm(TFAIL, "Test failed\n");
}
tst_exit();
} /* end for */
return(0);
}
Index: Makefile
===================================================================
RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/dup/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:58:29 -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
|