mghttpd01: Add test - does not build yet

This commit is contained in:
Joel Sherrill 2012-07-28 06:42:15 -05:00
parent 68e4c84698
commit d32a9cf7c5
7 changed files with 235 additions and 0 deletions

1
testsuite/mghttpd01/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
init.c

View File

@ -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)

Binary file not shown.

View File

@ -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

View File

@ -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 ***

View File

@ -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;
}

View File

@ -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 */