Skip to content

Commit 10b8597

Browse files
author
Cruz Monrreal
authored
Merge pull request #7103 from mikaleppanen/test_updat_lpc17xx
Greentea test updated for NXP lpc17xx
2 parents 871489e + 35f064f commit 10b8597

File tree

9 files changed

+173
-26
lines changed

9 files changed

+173
-26
lines changed

TESTS/netsocket/tcp/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace
3434
NetworkInterface* net;
3535
}
3636

37+
char tcp_global::rx_buffer[RX_BUFF_SIZE];
38+
char tcp_global::tx_buffer[TX_BUFF_SIZE];
39+
3740
NetworkInterface* get_interface()
3841
{
3942
return net;

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ void fill_tx_buffer_ascii(char *buff, size_t len);
2424
void tcpsocket_connect_to_echo_srv(TCPSocket& sock);
2525
void tcpsocket_connect_to_discard_srv(TCPSocket& sock);
2626

27+
namespace tcp_global
28+
{
29+
static const int TCP_OS_STACK_SIZE = 1024;
30+
31+
static const int RX_BUFF_SIZE = 1220;
32+
static const int TX_BUFF_SIZE = 1220;
33+
34+
extern char rx_buffer[RX_BUFF_SIZE];
35+
extern char tx_buffer[TX_BUFF_SIZE];
36+
}
37+
2738
/*
2839
* Test cases
2940
*/

TESTS/netsocket/tcp/tcpsocket_echotest.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ namespace
3131
static const int SIGIO_TIMEOUT = 5000; //[ms]
3232

3333
static const int BUFF_SIZE = 1200;
34-
char rx_buffer[BUFF_SIZE] = {0};
35-
char tx_buffer[BUFF_SIZE] = {0};
36-
3734
static const int PKTS = 22;
3835
static const int pkt_sizes[PKTS] = {1,2,3,4,5,6,7,8,9,10, \
3936
100,200,300,400,500,600,700,800,900,1000,\
@@ -54,24 +51,24 @@ void TCPSOCKET_ECHOTEST()
5451
int sent;
5552
int x = 0;
5653
for (int pkt_s = pkt_sizes[x]; x < PKTS; pkt_s = pkt_sizes[x++]) {
57-
fill_tx_buffer_ascii(tx_buffer, BUFF_SIZE);
54+
fill_tx_buffer_ascii(tcp_global::tx_buffer, BUFF_SIZE);
5855

59-
sent = sock.send(tx_buffer, pkt_s);
56+
sent = sock.send(tcp_global::tx_buffer, pkt_s);
6057
if (sent < 0) {
6158
printf("[Round#%02d] network error %d\n", x, sent);
6259
TEST_FAIL();
6360
}
6461

6562
int bytes2recv = sent;
6663
while (bytes2recv) {
67-
recvd = sock.recv(&(rx_buffer[sent-bytes2recv]), bytes2recv);
64+
recvd = sock.recv(&(tcp_global::rx_buffer[sent-bytes2recv]), bytes2recv);
6865
if (recvd < 0) {
6966
printf("[Round#%02d] network error %d\n", x, recvd);
7067
TEST_FAIL();
7168
}
7269
bytes2recv -= recvd;
7370
}
74-
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, sent));
71+
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, sent));
7572
}
7673
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
7774
}
@@ -81,7 +78,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
8178
int bytes2recv = *(int*)receive_bytes;
8279
int recvd;
8380
while (bytes2recv) {
84-
recvd = sock.recv(&(rx_buffer[*(int*)receive_bytes-bytes2recv]), bytes2recv);
81+
recvd = sock.recv(&(tcp_global::rx_buffer[*(int*)receive_bytes-bytes2recv]), bytes2recv);
8582
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
8683
wait(1);
8784
continue;
@@ -91,7 +88,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
9188
bytes2recv -= recvd;
9289
}
9390

94-
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, *(int*)receive_bytes));
91+
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, *(int*)receive_bytes));
9592

9693
static int round = 0;
9794
printf("[Recevr#%02d] bytes received: %d\n", round++, *(int*)receive_bytes);
@@ -110,22 +107,22 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
110107
int sent;
111108
int s_idx = 0;
112109
Thread *thread;
113-
unsigned char *stack_mem = (unsigned char *)malloc(OS_STACK_SIZE);
110+
unsigned char *stack_mem = (unsigned char *)malloc(tcp_global::TCP_OS_STACK_SIZE);
114111
TEST_ASSERT_NOT_NULL(stack_mem);
115112

116113
for (int pkt_s = pkt_sizes[s_idx]; s_idx < PKTS; ++s_idx) {
117114
pkt_s = pkt_sizes[s_idx];
118115
thread = new Thread(osPriorityNormal,
119-
OS_STACK_SIZE,
116+
tcp_global::TCP_OS_STACK_SIZE,
120117
stack_mem,
121118
"receiver");
122119
TEST_ASSERT_EQUAL(osOK, thread->start(callback(tcpsocket_echotest_nonblock_receiver, &pkt_s)));
123120

124-
fill_tx_buffer_ascii(tx_buffer, pkt_s);
121+
fill_tx_buffer_ascii(tcp_global::tx_buffer, pkt_s);
125122

126123
bytes2send = pkt_s;
127124
while (bytes2send > 0) {
128-
sent = sock.send(&(tx_buffer[pkt_s-bytes2send]), bytes2send);
125+
sent = sock.send(&(tcp_global::tx_buffer[pkt_s-bytes2send]), bytes2send);
129126
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
130127
TEST_ASSERT_NOT_EQUAL(osEventTimeout, osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status);
131128
continue;

TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace
3232

3333
static const int BURST_CNT = 100;
3434
static const int BURST_SIZE = 1220;
35-
char rx_buffer[BURST_SIZE] = {0};
36-
char tx_buffer[BURST_SIZE] = {0};
3735
}
3836

3937
static void _sigio_handler(osThreadId id) {
@@ -47,15 +45,15 @@ void TCPSOCKET_ECHOTEST_BURST()
4745
sock.sigio(callback(_sigio_handler, Thread::gettid()));
4846

4947
// TX buffer to be preserved for comparison
50-
fill_tx_buffer_ascii(tx_buffer, BURST_SIZE);
48+
fill_tx_buffer_ascii(tcp_global::tx_buffer, BURST_SIZE);
5149

5250
int recvd;
5351
int bt_left;
5452
int sent;
5553
for (int i = 0; i < BURST_CNT; i++) {
5654
bt_left = BURST_SIZE;
5755
while (bt_left > 0) {
58-
sent = sock.send(&(tx_buffer[BURST_SIZE-bt_left]), bt_left);
56+
sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE-bt_left]), bt_left);
5957
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
6058
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
6159
TEST_FAIL();
@@ -70,7 +68,7 @@ void TCPSOCKET_ECHOTEST_BURST()
7068

7169
bt_left = BURST_SIZE;
7270
while (bt_left > 0) {
73-
recvd = sock.recv(&(rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
71+
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
7472
if (recvd < 0) {
7573
printf("[%02d] network error %d\n", i, recvd);
7674
break;
@@ -83,7 +81,7 @@ void TCPSOCKET_ECHOTEST_BURST()
8381
TEST_FAIL();
8482
}
8583

86-
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, BURST_SIZE));
84+
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, BURST_SIZE));
8785
}
8886
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
8987
}
@@ -96,15 +94,15 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
9694
sock.sigio(callback(_sigio_handler, Thread::gettid()));
9795

9896
// TX buffer to be preserved for comparison
99-
fill_tx_buffer_ascii(tx_buffer, BURST_SIZE);
97+
fill_tx_buffer_ascii(tcp_global::tx_buffer, BURST_SIZE);
10098

10199
int sent;
102100
int recvd;
103101
int bt_left = 0;
104102
for (int i = 0; i < BURST_CNT; i++) {
105103
bt_left = BURST_SIZE;
106104
while (bt_left > 0) {
107-
sent = sock.send(&(tx_buffer[BURST_SIZE-bt_left]), bt_left);
105+
sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE-bt_left]), bt_left);
108106
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
109107
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
110108
TEST_FAIL();
@@ -120,7 +118,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
120118

121119
bt_left = BURST_SIZE;
122120
while (bt_left > 0) {
123-
recvd = sock.recv(&(rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
121+
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
124122
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
125123
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
126124
printf("[bt#%02d] packet timeout...", i);
@@ -140,7 +138,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
140138
TEST_FAIL();
141139
}
142140

143-
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, BURST_SIZE));
141+
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, BURST_SIZE));
144142
}
145143
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
146144
}

TESTS/network/emac/emac_TestMemoryManager.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
#include "rtos/Mutex.h"
2929

30+
extern "C" {
31+
#include "arm_hal_interrupt_private.h"
32+
}
33+
#include "nsdynmemLIB.h"
34+
3035
#include "EMACMemoryManager.h"
3136
#include "emac_TestMemoryManager.h"
3237

@@ -43,12 +48,57 @@
4348

4449
char s_trace_buffer[100] = MEM_MNGR_TRACE;
4550

51+
/* For LPC boards define the heap memory bank ourselves to give us section placement
52+
control */
53+
#ifndef ETHMEM_SECTION
54+
#if defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
55+
# if defined (__ICCARM__)
56+
# define ETHMEM_SECTION
57+
# elif defined(TOOLCHAIN_GCC_CR)
58+
# define ETHMEM_SECTION __attribute__((section(".data.$RamPeriph32")))
59+
# else
60+
# define ETHMEM_SECTION __attribute__((section("AHBSRAM1"),aligned))
61+
# endif
62+
#elif defined(TARGET_LPC1768) || defined(TARGET_LPC1769)
63+
# if defined (__ICCARM__)
64+
# define ETHMEM_SECTION
65+
# elif defined(TOOLCHAIN_GCC_CR)
66+
# define ETHMEM_SECTION __attribute__((section(".data.$RamPeriph32")))
67+
# else
68+
# define ETHMEM_SECTION __attribute__((section("AHBSRAM0"),aligned))
69+
# endif
70+
#endif
71+
#endif
72+
73+
#ifdef ETHMEM_SECTION
74+
// Use nanostack libservice dynamic memory library
75+
#define EMAC_HEAP_SIZE 16300
76+
77+
#if defined (__ICCARM__)
78+
#pragma location = ".ethusbram"
79+
#endif
80+
ETHMEM_SECTION static unsigned char ns_heap[EMAC_HEAP_SIZE];
81+
82+
void emac_heap_error_handler(heap_fail_t event)
83+
{
84+
MBED_ASSERT(0);
85+
}
86+
#endif
87+
4688
EmacTestMemoryManager::EmacTestMemoryManager()
4789
: m_mem_mutex(),
4890
m_mem_buffers(),
4991
m_alloc_unit(BUF_POOL_SIZE),
5092
m_memory_available(true)
5193
{
94+
#ifdef ETHMEM_SECTION
95+
static bool ns_heap_init = false;
96+
if (!ns_heap_init) {
97+
platform_critical_init(); // Create mutex for dynamic memory library
98+
ns_dyn_mem_init(ns_heap, EMAC_HEAP_SIZE, emac_heap_error_handler, NULL);
99+
ns_heap_init = true;
100+
}
101+
#endif
52102
}
53103

54104
emac_mem_buf_t *EmacTestMemoryManager::alloc_heap(uint32_t size, uint32_t align)
@@ -74,7 +124,11 @@ emac_mem_buf_t *EmacTestMemoryManager::alloc_heap(uint32_t size, uint32_t align,
74124

75125
CHECK_ASSERT(buf, "alloc_heap() no memory");
76126

127+
#ifdef ETHMEM_SECTION
128+
buf->buffer = ns_dyn_mem_alloc(BUF_HEAD_SIZE + size + align + BUF_TAIL_SIZE);
129+
#else
77130
buf->buffer = std::malloc(BUF_HEAD_SIZE + size + align + BUF_TAIL_SIZE);
131+
#endif
78132

79133
CHECK_ASSERT(buf->buffer, "alloc_heap() no memory");
80134

@@ -218,7 +272,12 @@ void EmacTestMemoryManager::free(emac_mem_buf_t *buf)
218272
emac_memory_t *next = mem_buf->next;
219273

220274
m_mem_buffers.erase(mem_buf_entry);
275+
276+
#ifdef ETHMEM_SECTION
277+
ns_dyn_mem_free(mem_buf->buffer);
278+
#else
221279
std::free(mem_buf->buffer);
280+
#endif
222281
delete mem_buf;
223282

224283
mem_buf = next;

TESTS/network/emac/emac_TestNetworkStack.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ nsapi_error_t EmacTestNetworkStack::add_dns_server(const SocketAddress &address)
3939
return NSAPI_ERROR_OK;
4040
}
4141

42+
nsapi_error_t EmacTestNetworkStack::call_in(int delay, mbed::Callback<void()> func)
43+
{
44+
// Implemented as empty to save memory
45+
return NSAPI_ERROR_DEVICE_ERROR;
46+
}
47+
48+
EmacTestNetworkStack::call_in_callback_cb_t EmacTestNetworkStack::get_call_in_callback()
49+
{
50+
call_in_callback_cb_t cb(this, &EmacTestNetworkStack::call_in);
51+
return cb;
52+
}
53+
4254
nsapi_error_t EmacTestNetworkStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
4355
{
4456
return NSAPI_ERROR_OK;

TESTS/network/emac/emac_TestNetworkStack.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,38 @@ class EmacTestNetworkStack : public OnboardNetworkStack, private mbed::NonCopyab
356356
int optname, void *optval, unsigned *optlen);
357357

358358
private:
359+
360+
/** Call in callback
361+
*
362+
* Callback is used to call the call in method of the network stack.
363+
*/
364+
typedef mbed::Callback<nsapi_error_t (int delay_ms, mbed::Callback<void()> user_cb)> call_in_callback_cb_t;
365+
366+
/** Get a call in callback
367+
*
368+
* Get a call in callback from the network stack context.
369+
*
370+
* Callback should not take more than 10ms to execute, otherwise it might
371+
* prevent underlying thread processing. A portable user of the callback
372+
* should not make calls to network operations due to stack size limitations.
373+
* The callback should not perform expensive operations such as socket recv/send
374+
* calls or blocking operations.
375+
*
376+
* @return Call in callback
377+
*/
378+
virtual call_in_callback_cb_t get_call_in_callback();
379+
380+
/** Call a callback after a delay
381+
*
382+
* Call a callback from the network stack context after a delay. If function
383+
* returns error callback will not be called.
384+
*
385+
* @param delay Delay in milliseconds
386+
* @param func Callback to be called
387+
* @return 0 on success, negative error code on failure
388+
*/
389+
virtual nsapi_error_t call_in(int delay, mbed::Callback<void()> func);
390+
359391
Interface *m_interface;
360392
};
361393

0 commit comments

Comments
 (0)