summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/mghttpd01
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/libtests/mghttpd01')
-rw-r--r--testsuites/libtests/mghttpd01/init.c290
-rw-r--r--testsuites/libtests/mghttpd01/mghttpd01.doc11
-rw-r--r--testsuites/libtests/mghttpd01/mghttpd01.scn33
-rw-r--r--testsuites/libtests/mghttpd01/mghttpd01.tarbin10240 -> 0 bytes
-rw-r--r--testsuites/libtests/mghttpd01/test-http-client.c224
-rw-r--r--testsuites/libtests/mghttpd01/test-http-client.h69
6 files changed, 0 insertions, 627 deletions
diff --git a/testsuites/libtests/mghttpd01/init.c b/testsuites/libtests/mghttpd01/init.c
deleted file mode 100644
index 93d42e174a..0000000000
--- a/testsuites/libtests/mghttpd01/init.c
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * 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.org/license/LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems.h>
-
-#include <tmacros.h>
-
-#include <rtems/rtems_bsdnet.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <mghttpd/mongoose.h>
-
-#include <rtems/imfs.h>
-#include <rtems/error.h>
-#include "mghttpd01-tar.h"
-
-#include "test-http-client.h"
-
-const char rtems_test_name[] = "MGHTTPD 1";
-
-#define TARFILE_START mghttpd01_tar
-#define TARFILE_SIZE mghttpd01_tar_size
-
-#define CBACKTEST_URI "/callbacktest.txt"
-#define CBACKTEST_TXT "HTTP/1.1 200 OK\r\n" \
- "Content-Type: text/plain\r\n" \
- "Content-Length: 47\r\n" \
- "\r\n" \
- "This is a message from the callback function.\r\n"
-
-#define WSTEST_REQ "Test request"
-#define WSTEST_RESP "This is a message from the WebSocket callback function."
-
-#define INDEX_HTML "HTTP/1.1 200 OK\r\n" \
- "Date: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n" \
- "Last-Modified: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n" \
- "Etag: \"21dae500.162\"\r\n" \
- "Content-Type: text/html\r\n" \
- "Content-Length: 162\r\n" \
- "Connection: close\r\n" \
- "Accept-Ranges: bytes\r\n" \
- "\r\n" \
- "<html>\r\n" \
- "<head>\r\n" \
- "<title>Second Instance</title>\r\n" \
- "</head>\r\n" \
- "\r\n" \
- "<body>\r\n" \
- "<h1>Second Instance</h1>\r\n" \
- "A test page for the Mongoose web server on RTEMS.\r\n" \
- "</body>\r\n" \
- "</html>\r\n"
-
-#define DATE_TAG "Date: "
-#define LASTMOD_TAG "Last-Modified: "
-#define TIMESTAMP_SIZE (sizeof("Fri, 01 Jan 1988 00:00:26 GMT") - 1)
-
-#define BUFFERSIZE 1024
-
-static void test_tarfs_load(void)
-{
- rtems_status_code sc;
-
- printf("Loading tarfs image ... ");
- sc = rtems_tarfs_load("/",(void *)TARFILE_START, TARFILE_SIZE);
- if (sc != RTEMS_SUCCESSFUL) {
- printf ("error: untar failed: %s\n", rtems_status_text (sc));
- rtems_test_exit(1);
- }
- printf ("successful\n");
-}
-
-static int callback(struct mg_connection *conn)
-{
- int cbacktest = strncmp(mg_get_request_info(conn)->uri, CBACKTEST_URI, sizeof(CBACKTEST_URI));
- if (cbacktest == 0)
- {
- mg_write(conn, CBACKTEST_TXT, sizeof(CBACKTEST_TXT));
-
- /* Mark as processed */
- return 1;
- }
-
- return 0;
-}
-
-static int callback_websocket(struct mg_connection *connection,
- int bits,
- char *data,
- size_t data_len)
-{
- if (data_len == strlen(WSTEST_REQ) && strncmp(data, WSTEST_REQ, data_len) == 0)
- {
- mg_websocket_write(connection, WEBSOCKET_OPCODE_TEXT, WSTEST_RESP, strlen(WSTEST_RESP));
-
- /* Don't close the WebSocket */
- return 1;
- }
-
- return 0;
-}
-
-static void test_mg_index_html(void)
-{
- httpc_context httpc_ctx;
- char *buffer = malloc(BUFFERSIZE);
- char *workpos = buffer;
- bool brv = false;
- int rv = 0;
-
- rtems_test_assert(buffer != NULL);
-
- puts("=== Get the index.html from second Mongoose instance:");
-
- httpc_init_context(&httpc_ctx);
- brv = httpc_open_connection(&httpc_ctx, "127.0.0.1", 8080);
- rtems_test_assert(brv);
- brv = httpc_send_request(&httpc_ctx, "GET /index.html", buffer, BUFFERSIZE);
- rtems_test_assert(brv);
- brv = httpc_close_connection(&httpc_ctx);
- rtems_test_assert(brv);
- puts(buffer);
-
- /* remove timestamps from html-header */
- workpos = strstr(buffer, DATE_TAG);
- rtems_test_assert(workpos != NULL);
- workpos += sizeof(DATE_TAG) - 1;
- memset(workpos, 'x', TIMESTAMP_SIZE);
-
- workpos = strstr(buffer, LASTMOD_TAG);
- rtems_test_assert(workpos != NULL);
- workpos += sizeof(LASTMOD_TAG) - 1;
- memset(workpos, 'x', TIMESTAMP_SIZE);
-
- rv = strcmp(buffer, INDEX_HTML);
- rtems_test_assert(rv == 0);
-
- puts("=== OK");
-
- free(buffer);
-}
-
-static void test_mg_callback(void)
-{
- httpc_context httpc_ctx;
- char *buffer = malloc(BUFFERSIZE);
- bool brv = false;
- int rv = 0;
-
- rtems_test_assert(buffer != NULL);
-
- puts("=== Get a page generated from a callback function from" \
- " first Mongoose instance:");
-
- httpc_init_context(&httpc_ctx);
- brv = httpc_open_connection(&httpc_ctx, "127.0.0.1", 80);
- rtems_test_assert(brv);
- brv = httpc_send_request(&httpc_ctx, "GET " CBACKTEST_URI, buffer, BUFFERSIZE);
- rtems_test_assert(brv);
- brv = httpc_close_connection(&httpc_ctx);
- rtems_test_assert(brv);
- puts(buffer);
- rv = strcmp(buffer, CBACKTEST_TXT);
- rtems_test_assert(rv == 0);
-
- puts("=== OK");
-
- free(buffer);
-}
-
-static void test_mg_websocket(void)
-{
- httpc_context httpc_ctx;
- char *buffer = malloc(BUFFERSIZE);
- bool brv = false;
- int rv = 0;
-
- rtems_test_assert(buffer != NULL);
-
- puts("=== Get a WebSocket response generated from a callback function" \
- " from first Mongoose instance:");
-
- httpc_init_context(&httpc_ctx);
- brv = httpc_open_connection(&httpc_ctx, "127.0.0.1", 80);
- rtems_test_assert(brv);
- brv = httpc_ws_open_connection(&httpc_ctx);
- rtems_test_assert(brv);
- brv = httpc_ws_send_request(&httpc_ctx, WSTEST_REQ, buffer, BUFFERSIZE);
- rtems_test_assert(brv);
- brv = httpc_close_connection(&httpc_ctx);
- rtems_test_assert(brv);
- puts(buffer);
- rv = strcmp(buffer, WSTEST_RESP);
- rtems_test_assert(rv == 0);
-
- puts("=== OK");
-
- free(buffer);
-}
-
-static void test_mongoose(void)
-{
- const struct mg_callbacks callbacks = {
- .begin_request = callback,
- .websocket_data = callback_websocket
- };
- const char *options[] = {
- "listening_ports", "80",
- "document_root", "/www",
- "num_threads", "1",
- "thread_stack_size", "16384",
- "thread_priority", "250",
- "thread_policy", "o",
- NULL};
- const struct mg_callbacks callbacks2 = {
- NULL
- };
- const char *options2[] = {
- "listening_ports", "8080",
- "document_root", "/www2",
- "num_threads", "1",
- "thread_stack_size", "16384",
- NULL};
-
- struct mg_context *mg1 = mg_start(&callbacks, NULL, options);
- struct mg_context *mg2 = mg_start(&callbacks2, NULL, options2);
-
- test_mg_index_html();
- test_mg_callback();
- test_mg_websocket();
-
- mg_stop(mg1);
- mg_stop(mg2);
-}
-
-static void Init(rtems_task_argument arg)
-{
- int rv = 0;
-
- TEST_BEGIN();
-
- rv = rtems_bsdnet_initialize_network();
- rtems_test_assert(rv == 0);
-
- test_tarfs_load();
-
- test_mongoose();
-
- TEST_END();
-
- rtems_test_exit(0);
-}
-
-#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
-#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
-
-#define CONFIGURE_FILESYSTEM_IMFS
-
-#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 16
-
-#define CONFIGURE_UNLIMITED_OBJECTS
-
-#define CONFIGURE_UNIFIED_WORK_AREAS
-
-#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
-
-#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
-
-#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
-#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
-
-#define CONFIGURE_INIT
-
-#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/mghttpd01/mghttpd01.doc b/testsuites/libtests/mghttpd01/mghttpd01.doc
deleted file mode 100644
index 7db498b7ca..0000000000
--- a/testsuites/libtests/mghttpd01/mghttpd01.doc
+++ /dev/null
@@ -1,11 +0,0 @@
-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/testsuites/libtests/mghttpd01/mghttpd01.scn b/testsuites/libtests/mghttpd01/mghttpd01.scn
deleted file mode 100644
index d3c061f0ae..0000000000
--- a/testsuites/libtests/mghttpd01/mghttpd01.scn
+++ /dev/null
@@ -1,33 +0,0 @@
-*** 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/testsuites/libtests/mghttpd01/mghttpd01.tar b/testsuites/libtests/mghttpd01/mghttpd01.tar
deleted file mode 100644
index 67132d5122..0000000000
--- a/testsuites/libtests/mghttpd01/mghttpd01.tar
+++ /dev/null
Binary files differ
diff --git a/testsuites/libtests/mghttpd01/test-http-client.c b/testsuites/libtests/mghttpd01/test-http-client.c
deleted file mode 100644
index 806283b2d2..0000000000
--- a/testsuites/libtests/mghttpd01/test-http-client.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * 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.org/license/LICENSE.
- */
-
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <limits.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <tmacros.h>
-
-#include "test-http-client.h"
-
-#define HTTPC_WS_CONN_REQ "GET / HTTP/1.1\r\n" \
- "Host: localhost\r\n" \
- "Upgrade: websocket\r\n" \
- "Connection: Upgrade\r\n" \
- "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" \
- "Sec-WebSocket-Version: 13\r\n" \
- "\r\n"
-#define HTTPC_WS_CONN_RESP "HTTP/1.1 101 Switching Protocols\r\n" \
- "Upgrade: websocket\r\n" \
- "Connection: Upgrade\r\n" \
- "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" \
- "\r\n"
-
-static ssize_t httpc_read_full(
- const httpc_context *ctx,
- void *response,
- size_t responsesize
-);
-
-void httpc_init_context(
- httpc_context *ctx
-)
-{
- ctx->socket = -1;
- ctx->fd = NULL;
-}
-
-bool httpc_open_connection(
- httpc_context *ctx,
- const char *targethost,
- int targetport
-)
-{
- struct sockaddr_in addr;
-
- struct hostent *server;
-
- 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(
- const httpc_context *ctx,
- const char *request,
- char *response,
- int responsesize
-)
-{
- rtems_test_assert(ctx != NULL);
- rtems_test_assert(ctx->socket >= 0);
- rtems_test_assert(request != NULL);
- rtems_test_assert(response != NULL);
- rtems_test_assert(responsesize > 1);
-
- static const char * const lineend = " HTTP/1.1\r\n\r\n";
-
- write(ctx->socket, request, strlen(request));
- write(ctx->socket, lineend, strlen(lineend));
-
- ssize_t size;
- if((size = httpc_read_full(ctx, response, responsesize - 1)) == -1)
- {
- return false;
- }
- *(response + size) = '\0';
-
- return true;
-}
-
-bool httpc_ws_open_connection(
- const httpc_context *ctx
-)
-{
- rtems_test_assert(ctx != NULL);
- rtems_test_assert(ctx->socket >= 0);
-
- write(ctx->socket, HTTPC_WS_CONN_REQ, strlen(HTTPC_WS_CONN_REQ));
-
- char response[strlen(HTTPC_WS_CONN_RESP)];
- if(httpc_read_full(ctx, response, sizeof(response)) != sizeof(response))
- {
- return false;
- }
- if(strncmp(response, HTTPC_WS_CONN_RESP, sizeof(response)) != 0)
- {
- return false;
- }
-
- return true;
-}
-
-bool httpc_ws_send_request(
- const httpc_context *ctx,
- const char *request,
- char *response,
- int responsesize
-)
-{
- rtems_test_assert(ctx != NULL);
- rtems_test_assert(ctx->socket >= 0);
- rtems_test_assert(request != NULL);
- rtems_test_assert(response != NULL);
- rtems_test_assert(responsesize > 0);
-
- static const uint16_t ws_header_fin = 1U << 15;
- static const uint16_t ws_header_text = 1U << 8;
- static const uint16_t ws_header_size = 0x7FU;
-
- /*
- * We don't support sending WebSocket messages which require multiple
- * chunks
- */
- if(strlen(request) > ws_header_size) { return false; }
-
- uint16_t header = htons(ws_header_fin | ws_header_text | strlen(request));
-
- write(ctx->socket, &header, sizeof(header));
- write(ctx->socket, request, strlen(request));
-
- if (httpc_read_full(ctx, &header, sizeof(header)) != sizeof(header))
- {
- return false;
- }
- header = ntohs(header);
- if (!(header & ws_header_fin)) { return false; }
- if (!(header & ws_header_text)) { return false; }
- if (responsesize < (header & ws_header_size) + 1) { return false; }
-
- responsesize = header & ws_header_size;
- if (httpc_read_full(ctx, response, responsesize) != responsesize)
- {
- return false;
- }
- *(response + responsesize) = '\0';
-
- return true;
-}
-
-
-static ssize_t httpc_read_full(
- const httpc_context *ctx,
- void *response,
- size_t responsesize
-)
-{
- rtems_test_assert(ctx != NULL);
- rtems_test_assert(ctx->socket >= 0);
- rtems_test_assert(response != NULL);
- rtems_test_assert(responsesize > 0);
-
- if (responsesize > SSIZE_MAX) { return -1; }
-
- unsigned char *pos = response;
-
- while(pos < (unsigned char *)response + responsesize)
- {
- ssize_t size =
- read(ctx->socket, pos, (unsigned char *)response + responsesize - pos);
- if (size == -1) { return -1; }
- if (size == 0) { break; }
- pos += size;
- }
-
- return (pos - (unsigned char *)response);
-}
diff --git a/testsuites/libtests/mghttpd01/test-http-client.h b/testsuites/libtests/mghttpd01/test-http-client.h
deleted file mode 100644
index 811c790110..0000000000
--- a/testsuites/libtests/mghttpd01/test-http-client.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.org/license/LICENSE.
- */
-
-#ifndef TEST_WEB_CLIENT_H
-#define TEST_WEB_CLIENT_H
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-typedef struct
-{
- int socket;
- FILE *fd;
-}
-httpc_context;
-
-void httpc_init_context(
- httpc_context *ctx
-);
-
-bool httpc_open_connection(
- httpc_context *ctx,
- const char *targethost,
- int targetport
-);
-
-bool httpc_close_connection(
- httpc_context *ctx
-);
-
-bool httpc_send_request(
- const httpc_context *ctx,
- const char *request,
- char *response,
- int responsesize
-);
-
-bool httpc_ws_open_connection(
- const httpc_context *ctx
-);
-
-bool httpc_ws_send_request(
- const httpc_context *ctx,
- const char *request,
- char *response,
- int responsesize
-);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* TEST_WEB_CLIENT_H */