From d32a9cf7c51b7be1071e954976ddfae4b9afa43d Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Sat, 28 Jul 2012 06:42:15 -0500 Subject: mghttpd01: Add test - does not build yet --- testsuite/mghttpd01/.gitignore | 1 + testsuite/mghttpd01/Makefile | 37 +++++++++++++ testsuite/mghttpd01/init_fs.tar | Bin 0 -> 10240 bytes testsuite/mghttpd01/mghttpd01.doc | 11 ++++ testsuite/mghttpd01/mghttpd01.scn | 33 ++++++++++++ testsuite/mghttpd01/test-http-client.c | 95 +++++++++++++++++++++++++++++++++ testsuite/mghttpd01/test-http-client.h | 58 ++++++++++++++++++++ 7 files changed, 235 insertions(+) create mode 100644 testsuite/mghttpd01/.gitignore create mode 100644 testsuite/mghttpd01/Makefile create mode 100644 testsuite/mghttpd01/init_fs.tar create mode 100644 testsuite/mghttpd01/mghttpd01.doc create mode 100644 testsuite/mghttpd01/mghttpd01.scn create mode 100644 testsuite/mghttpd01/test-http-client.c create mode 100644 testsuite/mghttpd01/test-http-client.h diff --git a/testsuite/mghttpd01/.gitignore b/testsuite/mghttpd01/.gitignore new file mode 100644 index 00000000..27bb1279 --- /dev/null +++ b/testsuite/mghttpd01/.gitignore @@ -0,0 +1 @@ +init.c diff --git a/testsuite/mghttpd01/Makefile b/testsuite/mghttpd01/Makefile new file mode 100644 index 00000000..4444a517 --- /dev/null +++ b/testsuite/mghttpd01/Makefile @@ -0,0 +1,37 @@ +# +# $Id$ +# + +include ../../config.inc + +PGM=${ARCH}/mghttpd01.exe + +# optional managers required +MANAGERS=all + +# XXX = mghttpd01.doc mghttpd01.scn +# C source names +C_FILES = init.c test-http-client.c +C_O_FILES = $(C_FILES:%.c=${ARCH}/%.o) + +AM_CPPFLAGS += -I $(INSTALL_BASE)/include +AM_CPPFLAGS += -I ../init01 +AM_CPPFLAGS += -I ${r}/testsuites/support/include +LINK_LIBS += $(INSTALL_BASE)/libmghttpd.a +LINK_LIBS += $(INSTALL_BASE)/libbsdc.a +LINK_LIBS += $(INSTALL_BASE)/libbsd.a + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(C_O_FILES) +CLEAN_ADDITIONS += init.c + +all: init.c ${ARCH} $(PGM) + +init.c: ../init01/init.c + cp ../init01/init.c . + +$(PGM): $(OBJS) + -$(make-exe) diff --git a/testsuite/mghttpd01/init_fs.tar b/testsuite/mghttpd01/init_fs.tar new file mode 100644 index 00000000..67132d51 Binary files /dev/null and b/testsuite/mghttpd01/init_fs.tar differ diff --git a/testsuite/mghttpd01/mghttpd01.doc b/testsuite/mghttpd01/mghttpd01.doc new file mode 100644 index 00000000..7db498b7 --- /dev/null +++ b/testsuite/mghttpd01/mghttpd01.doc @@ -0,0 +1,11 @@ +This file describes the directives and concepts tested by this test set. + +test set name: mghttpd01 + +directives: + + TBD + +concepts: + + - Ensure that the Mongoose HTTP server works with a basic setup diff --git a/testsuite/mghttpd01/mghttpd01.scn b/testsuite/mghttpd01/mghttpd01.scn new file mode 100644 index 00000000..d3c061f0 --- /dev/null +++ b/testsuite/mghttpd01/mghttpd01.scn @@ -0,0 +1,33 @@ +*** TEST MGHTTPD 01 *** +Loading tarfs image ... successful +=== Get the index.html from second Mongoose instance: +HTTP/1.1 200 OK +Date: Fri, 01 Jan 1988 00:00:01 GMT +Last-Modified: Fri, 01 Jan 1988 00:00:01 GMT +Etag: "21dae501.a2" +Content-Type: text/html +Content-Length: 162 +Connection: close +Accept-Ranges: bytes + + + +Second Instance + + + +

Second Instance

+A test page for the Mongoose web server on RTEMS. + + + +=== OK +=== Get a page generated from a callback function from first Mongoose instance: +HTTP/1.1 200 OK +Content-Type: text/plain +Content-Length: 47 + +This is a message from the callback function. + +=== OK +*** END OF TEST MGHTTPD 01 *** diff --git a/testsuite/mghttpd01/test-http-client.c b/testsuite/mghttpd01/test-http-client.c new file mode 100644 index 00000000..6e784574 --- /dev/null +++ b/testsuite/mghttpd01/test-http-client.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include "test-http-client.h" + +#include +#include +#include +#include +#include +#include + +void httpc_init_context( + httpc_context *ctx +) +{ + ctx->socket = -1; + ctx->fd = NULL; +} + +bool httpc_open_connection( + httpc_context *ctx, + char *targethost, + int targetport +) +{ + struct sockaddr_in addr; + + struct hostent *server; + struct servent *service; + + ctx->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if(ctx->socket < 0) { return false; } + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(targetport); + + server = gethostbyname(targethost); + if(server == NULL) { return false; } + memcpy(&addr.sin_addr.s_addr, server->h_addr, (size_t) server->h_length); + + if(connect(ctx->socket, (struct sockaddr *)&addr, sizeof(addr)) != 0) + { + return false; + } + + ctx->fd = fdopen(ctx->socket,"rw"); + if(ctx->fd == NULL) { return false; } + + return true; +} + +bool httpc_close_connection( + httpc_context *ctx +) +{ + if(close(ctx->socket) != 0) + { + return false; + } + + return true; +} + +bool httpc_send_request( + httpc_context *ctx, + char *request, + char *response, + int responsesize +) +{ + int size = strlen(request); + char lineend[] = " HTTP/1.1\r\n\r\n"; + + write(ctx->socket, request, size); + write(ctx->socket, lineend, sizeof(lineend)); + + size = read(ctx->socket, response, responsesize-1); + response[size] = '\0'; + + return true; +} + diff --git a/testsuite/mghttpd01/test-http-client.h b/testsuite/mghttpd01/test-http-client.h new file mode 100644 index 00000000..5e06f96e --- /dev/null +++ b/testsuite/mghttpd01/test-http-client.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#ifndef TEST_WEB_CLIENT_H +#define TEST_WEB_CLIENT_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include +#include + +typedef struct +{ + int socket; + FILE *fd; +} +httpc_context; + +void httpc_init_context( + httpc_context *ctx +); + +bool httpc_open_connection( + httpc_context *ctx, + char *targethost, + int targetport +); + +bool httpc_close_connection( + httpc_context *ctx +); + +bool httpc_send_request( + httpc_context *ctx, + char *request, + char *response, + int responsesize +); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* TEST_WEB_CLIENT_H */ -- cgit v1.2.3