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 "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 RXPIN USBRX
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
const int BUFFER_SIZE = 48;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char buf[256];
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
|
||||
Serial pc(TXPIN, RXPIN);
|
||||
pc.baud(115200);
|
||||
|
@ -28,7 +20,7 @@ int main() {
|
|||
pc.puts("}}");
|
||||
|
||||
while (1) {
|
||||
pc.gets(buf, 256);
|
||||
pc.printf("%s", buf);
|
||||
pc.gets(buffer, BUFFER_SIZE - 1);
|
||||
pc.printf("%s", buffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ const char* TEST_ENV_FAILURE = "failure";
|
|||
const char* TEST_ENV_MEASURE = "measure";
|
||||
const char* TEST_ENV_END = "end";
|
||||
|
||||
|
||||
static void led_blink(PinName led, float delay)
|
||||
{
|
||||
if (led != NC) {
|
||||
|
@ -41,11 +42,20 @@ void notify_performance_coefficient(const char* measurement_name, const double v
|
|||
|
||||
void notify_completion(bool success)
|
||||
{
|
||||
printf("{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE);
|
||||
printf("{{%s}}" NL, TEST_ENV_END);
|
||||
printf("{{%s}}" NL "{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE, TEST_ENV_END);
|
||||
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
|
||||
unsigned int testenv_randseed()
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ extern const char* TEST_ENV_END;
|
|||
// Test result related notification functions
|
||||
void notify_start();
|
||||
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 unsigned int value);
|
||||
void notify_performance_coefficient(const char* measurement_name, const double value);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
notify_start();
|
||||
printf("Hello World\r\n");
|
||||
while(1);
|
||||
}
|
||||
|
|
|
@ -1,40 +1,47 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include <algorithm>
|
||||
|
||||
struct s_ip_address
|
||||
{
|
||||
int ip_1;
|
||||
int ip_2;
|
||||
int ip_3;
|
||||
int ip_4;
|
||||
};
|
||||
namespace {
|
||||
const int BUFFER_SIZE = 64;
|
||||
const int MAX_ECHO_LOOPS = 1000;
|
||||
const char ASCII_MAX = '~' - ' ';
|
||||
|
||||
#define MAX_ECHO_LOOPS 100
|
||||
struct s_ip_address
|
||||
{
|
||||
int ip_1;
|
||||
int ip_2;
|
||||
int ip_3;
|
||||
int ip_4;
|
||||
};
|
||||
}
|
||||
|
||||
char char_rand() {
|
||||
return (rand() % ASCII_MAX) + ' ';
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
char buffer[256] = {0};
|
||||
char out_buffer[] = "Hello World\n";
|
||||
char out_success[] = "{{success}}\n{{end}}\n";
|
||||
char out_failure[] = "{{failure}}\n{{end}}\n";
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
char out_buffer[BUFFER_SIZE] = {0};
|
||||
s_ip_address ip_addr = {0, 0, 0, 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);
|
||||
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;
|
||||
eth.init(); //Use DHCP
|
||||
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);
|
||||
|
||||
TCPSocketConnection socket;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -42,14 +49,13 @@ int main() {
|
|||
bool result = true;
|
||||
int count_error = 0;
|
||||
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)
|
||||
{
|
||||
buffer[n] = '\0';
|
||||
printf("%s", buffer);
|
||||
bool echoed = strncmp(out_buffer, buffer, sizeof(out_buffer) - 1) == 0;
|
||||
bool echoed = memcmp(out_buffer, buffer, BUFFER_SIZE) == 0;
|
||||
result = result && echoed;
|
||||
if (echoed == false) {
|
||||
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) {
|
||||
socket.send_all(out_success, sizeof(out_success) - 1);
|
||||
}
|
||||
else {
|
||||
socket.send_all(out_failure, sizeof(out_failure) - 1);
|
||||
if (notify_completion_str(result, buffer)) {
|
||||
socket.send_all(buffer, strlen(buffer));
|
||||
}
|
||||
socket.close();
|
||||
eth.disconnect();
|
||||
notify_completion(result);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,35 +3,38 @@
|
|||
|
||||
namespace {
|
||||
const int ECHO_SERVER_PORT = 7;
|
||||
const int BUFFER_SIZE = 256;
|
||||
const int BUFFER_SIZE = 64;
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
EthernetInterface eth;
|
||||
eth.init(); //Use DHCP
|
||||
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;
|
||||
server.bind(ECHO_SERVER_PORT);
|
||||
server.listen();
|
||||
|
||||
while (true) {
|
||||
printf("Wait for new connection...\n");
|
||||
printf("MBED: Wait for new connection...\n");
|
||||
TCPSocketConnection client;
|
||||
server.accept(client);
|
||||
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) {
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
int n = client.receive(buffer, sizeof(buffer));
|
||||
if (n <= 0) break;
|
||||
const int n = client.receive(buffer, sizeof(buffer));
|
||||
if (n <= 0) {
|
||||
break;
|
||||
}
|
||||
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
|
||||
buffer[buffer_string_end_index] = '\0';
|
||||
printf("Server received: %s\n", buffer);
|
||||
client.send_all(buffer, n);
|
||||
if (n <= 0) break;
|
||||
if (n <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
|
|
|
@ -1,28 +1,40 @@
|
|||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
#include "test_env.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
|
||||
{
|
||||
int ip_1;
|
||||
int ip_2;
|
||||
int ip_3;
|
||||
int ip_4;
|
||||
};
|
||||
}
|
||||
|
||||
char char_rand() {
|
||||
return (rand() % ASCII_MAX) + ' ';
|
||||
}
|
||||
|
||||
struct s_ip_address
|
||||
{
|
||||
int ip_1;
|
||||
int ip_2;
|
||||
int ip_3;
|
||||
int ip_4;
|
||||
};
|
||||
|
||||
int main() {
|
||||
char buffer[256] = {0};
|
||||
char out_buffer[] = "Hello World\n";
|
||||
char out_success[] = "{{success}}\n{{end}}\n";
|
||||
char out_failure[] = "{{failure}}\n{{end}}\n";
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
char out_buffer[BUFFER_SIZE] = {0};
|
||||
s_ip_address ip_addr = {0, 0, 0, 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);
|
||||
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;
|
||||
int rc = eth.init(); //Use DHCP
|
||||
|
@ -36,30 +48,33 @@ int main() {
|
|||
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);
|
||||
|
||||
Endpoint echo_server;
|
||||
rc = echo_server.set_address(buffer, port);
|
||||
CHECK(rc, "set_address");
|
||||
|
||||
rc = socket.sendTo(echo_server, out_buffer, sizeof(out_buffer));
|
||||
CHECK(rc, "sendTo");
|
||||
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));
|
||||
CHECK(rc, "sendTo");
|
||||
|
||||
int n = socket.receiveFrom(echo_server, buffer, sizeof(buffer));
|
||||
CHECK(n, "receiveFrom");
|
||||
if (n > 0)
|
||||
{
|
||||
buffer[n] = '\0';
|
||||
printf("%s", buffer);
|
||||
if (strncmp(out_buffer, buffer, sizeof(out_buffer) - 1) == 0) {
|
||||
socket.sendTo(echo_server, out_success, sizeof(out_success) - 1);
|
||||
const int n = socket.receiveFrom(echo_server, buffer, sizeof(buffer));
|
||||
CHECK(n, "receiveFrom");
|
||||
|
||||
if (memcmp(buffer, out_buffer, BUFFER_SIZE) != 0) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
eth.disconnect();
|
||||
notify_completion(result);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -12,24 +12,24 @@
|
|||
|
||||
// Evil globals
|
||||
namespace {
|
||||
Mutex cli_serv_mutex;
|
||||
// cli_serv_mutex.lock(); // LOCK
|
||||
// cli_serv_mutex.unlock(); // LOCK
|
||||
// IP and port used to store HOST address info
|
||||
char host_address[32] = {0};
|
||||
volatile int host_port = 0;
|
||||
|
||||
const int ECHO_SERVER_PORT = 7;
|
||||
const int BUFFER_SIZE = 256;
|
||||
const int ECHO_SERVER_PORT = 7;
|
||||
const int BUFFER_SIZE = 64;
|
||||
|
||||
// Forwarding packet queue
|
||||
std::list<std::string> datagram_queue;
|
||||
// Forwarding packet queue
|
||||
std::list<std::string> datagram_queue;
|
||||
|
||||
// IP and port used to store HOST address info
|
||||
char host_address[32] = { 0 };
|
||||
volatile int host_port = 0;
|
||||
// Statistics (mbed)
|
||||
volatile int received_packets = 0;
|
||||
volatile int forwarded_packets = 0;
|
||||
volatile int max_queue_len = 0;
|
||||
|
||||
// Statistics (mbed)
|
||||
volatile int received_packets = 0;
|
||||
volatile int forwarded_packets = 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)
|
||||
|
@ -107,13 +107,14 @@ int main(void)
|
|||
|
||||
eth.init(); //Use DHCP
|
||||
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 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 BUFFER_SIZE = 256;
|
||||
TCPSocketServer server;
|
||||
|
@ -121,18 +122,17 @@ int main(void)
|
|||
server.listen();
|
||||
|
||||
while (true) {
|
||||
printf("Wait for new connection...\n");
|
||||
printf("MBED: Wait for new connection...\r\n");
|
||||
TCPSocketConnection client;
|
||||
server.accept(client);
|
||||
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) {
|
||||
int n = client.receive(buffer, sizeof(buffer));
|
||||
//if (n <= 0) break;
|
||||
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;
|
||||
buffer[buffer_string_end_index] = '\0';
|
||||
// client.send_all(buffer, strlen(buffer));
|
||||
|
|
|
@ -3,28 +3,28 @@
|
|||
|
||||
namespace {
|
||||
const int ECHO_SERVER_PORT = 7;
|
||||
const int BUFFER_SIZE = 256;
|
||||
const int BUFFER_SIZE = 64;
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
EthernetInterface eth;
|
||||
eth.init(); //Use DHCP
|
||||
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;
|
||||
server.bind(ECHO_SERVER_PORT);
|
||||
|
||||
Endpoint client;
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
printf("MBED: Waiting for packet...\r\n");
|
||||
while (true) {
|
||||
printf("Wait for packet...\n");
|
||||
int n = server.receiveFrom(client, buffer, sizeof(buffer));
|
||||
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;
|
||||
buffer[buffer_string_end_index] = '\0';
|
||||
printf("Server received: %s\n", buffer);
|
||||
//printf("Server received: %s\n", buffer);
|
||||
server.sendTo(client, buffer, n);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
#include "EthernetInterface.h"
|
||||
#include "HTTPClient.h"
|
||||
|
||||
#define BUFFER_SIZE 512
|
||||
|
||||
namespace {
|
||||
const int BUFFER_SIZE = 512;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -27,6 +30,7 @@ int main()
|
|||
}
|
||||
|
||||
if (result == false) {
|
||||
eth.disconnect();
|
||||
notify_completion(false);
|
||||
exit(ret);
|
||||
}
|
||||
|
@ -51,6 +55,7 @@ int main()
|
|||
}
|
||||
|
||||
if (result == false) {
|
||||
eth.disconnect();
|
||||
notify_completion(false);
|
||||
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
|
||||
limitations under the License.
|
||||
"""
|
||||
import sys
|
||||
import uuid
|
||||
from sys import stdout
|
||||
from host_test import Test
|
||||
|
@ -24,40 +25,35 @@ class EchoTest(Test):
|
|||
Test.__init__(self)
|
||||
self.mbed.init_serial(115200)
|
||||
self.mbed.reset()
|
||||
self.TEST_LOOP_COUNT = 50
|
||||
|
||||
def test(self):
|
||||
# Let's wait for Mbed to print its readiness, usually "{{start}}"
|
||||
if self.mbed.serial_timeout(None) is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
|
||||
c = self.mbed.serial_read(len('{{start}}'))
|
||||
""" Test function, return True or False to get standard test notification on stdout
|
||||
"""
|
||||
c = self.mbed.serial_readline() # '{{start}}'
|
||||
if c is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
print c
|
||||
print c.strip()
|
||||
stdout.flush()
|
||||
|
||||
if self.mbed.serial_timeout(1) is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
|
||||
self.mbed.flush()
|
||||
self.notify("Starting the ECHO test")
|
||||
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))
|
||||
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")
|
||||
return
|
||||
if c.strip() != TEST.strip():
|
||||
self.notify('HOST: "%s" != "%s"'% (c, TEST))
|
||||
result = False
|
||||
else:
|
||||
if (i % 10) == 0:
|
||||
self.notify(TEST)
|
||||
return check
|
||||
sys.stdout.write('.')
|
||||
stdout.flush()
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -23,21 +23,24 @@ class HelloTest(DefaultTest):
|
|||
HELLO_WORLD = "Hello World"
|
||||
|
||||
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()
|
||||
if c is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
print "Read %d bytes"% len(c)
|
||||
print c
|
||||
print c.strip()
|
||||
stdout.flush()
|
||||
result = True
|
||||
# Because we can have targetID here let's try to decode
|
||||
if len(c) < len(self.HELLO_WORLD):
|
||||
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:
|
||||
result = self.HELLO_WORLD in c
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
"""
|
||||
|
||||
import random
|
||||
import re
|
||||
from host_test import DefaultTest
|
||||
from time import time
|
||||
import random
|
||||
from sys import stdout
|
||||
from time import time
|
||||
from host_test import DefaultTest
|
||||
|
||||
class StdioTest(DefaultTest):
|
||||
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.
|
||||
"""
|
||||
|
||||
from SocketServer import BaseRequestHandler, TCPServer
|
||||
import sys
|
||||
import socket
|
||||
from host_test import Test
|
||||
from sys import stdout
|
||||
from time import sleep
|
||||
from host_test import Test
|
||||
from SocketServer import BaseRequestHandler, TCPServer
|
||||
|
||||
|
||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||
SERVER_PORT = 7
|
||||
|
||||
|
||||
class TCPEchoClientTest(Test):
|
||||
def __init__(self):
|
||||
Test.__init__(self)
|
||||
self.mbed.init_serial()
|
||||
|
||||
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()
|
||||
|
||||
# Let's wait for Mbed to print its readiness, usually "{{start}}"
|
||||
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...'))
|
||||
c = self.mbed.serial_readline() # 'TCPCllient waiting for server IP and port...'
|
||||
if c is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
print c
|
||||
stdout.flush()
|
||||
|
||||
if self.mbed.serial_timeout(1) is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
|
||||
print "Sending server IP Address to target..."
|
||||
print c.strip()
|
||||
print "HOST: Sending server IP Address to target...",
|
||||
stdout.flush()
|
||||
connection_str = ip_address + ":" + str(port_no) + "\n"
|
||||
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):
|
||||
def print_result(self, result):
|
||||
print "\n{%s}\n{end}" % result
|
||||
|
||||
def handle(self):
|
||||
""" One handle per connection """
|
||||
print "connection received"
|
||||
print "HOST: Connection received...",
|
||||
count = 1;
|
||||
while True:
|
||||
data = self.request.recv(1024)
|
||||
if not data: break
|
||||
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()
|
||||
|
||||
|
||||
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.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.
|
||||
"""
|
||||
|
||||
import socket
|
||||
import re
|
||||
from host_test import DefaultTest
|
||||
from time import time
|
||||
import sys
|
||||
import uuid
|
||||
import socket
|
||||
from sys import stdout
|
||||
from time import time
|
||||
from host_test import DefaultTest
|
||||
|
||||
class TCPEchoServerTest(DefaultTest):
|
||||
ECHO_SERVER_ADDRESS = ""
|
||||
ECHO_PORT = 0
|
||||
ECHO_LOOPs = 100
|
||||
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)
|
||||
|
||||
def run(self):
|
||||
ip_msg_timeout = self.mbed.options.timeout
|
||||
serial_ip_msg = ""
|
||||
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")
|
||||
return
|
||||
stdout.write(c)
|
||||
result = False
|
||||
c = self.mbed.serial_readline()
|
||||
if c is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
print c
|
||||
stdout.flush()
|
||||
|
||||
m = self.re_detect_server_ip.search(c)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
print "HOST: TCP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT)
|
||||
stdout.flush()
|
||||
serial_ip_msg += c
|
||||
# Searching for IP address and port prompted by server
|
||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
duration = time() - start_serial_pool
|
||||
print "TCP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
||||
stdout.flush()
|
||||
break
|
||||
|
||||
# We assume this test fails so can't send 'error' message to server
|
||||
try:
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||
except Exception, e:
|
||||
print "HOST: Error: %s" % e
|
||||
self.print_result('error')
|
||||
exit(-1)
|
||||
|
||||
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)
|
||||
data = self.s.recv(128)
|
||||
received_str = repr(data)[1:-1]
|
||||
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
||||
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 "Error: No IP and port information sent from server"
|
||||
self.print_result('error')
|
||||
exit(-2)
|
||||
print "HOST: TCP Server not found"
|
||||
result = False
|
||||
|
||||
# We assume this test fails so can't send 'error' message to server
|
||||
try:
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||
except Exception, e:
|
||||
print "Error: %s" % e
|
||||
self.print_result('error')
|
||||
exit(-1)
|
||||
|
||||
TEST_STRING = 'Hello, world !!!'
|
||||
self.s.sendall(TEST_STRING)
|
||||
|
||||
data = self.s.recv(1024)
|
||||
received_str = repr(data)[1:-1]
|
||||
|
||||
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
||||
print 'Received data: ' + received_str
|
||||
if result:
|
||||
self.print_result('success')
|
||||
else:
|
||||
self.print_result('failure')
|
||||
self.s.close()
|
||||
|
||||
# Receiving
|
||||
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
|
||||
"""
|
||||
|
||||
import thread
|
||||
from SocketServer import BaseRequestHandler, UDPServer
|
||||
import socket
|
||||
import re
|
||||
from host_test import DefaultTest
|
||||
from time import time, sleep
|
||||
import uuid
|
||||
import socket
|
||||
import thread
|
||||
from sys import stdout
|
||||
from time import time, sleep
|
||||
from host_test import DefaultTest
|
||||
from SocketServer import BaseRequestHandler, UDPServer
|
||||
|
||||
|
||||
# Received datagrams (with time)
|
||||
|
@ -39,7 +40,8 @@ dict_udp_sent_datagrams = dict()
|
|||
|
||||
class UDPEchoClient_Handler(BaseRequestHandler):
|
||||
def handle(self):
|
||||
""" One handle per connection """
|
||||
""" One handle per connection
|
||||
"""
|
||||
_data, _socket = self.request
|
||||
# Process received datagram
|
||||
data_str = repr(_data)[1:-1]
|
||||
|
@ -47,9 +49,10 @@ class UDPEchoClient_Handler(BaseRequestHandler):
|
|||
|
||||
|
||||
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)
|
||||
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()
|
||||
|
||||
|
||||
|
@ -61,8 +64,9 @@ class UDPEchoServerTest(DefaultTest):
|
|||
|
||||
TEST_PACKET_COUNT = 1000 # how many packets should be send
|
||||
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)
|
||||
|
||||
def get_control_data(self, command="stat\n"):
|
||||
|
@ -75,38 +79,27 @@ class UDPEchoServerTest(DefaultTest):
|
|||
return data
|
||||
|
||||
def run(self):
|
||||
ip_msg_timeout = self.mbed.options.timeout
|
||||
serial_ip_msg = ""
|
||||
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")
|
||||
return
|
||||
stdout.write(c)
|
||||
serial_ip_msg = self.mbed.serial_readline()
|
||||
if serial_ip_msg is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
stdout.write(serial_ip_msg)
|
||||
stdout.flush()
|
||||
# Searching for IP address and port prompted by server
|
||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
print "HOST: UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT)
|
||||
stdout.flush()
|
||||
serial_ip_msg += c
|
||||
# Searching for IP address and port prompted by server
|
||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
duration = time() - start_serial_pool
|
||||
print "UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
||||
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
|
||||
try:
|
||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
except Exception, e:
|
||||
print "Error: %s" % e
|
||||
print "HOST: Error: %s" % e
|
||||
self.print_result('error')
|
||||
exit(-1)
|
||||
return
|
||||
|
||||
# UDP replied receiver works in background to get echoed datagrams
|
||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||
|
@ -115,8 +108,8 @@ class UDPEchoServerTest(DefaultTest):
|
|||
sleep(0.5)
|
||||
|
||||
# Burst part
|
||||
TEST_STRING = 'Hello, world !!!'
|
||||
for no in range(self.TEST_PACKET_COUNT):
|
||||
TEST_STRING = str(uuid.uuid4())
|
||||
payload = str(no) + "__" + TEST_STRING
|
||||
self.s.sendto(payload, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||
dict_udp_sent_datagrams[payload] = time()
|
||||
|
@ -124,26 +117,33 @@ class UDPEchoServerTest(DefaultTest):
|
|||
self.s.close()
|
||||
|
||||
# Wait 5 seconds for packets to come
|
||||
result = True
|
||||
print
|
||||
print "Test Summary:"
|
||||
print "HOST: Test Summary:"
|
||||
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
|
||||
# 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()
|
||||
|
||||
# Getting control data from test
|
||||
print
|
||||
print "Mbed Summary:"
|
||||
print "HOST: Mbed Summary:"
|
||||
mbed_stats = self.get_control_data()
|
||||
print mbed_stats
|
||||
print
|
||||
stdout.flush()
|
||||
|
||||
if result:
|
||||
self.print_result('success')
|
||||
else:
|
||||
self.print_result('failure')
|
||||
|
||||
# Receiving serial data from mbed
|
||||
print
|
||||
print "Remaining mbed serial port data:"
|
||||
print "HOST: Remaining mbed serial port data:"
|
||||
try:
|
||||
while True:
|
||||
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
|
||||
limitations under the License.
|
||||
"""
|
||||
from SocketServer import BaseRequestHandler, UDPServer
|
||||
from host_test import Test
|
||||
|
||||
import sys
|
||||
import socket
|
||||
from sys import stdout
|
||||
from host_test import Test
|
||||
from SocketServer import BaseRequestHandler, UDPServer
|
||||
|
||||
|
||||
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
|
||||
SERVER_PORT = 7
|
||||
|
||||
|
||||
class UDPEchoClientTest(Test):
|
||||
def __init__(self):
|
||||
Test.__init__(self)
|
||||
self.mbed.init_serial()
|
||||
|
||||
def send_server_ip_port(self, ip_address, port_no):
|
||||
print "Resetting target..."
|
||||
print "HOST: Resetting target..."
|
||||
self.mbed.reset()
|
||||
|
||||
# Let's wait for Mbed to print its readiness, usually "{{start}}"
|
||||
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...'))
|
||||
c = self.mbed.serial_readline() # 'UDPCllient waiting for server IP and port...'
|
||||
if c is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
print c
|
||||
print c.strip()
|
||||
stdout.flush()
|
||||
|
||||
if self.mbed.serial_timeout(1) is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
|
||||
print "Sending server IP Address to target..."
|
||||
print "HOST: Sending server IP Address to target..."
|
||||
connection_str = ip_address + ":" + str(port_no) + "\n"
|
||||
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):
|
||||
def print_result(self, result):
|
||||
print "\n{%s}\n{end}" % result
|
||||
|
||||
def handle(self):
|
||||
""" One handle per connection """
|
||||
print "connection received"
|
||||
""" One handle per connection
|
||||
"""
|
||||
data, socket = self.request
|
||||
print "client: ", self.client_address
|
||||
print "data: ", data
|
||||
socket.sendto(data, self.client_address)
|
||||
if '{{end}}' in data:
|
||||
print
|
||||
print data
|
||||
else:
|
||||
sys.stdout.write('.')
|
||||
stdout.flush()
|
||||
|
||||
|
||||
server = UDPServer((SERVER_IP, SERVER_PORT), UDPEchoClient_Handler)
|
||||
print "listening for connections"
|
||||
print "HOST: Listening for connections..."
|
||||
|
||||
mbed_test = UDPEchoClientTest();
|
||||
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.
|
||||
"""
|
||||
|
||||
from socket import socket, AF_INET, SOCK_DGRAM
|
||||
|
||||
import re
|
||||
from host_test import DefaultTest
|
||||
from time import time
|
||||
import sys
|
||||
import uuid
|
||||
from sys import stdout
|
||||
from time import time
|
||||
from host_test import DefaultTest
|
||||
from socket import socket, AF_INET, SOCK_DGRAM
|
||||
|
||||
|
||||
class UDPEchoServerTest(DefaultTest):
|
||||
ECHO_SERVER_ADDRESS = ""
|
||||
ECHO_PORT = 0
|
||||
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)
|
||||
|
||||
def run(self):
|
||||
ip_msg_timeout = self.mbed.options.timeout
|
||||
serial_ip_msg = ""
|
||||
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")
|
||||
return
|
||||
stdout.write(c)
|
||||
result = True
|
||||
serial_ip_msg = self.mbed.serial_readline()
|
||||
if serial_ip_msg is None:
|
||||
self.print_result("ioerr_serial")
|
||||
return
|
||||
stdout.write(serial_ip_msg)
|
||||
stdout.flush()
|
||||
# Searching for IP address and port prompted by server
|
||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
print "HOST: UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT)
|
||||
stdout.flush()
|
||||
serial_ip_msg += c
|
||||
# Searching for IP address and port prompted by server
|
||||
m = self.re_detect_server_ip.search(serial_ip_msg)
|
||||
if m and len(m.groups()):
|
||||
self.ECHO_SERVER_ADDRESS = ".".join(m.groups()[:4])
|
||||
self.ECHO_PORT = int(m.groups()[4]) # must be integer for socket.connect method
|
||||
duration = time() - start_serial_pool
|
||||
print "UDP Server found at: " + self.ECHO_SERVER_ADDRESS + ":" + str(self.ECHO_PORT) + " after " + "%.2f" % duration + " sec"
|
||||
|
||||
# We assume this test fails so can't send 'error' message to server
|
||||
try:
|
||||
self.s = socket(AF_INET, SOCK_DGRAM)
|
||||
except Exception, e:
|
||||
print "HOST: Error: %s" % e
|
||||
self.print_result('error')
|
||||
exit(-1)
|
||||
|
||||
for i in range(0, 100):
|
||||
TEST_STRING = str(uuid.uuid4())
|
||||
self.s.sendto(TEST_STRING, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||
data = self.s.recv(len(TEST_STRING))
|
||||
received_str = repr(data)[1:-1]
|
||||
if TEST_STRING != received_str:
|
||||
result = False
|
||||
break
|
||||
sys.stdout.write('.')
|
||||
stdout.flush()
|
||||
break
|
||||
else:
|
||||
print "Error: No IP and port information sent from server"
|
||||
self.print_result('error')
|
||||
exit(-2)
|
||||
result = False
|
||||
|
||||
# We assume this test fails so can't send 'error' message to server
|
||||
try:
|
||||
self.s = socket(AF_INET, SOCK_DGRAM)
|
||||
except Exception, e:
|
||||
print "Error: %s" % e
|
||||
self.print_result('error')
|
||||
exit(-1)
|
||||
|
||||
TEST_STRING = 'Hello, world !!!'
|
||||
self.s.sendto(TEST_STRING, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||
|
||||
data = self.s.recv(len(TEST_STRING))
|
||||
received_str = repr(data)[1:-1]
|
||||
|
||||
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
||||
print 'Received data: ' + received_str
|
||||
self.s.close()
|
||||
if result:
|
||||
self.print_result('success')
|
||||
else:
|
||||
self.print_result('failure')
|
||||
self.s.close()
|
||||
|
||||
# Receiving
|
||||
try:
|
||||
|
|
|
@ -50,6 +50,10 @@ class WaitusTest(DefaultTest):
|
|||
if i > 2: # we will ignore first few measurements
|
||||
delta = time() - start
|
||||
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%
|
||||
test_result = test_result and deviation_ok
|
||||
msg = "OK" if deviation_ok else "FAIL"
|
||||
|
|
|
@ -88,7 +88,7 @@ def get_version():
|
|||
""" Returns test script version
|
||||
"""
|
||||
single_test_version_major = 1
|
||||
single_test_version_minor = 2
|
||||
single_test_version_minor = 3
|
||||
return (single_test_version_major, single_test_version_minor)
|
||||
|
||||
|
||||
|
|
|
@ -664,7 +664,7 @@ TESTS = [
|
|||
{
|
||||
"id": "NET_4", "description": "TCP echo 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,
|
||||
"host_test": "tcpecho_client_auto",
|
||||
"peripherals": ["ethernet"]
|
||||
|
@ -680,7 +680,7 @@ TESTS = [
|
|||
{
|
||||
"id": "NET_6", "description": "UDP echo 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,
|
||||
"host_test" : "udpecho_client_auto",
|
||||
"peripherals": ["ethernet"],
|
||||
|
@ -738,8 +738,8 @@ TESTS = [
|
|||
"source_dir": join(TEST_DIR, "net", "echo", "udp_link_layer"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
||||
"automated": False,
|
||||
"duration": 15,
|
||||
"host_test": "udp_link_layer_auto.py",
|
||||
"duration": 20,
|
||||
"host_test": "udp_link_layer_auto",
|
||||
"peripherals": ["ethernet"],
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue