mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			
							parent
							
								
									0887683a13
								
							
						
					
					
						commit
						467eb342f0
					
				| 
						 | 
				
			
			@ -56,8 +56,8 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("Testing bringing the network up and down", test_bring_up_down<1>),
 | 
			
		||||
    Case("Testing bringing the network up and down twice", test_bring_up_down<2>),
 | 
			
		||||
    Case("Bringing the network up and down", test_bring_up_down<1>),
 | 
			
		||||
    Case("Bringing the network up and down twice", test_bring_up_down<2>),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -97,10 +97,10 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("Testing DNS query",               test_dns_query),
 | 
			
		||||
    Case("Testing DNS preference query",    test_dns_query_pref),
 | 
			
		||||
    Case("Testing DNS literal",             test_dns_literal),
 | 
			
		||||
    Case("Testing DNS preference literal",  test_dns_literal_pref),
 | 
			
		||||
    Case("DNS query",               test_dns_query),
 | 
			
		||||
    Case("DNS preference query",    test_dns_query_pref),
 | 
			
		||||
    Case("DNS literal",             test_dns_literal),
 | 
			
		||||
    Case("DNS preference literal",  test_dns_literal_pref),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,9 @@
 | 
			
		|||
#include "TCPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
 | 
			
		||||
| 
						 | 
				
			
			@ -28,14 +31,13 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
void test_tcp_echo() {
 | 
			
		||||
    EthernetInterface eth;
 | 
			
		||||
    int err = eth.connect();
 | 
			
		||||
 | 
			
		||||
    if (err) {
 | 
			
		||||
        printf("MBED: failed to connect with an error of %d\r\n", err);
 | 
			
		||||
        GREENTEA_TESTSUITE_RESULT(false);
 | 
			
		||||
        TEST_ASSERT_EQUAL(0, err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    printf("MBED: TCPClient IP address is '%s'\n", eth.get_ip_address());
 | 
			
		||||
| 
						 | 
				
			
			@ -80,5 +82,22 @@ int main() {
 | 
			
		|||
 | 
			
		||||
    sock.close();
 | 
			
		||||
    eth.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
    TEST_ASSERT_EQUAL(true, result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("TCP echo", test_tcp_echo),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,9 @@
 | 
			
		|||
#include "TCPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
 | 
			
		||||
| 
						 | 
				
			
			@ -84,11 +87,9 @@ public:
 | 
			
		|||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
 | 
			
		||||
void test_tcp_echo_parallel() {
 | 
			
		||||
    Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
 | 
			
		||||
 | 
			
		||||
    int err = net.connect();
 | 
			
		||||
    TEST_ASSERT_EQUAL(0, err);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -123,5 +124,20 @@ int main() {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    net.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("TCP echo parallel", test_tcp_echo_parallel),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,10 @@
 | 
			
		|||
#include "TCPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
    // Test connection information
 | 
			
		||||
| 
						 | 
				
			
			@ -35,9 +39,7 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
 | 
			
		|||
    return (f != last);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "default_auto");
 | 
			
		||||
 | 
			
		||||
void test_tcp_hello_world() {
 | 
			
		||||
    bool result = false;
 | 
			
		||||
    EthernetInterface eth;
 | 
			
		||||
    //eth.init(); //Use DHCP
 | 
			
		||||
| 
						 | 
				
			
			@ -83,5 +85,22 @@ int main() {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    eth.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
    TEST_ASSERT_EQUAL(true, result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "default_auto");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("TCP hello world", test_tcp_hello_world),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,9 @@
 | 
			
		|||
#include "TCPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN
 | 
			
		||||
| 
						 | 
				
			
			@ -107,8 +110,7 @@ void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
void test_tcp_packet_pressure() {
 | 
			
		||||
    generate_buffer(&buffer, &buffer_size,
 | 
			
		||||
        MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN,
 | 
			
		||||
        MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX);
 | 
			
		||||
| 
						 | 
				
			
			@ -123,8 +125,6 @@ int main() {
 | 
			
		|||
 | 
			
		||||
    greentea_send_kv("target_ip", eth.get_ip_address());
 | 
			
		||||
 | 
			
		||||
    bool result = true;
 | 
			
		||||
 | 
			
		||||
    char recv_key[] = "host_port";
 | 
			
		||||
    char ipbuf[60] = {0};
 | 
			
		||||
    char portbuf[16] = {0};
 | 
			
		||||
| 
						 | 
				
			
			@ -223,5 +223,21 @@ int main() {
 | 
			
		|||
            MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
 | 
			
		||||
 | 
			
		||||
    eth.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("TCP packet pressure", test_tcp_packet_pressure),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,9 @@
 | 
			
		|||
#include "TCPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN
 | 
			
		||||
| 
						 | 
				
			
			@ -224,9 +227,7 @@ public:
 | 
			
		|||
PressureTest *pressure_tests[MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
 | 
			
		||||
void test_tcp_packet_pressure_parallel() {
 | 
			
		||||
    uint8_t *buffer;
 | 
			
		||||
    size_t buffer_size;
 | 
			
		||||
    generate_buffer(&buffer, &buffer_size,
 | 
			
		||||
| 
						 | 
				
			
			@ -247,8 +248,6 @@ int main() {
 | 
			
		|||
 | 
			
		||||
    greentea_send_kv("target_ip", net.get_ip_address());
 | 
			
		||||
 | 
			
		||||
    bool result = true;
 | 
			
		||||
 | 
			
		||||
    char recv_key[] = "host_port";
 | 
			
		||||
    char ipbuf[60] = {0};
 | 
			
		||||
    char portbuf[16] = {0};
 | 
			
		||||
| 
						 | 
				
			
			@ -286,5 +285,21 @@ int main() {
 | 
			
		|||
            MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
 | 
			
		||||
 | 
			
		||||
    net.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "tcp_echo");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("TCP packet pressure parallel", test_tcp_packet_pressure_parallel),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,10 @@
 | 
			
		|||
#include "UDPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_UDP_DTLS_HANDSHAKE_BUFFER_SIZE
 | 
			
		||||
#define MBED_CFG_UDP_DTLS_HANDSHAKE_BUFFER_SIZE 512
 | 
			
		||||
| 
						 | 
				
			
			@ -31,9 +35,7 @@ uint8_t buffer[MBED_CFG_UDP_DTLS_HANDSHAKE_BUFFER_SIZE] = {0};
 | 
			
		|||
int udp_dtls_handshake_pattern[] = {MBED_CFG_UDP_DTLS_HANDSHAKE_PATTERN};
 | 
			
		||||
const int udp_dtls_handshake_count = sizeof(udp_dtls_handshake_pattern) / sizeof(int);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "udp_shotgun");
 | 
			
		||||
 | 
			
		||||
void test_udp_dtls_handshake() {
 | 
			
		||||
    EthernetInterface eth;
 | 
			
		||||
    int err = eth.connect();
 | 
			
		||||
    TEST_ASSERT_EQUAL(0, err);
 | 
			
		||||
| 
						 | 
				
			
			@ -127,5 +129,22 @@ int main() {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    eth.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
    TEST_ASSERT_EQUAL(true, result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "udp_shotgun");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("UDP DTLS handshake", test_udp_dtls_handshake),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,10 @@
 | 
			
		|||
#include "UDPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE
 | 
			
		||||
#define MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE 64
 | 
			
		||||
| 
						 | 
				
			
			@ -25,14 +29,14 @@ namespace {
 | 
			
		|||
    char rx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE] = {0};
 | 
			
		||||
    const char ASCII_MAX = '~' - ' ';
 | 
			
		||||
    const int ECHO_LOOPS = 16;
 | 
			
		||||
    char uuid[48] = {0};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void prep_buffer(char *uuid_buffer, size_t uuid_len, char *tx_buffer, size_t tx_size) {
 | 
			
		||||
void prep_buffer(char *uuid, char *tx_buffer, size_t tx_size) {
 | 
			
		||||
    size_t i = 0;
 | 
			
		||||
 | 
			
		||||
    for (; i<uuid_len; ++i) {
 | 
			
		||||
        tx_buffer[i] = uuid_buffer[i];
 | 
			
		||||
    }
 | 
			
		||||
    memcpy(tx_buffer, uuid, strlen(uuid));
 | 
			
		||||
    i += strlen(uuid);
 | 
			
		||||
 | 
			
		||||
    tx_buffer[i++] = ' ';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,11 +45,7 @@ void prep_buffer(char *uuid_buffer, size_t uuid_len, char *tx_buffer, size_t tx_
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    char uuid[48] = {0};
 | 
			
		||||
    GREENTEA_SETUP_UUID(120, "udp_echo", uuid, 48);
 | 
			
		||||
    printf("Got a uuid of %s\r\n", uuid);
 | 
			
		||||
    size_t uuid_len = strlen(uuid);
 | 
			
		||||
void test_udp_echo() {
 | 
			
		||||
    EthernetInterface eth;
 | 
			
		||||
 | 
			
		||||
    int err = eth.connect();
 | 
			
		||||
| 
						 | 
				
			
			@ -53,8 +53,7 @@ int main() {
 | 
			
		|||
 | 
			
		||||
    if (err) {
 | 
			
		||||
        printf("MBED: failed to connect with an error of %d\r\n", err);
 | 
			
		||||
        GREENTEA_TESTSUITE_RESULT(false);
 | 
			
		||||
        return 0;
 | 
			
		||||
        TEST_ASSERT_EQUAL(0, err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    printf("UDP client IP Address is %s\n", eth.get_ip_address());
 | 
			
		||||
| 
						 | 
				
			
			@ -81,8 +80,8 @@ int main() {
 | 
			
		|||
    SocketAddress udp_addr(ipbuf, port);
 | 
			
		||||
 | 
			
		||||
    int success = 0;
 | 
			
		||||
        prep_buffer(uuid, uuid_len, tx_buffer, sizeof(tx_buffer));
 | 
			
		||||
    for (int i = 0; success < ECHO_LOOPS; i++) {
 | 
			
		||||
        prep_buffer(uuid, tx_buffer, sizeof(tx_buffer));
 | 
			
		||||
        const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
 | 
			
		||||
        if (ret >= 0) {
 | 
			
		||||
            printf("[%02d] sent %d bytes - %.*s  \n", i, ret, ret, tx_buffer);
 | 
			
		||||
| 
						 | 
				
			
			@ -120,9 +119,24 @@ int main() {
 | 
			
		|||
        sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool result = success == ECHO_LOOPS;
 | 
			
		||||
 | 
			
		||||
    sock.close();
 | 
			
		||||
    eth.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
    TEST_ASSERT_EQUAL(ECHO_LOOPS, success);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP_UUID(120, "udp_echo", uuid, 48);
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("UDP echo", test_udp_echo),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,10 @@
 | 
			
		|||
#include "UDPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE
 | 
			
		||||
#define MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE 64
 | 
			
		||||
| 
						 | 
				
			
			@ -28,17 +32,17 @@ const int ECHO_LOOPS = 16;
 | 
			
		|||
EthernetInterface net;
 | 
			
		||||
SocketAddress udp_addr;
 | 
			
		||||
Mutex iomutex;
 | 
			
		||||
char uuid[48] = {0};
 | 
			
		||||
 | 
			
		||||
// NOTE: assuming that "id" stays in the single digits
 | 
			
		||||
void prep_buffer(int id, char *uuid_buffer, size_t uuid_len, char *tx_buffer, size_t tx_size) {
 | 
			
		||||
    size_t i = 2;
 | 
			
		||||
void prep_buffer(int id, char *uuid, char *tx_buffer, size_t tx_size) {
 | 
			
		||||
    size_t i = 0;
 | 
			
		||||
 | 
			
		||||
    tx_buffer[0] = '0' + id;
 | 
			
		||||
    tx_buffer[1] = ' ';
 | 
			
		||||
    tx_buffer[i++] = '0' + id;
 | 
			
		||||
    tx_buffer[i++] = ' ';
 | 
			
		||||
 | 
			
		||||
    for (; i<uuid_len + 2; ++i) {
 | 
			
		||||
        tx_buffer[i] = uuid_buffer[i - 2];
 | 
			
		||||
    }
 | 
			
		||||
    memcpy(tx_buffer+i, uuid, strlen(uuid));
 | 
			
		||||
    i += strlen(uuid);
 | 
			
		||||
 | 
			
		||||
    tx_buffer[i++] = ' ';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -58,18 +62,16 @@ private:
 | 
			
		|||
    Thread thread;
 | 
			
		||||
    bool result;
 | 
			
		||||
    int id;
 | 
			
		||||
    char *uuid_buffer;
 | 
			
		||||
    size_t uuid_len;
 | 
			
		||||
    char *uuid;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    // Limiting stack size to 1k
 | 
			
		||||
    Echo(): thread(osPriorityNormal, 1024), result(false) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void start(int id, char *uuid_buffer, size_t uuid_len) {
 | 
			
		||||
    void start(int id, char *uuid) {
 | 
			
		||||
        this->id = id;
 | 
			
		||||
        this->uuid_buffer = uuid_buffer;
 | 
			
		||||
        this->uuid_len = uuid_len;
 | 
			
		||||
        this->uuid = uuid;
 | 
			
		||||
        osStatus status = thread.start(callback(this, &Echo::echo));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -86,8 +88,8 @@ public:
 | 
			
		|||
 | 
			
		||||
        sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
 | 
			
		||||
 | 
			
		||||
            prep_buffer(id, uuid_buffer, uuid_len, tx_buffer, sizeof(tx_buffer));
 | 
			
		||||
        for (int i = 0; success < ECHO_LOOPS; i++) {
 | 
			
		||||
            prep_buffer(id, uuid, tx_buffer, sizeof(tx_buffer));
 | 
			
		||||
            const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
 | 
			
		||||
            if (ret >= 0) {
 | 
			
		||||
                iomutex.lock();
 | 
			
		||||
| 
						 | 
				
			
			@ -148,14 +150,9 @@ public:
 | 
			
		|||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    char uuid[48] = {0};
 | 
			
		||||
    GREENTEA_SETUP_UUID(120, "udp_echo", uuid, 48);
 | 
			
		||||
    printf("Got a uuid of %s\r\n", uuid);
 | 
			
		||||
    size_t uuid_len = strlen(uuid);
 | 
			
		||||
 | 
			
		||||
void test_udp_echo_parallel() {
 | 
			
		||||
    Echo echoers[MBED_CFG_UDP_CLIENT_ECHO_THREADS];
 | 
			
		||||
 | 
			
		||||
    int err = net.connect();
 | 
			
		||||
    TEST_ASSERT_EQUAL(0, err);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -185,7 +182,7 @@ int main() {
 | 
			
		|||
 | 
			
		||||
        // Startup echo threads in parallel
 | 
			
		||||
        for (int i = 0; i < MBED_CFG_UDP_CLIENT_ECHO_THREADS; i++) {
 | 
			
		||||
            echoers[i].start(i, uuid, uuid_len);
 | 
			
		||||
            echoers[i].start(i, uuid);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        bool result = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -196,6 +193,23 @@ int main() {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        net.disconnect();
 | 
			
		||||
        GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
        TEST_ASSERT_EQUAL(true, result);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP_UUID(120, "udp_echo", uuid, 48);
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("UDP echo parallel", test_udp_echo_parallel),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,9 @@
 | 
			
		|||
#include "UDPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN
 | 
			
		||||
| 
						 | 
				
			
			@ -110,8 +113,7 @@ void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) {
 | 
			
		|||
    TEST_ASSERT(buffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "udp_echo");
 | 
			
		||||
void test_udp_packet_pressure() {
 | 
			
		||||
    generate_buffer(&buffer, &buffer_size,
 | 
			
		||||
        MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN,
 | 
			
		||||
        MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX);
 | 
			
		||||
| 
						 | 
				
			
			@ -126,8 +128,6 @@ int main() {
 | 
			
		|||
 | 
			
		||||
    greentea_send_kv("target_ip", eth.get_ip_address());
 | 
			
		||||
 | 
			
		||||
    bool result = true;
 | 
			
		||||
 | 
			
		||||
    char recv_key[] = "host_port";
 | 
			
		||||
    char ipbuf[60] = {0};
 | 
			
		||||
    char portbuf[16] = {0};
 | 
			
		||||
| 
						 | 
				
			
			@ -246,5 +246,21 @@ int main() {
 | 
			
		|||
            MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
 | 
			
		||||
 | 
			
		||||
    eth.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "udp_echo");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("UDP packet pressure", test_udp_packet_pressure),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,9 @@
 | 
			
		|||
#include "UDPSocket.h"
 | 
			
		||||
#include "greentea-client/test_env.h"
 | 
			
		||||
#include "unity/unity.h"
 | 
			
		||||
#include "utest.h"
 | 
			
		||||
 | 
			
		||||
using namespace utest::v1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN
 | 
			
		||||
| 
						 | 
				
			
			@ -249,9 +252,7 @@ public:
 | 
			
		|||
PressureTest *pressure_tests[MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    GREENTEA_SETUP(120, "udp_echo");
 | 
			
		||||
 | 
			
		||||
void test_udp_packet_pressure_parallel() {
 | 
			
		||||
    uint8_t *buffer;
 | 
			
		||||
    size_t buffer_size;
 | 
			
		||||
    generate_buffer(&buffer, &buffer_size,
 | 
			
		||||
| 
						 | 
				
			
			@ -272,8 +273,6 @@ int main() {
 | 
			
		|||
 | 
			
		||||
    greentea_send_kv("target_ip", net.get_ip_address());
 | 
			
		||||
 | 
			
		||||
    bool result = true;
 | 
			
		||||
 | 
			
		||||
    char recv_key[] = "host_port";
 | 
			
		||||
    char ipbuf[60] = {0};
 | 
			
		||||
    char portbuf[16] = {0};
 | 
			
		||||
| 
						 | 
				
			
			@ -311,5 +310,21 @@ int main() {
 | 
			
		|||
            MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
 | 
			
		||||
 | 
			
		||||
    net.disconnect();
 | 
			
		||||
    GREENTEA_TESTSUITE_RESULT(result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test setup
 | 
			
		||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
 | 
			
		||||
    GREENTEA_SETUP(120, "udp_echo");
 | 
			
		||||
    return verbose_test_setup_handler(number_of_cases);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Case cases[] = {
 | 
			
		||||
    Case("UDP packet pressure parallel", test_udp_packet_pressure_parallel),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Specification specification(test_setup, cases);
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    return !Harness::run(specification);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue