RTOS_6 Mail test automation added ti test suite

pull/234/head
Przemek Wirkus 2014-03-25 11:46:29 +00:00
parent 9a73b5a809
commit 40514add7f
2 changed files with 35 additions and 15 deletions

View File

@ -1,40 +1,59 @@
#include "mbed.h" #include "mbed.h"
#include "test_env.h"
#include "rtos.h" #include "rtos.h"
/* Mail */
typedef struct { typedef struct {
float voltage; /* AD result of measured voltage */ float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */ float current; /* AD result of measured current */
uint32_t counter; /* A counter value */ uint32_t counter; /* A counter value */
} mail_t; } mail_t;
Mail<mail_t, 16> mail_box; #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
Mail<mail_t, QUEUE_SIZE> mail_box;
void send_thread (void const *argument) { void send_thread (void const *argument) {
uint32_t i = 0; static uint32_t i = 10;
while (true) { while (true) {
i++; // fake data update i++; // fake data update
mail_t *mail = mail_box.alloc(); mail_t *mail = mail_box.alloc();
mail->voltage = (i * 0.1) * 33; mail->voltage = CREATE_VOLTAGE(i);
mail->current = (i * 0.1) * 11; mail->current = CREATE_CURRENT(i);
mail->counter = i; mail->counter = i;
mail_box.put(mail); mail_box.put(mail);
Thread::wait(1000); Thread::wait(QUEUE_PUT_DELAY);
} }
} }
int main (void) { int main (void) {
Thread thread(send_thread); Thread thread(send_thread);
bool result = true;
int result_counter = 0;
while (true) { while (true) {
osEvent evt = mail_box.get(); osEvent evt = mail_box.get();
if (evt.status == osEventMail) { if (evt.status == osEventMail) {
mail_t *mail = (mail_t*)evt.value.p; mail_t *mail = (mail_t*)evt.value.p;
printf("\nVoltage: %.2f V\n\r" , mail->voltage); const float expected_voltage = CREATE_VOLTAGE(mail->counter);
printf("Current: %.2f A\n\r" , mail->current); const float expected_current = CREATE_CURRENT(mail->counter);
printf("Number of cycles: %u\n\r", mail->counter); // Check using macros if received values correspond to values sent via queue
bool expected_values = (expected_voltage == mail->voltage) &&
(expected_current == mail->current);
result = result && expected_values;
const char *result_msg = expected_values ? "OK" : "FAIL";
printf("%3d %.2fV %.2fA ... [%s]\r\n", mail->counter,
mail->voltage,
mail->current,
result_msg);
mail_box.free(mail); mail_box.free(mail);
if (result == false || ++result_counter == QUEUE_SIZE) {
break;
} }
} }
}
notify_completion(result);
return 0;
} }

View File

@ -532,7 +532,8 @@ TESTS = [
{ {
"id": "RTOS_6", "description": "Mail", "id": "RTOS_6", "description": "Mail",
"source_dir": join(TEST_DIR, "rtos", "mbed", "mail"), "source_dir": join(TEST_DIR, "rtos", "mbed", "mail"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB],
"automated": True,
}, },
{ {
"id": "RTOS_7", "description": "Timer", "id": "RTOS_7", "description": "Timer",