Skip to content

Commit e10bd60

Browse files
committed
NET_7, NET_8 - HTTP and NTP client test automation added to test suite
1 parent 9c0ed35 commit e10bd60

File tree

4 files changed

+85
-60
lines changed

4 files changed

+85
-60
lines changed

libraries/tests/mbed/rpc/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
#include "test_env.h"
33
#include "mbed_rpc.h"
44

5-
char outbuf[RPC_MAX_STRING] = {0};
6-
float f = 0;
7-
85
void foo(Arguments *args, Reply *reply) {
96
reply->putData<float>(args->getArg<float>() * 3.3);
107
}
118

129
bool rpc_test(const char *input, const char *expected) {
13-
printf("RPC: %s -> ", input);
10+
char outbuf[RPC_MAX_STRING] = {0};
1411
bool result = RPC::call(input, outbuf);
12+
printf("RPC: %s -> ", input);
1513

1614
if (result == false) {
1715
printf("Procedure call ... [FAIL]\r\n");
@@ -27,6 +25,7 @@ bool rpc_test(const char *input, const char *expected) {
2725
#define RPC_TEST(INPUT,EXPECTED) result = result && rpc_test(INPUT,EXPECTED); if (result == false) { notify_completion(result); exit(1); }
2826

2927
int main() {
28+
float f = 0;
3029
bool result = true;
3130
// Variable
3231
RPCVariable<float> rpc_f(&f, "f");
Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,65 @@
11
#include "mbed.h"
2+
#include "test_env.h"
23
#include "EthernetInterface.h"
34
#include "HTTPClient.h"
45

5-
EthernetInterface eth;
6-
HTTPClient http;
7-
char str[512];
6+
#define BUFFER_SIZE 512
87

9-
int main()
8+
int main()
109
{
10+
char http_request_buffer[BUFFER_SIZE+1] = {0};
11+
HTTPClient http;
12+
EthernetInterface eth;
1113
eth.init(); //Use DHCP
12-
1314
eth.connect();
14-
15+
1516
//GET data
16-
printf("Trying to fetch page...\n");
17-
int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
18-
if (!ret)
1917
{
20-
printf("Page fetched successfully - read %d characters\n", strlen(str));
21-
printf("Result: %s\n", str);
22-
}
23-
else
24-
{
25-
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
18+
bool result = true;
19+
const char *url_hello_txt = "http://mbed.org/media/uploads/donatien/hello.txt";
20+
printf("HTTP_GET: Trying to fetch page '%s'...\r\n", url_hello_txt);
21+
const int ret = http.get(url_hello_txt, http_request_buffer, BUFFER_SIZE);
22+
if (ret == 0)
23+
{
24+
printf("HTTP_GET: Read %d chars: '%s' ... [OK]\r\n", strlen(http_request_buffer), http_request_buffer);
25+
}
26+
else
27+
{
28+
printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
29+
result = false;
30+
}
31+
32+
if (result == false) {
33+
notify_completion(false);
34+
exit(ret);
35+
}
2636
}
27-
37+
2838
//POST data
29-
HTTPMap map;
30-
HTTPText text(str, 512);
31-
map.put("Hello", "World");
32-
map.put("test", "1234");
33-
printf("Trying to post data...\n");
34-
ret = http.post("http://httpbin.org/post", map, &text);
35-
if (!ret)
36-
{
37-
printf("Executed POST successfully - read %d characters\n", strlen(str));
38-
printf("Result: %s\n", str);
39-
}
40-
else
4139
{
42-
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
43-
}
44-
45-
eth.disconnect();
40+
bool result = true;
41+
const char *url_httpbin_post = "http://httpbin.org/post";
42+
HTTPMap map;
43+
HTTPText text(http_request_buffer, BUFFER_SIZE);
44+
map.put("Hello", "World");
45+
map.put("test", "1234");
46+
printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post);
47+
const int ret = http.post(url_httpbin_post, map, &text);
48+
if (ret == 0) {
49+
printf("HTTP_POST: Read %d chars ... [OK]\n", strlen(http_request_buffer));
50+
printf("HTTP_POST: %s\r\n", http_request_buffer);
51+
}
52+
else {
53+
printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
54+
result = false;
55+
}
4656

47-
while(1) {
57+
if (result == false) {
58+
notify_completion(false);
59+
exit(ret);
60+
}
4861
}
62+
eth.disconnect();
63+
notify_completion(true);
64+
return 0;
4965
}
Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
#include "mbed.h"
2+
#include "test_env.h"
23
#include "EthernetInterface.h"
34
#include "NTPClient.h"
45

5-
EthernetInterface eth;
6-
NTPClient ntp;
7-
8-
int main()
6+
int main()
97
{
8+
EthernetInterface eth;
9+
NTPClient ntp;
1010
eth.init(); //Use DHCP
11-
1211
eth.connect();
13-
14-
printf("Trying to update time...\r\n");
15-
if (ntp.setTime("0.pool.ntp.org") == 0)
16-
{
17-
printf("Set time successfully\r\n");
18-
time_t ctTime;
19-
ctTime = time(NULL);
20-
printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
21-
}
22-
else
12+
13+
// NTP set time
2314
{
24-
printf("Error\r\n");
25-
}
26-
27-
eth.disconnect();
15+
bool result = true;
16+
const char *url_ntp_server = "0.pool.ntp.org";
17+
printf("NTP_SETTIME: Trying to update time... \r\n");
18+
const int ret = ntp.setTime(url_ntp_server);
19+
if (ret == 0) {
20+
time_t ctTime = time(NULL);
21+
printf("NTP_SETTIME: UTC Time read successfully ... [OK]\r\n");
22+
printf("NTP_SETTIME: %s\r\n", ctime(&ctTime));
23+
}
24+
else {
25+
printf("NTP_SETTIME: Error(%d) ... [FAIL]\r\n", ret);
26+
result = false;
27+
}
2828

29-
while(1) {
29+
if (result == false) {
30+
notify_completion(false);
31+
exit(ret);
32+
}
3033
}
34+
eth.disconnect();
35+
notify_completion(true);
36+
return 0;
3137
}

workspace_tools/tests.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,17 +600,21 @@
600600
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
601601
"automated": True,
602602
"host_test" : "udpecho_client_auto",
603-
"peripherals": ["ethernet"]
603+
"peripherals": ["ethernet"],
604604
},
605605
{
606606
"id": "NET_7", "description": "HTTP client",
607607
"source_dir": join(TEST_DIR, "net", "protocols", "HTTPClient_HelloWorld"),
608-
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
608+
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
609+
"automated": True,
610+
"peripherals": ["ethernet"],
609611
},
610612
{
611613
"id": "NET_8", "description": "NTP client",
612614
"source_dir": join(TEST_DIR, "net", "protocols", "NTPClient_HelloWorld"),
613-
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
615+
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
616+
"automated": True,
617+
"peripherals": ["ethernet"],
614618
},
615619
{
616620
"id": "NET_9", "description": "Multicast Send",

0 commit comments

Comments
 (0)