mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-04 14:14:07 +08:00
mghttpd01: Add test - does not build yet
This commit is contained in:
parent
68e4c84698
commit
d32a9cf7c5
1
testsuite/mghttpd01/.gitignore
vendored
Normal file
1
testsuite/mghttpd01/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
init.c
|
37
testsuite/mghttpd01/Makefile
Normal file
37
testsuite/mghttpd01/Makefile
Normal 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)
|
BIN
testsuite/mghttpd01/init_fs.tar
Normal file
BIN
testsuite/mghttpd01/init_fs.tar
Normal file
Binary file not shown.
11
testsuite/mghttpd01/mghttpd01.doc
Normal file
11
testsuite/mghttpd01/mghttpd01.doc
Normal 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
|
33
testsuite/mghttpd01/mghttpd01.scn
Normal file
33
testsuite/mghttpd01/mghttpd01.scn
Normal 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 ***
|
95
testsuite/mghttpd01/test-http-client.c
Normal file
95
testsuite/mghttpd01/test-http-client.c
Normal 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;
|
||||
}
|
||||
|
58
testsuite/mghttpd01/test-http-client.h
Normal file
58
testsuite/mghttpd01/test-http-client.h
Normal 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 */
|
Loading…
x
Reference in New Issue
Block a user