summaryrefslogtreecommitdiff
path: root/tftpTest
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2001-08-31 18:11:44 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2001-08-31 18:11:44 +0000
commitd51d8b5b51c6a0286eb1f7952b81799f3b0ef3eb (patch)
tree22f4af00c66dd8c4de09e758d5b6a3a6dd2a5584 /tftpTest
parentd37a99d444fcadc7574cab26cf9c081e7d0c6ab3 (diff)
2001-08-30 Joel Sherrill <joel@OARcorp.com>
* README, networkconfig.h, netdemo/README, tftpTest/test.c: Merged missing stuff from 4.5 branch. * http/Makefile, http/init.c: Minor modifications to improve buildability.
Diffstat (limited to 'tftpTest')
-rw-r--r--tftpTest/test.c176
1 files changed, 34 insertions, 142 deletions
diff --git a/tftpTest/test.c b/tftpTest/test.c
index 8ef3119..75e4666 100644
--- a/tftpTest/test.c
+++ b/tftpTest/test.c
@@ -1,5 +1,5 @@
/*
- * Test RTEMS/KA9Q TFTP device driver
+ * Test RTEMS TFTP Client Filesystem
*
* This program may be distributed and used for any purpose.
* I ask only that you:
@@ -22,24 +22,23 @@
#include <rtems/error.h>
#include <sys/fcntl.h>
#include <unistd.h>
-#include <malloc.h>
static char cbuf[1024];
-static char *readName, *writeName;
+static char *fullname;
static rtems_interval then, now;
static void
-showRate (unsigned long byteCount)
+showRate (unsigned long totalRead)
{
int elapsed;
- printf ("Transferred %lu bytes", byteCount);
+ printf ("Read %lu bytes", totalRead);
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)byteCount * ticksPerSecond)
+ (long)(((long long)totalRead * ticksPerSecond)
/ elapsed));
}
printf (".\n");
@@ -52,7 +51,7 @@ testRawRead (void)
int nread;
unsigned long totalRead = 0;
- fd = open (readName, O_RDONLY);
+ fd = open (fullname, O_RDONLY);
if (fd < 0) {
printf ("Open failed: %s\n", strerror (errno));
return;
@@ -82,7 +81,7 @@ testFread (void)
int nread;
unsigned long totalRead = 0;
- fp = fopen (readName, "r");
+ fp = fopen (fullname, "r");
if (fp == NULL) {
printf ("Open failed: %s\n", strerror (errno));
return;
@@ -105,148 +104,41 @@ testFread (void)
showRate (totalRead);
}
-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)
+static int
+makeFullname (const char *hostname, const char *file)
{
if (hostname == NULL)
hostname = "";
- 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);
- }
+ fullname = realloc (fullname, 8 + strlen (file) + strlen (hostname));
+ sprintf (fullname, "/TFTP/%s/%s", hostname, file);
+ printf ("Read `%s'.\n", fullname);
+ return 1;
}
void
testTFTP (const char *hostname, const char *filename)
{
- printf ("*** Check that invalid file names are reported as such.\n");
- makeFullName (hostname, "", O_RDONLY);
- testRawRead ();
- testFread ();
-
- printf ("*** Check that non-existent files are reported as such.\n");
- makeFullName (hostname, "BAD-FILE-NAME", O_RDONLY);
- testRawRead ();
- testFread ();
-
- printf ("*** Check that file read operations work.\n");
- makeFullName (hostname, filename, O_RDONLY);
- testRawRead ();
- testFread ();
+ /*
+ * Check that invalid file names are reported as such
+ */
+ if (makeFullname (hostname, "")) {
+ testRawRead ();
+ testFread ();
+ }
- printf ("*** Check that file write operations work.\n");
- makeFullName (hostname, filename, O_WRONLY);
- testRawWrite ();
- testFwrite ();
+ /*
+ * Check that non-existent files are reported as such
+ */
+ if (makeFullname (hostname, "BAD-FILE-NAME")) {
+ testRawRead ();
+ testFread ();
+ }
- printf ("*** Check that file copy operations work.\n");
- makeFullName (hostname, filename, O_RDWR);
- testFcopy ();
+ /*
+ * Check that read works
+ */
+ if (makeFullname (hostname, filename)) {
+ testRawRead ();
+ testFread ();
+ }
}