From 866b019ffb65164a9c9f067933e2a0e95373dc50 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 14 Jul 2017 12:56:11 -0500 Subject: [PATCH 01/21] Removed print statement from Level1/AnalogIn that I added earlier for debug purposes --- TESTS/Level1/AnalogIn/AnalogIn.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index 13718b2..a8314af 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -76,7 +76,6 @@ void test_analogin_execute(PinName pin, float tolerance, int iterations) { // Read the new value to make sure the voltage increased new_value = ain.read(); - DEBUG_PRINTF("new_value on bus = %d\n", new_value); TEST_ASSERT_MESSAGE(new_value > prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file") // Repeat the read multiple times to verify the output is not fluctuating From 104ea910e14410e5eab94a7c45f74811716908c1 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 14 Jul 2017 15:55:50 -0500 Subject: [PATCH 02/21] Fixed bug in BusInOut where it was calling level2 framework instead of level1. Formatted code --- TESTS/Level1/AnalogOut/AnalogOut.cpp | 21 ++++++++++---------- TESTS/Level1/BusInOut/BusInOut.cpp | 29 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/TESTS/Level1/AnalogOut/AnalogOut.cpp b/TESTS/Level1/AnalogOut/AnalogOut.cpp index 36a55dc..ccf75da 100644 --- a/TESTS/Level1/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/AnalogOut/AnalogOut.cpp @@ -38,25 +38,24 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_analogout_execute(PinName pin, float tolerance, int iterations) { +void test_analogout_execute(PinName pin, float tolerance, int iterations){ DEBUG_PRINTF("Running analog output range test on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - // Find all pins on the resistor ladder that are not the current pin + // Find all pins on the resistor ladder that are not the current pin std::vector resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin); - if (resistor_ladder_pins.size() < 5) + if (resistor_ladder_pins.size() < 5){ TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); + } - AnalogIn ain(resistor_ladder_pins[0]); - + AnalogIn ain(resistor_ladder_pins[0]); // Repeat to guarentee consistency - for (unsigned int i=0; i TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_busio_execute(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running analog input range test on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); +void test_busio_execute(PinName pin, float tolerance, int iterations) { + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - PinName pin_pair = TestFramework::find_pin_pair(pin); - BusInOut bio1(pin); - BusInOut bio2(pin_pair); + PinName pin_pair = TestFramework::find_pin_pair(pin); + DEBUG_PRINTF("Running BusIO test on pin %d and its pin-pair %d", pin, pin_pair); - bio1.output(); - bio2.input(); - bio1 = 0; - TEST_ASSERT_MESSAGE(bio2.read()==0, "Value read on bus does not equal value written."); - bio1 = 1; - TEST_ASSERT_MESSAGE(bio2.read()==1, "Value read on bus does not equal value written."); + BusInOut bio1(pin); + BusInOut bio2(pin_pair); + + bio1.output(); + bio2.input(); + bio1 = 0; + TEST_ASSERT_MESSAGE(bio2.read()==0, "Value read on bus does not equal value written."); + bio1 = 1; + TEST_ASSERT_MESSAGE(bio2.read()==1, "Value read on bus does not equal value written."); } utest::v1::control_t test_level1_busio(const size_t call_count) { - return TestFramework::test_level2_framework(TestFramework::BusIO, TestFramework::CITS_DigitalIO, &test_busio_execute, 0.05, 10); + return TestFramework::test_level1_framework(TestFramework::BusIO, TestFramework::CITS_DigitalIO, &test_busio_execute, 0.05, 10); } Case cases[] = { @@ -61,5 +62,5 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } From f3c2521f673b65ba5f072c6ea91cbd0cbf230838 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 17 Jul 2017 11:41:36 -0500 Subject: [PATCH 03/21] added ifdef guards to TestFramework.cpp, so that it can compile with boards that don't have all the PinMaps defined --- TestFramework.cpp | 51 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index 89ebe3e..ce743c3 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -21,25 +21,40 @@ // Initialization // /////////////////////////////////////////////////////////////////////////////*/ TestFramework::TestFramework() { - map_pins(PinMap_ADC, AnalogInput); - map_pins(PinMap_DAC, AnalogOutput); - map_pins(PinMap_PWM, DigitalIO); - map_pins(PinMap_ADC, DigitalIO); - // map_pins(PinMap_DAC, DigitalIO); grabbing pin number from PeripheralPins.c, instead of the pin translation from mbed_app.json - map_pins(PinMap_I2C_SDA, DigitalIO); - map_pins(PinMap_I2C_SCL, DigitalIO); - map_pins(PinMap_SPI_SCLK, DigitalIO); - map_pins(PinMap_SPI_MOSI, DigitalIO); - map_pins(PinMap_SPI_MISO, DigitalIO); - map_pins(PinMap_SPI_SSEL, DigitalIO); + #ifdef DEVICE_ANALOGIN + map_pins(PinMap_ADC, AnalogInput); + map_pins(PinMap_ADC, DigitalIO); + #endif // DEVICE_ANALOGIN + + #ifdef DEVICE_ANALOGOUT + map_pins(PinMap_DAC, AnalogOutput); + // map_pins(PinMap_DAC, DigitalIO); grabbing pin number from PeripheralPins.c, instead of the pin translation from mbed_app.json + #endif // DEVICE_ANALOGOUT + + #ifdef DEVICE_I2C + map_pins(PinMap_I2C_SDA, DigitalIO); + map_pins(PinMap_I2C_SCL, DigitalIO); + map_pins(PinMap_I2C_SDA, I2C_SDA); + map_pins(PinMap_I2C_SCL, I2C_SCL); + #endif // DEVICE_I2C + + #ifdef DEVICE_PWMOUT + map_pins(PinMap_PWM, DigitalIO); + map_pins(PinMap_PWM, PWM); + #endif // DEVICE_PWMOUT + + #ifdef DEVICE_SPI + map_pins(PinMap_SPI_SCLK, DigitalIO); + map_pins(PinMap_SPI_MOSI, DigitalIO); + map_pins(PinMap_SPI_MISO, DigitalIO); + map_pins(PinMap_SPI_SSEL, DigitalIO); + map_pins(PinMap_SPI_SCLK, SPI_CLK); + map_pins(PinMap_SPI_MOSI, SPI_MOSI); + map_pins(PinMap_SPI_MISO, SPI_MISO); + map_pins(PinMap_SPI_SSEL, SPI_CS); + #endif // DEVICE_SPI + pinout[BusIO] = pinout[DigitalIO]; - map_pins(PinMap_PWM, PWM); - map_pins(PinMap_I2C_SDA, I2C_SDA); - map_pins(PinMap_I2C_SCL, I2C_SCL); - map_pins(PinMap_SPI_SCLK, SPI_CLK); - map_pins(PinMap_SPI_MOSI, SPI_MOSI); - map_pins(PinMap_SPI_MISO, SPI_MISO); - map_pins(PinMap_SPI_SSEL, SPI_CS); setup_cits_pins(); } From d095c549a52f7adf3c3ac5c570ca0b3b1fe535de Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 17 Jul 2017 13:42:31 -0500 Subject: [PATCH 04/21] changed printf to use hex instead if decimal when printing pin names --- TESTS/Level0/AnalogIn/AnalogIn.cpp | 2 +- TESTS/Level0/AnalogOut/AnalogOut.cpp | 2 +- TESTS/Level0/BusInOut/BusInOut.cpp | 2 +- TESTS/Level0/DigitalIO/DigitalIO.cpp | 2 +- TESTS/Level0/I2C/I2C.cpp | 2 +- TESTS/Level0/Pwm/Pwm.cpp | 2 +- TESTS/Level0/SPI/SPI.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index 82d62cd..93d3057 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -40,7 +40,7 @@ TestFramework test_framework; utest::v1::control_t test_level0_analogin(const size_t call_count) { PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogInput); - DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin.pin); + DEBUG_PRINTF("Running analog input constructor on pin %#x\n", pin.pin); TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); AnalogIn ain(pin.pin); diff --git a/TESTS/Level0/AnalogOut/AnalogOut.cpp b/TESTS/Level0/AnalogOut/AnalogOut.cpp index ac767c3..59df303 100644 --- a/TESTS/Level0/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level0/AnalogOut/AnalogOut.cpp @@ -39,7 +39,7 @@ TestFramework test_framework; utest::v1::control_t test_level0_analogout(const size_t call_count) { PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogOutput); - DEBUG_PRINTF("Running analog output constructor on pin %d\n", pin.pin); + DEBUG_PRINTF("Running analog output constructor on pin %#x\n", pin.pin); TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); AnalogOut ain(pin.pin); diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index cf61a5c..0e6f877 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -53,7 +53,7 @@ utest::v1::control_t test_level0_businout(const size_t call_count) { } } - DEBUG_PRINTF("Pins assigned to bus:\n pin[0] = %d\n pin[1] = %d\n pin[2] = %d\n pin[3] = %d\n pin[4] = %d\n pin[5] = %d\n pin[6] = %d\n pin[7] = %d\n pin[8] = %d\n pin[9] = %d\n pin[10] = %d\n pin[11] = %d\n pin[12] = %d\n pin[13] = %d\n pin[14] = %d\n pin[15] = %d\n",pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); + DEBUG_PRINTF("Pins assigned to bus:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n pin[5] = %#x\n pin[6] = %#x\n pin[7] = %#x\n pin[8] = %#x\n pin[9] = %#x\n pin[10] = %#x\n pin[11] = %#x\n pin[12] = %#x\n pin[13] = %#x\n pin[14] = %#x\n pin[15] = %#x\n",pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); // construct the bus with assigned pins BusInOut bio(pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); diff --git a/TESTS/Level0/DigitalIO/DigitalIO.cpp b/TESTS/Level0/DigitalIO/DigitalIO.cpp index 30c1e58..42967fc 100644 --- a/TESTS/Level0/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level0/DigitalIO/DigitalIO.cpp @@ -36,7 +36,7 @@ TestFramework test_framework; utest::v1::control_t test_level0_digitalio(const size_t call_count) { PinMap pin = test_framework.get_increment_pin(TestFramework::DigitalIO); - DEBUG_PRINTF("Running digital io constructor on pin %d\n", pin.pin); + DEBUG_PRINTF("Running digital io constructor on pin %#x\n", pin.pin); TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); DigitalOut dout(pin.pin); diff --git a/TESTS/Level0/I2C/I2C.cpp b/TESTS/Level0/I2C/I2C.cpp index 04b351c..f7ffa35 100644 --- a/TESTS/Level0/I2C/I2C.cpp +++ b/TESTS/Level0/I2C/I2C.cpp @@ -39,7 +39,7 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; void construct_i2c(PinName sda, PinName scl) { - DEBUG_PRINTF("Running I2C Constructor on SDA pin %d and SCL pin %d\n", sda, scl); + DEBUG_PRINTF("Running I2C Constructor on SDA pin %#x and SCL pin %#x\n", sda, scl); TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC"); TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC"); diff --git a/TESTS/Level0/Pwm/Pwm.cpp b/TESTS/Level0/Pwm/Pwm.cpp index 4b80a61..19aacfd 100644 --- a/TESTS/Level0/Pwm/Pwm.cpp +++ b/TESTS/Level0/Pwm/Pwm.cpp @@ -40,7 +40,7 @@ TestFramework test_framework; utest::v1::control_t test_level0_pwm(const size_t call_count) { PinMap pin = test_framework.get_increment_pin(TestFramework::PWM); - DEBUG_PRINTF("Running pwm constructor on pin %d\n", pin.pin); + DEBUG_PRINTF("Running PWM constructor on pin %#x\n", pin.pin); TEST_ASSERT_MESSAGE(pin.pin != NC, "pin is NC"); PwmOut pwm(pin.pin); diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index 27d907f..e355b00 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -39,7 +39,7 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; void construct_spi(PinName pin_clk, PinName pin_miso, PinName pin_mosi, PinName pin_cs) { - DEBUG_PRINTF("Running SPI constructor on CLK pin %d, MISO pin %d, MOSI pin %d, and CS pin %d\n", pin_clk, pin_miso, pin_mosi, pin_cs); + DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); From 6a07ee1d1b13ed1a812328d3ad2947c408b5071b Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 17 Jul 2017 15:15:54 -0500 Subject: [PATCH 05/21] Added #ifdef check in map_pins() so that it no longer adds ADC internal channels on STM boards, as they cause timeout errors when constructed --- TestFramework.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index ce743c3..f02b809 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -102,9 +102,16 @@ void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { if (pinout[pintype][j].pin == pinmap[i].pin) alreadyExists = true; } - // if pin is not already in pinout and is not already assigned to USB_UART, then add to pinout - if ((!alreadyExists) && (pinmap[i].pin != USBTX) && (pinmap[i].pin != USBRX)) { - pinout[pintype].push_back(pinmap[i]); + // push each valid pin onto the pinmap once for each pin. + #ifdef TARGET_STM + // if testing on STM boards, do not add ADC internal channels, USBTX, and USBRX pins + if ((!alreadyExists) && (pinmap[i].pin != USBTX) && (pinmap[i].pin != USBRX) && (pinmap[i].pin != ADC_TEMP) && (pinmap[i].pin != ADC_VREF) && (pinmap[i].pin != ADC_VBAT)){ + + #else // else if not testing on STM boards + // do not add USBTX and USBRX pins + if ((!alreadyExists) && (pinmap[i].pin != USBTX) && (pinmap[i].pin != USBRX)){ + #endif // TARGET_STM + pinout[pintype].push_back(pinmap[i]); // add pin to end of pinmap } i++; } From f13f5245762be35f304c8c3375171a878611c5ee Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 17 Jul 2017 15:42:17 -0500 Subject: [PATCH 06/21] Debug printf calls now report as hex instead of decimal for pin names on level1 tests. --- TESTS/Level1/AnalogIn/AnalogIn.cpp | 4 +- TESTS/Level1/AnalogOut/AnalogOut.cpp | 2 +- TESTS/Level1/BusInOut/BusInOut.cpp | 2 +- TESTS/Level1/DigitalIO/DigitalIO.cpp | 23 +++--- TESTS/Level1/I2C/I2C.cpp | 6 +- TESTS/Level1/Pwm/Pwm.cpp | 107 ++++++++++++++------------- TESTS/Level1/SPI/SPI.cpp | 2 +- 7 files changed, 74 insertions(+), 72 deletions(-) diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index a8314af..7412c48 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -39,7 +39,7 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; void test_analogin_execute(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running analog input range test on pin %d\n", pin); + DEBUG_PRINTF("Running analog input range test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); // Find all pins on the resistor ladder that are not the current pin @@ -51,7 +51,7 @@ void test_analogin_execute(PinName pin, float tolerance, int iterations) { BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); outputs.output(); - DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %d\n pin[1] = %d\n pin[2] = %d\n pin[3] = %d\n pin[4] = %d\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); // construct designated analogIn pin AnalogIn ain(pin); diff --git a/TESTS/Level1/AnalogOut/AnalogOut.cpp b/TESTS/Level1/AnalogOut/AnalogOut.cpp index ccf75da..0143f37 100644 --- a/TESTS/Level1/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/AnalogOut/AnalogOut.cpp @@ -39,7 +39,7 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; void test_analogout_execute(PinName pin, float tolerance, int iterations){ - DEBUG_PRINTF("Running analog output range test on pin %d\n", pin); + DEBUG_PRINTF("Running analog output range test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); // Find all pins on the resistor ladder that are not the current pin diff --git a/TESTS/Level1/BusInOut/BusInOut.cpp b/TESTS/Level1/BusInOut/BusInOut.cpp index 12b463f..990dd10 100644 --- a/TESTS/Level1/BusInOut/BusInOut.cpp +++ b/TESTS/Level1/BusInOut/BusInOut.cpp @@ -38,7 +38,7 @@ void test_busio_execute(PinName pin, float tolerance, int iterations) { TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); PinName pin_pair = TestFramework::find_pin_pair(pin); - DEBUG_PRINTF("Running BusIO test on pin %d and its pin-pair %d", pin, pin_pair); + DEBUG_PRINTF("Running BusIO test on pin %#x and its pin-pair %#x", pin, pin_pair); BusInOut bio1(pin); BusInOut bio2(pin_pair); diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index 6147694..da22a5b 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -42,18 +42,19 @@ void dio_toggled(void) { } void test_digitalio_execute(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running digital io test on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - PinName pinpair = TestFramework::find_pin_pair(pin); - DigitalOut dout(pinpair); - DigitalIn din(pin); + PinName pinpair = TestFramework::find_pin_pair(pin); + DEBUG_PRINTF("Running digital io test on pin %#x and its pin-pair %#x", pin, pin_pair); - // Verify Digital Input and Output can occur on the same pin - dout = 0; - TEST_ASSERT_MESSAGE(0 == din.read(),"Expected value to be 0, read value was not zero"); - dout = 1; - TEST_ASSERT_MESSAGE(1 == din.read(),"Expected value to be 1, read value was not one"); + DigitalOut dout(pinpair); + DigitalIn din(pin); + + // Verify Digital Input and Output can occur on the same pin + dout = 0; + TEST_ASSERT_MESSAGE(0 == din.read(),"Expected value to be 0, read value was not zero"); + dout = 1; + TEST_ASSERT_MESSAGE(1 == din.read(),"Expected value to be 1, read value was not one"); } utest::v1::control_t test_level1_digitalio(const size_t call_count) { @@ -67,5 +68,5 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index 13b9c2b..b71e827 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -53,7 +53,7 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) { return utest::v1::CaseNext; } - DEBUG_PRINTF("Running I2C constructor on SDA pin %d and SCL pin %d\n", pin_sda, pin_scl); + DEBUG_PRINTF("Running I2C constructor on SDA pin %#x and SCL pin %#x\n", pin_sda, pin_scl); TEST_ASSERT_MESSAGE(pin_sda != NC, "SDA Pin is NC"); TEST_ASSERT_MESSAGE(pin_scl != NC, "SCL Pin is NC"); @@ -61,9 +61,9 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) { // Generate a random string char test_string[128] = {0}; - for (int i=0; i @@ -124,5 +125,5 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index 8da1d12..76c1b6a 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -55,7 +55,7 @@ utest::v1::control_t test_level1_spi(const size_t call_count) { return utest::v1::CaseNext; } - DEBUG_PRINTF("Running SPI constructor on CLK pin %d, MISO pin %d, MOSI pin %d, and CS pin %d\n", pin_clk, pin_miso, pin_mosi, pin_cs); + DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); From 451b3a66f8172ec9608deb3be713426001c5e456 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 17 Jul 2017 16:05:00 -0500 Subject: [PATCH 07/21] Fixed typo in DigitalIO.cpp. Turned of Debug mode in mbed_app.json --- TESTS/Level1/DigitalIO/DigitalIO.cpp | 2 +- mbed_app.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index da22a5b..47bf45d 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -45,7 +45,7 @@ void test_digitalio_execute(PinName pin, float tolerance, int iterations) { TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); PinName pinpair = TestFramework::find_pin_pair(pin); - DEBUG_PRINTF("Running digital io test on pin %#x and its pin-pair %#x", pin, pin_pair); + DEBUG_PRINTF("Running digital io test on pin %#x and its pin-pair %#x", pin, pinpair); DigitalOut dout(pinpair); DigitalIn din(pin); diff --git a/mbed_app.json b/mbed_app.json index 1e456b4..f14bcf3 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -31,7 +31,7 @@ "PWM_1": "D5", "PWM_2": "D6", "PWM_3": "D9", - "DEBUG_MSG": 1 + "DEBUG_MSG": 0 }, "target_overrides": { "DISCO_L475VG_IOT01A": { From 5e0b680fd272d9f0ef589d14430873af4dd64912 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 4 Aug 2017 13:29:08 -0500 Subject: [PATCH 08/21] Formatted Level0 code per Martin Kojtal's request. --- TESTS/Level0/AnalogIn/AnalogIn.cpp | 13 +++++++++---- TESTS/Level0/AnalogOut/AnalogOut.cpp | 13 +++++++++---- TESTS/Level0/BusInOut/BusInOut.cpp | 23 +++++++++++++---------- TESTS/Level0/DigitalIO/DigitalIO.cpp | 13 +++++++++---- TESTS/Level0/I2C/I2C.cpp | 23 +++++++++++++++-------- TESTS/Level0/Pwm/Pwm.cpp | 17 +++++++++++------ TESTS/Level0/SPI/SPI.cpp | 27 +++++++++++++++++---------- 7 files changed, 83 insertions(+), 46 deletions(-) diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index 93d3057..22bf210 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -38,22 +38,27 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::control_t test_level0_analogin(const size_t call_count) { + +utest::v1::control_t test_level0_analogin(const size_t call_count) +{ PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogInput); DEBUG_PRINTF("Running analog input constructor on pin %#x\n", pin.pin); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); AnalogIn ain(pin.pin); return test_framework.reset_iterator(TestFramework::AnalogInput); } + Case cases[] = { Case("Level 0 - Analog Input Constructor", test_level0_analogin, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level0/AnalogOut/AnalogOut.cpp b/TESTS/Level0/AnalogOut/AnalogOut.cpp index 59df303..e208dc2 100644 --- a/TESTS/Level0/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level0/AnalogOut/AnalogOut.cpp @@ -37,22 +37,27 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::control_t test_level0_analogout(const size_t call_count) { + +utest::v1::control_t test_level0_analogout(const size_t call_count) +{ PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogOutput); DEBUG_PRINTF("Running analog output constructor on pin %#x\n", pin.pin); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); AnalogOut ain(pin.pin); return test_framework.reset_iterator(TestFramework::AnalogOutput); } + Case cases[] = { Case("Level 0 - Analog Output Constructor", test_level0_analogout, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index 0e6f877..cdfc13d 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -36,7 +36,9 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::control_t test_level0_businout(const size_t call_count) { + +utest::v1::control_t test_level0_businout(const size_t call_count) +{ DEBUG_PRINTF("Running bus input/output constructor\n"); std::vector pins; // vector of pins that the bus will contain @@ -45,18 +47,18 @@ utest::v1::control_t test_level0_businout(const size_t call_count) { if(TestFramework::check_size(TestFramework::BusIO)) { // fetch new pin pins.push_back(test_framework.get_increment_pin(TestFramework::BusIO).pin); - } + } - // if no more suitable pins are available, then add No-Connects until bus is full - else{ + // if no more suitable pins are available, then add No-Connects until bus is full + else { pins.push_back((PinName)NC); + } } - } - DEBUG_PRINTF("Pins assigned to bus:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n pin[5] = %#x\n pin[6] = %#x\n pin[7] = %#x\n pin[8] = %#x\n pin[9] = %#x\n pin[10] = %#x\n pin[11] = %#x\n pin[12] = %#x\n pin[13] = %#x\n pin[14] = %#x\n pin[15] = %#x\n",pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); + DEBUG_PRINTF("Pins assigned to bus:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n pin[5] = %#x\n pin[6] = %#x\n pin[7] = %#x\n pin[8] = %#x\n pin[9] = %#x\n pin[10] = %#x\n pin[11] = %#x\n pin[12] = %#x\n pin[13] = %#x\n pin[14] = %#x\n pin[15] = %#x\n",pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); - // construct the bus with assigned pins - BusInOut bio(pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); + // construct the bus with assigned pins + BusInOut bio(pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]); return test_framework.reset_iterator(TestFramework::BusIO); } @@ -65,8 +67,9 @@ Case cases[] = { Case("Level 0 - Bus Input/Output Constructor", test_level0_businout, TestFramework::greentea_failure_handler), }; -int main() { +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level0/DigitalIO/DigitalIO.cpp b/TESTS/Level0/DigitalIO/DigitalIO.cpp index 42967fc..f037f64 100644 --- a/TESTS/Level0/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level0/DigitalIO/DigitalIO.cpp @@ -34,10 +34,12 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::control_t test_level0_digitalio(const size_t call_count) { + +utest::v1::control_t test_level0_digitalio(const size_t call_count) +{ PinMap pin = test_framework.get_increment_pin(TestFramework::DigitalIO); DEBUG_PRINTF("Running digital io constructor on pin %#x\n", pin.pin); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); DigitalOut dout(pin.pin); DigitalIn din(pin.pin); @@ -45,12 +47,15 @@ utest::v1::control_t test_level0_digitalio(const size_t call_count) { return test_framework.reset_iterator(TestFramework::DigitalIO); } + Case cases[] = { Case("Level 0 - DigitalIO Constructor", test_level0_digitalio, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level0/I2C/I2C.cpp b/TESTS/Level0/I2C/I2C.cpp index f7ffa35..237d51d 100644 --- a/TESTS/Level0/I2C/I2C.cpp +++ b/TESTS/Level0/I2C/I2C.cpp @@ -38,24 +38,31 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void construct_i2c(PinName sda, PinName scl) { - DEBUG_PRINTF("Running I2C Constructor on SDA pin %#x and SCL pin %#x\n", sda, scl); - TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC"); - TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC"); - I2C i2c(sda, scl); +void construct_i2c(PinName sda, PinName scl) +{ + DEBUG_PRINTF("Running I2C Constructor on SDA pin %#x and SCL pin %#x\n", sda, scl); + TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC"); + TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC"); + + I2C i2c(sda, scl); } -utest::v1::control_t test_level0_i2c(const size_t call_count) { + +utest::v1::control_t test_level0_i2c(const size_t call_count) +{ return TestFramework::run_i2c(&construct_i2c); } + Case cases[] = { Case("Level 0 - I2C Constructor", test_level0_i2c, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level0/Pwm/Pwm.cpp b/TESTS/Level0/Pwm/Pwm.cpp index 19aacfd..9273eb2 100644 --- a/TESTS/Level0/Pwm/Pwm.cpp +++ b/TESTS/Level0/Pwm/Pwm.cpp @@ -38,24 +38,29 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::control_t test_level0_pwm(const size_t call_count) { + +utest::v1::control_t test_level0_pwm(const size_t call_count) +{ PinMap pin = test_framework.get_increment_pin(TestFramework::PWM); DEBUG_PRINTF("Running PWM constructor on pin %#x\n", pin.pin); - TEST_ASSERT_MESSAGE(pin.pin != NC, "pin is NC"); + TEST_ASSERT_MESSAGE(pin.pin != NC, "pin is NC"); PwmOut pwm(pin.pin); - pwm.period(1.0f); - pwm.write(0.5f); + pwm.period(1.0f); + pwm.write(0.5f); return test_framework.reset_iterator(TestFramework::PWM); } + Case cases[] = { Case("Level 0 - PWM Constructor", test_level0_pwm, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index e355b00..fda5c3b 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -38,27 +38,34 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void construct_spi(PinName pin_clk, PinName pin_miso, PinName pin_mosi, PinName pin_cs) { + +void construct_spi(PinName pin_clk, PinName pin_miso, PinName pin_mosi, PinName pin_cs) +{ DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); - TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); - TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); - TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); - TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); + TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); + TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); + TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); + TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); - SPI(pin_mosi, pin_miso, pin_clk); - DigitalOut cs(pin_cs); + SPI(pin_mosi, pin_miso, pin_clk); + DigitalOut cs(pin_cs); } -utest::v1::control_t test_level0_spi(const size_t call_count) { + +utest::v1::control_t test_level0_spi(const size_t call_count) +{ return test_framework.run_spi(&construct_spi); } + Case cases[] = { Case("Level 0 - SPI Constructor", test_level0_spi, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<60>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } From a7cd92c6b3089a2b127d63a9bc322549290cdfeb Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 7 Aug 2017 09:17:02 -0500 Subject: [PATCH 09/21] Formatted Level1 code per Martin Kojtal's requested format. --- TESTS/Level1/AnalogIn/AnalogIn.cpp | 92 ++++++++++--------- TESTS/Level1/AnalogOut/AnalogOut.cpp | 37 ++++---- TESTS/Level1/BusInOut/BusInOut.cpp | 42 +++++---- TESTS/Level1/DigitalIO/DigitalIO.cpp | 47 +++++----- TESTS/Level1/I2C/I2C.cpp | 62 +++++++------ TESTS/Level1/Pwm/Pwm.cpp | 130 ++++++++++++++------------- TESTS/Level1/SPI/SPI.cpp | 105 +++++++++++----------- 7 files changed, 275 insertions(+), 240 deletions(-) diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index 7412c48..d29bb8f 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -29,6 +29,8 @@ #include "TestFramework.hpp" #include +#define BUS_SIZE 5 + using namespace utest::v1; // Static variables for managing the dynamic list of pins @@ -38,65 +40,69 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_analogin_execute(PinName pin, float tolerance, int iterations) { +void test_analogin_execute(PinName pin, float tolerance, int iterations) +{ DEBUG_PRINTF("Running analog input range test on pin %#x\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - // Find all pins on the resistor ladder that are not the current pin + // Find all pins on the resistor ladder that are not the current pin std::vector resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin); - if (resistor_ladder_pins.size() < 5) - TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); + if (resistor_ladder_pins.size() < BUS_SIZE){ + TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); + } // Create a bus with all of these pins - BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); outputs.output(); - DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); - // construct designated analogIn pin + // construct designated analogIn pin AnalogIn ain(pin); - for (unsigned int i=0; i prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file") - - // Repeat the read multiple times to verify the output is not fluctuating - for (unsigned int j = 0; j prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file") + + // Repeat the read multiple times to verify the output is not fluctuating + for (unsigned int j = 0; j, cases); - return !Harness::run(specification); +int main() +{ + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<30>, cases); + return !Harness::run(specification); } diff --git a/TESTS/Level1/AnalogOut/AnalogOut.cpp b/TESTS/Level1/AnalogOut/AnalogOut.cpp index 0143f37..47407f2 100644 --- a/TESTS/Level1/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/AnalogOut/AnalogOut.cpp @@ -38,23 +38,24 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_analogout_execute(PinName pin, float tolerance, int iterations){ - DEBUG_PRINTF("Running analog output range test on pin %#x\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); +void test_analogout_execute(PinName pin, float tolerance, int iterations) +{ + DEBUG_PRINTF("Running analog output range test on pin %#x\n", pin); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - // Find all pins on the resistor ladder that are not the current pin + // Find all pins on the resistor ladder that are not the current pin std::vector resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin); - if (resistor_ladder_pins.size() < 5){ - TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); - } + if (resistor_ladder_pins.size() < 5){ + TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); + } AnalogIn ain(resistor_ladder_pins[0]); // Repeat to guarentee consistency - for (unsigned int i=0; i, cases); +int main() +{ + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level1/BusInOut/BusInOut.cpp b/TESTS/Level1/BusInOut/BusInOut.cpp index 990dd10..ebfcee3 100644 --- a/TESTS/Level1/BusInOut/BusInOut.cpp +++ b/TESTS/Level1/BusInOut/BusInOut.cpp @@ -34,33 +34,37 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_busio_execute(PinName pin, float tolerance, int iterations) { - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); +void test_busio_execute(PinName pin, float tolerance, int iterations) +{ + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - PinName pin_pair = TestFramework::find_pin_pair(pin); - DEBUG_PRINTF("Running BusIO test on pin %#x and its pin-pair %#x", pin, pin_pair); + PinName pin_pair = TestFramework::find_pin_pair(pin); + DEBUG_PRINTF("Running BusIO test on pin %#x and its pin-pair %#x", pin, pin_pair); - BusInOut bio1(pin); - BusInOut bio2(pin_pair); + BusInOut bio1(pin); + BusInOut bio2(pin_pair); - bio1.output(); - bio2.input(); - bio1 = 0; - TEST_ASSERT_MESSAGE(bio2.read()==0, "Value read on bus does not equal value written."); - bio1 = 1; - TEST_ASSERT_MESSAGE(bio2.read()==1, "Value read on bus does not equal value written."); + bio1.output(); + bio2.input(); + bio1 = 0; + TEST_ASSERT_MESSAGE(bio2.read()==0, "Value read on bus does not equal value written."); + bio1 = 1; + TEST_ASSERT_MESSAGE(bio2.read()==1, "Value read on bus does not equal value written."); } -utest::v1::control_t test_level1_busio(const size_t call_count) { - return TestFramework::test_level1_framework(TestFramework::BusIO, TestFramework::CITS_DigitalIO, &test_busio_execute, 0.05, 10); + +utest::v1::control_t test_level1_busio(const size_t call_count) +{ + return TestFramework::test_level1_framework(TestFramework::BusIO, TestFramework::CITS_DigitalIO, &test_busio_execute, 0.05, 10); } Case cases[] = { - Case("Level 1 - Bus Input/Output pair test", test_level1_busio, TestFramework::greentea_failure_handler), + Case("Level 1 - Bus Input/Output pair test", test_level1_busio, TestFramework::greentea_failure_handler), }; -int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); +int main() +{ + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<30>, cases); + return !Harness::run(specification); } diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index 47bf45d..da887a1 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -37,36 +37,43 @@ int clocked_dio_toggle; // Initialize a test framework object TestFramework test_framework; -void dio_toggled(void) { - clocked_dio_toggle = timer.read_us(); +void dio_toggled(void) +{ + clocked_dio_toggle = timer.read_us(); } -void test_digitalio_execute(PinName pin, float tolerance, int iterations) { - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - PinName pinpair = TestFramework::find_pin_pair(pin); - DEBUG_PRINTF("Running digital io test on pin %#x and its pin-pair %#x", pin, pinpair); +void test_digitalio_execute(PinName pin, float tolerance, int iterations) +{ + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - DigitalOut dout(pinpair); - DigitalIn din(pin); + PinName pinpair = TestFramework::find_pin_pair(pin); + DEBUG_PRINTF("Running digital io test on pin %#x and its pin-pair %#x", pin, pinpair); - // Verify Digital Input and Output can occur on the same pin - dout = 0; - TEST_ASSERT_MESSAGE(0 == din.read(),"Expected value to be 0, read value was not zero"); - dout = 1; - TEST_ASSERT_MESSAGE(1 == din.read(),"Expected value to be 1, read value was not one"); + DigitalOut dout(pinpair); + DigitalIn din(pin); + + // Verify Digital Input and Output can occur on the same pin + dout = 0; + TEST_ASSERT_MESSAGE(0 == din.read(),"Expected value to be 0, read value was not zero"); + dout = 1; + TEST_ASSERT_MESSAGE(1 == din.read(),"Expected value to be 1, read value was not one"); } -utest::v1::control_t test_level1_digitalio(const size_t call_count) { - return TestFramework::test_level1_framework(TestFramework::DigitalIO, TestFramework::CITS_DigitalIO, &test_digitalio_execute, 0.05, 10); + +utest::v1::control_t test_level1_digitalio(const size_t call_count) +{ + return TestFramework::test_level1_framework(TestFramework::DigitalIO, TestFramework::CITS_DigitalIO, &test_digitalio_execute, 0.05, 10); } Case cases[] = { - Case("Level 1 - Digital In/Out Range test (single pin)", test_level1_digitalio, TestFramework::greentea_failure_handler), + Case("Level 1 - Digital In/Out Range test (single pin)", test_level1_digitalio, TestFramework::greentea_failure_handler), }; -int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + +int main() +{ + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<30>, cases); + return !Harness::run(specification); } diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index b71e827..1ab1a1b 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -43,54 +43,58 @@ char* DEADBEEF = "DEADBEEF"; char NULL_STR[128] = {0}; template -utest::v1::control_t test_level1_i2c(const size_t call_count) { +utest::v1::control_t test_level1_i2c(const size_t call_count) +{ // Check to see if the CI test shield I2C pins are connected to the board PinName pin_scl = MBED_CONF_APP_I2C_SCL; PinName pin_sda = MBED_CONF_APP_I2C_SDA; if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || - TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { - return utest::v1::CaseNext; + TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { + return utest::v1::CaseNext; } - DEBUG_PRINTF("Running I2C constructor on SDA pin %#x and SCL pin %#x\n", pin_sda, pin_scl); - TEST_ASSERT_MESSAGE(pin_sda != NC, "SDA Pin is NC"); - TEST_ASSERT_MESSAGE(pin_scl != NC, "SCL Pin is NC"); + DEBUG_PRINTF("Running I2C constructor on SDA pin %#x and SCL pin %#x\n", pin_sda, pin_scl); + TEST_ASSERT_MESSAGE(pin_sda != NC, "SDA Pin is NC"); + TEST_ASSERT_MESSAGE(pin_scl != NC, "SCL Pin is NC"); - I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); - // Generate a random string - char test_string[128] = {0}; - for (int i=0; i, TestFramework::greentea_failure_handler), Case("Level 1 - I2C test - 10 byte (single pin set)", test_level1_i2c<10>, TestFramework::greentea_failure_handler), Case("Level 1 - I2C test - 100 byte (single pin set)", test_level1_i2c<100>, TestFramework::greentea_failure_handler), }; -int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + +int main() +{ + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<30>, cases); + return !Harness::run(specification); } diff --git a/TESTS/Level1/Pwm/Pwm.cpp b/TESTS/Level1/Pwm/Pwm.cpp index 3c31993..f2f3c62 100644 --- a/TESTS/Level1/Pwm/Pwm.cpp +++ b/TESTS/Level1/Pwm/Pwm.cpp @@ -45,74 +45,80 @@ int last_rise_time; int duty_count; // Callback for a PWM rising edge -void callback_pwm_rise(void) { - rise_count++; - last_rise_time = timer.read_ms(); +void callback_pwm_rise(void) +{ + rise_count++; + last_rise_time = timer.read_ms(); } + // Callback for a PWM falling edge -void callback_pwm_fall(void) { - fall_count++; - if (last_rise_time != 0){ - duty_count = duty_count + (timer.read_ms() - last_rise_time); - } +void callback_pwm_fall(void) +{ + fall_count++; + if (last_rise_time != 0){ + duty_count = duty_count + (timer.read_ms() - last_rise_time); + } } -void test_pwm_execute(PinName pin, float dutycycle, int period) { - DEBUG_PRINTF("Running pwm test on pin %#x\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - - // Initialize - float tolerance = 0.05; - int iterations = 20; - float calculated_percent = iterations * tolerance; - if (calculated_percent < 1) calculated_percent = 1.0f; - fall_count = 0; - rise_count = 0; - last_rise_time = 0; - duty_count = 0; - - PwmOut pwm(pin); - timer.reset(); - InterruptIn iin(TestFramework::find_pin_pair(pin)); - iin.rise(callback_pwm_rise); - iin.fall(callback_pwm_fall); - - // Set the period - DEBUG_PRINTF("Period set to: %f, duty cycle set to: %f\n", (float)period/1000, dutycycle); - pwm.period((float)period/1000); - pwm.write(0); - DEBUG_PRINTF("Waiting for %dms\n", iterations * period); - - // Start the timer, write the duty cycle, and wait for completion - timer.start(); - pwm.write(dutycycle); - wait_ms(iterations * period); - - // Stop the timer, reset the IRQ for interrupts (cause it may not work on some platforms) and clear the PWM duty cycle - pwm.write(0); - iin.disable_irq(); - timer.stop(); - - // Run post calculations for verification - int rc = rise_count; - int fc = fall_count; - float avgTime = (float)duty_count / iterations; - float expectedTime = (float)period * dutycycle; - DEBUG_PRINTF("Expected time: %f, Avg Time: %f\n", expectedTime, avgTime); - DEBUG_PRINTF("rise count = %d, fall count = %d, expected count = %d\n", rc, fc, iterations); - TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= calculated_percent, "There was more than a specific variance in number of rise vs fall cycles"); - TEST_ASSERT_MESSAGE( std::abs(iterations - rc) <= calculated_percent, "There was more than a specific variance in number of rise cycles seen and number expected."); - TEST_ASSERT_MESSAGE( std::abs(iterations - fc) <= calculated_percent, "There was more than a specific variance in number of fall cycles seen and number expected."); - // @TODO The following assert is a good check to have (comparing times) but fails on most platforms. Need to come up with a better way to do this test - // TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= calculated_percent,"Greater than a specific variance between expected and measured duty cycle"); +void test_pwm_execute(PinName pin, float dutycycle, int period) +{ + DEBUG_PRINTF("Running pwm test on pin %#x\n", pin); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + + // Initialize + float tolerance = 0.05; + int iterations = 20; + float calculated_percent = iterations * tolerance; + if (calculated_percent < 1) calculated_percent = 1.0f; + fall_count = 0; + rise_count = 0; + last_rise_time = 0; + duty_count = 0; + + PwmOut pwm(pin); + timer.reset(); + InterruptIn iin(TestFramework::find_pin_pair(pin)); + iin.rise(callback_pwm_rise); + iin.fall(callback_pwm_fall); + + // Set the period + DEBUG_PRINTF("Period set to: %f, duty cycle set to: %f\n", (float)period/1000, dutycycle); + pwm.period((float)period/1000); + pwm.write(0); + DEBUG_PRINTF("Waiting for %dms\n", iterations * period); + + // Start the timer, write the duty cycle, and wait for completion + timer.start(); + pwm.write(dutycycle); + wait_ms(iterations * period); + + // Stop the timer, reset the IRQ for interrupts (cause it may not work on some platforms) and clear the PWM duty cycle + pwm.write(0); + iin.disable_irq(); + timer.stop(); + + // Run post calculations for verification + int rc = rise_count; + int fc = fall_count; + float avgTime = (float)duty_count / iterations; + float expectedTime = (float)period * dutycycle; + DEBUG_PRINTF("Expected time: %f, Avg Time: %f\n", expectedTime, avgTime); + DEBUG_PRINTF("rise count = %d, fall count = %d, expected count = %d\n", rc, fc, iterations); + TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= calculated_percent, "There was more than a specific variance in number of rise vs fall cycles"); + TEST_ASSERT_MESSAGE( std::abs(iterations - rc) <= calculated_percent, "There was more than a specific variance in number of rise cycles seen and number expected."); + TEST_ASSERT_MESSAGE( std::abs(iterations - fc) <= calculated_percent, "There was more than a specific variance in number of fall cycles seen and number expected."); + // @TODO The following assert is a good check to have (comparing times) but fails on most platforms. Need to come up with a better way to do this test + // TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= calculated_percent,"Greater than a specific variance between expected and measured duty cycle"); } + template utest::v1::control_t test_level1_pwm(const size_t call_count) { - return TestFramework::test_level1_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); + return TestFramework::test_level1_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); } + Case cases[] = { Case("Level 1 - PWM Frequency test (single pin) - 10ms", test_level1_pwm<50, 10>, TestFramework::greentea_failure_handler), Case("Level 1 - PWM Frequency test (single pin) - 30ms", test_level1_pwm<50, 30>, TestFramework::greentea_failure_handler), @@ -122,8 +128,10 @@ Case cases[] = { Case("Level 1 - PWM Duty cycle test (single pin) - 90%", test_level1_pwm<90, 10>, TestFramework::greentea_failure_handler), }; -int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + +int main() +{ + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<30>, cases); + return !Harness::run(specification); } diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index 76c1b6a..5407778 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -41,8 +41,8 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; template -utest::v1::control_t test_level1_spi(const size_t call_count) { - +utest::v1::control_t test_level1_spi(const size_t call_count) +{ // Verify that the CI test shield pins are connected to the SPI pins PinName pin_clk = MBED_CONF_APP_SPI_CLK; PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; @@ -56,63 +56,66 @@ utest::v1::control_t test_level1_spi(const size_t call_count) { } DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); - TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); - TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); - TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); - TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); - - // Get a random seed from the Greentea host test - srand(TestFramework::get_seed()); - - // Initialize the SD card and file system residing on the SD card - int error = 0; - SDBlockDevice sd(pin_mosi, pin_miso, pin_clk, pin_cs); - FATFileSystem fs("sd"); - sd.init(); - error = fs.mount(&sd); - TEST_ASSERT_MESSAGE(error==0,"SD file system mount failed."); - - // Iterate twice for consistency - for (int i=0; i<2; i++) { - - // Generate a random string - char test_string[128] = {0}; - for (int i=0; i 0,"Writing File to sd card failed"); // write data - fclose(File_write);// close file on SD - - // Close the old file, open the same file in read only mode, and read the file - FILE *File_read = fopen("/sd/test_card.txt", "r"); // open File_read - char test_string_read[128] = {0}; - fgets(test_string_read, 128, File_read); // read string from the file - DEBUG_PRINTF("Read '%s' in read test\nString comparison returns %d\n",test_string_read,strcmp(test_string_read,test_string)); - TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string) == 0,"String read does not match string written"); // test that strings match - fclose(File_read);// close file on SD - remove("/sd/test_card.txt"); - } - - // Unmount and de-initialize the SD card - error = fs.unmount(); - TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); - - sd.deinit(); - - return utest::v1::CaseNext; + TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); + TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); + TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); + TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); + + // Get a random seed from the Greentea host test + srand(TestFramework::get_seed()); + + // Initialize the SD card and file system residing on the SD card + int error = 0; + SDBlockDevice sd(pin_mosi, pin_miso, pin_clk, pin_cs); + FATFileSystem fs("sd"); + sd.init(); + error = fs.mount(&sd); + TEST_ASSERT_MESSAGE(error==0,"SD file system mount failed."); + + // Iterate twice for consistency + for (int i=0; i<2; i++) { + + // Generate a random string + char test_string[128] = {0}; + for (int i=0; i 0,"Writing File to sd card failed"); // write data + fclose(File_write);// close file on SD + + // Close the old file, open the same file in read only mode, and read the file + FILE *File_read = fopen("/sd/test_card.txt", "r"); // open File_read + char test_string_read[128] = {0}; + fgets(test_string_read, 128, File_read); // read string from the file + DEBUG_PRINTF("Read '%s' in read test\nString comparison returns %d\n",test_string_read,strcmp(test_string_read,test_string)); + TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string) == 0,"String read does not match string written"); // test that strings match + fclose(File_read);// close file on SD + remove("/sd/test_card.txt"); + } + + // Unmount and de-initialize the SD card + error = fs.unmount(); + TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); + + sd.deinit(); + + return utest::v1::CaseNext; } + Case cases[] = { Case("Level 1 - SPI test - 1 byte (single pin set)", test_level1_spi<1>, TestFramework::greentea_failure_handler), Case("Level 1 - SPI test - 10 byte (single pin set)", test_level1_spi<10>, TestFramework::greentea_failure_handler), Case("Level 1 - SPI test - 100 byte (single pin set)", test_level1_spi<100>, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } From a421cff761a7f96862aadfe8e18e3160d2f01e8a Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 7 Aug 2017 13:24:29 -0500 Subject: [PATCH 10/21] Formatted TestFramework code per Martin Kojtal's requested format. --- TestFramework.cpp | 291 ++++++++++++++++++++++++---------------------- TestFramework.hpp | 20 +++- 2 files changed, 172 insertions(+), 139 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index f02b809..242e097 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -18,48 +18,50 @@ #include "TestFramework.hpp" /*///////////////////////////////////////////////////////////////////////////// -// Initialization // +// Initialization // /////////////////////////////////////////////////////////////////////////////*/ -TestFramework::TestFramework() { - #ifdef DEVICE_ANALOGIN - map_pins(PinMap_ADC, AnalogInput); +TestFramework::TestFramework() +{ + #ifdef DEVICE_ANALOGIN + map_pins(PinMap_ADC, AnalogInput); map_pins(PinMap_ADC, DigitalIO); - #endif // DEVICE_ANALOGIN + #endif // DEVICE_ANALOGIN - #ifdef DEVICE_ANALOGOUT + #ifdef DEVICE_ANALOGOUT map_pins(PinMap_DAC, AnalogOutput); // map_pins(PinMap_DAC, DigitalIO); grabbing pin number from PeripheralPins.c, instead of the pin translation from mbed_app.json - #endif // DEVICE_ANALOGOUT + #endif // DEVICE_ANALOGOUT - #ifdef DEVICE_I2C - map_pins(PinMap_I2C_SDA, DigitalIO); - map_pins(PinMap_I2C_SCL, DigitalIO); + #ifdef DEVICE_I2C + map_pins(PinMap_I2C_SDA, DigitalIO); + map_pins(PinMap_I2C_SCL, DigitalIO); map_pins(PinMap_I2C_SDA, I2C_SDA); - map_pins(PinMap_I2C_SCL, I2C_SCL); - #endif // DEVICE_I2C + map_pins(PinMap_I2C_SCL, I2C_SCL); + #endif // DEVICE_I2C - #ifdef DEVICE_PWMOUT + #ifdef DEVICE_PWMOUT map_pins(PinMap_PWM, DigitalIO); - map_pins(PinMap_PWM, PWM); - #endif // DEVICE_PWMOUT + map_pins(PinMap_PWM, PWM); + #endif // DEVICE_PWMOUT - #ifdef DEVICE_SPI + #ifdef DEVICE_SPI map_pins(PinMap_SPI_SCLK, DigitalIO); - map_pins(PinMap_SPI_MOSI, DigitalIO); - map_pins(PinMap_SPI_MISO, DigitalIO); - map_pins(PinMap_SPI_SSEL, DigitalIO); + map_pins(PinMap_SPI_MOSI, DigitalIO); + map_pins(PinMap_SPI_MISO, DigitalIO); + map_pins(PinMap_SPI_SSEL, DigitalIO); map_pins(PinMap_SPI_SCLK, SPI_CLK); - map_pins(PinMap_SPI_MOSI, SPI_MOSI); - map_pins(PinMap_SPI_MISO, SPI_MISO); - map_pins(PinMap_SPI_SSEL, SPI_CS); - #endif // DEVICE_SPI + map_pins(PinMap_SPI_MOSI, SPI_MOSI); + map_pins(PinMap_SPI_MISO, SPI_MISO); + map_pins(PinMap_SPI_SSEL, SPI_CS); + #endif // DEVICE_SPI pinout[BusIO] = pinout[DigitalIO]; setup_cits_pins(); } -void TestFramework::setup_cits_pins() { +void TestFramework::setup_cits_pins() +{ pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_0)); pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_1)); pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_2)); @@ -88,49 +90,55 @@ void TestFramework::setup_cits_pins() { } -PinMap TestFramework::construct_pinmap(PinName pin) { - PinMap pinmap = {pin, 0, 0}; - return pinmap; +PinMap TestFramework::construct_pinmap(PinName pin) +{ + PinMap pinmap = {pin, 0, 0}; + return pinmap; } -void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { - int i = 0; - while(pinmap[i].pin != (PinName)NC) { - bool alreadyExists = false; - for (unsigned int j=0; j TestFramework::find_resistor_ladder_pins(PinName pin) { +std::vector TestFramework::find_resistor_ladder_pins(PinName pin) +{ std::vector resistor_ladder_pins; for (unsigned int i = 0; i TestFramework::find_resistor_ladder_pins(PinName pin) { } -unsigned int TestFramework::get_seed() { +unsigned int TestFramework::get_seed() +{ // Send key value pair to greentea host tests greentea_send_kv("return_rand", "seed"); char key[16] = {0}; @@ -189,22 +203,22 @@ unsigned int TestFramework::get_seed() { /*///////////////////////////////////////////////////////////////////////////// -// level0 // -// // +// level0 // +// // // Level 0 tests test the constructor and deconstructor of each pin of a // // specified API. Every pin available for the specified API (ex. Analog in, // // digital io, SPI), gets tested regardless of if it is connected to the CI // -// test shield. // +// test shield. // /////////////////////////////////////////////////////////////////////////////*/ -utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, PinName)) { +utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, PinName)) +{ PinMap sda_pin = pinout[I2C_SDA][pin_iterators[I2C_SDA]]; - // Tag is used to identify if a test case had been executed (true) or not (false) + // Tag is used to identify if a test case had been executed (true) or not (false) bool tag = false; // Itereate through the SCL pins to find a pin that matches the HW block of the SDA pin while (pin_iterators[I2C_SCL] < pinout[I2C_SCL].size()) { if (pinout[I2C_SCL][pin_iterators[I2C_SCL]].peripheral == sda_pin.peripheral) { - // Execution has already occurred, but another SCL pin was found that matches the SDA pin. Queue up another test case if (tag) {return utest::v1::CaseRepeatAll;} // Matching SCL pin was found. Run the callback with the found pins @@ -224,10 +238,11 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, } -utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)) { - bool tag = false; // determines if execution_callback() was ran +utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)) +{ + bool tag = false; // determines if execution_callback() was ran - // Iterate through all CLK pins, finding the remaining SPI pins that have matching HW blocks + // Iterate through all CLK pins, finding the remaining SPI pins that have matching HW blocks while (pin_iterators[SPI_CLK] < pinout[SPI_CLK].size()) { // Iterate through all the MISO pins @@ -236,52 +251,51 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, // Iterate through all the MOSI pins while (pin_iterators[SPI_MOSI] < pinout[SPI_MOSI].size()) { - // Iterate through all the CS pins + // Iterate through all the CS pins while (pin_iterators[SPI_CS] < pinout[SPI_CS].size()) { - // create local variables to help make code easier to read - PinMap CLK = pinout[SPI_CLK][pin_iterators[SPI_CLK]]; - PinMap MISO = pinout[SPI_MISO][pin_iterators[SPI_MISO]]; - PinMap MOSI = pinout[SPI_MOSI][pin_iterators[SPI_MOSI]]; - PinMap CS = pinout[SPI_CS][pin_iterators[SPI_CS]]; - - // ensure that chosen MISO, MOSI, and CS pins match the CLK pin's HW block - if ((MISO.peripheral == CLK.peripheral) && (MOSI.peripheral == CLK.peripheral) && (CS.peripheral == CLK.peripheral)){ - - // ensure that chosen SPI_CLK pin is not already assigned to another peripheral - if((CLK.pin != MISO.pin) && (CLK.pin != MOSI.pin) && (CLK.pin != CS.pin)){ - - // ensure that chosen SPI_MISO pin is not already assigned to another peripheral - if((MISO.pin != CLK.pin) && (MISO.pin != MOSI.pin) && (MISO.pin != CS.pin)){ - - // ensure that chosen SPI_MOSI pin is not already assigned to another peripheral - if((MOSI.pin != CLK.pin) && (MOSI.pin != MISO.pin) && (MOSI.pin != CS.pin)){ - - // ensure that chosen SPI_CS pin is not already assigned to another peripheral - if((CS.pin != CLK.pin) && (CS.pin != MOSI.pin) && (CS.pin != MISO.pin)){ - - // Found matching HW block pins. Run execution callback with them. - execution_callback(CLK.pin, MISO.pin, MOSI.pin, CS.pin); - tag = true; - } + // create local variables to help make code easier to read + PinMap CLK = pinout[SPI_CLK][pin_iterators[SPI_CLK]]; + PinMap MISO = pinout[SPI_MISO][pin_iterators[SPI_MISO]]; + PinMap MOSI = pinout[SPI_MOSI][pin_iterators[SPI_MOSI]]; + PinMap CS = pinout[SPI_CS][pin_iterators[SPI_CS]]; + + // ensure that chosen MISO, MOSI, and CS pins match the CLK pin's HW block + if ((MISO.peripheral == CLK.peripheral) && (MOSI.peripheral == CLK.peripheral) && (CS.peripheral == CLK.peripheral)){ + // ensure that chosen SPI_CLK pin is not already assigned to another peripheral + if((CLK.pin != MISO.pin) && (CLK.pin != MOSI.pin) && (CLK.pin != CS.pin)){ + + // ensure that chosen SPI_MISO pin is not already assigned to another peripheral + if((MISO.pin != CLK.pin) && (MISO.pin != MOSI.pin) && (MISO.pin != CS.pin)){ + + // ensure that chosen SPI_MOSI pin is not already assigned to another peripheral + if((MOSI.pin != CLK.pin) && (MOSI.pin != MISO.pin) && (MOSI.pin != CS.pin)){ + + // ensure that chosen SPI_CS pin is not already assigned to another peripheral + if((CS.pin != CLK.pin) && (CS.pin != MOSI.pin) && (CS.pin != MISO.pin)){ + + // Found matching HW block pins. Run execution callback with them. + execution_callback(CLK.pin, MISO.pin, MOSI.pin, CS.pin); + tag = true; + } + } + } + } + } + pin_iterators[SPI_CS]++; // Increment and try next CS pin + if(tag) {return utest::v1::CaseRepeatAll;} } - } - } - } - pin_iterators[SPI_CS]++; // Increment and try next CS pin - if(tag) {return utest::v1::CaseRepeatAll;} + // Cycled through all CS pins. Reset CS iterator and increment MOSI iterator. + pin_iterators[SPI_CS] = 0; + pin_iterators[SPI_MOSI]++; + } + // Cycled through all MOSI pins. Reset MOSI iterator and increment MISO iterator. + pin_iterators[SPI_MOSI] = 0; + pin_iterators[SPI_MISO]++; } - // Cycled through all CS pins. Reset CS iterator and increment MOSI iterator. - pin_iterators[SPI_CS] = 0; - pin_iterators[SPI_MOSI]++; - } - // Cycled through all MOSI pins. Reset MOSI iterator and increment MISO iterator. - pin_iterators[SPI_MOSI] = 0; - pin_iterators[SPI_MISO]++; + // Cycled through all MISO pins. Reset MISO iterator and increment CLK iterator. + pin_iterators[SPI_MISO] = 0; + pin_iterators[SPI_CLK]++; } - // Cycled through all MISO pins. Reset MISO iterator and increment CLK iterator. - pin_iterators[SPI_MISO] = 0; - pin_iterators[SPI_CLK]++; - } // All pins configurations have been iterated through. Reset pin iterators, run the CI test shield pin pair, and then move on to the next test case pin_iterators[SPI_CLK] = 0; @@ -294,45 +308,47 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, /*////////////////////////////////////////////////////////////////////////////// -// level1 // -// // +// level1 // +// // // Level 1 tests begin to test the full API for each hardware component. // // The API can only be tested on pins mapped to the CI test shield, so the // // following function iterates through all pins associated with the specified // // hardware component until it finds a pin that is also mapped to the CI test // // shield. Once a pin is found, it runs the callback passed in. Note that // -// only one pin is tested for each hardware component. // +// only one pin is tested for each hardware component. // //////////////////////////////////////////////////////////////////////////////*/ -utest::v1::control_t TestFramework::test_level1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) { - while(check_size(pintype)) { - // Get current pin specified by the stored iterator - PinName pin = pinout[pintype][pin_iterators[pintype]].pin; - - // Check to see if current pin is available on the CI test shield - int index = find_pin(pin, testtype); - if (index != -1) { - // Current pin is mapped to the CI test shield. Run the callback, reset the iterator, and run the next case - execution_callback(pin, floatdata, intdata); - pin_iterators[pintype] = 0; - return utest::v1::CaseNext; - } - else{ - // Current pin was not mapped to CI test shield, try another pin - pin_iterators[pintype]++; +utest::v1::control_t TestFramework::test_level1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) +{ + while(check_size(pintype)) { + // Get current pin specified by the stored iterator + PinName pin = pinout[pintype][pin_iterators[pintype]].pin; + + // Check to see if current pin is available on the CI test shield + int index = find_pin(pin, testtype); + if (index != -1) { + // Current pin is mapped to the CI test shield. Run the callback, reset the iterator, and run the next case + execution_callback(pin, floatdata, intdata); + pin_iterators[pintype] = 0; + return utest::v1::CaseNext; + } + else{ + // Current pin was not mapped to CI test shield, try another pin + pin_iterators[pintype]++; + } } - } } /*///////////////////////////////////////////////////////////////////////////// -// level2 // -// // +// level2 // +// // // Level 2 tests test the full API for each hardware similar to level 1 but // // the difference is that the every pin mapped to the CI test shield (not // // just a single pin) is tested. In addition, the tolerance and iterations // -// get a little bit more intense. // +// get a little bit more intense. // /////////////////////////////////////////////////////////////////////////////*/ -utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) { +utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) +{ // Get current pin specified by the stored iterator PinName pin = pinout[pintype][pin_iterators[pintype]].pin; // Check to see if that current pin is available on the CI test shield @@ -360,7 +376,8 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes return utest::v1::CaseRepeatAll; // State: Execute // Pin was found and execution has not occurred yet - } else { + } + else { execution_callback(pin, floatdata, intdata); tag = true; } diff --git a/TestFramework.hpp b/TestFramework.hpp index 2166645..6025209 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -75,16 +75,20 @@ class TestFramework { template - static utest::v1::status_t test_setup(const size_t number_of_cases) { + static utest::v1::status_t test_setup(const size_t number_of_cases) + { GREENTEA_SETUP(timeout, "rand_provider"); return utest::v1::verbose_test_setup_handler(number_of_cases); } - static utest::v1::status_t greentea_failure_handler(const utest::v1::Case *const source, const utest::v1::failure_t reason) { + + static utest::v1::status_t greentea_failure_handler(const utest::v1::Case *const source, const utest::v1::failure_t reason) + { greentea_case_failure_abort_handler(source, reason); return utest::v1::STATUS_ABORT; } + /** * Find a pin within the array of type pintype * @param PinName pin to search for @@ -93,6 +97,7 @@ class TestFramework { **/ static int find_pin(PinName pin, Type pintype); + /** * Find the pin that is connected to the specified pin via a resistor on the DIO HW bank * @param PinName pin to find the corresponding pin connected by the resistor @@ -100,6 +105,7 @@ class TestFramework { **/ static PinName find_pin_pair(PinName pin); + /** * Check to see if the pin iterator is pointing at a valid pin in the pinout * @param Type pin type to validate @@ -107,6 +113,7 @@ class TestFramework { **/ static bool check_size(Type pintype); + /** * Reset the iterator if all pins of the specified pin type have been looked at,
* or proceed to the next pin of the pin type if there are remaining pins @@ -115,6 +122,7 @@ class TestFramework { **/ static utest::v1::control_t reset_iterator(Type pintype); + /** * Get the current pin for a specific pin type, and incrememnt the iterator for that pin type * @param Type pin type to retrieve and increment @@ -122,6 +130,7 @@ class TestFramework { **/ static PinMap get_increment_pin(Type pintype); + /** * Find the resistor ladder pins that are not the specified pin * @param PinName pin that should not be included in the resistor ladder @@ -129,12 +138,14 @@ class TestFramework { **/ static std::vector find_resistor_ladder_pins(PinName pin); + /** * Get a randomized seed from Greentea's host test * @return unsigned int random seed **/ static unsigned int get_seed(); + /** * Find a matching pin based on HW blocks to the current pin. Iterate the corresponding pin after test case execution * @param Callback to a function to run once a pin pairing has been found @@ -142,6 +153,7 @@ class TestFramework { **/ static utest::v1::control_t run_i2c(void (*execution_callback)(PinName, PinName)); + /** * Find a pin set (CLK, MISO, MOSI, CS) based on HW blocks that matches the current pin. Iterate the corresponding pins after test execution * @param Callback to a function to run once a pin pairing has been found @@ -149,6 +161,7 @@ class TestFramework { **/ static utest::v1::control_t run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)); + /** * Find a pin of a specified test type and run a test case (passed in as a callback) * @param Type type of pin to find to run the callback @@ -160,6 +173,7 @@ class TestFramework { **/ static utest::v1::control_t test_level1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); + /** * Find pins of a specified test type and run a test case (passed in as a callback) * Difference from the test_level1_framework function is this runs on ALL pins of a specified test type @@ -180,11 +194,13 @@ class TestFramework { **/ void setup_cits_pins(); + /** * Construct a pinmap from a pin **/ PinMap construct_pinmap(PinName pin); + /** * Put pins from the specified pinmap into the pinout array indexed by pin type * @param PinMap[] Found in the hal, specifies all the pins with a certain type From 53f3bce418b9acd0939ad1a6aba78ebc42d2ff42 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 7 Aug 2017 14:23:19 -0500 Subject: [PATCH 11/21] Modified Level1/I2C. Removed assert testing on write and then read of null string, since the test was not really determining which of the two functions was failing individually. The remaining test should be sufficient enough to test I2C. --- TESTS/Level1/I2C/I2C.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index 1ab1a1b..0dfdf39 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -42,7 +42,7 @@ TestFramework test_framework; char* DEADBEEF = "DEADBEEF"; char NULL_STR[128] = {0}; -template +template utest::v1::control_t test_level1_i2c(const size_t call_count) { @@ -62,23 +62,15 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) // Generate a random string char test_string[128] = {0}; - for (int i=0; i Date: Fri, 11 Aug 2017 14:34:11 -0500 Subject: [PATCH 12/21] Updated assert checking for SPI and I2C Level1 tests, ensuring that Arduino pins are connected to shield properly. Removed unused code from Level1 DIO test. --- TESTS/Level1/DigitalIO/DigitalIO.cpp | 10 +--------- TESTS/Level1/I2C/I2C.cpp | 3 ++- TESTS/Level1/SPI/SPI.cpp | 19 +++++++++---------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index da887a1..c9bd3c1 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -31,18 +31,9 @@ using namespace utest::v1; std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer timer; -int clocked_dio_toggle; - // Initialize a test framework object TestFramework test_framework; -void dio_toggled(void) -{ - clocked_dio_toggle = timer.read_us(); -} - - void test_digitalio_execute(PinName pin, float tolerance, int iterations) { TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -66,6 +57,7 @@ utest::v1::control_t test_level1_digitalio(const size_t call_count) return TestFramework::test_level1_framework(TestFramework::DigitalIO, TestFramework::CITS_DigitalIO, &test_digitalio_execute, 0.05, 10); } + Case cases[] = { Case("Level 1 - Digital In/Out Range test (single pin)", test_level1_digitalio, TestFramework::greentea_failure_handler), }; diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index 0dfdf39..5920c90 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -49,9 +49,10 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) // Check to see if the CI test shield I2C pins are connected to the board PinName pin_scl = MBED_CONF_APP_I2C_SCL; PinName pin_sda = MBED_CONF_APP_I2C_SDA; + if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { - return utest::v1::CaseNext; + TEST_ASSERT_MESSAGE(false,"CI test shield is not properly connected to default I2C pins, or pins are already assigned as greentea's UART pins."); } DEBUG_PRINTF("Running I2C constructor on SDA pin %#x and SCL pin %#x\n", pin_sda, pin_scl); diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index 5407778..2b4e330 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -40,7 +40,7 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -template +template utest::v1::control_t test_level1_spi(const size_t call_count) { // Verify that the CI test shield pins are connected to the SPI pins @@ -52,23 +52,22 @@ utest::v1::control_t test_level1_spi(const size_t call_count) TestFramework::find_pin(pin_miso, TestFramework::SPI_MISO)==-1 || TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || TestFramework::find_pin(pin_cs, TestFramework::SPI_CS)==-1) { - return utest::v1::CaseNext; + TEST_ASSERT_MESSAGE(false,"CI test shield is not properly connected to default SPI pins, or pins are already assigned as greentea's UART pins."); } - - DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); - TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); + TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); // Get a random seed from the Greentea host test - srand(TestFramework::get_seed()); + //srand(TestFramework::get_seed()); TODO: need to fix, causing test error when calling get_seed // Initialize the SD card and file system residing on the SD card - int error = 0; + DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); SDBlockDevice sd(pin_mosi, pin_miso, pin_clk, pin_cs); FATFileSystem fs("sd"); sd.init(); + int error = 0; error = fs.mount(&sd); TEST_ASSERT_MESSAGE(error==0,"SD file system mount failed."); @@ -77,8 +76,8 @@ utest::v1::control_t test_level1_spi(const size_t call_count) // Generate a random string char test_string[128] = {0}; - for (int i=0; i Date: Mon, 14 Aug 2017 09:21:28 -0500 Subject: [PATCH 13/21] Formatted Level2 tests to match mbed style guide. --- TESTS/Level2/AnalogIn/AnalogIn.cpp | 15 +++- TESTS/Level2/BusInOut/BusInOut.cpp | 19 +++-- TESTS/Level2/DigitalIO/DigitalIO.cpp | 16 +++- TESTS/Level2/I2C/I2C.cpp | 56 +++++++------ TESTS/Level2/Pwm/Pwm.cpp | 40 ++++++--- TESTS/Level2/SPI/SPI.cpp | 119 ++++++++++++++------------- 6 files changed, 157 insertions(+), 108 deletions(-) diff --git a/TESTS/Level2/AnalogIn/AnalogIn.cpp b/TESTS/Level2/AnalogIn/AnalogIn.cpp index 5fcacd3..491878f 100644 --- a/TESTS/Level2/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level2/AnalogIn/AnalogIn.cpp @@ -38,14 +38,16 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_analogin_execute(PinName pin, float tolerance, int iterations) { +void test_analogin_execute(PinName pin, float tolerance, int iterations) +{ DEBUG_PRINTF("Running analog input range test on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); // Find all of the pins in the resistor ladder that are not the current pin, organize them into a bus inout std::vector resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin); - if (resistor_ladder_pins.size() < 5) + if (resistor_ladder_pins.size() < 5){ TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); + } BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); outputs.output(); @@ -79,15 +81,20 @@ void test_analogin_execute(PinName pin, float tolerance, int iterations) { } } -utest::v1::control_t test_level2_analogin(const size_t call_count) { + +utest::v1::control_t test_level2_analogin(const size_t call_count) +{ return TestFramework::test_level2_framework(TestFramework::AnalogInput, TestFramework::CITS_AnalogInput, &test_analogin_execute, 0.02, 100); } + Case cases[] = { Case("Level 2 - Analog Input Range test (all pins)", test_level2_analogin, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); diff --git a/TESTS/Level2/BusInOut/BusInOut.cpp b/TESTS/Level2/BusInOut/BusInOut.cpp index 809a653..0877bce 100644 --- a/TESTS/Level2/BusInOut/BusInOut.cpp +++ b/TESTS/Level2/BusInOut/BusInOut.cpp @@ -35,15 +35,18 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; // test that all pins can be marked as BusIn -void busin_define_test(){ +void busin_define_test() +{ BusIn bin(MBED_CONF_APP_DIO_2,MBED_CONF_APP_DIO_3,MBED_CONF_APP_DIO_4,MBED_CONF_APP_DIO_5,MBED_CONF_APP_DIO_6,MBED_CONF_APP_DIO_7,MBED_CONF_APP_DIO_8,MBED_CONF_APP_DIO_9,MBED_CONF_APP_SPI_CS,MBED_CONF_APP_SPI_MOSI,MBED_CONF_APP_AIN_0,MBED_CONF_APP_AIN_1,MBED_CONF_APP_AIN_2,MBED_CONF_APP_AIN_3,MBED_CONF_APP_AIN_4,MBED_CONF_APP_AIN_5); int x = 0; x = bin.read(); TEST_ASSERT_MESSAGE(true,"The fact that it hasnt error out proves this passes the sniff test"); } + // test that all pins can be marked as BusOut -void busout_define_test(){ +void busout_define_test() +{ BusOut bout(MBED_CONF_APP_DIO_2,MBED_CONF_APP_DIO_3,MBED_CONF_APP_DIO_4,MBED_CONF_APP_DIO_5,MBED_CONF_APP_DIO_6,MBED_CONF_APP_DIO_7,MBED_CONF_APP_DIO_8,MBED_CONF_APP_DIO_9,MBED_CONF_APP_SPI_CS,MBED_CONF_APP_SPI_MOSI,MBED_CONF_APP_AIN_0,MBED_CONF_APP_AIN_1,MBED_CONF_APP_AIN_2,MBED_CONF_APP_AIN_3,MBED_CONF_APP_AIN_4,MBED_CONF_APP_AIN_5); bout = 0; volatile int x = 0; @@ -55,8 +58,10 @@ void busout_define_test(){ TEST_ASSERT_MESSAGE(true,"The fact that it hasnt error out proves this passes the sniff test"); } + // test that all pins can be marked as BusInOut -void businout_define_test(){ +void businout_define_test() +{ BusInOut bio1(MBED_CONF_APP_DIO_2,MBED_CONF_APP_DIO_4,MBED_CONF_APP_DIO_6,MBED_CONF_APP_DIO_8); BusInOut bio2(MBED_CONF_APP_DIO_3,MBED_CONF_APP_DIO_5,MBED_CONF_APP_DIO_7,MBED_CONF_APP_DIO_9); bio1.output(); @@ -89,7 +94,8 @@ void businout_define_test(){ } // Test writing from one bus to another -void businout_bidirectional_test(){ +void businout_bidirectional_test() +{ BusIn bin(MBED_CONF_APP_DIO_2,MBED_CONF_APP_DIO_4,MBED_CONF_APP_DIO_6,MBED_CONF_APP_DIO_8); BusOut bout(MBED_CONF_APP_DIO_3,MBED_CONF_APP_DIO_5,MBED_CONF_APP_DIO_7,MBED_CONF_APP_DIO_9); bout = 0; @@ -103,6 +109,7 @@ void businout_bidirectional_test(){ TEST_ASSERT_MESSAGE(true,"The fact that it hasnt error out proves this passes the sniff test"); } + Case cases[] = { Case("Level 2 - Bus Input definable", busin_define_test, TestFramework::greentea_failure_handler), Case("Level 2 - Bus Output definable", busout_define_test, TestFramework::greentea_failure_handler), @@ -110,8 +117,10 @@ Case cases[] = { Case("Level 2 - Bus Input/Output range test 2", businout_bidirectional_test, TestFramework::greentea_failure_handler), }; + // Entry point into the tests -int main() { +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); diff --git a/TESTS/Level2/DigitalIO/DigitalIO.cpp b/TESTS/Level2/DigitalIO/DigitalIO.cpp index cda4a58..3654860 100644 --- a/TESTS/Level2/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -37,11 +37,14 @@ int clocked_dio_toggle; // Initialize a test framework object TestFramework test_framework; -void dio_toggled(void) { +void dio_toggled(void) +{ clocked_dio_toggle = timer.read_us(); } -void test_digitalio_execute(PinName pin, float tolerance, int iterations) { + +void test_digitalio_execute(PinName pin, float tolerance, int iterations) +{ DEBUG_PRINTF("Running digital io test on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -78,15 +81,20 @@ void test_digitalio_execute(PinName pin, float tolerance, int iterations) { } } -utest::v1::control_t test_level2_digitalio(const size_t call_count) { + +utest::v1::control_t test_level2_digitalio(const size_t call_count) +{ return TestFramework::test_level2_framework(TestFramework::DigitalIO, TestFramework::CITS_DigitalIO, &test_digitalio_execute, 0.02, 100); } + Case cases[] = { Case("Level 2 - Digital In/Out Range test (all pins)", test_level2_digitalio, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); diff --git a/TESTS/Level2/I2C/I2C.cpp b/TESTS/Level2/I2C/I2C.cpp index 9277fe5..367453b 100644 --- a/TESTS/Level2/I2C/I2C.cpp +++ b/TESTS/Level2/I2C/I2C.cpp @@ -42,8 +42,8 @@ TestFramework test_framework; char NULL_STR[128] = {0}; template -utest::v1::control_t test_level2_i2c(const size_t call_count) { - +utest::v1::control_t test_level2_i2c(const size_t call_count) +{ // Check to see if the CI test shield I2C pins are connected to the board PinName pin_scl = MBED_CONF_APP_I2C_SCL; PinName pin_sda = MBED_CONF_APP_I2C_SDA; @@ -52,47 +52,51 @@ utest::v1::control_t test_level2_i2c(const size_t call_count) { } DEBUG_PRINTF("Running I2C constructor on SDA pin %d and SCL pin %d\n", pin_sda, pin_scl); - TEST_ASSERT_MESSAGE(pin_sda != NC, "SDA Pin is NC"); - TEST_ASSERT_MESSAGE(pin_scl != NC, "SCL Pin is NC"); + TEST_ASSERT_MESSAGE(pin_sda != NC, "SDA Pin is NC"); + TEST_ASSERT_MESSAGE(pin_scl != NC, "SCL Pin is NC"); - // Get a random seed from the Greentea host test + // Get a random seed from the Greentea host test srand(TestFramework::get_seed()); - I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); // Generate a random string - char test_string[128] = {0}; - for (int i=0; i, TestFramework::greentea_failure_handler), Case("Level 2 - I2C test - 10 byte (all pin set)", test_level2_i2c<10>, TestFramework::greentea_failure_handler), Case("Level 2 - I2C test - 100 byte (all pin set)", test_level2_i2c<100>, TestFramework::greentea_failure_handler), }; - -int main() { + + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level2/Pwm/Pwm.cpp b/TESTS/Level2/Pwm/Pwm.cpp index 59ab203..9487e03 100644 --- a/TESTS/Level2/Pwm/Pwm.cpp +++ b/TESTS/Level2/Pwm/Pwm.cpp @@ -45,20 +45,25 @@ int last_rise_time; int duty_count; // Callback for a PWM rising edge -void callback_pwm_rise(void) { +void callback_pwm_rise(void) +{ rise_count++; last_rise_time = timer.read_ms(); } + // Callback for a PWM falling edge -void callback_pwm_fall(void) { +void callback_pwm_fall(void) +{ fall_count++; - if (last_rise_time != 0) + if (last_rise_time != 0) { duty_count = duty_count + (timer.read_ms() - last_rise_time); + } } -void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycycle, int period) { +void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycycle, int period) +{ // Initialize float calculated_percent = iterations * tolerance; if (calculated_percent < 1) calculated_percent = 1.0f; @@ -101,22 +106,24 @@ void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycy TEST_ASSERT_MESSAGE( std::abs(iterations - fc) <= calculated_percent, "There was more than a specific variance in number of fall cycles seen and number expected."); // @TODO The following assert is a good check to have (comparing times) but fails on most platforms. Need to come up with a better way to do this test // TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= calculated_percent,"Greater than a specific variance between expected and measured duty cycle"); - } + // Test case to just iterate through duty cycles -void test_pwm_dutycycle(PinName pin, float tolerance, int iterations) { +void test_pwm_dutycycle(PinName pin, float tolerance, int iterations) +{ DEBUG_PRINTF("Running pwm test on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); for (float dutycycle=0.05f; dutycycle <= 0.95f; dutycycle+=0.1f) { test_pwm_execute(pin, tolerance, iterations, dutycycle, 10); } - } + // Test case to just iterate through the period -void test_pwm_frequency(PinName pin, float tolerance, int iterations) { +void test_pwm_frequency(PinName pin, float tolerance, int iterations) +{ DEBUG_PRINTF("Running pwm test on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -125,8 +132,10 @@ void test_pwm_frequency(PinName pin, float tolerance, int iterations) { } } + // Test case that combines period and duty cycles -void test_pwm(PinName pin, float tolerance, int iterations) { +void test_pwm(PinName pin, float tolerance, int iterations) +{ DEBUG_PRINTF("Running pwm test on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -137,11 +146,15 @@ void test_pwm(PinName pin, float tolerance, int iterations) { } } -utest::v1::control_t test_level2_pwm_frequency(const size_t call_count) { + +utest::v1::control_t test_level2_pwm_frequency(const size_t call_count) +{ return TestFramework::test_level2_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm_frequency, 0.05f, 20); } -utest::v1::control_t test_level2_pwm_dutycycle(const size_t call_count) { + +utest::v1::control_t test_level2_pwm_dutycycle(const size_t call_count) +{ return TestFramework::test_level2_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm_dutycycle, 0.05f, 20); } @@ -149,13 +162,16 @@ utest::v1::control_t test_level2_pwm(const size_t call_count) { return TestFramework::test_level2_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm, 0.05f, 20); } + Case cases[] = { Case("Level 2 - PWM Frequency test (all pins)", test_level2_pwm_frequency, TestFramework::greentea_failure_handler), Case("Level 2 - PWM Dutycycle test (all pins)", test_level2_pwm_dutycycle, TestFramework::greentea_failure_handler), Case("Level 2 - PWM all tests (all pins)", test_level2_pwm, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<300>, cases); return !Harness::run(specification); diff --git a/TESTS/Level2/SPI/SPI.cpp b/TESTS/Level2/SPI/SPI.cpp index fe08e64..5602a9c 100644 --- a/TESTS/Level2/SPI/SPI.cpp +++ b/TESTS/Level2/SPI/SPI.cpp @@ -41,8 +41,8 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; template -utest::v1::control_t test_level2_spi(const size_t call_count) { - +utest::v1::control_t test_level2_spi(const size_t call_count) +{ // Verify that the CI test shield pins are connected to the SPI pins PinName pin_clk = MBED_CONF_APP_SPI_CLK; PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; @@ -56,69 +56,74 @@ utest::v1::control_t test_level2_spi(const size_t call_count) { } DEBUG_PRINTF("Running SPI constructor on CLK pin %d, MISO pin %d, MOSI pin %d, and CS pin %d\n", pin_clk, pin_miso, pin_mosi, pin_cs); - TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); - TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); - TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); - TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); - - // Get a random seed from the Greentea host test - srand(TestFramework::get_seed()); - - // Initialize the SD card and file system residing on the SD card - int error = 0; - SDBlockDevice sd(pin_mosi, pin_miso, pin_clk, pin_cs); - FATFileSystem fs("sd"); - sd.init(); - error = fs.mount(&sd); - TEST_ASSERT_MESSAGE(error==0,"SD file system mount failed."); - - // Iterate twice for consistency - for (int i=0; i<2; i++) { - - // Generate a random string - char test_string[128] = {0}; - for (int j=0; j 0,"Writing File to sd card failed"); // write data - fclose(File_write);// close file on SD - - // Close the old file, open the same file in read only mode, and read the file - FILE *File_read = fopen(file_name, "r"); // open File_read - char test_string_read[128] = {0}; - fgets(test_string_read, 128, File_read); // read string from the file - DEBUG_PRINTF("Read '%s' in read test\n",test_string_read); - DEBUG_PRINTF("File name: '%s'\n",file_name); - TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string) == 0,"String read does not match string written"); // test that strings match - fclose(File_read);// close file on SD - remove(file_name); - } - - // Unmount and de-initialize the SD card - error = fs.unmount(); - TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); - - sd.deinit(); - - return utest::v1::CaseNext; + TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); + TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); + TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); + TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); + + // Get a random seed from the Greentea host test + srand(TestFramework::get_seed()); + + // Initialize the SD card and file system residing on the SD card + int error = 0; + SDBlockDevice sd(pin_mosi, pin_miso, pin_clk, pin_cs); + FATFileSystem fs("sd"); + sd.init(); + error = fs.mount(&sd); + TEST_ASSERT_MESSAGE(error==0,"SD file system mount failed."); + + // Iterate twice for consistency + for (int i=0; i<2; i++) { + + // Generate a random string + char test_string[128] = {0}; + for (int j=0; j 0,"Writing File to sd card failed"); // write data + fclose(File_write);// close file on SD + + // Close the old file, open the same file in read only mode, and read the file + FILE *File_read = fopen(file_name, "r"); // open File_read + char test_string_read[128] = {0}; + fgets(test_string_read, 128, File_read); // read string from the file + DEBUG_PRINTF("Read '%s' in read test\n",test_string_read); + DEBUG_PRINTF("File name: '%s'\n",file_name); + TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string) == 0,"String read does not match string written"); // test that strings match + fclose(File_read);// close file on SD + remove(file_name); + } + + // Unmount and de-initialize the SD card + error = fs.unmount(); + TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); + + sd.deinit(); + + return utest::v1::CaseNext; } + Case cases[] = { Case("Level 2 - SPI test - 1 byte (all pin sets)", test_level2_spi<1>, TestFramework::greentea_failure_handler), Case("Level 2 - SPI test - 10 byte (all pin sets)", test_level2_spi<10>, TestFramework::greentea_failure_handler), Case("Level 2 - SPI test - 100 byte (all pin sets)", test_level2_spi<100>, TestFramework::greentea_failure_handler), }; -int main() { + +int main() +{ // Formulate a specification and run the tests based on the Case array Specification specification(TestFramework::test_setup<30>, cases); - return !Harness::run(specification); + return !Harness::run(specification); } From ff9724dd19d6eb003caa8c0e480f5dfabec513ee Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 14 Aug 2017 14:39:06 -0500 Subject: [PATCH 14/21] Finished testing and updating Level2 AnalogIn. --- TESTS/Level2/AnalogIn/AnalogIn.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/TESTS/Level2/AnalogIn/AnalogIn.cpp b/TESTS/Level2/AnalogIn/AnalogIn.cpp index 491878f..126aae9 100644 --- a/TESTS/Level2/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level2/AnalogIn/AnalogIn.cpp @@ -29,6 +29,8 @@ #include "TestFramework.hpp" #include +#define BUS_SIZE 5 + using namespace utest::v1; // Static variables for managing the dynamic list of pins @@ -40,22 +42,26 @@ TestFramework test_framework; void test_analogin_execute(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running analog input range test on pin %d\n", pin); + DEBUG_PRINTF("Running analog input range test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - // Find all of the pins in the resistor ladder that are not the current pin, organize them into a bus inout - std::vector resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin); - if (resistor_ladder_pins.size() < 5){ + // Find all of the pins in the resistor ladder that are not the current pin + std::vector resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin); + if (resistor_ladder_pins.size() < BUS_SIZE){ TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); } + + // Create a bus with all of these pins BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); outputs.output(); + DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + + // construct designated analogIn pin AnalogIn ain(pin); for (unsigned int i=0; i prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file") - // Repeat multiple times to verify variability is minimal + + // Repeat multiple times to verify output is not fluctuating for (unsigned int j = 0; j Date: Wed, 16 Aug 2017 10:42:40 -0500 Subject: [PATCH 15/21] Updated level1-spi test so that it no longer checks the cs pin in the CS pinmap, but rather the DigitalIO pinmap, per response of issue that I raised here: https://github.com/ARMmbed/mbed-os/issues/4894 --- TESTS/Level1/SPI/SPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index 2b4e330..21dae6b 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -51,7 +51,7 @@ utest::v1::control_t test_level1_spi(const size_t call_count) if (TestFramework::find_pin(pin_mosi, TestFramework::SPI_MOSI)==-1 || TestFramework::find_pin(pin_miso, TestFramework::SPI_MISO)==-1 || TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || - TestFramework::find_pin(pin_cs, TestFramework::SPI_CS)==-1) { + TestFramework::find_pin(pin_cs, TestFramework::DigitalIO)==-1) { TEST_ASSERT_MESSAGE(false,"CI test shield is not properly connected to default SPI pins, or pins are already assigned as greentea's UART pins."); } TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); From b59a54faf10ec5c650a32caf5488ededacf19e12 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Wed, 16 Aug 2017 10:47:30 -0500 Subject: [PATCH 16/21] Updated level2-spi and level3-spi tests so that they no longer checks the cs pin in the CS pinmap, but rather the DigitalIO pinmap, per response of issue that I raised here: https://github.com/ARMmbed/mbed-os/issues/4894 --- TESTS/Level2/SPI/SPI.cpp | 2 +- TESTS/Level3/SPI/SPI.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TESTS/Level2/SPI/SPI.cpp b/TESTS/Level2/SPI/SPI.cpp index 5602a9c..a0ca6f2 100644 --- a/TESTS/Level2/SPI/SPI.cpp +++ b/TESTS/Level2/SPI/SPI.cpp @@ -51,7 +51,7 @@ utest::v1::control_t test_level2_spi(const size_t call_count) if (TestFramework::find_pin(pin_mosi, TestFramework::SPI_MOSI)==-1 || TestFramework::find_pin(pin_miso, TestFramework::SPI_MISO)==-1 || TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || - TestFramework::find_pin(pin_cs, TestFramework::SPI_CS)==-1) { + TestFramework::find_pin(pin_cs, TestFramework::DigitalIO)==-1) { return utest::v1::CaseNext; } diff --git a/TESTS/Level3/SPI/SPI.cpp b/TESTS/Level3/SPI/SPI.cpp index af1ea3c..1e09013 100644 --- a/TESTS/Level3/SPI/SPI.cpp +++ b/TESTS/Level3/SPI/SPI.cpp @@ -51,7 +51,7 @@ utest::v1::control_t test_level3_spi(const size_t call_count) { if (TestFramework::find_pin(pin_mosi, TestFramework::SPI_MOSI)==-1 || TestFramework::find_pin(pin_miso, TestFramework::SPI_MISO)==-1 || TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || - TestFramework::find_pin(pin_cs, TestFramework::SPI_CS)==-1) { + TestFramework::find_pin(pin_cs, TestFramework::DigitalIO)==-1) { return utest::v1::CaseNext; } From da446dc47ab4689d3d74b8f1e6c606ab71c704e8 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 17 Aug 2017 11:19:20 -0500 Subject: [PATCH 17/21] Level2-DIO test was only running 6 tests on the K64F instead of the intended 8 (one for each DIO pin that has a pin pair). Debugged issue and found that 2 of the DIO pins mapped to the Arduino Headers were not getting mapped to DigitalIO pins since they are only defined in the UART pinmaps in PeripheralPins.c. To fix this, I added UART pins to DIO pin mappings in TestFramework.cpp. --- TESTS/Level2/DigitalIO/DigitalIO.cpp | 2 +- TestFramework.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/TESTS/Level2/DigitalIO/DigitalIO.cpp b/TESTS/Level2/DigitalIO/DigitalIO.cpp index 3654860..978c38c 100644 --- a/TESTS/Level2/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -45,7 +45,7 @@ void dio_toggled(void) void test_digitalio_execute(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running digital io test on pin %d\n", pin); + DEBUG_PRINTF("Running digital io test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); PinName pinpair = TestFramework::find_pin_pair(pin); diff --git a/TestFramework.cpp b/TestFramework.cpp index 242e097..267b2cb 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -29,7 +29,7 @@ TestFramework::TestFramework() #ifdef DEVICE_ANALOGOUT map_pins(PinMap_DAC, AnalogOutput); - // map_pins(PinMap_DAC, DigitalIO); grabbing pin number from PeripheralPins.c, instead of the pin translation from mbed_app.json + // map_pins(PinMap_DAC, DigitalIO); grabbing pin number defined in PinNames.c, instead of the intended pin translation from mbed_app.json #endif // DEVICE_ANALOGOUT #ifdef DEVICE_I2C @@ -55,6 +55,13 @@ TestFramework::TestFramework() map_pins(PinMap_SPI_SSEL, SPI_CS); #endif // DEVICE_SPI + #ifdef DEVICE_SERIAL + map_pins(PinMap_UART_TX, DigitalIO); + map_pins(PinMap_UART_RX, DigitalIO); + map_pins(PinMap_UART_CTS, DigitalIO); + map_pins(PinMap_UART_RTS, DigitalIO); + #endif // DEVICE_SERIAL + pinout[BusIO] = pinout[DigitalIO]; setup_cits_pins(); } @@ -351,9 +358,9 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes { // Get current pin specified by the stored iterator PinName pin = pinout[pintype][pin_iterators[pintype]].pin; - // Check to see if that current pin is available on the CI test shield + // Check to see if that current pin is available on the CI test shield int index = find_pin(pin, testtype); - // Tag is used to identify if a test case had been executed (true) or not (false) + // Tag is used to identify if a test case had been executed (true) or not (false) bool tag = false; // State: Execute if (index != -1) { @@ -366,10 +373,9 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes // State: Increment iterator pin_iterators[pintype]++; pin = pinout[pintype][pin_iterators[pintype]].pin; - // Check to see if the current pin is available on the CI test shield + // Check to see if the current pin is available on the CI test shield index = find_pin(pin, testtype); - - if (index != -1) { + if (index != -1) { // State: End case // Pin was found, but execution had already occurred so queue up another test case if (tag) { From 4260250f2ee470617fd7f9e58c4ad75a43d08c84 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 17 Aug 2017 12:08:32 -0500 Subject: [PATCH 18/21] Finished testing level2/i2c. The logic used to test if write and read occured was not accurate, and not really necessary for the test to begin with, so was removed. --- TESTS/Level2/I2C/I2C.cpp | 48 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/TESTS/Level2/I2C/I2C.cpp b/TESTS/Level2/I2C/I2C.cpp index 367453b..23f3261 100644 --- a/TESTS/Level2/I2C/I2C.cpp +++ b/TESTS/Level2/I2C/I2C.cpp @@ -41,46 +41,42 @@ std::vector TestFramework::pin_iterators(TS_NC); TestFramework test_framework; char NULL_STR[128] = {0}; -template +template utest::v1::control_t test_level2_i2c(const size_t call_count) { - // Check to see if the CI test shield I2C pins are connected to the board + // Assign I2C pins PinName pin_scl = MBED_CONF_APP_I2C_SCL; PinName pin_sda = MBED_CONF_APP_I2C_SDA; - if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { - return utest::v1::CaseNext; - } - DEBUG_PRINTF("Running I2C constructor on SDA pin %d and SCL pin %d\n", pin_sda, pin_scl); + // Check to see if the CI test shield I2C pins are connected to the board + if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || + TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { + TEST_ASSERT_MESSAGE(false,"CI test shield is not properly connected to default I2C pins, or pins are already assigned as greentea's UART pins."); + } + TEST_ASSERT_MESSAGE(pin_sda != NC, "SDA Pin is NC"); TEST_ASSERT_MESSAGE(pin_scl != NC, "SCL Pin is NC"); - // Get a random seed from the Greentea host test - srand(TestFramework::get_seed()); - + DEBUG_PRINTF("Running I2C constructor on SDA pin %#x and SCL pin %#x\n", pin_sda, pin_scl); I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + // Get a random seed from the Greentea host test + //srand(TestFramework::get_seed()); // TODO not working properly. + // Generate a random string char test_string[128] = {0}; - for (int i=0; i, TestFramework::greentea_failure_handler), - Case("Level 2 - I2C test - 10 byte (all pin set)", test_level2_i2c<10>, TestFramework::greentea_failure_handler), - Case("Level 2 - I2C test - 100 byte (all pin set)", test_level2_i2c<100>, TestFramework::greentea_failure_handler), + Case("Level 2 - I2C test - 1 byte to random location", test_level2_i2c<1>, TestFramework::greentea_failure_handler), + Case("Level 2 - I2C test - 10 bytes to random location", test_level2_i2c<10>, TestFramework::greentea_failure_handler), + Case("Level 2 - I2C test - 100 bytes to random location", test_level2_i2c<100>, TestFramework::greentea_failure_handler), }; From ebf68a650135d6a020d7e5d38ead1d89f40a5ac8 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 17 Aug 2017 14:35:29 -0500 Subject: [PATCH 19/21] Removed the UART pins from DIO since having DEVICE_SERIAL defined, does not guarantee that UART_RTS and UART_CTS pins are defined in PeripheralPins.c, which will cause compile time errors if they are missing. For example, K22F does not have these pinmaps. --- TestFramework.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index 267b2cb..ca514bf 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -55,13 +55,6 @@ TestFramework::TestFramework() map_pins(PinMap_SPI_SSEL, SPI_CS); #endif // DEVICE_SPI - #ifdef DEVICE_SERIAL - map_pins(PinMap_UART_TX, DigitalIO); - map_pins(PinMap_UART_RX, DigitalIO); - map_pins(PinMap_UART_CTS, DigitalIO); - map_pins(PinMap_UART_RTS, DigitalIO); - #endif // DEVICE_SERIAL - pinout[BusIO] = pinout[DigitalIO]; setup_cits_pins(); } From cbffcaa4125a201586710bb2d24d52de1539c1bb Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 17 Aug 2017 15:25:29 -0500 Subject: [PATCH 20/21] Finished testing level2-pwm --- TESTS/Level2/Pwm/Pwm.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/TESTS/Level2/Pwm/Pwm.cpp b/TESTS/Level2/Pwm/Pwm.cpp index 9487e03..c80904e 100644 --- a/TESTS/Level2/Pwm/Pwm.cpp +++ b/TESTS/Level2/Pwm/Pwm.cpp @@ -112,7 +112,7 @@ void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycy // Test case to just iterate through duty cycles void test_pwm_dutycycle(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running pwm test on pin %d\n", pin); + DEBUG_PRINTF("Running pwm test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); for (float dutycycle=0.05f; dutycycle <= 0.95f; dutycycle+=0.1f) { @@ -124,7 +124,7 @@ void test_pwm_dutycycle(PinName pin, float tolerance, int iterations) // Test case to just iterate through the period void test_pwm_frequency(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running pwm test on pin %d\n", pin); + DEBUG_PRINTF("Running pwm test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); for (int period=10; period<=200; period+=40) { @@ -136,7 +136,7 @@ void test_pwm_frequency(PinName pin, float tolerance, int iterations) // Test case that combines period and duty cycles void test_pwm(PinName pin, float tolerance, int iterations) { - DEBUG_PRINTF("Running pwm test on pin %d\n", pin); + DEBUG_PRINTF("Running pwm test on pin %#x\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); for (float dutycycle=0.2f; dutycycle <= 0.8f; dutycycle+=0.2f) { @@ -158,6 +158,7 @@ utest::v1::control_t test_level2_pwm_dutycycle(const size_t call_count) return TestFramework::test_level2_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm_dutycycle, 0.05f, 20); } + utest::v1::control_t test_level2_pwm(const size_t call_count) { return TestFramework::test_level2_framework(TestFramework::PWM, TestFramework::CITS_PWM, &test_pwm, 0.05f, 20); } @@ -173,6 +174,6 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<300>, cases); + Specification specification(TestFramework::test_setup<360>, cases); return !Harness::run(specification); } From 7fd4207e5352a39e1a92086cb706318f4b4d30ab Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 18 Aug 2017 14:42:40 -0500 Subject: [PATCH 21/21] Finished testing level2/Spi. Should be finished testing all of level 2 now. --- TESTS/Level2/SPI/SPI.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/TESTS/Level2/SPI/SPI.cpp b/TESTS/Level2/SPI/SPI.cpp index a0ca6f2..bf0ee7b 100644 --- a/TESTS/Level2/SPI/SPI.cpp +++ b/TESTS/Level2/SPI/SPI.cpp @@ -52,21 +52,20 @@ utest::v1::control_t test_level2_spi(const size_t call_count) TestFramework::find_pin(pin_miso, TestFramework::SPI_MISO)==-1 || TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || TestFramework::find_pin(pin_cs, TestFramework::DigitalIO)==-1) { - return utest::v1::CaseNext; + TEST_ASSERT_MESSAGE(false,"CI test shield is not properly connected to default SPI pins, or pins are already assigned as greentea's UART pins."); } - - DEBUG_PRINTF("Running SPI constructor on CLK pin %d, MISO pin %d, MOSI pin %d, and CS pin %d\n", pin_clk, pin_miso, pin_mosi, pin_cs); TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC"); TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC"); TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC"); // Get a random seed from the Greentea host test - srand(TestFramework::get_seed()); + // srand(TestFramework::get_seed()); TODO: not working properly. // Initialize the SD card and file system residing on the SD card - int error = 0; + DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs); SDBlockDevice sd(pin_mosi, pin_miso, pin_clk, pin_cs); + int error = 0; FATFileSystem fs("sd"); sd.init(); error = fs.mount(&sd); @@ -115,9 +114,9 @@ utest::v1::control_t test_level2_spi(const size_t call_count) Case cases[] = { - Case("Level 2 - SPI test - 1 byte (all pin sets)", test_level2_spi<1>, TestFramework::greentea_failure_handler), - Case("Level 2 - SPI test - 10 byte (all pin sets)", test_level2_spi<10>, TestFramework::greentea_failure_handler), - Case("Level 2 - SPI test - 100 byte (all pin sets)", test_level2_spi<100>, TestFramework::greentea_failure_handler), + Case("Level 2 - SPI test - 1 byte of random data to random file name", test_level2_spi<1>, TestFramework::greentea_failure_handler), + Case("Level 2 - SPI test - 10 byte of random data to random file name", test_level2_spi<10>, TestFramework::greentea_failure_handler), + Case("Level 2 - SPI test - 100 byte of random data to random file name", test_level2_spi<100>, TestFramework::greentea_failure_handler), };