From 908003b4cd0098e41867295fa7bfb515940ac3c8 Mon Sep 17 00:00:00 2001 From: Austin Blackstone Date: Wed, 13 Jul 2016 18:06:21 -0500 Subject: [PATCH] adding assert failure messages --- TESTS/API/AnalogOut/AnalogOut.cpp | 108 +++++++++++++++--------------- TESTS/API/SPI/SPI.cpp | 2 +- TESTS/API/UART/UART.cpp | 5 +- 3 files changed, 57 insertions(+), 58 deletions(-) diff --git a/TESTS/API/AnalogOut/AnalogOut.cpp b/TESTS/API/AnalogOut/AnalogOut.cpp index 45b94fe..8c47e9b 100644 --- a/TESTS/API/AnalogOut/AnalogOut.cpp +++ b/TESTS/API/AnalogOut/AnalogOut.cpp @@ -1,54 +1,54 @@ -#include "mbed.h" -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "rtos.h" - -using namespace utest::v1; - -// Template to set one Analog pin as input and then cycle through the rest as outputs. -// As you turn more pins on the voltage on the ain pin will go up. -template -void AnalogOutput_Test() -{ - AnalogIn ain(ain_pin); - AnalogOut aout(aout_pin); - float valueOff = 0; - float valueOn = 0; - aout = 0; - valueOff = ain.read(); - aout = 0.5; - valueOn = ain.read(); - printf("***** valueOff = %f, valueOn = %f \n",valueOff, valueOn); - TEST_ASSERT(valueOn > valueOff); - valueOff = ain.read(); - aout = 1.0; - valueOn = ain.read(); - printf("***** valueOff = %f, valueOn = %f \n",valueOff, valueOn); - TEST_ASSERT(valueOn > valueOff); -} - -utest::v1::status_t test_setup(const size_t number_of_cases) { - // Setup Greentea using a reasonable timeout in seconds - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -// Handle test failures, keep testing, dont stop -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_CONTINUE; -} - -// Test cases -// TODO: take input based on pinmap -Case cases[] = { - Case("Test Analog Output on A5", AnalogOutput_Test,greentea_failure_handler), -}; - -Specification specification(test_setup, cases); - -// Entry point into the tests -int main() { - return !Harness::run(specification); -} +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "rtos.h" + +using namespace utest::v1; + +// Template to set one Analog pin as input and then cycle through the rest as outputs. +// As you turn more pins on the voltage on the ain pin will go up. +template +void AnalogOutput_Test() +{ + AnalogIn ain(ain_pin); + AnalogOut aout(aout_pin); + float valueOff = 0; + float valueOn = 0; + aout = 0; + valueOff = ain.read(); + aout = 0.5; + valueOn = ain.read(); + printf("***** valueOff = %f, valueOn = %f \n",valueOff, valueOn); + TEST_ASSERT(valueOn > valueOff); + valueOff = ain.read(); + aout = 1.0; + valueOn = ain.read(); + printf("***** valueOff = %f, valueOn = %f \n",valueOff, valueOn); + TEST_ASSERT(valueOn > valueOff); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + +// Test cases +// TODO: take input based on pinmap +Case cases[] = { + Case("Test Analog Output on A5", AnalogOutput_Test,greentea_failure_handler), +}; + +Specification specification(test_setup, cases); + +// Entry point into the tests +int main() { + return !Harness::run(specification); +} diff --git a/TESTS/API/SPI/SPI.cpp b/TESTS/API/SPI/SPI.cpp index 88bbfac..c40c10f 100755 --- a/TESTS/API/SPI/SPI.cpp +++ b/TESTS/API/SPI/SPI.cpp @@ -24,7 +24,7 @@ void test_sd_write(){ // Currently no SD Test written, waiting for public release to enable - TEST_ASSERT(false); + TEST_ASSERT_MESSAGE(false,"SD Tests are not supported yet, this is a placeholder for future tests."); } utest::v1::status_t test_setup(const size_t number_of_cases) { diff --git a/TESTS/API/UART/UART.cpp b/TESTS/API/UART/UART.cpp index ece789e..07ab07c 100755 --- a/TESTS/API/UART/UART.cpp +++ b/TESTS/API/UART/UART.cpp @@ -20,12 +20,11 @@ void test_uart_single(){ TEST_ASSERT(UART_SENTINAL == value); if(UART_SENTINAL == value){ // printf("Test Finished Successfully!\n"); - TEST_ASSERT(true); + TEST_ASSERT_MESSAGE(true,"characters match!"); } else{ // printf("Test Failed! \n"); - TEST_ASSERT(false); + TEST_ASSERT_MESSAGE(false,"characters do not match, possible corruption?"); } - TEST_ASSERT(true); } // TODO: add more verbose tests