aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMichael Brown <mcb30@etherboot.org>2006-08-09 00:09:29 +0000
committerMichael Brown <mcb30@etherboot.org>2006-08-09 00:09:29 +0000
commitd1a123b1f4f265aa415d647212c64fb02d47e208 (patch)
tree76d61ff8a19d734dc8d7620980f0d4112bc8aeed /src/tests
parent3611cb17b74740588059c5fe2d11545c6e11f573 (diff)
downloadipxe-d1a123b1f4f265aa415d647212c64fb02d47e208.zip
ipxe-d1a123b1f4f265aa415d647212c64fb02d47e208.tar.gz
ipxe-d1a123b1f4f265aa415d647212c64fb02d47e208.tar.bz2
Added TFTP test code (currently just dumps file to console).
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/dhcptest.c18
-rw-r--r--src/tests/tftptest.c35
2 files changed, 51 insertions, 2 deletions
diff --git a/src/tests/dhcptest.c b/src/tests/dhcptest.c
index 4bb2e11..2afe6fa 100644
--- a/src/tests/dhcptest.c
+++ b/src/tests/dhcptest.c
@@ -57,6 +57,21 @@ static int test_dhcp_hello ( char *helloname ) {
return 0;
}
+static int test_dhcp_tftp ( char *tftpname ) {
+ union {
+ struct sockaddr_in sin;
+ struct sockaddr_tcpip st;
+ } target;
+
+ memset ( &target, 0, sizeof ( target ) );
+ target.sin.sin_family = AF_INET;
+ target.sin.sin_port = htons ( 69 );
+ find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR,
+ &target.sin.sin_addr );
+
+ return test_tftp ( &target.st, tftpname );
+}
+
static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
return test_dhcp_aoe_boot ( netdev, &filename[4] );
@@ -65,8 +80,7 @@ static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
} else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
return test_dhcp_hello ( &filename[6] );
} else {
- printf ( "Don't know how to boot %s\n", filename );
- return -EPROTONOSUPPORT;
+ return test_dhcp_tftp ( filename );
}
}
diff --git a/src/tests/tftptest.c b/src/tests/tftptest.c
new file mode 100644
index 0000000..ba4c5d0
--- /dev/null
+++ b/src/tests/tftptest.c
@@ -0,0 +1,35 @@
+#include <stdint.h>
+#include <string.h>
+#include <console.h>
+#include <gpxe/udp.h>
+#include <gpxe/tftp.h>
+#include <gpxe/async.h>
+
+static void test_tftp_callback ( struct tftp_session *tftp __unused,
+ unsigned int block __unused,
+ void *data, size_t len ) {
+ unsigned int i;
+ char c;
+
+ for ( i = 0 ; i < len ; i++ ) {
+ c = * ( ( char * ) data + i );
+ if ( c == '\r' ) {
+ /* Print nothing */
+ } else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
+ putchar ( c );
+ } else {
+ putchar ( '.' );
+ }
+ }
+}
+
+int test_tftp ( struct sockaddr_tcpip *target, const char *filename ) {
+ struct tftp_session tftp;
+
+ memset ( &tftp, 0, sizeof ( tftp ) );
+ udp_connect ( &tftp.udp, target );
+ tftp.filename = filename;
+ tftp.callback = test_tftp_callback;
+
+ return async_wait ( tftp_get ( &tftp ) );
+}