Added tests in support of the file system infrastructure.

This commit is contained in:
Joel Sherrill
1998-11-23 18:57:48 +00:00
parent 2a7920b58f
commit 0895bdb89c
43 changed files with 9817 additions and 1 deletions
+5 -1
View File
@@ -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
View 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 );
}
@@ -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 );
}
@@ -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
View 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
View 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 */
File diff suppressed because it is too large Load Diff
@@ -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
View 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,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
View 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 );
}
@@ -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
View 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 */
@@ -0,0 +1,2 @@
+49
View 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
View 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
View 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 */
+408
View 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);
}
@@ -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
View 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 */
@@ -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
View 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
View 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
View 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 */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+40
View 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 */
View File
File diff suppressed because it is too large Load Diff
+40
View 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
View 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
View 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 );
}
+31
View 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 */
+408
View 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);
}
+29
View 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 */
@@ -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
View 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);
}
+40
View 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 */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff