mbed-os/TESTS/mbedmicro-rtos-mbed/queue/main.cpp

79 lines
2.9 KiB
C++
Raw Normal View History

Adding test frameworks and test sources This commit adds the following test frameworks: - `greentea-client` (https://github.com/ARMmbed/greentea-client) - This framework provides a key-value api for communicating with the greentea test tool (https://github.com/ARMmbed/greentea) - `unity` (https://github.com/ARMmbed/unity) - This framework provides test assert macros that can be used when writing test cases - `utest` (https://github.com/ARMmbed/utest) - This framework allows you to execute a series of test cases with reporting that works with the greentea test tool (https://github.com/ARMmbed/greentea) The following changes were made when bringing these frameworks into the tree: - References to `mbed_drivers/mbed.h` within utest's tests were migrated to `mbed.h` - The yotta file `module.json` was removed from `greentea-client` and `unity` - `coverage.json` was also removed from `greentea-client` - `.gitignore` and `.gitattributes` were removed from `greentea-client` - Apache 2.0 license files were removed from `greentea-client` This also brings in a number of tests that have been newly written or ported from various sources: - `TESTS/integration` - Very basic tests, used to check if testing frameworks are working correctly - `TESTS/mbed_drivers` (Thanks @PrzemekWirkus!) - TESTS ported from mbed OS 3.0 (https://github.com/ARMmbed/mbed-drivers) - `TESTS/mbedmicro-mbed` (Thanks @PrzemekWirkus!) - Tests that weren't covered by `TESTS/mbed_drivers` that currently live in `libraries/tests/mbed` - `TESTS/mbedmicro-rtos-mbed` (Thanks @PrzemekWirkus!) - Ported tests that currently live in `libraries/tests/rtos/mbed` - `TESTS/storage_abstraction` (Thanks @rgrover!) - Tests for the storage_abstraction hal
2016-07-19 18:39:53 +00:00
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "rtos.h"
typedef struct {
float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */
uint32_t counter; /* A counter value */
} message_t;
#define CREATE_VOLTAGE(COUNTER) (COUNTER * 0.1) * 33
#define CREATE_CURRENT(COUNTER) (COUNTER * 0.1) * 11
#define QUEUE_SIZE 16
#define QUEUE_PUT_DELAY 100
/*
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
*/
#if (defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)) && defined(TOOLCHAIN_GCC)
#define STACK_SIZE DEFAULT_STACK_SIZE/4
#elif (defined(TARGET_STM32F030R8)) && defined(TOOLCHAIN_GCC)
#define STACK_SIZE DEFAULT_STACK_SIZE/4
#elif (defined(TARGET_STM32F030R8)) && defined(TOOLCHAIN_IAR)
#define STACK_SIZE DEFAULT_STACK_SIZE/2
#else
#define STACK_SIZE DEFAULT_STACK_SIZE
#endif
MemoryPool<message_t, QUEUE_SIZE> mpool;
Queue<message_t, QUEUE_SIZE> queue;
/* Send Thread */
void send_thread (void const *argument) {
static uint32_t i = 10;
while (true) {
i++; // Fake data update
message_t *message = mpool.alloc();
message->voltage = CREATE_VOLTAGE(i);
message->current = CREATE_CURRENT(i);
message->counter = i;
queue.put(message);
Thread::wait(QUEUE_PUT_DELAY);
}
}
int main (void) {
GREENTEA_SETUP(20, "default_auto");
Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
bool result = true;
int result_counter = 0;
while (true) {
osEvent evt = queue.get();
if (evt.status == osEventMessage) {
message_t *message = (message_t*)evt.value.p;
const float expected_voltage = CREATE_VOLTAGE(message->counter);
const float expected_current = CREATE_CURRENT(message->counter);
// Check using macros if received values correspond to values sent via queue
bool expected_values = (expected_voltage == message->voltage) &&
(expected_current == message->current);
result = result && expected_values;
const char *result_msg = expected_values ? "OK" : "FAIL";
printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter,
message->voltage,
message->current,
result_msg);
mpool.free(message);
if (result == false || ++result_counter == QUEUE_SIZE) {
break;
}
}
}
GREENTEA_TESTSUITE_RESULT(result);
return 0;
}