summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2000-12-14 14:16:08 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2000-12-14 14:16:08 +0000
commitd8a2e924ccde7eb2c16d518d37c63b7c272e6095 (patch)
treedf12a383eb3c70af23cc31c8d6c986112e4adda7
parent2000-12-14 Joel Sherrill <joel@OARcorp.com> (diff)
downloadnetwork-demos-d8a2e924ccde7eb2c16d518d37c63b7c272e6095.tar.bz2
2000-12-14 Eric Norum <eric.norum@usask.ca>
* init.c, test.c: Added test of write capability.
-rw-r--r--tftpTest/ChangeLog4
-rw-r--r--tftpTest/init.c10
-rw-r--r--tftpTest/test.c174
3 files changed, 150 insertions, 38 deletions
diff --git a/tftpTest/ChangeLog b/tftpTest/ChangeLog
index 8a59d16..6ae18ac 100644
--- a/tftpTest/ChangeLog
+++ b/tftpTest/ChangeLog
@@ -1,3 +1,7 @@
+2000-12-14 Eric Norum <eric.norum@usask.ca>
+
+ * init.c, test.c: Added test of write capability.
+
2000-12-14 Joel Sherrill <joel@OARcorp.com>
* ChangeLog: New file.
diff --git a/tftpTest/init.c b/tftpTest/init.c
index 5356a03..9b7c12f 100644
--- a/tftpTest/init.c
+++ b/tftpTest/init.c
@@ -18,6 +18,9 @@
#include <bsp.h>
#include <rtems/tftp.h>
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
@@ -46,6 +49,8 @@ rtems_task Init (rtems_task_argument argument);
#include <arpa/inet.h>
#include "../networkconfig.h"
+void testTFTP (const char *hostname, const char *filename);
+
/*
* RTEMS Startup Task
*/
@@ -57,13 +62,8 @@ Init (rtems_task_argument ignored)
rtems_bsdnet_initialize_network ();
rtems_bsdnet_initialize_tftp_filesystem ();
-#if (defined (RTEMS_USE_BOOTP))
- hostname = inet_ntoa (rtems_bsdnet_bootp_server_address);
- filename = rtems_bsdnet_bootp_boot_file_name;
-#else
hostname = RTEMS_TFTP_TEST_HOST_NAME;
filename = RTEMS_TFTP_TEST_FILE_NAME;
-#endif
testTFTP (hostname, filename);
exit (0);
diff --git a/tftpTest/test.c b/tftpTest/test.c
index 7cbb988..8ef3119 100644
--- a/tftpTest/test.c
+++ b/tftpTest/test.c
@@ -22,23 +22,24 @@
#include <rtems/error.h>
#include <sys/fcntl.h>
#include <unistd.h>
+#include <malloc.h>
static char cbuf[1024];
-static char *fullname;
+static char *readName, *writeName;
static rtems_interval then, now;
static void
-showRate (unsigned long totalRead)
+showRate (unsigned long byteCount)
{
int elapsed;
- printf ("Read %lu bytes", totalRead);
+ printf ("Transferred %lu bytes", byteCount);
elapsed = now - then;
if (elapsed) {
rtems_interval ticksPerSecond;
rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
printf (" (%ld bytes/sec)",
- (long)(((long long)totalRead * ticksPerSecond)
+ (long)(((long long)byteCount * ticksPerSecond)
/ elapsed));
}
printf (".\n");
@@ -51,7 +52,7 @@ testRawRead (void)
int nread;
unsigned long totalRead = 0;
- fd = open (fullname, O_RDONLY);
+ fd = open (readName, O_RDONLY);
if (fd < 0) {
printf ("Open failed: %s\n", strerror (errno));
return;
@@ -81,7 +82,7 @@ testFread (void)
int nread;
unsigned long totalRead = 0;
- fp = fopen (fullname, "r");
+ fp = fopen (readName, "r");
if (fp == NULL) {
printf ("Open failed: %s\n", strerror (errno));
return;
@@ -104,41 +105,148 @@ testFread (void)
showRate (totalRead);
}
-static int
-makeFullname (const char *hostname, const char *file)
+static void
+testRawWrite (void)
+{
+ int fd;
+ int nwrite;
+ unsigned long totalWrite = 0;
+
+ fd = open (writeName, O_WRONLY|O_CREAT);
+ if (fd < 0) {
+ printf ("Open failed: %s\n", strerror (errno));
+ return;
+ }
+
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
+ while (totalWrite < (100 * 1024)) {
+ nwrite = write (fd, cbuf, sizeof cbuf);
+ if (nwrite != sizeof cbuf) {
+ printf ("Write failed: %s\n", strerror (errno));
+ close (fd);
+ return;
+ }
+ totalWrite += nwrite;
+ }
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
+ close (fd);
+ showRate (totalWrite);
+}
+
+static void
+testFwrite (void)
+{
+ FILE *fp;
+ int nwrite;
+ unsigned long totalWrite = 0;
+
+ fp = fopen (writeName, "w");
+ if (fp == NULL) {
+ printf ("Open failed: %s\n", strerror (errno));
+ return;
+ }
+
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
+ while (totalWrite < (100 * 1024)) {
+ nwrite = fwrite (cbuf, sizeof cbuf[0], sizeof cbuf, fp);
+ if (nwrite != sizeof cbuf) {
+ printf ("Write failed: %s\n", strerror (errno));
+ fclose (fp);
+ return;
+ }
+ totalWrite += nwrite;
+ }
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
+ fclose (fp);
+ showRate (totalWrite);
+}
+
+static void
+testFcopy (void)
+{
+ FILE *fin, *fout;
+ int nread, nwrite;
+ unsigned long totalRead = 0;
+
+ fin = fopen (readName, "r");
+ if (fin == NULL) {
+ printf ("Open (%s) failed: %s\n", readName, strerror (errno));
+ return;
+ }
+ fout = fopen (writeName, "w");
+ if (fout == NULL) {
+ printf ("Open (%s) failed: %s\n", writeName, strerror (errno));
+ fclose (fin);
+ return;
+ }
+
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
+ for (;;) {
+ nread = fread (cbuf, sizeof cbuf[0], sizeof cbuf, fin);
+ if (nread < 0) {
+ printf ("Read failed: %s\n", strerror (errno));
+ fclose (fin);
+ fclose (fout);
+ return;
+ }
+ if (nread == 0)
+ break;
+ nwrite = fwrite (cbuf, sizeof cbuf[0], nread, fout);
+ if (nwrite != nread) {
+ printf ("Write failed: %s\n", strerror (errno));
+ fclose (fin);
+ fclose (fout);
+ return;
+ }
+ totalRead += nread;
+ }
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
+ fclose (fin);
+ fclose (fout);
+ showRate (totalRead);
+}
+
+static void
+makeFullName (const char *hostname, const char *file, int flags)
{
if (hostname == NULL)
hostname = "";
- fullname = realloc (fullname, 8 + strlen (file) + strlen (hostname));
- sprintf (fullname, "/TFTP/%s/%s", hostname, file);
- printf ("Read `%s'.\n", fullname);
- return 1;
+ if ((flags == O_RDONLY) || (flags == O_RDWR)) {
+ readName = realloc (readName, 8 + strlen (file) + strlen (hostname));
+ sprintf (readName, "/TFTP/%s/%s", hostname, file);
+ printf ("Read `%s'.\n", readName);
+ }
+ if ((flags == O_WRONLY) || (flags == O_RDWR)) {
+ writeName = realloc (writeName, 12 + strlen (file) + strlen (hostname));
+ sprintf (writeName, "/TFTP/%s/%s.tmp", hostname, file);
+ printf ("Write `%s'.\n", writeName);
+ }
}
void
testTFTP (const char *hostname, const char *filename)
{
- /*
- * Check that invalid file names are reported as such
- */
- if (makeFullname (hostname, "")) {
- testRawRead ();
- testFread ();
- }
+ printf ("*** Check that invalid file names are reported as such.\n");
+ makeFullName (hostname, "", O_RDONLY);
+ testRawRead ();
+ testFread ();
- /*
- * Check that non-existent files are reported as such
- */
- if (makeFullname (hostname, "BAD-FILE-NAME")) {
- testRawRead ();
- testFread ();
- }
+ printf ("*** Check that non-existent files are reported as such.\n");
+ makeFullName (hostname, "BAD-FILE-NAME", O_RDONLY);
+ testRawRead ();
+ testFread ();
- /*
- * Check that read works
- */
- if (makeFullname (hostname, filename)) {
- testRawRead ();
- testFread ();
- }
+ printf ("*** Check that file read operations work.\n");
+ makeFullName (hostname, filename, O_RDONLY);
+ testRawRead ();
+ testFread ();
+
+ printf ("*** Check that file write operations work.\n");
+ makeFullName (hostname, filename, O_WRONLY);
+ testRawWrite ();
+ testFwrite ();
+
+ printf ("*** Check that file copy operations work.\n");
+ makeFullName (hostname, filename, O_RDWR);
+ testFcopy ();
}