summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@oarcorp.com>2012-07-28 06:42:15 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2012-07-28 06:42:15 -0500
commitd32a9cf7c51b7be1071e954976ddfae4b9afa43d (patch)
tree21b1ffc664973b3deabe9f8d0f9ee3f2f951489e
parenttestsuite/Makefile: Clean up after test name change (diff)
downloadrtems-libbsd-d32a9cf7c51b7be1071e954976ddfae4b9afa43d.tar.bz2
mghttpd01: Add test - does not build yet
-rw-r--r--testsuite/mghttpd01/.gitignore1
-rw-r--r--testsuite/mghttpd01/Makefile37
-rw-r--r--testsuite/mghttpd01/init_fs.tarbin0 -> 10240 bytes
-rw-r--r--testsuite/mghttpd01/mghttpd01.doc11
-rw-r--r--testsuite/mghttpd01/mghttpd01.scn33
-rw-r--r--testsuite/mghttpd01/test-http-client.c95
-rw-r--r--testsuite/mghttpd01/test-http-client.h58
7 files changed, 235 insertions, 0 deletions
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
--- /dev/null
+++ b/testsuite/mghttpd01/init_fs.tar
Binary files 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
+
+<html>
+<head>
+<title>Second Instance</title>
+</head>
+
+<body>
+<h1>Second Instance</h1>
+A test page for the Mongoose web server on RTEMS.
+</body>
+</html>
+
+=== 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
+ * <rtems@embedded-brains.de>
+ *
+ * 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 <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#include <unistd.h>
+
+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
+ * <rtems@embedded-brains.de>
+ *
+ * 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 <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+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 */