Tests for simple blinky library.

Dependencies:   Blinky

Fork of Blinky_Tests by Sarah Marsh

TESTS/Blinky/5_Blinks/main.cpp

Committer:
mbed_demo
Date:
2016-11-08
Revision:
4:09af3b2d723e
Parent:
2:a6755ef75598
Child:
5:4f1e6b065e6b

File content as of revision 4:09af3b2d723e:

#include "Blinky.h"
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "rtos.h"
 
using namespace utest::v1;
 
//All tests will blink the LED 5 times
const int expected_blinks = 5;
//To be set by interrupt handler
 
//Generic blink test
//interval => the the amount of time between blinks
//led => PinName of LED to blink
void test_blinks(PinName led, int interval){
    //Set an appropriate wait time to measure exactly expected_blinks
    //with the given interval 
    float wait_time = 2*interval*expected_blinks;
    //Create Blinky
    Blinky blinker(led, interval);
    //start blinky
    blinker.start();
    //Wait the appropriate amount of time for expected_blinks 
    Thread::wait(wait_time);
    blinker.stop();
    
    float measured_blinks = blinker.times_blinked();
    //Only assert if failure
    TEST_ASSERT(measured_blinks == (float)expected_blinks);
}
 
void blink_500(){
    //Blinky with a 500 ms interval between blinks
    test_blinks(LED1, 500);
}
void blink_1000(){
    //Blinky with a 1000 ms interval between blinks
    test_blinks(LED1, 1000);
}
 
utest::v1::status_t test_setup(const size_t number_of_cases) {
    // Setup Greentea using a reasonable timeout in seconds
    GREENTEA_SETUP(40, "default_auto");
    return verbose_test_setup_handler(number_of_cases);
}
 
// Test cases
Case cases[] = {
    Case("Testing 500 ms interval", blink_500),
    Case("Testing 1000 ms interval", blink_1000),
};
 
Specification specification(test_setup, cases);
 
// Entry point into the tests
int main() {
    return !Harness::run(specification);
}