From bdaa9488e88a49746e058386c3b74ba338525812 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 5 May 2010 15:29:54 +0000 Subject: 2010-05-05 Joel Sherrill * qemu_vfat/Makefile, qemu_vfat/README, qemu_vfat/init.c: Now includes a start_test example which parses arguments. * qemu_vfat/start_test.c: New file. --- misc/ChangeLog | 6 +++ misc/qemu_vfat/Makefile | 2 +- misc/qemu_vfat/README | 1 + misc/qemu_vfat/init.c | 4 +- misc/qemu_vfat/start_test.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 misc/qemu_vfat/start_test.c diff --git a/misc/ChangeLog b/misc/ChangeLog index 46dac60..6a69f09 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,9 @@ +2010-05-05 Joel Sherrill + + * qemu_vfat/Makefile, qemu_vfat/README, qemu_vfat/init.c: Now includes + a start_test example which parses arguments. + * qemu_vfat/start_test.c: New file. + 2010-05-05 Joel Sherrill * qemu_vfat/.cvsignore, qemu_vfat/Makefile, qemu_vfat/README, diff --git a/misc/qemu_vfat/Makefile b/misc/qemu_vfat/Makefile index 3b873d5..98f13ca 100644 --- a/misc/qemu_vfat/Makefile +++ b/misc/qemu_vfat/Makefile @@ -12,7 +12,7 @@ PGM=${ARCH}/qemu_vfat.exe MANAGERS=all # C source names -CSRCS = init.c +CSRCS = init.c start_test.c COBJS = $(CSRCS:%.c=${ARCH}/%.o) include $(RTEMS_MAKEFILE_PATH)/Makefile.inc diff --git a/misc/qemu_vfat/README b/misc/qemu_vfat/README index 14b1922..d9ba661 100644 --- a/misc/qemu_vfat/README +++ b/misc/qemu_vfat/README @@ -17,3 +17,4 @@ executable exercised with different arguments or input files. With this setup, you can copy those test support files into the host directory and the RTEMS "main" will use those in support of the testing. + diff --git a/misc/qemu_vfat/init.c b/misc/qemu_vfat/init.c index 05a2913..6d297b3 100644 --- a/misc/qemu_vfat/init.c +++ b/misc/qemu_vfat/init.c @@ -30,9 +30,10 @@ * with the "rtems_fsmount" function. * See cpukit/libmisc/fsmount for definition of fields */ +#define MOUNT_POINT "/mnt/test" fstab_t fs_table[] = { { - "/dev/hda1", "/mnt/test", + "/dev/hda1", MOUNT_POINT, &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE, FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, 0 @@ -148,6 +149,7 @@ Init (rtems_task_argument ignored) fileio_start_shell (); #endif #if defined(USE_START_TEST) + chdir( MOUNT_POINT ); start_test (); #endif puts( "*** END OF QEMU VFAT AND SHELL TEST ***" ); diff --git a/misc/qemu_vfat/start_test.c b/misc/qemu_vfat/start_test.c new file mode 100644 index 0000000..b062e18 --- /dev/null +++ b/misc/qemu_vfat/start_test.c @@ -0,0 +1,91 @@ +/* + * Start Test Example + * + * $Id$ + */ + +#if defined(USE_START_TEST) + +#define __need_getopt_newlib +#include +#include +#include +#include +#include + +#define COMMAND_LINE_ARGUMENTS_FILE "arguments" + +#define ARGV_LENGTH 80 +#define ARGV_LIMIT 32 + +int Argc; +char *Argv[ARGV_LIMIT]; +char Argv_String[ ARGV_LENGTH ]; + +void parse_arguments(void) +{ + FILE *in; + char *cStatus; + size_t length; + int sc; + + in = fopen( COMMAND_LINE_ARGUMENTS_FILE, "r" ); + if ( !in ) { + fprintf( stderr, "Unable to open %s\n", COMMAND_LINE_ARGUMENTS_FILE ); + exit(1); + } + + cStatus = fgets( Argv_String, sizeof(Argv_String), in ); + if ( cStatus == NULL ) { + fprintf( stderr, "Unable to read %s\n", COMMAND_LINE_ARGUMENTS_FILE ); + exit(1); + } + + // If the last line does not have a CR, then we don't want to + // arbitrarily clobber an = instead of a \n. + length = strlen(Argv_String); + if ( Argv_String[ length - 1] != '\n' ) { + fprintf( + stderr, + "Line appears to be too long in %s\n", + COMMAND_LINE_ARGUMENTS_FILE + ); + exit(1); + } + + Argv_String[ length - 1] = '\0'; + + sc = rtems_shell_make_args( + &Argv_String[0], + &Argc, + &Argv[1], + ARGV_LIMIT - 1 + ); + if ( sc ) { + fprintf( stderr, "Error parsing arguments\n" ); + exit(1); + } + + /* Since we added the program name ourselves and started at 0 */ + Argc++; + fclose(in); +} + +void print_arguments(void) +{ + int i; + + for ( i=0 ; i