NET_7, NET_8 - HTTP and NTP client test automation added to test suite

pull/236/head
Przemek Wirkus 2014-03-26 14:48:44 +00:00
parent 9c0ed35267
commit e10bd60385
4 changed files with 91 additions and 66 deletions

View File

@ -2,16 +2,14 @@
#include "test_env.h"
#include "mbed_rpc.h"
char outbuf[RPC_MAX_STRING] = {0};
float f = 0;
void foo(Arguments *args, Reply *reply) {
reply->putData<float>(args->getArg<float>() * 3.3);
}
bool rpc_test(const char *input, const char *expected) {
printf("RPC: %s -> ", input);
char outbuf[RPC_MAX_STRING] = {0};
bool result = RPC::call(input, outbuf);
printf("RPC: %s -> ", input);
if (result == false) {
printf("Procedure call ... [FAIL]\r\n");
@ -27,6 +25,7 @@ bool rpc_test(const char *input, const char *expected) {
#define RPC_TEST(INPUT,EXPECTED) result = result && rpc_test(INPUT,EXPECTED); if (result == false) { notify_completion(result); exit(1); }
int main() {
float f = 0;
bool result = true;
// Variable
RPCVariable<float> rpc_f(&f, "f");

View File

@ -1,49 +1,65 @@
#include "mbed.h"
#include "test_env.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"
EthernetInterface eth;
HTTPClient http;
char str[512];
#define BUFFER_SIZE 512
int main()
{
char http_request_buffer[BUFFER_SIZE+1] = {0};
HTTPClient http;
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
//GET data
printf("Trying to fetch page...\n");
int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
if (!ret)
{
printf("Page fetched successfully - read %d characters\n", strlen(str));
printf("Result: %s\n", str);
}
else
{
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
bool result = true;
const char *url_hello_txt = "http://mbed.org/media/uploads/donatien/hello.txt";
printf("HTTP_GET: Trying to fetch page '%s'...\r\n", url_hello_txt);
const int ret = http.get(url_hello_txt, http_request_buffer, BUFFER_SIZE);
if (ret == 0)
{
printf("HTTP_GET: Read %d chars: '%s' ... [OK]\r\n", strlen(http_request_buffer), http_request_buffer);
}
else
{
printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
result = false;
}
if (result == false) {
notify_completion(false);
exit(ret);
}
}
//POST data
HTTPMap map;
HTTPText text(str, 512);
map.put("Hello", "World");
map.put("test", "1234");
printf("Trying to post data...\n");
ret = http.post("http://httpbin.org/post", map, &text);
if (!ret)
{
printf("Executed POST successfully - read %d characters\n", strlen(str));
printf("Result: %s\n", str);
}
else
{
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
}
bool result = true;
const char *url_httpbin_post = "http://httpbin.org/post";
HTTPMap map;
HTTPText text(http_request_buffer, BUFFER_SIZE);
map.put("Hello", "World");
map.put("test", "1234");
printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post);
const int ret = http.post(url_httpbin_post, map, &text);
if (ret == 0) {
printf("HTTP_POST: Read %d chars ... [OK]\n", strlen(http_request_buffer));
printf("HTTP_POST: %s\r\n", http_request_buffer);
}
else {
printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
result = false;
}
if (result == false) {
notify_completion(false);
exit(ret);
}
}
eth.disconnect();
while(1) {
}
notify_completion(true);
return 0;
}

View File

@ -1,31 +1,37 @@
#include "mbed.h"
#include "test_env.h"
#include "EthernetInterface.h"
#include "NTPClient.h"
EthernetInterface eth;
NTPClient ntp;
int main()
{
EthernetInterface eth;
NTPClient ntp;
eth.init(); //Use DHCP
eth.connect();
printf("Trying to update time...\r\n");
if (ntp.setTime("0.pool.ntp.org") == 0)
// NTP set time
{
printf("Set time successfully\r\n");
time_t ctTime;
ctTime = time(NULL);
printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
}
else
{
printf("Error\r\n");
}
bool result = true;
const char *url_ntp_server = "0.pool.ntp.org";
printf("NTP_SETTIME: Trying to update time... \r\n");
const int ret = ntp.setTime(url_ntp_server);
if (ret == 0) {
time_t ctTime = time(NULL);
printf("NTP_SETTIME: UTC Time read successfully ... [OK]\r\n");
printf("NTP_SETTIME: %s\r\n", ctime(&ctTime));
}
else {
printf("NTP_SETTIME: Error(%d) ... [FAIL]\r\n", ret);
result = false;
}
if (result == false) {
notify_completion(false);
exit(ret);
}
}
eth.disconnect();
while(1) {
}
notify_completion(true);
return 0;
}

View File

@ -600,17 +600,21 @@ TESTS = [
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"automated": True,
"host_test" : "udpecho_client_auto",
"peripherals": ["ethernet"]
"peripherals": ["ethernet"],
},
{
"id": "NET_7", "description": "HTTP client",
"source_dir": join(TEST_DIR, "net", "protocols", "HTTPClient_HelloWorld"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
"automated": True,
"peripherals": ["ethernet"],
},
{
"id": "NET_8", "description": "NTP client",
"source_dir": join(TEST_DIR, "net", "protocols", "NTPClient_HelloWorld"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
"automated": True,
"peripherals": ["ethernet"],
},
{
"id": "NET_9", "description": "Multicast Send",