-
Notifications
You must be signed in to change notification settings - Fork 3k
Networking test fixes #4240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Networking test fixes #4240
Changes from all commits
fecb005
86c1680
41fd05c
8222627
27a97f9
4d672e0
6862912
984af4b
abcdd01
d55b3cf
9c98f3f
2761a8c
81bedff
3c7f2ab
56ba283
d852bf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,16 +91,25 @@ void test_dns_literal_pref() { | |
|
||
// Test setup | ||
utest::v1::status_t test_setup(const size_t number_of_cases) { | ||
GREENTEA_SETUP(60, "default_auto"); | ||
char uuid[48] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 48 ? |
||
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48); | ||
|
||
// create mac address based on uuid | ||
uint64_t mac = 0; | ||
for (int i = 0; i < sizeof(uuid); i++) { | ||
mac += uuid[i]; | ||
} | ||
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment inside function call |
||
net_bringup(); | ||
|
||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
Case("Testing DNS query", test_dns_query), | ||
Case("Testing DNS preference query", test_dns_query_pref), | ||
Case("Testing DNS literal", test_dns_literal), | ||
Case("Testing DNS preference literal", test_dns_literal_pref), | ||
Case("DNS query", test_dns_query), | ||
Case("DNS preference query", test_dns_query_pref), | ||
Case("DNS literal", test_dns_literal), | ||
Case("DNS preference literal", test_dns_literal_pref), | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
#include "TCPSocket.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
|
||
using namespace utest::v1; | ||
|
||
|
||
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE | ||
|
@@ -28,11 +31,14 @@ void prep_buffer(char *tx_buffer, size_t tx_size) { | |
} | ||
} | ||
|
||
int main() { | ||
GREENTEA_SETUP(60, "tcp_echo"); | ||
|
||
void test_tcp_echo() { | ||
EthernetInterface eth; | ||
eth.connect(); | ||
int err = eth.connect(); | ||
|
||
if (err) { | ||
printf("MBED: failed to connect with an error of %d\r\n", err); | ||
TEST_ASSERT_EQUAL(0, err); | ||
} | ||
|
||
printf("MBED: TCPClient IP address is '%s'\n", eth.get_ip_address()); | ||
printf("MBED: TCPClient waiting for server IP and port...\n"); | ||
|
@@ -64,17 +70,44 @@ int main() { | |
|
||
prep_buffer(tx_buffer, sizeof(tx_buffer)); | ||
sock.send(tx_buffer, sizeof(tx_buffer)); | ||
|
||
printf("MBED: Finished sending\r\n"); | ||
// Server will respond with HTTP GET's success code | ||
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer)); | ||
|
||
printf("MBED: Finished receiving\r\n"); | ||
|
||
result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer)); | ||
|
||
TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer)); | ||
TEST_ASSERT_EQUAL(true, result); | ||
} | ||
|
||
sock.close(); | ||
eth.disconnect(); | ||
GREENTEA_TESTSUITE_RESULT(result); | ||
TEST_ASSERT_EQUAL(true, result); | ||
} | ||
|
||
|
||
// Test setup | ||
utest::v1::status_t test_setup(const size_t number_of_cases) { | ||
char uuid[48] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic number |
||
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48); | ||
|
||
// create mac address based on uuid | ||
uint64_t mac = 0; | ||
for (int i = 0; i < sizeof(uuid); i++) { | ||
mac += uuid[i]; | ||
} | ||
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment in function |
||
|
||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
Case("TCP echo", test_tcp_echo), | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
||
int main() { | ||
return !Harness::run(specification); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
#include "TCPSocket.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
|
||
using namespace utest::v1; | ||
|
||
|
||
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE | ||
|
@@ -64,7 +67,7 @@ class Echo { | |
TEST_ASSERT_EQUAL(0, err); | ||
|
||
iomutex.lock(); | ||
printf("HTTP: Connected to %s:%d\r\n", | ||
printf("HTTP: Connected to %s:%d\r\n", | ||
tcp_addr.get_ip_address(), tcp_addr.get_port()); | ||
printf("tx_buffer buffer size: %u\r\n", sizeof(tx_buffer)); | ||
printf("rx_buffer buffer size: %u\r\n", sizeof(rx_buffer)); | ||
|
@@ -84,12 +87,10 @@ class Echo { | |
} | ||
}; | ||
|
||
Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS]; | ||
|
||
Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS]; | ||
|
||
int main() { | ||
GREENTEA_SETUP(60, "tcp_echo"); | ||
|
||
void test_tcp_echo_parallel() { | ||
int err = net.connect(); | ||
TEST_ASSERT_EQUAL(0, err); | ||
|
||
|
@@ -116,13 +117,40 @@ int main() { | |
|
||
// Startup echo threads in parallel | ||
for (int i = 0; i < MBED_CFG_TCP_CLIENT_ECHO_THREADS; i++) { | ||
echoers[i].start(); | ||
echoers[i] = new Echo; | ||
echoers[i]->start(); | ||
} | ||
|
||
for (int i = 0; i < MBED_CFG_TCP_CLIENT_ECHO_THREADS; i++) { | ||
echoers[i].join(); | ||
echoers[i]->join(); | ||
delete echoers[i]; | ||
} | ||
|
||
net.disconnect(); | ||
GREENTEA_TESTSUITE_RESULT(true); | ||
} | ||
|
||
// Test setup | ||
utest::v1::status_t test_setup(const size_t number_of_cases) { | ||
char uuid[48] = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic number |
||
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48); | ||
|
||
// create mac address based on uuid | ||
uint64_t mac = 0; | ||
for (int i = 0; i < sizeof(uuid); i++) { | ||
mac += uuid[i]; | ||
} | ||
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment inside function |
||
|
||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
Case("TCP echo parallel", test_tcp_echo_parallel), | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
||
int main() { | ||
return !Harness::run(specification); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
#include "TCPSocket.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
|
||
using namespace utest::v1; | ||
|
||
|
||
namespace { | ||
// Test connection information | ||
|
@@ -35,12 +39,9 @@ bool find_substring(const char *first, const char *last, const char *s_first, co | |
return (f != last); | ||
} | ||
|
||
int main() { | ||
GREENTEA_SETUP(60, "default_auto"); | ||
|
||
void test_tcp_hello_world() { | ||
bool result = false; | ||
EthernetInterface eth; | ||
//eth.init(); //Use DHCP | ||
eth.connect(); | ||
printf("TCP client IP Address is %s\r\n", eth.get_ip_address()); | ||
|
||
|
@@ -83,5 +84,32 @@ int main() { | |
} | ||
|
||
eth.disconnect(); | ||
GREENTEA_TESTSUITE_RESULT(result); | ||
TEST_ASSERT_EQUAL(true, result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be TEST_ASSERT_TRUE(result) |
||
} | ||
|
||
|
||
// Test setup | ||
utest::v1::status_t test_setup(const size_t number_of_cases) { | ||
char uuid[48] = {0}; | ||
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48); | ||
|
||
// create mac address based on uuid | ||
uint64_t mac = 0; | ||
for (int i = 0; i < sizeof(uuid); i++) { | ||
mac += uuid[i]; | ||
} | ||
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1); | ||
|
||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
Case("TCP hello world", test_tcp_hello_world), | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
||
int main() { | ||
return !Harness::run(specification); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
48 ??? Magic number, should be #defined