Merge pull request #11276 from ARMmbed/sip-workshop

Add integration tests
pull/11370/head
Martin Kojtal 2019-08-28 07:13:30 +02:00 committed by GitHub
commit d2c05915ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 21865 additions and 8 deletions

View File

@ -0,0 +1,81 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
#define ETHERNET 1
#define WIFI 2
#define MESH 3
#define CELLULAR 4
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE)
#error [NOT_SUPPORTED] No network interface found on this target.
#endif
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == ETHERNET
#define TEST_NETWORK_TYPE "Ethernet"
#elif MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI
#define TEST_NETWORK_TYPE "WiFi"
#elif MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
#define TEST_NETWORK_TYPE "Mesh"
#elif MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == CELLULAR
#define TEST_NETWORK_TYPE "Cellular"
#else
#error [NOT_SUPPORTED] Either WiFi, Ethernet or Cellular network interface need to be enabled
#endif
#define FS_FAT 1
#define FS_LFS 2
#if COMPONENT_SPIF
#define TEST_BLOCK_DEVICE_TYPE "SPIF"
#elif COMPONENT_QSPIF
#define TEST_BLOCK_DEVICE_TYPE "QSPIF"
#elif COMPONENT_DATAFLASH
#define TEST_BLOCK_DEVICE_TYPE "DATAFLASH"
#elif COMPONENT_SD
#define TEST_BLOCK_DEVICE_TYPE "SD"
#define TEST_USE_FILESYSTEM FS_FAT
#elif COMPONENT_FLASHIAP
#define TEST_BLOCK_DEVICE_TYPE "FLASHIAP"
#elif COMPONENT_SDIO
#define TEST_BLOCK_DEVICE_TYPE "SDIO"
#elif COMPONENT_NUSD
#define TEST_BLOCK_DEVICE_TYPE "NUSD"
#define TEST_USE_FILESYSTEM FS_FAT
#else
#define TEST_BLOCK_DEVICE_TYPE "UNKNOWN"
#endif
#if !defined(TEST_USE_FILESYSTEM)
#define TEST_USE_FILESYSTEM FS_LFS
#endif
#if TEST_USE_FILESYSTEM == FS_FAT
#define TEST_FILESYSTEM_TYPE "FAT"
#elif TEST_USE_FILESYSTEM == FS_LFS
#define TEST_FILESYSTEM_TYPE "LFS"
#else
#define TEST_FILESYSTEM_TYPE "UNKNOWN"
#endif
#define TEST_MEMORY_SIZE_10K 10240
#define TEST_MEMORY_SIZE_20K 20480
#define TEST_MEMORY_SIZE_40K 40960
#define TEST_MEMORY_SIZE_60K 61440
#define TEST_MEMORY_SIZE_80K 81920
#define TEST_MEMORY_SIZE_100K 102400

View File

@ -0,0 +1,205 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include <string>
#define MAX_THREADS 5
#define MAX_RETRIES 3
#ifdef MBED_CONF_DOWNLOAD_TEST_URL_HOST
const char dl_host[] = MBED_CONF_DOWNLOAD_TEST_URL_HOST;
#else
const char dl_host[] = "armmbed.github.io";
#endif
#ifdef MBED_CONF_DOWNLOAD_TEST_URL_PATH
const char dl_path[] = MBED_CONF_DOWNLOAD_TEST_URL_PATH;
#else
const char dl_path[] = "/mbed-test-files/sample.txt";
#endif
const char req_template[] = "GET %s HTTP/1.1\nHost: %s\n\n";
#define REQ_BUF_SIZE 256
#define RECV_BUF_SIZE 1024
static char g_request_buffer[MAX_THREADS][REQ_BUF_SIZE]; // the default request is 65bytes long.
static char g_receive_buffer[MAX_THREADS * RECV_BUF_SIZE];
static volatile bool event_fired[MAX_THREADS] = { };
static void socket_event_0(void)
{
event_fired[0] = true;
}
static void socket_event_1(void)
{
event_fired[1] = true;
}
static void socket_event_2(void)
{
event_fired[2] = true;
}
static void socket_event_3(void)
{
event_fired[3] = true;
}
static void socket_event_4(void)
{
event_fired[4] = true;
}
size_t download_test(NetworkInterface *interface, const unsigned char *data, size_t data_length, size_t buff_size, uint32_t thread_id)
{
int result = -1;
TEST_ASSERT_MESSAGE(MAX_THREADS > thread_id, "Unsupported thread ID");
TEST_ASSERT_MESSAGE((MAX_THREADS * RECV_BUF_SIZE) >= buff_size, "Cannot test with the requested buffer size");
/* setup TCP socket */
TCPSocket tcpsocket(interface);
for (int tries = 0; tries < MAX_RETRIES; tries++) {
result = tcpsocket.connect(dl_host, 80);
TEST_ASSERT_MESSAGE(result != NSAPI_ERROR_NO_SOCKET, "out of sockets");
if (result == 0) {
break;
}
ThisThread::sleep_for(1000);
printf("[NET-%d] Connection failed. Retry %d of %d\r\n", thread_id, tries, MAX_RETRIES);
}
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "failed to connect");
if (thread_id == 0) {
// technically this is non-threaded mode
tcpsocket.sigio(socket_event_0);
} else if (thread_id == 1) {
tcpsocket.sigio(socket_event_1);
} else if (thread_id == 2) {
tcpsocket.sigio(socket_event_2);
} else if (thread_id == 3) {
tcpsocket.sigio(socket_event_3);
} else if (thread_id == 4) {
tcpsocket.sigio(socket_event_4);
} else {
TEST_ASSERT_MESSAGE(0, "wrong thread id");
}
printf("[NET-%d] Registered socket callback function\r\n", thread_id);
event_fired[thread_id] = false;
/* setup request */
char *request = g_request_buffer[thread_id];
/* construct request */
size_t req_len = snprintf(request, REQ_BUF_SIZE - 1, req_template, dl_path, dl_host);
request[req_len] = 0;
printf("[NET-%d] Request header (%u): %s\r\n", thread_id, req_len, request);
/* send request to server */
result = tcpsocket.send(request, req_len);
TEST_ASSERT_EQUAL_INT_MESSAGE(req_len, result, "failed to send");
/* read response */
char *receive_buffer = &g_receive_buffer[thread_id * RECV_BUF_SIZE];
tcpsocket.set_blocking(false);
printf("[NET-%d] Non-blocking socket mode set\r\n", thread_id);
size_t received_bytes = 0;
int body_index = -1;
float speed;
float percent;
uint32_t time_left;
Timer timer;
timer.start();
/* loop until all expected bytes have been received */
while (received_bytes < data_length) {
/* wait for async event */
while (!event_fired[thread_id]) {
if (thread_id > 0) {
ThisThread::yield();
}
}
event_fired[thread_id] = false;
/* loop until all data has been read from socket */
do {
result = tcpsocket.recv(receive_buffer, buff_size);
TEST_ASSERT_MESSAGE((result == NSAPI_ERROR_WOULD_BLOCK) || (result >= 0),
"failed to read socket");
if (result > 0) {
/* skip HTTP header */
if (body_index < 0) {
/* note that there are no required Response headers and their length may greatly vary */
std::string header(receive_buffer, result);
body_index = header.find("\r\n\r\n");
if (body_index < 0) {
continue;
} else {
printf("[NET-%d] Found body index: %d\r\n", thread_id, body_index);
/* remove header before comparison */
memmove(receive_buffer, &receive_buffer[body_index + 4], result - body_index - 4);
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(data, receive_buffer, result - body_index - 4,
"character mismatch in header");
received_bytes += (result - body_index - 4);
}
} else {
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(&data[received_bytes], receive_buffer, result,
"character mismatch in body");
received_bytes += result;
}
speed = float(received_bytes) / timer.read();
percent = float(received_bytes) * 100 / float(data_length);
time_left = (data_length - received_bytes) / speed;
printf("[NET-%d] Received bytes: %u, (%.2f%%, %.2fKB/s, ETA: %02d:%02d:%02d)\r\n",
thread_id, received_bytes, percent, speed / 1024,
time_left / 3600, (time_left / 60) % 60, time_left % 60);
}
} while ((result > 0) && (received_bytes < data_length));
}
TEST_ASSERT_MESSAGE(body_index >= 0, "failed to find body");
timer.stop();
float f_received_bytes = float(received_bytes);
printf("[NET-%d] Downloaded: %.2fKB (%.2fKB/s, %.2f secs)\r\n", thread_id,
f_received_bytes / 1024.,
f_received_bytes / (timer.read() * 1024.),
timer.read());
return received_bytes;
}

View File

@ -1,5 +1,8 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,10 +16,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test_env.h"
int main()
{
GREENTEA_SETUP(15, "default_auto");
GREENTEA_TESTSUITE_RESULT(true);
}
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
size_t download_test(NetworkInterface *interface, const unsigned char *data, size_t data_length, size_t buff_size, uint32_t thread_id = 0);

View File

@ -0,0 +1,105 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "unity/unity.h"
void file_test_write(const char *file, size_t offset, const unsigned char *data, size_t data_length, size_t block_size)
{
char filename[255] = { 0 };
snprintf(filename, 255, "/sd/%s", file);
FILE *output = fopen(filename, "w+");
TEST_ASSERT_NOT_NULL_MESSAGE(output, "could not open file");
int result = fseek(output, offset, SEEK_SET);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "could not seek to location");
Timer timer;
timer.start();
size_t index = 0;
while (index < data_length) {
size_t write_length = data_length - index;
if (write_length > block_size) {
write_length = block_size;
}
size_t written = fwrite(&data[index], sizeof(unsigned char), write_length, output);
TEST_ASSERT_EQUAL_UINT_MESSAGE(write_length, written, "failed to write");
index += write_length;
}
TEST_ASSERT_EQUAL_UINT_MESSAGE(index, data_length, "wrong length");
result = fclose(output);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "could not close file");
timer.stop();
printf("[FS] Wrote: \"%s\" %.2fKB (%.2fKB/s, %.2f secs)\r\n", file,
float(data_length) / 1024, float(data_length) / timer.read() / 1024, timer.read());
}
void file_test_read(const char *file, size_t offset, const unsigned char *data, size_t data_length, size_t block_size)
{
char filename[255] = { 0 };
snprintf(filename, 255, "/sd/%s", file);
FILE *output = fopen(filename, "r");
TEST_ASSERT_NOT_NULL_MESSAGE(output, "could not open file");
int result = fseek(output, offset, SEEK_SET);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "could not seek to location");
char *buffer = (char *) malloc(block_size);
TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "could not allocate buffer");
Timer timer;
timer.start();
size_t index = 0;
while (index < data_length) {
uint32_t read_length = data_length - index;
if (read_length > block_size) {
read_length = block_size;
}
size_t read = fread(buffer, sizeof(char), read_length, output);
TEST_ASSERT_EQUAL_MESSAGE(read, read_length, "failed to read");
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(buffer, &data[index], read_length, "character mismatch");
index += read_length;
}
TEST_ASSERT_EQUAL_UINT_MESSAGE(index, data_length, "wrong length");
result = fclose(output);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "could not close file");
free(buffer);
printf("[FS] Read : \"%s\" %.2fKB (%.2fKB/s, %.2f secs)\r\n", file,
float(data_length) / 1024, float(data_length) / timer.read() / 1024, timer.read());
}

View File

@ -0,0 +1,26 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2018 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
void file_test_write(const char *file, size_t offset, const unsigned char *data, size_t data_length, size_t block_size);
void file_test_read(const char *file, size_t offset, const unsigned char *data, size_t data_length, size_t block_size);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,248 @@
{
"target_overrides": {
"NUCLEO_F412ZG": {
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "D11",
"sd.SPI_MISO" : "D12",
"sd.SPI_CLK" : "D13",
"sd.SPI_CS" : "D10",
"target.components_add" : ["WIFI_WIZFI310"],
"target.network-default-interface-type" : "WIFI",
"wizfi310.tx" : "PD_5",
"wizfi310.rx" : "PD_6",
"wizfi310.rts" : "PD_4",
"wizfi310.cts" : "PD_3",
"wizfi310.rx-buffer-size" : 512,
"wizfi310.stacksize" : 1536,
"wizfi310.event-queue-size" : 1024,
"wizfi310.provide-default" : true
},
"NUCLEO_F429ZI": {
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "PC_12",
"sd.SPI_MISO" : "PC_11",
"sd.SPI_CLK" : "PC_10",
"sd.SPI_CS" : "PC_9"
},
"NUCLEO_F767ZI": {
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "PC_12",
"sd.SPI_MISO" : "PC_11",
"sd.SPI_CLK" : "PC_10",
"sd.SPI_CS" : "PC_9"
},
"NUCLEO_F746ZG": {
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "PC_12",
"sd.SPI_MISO" : "PC_11",
"sd.SPI_CLK" : "PC_10",
"sd.SPI_CS" : "PC_9"
},
"NUCLEO_F207ZG": {
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "PC_12",
"sd.SPI_MISO" : "PC_11",
"sd.SPI_CLK" : "PC_10",
"sd.SPI_CS" : "PC_9"
},
"NUCLEO_L476RG": {
"target.macros_remove" : ["MBED_TICKLESS"],
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "D11",
"sd.SPI_MISO" : "D12",
"sd.SPI_CLK" : "D13",
"sd.SPI_CS" : "D10",
"target.components_add" : ["WIFI_WIZFI310"],
"target.network-default-interface-type" : "WIFI",
"wizfi310.tx" : "D8",
"wizfi310.rx" : "D2",
"wizfi310.rts" : "D3",
"wizfi310.cts" : "D5",
"wizfi310.rx-buffer-size" : 64,
"wizfi310.stacksize" : 1536,
"wizfi310.event-queue-size" : 256,
"wizfi310.provide-default" : true,
"no_led" : "1"
},
"NUCLEO_L4R5ZI": {
"target.macros_remove" : ["MBED_TICKLESS"],
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "D11",
"sd.SPI_MISO" : "D12",
"sd.SPI_CLK" : "D13",
"sd.SPI_CS" : "D10",
"target.network-default-interface-type" : "WIFI",
"target.components_add" : ["WIFI_WIZFI310"],
"wizfi310.tx" : "D1",
"wizfi310.rx" : "D0",
"wizfi310.rts" : "PB_1",
"wizfi310.cts" : "PB_13",
"wizfi310.rx-buffer-size" : 512,
"wizfi310.stacksize" : 1536,
"wizfi310.event-queue-size" : 1024,
"wizfi310.provide-default" : true
},
"NUCLEO_L496ZG": {
"target.macros_remove" : ["MBED_TICKLESS"],
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "D11",
"sd.SPI_MISO" : "D12",
"sd.SPI_CLK" : "D13",
"sd.SPI_CS" : "D10",
"target.components_add" : ["WIFI_WIZFI310"],
"target.network-default-interface-type" : "WIFI",
"wizfi310.tx" : "D1",
"wizfi310.rx" : "D0",
"wizfi310.rts" : "PB_1",
"wizfi310.cts" : "PB_13",
"wizfi310.rx-buffer-size" : 512,
"wizfi310.stacksize" : 1536,
"wizfi310.event-queue-size" : 1024,
"wizfi310.provide-default" : true
},
"DISCO_L475VG_IOT01A": {
"target.macros_remove" : ["MBED_TICKLESS"],
"target.components_add" : ["WIFI_ISM43362"],
"target.network-default-interface-type" : "WIFI"
},
"DISCO_L496AG": {
"target.macros_remove" : ["MBED_TICKLESS"],
"target.components_add" : ["WIFI_WIZFI310"],
"target.network-default-interface-type" : "WIFI",
"wizfi310.tx" : "PB_6",
"wizfi310.rx" : "PG_10",
"wizfi310.rts" : "PG_12",
"wizfi310.cts" : "PG_11",
"wizfi310.rx-buffer-size" : 512,
"wizfi310.stacksize" : 1536,
"wizfi310.event-queue-size" : 1024,
"wizfi310.provide-default" : true
},
"DISCO_F413ZH": {
"target.components_add" : ["WIFI_ISM43362"],
"target.network-default-interface-type" : "WIFI"
},
"DISCO_F469NI": {
"target.components_add" : ["WIFI_WIZFI310"],
"target.network-default-interface-type" : "WIFI",
"wizfi310.tx" : "D1",
"wizfi310.rx" : "D0",
"wizfi310.rts" : "D4",
"wizfi310.cts" : "D2",
"wizfi310.rx-buffer-size" : 512,
"wizfi310.stacksize" : 1536,
"wizfi310.event-queue-size" : 1024,
"wizfi310.provide-default" : true
},
"NUMAKER_PFM_NUC472": {
"target.components_add" : ["NUSD"],
"drivers.uart-serial-rxbuf-size" : 1024,
"drivers.uart-serial-txbuf-size" : 1024
},
"NUMAKER_PFM_M487": {
"target.components_add" : ["NUSD"],
"drivers.uart-serial-rxbuf-size" : 1024,
"drivers.uart-serial-txbuf-size" : 1024
},
"NUMAKER_IOT_M487": {
"target.components_add" : ["NUSD"],
"target.network-default-interface-type" : "WIFI",
"esp8266.tx" : "PH_8",
"esp8266.rx" : "PH_9",
"esp8266.provide-default" : true,
"drivers.uart-serial-rxbuf-size" : 1024,
"drivers.uart-serial-txbuf-size" : 1024
},
"SDT64B": {
"target.components_add" : ["SD"],
"sd.SPI_MOSI" : "PTB16",
"sd.SPI_MISO" : "PTB17",
"sd.SPI_CLK" : "PTB11",
"sd.SPI_CS" : "PTB10"
},
"GR_LYCHEE": {
"target.components_add" : ["WIFI_ESP32"],
"target.network-default-interface-type" : "WIFI"
},
"RZ_A1H": {
"target.macros_add" : ["MBEDTLS_TEST_NULL_ENTROPY", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES"]
},
"UBLOX_C030_U201": {
"target.features_add" : ["STORAGE", "LWIP"],
"target.network-default-interface-type" : "CELLULAR",
"lwip.ipv4-enabled" : true,
"lwip.ethernet-enabled" : false,
"lwip.ppp-enabled" : true,
"lwip.tcp-enabled" : true,
"mbed-trace.enable" : false
},
"MTB_MXCHIP_EMW3166": {
"target.components_add" : ["SPIF"],
"spif-driver.SPI_MOSI" : "PB_15",
"spif-driver.SPI_MISO" : "PB_14",
"spif-driver.SPI_CLK" : "PB_13",
"spif-driver.SPI_CS" : "PA_10"
},
"EFM32GG11_STK3701": {
"target.components_add" : ["QSPIF"],
"qspif.QSPI_FREQ" : 10000000
},
"TB_SENSE_12": {
"target.components_add" : ["SPIF"],
"spif-driver.SPI_MOSI" : "PK0",
"spif-driver.SPI_MISO" : "PK2",
"spif-driver.SPI_CLK" : "PF7",
"spif-driver.SPI_CS" : "PK1",
"spif-driver.SPI_FREQ" : 10000000,
"target.network-default-interface-type" : "MESH",
"mbed-mesh-api.thread-config-channel" : 22,
"mbed-mesh-api.thread-config-panid" : "0x0700",
"nsapi.default-mesh-type" : "THREAD",
"nanostack.configuration" : "thread_router",
"nanostack-hal.event_loop_thread_stack_size": 8192
},
"MTB_USI_WM_BN_BM_22": {
"target.components_add" : ["SPIF"],
"spif-driver.SPI_MOSI" : "PC_3",
"spif-driver.SPI_MISO" : "PC_2",
"spif-driver.SPI_CLK" : "PB_13",
"spif-driver.SPI_CS" : "PA_6"
},
"MTB_ADV_WISE_1570": {
"target.components_add" : ["SPIF"],
"spif-driver.SPI_FREQ" : 20000000,
"target.network-default-interface-type" : "CELLULAR",
"cellular.debug-at" : false,
"cellular.use-apn-lookup" : false,
"platform.stdio-baud-rate" : 115200,
"platform.default-serial-baud-rate" : 115200,
"nsapi.dns-response-wait-time" : 30000
},
"MTB_ADV_WISE_1530": {
"target.components_add" : ["SPIF"],
"spif-driver.SPI_MOSI" : "PC_3",
"spif-driver.SPI_MISO" : "PC_2",
"spif-driver.SPI_CLK" : "PB_13",
"spif-driver.SPI_CS" : "PC_12",
"no_led" : "1",
"tests-fs-size" : "2*1024*1024"
}
},
"config": {
"format-storage-layer-on-error": {
"help": "Whether to format the storage layer when it cannot be read - always disable for production devices!",
"value": 1
},
"main-stack-size": {
"value": 6000
},
"no_led": {
"help": "This flag disables the heartbeat thread in tests. This is useful for platforms that don't have an LED or the LED is used for other functionality like LED on the SPI clockline etc",
"value": null
},
"tests-fs-size": {
"help": "Maximum size of the file system used for tests",
"value": null
}
}
}

View File

@ -0,0 +1,164 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "FATFileSystem.h"
#include "LittleFileSystem.h"
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "common_defines_test.h"
#include "file_test.h"
#if !INTEGRATION_TESTS
#error [NOT_SUPPORTED] integration tests not enabled for this target
#endif
#ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
#include MBED_CONF_APP_BASICS_TEST_FILENAME
#else
#include "sample.h"
#endif
#ifndef MBED_CONF_APP_TESTS_FS_SIZE
#define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
#endif
using namespace utest::v1;
#if !defined(MBED_CONF_APP_NO_LED)
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void led_thread()
{
led1 = !led1;
led2 = !led1;
}
#endif
BlockDevice *bd = BlockDevice::get_default_instance();
SlicingBlockDevice sd(bd, 0, MBED_CONF_APP_TESTS_FS_SIZE);
#if TEST_USE_FILESYSTEM == FS_FAT
FATFileSystem fs("sd");
#else
LittleFileSystem fs("sd");
#endif
static control_t test_format(const size_t call_count)
{
int mount_err = fs.mount(&sd);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, mount_err, "could not mount block device");
int format_err = fs.reformat(&sd);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, format_err, "could not format block device");
return CaseNext;
}
static control_t test_block_size_1(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 1);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 1);
return CaseNext;
}
static control_t test_block_size_4(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 4);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 4);
return CaseNext;
}
static control_t test_block_size_16(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 16);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 16);
return CaseNext;
}
static control_t test_block_size_64(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 64);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 64);
return CaseNext;
}
static control_t test_block_size_256(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 256);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 256);
return CaseNext;
}
static control_t test_block_size_1k(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 1024);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 1024);
return CaseNext;
}
static control_t test_block_size_4k(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 4 * 1024);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 4 * 1024);
return CaseNext;
}
static control_t test_block_size_16k(const size_t call_count)
{
file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 16 * 1024);
file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 16 * 1024);
return CaseNext;
}
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(5 * 60, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " format", test_format),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 1", test_block_size_1),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 4", test_block_size_4),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 16", test_block_size_16),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 64", test_block_size_64),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 256", test_block_size_256),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 1024", test_block_size_1k),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 4096", test_block_size_4k),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 16384", test_block_size_16k),
};
Specification specification(greentea_setup, cases);
int main()
{
//Create a thread to blink an LED and signal that the device is alive
#if !defined(MBED_CONF_APP_NO_LED)
Ticker t;
t.attach(led_thread, 0.5);
#endif
return !Harness::run(specification);
}

View File

@ -0,0 +1,183 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "FATFileSystem.h"
#include "LittleFileSystem.h"
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "common_defines_test.h"
#include "file_test.h"
#if !INTEGRATION_TESTS
#error [NOT_SUPPORTED] integration tests not enabled for this target
#endif
#ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
#include MBED_CONF_APP_BASICS_TEST_FILENAME
#else
#include "sample.h"
#endif
#ifndef MBED_CONF_APP_TESTS_FS_SIZE
#define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
#endif
using namespace utest::v1;
#if !defined(MBED_CONF_APP_NO_LED)
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void led_thread()
{
led1 = !led1;
led2 = !led1;
}
#endif
BlockDevice *bd = BlockDevice::get_default_instance();
SlicingBlockDevice sd(bd, 0, MBED_CONF_APP_TESTS_FS_SIZE);
#if TEST_USE_FILESYSTEM == FS_FAT
FATFileSystem fs("sd");
#else
LittleFileSystem fs("sd");
#endif
static control_t test_format(const size_t call_count)
{
int format_err = fs.format(&sd);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, format_err, "could not format block device");
int mount_err = fs.mount(&sd);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, mount_err, "could not mount block device");
return CaseNext;
}
static uint32_t thread_counter = 0;
void file_fn(size_t buffer)
{
uint32_t thread_id = core_util_atomic_incr_u32(&thread_counter, 1);
char filename[255] = { 0 };
snprintf(filename, 255, "mbed-file-test-%d.txt", thread_id);
file_test_write(filename, 0, story, sizeof(story), buffer);
file_test_read(filename, 0, story, sizeof(story), buffer);
}
void file_4b_fn()
{
return file_fn(4);
}
void file_256b_fn()
{
return file_fn(256);
}
void file_1kb_fn()
{
return file_fn(1024);
}
void file_2kb_fn()
{
return file_fn(2048);
}
void file_4kb_fn()
{
return file_fn(4096);
}
static control_t file_2_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
t1.start(file_4b_fn);
t2.start(file_256b_fn);
t1.join();
t2.join();
return CaseNext;
}
static control_t file_3_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
Thread t3;
t1.start(file_256b_fn);
t2.start(file_1kb_fn);
t3.start(file_4kb_fn);
t1.join();
t2.join();
t3.join();
return CaseNext;
}
static control_t file_4_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
Thread t3;
Thread t4;
t1.start(file_256b_fn);
t2.start(file_256b_fn);
t3.start(file_1kb_fn);
t4.start(file_2kb_fn);
t1.join();
t2.join();
t3.join();
t4.join();
return CaseNext;
}
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10 * 60, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " format", test_format),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 2 files, buff 4b/256b", file_2_threads),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 3 files, buff 256b/1kb/4kb", file_3_threads),
};
Specification specification(greentea_setup, cases);
int main()
{
//Create a thread to blink an LED and signal that the device is alive
#if !defined(MBED_CONF_APP_NO_LED)
Ticker t;
t.attach(led_thread, 0.5);
#endif
return !Harness::run(specification);
}

View File

@ -0,0 +1,141 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "common_defines_test.h"
#include "download_test.h"
#include <string>
#if !INTEGRATION_TESTS
#error [NOT_SUPPORTED] integration tests not enabled for this target
#endif
#ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
#include MBED_CONF_APP_BASICS_TEST_FILENAME
#else
#include "sample.h"
#endif
#ifndef MBED_CONF_APP_TESTS_FS_SIZE
#define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
#endif
using namespace utest::v1;
#if !defined(MBED_CONF_APP_NO_LED)
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void led_thread()
{
led1 = !led1;
led2 = !led1;
}
#endif
#define MAX_RETRIES 3
NetworkInterface *interface = NULL;
static control_t setup_network(const size_t call_count)
{
interface = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(interface, "failed to initialize network");
nsapi_error_t err = -1;
for (int tries = 0; tries < MAX_RETRIES; tries++) {
err = interface->connect();
if (err == NSAPI_ERROR_OK) {
break;
} else {
printf("[ERROR] Connecting to network. Retrying %d of %d.\r\n", tries, MAX_RETRIES);
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("[NET] IP address is '%s'\n", interface->get_ip_address());
printf("[NET] MAC address is '%s'\n", interface->get_mac_address());
return CaseNext;
}
static control_t download_128(const size_t call_count)
{
download_test(interface, story, sizeof(story), 128);
return CaseNext;
}
static control_t download_256(const size_t call_count)
{
download_test(interface, story, sizeof(story), 256);
return CaseNext;
}
static control_t download_1k(const size_t call_count)
{
download_test(interface, story, sizeof(story), 1024);
return CaseNext;
}
static control_t download_2k(const size_t call_count)
{
download_test(interface, story, sizeof(story), 2 * 1024);
return CaseNext;
}
static control_t download_4k(const size_t call_count)
{
download_test(interface, story, sizeof(story), 4 * 1024);
return CaseNext;
}
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(8 * 60, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case(TEST_NETWORK_TYPE " network setup", setup_network),
Case(TEST_NETWORK_TYPE " 128 buffer", download_128),
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != CELLULAR
Case(TEST_NETWORK_TYPE " 256 buffer", download_256),
Case(TEST_NETWORK_TYPE " 1024 buffer", download_1k),
Case(TEST_NETWORK_TYPE " 4096 buffer", download_4k),
#endif
};
Specification specification(greentea_setup, cases);
int main()
{
//Create a thread to blink an LED and signal that the device is alive
#if !defined(MBED_CONF_APP_NO_LED)
Ticker t;
t.attach(led_thread, 0.5);
#endif
return !Harness::run(specification);
}

View File

@ -0,0 +1,175 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "common_defines_test.h"
#include "download_test.h"
#include <string>
#if !INTEGRATION_TESTS
#error [NOT_SUPPORTED] integration tests not enabled for this target
#endif
#ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
#include MBED_CONF_APP_BASICS_TEST_FILENAME
#else
#include "sample.h"
#endif
#ifndef MBED_CONF_APP_TESTS_FS_SIZE
#define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
#endif
using namespace utest::v1;
#if !defined(MBED_CONF_APP_NO_LED)
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void led_thread()
{
led1 = !led1;
led2 = !led1;
}
#endif
#define MAX_RETRIES 3
NetworkInterface *net = NULL;
static control_t setup_network(const size_t call_count)
{
net = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(net, "failed to initialize network");
nsapi_error_t err = -1;
for (int tries = 0; tries < MAX_RETRIES; tries++) {
err = net->connect();
if (err == NSAPI_ERROR_OK) {
break;
} else {
printf("[ERROR] Connecting to network. Retrying %d of %d.\r\n", tries, MAX_RETRIES);
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("[NET] IP address is '%s'\n", net->get_ip_address());
printf("[NET] MAC address is '%s'\n", net->get_mac_address());
return CaseNext;
}
static uint32_t thread_counter = 0;
void download_fn()
{
uint32_t thread_id = core_util_atomic_incr_u32(&thread_counter, 1);
download_test(net, story, sizeof(story), 1024, thread_id);
}
static control_t download_1_thread(const size_t call_count)
{
thread_counter = 0;
Thread t1;
t1.start(download_fn);
t1.join();
return CaseNext;
}
static control_t download_2_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
t1.start(download_fn);
wait(0.5);
t2.start(download_fn);
t2.join();
t1.join();
return CaseNext;
}
static control_t download_3_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
Thread t3;
t1.start(download_fn);
t2.start(download_fn);
t3.start(download_fn);
t1.join();
t2.join();
t3.join();
return CaseNext;
}
static control_t download_4_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
Thread t3;
Thread t4;
t1.start(download_fn);
t2.start(download_fn);
t3.start(download_fn);
t4.start(download_fn);
t1.join();
t2.join();
t3.join();
t4.join();
return CaseNext;
}
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(12 * 60, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case(TEST_NETWORK_TYPE " network setup", setup_network),
Case(TEST_NETWORK_TYPE " 1 thread", download_1_thread),
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != CELLULAR
Case(TEST_NETWORK_TYPE " 2 threads", download_2_threads),
#endif
};
Specification specification(greentea_setup, cases);
int main()
{
//Create a thread to blink an LED and signal that the device is alive
#if !defined(MBED_CONF_APP_NO_LED)
Ticker t;
t.attach(led_thread, 0.5);
#endif
return !Harness::run(specification);
}

View File

@ -0,0 +1,245 @@
/*
* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
/*
* Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
*/
#include "mbed.h"
#include "FATFileSystem.h"
#include "LittleFileSystem.h"
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "common_defines_test.h"
#include "download_test.h"
#include "file_test.h"
#include <string>
#if !INTEGRATION_TESTS
#error [NOT_SUPPORTED] integration tests not enabled for this target
#endif
#ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
#include MBED_CONF_APP_BASICS_TEST_FILENAME
#else
#include "sample.h"
#endif
#ifndef MBED_CONF_APP_TESTS_FS_SIZE
#define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
#endif
using namespace utest::v1;
#if !defined(MBED_CONF_APP_NO_LED)
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void led_thread()
{
led1 = !led1;
led2 = !led1;
}
#endif
#define MAX_RETRIES 3
NetworkInterface *interface = NULL;
static control_t setup_network(const size_t call_count)
{
interface = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(interface, "failed to initialize network");
nsapi_error_t err = -1;
for (int tries = 0; tries < MAX_RETRIES; tries++) {
err = interface->connect();
if (err == NSAPI_ERROR_OK) {
break;
} else {
printf("[ERROR] Connecting to network. Retrying %d of %d...\r\n", tries, MAX_RETRIES);
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("[NET] IP address is '%s'\n", interface->get_ip_address());
printf("[NET] MAC address is '%s'\n", interface->get_mac_address());
return CaseNext;
}
BlockDevice *bd = BlockDevice::get_default_instance();
SlicingBlockDevice sd(bd, 0, MBED_CONF_APP_TESTS_FS_SIZE);
#if TEST_USE_FILESYSTEM == FS_FAT
FATFileSystem fs("sd");
#else
LittleFileSystem fs("sd");
#endif
static control_t test_format(const size_t call_count)
{
int format_err = fs.format(&sd);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, format_err, "could not format block device");
int mount_err = fs.mount(&sd);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, mount_err, "could not mount block device");
return CaseNext;
}
static uint32_t thread_counter = 0;
void download_fn()
{
uint32_t thread_id = core_util_atomic_incr_u32(&thread_counter, 1);
download_test(interface, story, sizeof(story), 256, thread_id);
}
void file_fn(size_t buffer)
{
uint32_t thread_id = core_util_atomic_incr_u32(&thread_counter, 1);
char filename[255] = { 0 };
snprintf(filename, 255, "mbed-file-test-%d.txt", thread_id);
file_test_write(filename, 0, story, sizeof(story), buffer);
file_test_read(filename, 0, story, sizeof(story), buffer);
}
void file_1b_fn()
{
return file_fn(1);
}
void file_4b_fn()
{
return file_fn(4);
}
void file_256b_fn()
{
return file_fn(256);
}
void file_1kb_fn()
{
return file_fn(1024);
}
static control_t stress_1_thread(const size_t call_count)
{
thread_counter = 0;
Thread t1;
t1.start(download_fn);
t1.join();
t1.start(file_1kb_fn);
t1.join();
return CaseNext;
}
static control_t stress_2_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
t1.start(file_1kb_fn);
wait(1);
t2.start(download_fn);
t2.join();
t1.join();
return CaseNext;
}
static control_t stress_3_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
Thread t3;
t1.start(file_256b_fn);
t2.start(file_1kb_fn);
wait(1);
t3.start(download_fn);
t3.join();
t2.join();
t1.join();
return CaseNext;
}
static control_t stress_4_threads(const size_t call_count)
{
thread_counter = 0;
Thread t1;
Thread t2;
Thread t3;
Thread t4;
t1.start(file_256b_fn);
t2.start(file_256b_fn);
t3.start(file_256b_fn);
wait(1);
t4.start(download_fn);
t4.join();
t3.join();
t2.join();
t1.join();
return CaseNext;
}
template <uint32_t size>
void test_malloc()
{
void *bufferTest = NULL;
TEST_ASSERT_MESSAGE(size > 0, "Size must not be zero for test");
printf("Allocating %d bytes", (int)size);
bufferTest = malloc(size);
TEST_ASSERT(bufferTest != NULL);
free(bufferTest);
}
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(12 * 60, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case(TEST_NETWORK_TYPE " network setup", setup_network),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " format", test_format),
Case("Test memory allocation of 10 K bytes", test_malloc<TEST_MEMORY_SIZE_10K>),
Case("Test memory allocation of 20 K bytes", test_malloc<TEST_MEMORY_SIZE_20K>),
Case("Test memory allocation of 40 K bytes", test_malloc<TEST_MEMORY_SIZE_40K>),
Case("Test memory allocation of 60 K bytes", test_malloc<TEST_MEMORY_SIZE_60K>),
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != CELLULAR
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE "+" TEST_NETWORK_TYPE " 1 thread, dl, file seq.", stress_1_thread),
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE "+" TEST_NETWORK_TYPE " 2 threads, dl, 1kb", stress_2_threads),
#endif
Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE "+" TEST_NETWORK_TYPE " 3 threads, dl, 256b, 1kb", stress_3_threads),
};
Specification specification(greentea_setup, cases);
int main()
{
//Create a thread to blink an LED and signal that the device is alive
#if !defined(MBED_CONF_APP_NO_LED)
Ticker t;
t.attach(led_thread, 0.5);
#endif
return !Harness::run(specification);
}