mirror of https://github.com/ARMmbed/mbed-os.git
Modified host tests to use serial.realine() function to avoid extra timeouts during tests (test will work faster and will be more reliable)
parent
0748ef4a2a
commit
63ee01bdd9
|
@ -1,24 +1,16 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "test_env.h"
|
#include "test_env.h"
|
||||||
|
|
||||||
#if defined(TARGET_NUCLEO_F103RB) || \
|
|
||||||
defined(TARGET_NUCLEO_L152RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F302R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F030R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F401RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F411RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F072RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F334R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L053R8)
|
|
||||||
#define TXPIN STDIO_UART_TX
|
|
||||||
#define RXPIN STDIO_UART_RX
|
|
||||||
#else
|
|
||||||
#define TXPIN USBTX
|
#define TXPIN USBTX
|
||||||
#define RXPIN USBRX
|
#define RXPIN USBRX
|
||||||
#endif
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const int BUFFER_SIZE = 48;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char buf[256];
|
char buffer[BUFFER_SIZE] = {0};
|
||||||
|
|
||||||
Serial pc(TXPIN, RXPIN);
|
Serial pc(TXPIN, RXPIN);
|
||||||
pc.baud(115200);
|
pc.baud(115200);
|
||||||
|
@ -28,7 +20,7 @@ int main() {
|
||||||
pc.puts("}}");
|
pc.puts("}}");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
pc.gets(buf, 256);
|
pc.gets(buffer, BUFFER_SIZE - 1);
|
||||||
pc.printf("%s", buf);
|
pc.printf("%s", buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ const char* TEST_ENV_FAILURE = "failure";
|
||||||
const char* TEST_ENV_MEASURE = "measure";
|
const char* TEST_ENV_MEASURE = "measure";
|
||||||
const char* TEST_ENV_END = "end";
|
const char* TEST_ENV_END = "end";
|
||||||
|
|
||||||
|
|
||||||
static void led_blink(PinName led, float delay)
|
static void led_blink(PinName led, float delay)
|
||||||
{
|
{
|
||||||
if (led != NC) {
|
if (led != NC) {
|
||||||
|
@ -41,11 +42,20 @@ void notify_performance_coefficient(const char* measurement_name, const double v
|
||||||
|
|
||||||
void notify_completion(bool success)
|
void notify_completion(bool success)
|
||||||
{
|
{
|
||||||
printf("{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE);
|
printf("{{%s}}" NL "{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE, TEST_ENV_END);
|
||||||
printf("{{%s}}" NL, TEST_ENV_END);
|
|
||||||
led_blink(LED1, success ? 1.0 : 0.1);
|
led_blink(LED1, success ? 1.0 : 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool notify_completion_str(bool success, char* buffer)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
if (buffer) {
|
||||||
|
sprintf(buffer, "{{%s}}" NL "{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE, TEST_ENV_END);
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// -DMBED_BUILD_TIMESTAMP=1406208182.13
|
// -DMBED_BUILD_TIMESTAMP=1406208182.13
|
||||||
unsigned int testenv_randseed()
|
unsigned int testenv_randseed()
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern const char* TEST_ENV_END;
|
||||||
// Test result related notification functions
|
// Test result related notification functions
|
||||||
void notify_start();
|
void notify_start();
|
||||||
void notify_completion(bool success);
|
void notify_completion(bool success);
|
||||||
|
bool notify_completion_str(bool success, char* buffer);
|
||||||
void notify_performance_coefficient(const char* measurement_name, const int value);
|
void notify_performance_coefficient(const char* measurement_name, const int value);
|
||||||
void notify_performance_coefficient(const char* measurement_name, const unsigned int value);
|
void notify_performance_coefficient(const char* measurement_name, const unsigned int value);
|
||||||
void notify_performance_coefficient(const char* measurement_name, const double value);
|
void notify_performance_coefficient(const char* measurement_name, const double value);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
notify_start();
|
||||||
printf("Hello World\r\n");
|
printf("Hello World\r\n");
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "test_env.h"
|
#include "test_env.h"
|
||||||
#include "EthernetInterface.h"
|
#include "EthernetInterface.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const int BUFFER_SIZE = 64;
|
||||||
|
const int MAX_ECHO_LOOPS = 1000;
|
||||||
|
const char ASCII_MAX = '~' - ' ';
|
||||||
|
|
||||||
struct s_ip_address
|
struct s_ip_address
|
||||||
{
|
{
|
||||||
|
@ -9,32 +15,33 @@ struct s_ip_address
|
||||||
int ip_3;
|
int ip_3;
|
||||||
int ip_4;
|
int ip_4;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#define MAX_ECHO_LOOPS 100
|
char char_rand() {
|
||||||
|
return (rand() % ASCII_MAX) + ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char buffer[256] = {0};
|
char buffer[BUFFER_SIZE] = {0};
|
||||||
char out_buffer[] = "Hello World\n";
|
char out_buffer[BUFFER_SIZE] = {0};
|
||||||
char out_success[] = "{{success}}\n{{end}}\n";
|
|
||||||
char out_failure[] = "{{failure}}\n{{end}}\n";
|
|
||||||
s_ip_address ip_addr = {0, 0, 0, 0};
|
s_ip_address ip_addr = {0, 0, 0, 0};
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
|
||||||
printf("TCPCllient waiting for server IP and port...\r\n");
|
printf("MBED: TCPCllient waiting for server IP and port...\r\n");
|
||||||
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
|
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
|
||||||
printf("Address received:%d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
|
printf("MBED: Address received: %d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
|
||||||
|
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
eth.init(); //Use DHCP
|
eth.init(); //Use DHCP
|
||||||
eth.connect();
|
eth.connect();
|
||||||
|
|
||||||
printf("TCPClient IP Address is %s\r\n", eth.getIPAddress());
|
printf("MBED: TCPClient IP Address is %s\r\n", eth.getIPAddress());
|
||||||
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
|
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
|
||||||
|
|
||||||
TCPSocketConnection socket;
|
TCPSocketConnection socket;
|
||||||
while (socket.connect(buffer, port) < 0) {
|
while (socket.connect(buffer, port) < 0) {
|
||||||
printf("TCPCllient unable to connect to %s:%d\r\n", buffer, port);
|
printf("MBED: TCPCllient unable to connect to %s:%d\r\n", buffer, port);
|
||||||
wait(1);
|
wait(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,14 +49,13 @@ int main() {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
int count_error = 0;
|
int count_error = 0;
|
||||||
for (int i = 0; i < MAX_ECHO_LOOPS; i++) {
|
for (int i = 0; i < MAX_ECHO_LOOPS; i++) {
|
||||||
socket.send_all(out_buffer, sizeof(out_buffer) - 1);
|
std::generate(out_buffer, out_buffer + BUFFER_SIZE, char_rand);
|
||||||
|
socket.send_all(out_buffer, BUFFER_SIZE);
|
||||||
|
|
||||||
int n = socket.receive(buffer, sizeof(buffer));
|
int n = socket.receive(buffer, BUFFER_SIZE);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
{
|
{
|
||||||
buffer[n] = '\0';
|
bool echoed = memcmp(out_buffer, buffer, BUFFER_SIZE) == 0;
|
||||||
printf("%s", buffer);
|
|
||||||
bool echoed = strncmp(out_buffer, buffer, sizeof(out_buffer) - 1) == 0;
|
|
||||||
result = result && echoed;
|
result = result && echoed;
|
||||||
if (echoed == false) {
|
if (echoed == false) {
|
||||||
count_error++; // Count error messages
|
count_error++; // Count error messages
|
||||||
|
@ -57,15 +63,13 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Loop messages passed: %d/%d\r\n", MAX_ECHO_LOOPS - count_error, MAX_ECHO_LOOPS);
|
printf("MBED: Loop messages passed: %d / %d\r\n", MAX_ECHO_LOOPS - count_error, MAX_ECHO_LOOPS);
|
||||||
|
|
||||||
if (result) {
|
if (notify_completion_str(result, buffer)) {
|
||||||
socket.send_all(out_success, sizeof(out_success) - 1);
|
socket.send_all(buffer, strlen(buffer));
|
||||||
}
|
|
||||||
else {
|
|
||||||
socket.send_all(out_failure, sizeof(out_failure) - 1);
|
|
||||||
}
|
}
|
||||||
socket.close();
|
socket.close();
|
||||||
eth.disconnect();
|
eth.disconnect();
|
||||||
|
notify_completion(result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,35 +3,38 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const int ECHO_SERVER_PORT = 7;
|
const int ECHO_SERVER_PORT = 7;
|
||||||
const int BUFFER_SIZE = 256;
|
const int BUFFER_SIZE = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
|
char buffer[BUFFER_SIZE] = {0};
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
eth.init(); //Use DHCP
|
eth.init(); //Use DHCP
|
||||||
eth.connect();
|
eth.connect();
|
||||||
printf("Server IP Address is %s:%d\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
printf("MBED: Server IP Address is %s:%d\r\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
||||||
|
|
||||||
TCPSocketServer server;
|
TCPSocketServer server;
|
||||||
server.bind(ECHO_SERVER_PORT);
|
server.bind(ECHO_SERVER_PORT);
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
printf("Wait for new connection...\n");
|
printf("MBED: Wait for new connection...\n");
|
||||||
TCPSocketConnection client;
|
TCPSocketConnection client;
|
||||||
server.accept(client);
|
server.accept(client);
|
||||||
client.set_blocking(false, 1500); // Timeout after (1.5)s
|
client.set_blocking(false, 1500); // Timeout after (1.5)s
|
||||||
printf("Connection from: %s\n", client.get_address());
|
printf("MBED: Connection from: %s\r\n", client.get_address());
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
char buffer[BUFFER_SIZE] = {0};
|
const int n = client.receive(buffer, sizeof(buffer));
|
||||||
int n = client.receive(buffer, sizeof(buffer));
|
if (n <= 0) {
|
||||||
if (n <= 0) break;
|
break;
|
||||||
|
}
|
||||||
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
|
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
|
||||||
buffer[buffer_string_end_index] = '\0';
|
buffer[buffer_string_end_index] = '\0';
|
||||||
printf("Server received: %s\n", buffer);
|
|
||||||
client.send_all(buffer, n);
|
client.send_all(buffer, n);
|
||||||
if (n <= 0) break;
|
if (n <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "rtos.h"
|
#include "rtos.h"
|
||||||
|
#include "test_env.h"
|
||||||
#include "EthernetInterface.h"
|
#include "EthernetInterface.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define CHECK(RC, STEP) if (RC < 0) error(STEP": %d\n", RC)
|
#define CHECK(RC, STEP) if (RC < 0) error(STEP": %d\r\n", RC)
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const int BUFFER_SIZE = 64;
|
||||||
|
const int MAX_ECHO_LOOPS = 100;
|
||||||
|
const char ASCII_MAX = '~' - ' ';
|
||||||
|
|
||||||
struct s_ip_address
|
struct s_ip_address
|
||||||
{
|
{
|
||||||
|
@ -11,18 +18,23 @@ struct s_ip_address
|
||||||
int ip_3;
|
int ip_3;
|
||||||
int ip_4;
|
int ip_4;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
char char_rand() {
|
||||||
|
return (rand() % ASCII_MAX) + ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char buffer[256] = {0};
|
char buffer[BUFFER_SIZE] = {0};
|
||||||
char out_buffer[] = "Hello World\n";
|
char out_buffer[BUFFER_SIZE] = {0};
|
||||||
char out_success[] = "{{success}}\n{{end}}\n";
|
|
||||||
char out_failure[] = "{{failure}}\n{{end}}\n";
|
|
||||||
s_ip_address ip_addr = {0, 0, 0, 0};
|
s_ip_address ip_addr = {0, 0, 0, 0};
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
printf("UDPCllient waiting for server IP and port...\r\n");
|
printf("MBED: UDPCllient waiting for server IP and port...\r\n");
|
||||||
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
|
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
|
||||||
printf("Address received:%d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
|
printf("MBED: Address received: %d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
|
||||||
|
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
int rc = eth.init(); //Use DHCP
|
int rc = eth.init(); //Use DHCP
|
||||||
|
@ -36,30 +48,33 @@ int main() {
|
||||||
rc = socket.init();
|
rc = socket.init();
|
||||||
CHECK(rc, "socket init");
|
CHECK(rc, "socket init");
|
||||||
|
|
||||||
printf("UDPClient IP Address is %s\r\n", eth.getIPAddress());
|
printf("MBED: UDPClient IP Address is %s\r\n", eth.getIPAddress());
|
||||||
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
|
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
|
||||||
|
|
||||||
Endpoint echo_server;
|
Endpoint echo_server;
|
||||||
rc = echo_server.set_address(buffer, port);
|
rc = echo_server.set_address(buffer, port);
|
||||||
CHECK(rc, "set_address");
|
CHECK(rc, "set_address");
|
||||||
|
|
||||||
|
for (int i =0; i < MAX_ECHO_LOOPS; i++) {
|
||||||
|
std::generate(out_buffer, out_buffer + BUFFER_SIZE, char_rand);
|
||||||
rc = socket.sendTo(echo_server, out_buffer, sizeof(out_buffer));
|
rc = socket.sendTo(echo_server, out_buffer, sizeof(out_buffer));
|
||||||
CHECK(rc, "sendTo");
|
CHECK(rc, "sendTo");
|
||||||
|
|
||||||
int n = socket.receiveFrom(echo_server, buffer, sizeof(buffer));
|
const int n = socket.receiveFrom(echo_server, buffer, sizeof(buffer));
|
||||||
CHECK(n, "receiveFrom");
|
CHECK(n, "receiveFrom");
|
||||||
if (n > 0)
|
|
||||||
{
|
if (memcmp(buffer, out_buffer, BUFFER_SIZE) != 0) {
|
||||||
buffer[n] = '\0';
|
result = false;
|
||||||
printf("%s", buffer);
|
break;
|
||||||
if (strncmp(out_buffer, buffer, sizeof(out_buffer) - 1) == 0) {
|
|
||||||
socket.sendTo(echo_server, out_success, sizeof(out_success) - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.sendTo(echo_server, out_failure, sizeof(out_failure) - 1);
|
if (notify_completion_str(result, buffer)) {
|
||||||
|
socket.sendTo(echo_server, buffer, strlen(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
eth.disconnect();
|
eth.disconnect();
|
||||||
|
notify_completion(result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,24 +12,24 @@
|
||||||
|
|
||||||
// Evil globals
|
// Evil globals
|
||||||
namespace {
|
namespace {
|
||||||
Mutex cli_serv_mutex;
|
|
||||||
// cli_serv_mutex.lock(); // LOCK
|
|
||||||
// cli_serv_mutex.unlock(); // LOCK
|
|
||||||
|
|
||||||
const int ECHO_SERVER_PORT = 7;
|
|
||||||
const int BUFFER_SIZE = 256;
|
|
||||||
|
|
||||||
// Forwarding packet queue
|
|
||||||
std::list<std::string> datagram_queue;
|
|
||||||
|
|
||||||
// IP and port used to store HOST address info
|
// IP and port used to store HOST address info
|
||||||
char host_address[32] = {0};
|
char host_address[32] = {0};
|
||||||
volatile int host_port = 0;
|
volatile int host_port = 0;
|
||||||
|
|
||||||
|
const int ECHO_SERVER_PORT = 7;
|
||||||
|
const int BUFFER_SIZE = 64;
|
||||||
|
|
||||||
|
// Forwarding packet queue
|
||||||
|
std::list<std::string> datagram_queue;
|
||||||
|
|
||||||
// Statistics (mbed)
|
// Statistics (mbed)
|
||||||
volatile int received_packets = 0;
|
volatile int received_packets = 0;
|
||||||
volatile int forwarded_packets = 0;
|
volatile int forwarded_packets = 0;
|
||||||
volatile int max_queue_len = 0;
|
volatile int max_queue_len = 0;
|
||||||
|
|
||||||
|
Mutex cli_serv_mutex;
|
||||||
|
// cli_serv_mutex.lock(); // LOCK
|
||||||
|
// cli_serv_mutex.unlock(); // LOCK
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_server_task(void const *argument)
|
void udp_server_task(void const *argument)
|
||||||
|
@ -107,13 +107,14 @@ int main(void)
|
||||||
|
|
||||||
eth.init(); //Use DHCP
|
eth.init(); //Use DHCP
|
||||||
eth.connect();
|
eth.connect();
|
||||||
printf("Server IP Address is %s:%d\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
printf("MBED: Server IP Address is %s:%d\r\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
||||||
|
|
||||||
Thread UdpServerTask(udp_server_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
Thread UdpServerTask(udp_server_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
||||||
Thread UdpClientTask(udp_client_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
Thread UdpClientTask(udp_client_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
||||||
|
|
||||||
// Control TCP server to get mbed statistics
|
// Control TCP server to get MBED statistics
|
||||||
{
|
{
|
||||||
|
char buffer[BUFFER_SIZE] = {0};
|
||||||
const int TELNET_SERVER_PORT = 23;
|
const int TELNET_SERVER_PORT = 23;
|
||||||
const int BUFFER_SIZE = 256;
|
const int BUFFER_SIZE = 256;
|
||||||
TCPSocketServer server;
|
TCPSocketServer server;
|
||||||
|
@ -121,18 +122,17 @@ int main(void)
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
printf("Wait for new connection...\n");
|
printf("MBED: Wait for new connection...\r\n");
|
||||||
TCPSocketConnection client;
|
TCPSocketConnection client;
|
||||||
server.accept(client);
|
server.accept(client);
|
||||||
client.set_blocking(false, 1500); // Timeout after (1.5)s
|
client.set_blocking(false, 1500); // Timeout after (1.5)s
|
||||||
printf("Connection from: %s\n", client.get_address());
|
printf("MBED: Connection from: %s\r\n", client.get_address());
|
||||||
|
|
||||||
char buffer[BUFFER_SIZE] = { 0 };
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int n = client.receive(buffer, sizeof(buffer));
|
int n = client.receive(buffer, sizeof(buffer));
|
||||||
//if (n <= 0) break;
|
//if (n <= 0) break;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
printf("Recv %d chars\r\n", n);
|
// printf("Recv %d chars\r\n", n);
|
||||||
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE - 1 : n;
|
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE - 1 : n;
|
||||||
buffer[buffer_string_end_index] = '\0';
|
buffer[buffer_string_end_index] = '\0';
|
||||||
// client.send_all(buffer, strlen(buffer));
|
// client.send_all(buffer, strlen(buffer));
|
||||||
|
|
|
@ -3,28 +3,28 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const int ECHO_SERVER_PORT = 7;
|
const int ECHO_SERVER_PORT = 7;
|
||||||
const int BUFFER_SIZE = 256;
|
const int BUFFER_SIZE = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
eth.init(); //Use DHCP
|
eth.init(); //Use DHCP
|
||||||
eth.connect();
|
eth.connect();
|
||||||
printf("Server IP Address is %s:%d\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
printf("MBED: Server IP Address is %s:%d\r\n", eth.getIPAddress(), ECHO_SERVER_PORT);
|
||||||
|
|
||||||
UDPSocket server;
|
UDPSocket server;
|
||||||
server.bind(ECHO_SERVER_PORT);
|
server.bind(ECHO_SERVER_PORT);
|
||||||
|
|
||||||
Endpoint client;
|
Endpoint client;
|
||||||
char buffer[BUFFER_SIZE] = {0};
|
char buffer[BUFFER_SIZE] = {0};
|
||||||
|
printf("MBED: Waiting for packet...\r\n");
|
||||||
while (true) {
|
while (true) {
|
||||||
printf("Wait for packet...\n");
|
|
||||||
int n = server.receiveFrom(client, buffer, sizeof(buffer));
|
int n = server.receiveFrom(client, buffer, sizeof(buffer));
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
printf("Received packet from: %s\n", client.get_address());
|
//printf("Received packet from: %s\n", client.get_address());
|
||||||
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
|
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
|
||||||
buffer[buffer_string_end_index] = '\0';
|
buffer[buffer_string_end_index] = '\0';
|
||||||
printf("Server received: %s\n", buffer);
|
//printf("Server received: %s\n", buffer);
|
||||||
server.sendTo(client, buffer, n);
|
server.sendTo(client, buffer, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
#include "EthernetInterface.h"
|
#include "EthernetInterface.h"
|
||||||
#include "HTTPClient.h"
|
#include "HTTPClient.h"
|
||||||
|
|
||||||
#define BUFFER_SIZE 512
|
|
||||||
|
namespace {
|
||||||
|
const int BUFFER_SIZE = 512;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -27,6 +30,7 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == false) {
|
if (result == false) {
|
||||||
|
eth.disconnect();
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +55,7 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == false) {
|
if (result == false) {
|
||||||
|
eth.disconnect();
|
||||||
notify_completion(false);
|
notify_completion(false);
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from host_test import Test
|
from host_test import Test
|
||||||
|
@ -24,40 +25,35 @@ class EchoTest(Test):
|
||||||
Test.__init__(self)
|
Test.__init__(self)
|
||||||
self.mbed.init_serial(115200)
|
self.mbed.init_serial(115200)
|
||||||
self.mbed.reset()
|
self.mbed.reset()
|
||||||
|
self.TEST_LOOP_COUNT = 50
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
# Let's wait for Mbed to print its readiness, usually "{{start}}"
|
""" Test function, return True or False to get standard test notification on stdout
|
||||||
if self.mbed.serial_timeout(None) is None:
|
"""
|
||||||
self.print_result("ioerr_serial")
|
c = self.mbed.serial_readline() # '{{start}}'
|
||||||
return
|
|
||||||
|
|
||||||
c = self.mbed.serial_read(len('{{start}}'))
|
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
print c
|
print c.strip()
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
if self.mbed.serial_timeout(1) is None:
|
self.mbed.flush()
|
||||||
|
self.notify("HOST: Starting the ECHO test")
|
||||||
|
result = True
|
||||||
|
for i in range(0, self.TEST_LOOP_COUNT):
|
||||||
|
TEST = str(uuid.uuid4()) + "\n"
|
||||||
|
self.mbed.serial_write(TEST)
|
||||||
|
c = self.mbed.serial_readline()
|
||||||
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
|
if c.strip() != TEST.strip():
|
||||||
self.mbed.flush()
|
self.notify('HOST: "%s" != "%s"'% (c, TEST))
|
||||||
self.notify("Starting the ECHO test")
|
result = False
|
||||||
check = True
|
|
||||||
for i in range(1, 100):
|
|
||||||
TEST = str(uuid.uuid4())
|
|
||||||
self.mbed.serial_write(TEST + "\n")
|
|
||||||
l = self.mbed.serial.readline().strip()
|
|
||||||
if not l: continue
|
|
||||||
|
|
||||||
if l != TEST:
|
|
||||||
check = False
|
|
||||||
self.notify('"%s" != "%s"' % (l, TEST))
|
|
||||||
else:
|
else:
|
||||||
if (i % 10) == 0:
|
sys.stdout.write('.')
|
||||||
self.notify(TEST)
|
stdout.flush()
|
||||||
return check
|
return result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -23,21 +23,24 @@ class HelloTest(DefaultTest):
|
||||||
HELLO_WORLD = "Hello World"
|
HELLO_WORLD = "Hello World"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
c = self.mbed.serial_readline()
|
||||||
|
if c is None:
|
||||||
|
self.print_result("ioerr_serial")
|
||||||
|
return
|
||||||
|
print c.strip()
|
||||||
|
stdout.flush()
|
||||||
|
|
||||||
c = self.mbed.serial_readline()
|
c = self.mbed.serial_readline()
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
print "Read %d bytes"% len(c)
|
print "Read %d bytes"% len(c)
|
||||||
print c
|
print c.strip()
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
result = True
|
result = True
|
||||||
# Because we can have targetID here let's try to decode
|
# Because we can have targetID here let's try to decode
|
||||||
if len(c) < len(self.HELLO_WORLD):
|
if len(c) < len(self.HELLO_WORLD):
|
||||||
result = False
|
result = False
|
||||||
elif c[0] == '$':
|
|
||||||
# We are looking for targetID here
|
|
||||||
res = re.search('^[$]+[0-9a-fA-F]+' + self.HELLO_WORLD, c)
|
|
||||||
result = res is not None
|
|
||||||
else:
|
else:
|
||||||
result = self.HELLO_WORLD in c
|
result = self.HELLO_WORLD in c
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import random
|
|
||||||
import re
|
import re
|
||||||
from host_test import DefaultTest
|
import random
|
||||||
from time import time
|
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
from time import time
|
||||||
|
from host_test import DefaultTest
|
||||||
|
|
||||||
class StdioTest(DefaultTest):
|
class StdioTest(DefaultTest):
|
||||||
PATTERN_INT_VALUE = "Your value was: (-?\d+)"
|
PATTERN_INT_VALUE = "Your value was: (-?\d+)"
|
||||||
|
|
|
@ -15,63 +15,73 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from SocketServer import BaseRequestHandler, TCPServer
|
import sys
|
||||||
import socket
|
import socket
|
||||||
from host_test import Test
|
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from host_test import Test
|
||||||
|
from SocketServer import BaseRequestHandler, TCPServer
|
||||||
|
|
||||||
|
|
||||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||||
SERVER_PORT = 7
|
SERVER_PORT = 7
|
||||||
|
|
||||||
|
|
||||||
class TCPEchoClientTest(Test):
|
class TCPEchoClientTest(Test):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Test.__init__(self)
|
Test.__init__(self)
|
||||||
self.mbed.init_serial()
|
self.mbed.init_serial()
|
||||||
|
|
||||||
def send_server_ip_port(self, ip_address, port_no):
|
def send_server_ip_port(self, ip_address, port_no):
|
||||||
print "Resetting target..."
|
""" Set up network host. Reset target and and send server IP via serial to Mbed
|
||||||
|
"""
|
||||||
|
print "HOST: Resetting target..."
|
||||||
self.mbed.reset()
|
self.mbed.reset()
|
||||||
|
|
||||||
# Let's wait for Mbed to print its readiness, usually "{{start}}"
|
c = self.mbed.serial_readline() # 'TCPCllient waiting for server IP and port...'
|
||||||
if self.mbed.serial_timeout(None) is None:
|
|
||||||
self.print_result("ioerr_serial")
|
|
||||||
return
|
|
||||||
|
|
||||||
c = self.mbed.serial_read(len('TCPCllient waiting for server IP and port...'))
|
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
print c
|
|
||||||
stdout.flush()
|
|
||||||
|
|
||||||
if self.mbed.serial_timeout(1) is None:
|
print c.strip()
|
||||||
self.print_result("ioerr_serial")
|
print "HOST: Sending server IP Address to target...",
|
||||||
return
|
|
||||||
|
|
||||||
print "Sending server IP Address to target..."
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
connection_str = ip_address + ":" + str(port_no) + "\n"
|
connection_str = ip_address + ":" + str(port_no) + "\n"
|
||||||
self.mbed.serial_write(connection_str)
|
self.mbed.serial_write(connection_str)
|
||||||
|
print connection_str
|
||||||
|
stdout.flush()
|
||||||
|
|
||||||
|
# Two more strings about connection should be sent by MBED
|
||||||
|
for i in range(0, 2):
|
||||||
|
c = self.mbed.serial_readline()
|
||||||
|
if c is None:
|
||||||
|
self.print_result("ioerr_serial")
|
||||||
|
return
|
||||||
|
print c.strip()
|
||||||
|
stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
class TCPEchoClient_Handler(BaseRequestHandler):
|
class TCPEchoClient_Handler(BaseRequestHandler):
|
||||||
def print_result(self, result):
|
|
||||||
print "\n{%s}\n{end}" % result
|
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
""" One handle per connection """
|
""" One handle per connection """
|
||||||
print "connection received"
|
print "HOST: Connection received...",
|
||||||
|
count = 1;
|
||||||
while True:
|
while True:
|
||||||
data = self.request.recv(1024)
|
data = self.request.recv(1024)
|
||||||
if not data: break
|
if not data: break
|
||||||
self.request.sendall(data)
|
self.request.sendall(data)
|
||||||
print "echo: " + repr(data)
|
if '{{end}}' in str(data):
|
||||||
|
print
|
||||||
|
print str(data)
|
||||||
|
else:
|
||||||
|
if not count % 10:
|
||||||
|
sys.stdout.write('.')
|
||||||
|
count += 1
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
server = TCPServer((SERVER_IP, SERVER_PORT), TCPEchoClient_Handler)
|
server = TCPServer((SERVER_IP, SERVER_PORT), TCPEchoClient_Handler)
|
||||||
print "listening for connections: " + SERVER_IP + ":" + str(SERVER_PORT)
|
print "HOST: Listening for connections: " + SERVER_IP + ":" + str(SERVER_PORT)
|
||||||
|
|
||||||
mbed_test = TCPEchoClientTest();
|
mbed_test = TCPEchoClientTest();
|
||||||
mbed_test.send_server_ip_port(SERVER_IP, SERVER_PORT)
|
mbed_test.send_server_ip_port(SERVER_IP, SERVER_PORT)
|
||||||
|
|
|
@ -15,67 +15,74 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import socket
|
|
||||||
import re
|
import re
|
||||||
from host_test import DefaultTest
|
import sys
|
||||||
from time import time
|
import uuid
|
||||||
|
import socket
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
from time import time
|
||||||
|
from host_test import DefaultTest
|
||||||
|
|
||||||
class TCPEchoServerTest(DefaultTest):
|
class TCPEchoServerTest(DefaultTest):
|
||||||
ECHO_SERVER_ADDRESS = ""
|
ECHO_SERVER_ADDRESS = ""
|
||||||
ECHO_PORT = 0
|
ECHO_PORT = 0
|
||||||
|
ECHO_LOOPs = 100
|
||||||
s = None # Socket
|
s = None # Socket
|
||||||
|
|
||||||
PATTERN_SERVER_IP = "^Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
PATTERN_SERVER_IP = "Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
||||||
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
ip_msg_timeout = self.mbed.options.timeout
|
result = False
|
||||||
serial_ip_msg = ""
|
c = self.mbed.serial_readline()
|
||||||
start_serial_pool = time();
|
|
||||||
while (time() - start_serial_pool) < ip_msg_timeout:
|
|
||||||
c = self.mbed.serial_read(512)
|
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
stdout.write(c)
|
print c
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
serial_ip_msg += c
|
|
||||||
# Searching for IP address and port prompted by server
|
m = self.re_detect_server_ip.search(c)
|
||||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
|
||||||
if m and len(m.groups()):
|
if m and len(m.groups()):
|
||||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||||
duration = time() - start_serial_pool
|
print "HOST: TCP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT)
|
||||||
print "TCP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
break
|
|
||||||
else:
|
|
||||||
print "Error: No IP and port information sent from server"
|
|
||||||
self.print_result('error')
|
|
||||||
exit(-2)
|
|
||||||
|
|
||||||
# We assume this test fails so can't send 'error' message to server
|
# We assume this test fails so can't send 'error' message to server
|
||||||
try:
|
try:
|
||||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "Error: %s" % e
|
print "HOST: Error: %s" % e
|
||||||
self.print_result('error')
|
self.print_result('error')
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
TEST_STRING = 'Hello, world !!!'
|
print 'HOST: Sending %d echo strings...'% self.ECHO_LOOPs,
|
||||||
|
for i in range(0, self.ECHO_LOOPs):
|
||||||
|
TEST_STRING = str(uuid.uuid4())
|
||||||
self.s.sendall(TEST_STRING)
|
self.s.sendall(TEST_STRING)
|
||||||
|
data = self.s.recv(128)
|
||||||
data = self.s.recv(1024)
|
|
||||||
received_str = repr(data)[1:-1]
|
received_str = repr(data)[1:-1]
|
||||||
|
|
||||||
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
||||||
print 'Received data: ' + received_str
|
sys.stdout.write('.')
|
||||||
|
stdout.flush()
|
||||||
|
result = True
|
||||||
|
else:
|
||||||
|
print "Expected: "
|
||||||
|
print "'%s'"% TEST_STRING
|
||||||
|
print "received: "
|
||||||
|
print "'%s'"% received_str
|
||||||
|
result = False
|
||||||
|
break
|
||||||
|
self.s.close()
|
||||||
|
else:
|
||||||
|
print "HOST: TCP Server not found"
|
||||||
|
result = False
|
||||||
|
|
||||||
|
if result:
|
||||||
self.print_result('success')
|
self.print_result('success')
|
||||||
else:
|
else:
|
||||||
self.print_result('failure')
|
self.print_result('failure')
|
||||||
self.s.close()
|
|
||||||
|
|
||||||
# Receiving
|
# Receiving
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -21,13 +21,14 @@ make.py -m LPC1768 -t ARM -d E:\ -n NET_14
|
||||||
udp_link_layer_auto.py -p COM20 -d E:\ -t 10
|
udp_link_layer_auto.py -p COM20 -d E:\ -t 10
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import thread
|
|
||||||
from SocketServer import BaseRequestHandler, UDPServer
|
|
||||||
import socket
|
|
||||||
import re
|
import re
|
||||||
from host_test import DefaultTest
|
import uuid
|
||||||
from time import time, sleep
|
import socket
|
||||||
|
import thread
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
from time import time, sleep
|
||||||
|
from host_test import DefaultTest
|
||||||
|
from SocketServer import BaseRequestHandler, UDPServer
|
||||||
|
|
||||||
|
|
||||||
# Received datagrams (with time)
|
# Received datagrams (with time)
|
||||||
|
@ -39,7 +40,8 @@ dict_udp_sent_datagrams = dict()
|
||||||
|
|
||||||
class UDPEchoClient_Handler(BaseRequestHandler):
|
class UDPEchoClient_Handler(BaseRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
""" One handle per connection """
|
""" One handle per connection
|
||||||
|
"""
|
||||||
_data, _socket = self.request
|
_data, _socket = self.request
|
||||||
# Process received datagram
|
# Process received datagram
|
||||||
data_str = repr(_data)[1:-1]
|
data_str = repr(_data)[1:-1]
|
||||||
|
@ -47,7 +49,8 @@ class UDPEchoClient_Handler(BaseRequestHandler):
|
||||||
|
|
||||||
|
|
||||||
def udp_packet_recv(threadName, server_ip, server_port):
|
def udp_packet_recv(threadName, server_ip, server_port):
|
||||||
""" This function will receive packet stream from mbed device """
|
""" This function will receive packet stream from mbed device
|
||||||
|
"""
|
||||||
server = UDPServer((server_ip, server_port), UDPEchoClient_Handler)
|
server = UDPServer((server_ip, server_port), UDPEchoClient_Handler)
|
||||||
print "[UDP_COUNTER] Listening for connections... %s:%d"% (server_ip, server_port)
|
print "[UDP_COUNTER] Listening for connections... %s:%d"% (server_ip, server_port)
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
@ -61,8 +64,9 @@ class UDPEchoServerTest(DefaultTest):
|
||||||
|
|
||||||
TEST_PACKET_COUNT = 1000 # how many packets should be send
|
TEST_PACKET_COUNT = 1000 # how many packets should be send
|
||||||
TEST_STRESS_FACTOR = 0.001 # stress factor: 10 ms
|
TEST_STRESS_FACTOR = 0.001 # stress factor: 10 ms
|
||||||
|
PACKET_SATURATION_RATIO = 29.9 # Acceptable packet transmission in %
|
||||||
|
|
||||||
PATTERN_SERVER_IP = "^Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
PATTERN_SERVER_IP = "Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
||||||
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
||||||
|
|
||||||
def get_control_data(self, command="stat\n"):
|
def get_control_data(self, command="stat\n"):
|
||||||
|
@ -75,38 +79,27 @@ class UDPEchoServerTest(DefaultTest):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
ip_msg_timeout = self.mbed.options.timeout
|
serial_ip_msg = self.mbed.serial_readline()
|
||||||
serial_ip_msg = ""
|
if serial_ip_msg is None:
|
||||||
start_serial_pool = time()
|
|
||||||
while (time() - start_serial_pool) < ip_msg_timeout:
|
|
||||||
c = self.mbed.serial_read(512)
|
|
||||||
if c is None:
|
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
stdout.write(c)
|
stdout.write(serial_ip_msg)
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
serial_ip_msg += c
|
|
||||||
# Searching for IP address and port prompted by server
|
# Searching for IP address and port prompted by server
|
||||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||||
if m and len(m.groups()):
|
if m and len(m.groups()):
|
||||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||||
duration = time() - start_serial_pool
|
print "HOST: UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT)
|
||||||
print "UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
break
|
|
||||||
else:
|
|
||||||
print "Error: No IP and port information sent from server"
|
|
||||||
self.print_result('error')
|
|
||||||
exit(-2)
|
|
||||||
|
|
||||||
# Open client socket to burst datagrams to UDP server in mbed
|
# Open client socket to burst datagrams to UDP server in mbed
|
||||||
try:
|
try:
|
||||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "Error: %s" % e
|
print "HOST: Error: %s" % e
|
||||||
self.print_result('error')
|
self.print_result('error')
|
||||||
exit(-1)
|
return
|
||||||
|
|
||||||
# UDP replied receiver works in background to get echoed datagrams
|
# UDP replied receiver works in background to get echoed datagrams
|
||||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||||
|
@ -115,8 +108,8 @@ class UDPEchoServerTest(DefaultTest):
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
|
|
||||||
# Burst part
|
# Burst part
|
||||||
TEST_STRING = 'Hello, world !!!'
|
|
||||||
for no in range(self.TEST_PACKET_COUNT):
|
for no in range(self.TEST_PACKET_COUNT):
|
||||||
|
TEST_STRING = str(uuid.uuid4())
|
||||||
payload = str(no) + "__" + TEST_STRING
|
payload = str(no) + "__" + TEST_STRING
|
||||||
self.s.sendto(payload, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
self.s.sendto(payload, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||||
dict_udp_sent_datagrams[payload] = time()
|
dict_udp_sent_datagrams[payload] = time()
|
||||||
|
@ -124,26 +117,33 @@ class UDPEchoServerTest(DefaultTest):
|
||||||
self.s.close()
|
self.s.close()
|
||||||
|
|
||||||
# Wait 5 seconds for packets to come
|
# Wait 5 seconds for packets to come
|
||||||
|
result = True
|
||||||
print
|
print
|
||||||
print "Test Summary:"
|
print "HOST: Test Summary:"
|
||||||
for d in range(5):
|
for d in range(5):
|
||||||
sleep(1)
|
sleep(1.0)
|
||||||
summary_datagram_success = (float(len(dict_udp_recv_datagrams)) / float(self.TEST_PACKET_COUNT)) * 100.0
|
summary_datagram_success = (float(len(dict_udp_recv_datagrams)) / float(self.TEST_PACKET_COUNT)) * 100.0
|
||||||
# print dict_udp_recv_datagrams
|
# print dict_udp_recv_datagrams
|
||||||
print "Datagrams received after +%d sec: %.3f%% (%d / %d), stress=%.3f ms" % (d, summary_datagram_success, len(dict_udp_recv_datagrams), self.TEST_PACKET_COUNT, self.TEST_STRESS_FACTOR)
|
print "HOST: Datagrams received after +%d sec: %.3f%% (%d / %d), stress=%.3f ms" % (d, summary_datagram_success, len(dict_udp_recv_datagrams), self.TEST_PACKET_COUNT, self.TEST_STRESS_FACTOR)
|
||||||
|
result = result and (summary_datagram_success >= self.PACKET_SATURATION_RATIO)
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
# Getting control data from test
|
# Getting control data from test
|
||||||
print
|
print
|
||||||
print "Mbed Summary:"
|
print "HOST: Mbed Summary:"
|
||||||
mbed_stats = self.get_control_data()
|
mbed_stats = self.get_control_data()
|
||||||
print mbed_stats
|
print mbed_stats
|
||||||
print
|
print
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
|
if result:
|
||||||
|
self.print_result('success')
|
||||||
|
else:
|
||||||
|
self.print_result('failure')
|
||||||
|
|
||||||
# Receiving serial data from mbed
|
# Receiving serial data from mbed
|
||||||
print
|
print
|
||||||
print "Remaining mbed serial port data:"
|
print "HOST: Remaining mbed serial port data:"
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
c = self.mbed.serial_read(512)
|
c = self.mbed.serial_read(512)
|
||||||
|
|
|
@ -14,60 +14,61 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
from SocketServer import BaseRequestHandler, UDPServer
|
|
||||||
from host_test import Test
|
import sys
|
||||||
import socket
|
import socket
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
from host_test import Test
|
||||||
|
from SocketServer import BaseRequestHandler, UDPServer
|
||||||
|
|
||||||
|
|
||||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||||
SERVER_PORT = 7
|
SERVER_PORT = 7
|
||||||
|
|
||||||
|
|
||||||
class UDPEchoClientTest(Test):
|
class UDPEchoClientTest(Test):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Test.__init__(self)
|
Test.__init__(self)
|
||||||
self.mbed.init_serial()
|
self.mbed.init_serial()
|
||||||
|
|
||||||
def send_server_ip_port(self, ip_address, port_no):
|
def send_server_ip_port(self, ip_address, port_no):
|
||||||
print "Resetting target..."
|
print "HOST: Resetting target..."
|
||||||
self.mbed.reset()
|
self.mbed.reset()
|
||||||
|
|
||||||
# Let's wait for Mbed to print its readiness, usually "{{start}}"
|
c = self.mbed.serial_readline() # 'UDPCllient waiting for server IP and port...'
|
||||||
if self.mbed.serial_timeout(None) is None:
|
|
||||||
self.print_result("ioerr_serial")
|
|
||||||
return
|
|
||||||
|
|
||||||
c = self.mbed.serial_read(len('UDPCllient waiting for server IP and port...'))
|
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
print c
|
print c.strip()
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
if self.mbed.serial_timeout(1) is None:
|
print "HOST: Sending server IP Address to target..."
|
||||||
self.print_result("ioerr_serial")
|
|
||||||
return
|
|
||||||
|
|
||||||
print "Sending server IP Address to target..."
|
|
||||||
connection_str = ip_address + ":" + str(port_no) + "\n"
|
connection_str = ip_address + ":" + str(port_no) + "\n"
|
||||||
self.mbed.serial_write(connection_str)
|
self.mbed.serial_write(connection_str)
|
||||||
|
|
||||||
|
c = self.mbed.serial_readline() # 'UDPCllient waiting for server IP and port...'
|
||||||
|
if c is None:
|
||||||
|
self.print_result("ioerr_serial")
|
||||||
|
return
|
||||||
|
print c.strip()
|
||||||
|
stdout.flush()
|
||||||
|
|
||||||
class UDPEchoClient_Handler(BaseRequestHandler):
|
class UDPEchoClient_Handler(BaseRequestHandler):
|
||||||
def print_result(self, result):
|
|
||||||
print "\n{%s}\n{end}" % result
|
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
""" One handle per connection """
|
""" One handle per connection
|
||||||
print "connection received"
|
"""
|
||||||
data, socket = self.request
|
data, socket = self.request
|
||||||
print "client: ", self.client_address
|
|
||||||
print "data: ", data
|
|
||||||
socket.sendto(data, self.client_address)
|
socket.sendto(data, self.client_address)
|
||||||
|
if '{{end}}' in data:
|
||||||
|
print
|
||||||
|
print data
|
||||||
|
else:
|
||||||
|
sys.stdout.write('.')
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
server = UDPServer((SERVER_IP, SERVER_PORT), UDPEchoClient_Handler)
|
server = UDPServer((SERVER_IP, SERVER_PORT), UDPEchoClient_Handler)
|
||||||
print "listening for connections"
|
print "HOST: Listening for connections..."
|
||||||
|
|
||||||
mbed_test = UDPEchoClientTest();
|
mbed_test = UDPEchoClientTest();
|
||||||
mbed_test.send_server_ip_port(SERVER_IP, SERVER_PORT)
|
mbed_test.send_server_ip_port(SERVER_IP, SERVER_PORT)
|
||||||
|
|
|
@ -15,66 +15,66 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from socket import socket, AF_INET, SOCK_DGRAM
|
|
||||||
import re
|
import re
|
||||||
from host_test import DefaultTest
|
import sys
|
||||||
from time import time
|
import uuid
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
from time import time
|
||||||
|
from host_test import DefaultTest
|
||||||
|
from socket import socket, AF_INET, SOCK_DGRAM
|
||||||
|
|
||||||
|
|
||||||
class UDPEchoServerTest(DefaultTest):
|
class UDPEchoServerTest(DefaultTest):
|
||||||
ECHO_SERVER_ADDRESS = ""
|
ECHO_SERVER_ADDRESS = ""
|
||||||
ECHO_PORT = 0
|
ECHO_PORT = 0
|
||||||
s = None # Socket
|
s = None # Socket
|
||||||
|
|
||||||
PATTERN_SERVER_IP = "^Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
PATTERN_SERVER_IP = "Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
||||||
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
ip_msg_timeout = self.mbed.options.timeout
|
result = True
|
||||||
serial_ip_msg = ""
|
serial_ip_msg = self.mbed.serial_readline()
|
||||||
start_serial_pool = time();
|
if serial_ip_msg is None:
|
||||||
while (time() - start_serial_pool) < ip_msg_timeout:
|
|
||||||
c = self.mbed.serial_read(512)
|
|
||||||
if c is None:
|
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
stdout.write(c)
|
stdout.write(serial_ip_msg)
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
serial_ip_msg += c
|
|
||||||
# Searching for IP address and port prompted by server
|
# Searching for IP address and port prompted by server
|
||||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||||
if m and len(m.groups()):
|
if m and len(m.groups()):
|
||||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||||
duration = time() - start_serial_pool
|
print "HOST: UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT)
|
||||||
print "UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
break
|
|
||||||
else:
|
|
||||||
print "Error: No IP and port information sent from server"
|
|
||||||
self.print_result('error')
|
|
||||||
exit(-2)
|
|
||||||
|
|
||||||
# We assume this test fails so can't send 'error' message to server
|
# We assume this test fails so can't send 'error' message to server
|
||||||
try:
|
try:
|
||||||
self.s = socket(AF_INET, SOCK_DGRAM)
|
self.s = socket(AF_INET, SOCK_DGRAM)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "Error: %s" % e
|
print "HOST: Error: %s" % e
|
||||||
self.print_result('error')
|
self.print_result('error')
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
TEST_STRING = 'Hello, world !!!'
|
for i in range(0, 100):
|
||||||
|
TEST_STRING = str(uuid.uuid4())
|
||||||
self.s.sendto(TEST_STRING, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
self.s.sendto(TEST_STRING, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||||
|
|
||||||
data = self.s.recv(len(TEST_STRING))
|
data = self.s.recv(len(TEST_STRING))
|
||||||
received_str = repr(data)[1:-1]
|
received_str = repr(data)[1:-1]
|
||||||
|
if TEST_STRING != received_str:
|
||||||
|
result = False
|
||||||
|
break
|
||||||
|
sys.stdout.write('.')
|
||||||
|
stdout.flush()
|
||||||
|
else:
|
||||||
|
result = False
|
||||||
|
|
||||||
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
self.s.close()
|
||||||
print 'Received data: ' + received_str
|
if result:
|
||||||
self.print_result('success')
|
self.print_result('success')
|
||||||
else:
|
else:
|
||||||
self.print_result('failure')
|
self.print_result('failure')
|
||||||
self.s.close()
|
|
||||||
|
|
||||||
# Receiving
|
# Receiving
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -50,6 +50,10 @@ class WaitusTest(DefaultTest):
|
||||||
if i > 2: # we will ignore first few measurements
|
if i > 2: # we will ignore first few measurements
|
||||||
delta = time() - start
|
delta = time() - start
|
||||||
deviation = abs(delta - 1)
|
deviation = abs(delta - 1)
|
||||||
|
# Round values
|
||||||
|
delta = round(delta, 2)
|
||||||
|
deviation = round(deviation, 2)
|
||||||
|
# Check if time measurements are in given range
|
||||||
deviation_ok = True if delta > 0 and deviation <= 0.10 else False # +/-10%
|
deviation_ok = True if delta > 0 and deviation <= 0.10 else False # +/-10%
|
||||||
test_result = test_result and deviation_ok
|
test_result = test_result and deviation_ok
|
||||||
msg = "OK" if deviation_ok else "FAIL"
|
msg = "OK" if deviation_ok else "FAIL"
|
||||||
|
|
|
@ -88,7 +88,7 @@ def get_version():
|
||||||
""" Returns test script version
|
""" Returns test script version
|
||||||
"""
|
"""
|
||||||
single_test_version_major = 1
|
single_test_version_major = 1
|
||||||
single_test_version_minor = 2
|
single_test_version_minor = 3
|
||||||
return (single_test_version_major, single_test_version_minor)
|
return (single_test_version_major, single_test_version_minor)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -664,7 +664,7 @@ TESTS = [
|
||||||
{
|
{
|
||||||
"id": "NET_4", "description": "TCP echo client",
|
"id": "NET_4", "description": "TCP echo client",
|
||||||
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client"),
|
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client"),
|
||||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
|
||||||
"automated": True,
|
"automated": True,
|
||||||
"host_test": "tcpecho_client_auto",
|
"host_test": "tcpecho_client_auto",
|
||||||
"peripherals": ["ethernet"]
|
"peripherals": ["ethernet"]
|
||||||
|
@ -680,7 +680,7 @@ TESTS = [
|
||||||
{
|
{
|
||||||
"id": "NET_6", "description": "UDP echo client",
|
"id": "NET_6", "description": "UDP echo client",
|
||||||
"source_dir": join(TEST_DIR, "net", "echo", "udp_client"),
|
"source_dir": join(TEST_DIR, "net", "echo", "udp_client"),
|
||||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
|
||||||
"automated": True,
|
"automated": True,
|
||||||
"host_test" : "udpecho_client_auto",
|
"host_test" : "udpecho_client_auto",
|
||||||
"peripherals": ["ethernet"],
|
"peripherals": ["ethernet"],
|
||||||
|
@ -738,8 +738,8 @@ TESTS = [
|
||||||
"source_dir": join(TEST_DIR, "net", "echo", "udp_link_layer"),
|
"source_dir": join(TEST_DIR, "net", "echo", "udp_link_layer"),
|
||||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
||||||
"automated": False,
|
"automated": False,
|
||||||
"duration": 15,
|
"duration": 20,
|
||||||
"host_test": "udp_link_layer_auto.py",
|
"host_test": "udp_link_layer_auto",
|
||||||
"peripherals": ["ethernet"],
|
"peripherals": ["ethernet"],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue