mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 14:18:20 +00:00
Added tests in support of the file system infrastructure.
This commit is contained in:
@@ -11,6 +11,10 @@ PROJECT_ROOT = @PROJECT_ROOT@
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/directory.cfg
|
||||
|
||||
SUB_DIRS=support psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 \
|
||||
POSIX_DIRS=psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 \
|
||||
psx09 psx10 psx11 psx12
|
||||
|
||||
POSIX_FILES_DIRS=file01 readdir dup stat mount psx13
|
||||
|
||||
SUB_DIRS=support $(POSIX_DIRS) $(POSIX_FILES_DIRS)
|
||||
|
||||
|
||||
81
c/src/tests/psxtests/filesupp/test_cat.c
Normal file
81
c/src/tests/psxtests/filesupp/test_cat.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* A test support function which performs a crude version of
|
||||
* "cat" so you can look at specific parts of a file.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* test_cat routine
|
||||
*/
|
||||
|
||||
unsigned char test_cat_buffer[ 1024 ];
|
||||
|
||||
void test_cat(
|
||||
char *file,
|
||||
int offset_arg,
|
||||
int length
|
||||
)
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
int is_printable = 0;
|
||||
int my_length;
|
||||
int i;
|
||||
unsigned char c;
|
||||
int count = 0;
|
||||
off_t offset = (off_t)offset_arg;
|
||||
|
||||
my_length = (length) ? length : sizeof( test_cat_buffer );
|
||||
assert( my_length <= sizeof( test_cat_buffer ) );
|
||||
|
||||
fd = open( file, O_RDONLY );
|
||||
if ( fd == -1 ) {
|
||||
printf( "test_cat: open( %s ) failed : %s\n", file, strerror( errno ) );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
for ( ;; ) {
|
||||
status = lseek( fd, offset, SEEK_SET );
|
||||
assert( !status );
|
||||
|
||||
status = read( fd, test_cat_buffer, sizeof(test_cat_buffer) );
|
||||
if ( status <= 0 ) {
|
||||
if (!is_printable)
|
||||
printf( "(%d)", count );
|
||||
puts( "" );
|
||||
break;
|
||||
}
|
||||
|
||||
for ( i=0 ; i<status ; i++ ) {
|
||||
c = test_cat_buffer[i];
|
||||
if (isprint(c) || isspace(c)) {
|
||||
if (!is_printable) {
|
||||
printf( "(%d)", count );
|
||||
count = 0;
|
||||
is_printable = 1;
|
||||
}
|
||||
putchar(c);
|
||||
} else {
|
||||
is_printable = 0;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
offset += status;
|
||||
}
|
||||
|
||||
status = close( fd );
|
||||
assert( !status );
|
||||
}
|
||||
60
c/src/tests/psxtests/filesupp/test_extend.c
Normal file
60
c/src/tests/psxtests/filesupp/test_extend.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* A test support function which extends the file to the specified
|
||||
* length. This handles the implied open(), lseek(), write(), and close()
|
||||
* operations.
|
||||
*
|
||||
* The defined behavior is a seek() followed by a write() extends the file
|
||||
* and zero fills the new length part.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* test_extend routine
|
||||
*/
|
||||
|
||||
void test_extend(
|
||||
char *file,
|
||||
off_t offset
|
||||
)
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
char c = 0;
|
||||
|
||||
fd = open( file, O_WRONLY );
|
||||
if ( fd == -1 ) {
|
||||
printf( "test_extend: open( %s ) failed : %s\n", file, strerror( errno ) );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
status = lseek( fd, offset - 1, SEEK_SET );
|
||||
assert( !status );
|
||||
|
||||
status = write( fd, &c, 1 );
|
||||
if ( status == -1 ) {
|
||||
printf( "test_extend: write( %s ) failed : %s\n", file, strerror( errno ) );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
if ( status != 1 ) {
|
||||
printf( "test_extend: write( %s ) only wrote %d of %d bytes\n",
|
||||
file, status, 1 );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
status = close( fd );
|
||||
assert( !status );
|
||||
}
|
||||
59
c/src/tests/psxtests/filesupp/test_write.c
Normal file
59
c/src/tests/psxtests/filesupp/test_write.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* A test support function which performs a write() and
|
||||
* handles implied open(), lseek(), write(), and close() operations.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* test_write routine
|
||||
*/
|
||||
|
||||
void test_write(
|
||||
char *file,
|
||||
off_t offset,
|
||||
char *buffer
|
||||
)
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
int length;
|
||||
|
||||
|
||||
length = strlen( buffer );
|
||||
|
||||
fd = open( file, O_WRONLY );
|
||||
if ( fd == -1 ) {
|
||||
printf( "test_write: open( %s ) failed : %s\n", file, strerror( errno ) );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
status = lseek( fd, offset, SEEK_SET );
|
||||
assert( !status );
|
||||
|
||||
status = write( fd, buffer, length );
|
||||
if ( status == -1 ) {
|
||||
printf( "test_write: write( %s ) failed : %s\n", file, strerror( errno ) );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
if ( status != length ) {
|
||||
printf( "test_write: write( %s ) only wrote %d of %d bytes\n",
|
||||
file, status, length );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
status = close( fd );
|
||||
assert( !status );
|
||||
}
|
||||
63
c/src/tests/psxtests/psx13/Makefile.in
Normal file
63
c/src/tests/psxtests/psx13/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
@SET_MAKE@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
RTEMS_ROOT = @top_srcdir@
|
||||
PROJECT_ROOT = @PROJECT_ROOT@
|
||||
|
||||
TEST=psx13
|
||||
|
||||
MANAGERS=all
|
||||
|
||||
# C source names, if any, go here -- minus the .c
|
||||
C_PIECES=main test
|
||||
C_FILES=$(C_PIECES:%=%.c)
|
||||
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
|
||||
|
||||
H_FILES=
|
||||
|
||||
DOCTYPES=scn
|
||||
DOCS=$(DOCTYPES:%=$(TEST).%)
|
||||
|
||||
SRCS=$(DOCS) $(C_FILES) $(H_FILES)
|
||||
OBJS=$(C_O_FILES)
|
||||
|
||||
PRINT_SRCS=$(DOCS)
|
||||
|
||||
PGM=${ARCH}/$(TEST).exe
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/leaf.cfg
|
||||
|
||||
#
|
||||
# (OPTIONAL) Add local stuff here using +=
|
||||
#
|
||||
|
||||
DEFINES +=
|
||||
CPPFLAGS +=
|
||||
CFLAGS +=
|
||||
|
||||
LD_PATHS +=
|
||||
LD_LIBS +=
|
||||
LDFLAGS +=
|
||||
|
||||
#
|
||||
# Add your list of files to delete here. The config files
|
||||
# already know how to delete some stuff, so you may want
|
||||
# to just run 'make clean' first to see what gets missed.
|
||||
# 'make clobber' already includes 'make clean'
|
||||
#
|
||||
|
||||
CLEAN_ADDITIONS +=
|
||||
CLOBBER_ADDITIONS +=
|
||||
|
||||
all: ${ARCH} $(SRCS) $(PGM)
|
||||
$(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
|
||||
$(INSTALL) $(srcdir)/$(TEST).scn \
|
||||
${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn
|
||||
|
||||
${PGM}: $(OBJS) $(LINK_FILES)
|
||||
$(make-exe)
|
||||
40
c/src/tests/psxtests/psx13/main.c
Normal file
40
c/src/tests/psxtests/psx13/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Simple test program -- simplified version of sample test hello.
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1998.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* Copyright assigned to U.S. Government, 1994.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.OARcorp.com/rtems/license.html.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#define TEST_INIT
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
void test_main( void );
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
test_main();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
0
c/src/tests/psxtests/psx13/psx13.scn
Normal file
0
c/src/tests/psxtests/psx13/psx13.scn
Normal file
687
c/src/tests/psxtests/psx13/test.c
Normal file
687
c/src/tests/psxtests/psx13/test.c
Normal file
@@ -0,0 +1,687 @@
|
||||
/*
|
||||
* Psx13
|
||||
* Chris Bond (working under Jennifer's account)
|
||||
*
|
||||
* This test exercises the following routines:
|
||||
*
|
||||
* device_lseek - test implemented
|
||||
* dup - test implemented
|
||||
* dup2 - test implemented
|
||||
* fdatasync - test implemented
|
||||
* fsync - test implemented
|
||||
* pathconf - test implemented
|
||||
* fpathconf - test implemented
|
||||
* pipe - test implemented
|
||||
* umask - test implemented
|
||||
* utime - test implemented
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1998.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* Copyright assigned to U.S. Government, 1994.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.OARcorp.com/rtems/license.html.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/libio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*-------------------------------------------------------------------
|
||||
* InitFiles function
|
||||
*
|
||||
* Initializes the three files to be used in the test.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: fopen, fprintf, fwrite, FILE are available
|
||||
* actions: creates testfile1, a text file with 'a'..'z' listed 4 times.
|
||||
* creates testfile2, a text file with 'a'..'z' listed 4 times.
|
||||
* creates testfile3, a binary file with 0..9 listed 4 times.
|
||||
* returns: TRUE if files opened successfully.
|
||||
* FALSE if fail on file open for write.
|
||||
*
|
||||
* ------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int InitFiles (void) {
|
||||
|
||||
int count;
|
||||
FILE *fp1, *fp2, *fp3;
|
||||
char letter;
|
||||
int number;
|
||||
int retval;
|
||||
|
||||
fp1 = fopen("testfile1.tst", "wt");
|
||||
fp2 = fopen("testfile2.tst", "wt");
|
||||
fp3 = fopen("testfile4.tst", "wb");
|
||||
|
||||
if ((fp1 != NULL) && (fp2 != NULL) && (fp3 !=NULL)) {
|
||||
|
||||
letter = 'a';
|
||||
|
||||
for (count=0 ; count<(26*4); ++count) {
|
||||
fprintf (fp1, "%c", letter);
|
||||
fprintf (fp2, "%c", letter);
|
||||
|
||||
++letter;
|
||||
if (letter > 'z')
|
||||
letter = 'a';
|
||||
}
|
||||
|
||||
number = 0;
|
||||
|
||||
for (count = 0; count <40; ++count) {
|
||||
|
||||
fwrite (&number, 1, sizeof(int), fp3);
|
||||
|
||||
++number;
|
||||
if (number > 9)
|
||||
number = 0;
|
||||
}
|
||||
|
||||
fclose(fp1);
|
||||
fclose(fp2);
|
||||
fclose(fp3);
|
||||
|
||||
retval = TRUE;
|
||||
}
|
||||
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* DeviceLSeekTest function
|
||||
*
|
||||
* Hits the device_lseek code by lseeking on the console.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: lseek available
|
||||
* actions: hits lseek with some dummy arguments.
|
||||
* returns: value of return from lseek.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int DeviceLSeekTest (void) {
|
||||
|
||||
int error = -1, retval = FALSE;
|
||||
|
||||
int fd = open ("/dev/console", O_RDONLY);
|
||||
|
||||
error = lseek(fd, 5, SEEK_SET);
|
||||
|
||||
if (error == 0)
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return (retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* DupTest function
|
||||
*
|
||||
* Hits the dup code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: dup, open, close, fcntl available.
|
||||
* actions: Gets a file descriptor(fd1) for test file1.
|
||||
* dups fd1 to fd2.
|
||||
* sets fd1 to append mode
|
||||
* checks fd2 to ensure it's in append mode, also.
|
||||
* returns: success if fd2 is indeed a copy of fd1.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int DupTest(void) {
|
||||
|
||||
int fd1, fd2;
|
||||
|
||||
int flags = 0, retval = FALSE;
|
||||
|
||||
fd1 = open ("testfile1.tst", O_RDONLY);
|
||||
fd2 = dup(fd1);
|
||||
|
||||
if (fd2 != -1) {
|
||||
|
||||
fcntl(F_SETFL, fd1, O_APPEND);
|
||||
flags = fcntl(F_GETFL, fd2);
|
||||
|
||||
close (fd1);
|
||||
|
||||
flags = (flags & O_APPEND);
|
||||
|
||||
retval = (flags == O_APPEND);
|
||||
}
|
||||
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return (retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Dup2Test function
|
||||
*
|
||||
* Hits the dup2 code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: dup, dup2, open, close, fcntl available.
|
||||
* actions: Gets a file descriptor(fd1) for test file1.
|
||||
* dups fd1 to fd2.
|
||||
* sets fd1 to append mode
|
||||
* checks fd2 to ensure it's in append mode, also.
|
||||
* sets fd1 to invalid value, fd2 to valid, tries to dup2.
|
||||
* sets fd2 to invalid value, fd1 to valid tries to dup2.
|
||||
* returns: success if fd2 is a copy of fd1, and invalid fd1 or fd2 produce errors.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int Dup2Test(void) {
|
||||
|
||||
int fd1, fd2;
|
||||
|
||||
int flags = 0, retval = FALSE;
|
||||
|
||||
int error = 0;
|
||||
|
||||
fd1 = open ("testfile1.tst", O_RDONLY);
|
||||
fd2 = open ("testfile2.tst", O_RDONLY);
|
||||
error = dup2(fd1, fd2);
|
||||
|
||||
/* make sure dup2 works if both fd1 and fd2 are valid file descriptors. */
|
||||
|
||||
if (error != -1) {
|
||||
|
||||
fcntl(F_SETFL, fd1, O_APPEND);
|
||||
flags = fcntl(F_GETFL, fd1);
|
||||
|
||||
flags = (flags & O_APPEND);
|
||||
retval = (flags == O_APPEND);
|
||||
}
|
||||
|
||||
else {
|
||||
retval = FALSE;
|
||||
close(fd2);
|
||||
}
|
||||
|
||||
if (retval == TRUE) {
|
||||
|
||||
/* make sure dup2 fails correctly if one or the other arguments are invalid. */
|
||||
/* this assumes -1 is an invalid value for a file descriptor!!! (POSIX book, p.135) */
|
||||
|
||||
fd1 = -1;
|
||||
|
||||
if (dup2 (fd1, fd2) != -1)
|
||||
retval = FALSE;
|
||||
else {
|
||||
fd1 = dup(fd2);
|
||||
fd2 = -1;
|
||||
|
||||
if (dup2(fd1, fd2) != -1)
|
||||
retval = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
close (fd1);
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return (retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* FDataSyncTest function
|
||||
*
|
||||
* Hits the fdatasync code. Does NOT test the functionality of the
|
||||
* underlying fdatasync entry in the IMFS op table.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: open, close, fdatasync functions available.
|
||||
* actions: attempts to fdatasync a file descriptor flagged as read-only.
|
||||
* attempts to fdatasync an invalid file descriptor (-1).
|
||||
* attempts to fdatasync a perfectly valid fd opened as RDWR
|
||||
*
|
||||
* returns: TRUE if attempt to fdatasync invalid and read-only filed escriptor fail, and fdatasync succeeds on valid fd.
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int FDataSyncTest(void) {
|
||||
|
||||
int fd = -1;
|
||||
int error = 0, retval = TRUE;
|
||||
|
||||
/* Try it with a RD_ONLY file. */
|
||||
|
||||
fd = open ("testfile1.tst", O_RDONLY);
|
||||
|
||||
error = fdatasync(fd);
|
||||
if ((error == -1) && (errno == EINVAL))
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
close (fd);
|
||||
|
||||
if (retval == TRUE) {
|
||||
|
||||
/* Try it with a bad file descriptor */
|
||||
|
||||
fd = -1;
|
||||
|
||||
error = fdatasync(fd);
|
||||
if ((errno == EBADF) && (error == -1))
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
}
|
||||
|
||||
/* Okay - now the success case... */
|
||||
|
||||
if (retval == TRUE) {
|
||||
fd = open ("testfile1.tst", O_RDWR);
|
||||
error = fdatasync(fd);
|
||||
|
||||
if (error == 0)
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
close (fd);
|
||||
|
||||
}
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* UMaskTest function
|
||||
*
|
||||
* Hits the umask code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: umask function available.
|
||||
* actions: set umask to 0ctal 23.
|
||||
* set umask to Octal 22, retrieve the old value.
|
||||
*
|
||||
* returns: TRUE if old value is 23,
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int UMaskTest (void) {
|
||||
|
||||
int error = 0, retval = FALSE;
|
||||
|
||||
umask (023);
|
||||
error = umask(022);
|
||||
|
||||
if (error == 023)
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return(retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* UTimeTest function
|
||||
*
|
||||
* Hits the utime code. Does NOT test the functionality of the underlying utime
|
||||
* entry in the IMFS op table.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: utime function available.
|
||||
* actions: set utime for an invalid filename.
|
||||
* set utime for a valid filename.
|
||||
*
|
||||
* returns: TRUE if time on valid file is set correctly and utime failed on an invaid filename.
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int UTimeTest (void) {
|
||||
|
||||
int error = 0, retval = FALSE;
|
||||
struct utimbuf time;
|
||||
struct stat fstat;
|
||||
|
||||
/* First, an invalid filename. */
|
||||
error = utime("!This is an =invalid p@thname!!! :)", NULL);
|
||||
|
||||
if (error == -1)
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* Now, the success test. */
|
||||
if (retval == TRUE) {
|
||||
|
||||
time.actime = 12345;
|
||||
time.modtime = 54321;
|
||||
|
||||
error = utime("testfile1.tst", &time);
|
||||
|
||||
if (error == 0) {
|
||||
|
||||
/* But, did it set the time? */
|
||||
stat ("testfile1.tst", &fstat);
|
||||
|
||||
if ((fstat.st_atime == 12345) && (fstat.st_mtime == 54321 ))
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
}
|
||||
|
||||
else
|
||||
retval = FALSE;
|
||||
}
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return (retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* PipeTest function
|
||||
*
|
||||
* Hits the pipe code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: pipe function available.
|
||||
* actions: call pipe.
|
||||
*
|
||||
* returns: TRUE if pipe retuens ENOSYS,
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int PipeTest (void) {
|
||||
|
||||
int error = 0, retval = FALSE;
|
||||
int fd[2];
|
||||
|
||||
error = pipe(fd);
|
||||
|
||||
if ((error == -1) && (errno == ENOSYS))
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return(retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* PathConfTest function
|
||||
*
|
||||
* Hits the pathconf code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: pathconf function available.
|
||||
* actions: Try to pathconf a bad filename.
|
||||
* Try to pathconf a good filename.
|
||||
*
|
||||
* returns: TRUE if pathconf fails on bad file, succeeds on good file.
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int PathConfTest (void) {
|
||||
|
||||
int error = 0, retval = FALSE;
|
||||
|
||||
error = pathconf("thisfiledoesnotexist", _PC_LINK_MAX);
|
||||
|
||||
if (error == -1) {
|
||||
error = pathconf("testfile1.tst", _PC_LINK_MAX);
|
||||
|
||||
if (error != -1)
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
}
|
||||
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return(retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* FPathConfTest function
|
||||
*
|
||||
* Hits the fpathconf code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: fpathconf function available.
|
||||
* actions: Call fpathconf with all arguments, plus an invalid.
|
||||
*
|
||||
* returns: TRUE always.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int FPathConfTest (void) {
|
||||
|
||||
int error = 0, retval = TRUE;
|
||||
|
||||
int fd = -1;
|
||||
|
||||
error = fpathconf(fd, _PC_LINK_MAX);
|
||||
|
||||
if (error == -1) {
|
||||
fd = open("testfile1.tst", O_RDWR);
|
||||
|
||||
error = fpathconf(fd, _PC_LINK_MAX);
|
||||
error = fpathconf(fd, _PC_MAX_CANON);
|
||||
error = fpathconf(fd, _PC_MAX_INPUT);
|
||||
error = fpathconf(fd, _PC_NAME_MAX);
|
||||
error = fpathconf(fd, _PC_PATH_MAX);
|
||||
error = fpathconf(fd, _PC_PIPE_BUF);
|
||||
error = fpathconf(fd, _PC_CHOWN_RESTRICTED);
|
||||
error = fpathconf(fd, _PC_NO_TRUNC);
|
||||
error = fpathconf(fd, _PC_VDISABLE);
|
||||
error = fpathconf(fd, _PC_ASYNC_IO);
|
||||
error = fpathconf(fd, _PC_PRIO_IO);
|
||||
error = fpathconf(fd, _PC_SYNC_IO);
|
||||
error = fpathconf(fd, 255);
|
||||
|
||||
retval = TRUE;
|
||||
}
|
||||
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return(retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* FSyncTest function
|
||||
*
|
||||
* Hits the fsync code.
|
||||
*
|
||||
* arguments: none
|
||||
* assumptions: open, fsync functions available.
|
||||
* actions: open test file,
|
||||
* try to fsync it.
|
||||
*
|
||||
* returns: TRUE if fsync doesn't return -1,
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int FSyncTest (void) {
|
||||
|
||||
int error = 0, retval = FALSE;
|
||||
int fd = -1;
|
||||
|
||||
fd = open("testfile1.tst", O_RDWR);
|
||||
|
||||
if (fd != -1) {
|
||||
|
||||
error = fsync(fd);
|
||||
|
||||
if (error != -1)
|
||||
retval = TRUE;
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
else
|
||||
retval = FALSE;
|
||||
|
||||
/* assert (retval == TRUE);*/
|
||||
|
||||
return(retval);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
* Main function
|
||||
*
|
||||
* main entry point to the test
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
if (InitFiles() == TRUE) {
|
||||
puts ("\nFiles initialized successfully.\n");
|
||||
|
||||
puts ("Testing device_lseek()...");
|
||||
if (DeviceLSeekTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing dup()...");
|
||||
if (DupTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing dup2()...");
|
||||
if (Dup2Test() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing fdatasync()...");
|
||||
if (FDataSyncTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing umask()...");
|
||||
if (UMaskTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing utime()...");
|
||||
if (UTimeTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing pipe()...");
|
||||
if (PipeTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing fsync()...");
|
||||
if (FSyncTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing pathconf()...");
|
||||
if (PathConfTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
|
||||
puts ("Testing fpathconf()...");
|
||||
if (FPathConfTest() == TRUE)
|
||||
puts ("Success.\n");
|
||||
else
|
||||
puts ("Failed!!!\n");
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
puts ("\n\nError opening files for write!!!!\n");
|
||||
|
||||
puts( "\n\n*** XXX ***" );
|
||||
|
||||
puts( "\n\n*** END OF TEST PSX13 ***" );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
63
c/src/tests/psxtests/psxfile01/Makefile.in
Normal file
63
c/src/tests/psxtests/psxfile01/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
@SET_MAKE@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@:@srcdir@/../filesupp
|
||||
RTEMS_ROOT = @top_srcdir@
|
||||
PROJECT_ROOT = @PROJECT_ROOT@
|
||||
|
||||
TEST=file01
|
||||
|
||||
MANAGERS=all
|
||||
|
||||
# C source names, if any, go here -- minus the .c
|
||||
C_PIECES=main test test_cat test_extend test_write
|
||||
C_FILES=$(C_PIECES:%=%.c)
|
||||
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
|
||||
|
||||
H_FILES=
|
||||
|
||||
DOCTYPES=scn
|
||||
DOCS=$(DOCTYPES:%=$(TEST).%)
|
||||
|
||||
SRCS=$(DOCS) $(C_FILES) $(H_FILES)
|
||||
OBJS=$(C_O_FILES)
|
||||
|
||||
PRINT_SRCS=$(DOCS)
|
||||
|
||||
PGM=${ARCH}/$(TEST).exe
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/leaf.cfg
|
||||
|
||||
#
|
||||
# (OPTIONAL) Add local stuff here using +=
|
||||
#
|
||||
|
||||
DEFINES +=
|
||||
CPPFLAGS +=
|
||||
CFLAGS +=
|
||||
|
||||
LD_PATHS +=
|
||||
LD_LIBS +=
|
||||
LDFLAGS +=
|
||||
|
||||
#
|
||||
# Add your list of files to delete here. The config files
|
||||
# already know how to delete some stuff, so you may want
|
||||
# to just run 'make clean' first to see what gets missed.
|
||||
# 'make clobber' already includes 'make clean'
|
||||
#
|
||||
|
||||
CLEAN_ADDITIONS +=
|
||||
CLOBBER_ADDITIONS +=
|
||||
|
||||
all: ${ARCH} $(SRCS) $(PGM)
|
||||
$(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
|
||||
$(INSTALL) $(srcdir)/$(TEST).scn \
|
||||
${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn
|
||||
|
||||
${PGM}: $(OBJS) $(LINK_FILES)
|
||||
$(make-exe)
|
||||
40
c/src/tests/psxtests/psxfile01/main.c
Normal file
40
c/src/tests/psxtests/psxfile01/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Simple test program -- simplified version of sample test hello.
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1998.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* Copyright assigned to U.S. Government, 1994.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.OARcorp.com/rtems/license.html.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#define TEST_INIT
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
void test_main( void );
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
test_main();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
168
c/src/tests/psxtests/psxfile01/psxfile01.scn
Normal file
168
c/src/tests/psxtests/psxfile01/psxfile01.scn
Normal file
@@ -0,0 +1,168 @@
|
||||
|
||||
|
||||
*** FILE TEST 1 ***
|
||||
*************** Dump of Entire IMFS ***************
|
||||
/
|
||||
dev/
|
||||
console (device 0, 0)
|
||||
*************** End of Dump ***************
|
||||
stat of /dev/console
|
||||
st_dev (0x0:0x0)
|
||||
st_ino 3
|
||||
mode = 00020771
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Fri Jan 01 00:00:00 1988
|
||||
mtime = Fri Jan 01 00:00:00 1988
|
||||
ctime = Fri Jan 01 00:00:00 1988
|
||||
|
||||
mkdir /dev/tty
|
||||
|
||||
mkdir /usr
|
||||
mkdir /etc
|
||||
mkdir /tmp
|
||||
mkdir /tmp/..
|
||||
mkdir /tmp/
|
||||
mkdir /j/j1
|
||||
mkdir tmp
|
||||
|
||||
rmdir /usr
|
||||
mkdir /etc/passwd/j
|
||||
open /tmp/joel - should fail with ENOENT
|
||||
open /tmp/j
|
||||
open returned file descriptor 3
|
||||
close /tmp/j
|
||||
unlink /tmp/j
|
||||
(0)the first write!!!
|
||||
|
||||
(10)the first write!!!
|
||||
|
||||
stat( /tmp/joel ) returned st_dev (0x1a7f8:0x3e86f0)
|
||||
st_ino d
|
||||
mode = 00100700
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Sat Dec 31 09:00:00 1988
|
||||
mtime = Sat Dec 31 09:00:00 1988
|
||||
ctime = Sat Dec 31 09:00:00 1988
|
||||
(514)the first write!!!
|
||||
|
||||
(513)the first write!!!
|
||||
|
||||
(24)the first write!!!
|
||||
|
||||
(2)the first write!!!
|
||||
|
||||
(1)the first write!!!
|
||||
|
||||
(0)the first write!!!
|
||||
|
||||
(0)rst write!!!
|
||||
|
||||
(513)the first write!!!
|
||||
|
||||
(139743)
|
||||
stat( /tmp/joel ) returned st_dev (0x1a7f8:0x3e86f0)
|
||||
st_ino e
|
||||
mode = 00100700
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Sat Dec 31 09:00:00 1988
|
||||
mtime = Sat Dec 31 09:00:00 1988
|
||||
ctime = Sat Dec 31 09:00:00 1988
|
||||
stat of /tmp/j
|
||||
stat(/tmp/j) returned -1 (errno=2)
|
||||
st_dev (0x0:0x0)
|
||||
st_ino 3
|
||||
mode = 00020771
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Fri Jan 01 00:00:00 1988
|
||||
mtime = Fri Jan 01 00:00:00 1988
|
||||
ctime = Fri Jan 01 00:00:00 1988
|
||||
fopen of /tmp/j
|
||||
fprintf to /tmp/j
|
||||
(1) 26 characters written to the file
|
||||
(2) 26 characters written to the file
|
||||
(3) 26 characters written to the file
|
||||
(4) 26 characters written to the file
|
||||
(5) 26 characters written to the file
|
||||
st_dev (0x0:0x0)
|
||||
st_ino f
|
||||
mode = 00100660
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Sat Dec 31 09:00:00 1988
|
||||
mtime = Sat Dec 31 09:00:00 1988
|
||||
ctime = Sat Dec 31 09:00:00 1988
|
||||
This is call 1 to fprintf
|
||||
This is call 2 to fprintf
|
||||
This is call 3 to fprintf
|
||||
This is call 4 to fprintf
|
||||
This is call 5 to fprintf
|
||||
st_dev (0x0:0x0)
|
||||
st_ino f
|
||||
mode = 00100660
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Sat Dec 31 09:00:01 1988
|
||||
mtime = Sat Dec 31 09:00:00 1988
|
||||
ctime = Sat Dec 31 09:00:00 1988
|
||||
*************** Dump of Entire IMFS ***************
|
||||
/
|
||||
dev/
|
||||
console (device 0, 0)
|
||||
tty/
|
||||
S3 (device 255, 128)
|
||||
test_console (device 0, 0)
|
||||
etc/
|
||||
passwd (file 0 0x0 0x0 0x0)
|
||||
tmp/
|
||||
joel (file 279487 0x3d5ac0 0x3d5570 0x3d5020)
|
||||
j (file 130 0x37f530 0x0 0x0)
|
||||
*************** End of Dump ***************
|
||||
truncate /tmp/j to length of 40
|
||||
st_dev (0x0:0x0)
|
||||
st_ino f
|
||||
mode = 00100660
|
||||
nlink = 1
|
||||
uid = 0
|
||||
gid = 0
|
||||
atime = Sat Dec 31 09:00:02 1988
|
||||
mtime = Sat Dec 31 09:00:00 1988
|
||||
ctime = Sat Dec 31 09:00:00 1988
|
||||
*************** Dump of Entire IMFS ***************
|
||||
/
|
||||
dev/
|
||||
console (device 0, 0)
|
||||
tty/
|
||||
S3 (device 255, 128)
|
||||
test_console (device 0, 0)
|
||||
etc/
|
||||
passwd (file 0 0x0 0x0 0x0)
|
||||
tmp/
|
||||
j (file 40 0x37f530 0x0 0x0)
|
||||
*************** End of Dump ***************
|
||||
truncate /tmp/j to length of 0
|
||||
truncate /tmp to length of 0 should fail with EISDIR
|
||||
|
||||
21: Is a directory
|
||||
*************** Dump of Entire IMFS ***************
|
||||
/
|
||||
dev/
|
||||
console (device 0, 0)
|
||||
tty/
|
||||
S3 (device 255, 128)
|
||||
test_console (device 0, 0)
|
||||
etc/
|
||||
passwd (file 0 0x0 0x0 0x0)
|
||||
tmp/
|
||||
j (file 0 0x37f530 0x0 0x0)
|
||||
*************** End of Dump ***************
|
||||
*** END OF FILE TEST 1 ***
|
||||
475
c/src/tests/psxtests/psxfile01/test.c
Normal file
475
c/src/tests/psxtests/psxfile01/test.c
Normal file
@@ -0,0 +1,475 @@
|
||||
/*
|
||||
* Simple test program to exercise some of the basic functionality of
|
||||
* POSIX Files and Directories Support.
|
||||
*
|
||||
* This test assumes that the file system is initialized with the
|
||||
* following directory structure:
|
||||
*
|
||||
* XXXX fill this in.
|
||||
* /
|
||||
* /dev
|
||||
* /dev/XXX [where XXX includes at least console]
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1998.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* Copyright assigned to U.S. Government, 1994.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.OARcorp.com/rtems/license.html.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <tmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <rtems.h>
|
||||
#include <rtems/libio.h>
|
||||
|
||||
char test_write_buffer[ 1024 ];
|
||||
|
||||
/*
|
||||
* File test support routines.
|
||||
*/
|
||||
|
||||
void test_cat(
|
||||
char *file,
|
||||
int offset_arg,
|
||||
int length
|
||||
);
|
||||
|
||||
void test_write(
|
||||
char *file,
|
||||
off_t offset,
|
||||
char *buffer
|
||||
);
|
||||
|
||||
void test_extend(
|
||||
char *file,
|
||||
off_t new_len
|
||||
);
|
||||
|
||||
void IMFS_dump( void );
|
||||
int IMFS_memfile_maximum_size( void );
|
||||
|
||||
/*
|
||||
* dump_statbuf
|
||||
*/
|
||||
|
||||
void dump_statbuf( struct stat *buf )
|
||||
{
|
||||
int major1;
|
||||
int minor1;
|
||||
int major2;
|
||||
int minor2;
|
||||
|
||||
rtems_filesystem_split_dev_t( buf->st_dev, major1, minor1 );
|
||||
rtems_filesystem_split_dev_t( buf->st_rdev, major2, minor2 );
|
||||
|
||||
printf( " st_dev (0x%x:0x%x)\n", major1, minor1 );
|
||||
printf( " st_ino %x\n", buf->st_ino );
|
||||
printf( " mode = %08o\n", buf->st_mode );
|
||||
printf( " nlink = %d\n", buf->st_nlink );
|
||||
|
||||
printf( " uid = %d\n", buf->st_uid );
|
||||
printf( " gid = %d\n", buf->st_gid );
|
||||
|
||||
printf( " atime = %s", ctime(&buf->st_atime) );
|
||||
printf( " mtime = %s", ctime(&buf->st_mtime) );
|
||||
printf( " ctime = %s", ctime(&buf->st_ctime) );
|
||||
|
||||
#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
|
||||
printf( " st_blksize %x\n", buf.st_blksize );
|
||||
printf( " st_blocks %x\n", buf.st_blocks );
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void stat_a_file(
|
||||
const char *file
|
||||
)
|
||||
{
|
||||
int status;
|
||||
struct stat statbuf;
|
||||
|
||||
assert( file );
|
||||
|
||||
printf( "stat( %s ) returned ", file );
|
||||
fflush( stdout );
|
||||
|
||||
status = stat( file, &statbuf );
|
||||
|
||||
if ( status == -1 ) {
|
||||
printf( ": %s\n", strerror( errno ) );
|
||||
} else {
|
||||
dump_statbuf( &statbuf );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main entry point of the test
|
||||
*/
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
int status;
|
||||
int max_size;
|
||||
int fd, fd1;
|
||||
int i;
|
||||
struct stat buf;
|
||||
char buffer[128];
|
||||
FILE *file;
|
||||
time_t atime1;
|
||||
time_t mtime1;
|
||||
time_t ctime1;
|
||||
time_t atime2;
|
||||
time_t mtime2;
|
||||
time_t ctime2;
|
||||
rtems_status_code rtems_status;
|
||||
rtems_time_of_day time;
|
||||
|
||||
printf( "\n\n*** FILE TEST 1 ***\n" );
|
||||
|
||||
/*
|
||||
* Grab the maximum size of an in-memory file.
|
||||
*/
|
||||
|
||||
max_size = IMFS_memfile_maximum_size();
|
||||
|
||||
build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
|
||||
rtems_status = rtems_clock_set( &time );
|
||||
|
||||
/*
|
||||
* Dump an empty file system
|
||||
*/
|
||||
|
||||
IMFS_dump();
|
||||
|
||||
/*
|
||||
* Simple stat() of /dev/console.
|
||||
*/
|
||||
|
||||
puts( "stat of /dev/console" );
|
||||
status = stat( "/dev/console", &buf );
|
||||
assert( !status );
|
||||
|
||||
dump_statbuf( &buf );
|
||||
|
||||
/*
|
||||
* Exercise mkdir() and some path evaluation.
|
||||
*/
|
||||
|
||||
puts( "" );
|
||||
puts( "mkdir /dev/tty" );
|
||||
status = mkdir( "/dev/tty", S_IRWXU );
|
||||
assert( !status );
|
||||
|
||||
puts( "" );
|
||||
puts( "mkdir /usr" );
|
||||
status = mkdir( "/usr", S_IRWXU );
|
||||
assert( !status );
|
||||
puts( "mkdir /etc" );
|
||||
status = mkdir( "/etc", S_IRWXU );
|
||||
assert( !status );
|
||||
|
||||
puts( "mkdir /tmp" );
|
||||
status = mkdir( "/tmp", S_IRWXU );
|
||||
assert( !status );
|
||||
|
||||
/* this tests the ".." path in path name evaluation */
|
||||
puts( "mkdir /tmp/.." );
|
||||
status = mkdir( "/tmp/..", S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == EEXIST );
|
||||
|
||||
/* now check out trailing separators */
|
||||
puts( "mkdir /tmp/" );
|
||||
status = mkdir( "/tmp/", S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == EEXIST );
|
||||
|
||||
/* try to make a directory under a non-existent subdirectory */
|
||||
puts( "mkdir /j/j1" );
|
||||
status = mkdir( "/j/j1", S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOENT );
|
||||
|
||||
/* this tests the ability to make a directory in the current one */
|
||||
puts( "mkdir tmp" );
|
||||
status = mkdir( "tmp", S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == EEXIST );
|
||||
|
||||
/* test rtems_filesystem_evaluate_path by sending NULL path */
|
||||
status = chdir( NULL );
|
||||
assert( status == -1 );
|
||||
|
||||
/*
|
||||
* Now switch gears and exercise rmdir().
|
||||
*/
|
||||
|
||||
puts( "" );
|
||||
puts( "rmdir /usr" );
|
||||
status = rmdir( "/usr" );
|
||||
assert( !status );
|
||||
|
||||
status = rmdir( "/dev" );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOTEMPTY);
|
||||
|
||||
status = rmdir ("/fred");
|
||||
assert (status == -1);
|
||||
|
||||
status = mknod( "/dev/test_console", S_IFCHR, 0LL );
|
||||
assert( !status );
|
||||
status = mknod( "/dev/tty/S3", S_IFCHR, 0xFF00000080LL );
|
||||
assert( !status );
|
||||
status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL );
|
||||
assert( !status );
|
||||
|
||||
status = mkdir( "/tmp/my_dir", S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
status = mkfifo( "/c/my_dir", S_IRWXU );
|
||||
assert( status == -1 );
|
||||
|
||||
/*
|
||||
* Try to make a directory under a file -- ERROR
|
||||
*/
|
||||
|
||||
puts( "mkdir /etc/passwd/j" );
|
||||
status = mkdir( "/etc/passwd/j", S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOTDIR );
|
||||
|
||||
/*
|
||||
* Simple open failure case on non-existent file
|
||||
*/
|
||||
|
||||
puts( "open /tmp/joel - should fail with ENOENT" );
|
||||
fd = open( "/tmp/joel", O_RDONLY );
|
||||
assert( fd == -1 );
|
||||
assert( errno == ENOENT );
|
||||
|
||||
/*
|
||||
* Simple open case where the file is created.
|
||||
*/
|
||||
|
||||
puts( "open /tmp/j" );
|
||||
fd = open( "/tmp/j", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO );
|
||||
assert( fd != -1 );
|
||||
|
||||
printf( "open returned file descriptor %d\n", fd );
|
||||
|
||||
puts( "close /tmp/j" );
|
||||
status = close( fd );
|
||||
assert( !status );
|
||||
|
||||
status = close( fd );
|
||||
assert( status == -1 );
|
||||
|
||||
puts( "unlink /tmp/j" );
|
||||
status = unlink( "/tmp/j" );
|
||||
assert( !status );
|
||||
|
||||
status = unlink( "/tmp" );
|
||||
assert( status );
|
||||
|
||||
/*
|
||||
* Simple open failure. Trying to create an existing file.
|
||||
*/
|
||||
|
||||
fd = open( "/tmp/tom", O_CREAT );
|
||||
status = close( fd );
|
||||
fd1 = open( "/tmp/tom", O_CREAT );
|
||||
assert( fd1 == -1 );
|
||||
|
||||
fd = open( "/tmp/john", O_CREAT );
|
||||
assert( fd != -1 );
|
||||
status = tcdrain( fd );
|
||||
assert( status == 0 );
|
||||
|
||||
/*
|
||||
* Test simple write to a file at offset 0
|
||||
*/
|
||||
|
||||
status = mknod( "/tmp/joel", (S_IFREG | S_IRWXU), 0LL );
|
||||
test_write( "/tmp/joel", 0, "the first write!!!\n" );
|
||||
test_cat( "/tmp/joel", 0, 0 );
|
||||
|
||||
/*
|
||||
* Test simple write to a file at a non-0 offset in the first block
|
||||
*/
|
||||
|
||||
status = unlink( "/tmp/joel" );
|
||||
assert( !status );
|
||||
|
||||
status = mknod( "/tmp/joel", (S_IFREG | S_IRWXU), 0LL );
|
||||
assert( !status );
|
||||
|
||||
test_write( "/tmp/joel", 10, "the first write!!!\n" );
|
||||
test_cat( "/tmp/joel", 0, 0 );
|
||||
stat_a_file( "/tmp/joel" );
|
||||
|
||||
/*
|
||||
* Test simple write to a file at a non-0 offset in the second block. Then
|
||||
* try to read from various offsets and lengths.
|
||||
*/
|
||||
|
||||
status = unlink( "/tmp/joel" );
|
||||
assert( !status );
|
||||
|
||||
/* Test a failure path */
|
||||
|
||||
status = unlink( "/tmp/joel" );
|
||||
assert( status == -1 );
|
||||
|
||||
status = mknod( "/tmp/joel", (S_IFREG | S_IRWXU), 0LL );
|
||||
assert( !status );
|
||||
|
||||
test_write( "/tmp/joel", 514, "the first write!!!\n" );
|
||||
test_write( "/tmp/joel", 1, test_write_buffer );
|
||||
test_write( "/tmp/joel", 63, test_write_buffer );
|
||||
test_cat( "/tmp/joel", 0, 1 );
|
||||
test_cat( "/tmp/joel", 1, 1 );
|
||||
test_cat( "/tmp/joel", 490, 1 );
|
||||
test_cat( "/tmp/joel", 512, 1 );
|
||||
test_cat( "/tmp/joel", 513, 1 );
|
||||
test_cat( "/tmp/joel", 514, 1 );
|
||||
test_cat( "/tmp/joel", 520, 1 );
|
||||
test_cat( "/tmp/joel", 1, 1024 );
|
||||
|
||||
/*
|
||||
* Read from a much longer file so we can descend into doubly and
|
||||
* triply indirect blocks.
|
||||
*/
|
||||
|
||||
test_extend( "/tmp/joel", max_size - 1 );
|
||||
test_cat( "/tmp/joel", max_size / 2, 1024 );
|
||||
|
||||
stat_a_file( "/tmp/joel" );
|
||||
|
||||
/*
|
||||
* Now try to use a FILE * descriptor
|
||||
*
|
||||
* /tmp/j should not exist at this point.
|
||||
*/
|
||||
|
||||
puts( "stat of /tmp/j" );
|
||||
errno = 0;
|
||||
status = stat( "/tmp/j", &buf );
|
||||
printf( "stat(/tmp/j) returned %d (errno=%d)\n", status, errno );
|
||||
dump_statbuf( &buf );
|
||||
|
||||
puts( "fopen of /tmp/j" );
|
||||
file = fopen( "/tmp/j", "w+" );
|
||||
assert( file );
|
||||
|
||||
puts( "fprintf to /tmp/j" );
|
||||
for (i=1 ; i<=5 ; i++) {
|
||||
status = fprintf( file, "This is call %d to fprintf\n", i );
|
||||
assert( status );
|
||||
printf( "(%d) %d characters written to the file\n", i, status );
|
||||
}
|
||||
|
||||
fflush( file );
|
||||
|
||||
status = stat( "/tmp/j", &buf );
|
||||
assert( !status );
|
||||
dump_statbuf( &buf );
|
||||
atime2 = buf.st_atime;
|
||||
mtime2 = buf.st_mtime;
|
||||
ctime2 = buf.st_ctime;
|
||||
|
||||
|
||||
status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
|
||||
rewind( file );
|
||||
while ( fgets(buffer, 128, file) )
|
||||
printf( buffer );
|
||||
|
||||
/*
|
||||
* Verify only atime changed for a read.
|
||||
*/
|
||||
status = stat( "/tmp/j", &buf );
|
||||
assert( !status );
|
||||
dump_statbuf( &buf );
|
||||
atime1 = buf.st_atime;
|
||||
mtime1 = buf.st_mtime;
|
||||
ctime1 = buf.st_ctime;
|
||||
assert( atime1 != atime2);
|
||||
assert( mtime1 == mtime2);
|
||||
assert( ctime1 == ctime2);
|
||||
|
||||
IMFS_dump();
|
||||
|
||||
unlink( "/tmp/joel" );
|
||||
|
||||
/*
|
||||
* Now truncate a file
|
||||
*/
|
||||
|
||||
status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
|
||||
puts( "truncate /tmp/j to length of 40" );
|
||||
status = truncate( "/tmp/j", 40 );
|
||||
assert( !status );
|
||||
|
||||
/*
|
||||
* Verify truncate changed only atime.
|
||||
*/
|
||||
status = stat( "/tmp/j", &buf );
|
||||
assert( !status );
|
||||
dump_statbuf( &buf );
|
||||
atime2 = buf.st_atime;
|
||||
mtime2 = buf.st_mtime;
|
||||
ctime2 = buf.st_ctime;
|
||||
assert( atime1 != atime2);
|
||||
assert( mtime1 == mtime2);
|
||||
assert( ctime1 == ctime2);
|
||||
|
||||
IMFS_dump();
|
||||
|
||||
/* try to truncate the console and see what happens */
|
||||
status = truncate( "/dev/console", 40 );
|
||||
assert(status == -1 );
|
||||
|
||||
puts( "truncate /tmp/j to length of 0" );
|
||||
status = truncate( "/tmp/j", 0 );
|
||||
assert( !status );
|
||||
|
||||
puts( "truncate /tmp to length of 0 should fail with EISDIR\n");
|
||||
status = truncate( "/tmp", 0 );
|
||||
assert( status == -1 );
|
||||
printf( "%d: %s\n", errno, strerror( errno ) );
|
||||
assert( errno == EISDIR );
|
||||
|
||||
IMFS_dump();
|
||||
|
||||
status = truncate( "/tmp/fred", 10 );
|
||||
assert( status == -1);
|
||||
|
||||
rtems_status = rtems_io_register_name( "/dev/console", 0, 0 );
|
||||
|
||||
printf( "*** END OF FILE TEST 1 ***\n" );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
|
||||
63
c/src/tests/psxtests/psxfile02/Makefile.in
Normal file
63
c/src/tests/psxtests/psxfile02/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
@SET_MAKE@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
RTEMS_ROOT = @top_srcdir@
|
||||
PROJECT_ROOT = @PROJECT_ROOT@
|
||||
|
||||
TEST=file02
|
||||
|
||||
MANAGERS=all
|
||||
|
||||
# C source names, if any, go here -- minus the .c
|
||||
C_PIECES=main test
|
||||
C_FILES=$(C_PIECES:%=%.c)
|
||||
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
|
||||
|
||||
H_FILES=
|
||||
|
||||
DOCTYPES=scn
|
||||
DOCS=$(DOCTYPES:%=$(TEST).%)
|
||||
|
||||
SRCS=$(DOCS) $(C_FILES) $(H_FILES)
|
||||
OBJS=$(C_O_FILES)
|
||||
|
||||
PRINT_SRCS=$(DOCS)
|
||||
|
||||
PGM=${ARCH}/$(TEST).exe
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/leaf.cfg
|
||||
|
||||
#
|
||||
# (OPTIONAL) Add local stuff here using +=
|
||||
#
|
||||
|
||||
DEFINES +=
|
||||
CPPFLAGS +=
|
||||
CFLAGS +=
|
||||
|
||||
LD_PATHS +=
|
||||
LD_LIBS +=
|
||||
LDFLAGS +=
|
||||
|
||||
#
|
||||
# Add your list of files to delete here. The config files
|
||||
# already know how to delete some stuff, so you may want
|
||||
# to just run 'make clean' first to see what gets missed.
|
||||
# 'make clobber' already includes 'make clean'
|
||||
#
|
||||
|
||||
CLEAN_ADDITIONS +=
|
||||
CLOBBER_ADDITIONS +=
|
||||
|
||||
all: ${ARCH} $(SRCS) $(PGM)
|
||||
$(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
|
||||
$(INSTALL) $(srcdir)/$(TEST).scn \
|
||||
${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn
|
||||
|
||||
${PGM}: $(OBJS) $(LINK_FILES)
|
||||
$(make-exe)
|
||||
29
c/src/tests/psxtests/psxfile02/main.c
Normal file
29
c/src/tests/psxtests/psxfile02/main.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Simple test program -- simplified version of sample test hello.
|
||||
*/
|
||||
|
||||
#define TEST_INIT
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
void test_main( void );
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
test_main();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
2
c/src/tests/psxtests/psxfile02/psxfile02.scn
Normal file
2
c/src/tests/psxtests/psxfile02/psxfile02.scn
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
49
c/src/tests/psxtests/psxfile02/test.c
Normal file
49
c/src/tests/psxtests/psxfile02/test.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Simple test program to exercise some of the basic functionality of
|
||||
* POSIX Files and Directories Support.
|
||||
*
|
||||
* This test assumes that the file system is initialized with the
|
||||
* following directory structure:
|
||||
*
|
||||
* XXXX fill this in.
|
||||
* /
|
||||
* /dev
|
||||
* /dev/XXX [where XXX includes at least console]
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* Main entry point of the test
|
||||
*/
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
printf( "\n\n*** FILE TEST 2 ***\n" );
|
||||
|
||||
/*
|
||||
* XXX test code goes here
|
||||
*/
|
||||
|
||||
printf( "*** END OF FILE TEST 2 ***\n" );
|
||||
exit( 0 );
|
||||
}
|
||||
63
c/src/tests/psxtests/psxmount/Makefile.in
Normal file
63
c/src/tests/psxtests/psxmount/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
@SET_MAKE@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
RTEMS_ROOT = @top_srcdir@
|
||||
PROJECT_ROOT = @PROJECT_ROOT@
|
||||
|
||||
TEST=mount
|
||||
|
||||
MANAGERS=all
|
||||
|
||||
# C source names, if any, go here -- minus the .c
|
||||
C_PIECES=main test
|
||||
C_FILES=$(C_PIECES:%=%.c)
|
||||
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
|
||||
|
||||
H_FILES=
|
||||
|
||||
#DOCTYPES=scn
|
||||
DOCS=$(DOCTYPES:%=$(TEST).%)
|
||||
|
||||
SRCS=$(DOCS) $(C_FILES) $(H_FILES)
|
||||
OBJS=$(C_O_FILES)
|
||||
|
||||
PRINT_SRCS=$(DOCS)
|
||||
|
||||
PGM=${ARCH}/$(TEST).exe
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/leaf.cfg
|
||||
|
||||
#
|
||||
# (OPTIONAL) Add local stuff here using +=
|
||||
#
|
||||
|
||||
DEFINES +=
|
||||
CPPFLAGS +=
|
||||
CFLAGS +=
|
||||
|
||||
LD_PATHS +=
|
||||
LD_LIBS +=
|
||||
LDFLAGS +=
|
||||
|
||||
#
|
||||
# Add your list of files to delete here. The config files
|
||||
# already know how to delete some stuff, so you may want
|
||||
# to just run 'make clean' first to see what gets missed.
|
||||
# 'make clobber' already includes 'make clean'
|
||||
#
|
||||
|
||||
CLEAN_ADDITIONS +=
|
||||
CLOBBER_ADDITIONS +=
|
||||
|
||||
all: ${ARCH} $(SRCS) $(PGM)
|
||||
$(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
|
||||
$(INSTALL) $(srcdir)/$(TEST).scn \
|
||||
${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn
|
||||
|
||||
${PGM}: $(OBJS) $(LINK_FILES)
|
||||
$(make-exe)
|
||||
31
c/src/tests/psxtests/psxmount/main.c
Normal file
31
c/src/tests/psxtests/psxmount/main.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Simple test program -- check out of the basic file system mounting
|
||||
* capabilities
|
||||
* Attempt to mount the IMFS file system on a mount point in the base IMFS
|
||||
*/
|
||||
|
||||
#define TEST_INIT
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
void test_main( void );
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
test_main();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
0
c/src/tests/psxtests/psxmount/psxmount.scn
Normal file
0
c/src/tests/psxtests/psxmount/psxmount.scn
Normal file
408
c/src/tests/psxtests/psxmount/test.c
Normal file
408
c/src/tests/psxtests/psxmount/test.c
Normal file
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
* This is a native test to explore how the readdir() family works.
|
||||
* Newlib supports the following readdir() family members:
|
||||
*
|
||||
* closedir() -
|
||||
* readdir() -
|
||||
* scandir() -
|
||||
* opendir() -
|
||||
* rewinddir() -
|
||||
* telldir() - BSD not in POSIX
|
||||
* seekdir() - BSD not in POSIX
|
||||
*
|
||||
*
|
||||
* seekdir() takes an offset which is a byte offset. The Linux
|
||||
* implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1)
|
||||
* record where DIRENT_SIZE seems to be 12 bytes.
|
||||
*
|
||||
*
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <rtems.h>
|
||||
#include <rtems/libio.h>
|
||||
|
||||
extern rtems_filesystem_location_info_t rtems_filesystem_current;
|
||||
|
||||
DIR *directory;
|
||||
DIR *directory2;
|
||||
DIR *directory3;
|
||||
DIR *directory_not;
|
||||
|
||||
#ifndef __P
|
||||
#define __P(args)()
|
||||
#endif
|
||||
|
||||
char *dnames[] = {
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"f",
|
||||
"c/y",
|
||||
"c/z",
|
||||
"c/x",
|
||||
"c/y/a3333",
|
||||
"c/y/j123",
|
||||
"c/y/my_mount_point",
|
||||
"c/y/my_mount_point/my_dir",
|
||||
"c/z/my_mount_point",
|
||||
"END"
|
||||
};
|
||||
|
||||
char *fnames[] = {
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"f",
|
||||
"c/y",
|
||||
"c/z",
|
||||
"c/x",
|
||||
"c/y/a3333",
|
||||
"c/y/j123",
|
||||
"c/y/my_mount_point",
|
||||
"c/y/my_mount_point/my_dir",
|
||||
"c/y/my_mount_point/my_dir/d",
|
||||
"c/z/my_mount_point",
|
||||
"/c/z/my_mount_point/a/../../my_mount_point/a/g",
|
||||
"END"
|
||||
};
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
int status;
|
||||
struct stat statbuf;
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry;
|
||||
static char mount_point_string[25] = { "/c/z/my_mount_point" };
|
||||
|
||||
|
||||
printf( "\n\n*** MOUNT/UNMOUNT TEST ***\n" );
|
||||
|
||||
printf( "\nchdir to the root directory\n" );
|
||||
status = chdir( "/" );
|
||||
printf( "chdir() status : %d\n\n", status );
|
||||
|
||||
printf( "\nCreating a series of directories under /\n" );
|
||||
i=0;
|
||||
while ( strcmp(dnames[i], "END") != 0 )
|
||||
{
|
||||
status = mkdir( dnames[i], 0777 );
|
||||
printf("Creating directory: %s %d %d ", dnames[i], status, errno );
|
||||
if ( status == 0 )
|
||||
printf(" Success\n");
|
||||
else
|
||||
printf(" Failure\n");
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
fd = open ("/b/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
close (fd);
|
||||
fd = open("/b/my_file", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
close( fd );
|
||||
|
||||
fd = open ("c/y/my_mount_point/my_dir/d", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
close (fd);
|
||||
fd = open("c/y/my_mount_point/my_dir/d", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
close( fd );
|
||||
|
||||
printf("Attempting to mount IMFS file system at /c/z/my_mount_point \n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RW",
|
||||
NULL,
|
||||
mount_point_string );
|
||||
assert( status == 0 );
|
||||
if( mt_entry == NULL ){
|
||||
printf(" NULL mount table entry was returned\n");
|
||||
}
|
||||
else {
|
||||
printf("2nd file system successfully mounted at /c/z/my_mount_point \n");
|
||||
}
|
||||
|
||||
printf( "\nchdir to /c/z/my_mount_point the mount point of the \n" );
|
||||
printf( "second file system \n" );
|
||||
status = chdir( "/c/z/my_mount_point" );
|
||||
printf( "chdir() status : %d\n\n", status );
|
||||
|
||||
printf( "\nCreating a series of directories under /c/z/my_mount_point\n" );
|
||||
i=0;
|
||||
while ( strcmp(fnames[i], "END") != 0 )
|
||||
{
|
||||
status = mkdir( fnames[i], 0777 );
|
||||
printf("Creating directory: %s %d %d ", fnames[i], status, errno );
|
||||
if ( status == 0 )
|
||||
printf(" Success\n");
|
||||
else {
|
||||
printf(" Failure\n");
|
||||
perror("errno");
|
||||
}
|
||||
|
||||
status = stat( fnames[i], &statbuf );
|
||||
if ( status == -1 )
|
||||
printf( ": %s\n", strerror( errno ) );
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
printf( "\nchdir to / the mount point of the first file system \n" );
|
||||
status = chdir( "/" );
|
||||
printf( "chdir() status : %d\n\n", status );
|
||||
|
||||
/*
|
||||
* Unmount the first file system we mounted
|
||||
*/
|
||||
|
||||
printf( "Unmount status:");
|
||||
status = unmount( "/c/z/my_mount_point" );
|
||||
printf( " %d\n", status );
|
||||
|
||||
/*
|
||||
status = chmod( "c/y/j123", S_IRUSR );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("Attempting to mount IMFS file system at c/y/j123\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"c/y/j123" );
|
||||
assert( status == 0 );
|
||||
|
||||
status = mkdir( "c/y/j123/new_dir", S_IRUSR );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("Unmount c/y/j123\n");
|
||||
status = unmount( "c/y/j123" );
|
||||
assert( status == 0 );
|
||||
*/
|
||||
|
||||
printf(" File system type should be invalid.\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
NULL,
|
||||
"RW",
|
||||
NULL,
|
||||
mount_point_string );
|
||||
assert( status == -1 );
|
||||
assert( errno == EINVAL );
|
||||
|
||||
printf("Attempting to mount IMFS file system at /c/y/my_mount_point \n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
if( mt_entry == NULL ){
|
||||
printf(" NULL mount table entry was returned\n");
|
||||
}
|
||||
else {
|
||||
printf("3rd file system successfully mounted at /c/y/my_mount_point \n");
|
||||
}
|
||||
|
||||
status = mkdir("c/y/my_mount_point/../../y/my_mount_point/new_dir",S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
status = stat("c/y/my_mount_point/../../y/my_mount_point/new_dir",&statbuf );
|
||||
assert( status == 0 );
|
||||
status = stat("c/y/my_mount_point/new_dir/..", &statbuf );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("Mount another file system at /c/y/my_mount_point should fail with EBUSY\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
assert( status == -1 );
|
||||
assert( errno == EBUSY);
|
||||
|
||||
printf("Mount /b/my_file should fail in rtems_filesystem_evaluate_path\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"/b/my_file" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("Unmount /c/y/my_mount_point\n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
/* What's wrong with this? It should be causing failure at unmount.c:87,
|
||||
* instead, it's returning a status of 0.
|
||||
*/
|
||||
|
||||
printf("Mount /c/y/my_mount_point to cause error\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
|
||||
assert( status == 0 );
|
||||
status = mkdir( "/c/y/my_mount_point/mydir", 0777);
|
||||
assert( status == 0 );
|
||||
|
||||
status = chdir( "/c/y/my_mount_point/mydir" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf(" unmount of /c/y/my_mount_point should fail with EBUSY\n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == -1 );
|
||||
assert( errno == EBUSY );
|
||||
|
||||
status = chdir( "/" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf(" unmount /c/y/my_mount_point \n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf(" unmount /b/mount_point should fail\n");
|
||||
status = unmount( "/b/mount_point" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("Mount /c/y/my_mount_point\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
/* XXX - There is an error in open that calculates incorrect mode. */
|
||||
printf("Create and open /c/y/my_mount_point/my_file\n");
|
||||
fd = open( "/c/y/my_mount_point/my_file", O_CREAT );
|
||||
assert( fd != -1 );
|
||||
status = close( fd );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("\nmkdir /c/y/my_mount_point/my_dir\n");
|
||||
status = mkdir( "/c/y/my_mount_point/my_dir", 0x1c0 );
|
||||
printf("Open /c/y/my_mount_point/my_dir\n");
|
||||
directory = opendir( "/c/y/my_mount_point/my_dir" );
|
||||
assert( directory );
|
||||
|
||||
printf("Unmount /c/y/my_mount_point should fail with EBUSY\n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("Close /c/y/my_mount_point/my_dir\n");
|
||||
status = closedir( directory );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("Unmount /c/y/my_mount_point/d should fail at 107\n");
|
||||
status = unmount( "/c/y/my_mount_point/d" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("unmount /c/y/my_mount_point\n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("mount with option RA should fail with EINVAL\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RA",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("Mount a file system at /c/y/my_mount_point/my_dir\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RW",
|
||||
NULL,
|
||||
"/c/y/my_mount_point/my_dir");
|
||||
assert( status == 0 );
|
||||
|
||||
printf("unmount /c/y/my_mount_point/my_dir should fail in ");
|
||||
printf("file_systems_below_this_mountpoint \n");
|
||||
status = unmount( "/c/y/my_mount_point/my_dir" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("mount first filesystem /c/y/my_mount_point/\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RW",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("\nmkdir /c/y/my_mount_point/my_dir\n");
|
||||
status = mkdir( "/c/y/my_mount_point/my_dir", S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("Mount another filesystem at /c/y/my_mount_point/my_dir\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RW",
|
||||
NULL,
|
||||
"/c/y/my_mount_point/my_dir");
|
||||
assert( status == 0 );
|
||||
|
||||
status = mkdir( "/c/y/my_mount_point/my_dir2", S_IRWXU );
|
||||
assert( status != -1 );
|
||||
|
||||
status = link( "/c/y/my_mount_point/my_dir2", "/c/y/my_mount_point/my_dir/my_link" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("unmount /c/y/my_mount_point\n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == -1 );
|
||||
|
||||
printf("unmount /c/y/my_mount_point/my_dir\n");
|
||||
status = unmount( "/c/y/my_mount_point/my_dir" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("unmount /c/y/my_mount_point\n");
|
||||
status = unmount( "/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
/* printf("Mount /c/y/my_mount_point\n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RO",
|
||||
NULL,
|
||||
"/c/y/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
*/
|
||||
|
||||
printf( "\n\n*** END OF MOUNT/UNMOUNT TEST ***\n" );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
63
c/src/tests/psxtests/psxreaddir/Makefile.in
Normal file
63
c/src/tests/psxtests/psxreaddir/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
@SET_MAKE@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
RTEMS_ROOT = @top_srcdir@
|
||||
PROJECT_ROOT = @PROJECT_ROOT@
|
||||
|
||||
TEST=readdir
|
||||
|
||||
MANAGERS=all
|
||||
|
||||
# C source names, if any, go here -- minus the .c
|
||||
C_PIECES=main test
|
||||
C_FILES=$(C_PIECES:%=%.c)
|
||||
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
|
||||
|
||||
H_FILES=
|
||||
|
||||
#DOCTYPES=scn
|
||||
DOCS=$(DOCTYPES:%=$(TEST).%)
|
||||
|
||||
SRCS=$(DOCS) $(C_FILES) $(H_FILES)
|
||||
OBJS=$(C_O_FILES)
|
||||
|
||||
PRINT_SRCS=$(DOCS)
|
||||
|
||||
PGM=${ARCH}/$(TEST).exe
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/leaf.cfg
|
||||
|
||||
#
|
||||
# (OPTIONAL) Add local stuff here using +=
|
||||
#
|
||||
|
||||
DEFINES +=
|
||||
CPPFLAGS +=
|
||||
CFLAGS +=
|
||||
|
||||
LD_PATHS +=
|
||||
LD_LIBS +=
|
||||
LDFLAGS +=
|
||||
|
||||
#
|
||||
# Add your list of files to delete here. The config files
|
||||
# already know how to delete some stuff, so you may want
|
||||
# to just run 'make clean' first to see what gets missed.
|
||||
# 'make clobber' already includes 'make clean'
|
||||
#
|
||||
|
||||
CLEAN_ADDITIONS +=
|
||||
CLOBBER_ADDITIONS +=
|
||||
|
||||
all: ${ARCH} $(SRCS) $(PGM)
|
||||
$(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
|
||||
$(INSTALL) $(srcdir)/$(TEST).scn \
|
||||
${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn
|
||||
|
||||
${PGM}: $(OBJS) $(LINK_FILES)
|
||||
$(make-exe)
|
||||
29
c/src/tests/psxtests/psxreaddir/main.c
Normal file
29
c/src/tests/psxtests/psxreaddir/main.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Simple test program -- simplified version of sample test hello.
|
||||
*/
|
||||
|
||||
#define TEST_INIT
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
void test_main( void );
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
test_main();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
156
c/src/tests/psxtests/psxreaddir/psxreaddir.scn
Normal file
156
c/src/tests/psxtests/psxreaddir/psxreaddir.scn
Normal file
@@ -0,0 +1,156 @@
|
||||
|
||||
|
||||
*** READDIR TEST ***
|
||||
|
||||
chdir to the root directory
|
||||
chdir() status : 0
|
||||
|
||||
|
||||
Creating a series of directories under /
|
||||
Creating directory: a 0 0 Success
|
||||
Creating directory: b 0 0 Success
|
||||
Creating directory: c 0 0 Success
|
||||
Creating directory: d 0 0 Success
|
||||
Creating directory: e 0 0 Success
|
||||
Creating directory: f 0 0 Success
|
||||
Creating directory: c/y 0 0 Success
|
||||
Creating directory: c/z 0 0 Success
|
||||
Creating directory: c/x 0 0 Success
|
||||
Creating directory: c/y/a3333 0 0 Success
|
||||
Creating directory: c/y/j123 0 0 Success
|
||||
|
||||
Performing stat of directory /
|
||||
status for stat : 0, size of directory: 196
|
||||
|
||||
|
||||
Opening directory /
|
||||
name inode offset reclen type
|
||||
dev 1 0 28 0x001c
|
||||
a 1 28 28 0x001c
|
||||
b 1 56 28 0x001c
|
||||
c 1 84 28 0x001c
|
||||
d 1 112 28 0x001c
|
||||
e 1 140 28 0x001c
|
||||
f 1 168 28 0x001c
|
||||
|
||||
Opening directory /c
|
||||
name inode offset reclen type
|
||||
y 1 0 28 0x001c
|
||||
z 1 28 28 0x001c
|
||||
x 1 56 28 0x001c
|
||||
|
||||
Opening directory /c/y
|
||||
name inode offset reclen type
|
||||
a3333 1 0 28 0x001c
|
||||
j123 1 28 28 0x001c
|
||||
|
||||
LSEEK to the start of the open directory
|
||||
name inode offset reclen type
|
||||
dev 1 0 28 0x001c
|
||||
a 1 28 28 0x001c
|
||||
b 1 56 28 0x001c
|
||||
c 1 84 28 0x001c
|
||||
d 1 112 28 0x001c
|
||||
e 1 140 28 0x001c
|
||||
f 1 168 28 0x001c
|
||||
|
||||
Rewinding directory
|
||||
name inode offset reclen type
|
||||
dev 1 0 28 0x001c
|
||||
a 1 28 28 0x001c
|
||||
b 1 56 28 0x001c
|
||||
c 1 84 28 0x001c
|
||||
d 1 112 28 0x001c
|
||||
e 1 140 28 0x001c
|
||||
f 1 168 28 0x001c
|
||||
|
||||
Seek directory
|
||||
telldir() should report only sizeof(struct dirent) increments
|
||||
in position. Sizeof(struct dirent): 28
|
||||
seeked to 0 -- currently at 0
|
||||
seeked to 7 -- currently at 0
|
||||
seeked to 14 -- currently at 0
|
||||
seeked to 21 -- currently at 0
|
||||
seeked to 28 -- currently at 28
|
||||
seeked to 35 -- currently at 28
|
||||
seeked to 42 -- currently at 28
|
||||
seeked to 49 -- currently at 28
|
||||
seeked to 56 -- currently at 56
|
||||
seeked to 63 -- currently at 56
|
||||
seeked to 70 -- currently at 56
|
||||
seeked to 77 -- currently at 56
|
||||
seeked to 84 -- currently at 84
|
||||
seeked to 91 -- currently at 84
|
||||
seeked to 98 -- currently at 84
|
||||
seeked to 105 -- currently at 84
|
||||
seeked to 112 -- currently at 112
|
||||
seeked to 119 -- currently at 112
|
||||
seeked to 126 -- currently at 112
|
||||
seeked to 133 -- currently at 112
|
||||
seeked to 140 -- currently at 140
|
||||
seeked to 147 -- currently at 140
|
||||
seeked to 154 -- currently at 140
|
||||
seeked to 161 -- currently at 140
|
||||
seeked to 168 -- currently at 168
|
||||
seeked to 175 -- currently at 168
|
||||
seeked to 182 -- currently at 168
|
||||
seeked to 189 -- currently at 168
|
||||
seeked to 196 -- currently at 196
|
||||
|
||||
Closing directory
|
||||
|
||||
SCANDIR TEST
|
||||
|
||||
selection rule 1
|
||||
scanning for any entry under directory /c
|
||||
|
||||
SCANDIR SELECT1 accepts nodename: y
|
||||
SCANDIR SELECT1 accepts nodename: z
|
||||
SCANDIR SELECT1 accepts nodename: x
|
||||
|
||||
scandir status: 3
|
||||
Selected Node Name: y
|
||||
Selected Node Name: z
|
||||
Selected Node Name: x
|
||||
|
||||
selection rule 2
|
||||
scanning for any entry under directory /c whose name = y
|
||||
|
||||
SCANDIR SELECT accepted nodename: y
|
||||
SCANDIR SELECT rejected nodename: z
|
||||
SCANDIR SELECT rejected nodename: x
|
||||
|
||||
scandir status: 1
|
||||
Selected Node Name: y
|
||||
|
||||
SCANDIR with sorting
|
||||
|
||||
selection rule 1
|
||||
scanning for any entry under directory /c
|
||||
sort in ascending order
|
||||
|
||||
SCANDIR SELECT1 accepts nodename: y
|
||||
SCANDIR SELECT1 accepts nodename: z
|
||||
SCANDIR SELECT1 accepts nodename: x
|
||||
|
||||
scandir status: 3
|
||||
Selected and Sorted Node Name: x
|
||||
Selected and Sorted Node Name: y
|
||||
Selected and Sorted Node Name: z
|
||||
|
||||
SCANDIR with sorting
|
||||
|
||||
selection rule 1
|
||||
scanning for any entry under directory /c
|
||||
sort in descending order
|
||||
|
||||
SCANDIR SELECT1 accepts nodename: y
|
||||
SCANDIR SELECT1 accepts nodename: z
|
||||
SCANDIR SELECT1 accepts nodename: x
|
||||
scandir status: 3
|
||||
Selected and Sorted Node Name: z
|
||||
Selected and Sorted Node Name: y
|
||||
Selected and Sorted Node Name: x
|
||||
|
||||
|
||||
*** END OF READDIR TEST ***
|
||||
416
c/src/tests/psxtests/psxreaddir/test.c
Normal file
416
c/src/tests/psxtests/psxreaddir/test.c
Normal file
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* This is a native test to explore how the readdir() family works.
|
||||
* Newlib supports the following readdir() family members:
|
||||
*
|
||||
* closedir() -
|
||||
* readdir() -
|
||||
* scandir() -
|
||||
* opendir() -
|
||||
* rewinddir() -
|
||||
* telldir() - BSD not in POSIX
|
||||
* seekdir() - BSD not in POSIX
|
||||
*
|
||||
*
|
||||
* seekdir() takes an offset which is a byte offset. The Linux
|
||||
* implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1)
|
||||
* record where DIRENT_SIZE seems to be 12 bytes.
|
||||
*
|
||||
*
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "/usr1/rtems/mg10/rtems-mg10/c/src/lib/libc/libio_.h"
|
||||
|
||||
DIR *directory;
|
||||
DIR *directory2;
|
||||
DIR *directory3;
|
||||
DIR *directory_not;
|
||||
|
||||
#ifndef __P
|
||||
#define __P(args)()
|
||||
#endif
|
||||
|
||||
int scandir ( const char *dirname,
|
||||
struct dirent *** namelist,
|
||||
int (*select) __P((struct dirent *)),
|
||||
int (*dcomp) __P((const void *, const void *))
|
||||
);
|
||||
|
||||
#if defined(__rtems__)
|
||||
#define d_type d_reclen
|
||||
#endif
|
||||
|
||||
void printdir( DIR *directory )
|
||||
{
|
||||
struct dirent *d;
|
||||
|
||||
printf( " %-20s %8s %8s %8s %4s\n",
|
||||
" name", "inode", " offset", "reclen", " type" );
|
||||
d = readdir(directory);
|
||||
|
||||
while (d) {
|
||||
printf( " %-20s %8d %8d %6d 0x%04x\n",
|
||||
d->d_name, (int)d->d_ino, (int)d->d_off, d->d_reclen, d->d_type );
|
||||
d = readdir(directory);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
char *many_files[] = {
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"f",
|
||||
"g",
|
||||
"h",
|
||||
"i",
|
||||
"j",
|
||||
"k",
|
||||
"l",
|
||||
"m",
|
||||
"n",
|
||||
"o",
|
||||
"p",
|
||||
"q",
|
||||
"r",
|
||||
"s",
|
||||
"t",
|
||||
"u",
|
||||
"v",
|
||||
"w",
|
||||
"x",
|
||||
"y",
|
||||
"z",
|
||||
"aa",
|
||||
"ab",
|
||||
"ac",
|
||||
"ad",
|
||||
"ae",
|
||||
"af",
|
||||
"ag",
|
||||
"ah",
|
||||
"ai",
|
||||
"aj",
|
||||
"ak",
|
||||
"al",
|
||||
"am",
|
||||
"an",
|
||||
"ao",
|
||||
"ap",
|
||||
"aq",
|
||||
"ar"
|
||||
};
|
||||
|
||||
char *dnames[] = {
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"f",
|
||||
"c/y",
|
||||
"c/z",
|
||||
"c/x",
|
||||
"c/y/a3333",
|
||||
"c/y/j123",
|
||||
"END"
|
||||
};
|
||||
|
||||
int select1 ( struct dirent *entry )
|
||||
{
|
||||
printf("SCANDIR SELECT1 accepts nodename: %s\n", entry->d_name );
|
||||
return 1;
|
||||
}
|
||||
|
||||
int select2 ( struct dirent *entry )
|
||||
{
|
||||
if( strcmp( entry->d_name, "y") == 0 ) {
|
||||
printf("SCANDIR SELECT accepted nodename: %s\n", entry->d_name );
|
||||
return 1;
|
||||
}
|
||||
printf("SCANDIR SELECT rejected nodename: %s\n", entry->d_name );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int compare_ascending( struct dirent **a, struct dirent **b )
|
||||
{
|
||||
int i;
|
||||
|
||||
i = strcmp (
|
||||
(char *)((struct dirent *)(*a)->d_name),
|
||||
(char *)((struct dirent *)(*b)->d_name)
|
||||
);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int compare_descending( struct dirent **a, struct dirent **b )
|
||||
{
|
||||
int i;
|
||||
|
||||
i = strcmp (
|
||||
(char *)((struct dirent *)(*b)->d_name),
|
||||
(char *)((struct dirent *)(*a)->d_name)
|
||||
);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
int fd;
|
||||
int i;
|
||||
int status;
|
||||
off_t off;
|
||||
struct dirent *d_not;
|
||||
struct dirent **namelist;
|
||||
struct stat s;
|
||||
|
||||
|
||||
printf( "\n\n*** READDIR TEST ***\n" );
|
||||
|
||||
printf( "\nchdir to the root directory\n" );
|
||||
status = chdir( "/" );
|
||||
printf( "chdir() status : %d\n\n", status );
|
||||
|
||||
printf( "\nCreating a series of directories under /\n" );
|
||||
i=0;
|
||||
while ( strcmp(dnames[i], "END") != 0 )
|
||||
{
|
||||
status = mkdir( dnames[i], 0x1c0 );
|
||||
printf("Creating directory: %s %d %d ", dnames[i], status, errno );
|
||||
if ( errno == 0 )
|
||||
printf(" Success\n");
|
||||
else
|
||||
printf(" Failure\n");
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
status = mkdir( "/many", 0x1c0 );
|
||||
status = chdir( "/many" );
|
||||
for (i = 0; i<=44; i++) {
|
||||
fd = open (many_files[i], O_CREAT);
|
||||
close (fd);
|
||||
}
|
||||
directory_not = opendir( "/many" );
|
||||
printdir ( directory_not );
|
||||
d_not = readdir( directory_not );
|
||||
|
||||
fd = open ("/b/my_file", O_CREAT);
|
||||
assert( fd != -1 );
|
||||
close (fd);
|
||||
|
||||
status = scandir(
|
||||
"/b/my_file",
|
||||
&namelist,
|
||||
select1,
|
||||
NULL
|
||||
);
|
||||
|
||||
fd = open( "/b/new_file", O_CREAT );
|
||||
assert( fd != -1 );
|
||||
|
||||
status = fcntl( fd, F_SETFD, 1 );
|
||||
assert( status == 0 );
|
||||
status = fcntl( fd, F_GETFD, 1 );
|
||||
assert( status == 1 );
|
||||
|
||||
status = fcntl( fd, F_DUPFD, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_GETFL, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_SETFL, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_GETLK, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_SETLK, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_SETLKW, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_SETOWN, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, F_GETOWN, 1 );
|
||||
assert ( status == -1 );
|
||||
|
||||
status = fcntl( fd, 0xb, 1 );
|
||||
assert( status == -1 );
|
||||
|
||||
directory_not = opendir ("/b/my_file");
|
||||
d_not = readdir(directory_not);
|
||||
|
||||
directory_not = opendir ("/a");
|
||||
d_not = readdir (directory_not);
|
||||
|
||||
status = chdir ("/b/my_file");
|
||||
assert (status == -1);
|
||||
|
||||
printf( "\nPerforming stat of directory /\n");
|
||||
status = stat( "/", &s );
|
||||
printf("status for stat : %d, size of directory: %d\n\n",
|
||||
status,(int)s.st_size);
|
||||
|
||||
puts( "\nOpening directory /" );
|
||||
directory = opendir("/");
|
||||
|
||||
assert( directory );
|
||||
|
||||
printdir(directory);
|
||||
|
||||
printf("\nmkdir /d/my_dir\n");
|
||||
status = mkdir( "/d/my_dir", 0x1c0 );
|
||||
printf("Open /d/my_dir\n");
|
||||
directory_not = opendir( "/d/my_dir" );
|
||||
assert( directory_not );
|
||||
|
||||
printf( "remove /d/my_dir.\n" );
|
||||
status = rmdir( "/d/my_dir" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf( "close /d/my_dir.\n" );
|
||||
closedir( directory_not );
|
||||
|
||||
printf( "\nOpening directory /c\n" );
|
||||
directory2 = opendir("/c");
|
||||
|
||||
assert( directory2 );
|
||||
|
||||
printdir(directory2);
|
||||
status = closedir( directory2 );
|
||||
|
||||
printf( "\nOpening directory /c/y\n" );
|
||||
directory3 = opendir("/c/y");
|
||||
|
||||
assert( directory3 );
|
||||
|
||||
printdir(directory3);
|
||||
status = closedir( directory3 );
|
||||
|
||||
printf( "\nLSEEK to the start of the open directory\n" );
|
||||
lseek( directory->dd_fd, 0, SEEK_SET );
|
||||
printdir(directory);
|
||||
|
||||
lseek( directory->dd_fd, 0, SEEK_CUR );
|
||||
|
||||
lseek( directory->dd_fd, 0, SEEK_END );
|
||||
|
||||
lseek( directory->dd_fd, 0, -99 );
|
||||
|
||||
printf( "\nRewinding directory\n" );
|
||||
rewinddir( directory );
|
||||
printdir(directory);
|
||||
|
||||
/* Don't know how to check this one automatically. */
|
||||
printf( "Send rewinddir a NULL pointer\n");
|
||||
rewinddir( NULL );
|
||||
|
||||
printf( "\nSeek directory\n" );
|
||||
printf( "telldir() should report only sizeof(struct dirent) increments \n" );
|
||||
printf( "in position. Sizeof(struct dirent): %d\n", sizeof(struct dirent) );
|
||||
rewinddir( directory );
|
||||
for( off=0 ; off<=200 ; off=off + sizeof(struct dirent) / 4 ) {
|
||||
seekdir( directory, off );
|
||||
printf(
|
||||
"seeked to %2d -- currently at %2d\n",
|
||||
(int)off,
|
||||
(int)telldir(directory)
|
||||
);
|
||||
}
|
||||
|
||||
seekdir( NULL, off );
|
||||
|
||||
printf( "\nClosing directory\n" );
|
||||
status = closedir( directory );
|
||||
|
||||
printf( "\nSCANDIR TEST\n");
|
||||
printf( "\nselection rule 1\n");
|
||||
printf( "scanning for any entry under directory /c\n\n");
|
||||
status = scandir(
|
||||
"/c",
|
||||
&namelist,
|
||||
select1,
|
||||
NULL
|
||||
);
|
||||
printf("\nscandir status: %d\n", status );
|
||||
for ( i=0; i<status; i++)
|
||||
{
|
||||
printf("Selected Node Name: %s\n", namelist[i]->d_name );
|
||||
}
|
||||
|
||||
printf( "\nselection rule 2\n");
|
||||
printf( "scanning for any entry under directory /c whose name = y\n\n");
|
||||
status = scandir(
|
||||
"/c",
|
||||
&namelist,
|
||||
select2,
|
||||
NULL
|
||||
);
|
||||
printf("\nscandir status: %d\n", status );
|
||||
for ( i=0; i<status; i++)
|
||||
{
|
||||
printf("Selected Node Name: %s\n", namelist[i]->d_name );
|
||||
}
|
||||
|
||||
printf( "\nSCANDIR with sorting\n" );
|
||||
printf( "\nselection rule 1\n");
|
||||
printf( "scanning for any entry under directory /c\n");
|
||||
printf( "sort in ascending order\n\n");
|
||||
status = scandir(
|
||||
"/c",
|
||||
&namelist,
|
||||
select1,
|
||||
compare_ascending
|
||||
);
|
||||
printf("\nscandir status: %d\n", status );
|
||||
for ( i=0; i<status; i++)
|
||||
{
|
||||
printf("Selected and Sorted Node Name: %s\n", namelist[i]->d_name );
|
||||
}
|
||||
|
||||
|
||||
printf( "\nSCANDIR with sorting\n" );
|
||||
printf( "\nselection rule 1\n");
|
||||
printf( "scanning for any entry under directory /c\n");
|
||||
printf( "sort in descending order\n\n");
|
||||
status = scandir(
|
||||
"/c",
|
||||
&namelist,
|
||||
select1,
|
||||
compare_descending
|
||||
);
|
||||
printf("scandir status: %d\n", status );
|
||||
for ( i=0; i<status; i++)
|
||||
{
|
||||
printf("Selected and Sorted Node Name: %s\n", namelist[i]->d_name );
|
||||
}
|
||||
|
||||
|
||||
printf( "\n\n*** END OF READDIR TEST ***\n" );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
63
c/src/tests/psxtests/psxstat/Makefile.in
Normal file
63
c/src/tests/psxtests/psxstat/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
@SET_MAKE@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
RTEMS_ROOT = @top_srcdir@
|
||||
PROJECT_ROOT = @PROJECT_ROOT@
|
||||
|
||||
TEST=stat
|
||||
|
||||
MANAGERS=all
|
||||
|
||||
# C source names, if any, go here -- minus the .c
|
||||
C_PIECES=main test
|
||||
C_FILES=$(C_PIECES:%=%.c)
|
||||
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
|
||||
|
||||
H_FILES=
|
||||
|
||||
DOCTYPES=scn
|
||||
DOCS=$(DOCTYPES:%=$(TEST).%)
|
||||
|
||||
SRCS=$(DOCS) $(C_FILES) $(H_FILES)
|
||||
OBJS=$(C_O_FILES)
|
||||
|
||||
PRINT_SRCS=$(DOCS)
|
||||
|
||||
PGM=${ARCH}/$(TEST).exe
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
|
||||
include $(RTEMS_ROOT)/make/leaf.cfg
|
||||
|
||||
#
|
||||
# (OPTIONAL) Add local stuff here using +=
|
||||
#
|
||||
|
||||
DEFINES +=
|
||||
CPPFLAGS +=
|
||||
CFLAGS +=
|
||||
|
||||
LD_PATHS +=
|
||||
LD_LIBS +=
|
||||
LDFLAGS +=
|
||||
|
||||
#
|
||||
# Add your list of files to delete here. The config files
|
||||
# already know how to delete some stuff, so you may want
|
||||
# to just run 'make clean' first to see what gets missed.
|
||||
# 'make clobber' already includes 'make clean'
|
||||
#
|
||||
|
||||
CLEAN_ADDITIONS +=
|
||||
CLOBBER_ADDITIONS +=
|
||||
|
||||
all: ${ARCH} $(SRCS) $(PGM)
|
||||
$(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
|
||||
$(INSTALL) $(srcdir)/$(TEST).scn \
|
||||
${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn
|
||||
|
||||
${PGM}: $(OBJS) $(LINK_FILES)
|
||||
$(make-exe)
|
||||
40
c/src/tests/psxtests/psxstat/main.c
Normal file
40
c/src/tests/psxtests/psxstat/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Simple test program -- simplified version of sample test hello.
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1998.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* Copyright assigned to U.S. Government, 1994.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.OARcorp.com/rtems/license.html.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#define TEST_INIT
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
void test_main( void );
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
{
|
||||
test_main();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <confdefs.h>
|
||||
|
||||
/* end of file */
|
||||
1253
c/src/tests/psxtests/psxstat/psxstat.scn
Normal file
1253
c/src/tests/psxtests/psxstat/psxstat.scn
Normal file
File diff suppressed because it is too large
Load Diff
834
c/src/tests/psxtests/psxstat/test.c
Normal file
834
c/src/tests/psxtests/psxstat/test.c
Normal file
@@ -0,0 +1,834 @@
|
||||
/*
|
||||
* This test exercises stat() via fstat() and generates as many of the
|
||||
* path evaluation cases as possible.
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1998.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* Copyright assigned to U.S. Government, 1994.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.OARcorp.com/rtems/license.html.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <tmacros.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <rtems.h>
|
||||
#include <rtems/libio.h>
|
||||
|
||||
#define MAXSYMLINK 5 /* There needs to be a better way of getting this. */
|
||||
|
||||
/*
|
||||
* List of files which should exist.
|
||||
*/
|
||||
|
||||
char *Files[] = {
|
||||
"////dir1/\\//file1\\\\//",
|
||||
"/dir1/file2",
|
||||
"/dir1/file3",
|
||||
"/dir1/file4",
|
||||
"/dir1/dir1/file1",
|
||||
"../../..//dir1/./././dir1/ file1",
|
||||
"main.c",
|
||||
0
|
||||
};
|
||||
|
||||
/*
|
||||
* List of directories which should exist.
|
||||
*/
|
||||
|
||||
char *Directories[] = {
|
||||
"/dir1",
|
||||
"/dir2",
|
||||
"/dir3",
|
||||
"/dir4",
|
||||
"/dir1/dir1",
|
||||
"/./././dir1/ dir1",
|
||||
"/./././links",
|
||||
"///dir1/dir1/../../dir1/../symlinks/////",
|
||||
0
|
||||
};
|
||||
|
||||
char *Links_to_Dirs[]= {
|
||||
"dir1/dir1/../../links/dir1",
|
||||
"links/dir2",
|
||||
"links/dir3",
|
||||
"links/dir4",
|
||||
"links/dir1_dir1",
|
||||
"links/dir1_ dir1",
|
||||
"links/../links/../links/links",
|
||||
0
|
||||
};
|
||||
|
||||
char *Links_to_Files[]= {
|
||||
"links/dir1_file1",
|
||||
"links/dir1_file2",
|
||||
"links/dir1_file3",
|
||||
"links/dir1_file4",
|
||||
"links/dir1_dir1_f1",
|
||||
"links/dir1_dir1 f1",
|
||||
0
|
||||
};
|
||||
|
||||
char *Links_to_dirlinks[]= {
|
||||
"links/links/links/links_dir1",
|
||||
"links//links_dir2",
|
||||
"links//links_dir3",
|
||||
"links//links_dir4",
|
||||
"links//links_dir1_d1",
|
||||
"links//links_dir1 d1",
|
||||
"links//links_links",
|
||||
0
|
||||
};
|
||||
|
||||
char *Links_to_filelinks[]= {
|
||||
"links///links_d1_file1",
|
||||
"links///links_d1_file2",
|
||||
"links///links_d1_file3",
|
||||
"links///links_d1_file4",
|
||||
"links///links_d1_d1_f1",
|
||||
"links///links_r1_d1 f1",
|
||||
0
|
||||
};
|
||||
|
||||
char *SymLinks[]= {
|
||||
"/symlinks/a_file_symlink",
|
||||
"/symlinks/a_dir_symlink",
|
||||
"/symlinks/a_link_symlink",
|
||||
"../symlinks/no_file",
|
||||
"/symlinks/a_dir_symlink/a_file_symlink",
|
||||
0
|
||||
};
|
||||
|
||||
/*
|
||||
* List of absolute paths to stat.
|
||||
*/
|
||||
|
||||
char *Good_absolute_paths[] = {
|
||||
"/dev",
|
||||
"////dir1/\\//file1\\\\//",
|
||||
"/dir1/\\\\/file2",
|
||||
"/dir1/file3/////\\\\\\",
|
||||
"/dir1/file4",
|
||||
"/dir1/dir1/file1",
|
||||
"/dir1/dir1/ file1",
|
||||
"/dir1",
|
||||
"/dir2//////\\",
|
||||
"/dir3",
|
||||
"/dir4",
|
||||
"/dir1/dir1",
|
||||
"/dir1/ dir1///\\\\",
|
||||
"/\\/\\/\\/\\/\\/\\/links\\/\\/\\/\\/\\/\\",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
char *Bad_paths[] = {
|
||||
"/links/ENAMETOOLONG___",
|
||||
"/dir1/file4/NOTADIR",
|
||||
"/dir1/dir1/EACCES__",
|
||||
0
|
||||
};
|
||||
|
||||
/*
|
||||
* List of relative paths to stat.
|
||||
*/
|
||||
|
||||
char *Good_relative_paths[] = {
|
||||
"dev",
|
||||
"dir1/\\//file1\\\\//",
|
||||
"dir1/\\\\/file2",
|
||||
"dir1/file3/////\\\\\\",
|
||||
"dir1/file4",
|
||||
"dir1/dir1/file1",
|
||||
"dir1/dir1/ file1",
|
||||
"dir1",
|
||||
"dir2//////\\",
|
||||
"dir3",
|
||||
"dir4",
|
||||
"dir1/dir1",
|
||||
"dir1/ dir1///\\\\",
|
||||
"main.c",
|
||||
0
|
||||
};
|
||||
|
||||
/*
|
||||
* Do a stat on a single file and report the status.
|
||||
*/
|
||||
|
||||
void stat_a_file(
|
||||
const char *file
|
||||
)
|
||||
{
|
||||
int status;
|
||||
struct stat statbuf;
|
||||
int major1;
|
||||
int minor1;
|
||||
int major2;
|
||||
int minor2;
|
||||
|
||||
|
||||
assert( file );
|
||||
|
||||
printf( "stat( %s ) returned ", file );
|
||||
fflush( stdout );
|
||||
|
||||
status = stat( file, &statbuf );
|
||||
|
||||
if ( status == -1 ) {
|
||||
printf( ": %s\n", strerror( errno ) );
|
||||
} else {
|
||||
|
||||
rtems_filesystem_split_dev_t( statbuf.st_dev, major1, minor1 );
|
||||
rtems_filesystem_split_dev_t( statbuf.st_rdev, major2, minor2 );
|
||||
|
||||
|
||||
printf("\n st_dev (0x%x:0x%x)\n", major1, minor1 );
|
||||
printf( " st_ino %x\n", statbuf.st_ino );
|
||||
printf( " st_mode %o\n", statbuf.st_mode );
|
||||
printf( " st_nlink %x\n", statbuf.st_nlink );
|
||||
printf( " st_uid %d\n", statbuf.st_uid );
|
||||
printf( " st_gid %d\n", statbuf.st_gid );
|
||||
printf( " st_rdev (0x%x:0x%x)\n", major2, minor2 );
|
||||
printf( " st_size %d\n",(unsigned int) statbuf.st_size );
|
||||
printf( " st_atime %s", ctime( &statbuf.st_atime ) );
|
||||
printf( " st_mtime %s", ctime( &statbuf.st_mtime ) );
|
||||
printf( " st_ctime %s", ctime( &statbuf.st_ctime ) );
|
||||
#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
|
||||
printf( " st_blksize %x\n", statbuf.st_blksize );
|
||||
printf( " st_blocks %x\n", statbuf.st_blocks );
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* stat() multiple files at a time
|
||||
*/
|
||||
|
||||
void stat_multiple_files(
|
||||
char **files
|
||||
)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while ( files[i] ) {
|
||||
stat_a_file( files[i] );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* chown() multiple files at a time
|
||||
*/
|
||||
void chown_multiple_files(
|
||||
char **files
|
||||
)
|
||||
{
|
||||
int i;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
|
||||
#if defined(RTEMS_POSIX_API)
|
||||
st_uid = geteuid();
|
||||
st_gid = getegid();
|
||||
#else
|
||||
st_uid = 100;
|
||||
st_gid = 0;
|
||||
#endif
|
||||
|
||||
i = 0;
|
||||
while ( files[i] ) {
|
||||
printf("Change group of %s\n", files[i]);
|
||||
chown( files[i], st_uid, (st_gid+1) );
|
||||
stat_a_file( files[i] );
|
||||
|
||||
printf("Change owner of %s\n", files[i]);
|
||||
chown( files[i], (st_uid+1), st_gid );
|
||||
stat_a_file( files[i] );
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* mknod() multiple files at a time
|
||||
*/
|
||||
|
||||
void make_multiple_files(
|
||||
char **files
|
||||
)
|
||||
{
|
||||
int i;
|
||||
int status;
|
||||
|
||||
i = 0;
|
||||
while ( files[i] ) {
|
||||
printf( "Making file %s\n", files[i] );
|
||||
status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL );
|
||||
assert( !status );
|
||||
i++;
|
||||
}
|
||||
puts( "" );
|
||||
}
|
||||
|
||||
void make_multiple_bad_files(
|
||||
char **files
|
||||
)
|
||||
{
|
||||
int i;
|
||||
int status;
|
||||
|
||||
i = 0;
|
||||
while ( files[i] ) {
|
||||
printf( "Making file %s ", files[i] );
|
||||
status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL );
|
||||
assert( status );
|
||||
printf( ": %s\n", strerror( errno ) );
|
||||
i++;
|
||||
}
|
||||
puts( "" );
|
||||
}
|
||||
|
||||
void make_multiple_links(
|
||||
char **existing,
|
||||
char **new
|
||||
)
|
||||
{
|
||||
int i;
|
||||
int status;
|
||||
|
||||
i = 0;
|
||||
while ( new[i] && existing[i] ) {
|
||||
printf( "Making file %s\n", new[i] );
|
||||
status = link( existing[i], new[i] );
|
||||
assert( !status );
|
||||
i++;
|
||||
}
|
||||
puts( "" );
|
||||
|
||||
status = link( "fred", "bob" );
|
||||
assert( status == -1 );
|
||||
|
||||
status = link( existing[1], "doug/bob" );
|
||||
assert( status == -1 );
|
||||
}
|
||||
|
||||
|
||||
void make_too_many_links()
|
||||
{
|
||||
int i;
|
||||
int status;
|
||||
char name [20];
|
||||
|
||||
status = mkdir("/dummy", S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
for (i=1; i<= LINK_MAX; i++) {
|
||||
|
||||
sprintf(name,"/LinkName%d",i);
|
||||
printf( "Making file %s\n", name );
|
||||
status = link("/dummy" , name );
|
||||
if( i < LINK_MAX )
|
||||
assert( !status );
|
||||
else
|
||||
assert( status == -1 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void make_a_symlink(
|
||||
char *existing,
|
||||
char *new
|
||||
)
|
||||
{
|
||||
int status;
|
||||
char buf[100];
|
||||
int len;
|
||||
|
||||
memset( buf, 0, 100 );
|
||||
|
||||
printf( "Making file %s\n", new );
|
||||
status = symlink( existing, new );
|
||||
assert( !status );
|
||||
|
||||
printf( "Verify with readlink\n");
|
||||
status = readlink( new, buf, 100 );
|
||||
len = strlen( existing );
|
||||
assert ( status == len );
|
||||
|
||||
status = readlink( new, buf, 3 );
|
||||
len = strlen( existing );
|
||||
if (len < 3 )
|
||||
assert( status == len );
|
||||
else
|
||||
assert( status == 3 );
|
||||
|
||||
status = strcmp( existing, buf );
|
||||
assert( !status );
|
||||
}
|
||||
|
||||
void make_multiple_symlinks()
|
||||
{
|
||||
int status;
|
||||
|
||||
make_a_symlink( Files[0], SymLinks[0] );
|
||||
make_a_symlink( Directories[0], SymLinks[1] );
|
||||
make_a_symlink( Links_to_dirlinks[0], SymLinks[2] );
|
||||
make_a_symlink( "No_File", SymLinks[3] );
|
||||
make_a_symlink( SymLinks[1], SymLinks[4] );
|
||||
make_a_symlink( "//links", "/symlinks/links" );
|
||||
|
||||
stat_a_file( SymLinks[0] );
|
||||
stat_a_file( SymLinks[1] );
|
||||
stat_a_file( SymLinks[2] );
|
||||
stat_a_file( SymLinks[3] );
|
||||
stat_a_file( SymLinks[4] );
|
||||
|
||||
status = symlink( "//links", "bob/frank" );
|
||||
assert (status == -1);
|
||||
|
||||
}
|
||||
/*
|
||||
void make_too_many_symlinks()
|
||||
{
|
||||
int i, status;
|
||||
char name1[8];
|
||||
|
||||
for (i=1; i <= MAXSYMLINK; i++) {
|
||||
sprintf( name1, "SymLink%d", i );
|
||||
status = symlink( "/dummy", name1 );
|
||||
if( i < MAXSYMLINK )
|
||||
assert( !status );
|
||||
else
|
||||
assert( status == -1 );
|
||||
}
|
||||
}
|
||||
*/
|
||||
void make_many_symlinks(
|
||||
char *real_file,
|
||||
int link_count
|
||||
)
|
||||
{
|
||||
int i;
|
||||
char name1[5];
|
||||
char name2[5];
|
||||
char *link_file;
|
||||
|
||||
link_file = real_file;
|
||||
for (i=1; i < link_count; i++) {
|
||||
sprintf( name1, "%d", i );
|
||||
make_a_symlink( link_file, name1 );
|
||||
strcpy( name2, name1 );
|
||||
link_file = name2;
|
||||
}
|
||||
|
||||
for (i=1; i < link_count; i++) {
|
||||
sprintf( name1, "%d", i );
|
||||
stat_a_file( name1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* mkdir() multiple directories at a time
|
||||
*/
|
||||
|
||||
void make_multiple_directories(
|
||||
char **files
|
||||
)
|
||||
{
|
||||
int i;
|
||||
int status;
|
||||
|
||||
i = 0;
|
||||
while ( files[i] ) {
|
||||
printf( "Making directory %s\n", files[i] );
|
||||
status = mkdir( files[i], S_IRWXU );
|
||||
assert( !status );
|
||||
i++;
|
||||
}
|
||||
puts( "" );
|
||||
}
|
||||
|
||||
/*
|
||||
* Cause faults.
|
||||
*/
|
||||
|
||||
|
||||
void Cause_faults()
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
char longer_name[100];
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry;
|
||||
|
||||
/*
|
||||
* Verify chmod with an invalid type.
|
||||
*/
|
||||
|
||||
printf("\n\nPass an invalid mode to chmod should fail with EPERM \n" );
|
||||
status = chmod( Files[0], S_IFREG );
|
||||
assert( status == -1 );
|
||||
assert( errno == EPERM );
|
||||
|
||||
/*
|
||||
* Try to chdir to a file.
|
||||
*/
|
||||
|
||||
printf("chdir to a file should fail with ENOTDIR\n");
|
||||
status = chdir( Files[0] );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOTDIR );
|
||||
|
||||
/*
|
||||
* Change mode to read/write on a directory.
|
||||
* Verify directory works properly.
|
||||
*/
|
||||
|
||||
printf("Verify RWX permission on %s via access\n", Directories[0]);
|
||||
status = access( Directories[0], ( R_OK | W_OK | X_OK ) );
|
||||
assert( status == 0 );
|
||||
|
||||
printf( "chmod of %s to Read/Write\n", Directories[0] );
|
||||
status = chmod( Directories[0], (S_IXGRP | S_IXOTH) );
|
||||
assert( status == 0 );
|
||||
|
||||
printf( "chmod fred should fail with ENOENT\n" );
|
||||
status = chmod( "fred", (S_IXGRP | S_IXOTH) );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOENT );
|
||||
|
||||
strcpy(longer_name, Directories[0] );
|
||||
strcat(longer_name, "/BADNAME" );
|
||||
printf( "Create under %s should fail with EACCES\n", Directories[0] );
|
||||
status = mkdir( longer_name , S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == EACCES );
|
||||
|
||||
printf("chdir to %s should fail with EACCES\n", Directories[4] );
|
||||
status = chdir( Directories[4] );
|
||||
assert( status == -1 );
|
||||
assert( errno == EACCES );
|
||||
|
||||
/*
|
||||
* Check stat with a NULL buffer.
|
||||
*/
|
||||
|
||||
printf("Stat with a NULL buffer should fail with EFAULT\n");
|
||||
status = stat( Directories[0], NULL );
|
||||
assert( status == -1 );
|
||||
assert( errno == EFAULT );
|
||||
|
||||
/*
|
||||
* Set current to a directory with no owner permissions.
|
||||
* Verify it works properly.
|
||||
*/
|
||||
|
||||
printf( "\n\nchmod of %s to Read/Write\n", Directories[0] );
|
||||
status = chmod( Directories[0], (S_IXGRP | S_IXOTH) );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("mkdir %s should fail with EACCESS\n", longer_name );
|
||||
status = mkdir( longer_name , S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == EACCES );
|
||||
|
||||
printf("\n%s Should exist ( access )\n",Directories[0] );
|
||||
status = access( Directories[0], F_OK );
|
||||
assert( status == 0 );
|
||||
printf("\n%s Should have read permission( access )\n",Directories[0] );
|
||||
status = access( Directories[0], R_OK );
|
||||
assert( status != 0 );
|
||||
printf("\n%s Should have write permission( access )\n",Directories[0] );
|
||||
status = access( Directories[0], W_OK );
|
||||
assert( status != 0 );
|
||||
printf("\n%s Should not have execute permission( access )\n",Directories[0] );
|
||||
status = access( Directories[0], X_OK );
|
||||
assert( status != 0 );
|
||||
|
||||
printf("\nRestore %s to RWX\n",Directories[0] );
|
||||
status = chmod( Directories[0], S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("chdir to / \n");
|
||||
status = chdir( "/" );
|
||||
assert( status == 0 );
|
||||
|
||||
/*
|
||||
* Remove one of the directories.
|
||||
* Verify links to the removed directory still work.
|
||||
*/
|
||||
|
||||
printf( "Remove %s\n", Directories[5] );
|
||||
status = rmdir( Directories[5] );
|
||||
assert( status == 0 );
|
||||
|
||||
stat_a_file( Directories[5] );
|
||||
status = access( Directories[5], F_OK );
|
||||
assert( status != 0 );
|
||||
|
||||
stat_a_file( Links_to_Dirs[5] );
|
||||
status = readlink( Links_to_Dirs[5], longer_name, 3 );
|
||||
assert( status == -1 );
|
||||
assert( errno == EINVAL );
|
||||
|
||||
stat_a_file( Links_to_dirlinks[5] );
|
||||
printf("Chdir to %s\n", Links_to_Dirs[5] );
|
||||
status = chdir( Links_to_Dirs[5] );
|
||||
assert( status == 0 );
|
||||
|
||||
/*
|
||||
* Verify we cannot move up from a node with no parent node.
|
||||
*/
|
||||
|
||||
printf("Chdir to .. should fail with ENOENT\n" );
|
||||
status = chdir( ".." );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOENT );
|
||||
|
||||
/*
|
||||
* Create a subdirectory under the dangling node.
|
||||
*/
|
||||
|
||||
printf("mkdir ../t should fail with ENOENT\n" );
|
||||
status = mkdir( "../t" , S_IRWXU );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOENT );
|
||||
|
||||
printf("mkdir t\n");
|
||||
status = mkdir( "t" , S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("chdir to / \n");
|
||||
status = chdir( "/" );
|
||||
assert( status == 0 );
|
||||
|
||||
/*
|
||||
* Check rmdir, rmnod, and unlink
|
||||
*/
|
||||
|
||||
printf("rmdir %s should fail with ENOTDIR\n", Links_to_Dirs[5] );
|
||||
status = rmdir( Links_to_Dirs[5] );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOTDIR );
|
||||
|
||||
printf("unlink %s\n", Links_to_Dirs[5] );
|
||||
status = unlink( Links_to_Dirs[5] );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("unlink %s should fail with ENOTEMPTY\n", Links_to_dirlinks[5] );
|
||||
status = unlink( Links_to_dirlinks[5] );
|
||||
assert( status == -1 );
|
||||
assert( errno == ENOTEMPTY );
|
||||
|
||||
strcpy( longer_name, Links_to_dirlinks[5] );
|
||||
strcat( longer_name, "/t");
|
||||
printf("rmdir %s\n", longer_name );
|
||||
status = rmdir( longer_name );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("unlink %s\n", Links_to_Dirs[5]);
|
||||
status = unlink( Links_to_dirlinks[5] );
|
||||
assert( status == 0 );
|
||||
|
||||
status = chdir( Directories[0] );
|
||||
status = mkdir ( "my_mount_point", S_IRWXU );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("Attempting to mount IMFS file system at /dir1/my_mount_point \n");
|
||||
status = mount(
|
||||
&mt_entry,
|
||||
&IMFS_ops,
|
||||
"RW",
|
||||
NULL,
|
||||
"/dir1/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("rmdir /dir1/my_mount_point should fail with EBUSY\n");
|
||||
status = rmdir ("/dir1/my_mount_point" );
|
||||
assert( status == -1 );
|
||||
assert( errno == EBUSY );
|
||||
|
||||
printf( "Unmount /dir1/my_mount_point\n");
|
||||
status = unmount( "/dir1/my_mount_point" );
|
||||
assert( status == 0 );
|
||||
|
||||
/*
|
||||
* Verify write permission is checked.
|
||||
*/
|
||||
|
||||
printf("chmod of %s to group and other execute\n", Files[0] );
|
||||
status = chmod (Files[0], (S_IXGRP | S_IXOTH) );
|
||||
assert( status == 0 );
|
||||
|
||||
printf("Open %s for write should fail with EACCES\n", Files[0] );
|
||||
fd = open (Files[0], O_WRONLY);
|
||||
assert( fd == -1 );
|
||||
assert( errno == EACCES );
|
||||
|
||||
printf("chmod of %s to User Execute and Read\n", Directories[3] );
|
||||
status = chmod (Directories[3], (S_IXUSR | S_IRUSR) );
|
||||
assert( status == 0 );
|
||||
strcpy(longer_name, Directories[3] );
|
||||
strcat(longer_name, "/NewFile" );
|
||||
printf("Mkdir of %s should fail with EACCES\n",longer_name );
|
||||
status = mkdir( longer_name, S_IRWXU );
|
||||
assert( status != 0 );
|
||||
assert( errno == EACCES );
|
||||
|
||||
printf(" Making too many hard links.\n" );
|
||||
make_too_many_links( );
|
||||
|
||||
printf( "pass fstat a null pointer should fail with EFAULT\n");
|
||||
status = fstat( fd, NULL );
|
||||
assert( status == -1 );
|
||||
assert( errno == EFAULT);
|
||||
|
||||
/*
|
||||
* The current directory MUST be restored at the end of this test.
|
||||
*/
|
||||
|
||||
printf("chdir to / \n");
|
||||
status = chdir( "/" );
|
||||
assert( status == 0 );
|
||||
|
||||
}
|
||||
|
||||
void Show_Time()
|
||||
{
|
||||
rtems_time_of_day time;
|
||||
rtems_status_code status;
|
||||
|
||||
status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
|
||||
printf(">>>>Current Time: ");
|
||||
print_time( " - rtems_clock_get - ", &time, "\n" );
|
||||
}
|
||||
|
||||
/*
|
||||
* main entry point to the test
|
||||
*/
|
||||
|
||||
#if defined(__rtems__)
|
||||
int test_main(void)
|
||||
#else
|
||||
int main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#endif
|
||||
{
|
||||
rtems_status_code status;
|
||||
rtems_time_of_day time;
|
||||
|
||||
puts( "\n\n*** STAT TEST 01 ***" );
|
||||
|
||||
build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
|
||||
status = rtems_clock_set( &time );
|
||||
|
||||
/*
|
||||
* Create the files and directories for the test.
|
||||
*/
|
||||
Show_Time();
|
||||
|
||||
make_multiple_directories( Directories );
|
||||
make_multiple_files( Files );
|
||||
make_multiple_links( Directories, Links_to_Dirs );
|
||||
make_multiple_links( Files, Links_to_Files );
|
||||
|
||||
status = rtems_task_wake_after( 5 * TICKS_PER_SECOND );
|
||||
make_multiple_links( Links_to_Dirs, Links_to_dirlinks );
|
||||
status = rtems_task_wake_after( 5 * TICKS_PER_SECOND );
|
||||
make_multiple_links( Links_to_Files, Links_to_filelinks );
|
||||
|
||||
status = rtems_task_wake_after( 5 * TICKS_PER_SECOND );
|
||||
|
||||
/*
|
||||
* Now go through all the absolute path.
|
||||
*/
|
||||
|
||||
puts( "Doing the stat() on all the good absolute paths" );
|
||||
stat_multiple_files( Good_absolute_paths );
|
||||
|
||||
/*
|
||||
* run through the relative paths.
|
||||
*/
|
||||
|
||||
puts( "\nDoing the stat() on all the good relative paths" );
|
||||
stat_multiple_files( Good_relative_paths );
|
||||
|
||||
/*
|
||||
* Change directory and releative paths are now bad.
|
||||
*/
|
||||
|
||||
puts("\nchdir to dev");
|
||||
chdir("dev");
|
||||
puts("\nstat relative paths that are now bad");
|
||||
stat_multiple_files( Good_relative_paths );
|
||||
|
||||
/*
|
||||
* Change directory to the link directory and follow links.
|
||||
*/
|
||||
|
||||
puts("\nchdir to ../links");
|
||||
chdir("../links");
|
||||
puts("Doing the stat() on good links\n");
|
||||
stat_multiple_files( Links_to_Dirs );
|
||||
stat_multiple_files( Links_to_Files );
|
||||
stat_multiple_files( Links_to_dirlinks );
|
||||
stat_multiple_files( Links_to_filelinks );
|
||||
|
||||
/*
|
||||
* Chmod on dir1/dir1. This allows the error path to be hit.
|
||||
*/
|
||||
|
||||
printf( "chmod of %s to Read/Write\n", Directories[4] );
|
||||
chmod( Directories[4], (S_IROTH|S_IWOTH) );
|
||||
puts( "\nDoing the stat() on all the bad paths" );
|
||||
|
||||
stat_multiple_files( Bad_paths );
|
||||
make_multiple_bad_files( Bad_paths );
|
||||
|
||||
printf( "Return %s to RWX\n", Directories[4] );
|
||||
chmod( Directories[4], S_IRWXU );
|
||||
|
||||
|
||||
/*
|
||||
* Check out symbolic links.
|
||||
*/
|
||||
|
||||
make_multiple_symlinks();
|
||||
make_many_symlinks( "/symlinks", 10 );
|
||||
|
||||
status = rtems_task_wake_after( 5 * TICKS_PER_SECOND );
|
||||
Cause_faults();
|
||||
|
||||
status = rtems_task_wake_after( 5 * TICKS_PER_SECOND );
|
||||
chown_multiple_files( Files );
|
||||
|
||||
status = rtems_task_wake_after( 5 * TICKS_PER_SECOND );
|
||||
chown_multiple_files( Links_to_Dirs );
|
||||
|
||||
puts( "\n\n*** END OF STAT TEST 01 ***" );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user