![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Tests for simple blinky library.
Fork of Blinky_Tests by
TESTS/Blinky/5_Blinks/main.cpp
- Committer:
- mbed_demo
- Date:
- 2016-11-08
- Revision:
- 2:a6755ef75598
- Parent:
- 1:b0034f8b2c42
- Child:
- 4:09af3b2d723e
File content as of revision 2:a6755ef75598:
#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 int measured_blinks = 0; //To be called by interrupt, increases the number of measured rising edges void count_blinks(){ measured_blinks++; } //Generic blink test //interval => the the amount of time between blinks //led => PinName of LED to blink void test_blinks(PinName led, int interval){ //reset the measured blinks to 0 for each case measured_blinks = 0; //Set an appropriate wait time to measure exactly expected_blinks //with the given interval float wait_time = 2*interval*expected_blinks; //Create an interrupt that calls count_blinks on rising edge of LED pin InterruptIn blink_counter(led); //Create Blinky Blinky blinker(led, interval); //Attach interrupt blink_counter.rise(&count_blinks); //start blinky blinker.start(); //Wait the appropriate amount of time for expected_blinks Thread::wait(wait_time); blinker.stop(); //Only assert if failure TEST_ASSERT(measured_blinks != 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); }