mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-09 08:37:58 +08:00
libtests/mghttpd01: New test
This commit is contained in:
1 parent
5267241b32
commit
0eb5bfba3c
9 files changed
+470
No files matched your search
@@ -20,6 +20,7 @@ SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
|
||||
mouse01
|
||||
|
||||
if NETTESTS
|
||||
SUBDIRS += mghttpd01
|
||||
SUBDIRS += ftp01
|
||||
SUBDIRS += syscall01
|
||||
endif
|
||||
|
||||
@@ -41,6 +41,7 @@ AM_CONDITIONAL(NETTESTS,test "$rtems_cv_RTEMS_NETWORKING" = "yes")
|
||||
|
||||
# Explicitly list all Makefiles here
|
||||
AC_CONFIG_FILES([Makefile
|
||||
mghttpd01/Makefile
|
||||
block15/Makefile
|
||||
block14/Makefile
|
||||
block13/Makefile
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
rtems_tests_PROGRAMS = mghttpd01
|
||||
|
||||
mghttpd01_SOURCES = init.c init_fs.c init_fs.h \
|
||||
test-http-client.c test-http-client.h
|
||||
mghttpd01_LDADD = -lmghttpd
|
||||
BUILT_SOURCES = init_fs.c init_fs.h
|
||||
|
||||
dist_rtems_tests_DATA = mghttpd01.scn mghttpd01.doc
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(mghttpd01_OBJECTS) $(mghttpd01_LDADD)
|
||||
LINK_LIBS = $(mghttpd01_LDLIBS)
|
||||
|
||||
mghttpd01$(EXEEXT): $(mghttpd01_OBJECTS) $(mghttpd01_DEPENDENCIES)
|
||||
@rm -f mghttpd01$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
init_fs.c:
|
||||
$(BIN2C) -C $(srcdir)/init_fs.tar init_fs
|
||||
CLEANFILES += init_fs.c
|
||||
|
||||
init_fs.h:
|
||||
$(BIN2C) -H $(srcdir)/init_fs.tar init_fs
|
||||
CLEANFILES += init_fs.h
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -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
|
||||
@@ -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 ***
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
Reference in new issue
Block a user