[rtems-libbsd commit] mghttpd01: Add test - does not build yet

Joel Sherrill joel at rtems.org
Fri Aug 3 13:36:47 UTC 2012


Module:    rtems-libbsd
Branch:    master
Commit:    d32a9cf7c51b7be1071e954976ddfae4b9afa43d
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=d32a9cf7c51b7be1071e954976ddfae4b9afa43d

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Sat Jul 28 06:42:15 2012 -0500

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(+), 0 deletions(-)

diff --git a/testsuite/mghttpd01/.gitignore b/testsuite/mghttpd01/.gitignore
new file mode 100644
index 0000000..27bb127
--- /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 0000000..4444a51
--- /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 0000000..67132d5
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 0000000..7db498b
--- /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 0000000..d3c061f
--- /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 0000000..6e78457
--- /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 at 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 0000000..5e06f96
--- /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 at 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 */




More information about the vc mailing list