summaryrefslogtreecommitdiff
path: root/tftpTest
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-07-30 14:42:29 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-07-30 14:42:29 +0000
commitc87143a1734b473b7c7e238660e2071d899bbe75 (patch)
treeef003634dbadbd829d8c1d49cb985bf45a641251 /tftpTest
base from Eric Norum -- Demos.30May1998.tar.gzDemos-30May1998ERIC-NORUM
Diffstat (limited to 'tftpTest')
-rw-r--r--tftpTest/Makefile60
-rw-r--r--tftpTest/init.c114
-rw-r--r--tftpTest/test.c159
3 files changed, 333 insertions, 0 deletions
diff --git a/tftpTest/Makefile b/tftpTest/Makefile
new file mode 100644
index 0000000..e9f7bdd
--- /dev/null
+++ b/tftpTest/Makefile
@@ -0,0 +1,60 @@
+SAMPLE=tftp
+PGM=${ARCH}/$(SAMPLE).exe
+
+MANAGERS=io event semaphore timer rate_monotonic
+
+# C source names, if any, go here -- minus the .c
+C_PIECES= init test
+C_FILES=$(C_PIECES:%=%.c)
+C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
+
+H_FILES=
+
+DOCTYPES=
+DOCS=$(DOCTYPES:%=$(SAMPLE).%)
+
+SRCS=$(DOCS) $(C_FILES) $(CC_FILES) $(H_FILES) $(S_FILES)
+OBJS=$(C_O_FILES) $(CC_O_FILES) $(S_O_FILES)
+
+PRINT_SRCS=$(DOCS)
+
+PGM=${ARCH}/$(SAMPLE).exe
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(PROJECT_ROOT)/make/leaf.cfg
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+DEFINES +=
+CPPFLAGS +=
+CFLAGS +=
+CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0x40000 # KA9Q needs more space
+CFLAGS_OPTIMIZE_V +=
+CFLAGS_DEBUG_V += -qrtems_debug # -v
+
+
+LD_PATHS +=
+LD_LIBS +=
+
+#
+# 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)
+
+${PGM}: $(OBJS) $(LINK_FILES)
+ $(make-exe)
+
+# Install the program(s), appending _g or _p as appropriate.
+# for include files, just use $(INSTALL)
+install: all
+ $(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
diff --git a/tftpTest/init.c b/tftpTest/init.c
new file mode 100644
index 0000000..d4b6100
--- /dev/null
+++ b/tftpTest/init.c
@@ -0,0 +1,114 @@
+/*
+ * Test RTEMS/KA9Q TFTP device driver
+ *
+ * This program may be distributed and used for any purpose.
+ * I ask only that you:
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ */
+
+#include <bsp.h>
+#include <rtems/error.h>
+#include <tftp.h>
+#include <rtems_ka9q.h>
+#include <stdio.h>
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_EXECUTIVE_RAM_SIZE (128*1024)
+#define CONFIGURE_MAXIMUM_SEMAPHORES 10
+#define CONFIGURE_MAXIMUM_TIMERS 5
+#define CONFIGURE_MAXIMUM_PERIODS 1
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 10486
+
+#define CONFIGURE_INIT
+rtems_task Init (rtems_task_argument argument);
+
+#define CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE
+rtems_driver_address_table Device_drivers[] = {
+ CONSOLE_DRIVER_TABLE_ENTRY,
+ CLOCK_DRIVER_TABLE_ENTRY,
+ TFTP_DRIVER_TABLE_ENTRY,
+};
+
+#include <confdefs.h>
+
+/*
+ * Board ethernet address
+ * REPLACE THIS WITH YOUR OWN VALUE BEFORE TRYING TO USE THIS PROGRAM!
+ */
+#define MY_ETHERNET_ADDRESS "48:3E:3E:21:2E:D5"
+#define MY_ETHERNET_ADDRESS "prom"
+
+#include <bootp.h>
+extern void testTFTP (void);
+
+/*
+ * RTEMS Startup Task
+ */
+rtems_task
+Init (rtems_task_argument ignored)
+{
+ int i;
+ rtems_task_priority oldPri;
+ rtems_interval ticksPerSecond;
+
+ /*
+ * Get some timing information
+ */
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
+
+ /*
+ * Start KA9Q
+ */
+ rtems_task_set_priority (RTEMS_SELF, 30, &oldPri);
+ rtems_ka9q_start (20);
+
+ /*
+ * Hook up drivers
+ */
+ if (rtems_ka9q_execute_command ("attach rtems broadcast n ether " MY_ETHERNET_ADDRESS))
+ rtems_panic ("Can't attach Ethernet driver.\n");
+
+ /*
+ * Configure the driver
+ */
+ if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
+ rtems_panic ("Can't configure Ethernet driver.\n");
+
+ /*
+ * Add the ethernet broadcast address to the ARP table.
+ */
+ if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
+ rtems_panic ("Can't add broadcast entry to ARP table.\n");
+
+ /*
+ * Get BOOTP information
+ */
+ for (i = 0 ; ; ) {
+ if (rtems_ka9q_execute_command ("bootp") == 0)
+ break;
+ if (++i == 10)
+ rtems_panic ("Can't get information from BOOTP server.\n");
+ rtems_task_wake_after (i * ticksPerSecond);
+ }
+
+ /*
+ * Test TFTP driver
+ */
+ testTFTP ();
+
+ /*
+ * Wind things up
+ */
+ rtems_task_wake_after (2 * ticksPerSecond);
+ rtems_ka9q_execute_command ("detach rtems");
+ exit (0);
+}
diff --git a/tftpTest/test.c b/tftpTest/test.c
new file mode 100644
index 0000000..b900030
--- /dev/null
+++ b/tftpTest/test.c
@@ -0,0 +1,159 @@
+/*
+ * Test RTEMS/KA9Q TFTP device driver
+ *
+ * This program may be distributed and used for any purpose.
+ * I ask only that you:
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ */
+
+#include <stdio.h>
+#include <rtems.h>
+#include <rtems/error.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <bootp.h>
+#include <netuser.h>
+
+static char cbuf[1024];
+static char *fullname;
+static rtems_interval then, now;
+
+static void
+showRate (unsigned long totalRead)
+{
+ int elapsed;
+
+ 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)totalRead * ticksPerSecond)
+ / elapsed));
+ }
+ printf (".\n");
+rtems_ka9q_execute_command ("ifconfig rtems");
+}
+
+static void
+testRawRead (void)
+{
+ int fd;
+ int nread;
+ unsigned long totalRead = 0;
+
+ fd = open (fullname, O_RDONLY);
+ if (fd < 0) {
+ printf ("Open failed: %s\n", strerror (errno));
+ return;
+ }
+
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
+ for (;;) {
+ nread = read (fd, cbuf, sizeof cbuf);
+ if (nread < 0) {
+ printf ("Read failed: %s\n", strerror (errno));
+ close (fd);
+ return;
+ }
+ if (nread == 0)
+ break;
+ totalRead += nread;
+ }
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
+ close (fd);
+ showRate (totalRead);
+}
+
+static void
+testFread (void)
+{
+ FILE *fp;
+ int nread;
+ unsigned long totalRead = 0;
+
+ fp = fopen (fullname, "r");
+ if (fp == NULL) {
+ printf ("Open failed: %s\n", strerror (errno));
+ return;
+ }
+
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
+ for (;;) {
+ nread = fread (cbuf, sizeof cbuf[0], sizeof cbuf, fp);
+ if (nread < 0) {
+ printf ("Read failed: %s\n", strerror (errno));
+ fclose (fp);
+ return;
+ }
+ if (nread == 0)
+ break;
+ totalRead += nread;
+ }
+ rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
+ fclose (fp);
+ showRate (totalRead);
+}
+
+static int
+makeFullname (rtems_unsigned32 host, const char *file)
+{
+ const char *hostname;
+
+ if (host) {
+ hostname = rtems_hostname_for_address (BootpHost.s_addr, 0);
+ if (hostname == NULL) {
+ printf ("No host to read from!\n");
+ return 0;
+ }
+ }
+ else {
+ hostname = "";
+ }
+ fullname = realloc (fullname, 8 + strlen (file) + strlen (hostname));
+ sprintf (fullname, "/TFTP/%s/%s", hostname, file);
+ printf ("Read `%s'.\n", fullname);
+ return 1;
+}
+
+void
+testTFTP (void)
+{
+ /*
+ * Check that invalid file names are reported as such
+ */
+ if (makeFullname (0, "")) {
+ testRawRead ();
+ testFread ();
+ }
+
+ /*
+ * Check that non-existent files are reported as such
+ */
+ if (makeFullname (0, "BAD-FILE-NAME")) {
+ testRawRead ();
+ testFread ();
+ }
+
+ /*
+ * Check read speed
+ */
+ if (BootpFileName == NULL) {
+ printf ("Nothing to read!\n");
+ return;
+ }
+ if (makeFullname (BootpHost.s_addr, BootpFileName)) {
+ testRawRead ();
+ testFread ();
+ }
+}
+ #include <limits.h>
+ int foo = INT_MAX;