mirror of https://github.com/ARMmbed/mbed-os.git
Modifying timing tests to use timing drift host test
parent
f6c60d07ac
commit
e678325730
|
@ -21,6 +21,7 @@
|
|||
using namespace utest::v1;
|
||||
|
||||
static const int ONE_SECOND_MS = 1000;
|
||||
static const int total_ticks = 10;
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
@ -28,25 +29,23 @@ DigitalOut led2(LED2);
|
|||
Ticker *ticker1;
|
||||
Ticker *ticker2;
|
||||
|
||||
volatile int ticker_count = 0;
|
||||
volatile bool print_tick = false;
|
||||
|
||||
void send_kv_tick() {
|
||||
static int count = 0;
|
||||
if (count < 10) {
|
||||
greentea_send_kv("tick", count);
|
||||
} else if (count == 10) {
|
||||
count = 0;
|
||||
Harness::validate_callback();
|
||||
if (ticker_count <= total_ticks) {
|
||||
print_tick = true;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
void ticker_callback_0(void) {
|
||||
static int ticker_count = 0;
|
||||
if (ticker_count >= ONE_SECOND_MS) {
|
||||
static int fast_ticker_count = 0;
|
||||
if (fast_ticker_count >= ONE_SECOND_MS) {
|
||||
send_kv_tick();
|
||||
ticker_count = 0;
|
||||
fast_ticker_count = 0;
|
||||
led1 = !led1;
|
||||
}
|
||||
ticker_count++;
|
||||
fast_ticker_count++;
|
||||
}
|
||||
|
||||
void ticker_callback_1(void) {
|
||||
|
@ -78,26 +77,38 @@ void ticker_callback_2_switch_to_1(void) {
|
|||
ticker_callback_2();
|
||||
}
|
||||
|
||||
utest::v1::control_t test_case_1x_ticker() {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
ticker1->attach_us(ticker_callback_0, ONE_SECOND_MS);
|
||||
return CaseTimeout(15 * ONE_SECOND_MS);
|
||||
void wait_and_print() {
|
||||
while(ticker_count <= total_ticks) {
|
||||
if (print_tick) {
|
||||
print_tick = false;
|
||||
greentea_send_kv("tick", ticker_count++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
control_t test_case_2x_ticker() {
|
||||
void test_case_1x_ticker() {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
ticker_count = 0;
|
||||
ticker1->attach_us(ticker_callback_0, ONE_SECOND_MS);
|
||||
wait_and_print();
|
||||
}
|
||||
|
||||
void test_case_2x_ticker() {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
ticker_count = 0;
|
||||
ticker1->attach(&ticker_callback_1, 1.0);
|
||||
ticker2->attach(&ticker_callback_2_led, 2.0);
|
||||
return CaseTimeout(15 * ONE_SECOND_MS);
|
||||
wait_and_print();
|
||||
}
|
||||
|
||||
utest::v1::control_t test_case_2x_callbacks() {
|
||||
void test_case_2x_callbacks() {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
ticker_count = 0;
|
||||
ticker1->attach(ticker_callback_1_switch_to_2, 1.0);
|
||||
return CaseTimeout(15 * ONE_SECOND_MS);
|
||||
wait_and_print();
|
||||
}
|
||||
|
||||
utest::v1::status_t one_ticker_case_setup_handler_t(const Case *const source, const size_t index_of_case) {
|
||||
|
@ -130,7 +141,7 @@ Case cases[] = {
|
|||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(60, "wait_us_auto");
|
||||
GREENTEA_SETUP((total_ticks + 5) * 3, "timing_drift_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,41 +22,51 @@ using namespace utest::v1;
|
|||
|
||||
Timeout timer;
|
||||
DigitalOut led(LED1);
|
||||
volatile int ticker_count = 0;
|
||||
volatile bool print_tick = false;
|
||||
static const int total_ticks = 10;
|
||||
|
||||
namespace {
|
||||
const int MS_INTERVALS = 1000;
|
||||
}
|
||||
|
||||
void send_kv_tick() {
|
||||
static int count = 0;
|
||||
if (count < 10) {
|
||||
greentea_send_kv("tick", count);
|
||||
} else if (count == 10) {
|
||||
Harness::validate_callback();
|
||||
if (ticker_count <= total_ticks) {
|
||||
print_tick = true;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
void toggleOff(void);
|
||||
|
||||
void toggleOn(void) {
|
||||
static int toggle_counter = 0;
|
||||
timer.attach_us(toggleOff, 500);
|
||||
|
||||
if (toggle_counter == MS_INTERVALS) {
|
||||
led = !led;
|
||||
send_kv_tick();
|
||||
toggle_counter = 0;
|
||||
}
|
||||
} else {
|
||||
toggle_counter++;
|
||||
timer.attach_us(toggleOff, 500);
|
||||
}
|
||||
}
|
||||
|
||||
void toggleOff(void) {
|
||||
timer.attach_us(toggleOn, 500);
|
||||
}
|
||||
|
||||
control_t test_case_ticker() {
|
||||
void wait_and_print() {
|
||||
while(ticker_count <= total_ticks) {
|
||||
if (print_tick) {
|
||||
print_tick = false;
|
||||
greentea_send_kv("tick", ticker_count++);
|
||||
led = !led;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_case_ticker() {
|
||||
toggleOn();
|
||||
return CaseTimeout(15 * 1000);
|
||||
wait_and_print();
|
||||
}
|
||||
|
||||
// Test cases
|
||||
|
@ -65,7 +75,7 @@ Case cases[] = {
|
|||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(20, "wait_us_auto");
|
||||
GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,17 +21,27 @@
|
|||
using namespace utest::v1;
|
||||
|
||||
DigitalOut led(LED1);
|
||||
Timer timer;
|
||||
volatile bool print_tick = false;
|
||||
const int ONE_SECOND_US = 1000000;
|
||||
const int total_ticks = 10;
|
||||
|
||||
void test_case_ticker() {
|
||||
for (int i=0; i < 10; ++i) {
|
||||
// 10 secs...
|
||||
for (int j = 0; j < 1000; ++j) {
|
||||
// 1000 * 1000us = 1 sec
|
||||
wait_us(1000);
|
||||
}
|
||||
led = !led; // Blink
|
||||
int before_print_us;
|
||||
int after_print_us;
|
||||
int wait_time_us = ONE_SECOND_US;
|
||||
|
||||
timer.start();
|
||||
for (int i = 0; i <= total_ticks; ++i) {
|
||||
wait_us(wait_time_us);
|
||||
before_print_us = timer.read();
|
||||
greentea_send_kv("tick", i);
|
||||
after_print_us = timer.read();
|
||||
|
||||
// This won't be 100% exact, but it should be pretty close
|
||||
wait_time_us = ONE_SECOND_US - (after_print_us - before_print_us);
|
||||
}
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
// Test cases
|
||||
|
@ -40,7 +50,7 @@ Case cases[] = {
|
|||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(20, "wait_us_auto");
|
||||
GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,25 +29,31 @@
|
|||
#define STACK_SIZE DEFAULT_STACK_SIZE
|
||||
#endif
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
#define SIGNAL_PRINT_TICK 0x01
|
||||
|
||||
void led2_thread(void const *argument) {
|
||||
static int count = 0;
|
||||
while (true) {
|
||||
led2 = !led2;
|
||||
Thread::wait(1000);
|
||||
greentea_send_kv("tick", count++);
|
||||
DigitalOut led1(LED1);
|
||||
|
||||
const int total_ticks = 10;
|
||||
|
||||
void print_tick_thread() {
|
||||
for (int i = 0; i <= total_ticks; i++) {
|
||||
Thread::signal_wait(SIGNAL_PRINT_TICK);
|
||||
greentea_send_kv("tick", i);
|
||||
led1 = !led1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
GREENTEA_SETUP(15, "wait_us_auto");
|
||||
GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto");
|
||||
|
||||
Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);
|
||||
Thread tick_thread(osPriorityNormal, STACK_SIZE);
|
||||
tick_thread.start(print_tick_thread);
|
||||
|
||||
while (true) {
|
||||
led1 = !led1;
|
||||
Thread::wait(500);
|
||||
for (int i = 0; i <= total_ticks; i++) {
|
||||
Thread::wait(1000);
|
||||
tick_thread.signal_set(SIGNAL_PRINT_TICK);
|
||||
}
|
||||
|
||||
tick_thread.join();
|
||||
GREENTEA_TESTSUITE_RESULT(1);
|
||||
}
|
||||
|
|
|
@ -6,23 +6,25 @@
|
|||
#error [NOT_SUPPORTED] test not supported
|
||||
#endif
|
||||
|
||||
int total_ticks = 10;
|
||||
volatile int current_tick = 0;
|
||||
|
||||
DigitalOut LEDs[4] = {
|
||||
DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
|
||||
};
|
||||
|
||||
void blink(void const *n) {
|
||||
static int blink_counter = 0;
|
||||
static int count = 0;
|
||||
const int led_id = int(n);
|
||||
LEDs[led_id] = !LEDs[led_id];
|
||||
if (++blink_counter == 75) {
|
||||
greentea_send_kv("tick", count++);
|
||||
if (++blink_counter == 75 && current_tick <= total_ticks) {
|
||||
greentea_send_kv("tick", current_tick++);
|
||||
blink_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
GREENTEA_SETUP(15, "wait_us_auto");
|
||||
GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto");
|
||||
|
||||
RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
|
||||
RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
|
||||
|
@ -34,5 +36,16 @@ int main(void) {
|
|||
led_3_timer.start(50);
|
||||
led_4_timer.start(25);
|
||||
|
||||
while(current_tick <= total_ticks) {
|
||||
Thread::wait(10);
|
||||
}
|
||||
|
||||
led_4_timer.stop();
|
||||
led_3_timer.stop();
|
||||
led_2_timer.stop();
|
||||
led_1_timer.stop();
|
||||
|
||||
GREENTEA_TESTSUITE_RESULT(1);
|
||||
|
||||
Thread::wait(osWaitForever);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue