From 23db630263a006d30aec5a98eb1e3dcfdddbff02 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Thu, 16 Feb 2017 10:02:05 -0600 Subject: [PATCH 01/28] Initial setup of mbed level testing --- TESTS/L0/AnalogIn/AnalogIn.cpp | 53 ++++++++++++++++++++++++++++++++ TESTS/L0/AnalogOut/AnalogOut.cpp | 53 ++++++++++++++++++++++++++++++++ TESTS/L1/AnalogIn/AnalogIn.cpp | 49 +++++++++++++++++++++++++++++ TESTS/L2/AnalogIn/AnalogIn.cpp | 49 +++++++++++++++++++++++++++++ TESTS/helper.hpp | 47 ++++++++++++++++++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 TESTS/L0/AnalogIn/AnalogIn.cpp create mode 100644 TESTS/L0/AnalogOut/AnalogOut.cpp create mode 100644 TESTS/L1/AnalogIn/AnalogIn.cpp create mode 100644 TESTS/L2/AnalogIn/AnalogIn.cpp create mode 100644 TESTS/helper.hpp diff --git a/TESTS/L0/AnalogIn/AnalogIn.cpp b/TESTS/L0/AnalogIn/AnalogIn.cpp new file mode 100644 index 0000000..8f12c52 --- /dev/null +++ b/TESTS/L0/AnalogIn/AnalogIn.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_ANALOGIN + #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +//TODO: Remove direct link +#include "../../helper.hpp" + +using namespace utest::v1; + +void AnalogIn_constructor(PinName pin) { + DEBUG_PRINTF("Testing Analog Input constructor on pin %d\n", pin); + AnalogIn ain(pin); +} +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L0 - Analog Input Constructors", FindAndRunPins, greentea_failure_handler), +}; + +Specification specification(test_setup, cases); + +int main() { + return !Harness::run(specification); +} diff --git a/TESTS/L0/AnalogOut/AnalogOut.cpp b/TESTS/L0/AnalogOut/AnalogOut.cpp new file mode 100644 index 0000000..c7e0098 --- /dev/null +++ b/TESTS/L0/AnalogOut/AnalogOut.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_ANALOGOUT + #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +//TODO: Remove direct link +#include "../../helper.hpp" + +using namespace utest::v1; + +void AnalogOut_constructor(PinName pin) { + DEBUG_PRINTF("Testing Analog Output constructor on pin %d\n", pin); + AnalogOut aout(pin); +} +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L0 - Analog Output Constructors", FindAndRunPins, greentea_failure_handler), +}; + +Specification specification(test_setup, cases); + +int main() { + return !Harness::run(specification); +} diff --git a/TESTS/L1/AnalogIn/AnalogIn.cpp b/TESTS/L1/AnalogIn/AnalogIn.cpp new file mode 100644 index 0000000..371ef6b --- /dev/null +++ b/TESTS/L1/AnalogIn/AnalogIn.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_ANALOGIN + #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +//TODO: Remove direct link +#include "../../helper.hpp" + +using namespace utest::v1; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L1 - Analog Input full API test single pin", FindAndRunPins, greentea_failure_handler), +}; + +Specification specification(test_setup, cases); + +int main() { + return !Harness::run(specification); +} diff --git a/TESTS/L2/AnalogIn/AnalogIn.cpp b/TESTS/L2/AnalogIn/AnalogIn.cpp new file mode 100644 index 0000000..70514c1 --- /dev/null +++ b/TESTS/L2/AnalogIn/AnalogIn.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_ANALOGIN + #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +//TODO: Remove direct link +#include "../../helper.hpp" + +using namespace utest::v1; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L2 - Analog Input full API test all pins", FindAndRunPins, greentea_failure_handler), +}; + +Specification specification(test_setup, cases); + +int main() { + return !Harness::run(specification); +} diff --git a/TESTS/helper.hpp b/TESTS/helper.hpp new file mode 100644 index 0000000..efdee9c --- /dev/null +++ b/TESTS/helper.hpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" +#include "mbed.h" + +template +void FindAndRunPins() { + int i = 0; + while(pinmap[i].pin != (PinName)NC) { + func(pinmap[i].pin); + i++; + if (iterateOnce) break; + } + TEST_ASSERT(true); +} + +void AnalogIn_PinTest(PinName pin) { + DEBUG_PRINTF("Testing Analog Input library on pin %d\n", pin); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + + AnalogIn ain(pin); + DigitalOut dout(MBED_CONF_APP_DIO_0); + dout=0; + ain.read(); + dout=1; + ain.read(); + + DigitalOut dout_a(pin); + dout_a=0; + dout_a=1; +} From 9c786c84cab321180b5581fc8e77dd02c7e0b2d4 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Tue, 21 Feb 2017 17:44:35 -0600 Subject: [PATCH 02/28] Working version of dynamic pin testing for L0 --- TESTS/L0/AnalogIn/AnalogIn.cpp | 26 ++++++++----- TESTS/L0/AnalogOut/AnalogOut.cpp | 26 ++++++++----- TESTS/helper.hpp | 40 +++++++++++++++++-- TestFramework.cpp | 38 ++++++++++++++++++ TestFramework.hpp | 67 ++++++++++++++++++++++++++++++++ mbed-os.lib | 2 +- mbed_app.json | 2 +- 7 files changed, 178 insertions(+), 23 deletions(-) create mode 100644 TestFramework.cpp create mode 100644 TestFramework.hpp diff --git a/TESTS/L0/AnalogIn/AnalogIn.cpp b/TESTS/L0/AnalogIn/AnalogIn.cpp index 8f12c52..e04ebab 100644 --- a/TESTS/L0/AnalogIn/AnalogIn.cpp +++ b/TESTS/L0/AnalogIn/AnalogIn.cpp @@ -17,21 +17,29 @@ #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. #endif +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" #include "ci_test_config.h" -//TODO: Remove direct link -#include "../../helper.hpp" +#include "TestFramework.hpp" +#include using namespace utest::v1; -void AnalogIn_constructor(PinName pin) { - DEBUG_PRINTF("Testing Analog Input constructor on pin %d\n", pin); - AnalogIn ain(pin); -} +// Static variables for managing the dynamic list of pins +int TestFramework::analog_pin_index; +std::vector TestFramework::analog_in_pins; +std::vector TestFramework::analog_out_pins; + +// Initialize a test framework object +TestFramework test_framework; + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(30, "default_auto"); return verbose_test_setup_handler(number_of_cases); @@ -43,11 +51,11 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L0 - Analog Input Constructors", FindAndRunPins, greentea_failure_handler), + Case("L0 - Analog Input Constructor", TestFramework::test_l0_analogin, greentea_failure_handler), }; -Specification specification(test_setup, cases); - int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/L0/AnalogOut/AnalogOut.cpp b/TESTS/L0/AnalogOut/AnalogOut.cpp index c7e0098..66ec9a5 100644 --- a/TESTS/L0/AnalogOut/AnalogOut.cpp +++ b/TESTS/L0/AnalogOut/AnalogOut.cpp @@ -17,21 +17,29 @@ #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. #endif +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" #include "ci_test_config.h" -//TODO: Remove direct link -#include "../../helper.hpp" +#include "TestFramework.hpp" +#include using namespace utest::v1; -void AnalogOut_constructor(PinName pin) { - DEBUG_PRINTF("Testing Analog Output constructor on pin %d\n", pin); - AnalogOut aout(pin); -} +// Static variables for managing the dynamic list of pins +int TestFramework::analog_pin_index; +std::vector TestFramework::analog_in_pins; +std::vector TestFramework::analog_out_pins; + +// Initialize a test framework object +TestFramework test_framework; + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(30, "default_auto"); return verbose_test_setup_handler(number_of_cases); @@ -43,11 +51,11 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L0 - Analog Output Constructors", FindAndRunPins, greentea_failure_handler), + Case("L0 - Analog Output Constructor", TestFramework::test_l0_analogout, greentea_failure_handler), }; -Specification specification(test_setup, cases); - int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/helper.hpp b/TESTS/helper.hpp index efdee9c..b742e4f 100644 --- a/TESTS/helper.hpp +++ b/TESTS/helper.hpp @@ -30,6 +30,35 @@ void FindAndRunPins() { TEST_ASSERT(true); } +void Analog_RangeTest(PinName pin, float tolerance) { + AnalogIn ain(pin); + AnalogOut aout(pin); + for (float i=0; i<=1; i+=0.1) { + aout=i; + float input = ain.read(); + DEBUG_PRINTF("Is input (%f) between %f and %f?\n", input, i-tolerance, i+tolerance); + TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + + // AnalogIn ain(ain_pin); + // AnalogOut aout(aout_pin); + // float valueOff = 0; + // float valueOn = 0; + // aout = 0; + // valueOff = ain.read(); + // aout = 0.5; + // valueOn = ain.read(); + // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); + // TEST_ASSERT_MESSAGE((0.4f < valueOn) && (0.6f > valueOn), "Value is not in expected range of ~0.5f"); + // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 0.5"); + // valueOff = ain.read(); + // aout = 1.0; + // valueOn = ain.read(); + // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); + // TEST_ASSERT_MESSAGE((0.9f < valueOn) && (1.1f > valueOn), "Value is not in expected range of ~0.5f"); + // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 1.0"); + } +} + void AnalogIn_PinTest(PinName pin) { DEBUG_PRINTF("Testing Analog Input library on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -40,8 +69,13 @@ void AnalogIn_PinTest(PinName pin) { ain.read(); dout=1; ain.read(); + TEST_ASSERT_MESSAGE(true, "Digital writes prevent analog inputs"); + + DigitalOut dout2(pin); + dout2=0; + dout2=1; + TEST_ASSERT_MESSAGE(true, "Analog pins do not dual purpose as digital IO"); + TEST_ASSERT_MESSAGE(ain.read(), "Analog pin did not match digital output"); - DigitalOut dout_a(pin); - dout_a=0; - dout_a=1; + Analog_RangeTest(pin, 0.05); } diff --git a/TestFramework.cpp b/TestFramework.cpp new file mode 100644 index 0000000..ca06a18 --- /dev/null +++ b/TestFramework.cpp @@ -0,0 +1,38 @@ +#include "TestFramework.hpp" + +TestFramework::TestFramework() { + map_pins(PinMap_ADC, &analog_in_pins); + map_pins(PinMap_DAC, &analog_out_pins); +} + +void TestFramework::map_pins(const PinMap pinmap[], std::vector * pin_list) { + int i = 0; + while(pinmap[i].pin != (PinName)NC) { + pin_list->push_back(pinmap[i].pin); + i++; + } +} + +utest::v1::control_t TestFramework::test_l0_analogin(const size_t call_count) { + DEBUG_PRINTF("Running analog input constructor on pin %d\n", analog_in_pins[analog_pin_index]); + AnalogIn ain(analog_in_pins[analog_pin_index++]); + TEST_ASSERT(true); + if (call_count < analog_in_pins.size()) { + return utest::v1::CaseRepeatAll; + } else { + analog_pin_index = 0; + return utest::v1::CaseNext; + } +} + +utest::v1::control_t TestFramework::test_l0_analogout(const size_t call_count) { + DEBUG_PRINTF("Running analog output constructor on pin %d\n", analog_out_pins[analog_pin_index]); + AnalogOut aout(analog_out_pins[analog_pin_index++]); + TEST_ASSERT(true); + if (call_count < analog_out_pins.size()) { + return utest::v1::CaseRepeatAll; + } else { + analog_pin_index = 0; + return utest::v1::CaseNext; + } +} \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp new file mode 100644 index 0000000..0b23316 --- /dev/null +++ b/TestFramework.hpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef TESTFRAMEWORK_H +#define TESTFRAMEWORK_H + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" +#include "mbed.h" + +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include + +using namespace std; + +class TestFramework { +public: + + enum Type { + AnalogInput, + AnalogOutput, + DigitalIO + }; + + // Analog pin iterator + static int analog_pin_index; + // Analog input pins + static vector analog_in_pins; + // Analog output pins + static vector analog_out_pins; + + // Analog In tests + static utest::v1::control_t test_l0_analogin(const size_t call_count); + // Analog Out tests + static utest::v1::control_t test_l0_analogout(const size_t call_count); + + TestFramework(); + +private: + + /** + * Gather all pins in a pinmap defined by the HAL and store them in the corresponding allPins vector + * @param PinMap[] from the HAL + * @param Type specifying which pin type to save the pins as + **/ + void map_pins(const PinMap pinmap[], std::vector * pin_list); + +}; + +#endif //TESTFRAMEWORK_H \ No newline at end of file diff --git a/mbed-os.lib b/mbed-os.lib index c6b22af..3a4b307 100644 --- a/mbed-os.lib +++ b/mbed-os.lib @@ -1 +1 @@ -https://github.com/ARMmbed/mbed-os/#e435a07d9252f133ea3d9f6c95dfb176f32ab9b6 +https://github.com/mray19027/mbed-os/#defc1842331ac39ed0658ca99f14c8a4224d03b2 diff --git a/mbed_app.json b/mbed_app.json index 4efb6af..33f22cc 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -31,7 +31,7 @@ "PWM_1": "D5", "PWM_2": "D6", "PWM_3": "D9", - "DEBUG_MSG": 0 + "DEBUG_MSG": 1 }, "target_overrides": { "K64F": { From 80d2c56ab34b20763cdbc984de696fa896138282 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Thu, 23 Feb 2017 14:09:31 -0600 Subject: [PATCH 03/28] Working state machine for L1/L2 tests --- TESTS/L0/AnalogIn/AnalogIn.cpp | 5 +- TESTS/L0/AnalogOut/AnalogOut.cpp | 5 +- TESTS/L1/AnalogIn/AnalogIn.cpp | 26 +++-- TESTS/helper.hpp | 81 ---------------- TestFramework.cpp | 160 +++++++++++++++++++++++++++---- TestFramework.hpp | 28 ++++-- 6 files changed, 181 insertions(+), 124 deletions(-) delete mode 100644 TESTS/helper.hpp diff --git a/TESTS/L0/AnalogIn/AnalogIn.cpp b/TESTS/L0/AnalogIn/AnalogIn.cpp index e04ebab..8c2cb4c 100644 --- a/TESTS/L0/AnalogIn/AnalogIn.cpp +++ b/TESTS/L0/AnalogIn/AnalogIn.cpp @@ -33,9 +33,8 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -int TestFramework::analog_pin_index; -std::vector TestFramework::analog_in_pins; -std::vector TestFramework::analog_out_pins; +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; diff --git a/TESTS/L0/AnalogOut/AnalogOut.cpp b/TESTS/L0/AnalogOut/AnalogOut.cpp index 66ec9a5..0f6bdde 100644 --- a/TESTS/L0/AnalogOut/AnalogOut.cpp +++ b/TESTS/L0/AnalogOut/AnalogOut.cpp @@ -33,9 +33,8 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -int TestFramework::analog_pin_index; -std::vector TestFramework::analog_in_pins; -std::vector TestFramework::analog_out_pins; +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; diff --git a/TESTS/L1/AnalogIn/AnalogIn.cpp b/TESTS/L1/AnalogIn/AnalogIn.cpp index 371ef6b..7c93419 100644 --- a/TESTS/L1/AnalogIn/AnalogIn.cpp +++ b/TESTS/L1/AnalogIn/AnalogIn.cpp @@ -17,33 +17,39 @@ #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. #endif +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" #include "ci_test_config.h" -//TODO: Remove direct link -#include "../../helper.hpp" +#include "TestFramework.hpp" +#include using namespace utest::v1; +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(30, "default_auto"); return verbose_test_setup_handler(number_of_cases); } -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - Case cases[] = { - Case("L1 - Analog Input full API test single pin", FindAndRunPins, greentea_failure_handler), + Case("L1 - Analog Input Range test (single pin)", TestFramework::test_l1_analogin), }; -Specification specification(test_setup, cases); - int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/helper.hpp b/TESTS/helper.hpp deleted file mode 100644 index b742e4f..0000000 --- a/TESTS/helper.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" -#include "mbed.h" - -template -void FindAndRunPins() { - int i = 0; - while(pinmap[i].pin != (PinName)NC) { - func(pinmap[i].pin); - i++; - if (iterateOnce) break; - } - TEST_ASSERT(true); -} - -void Analog_RangeTest(PinName pin, float tolerance) { - AnalogIn ain(pin); - AnalogOut aout(pin); - for (float i=0; i<=1; i+=0.1) { - aout=i; - float input = ain.read(); - DEBUG_PRINTF("Is input (%f) between %f and %f?\n", input, i-tolerance, i+tolerance); - TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); - - // AnalogIn ain(ain_pin); - // AnalogOut aout(aout_pin); - // float valueOff = 0; - // float valueOn = 0; - // aout = 0; - // valueOff = ain.read(); - // aout = 0.5; - // valueOn = ain.read(); - // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); - // TEST_ASSERT_MESSAGE((0.4f < valueOn) && (0.6f > valueOn), "Value is not in expected range of ~0.5f"); - // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 0.5"); - // valueOff = ain.read(); - // aout = 1.0; - // valueOn = ain.read(); - // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); - // TEST_ASSERT_MESSAGE((0.9f < valueOn) && (1.1f > valueOn), "Value is not in expected range of ~0.5f"); - // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 1.0"); - } -} - -void AnalogIn_PinTest(PinName pin) { - DEBUG_PRINTF("Testing Analog Input library on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - - AnalogIn ain(pin); - DigitalOut dout(MBED_CONF_APP_DIO_0); - dout=0; - ain.read(); - dout=1; - ain.read(); - TEST_ASSERT_MESSAGE(true, "Digital writes prevent analog inputs"); - - DigitalOut dout2(pin); - dout2=0; - dout2=1; - TEST_ASSERT_MESSAGE(true, "Analog pins do not dual purpose as digital IO"); - TEST_ASSERT_MESSAGE(ain.read(), "Analog pin did not match digital output"); - - Analog_RangeTest(pin, 0.05); -} diff --git a/TestFramework.cpp b/TestFramework.cpp index ca06a18..8683d4a 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -1,38 +1,162 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "TestFramework.hpp" TestFramework::TestFramework() { - map_pins(PinMap_ADC, &analog_in_pins); - map_pins(PinMap_DAC, &analog_out_pins); + map_pins(PinMap_ADC, AnalogInput); + map_pins(PinMap_DAC, AnalogOutput); + setup_cits_pins(); + DEBUG_PRINTF("HERE\n"); } -void TestFramework::map_pins(const PinMap pinmap[], std::vector * pin_list) { +void TestFramework::setup_cits_pins() { + pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_0); + pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_1); + pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_2); + pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_3); + pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_4); + pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_5); + pinout[CITS_AnalogOutput].push_back(MBED_CONF_APP_AOUT); +} + +void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { int i = 0; while(pinmap[i].pin != (PinName)NC) { - pin_list->push_back(pinmap[i].pin); + pinout[pintype].push_back(pinmap[i].pin); i++; } } -utest::v1::control_t TestFramework::test_l0_analogin(const size_t call_count) { - DEBUG_PRINTF("Running analog input constructor on pin %d\n", analog_in_pins[analog_pin_index]); - AnalogIn ain(analog_in_pins[analog_pin_index++]); - TEST_ASSERT(true); - if (call_count < analog_in_pins.size()) { +int TestFramework::find_pin(PinName pin, Type pintype) { + for (int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + +// // AnalogIn ain(ain_pin); +// // AnalogOut aout(aout_pin); +// // float valueOff = 0; +// // float valueOn = 0; +// // aout = 0; +// // valueOff = ain.read(); +// // aout = 0.5; +// // valueOn = ain.read(); +// // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); +// // TEST_ASSERT_MESSAGE((0.4f < valueOn) && (0.6f > valueOn), "Value is not in expected range of ~0.5f"); +// // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 0.5"); +// // valueOff = ain.read(); +// // aout = 1.0; +// // valueOn = ain.read(); +// // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); +// // TEST_ASSERT_MESSAGE((0.9f < valueOn) && (1.1f > valueOn), "Value is not in expected range of ~0.5f"); +// // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 1.0"); +// } +// } \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp index 0b23316..314e931 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -36,21 +36,23 @@ class TestFramework { enum Type { AnalogInput, AnalogOutput, - DigitalIO + DigitalIO, + CITS_AnalogInput, + CITS_AnalogOutput, + CITS_DigitalIO, + TS_NC }; - // Analog pin iterator - static int analog_pin_index; - // Analog input pins - static vector analog_in_pins; - // Analog output pins - static vector analog_out_pins; - // Analog In tests static utest::v1::control_t test_l0_analogin(const size_t call_count); + static utest::v1::control_t test_l1_analogin(const size_t call_count); + // Analog Out tests static utest::v1::control_t test_l0_analogout(const size_t call_count); + static vector< vector > pinout; + static vector pin_iterators; + TestFramework(); private: @@ -60,7 +62,15 @@ class TestFramework { * @param PinMap[] from the HAL * @param Type specifying which pin type to save the pins as **/ - void map_pins(const PinMap pinmap[], std::vector * pin_list); + void map_pins(const PinMap pinmap[], Type pintype); + + void setup_cits_pins(); + + static int find_pin(PinName pin, Type pintype); + + static utest::v1::control_t reset_iterator(Type pintype); + + static void test_analogin_execute(PinName pin); }; From ca78d45f01b990187715c80aa857f3aba02da255 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Thu, 23 Feb 2017 16:49:36 -0600 Subject: [PATCH 04/28] Failing analog out --- TESTS/L1/AnalogIn/AnalogIn.cpp | 7 ++- TESTS/L2/AnalogIn/AnalogIn.cpp | 21 +++++-- TestFramework.cpp | 109 ++++++++++++++++++--------------- TestFramework.hpp | 5 +- 4 files changed, 86 insertions(+), 56 deletions(-) diff --git a/TESTS/L1/AnalogIn/AnalogIn.cpp b/TESTS/L1/AnalogIn/AnalogIn.cpp index 7c93419..963c96e 100644 --- a/TESTS/L1/AnalogIn/AnalogIn.cpp +++ b/TESTS/L1/AnalogIn/AnalogIn.cpp @@ -44,8 +44,13 @@ utest::v1::status_t test_setup(const size_t number_of_cases) { return verbose_test_setup_handler(number_of_cases); } +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + Case cases[] = { - Case("L1 - Analog Input Range test (single pin)", TestFramework::test_l1_analogin), + Case("L1 - Analog Input Range test (single pin)", TestFramework::test_l1_analogin, greentea_failure_handler), }; int main() { diff --git a/TESTS/L2/AnalogIn/AnalogIn.cpp b/TESTS/L2/AnalogIn/AnalogIn.cpp index 70514c1..31068ab 100644 --- a/TESTS/L2/AnalogIn/AnalogIn.cpp +++ b/TESTS/L2/AnalogIn/AnalogIn.cpp @@ -17,17 +17,28 @@ #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. #endif +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" #include "ci_test_config.h" -//TODO: Remove direct link -#include "../../helper.hpp" +#include "TestFramework.hpp" +#include using namespace utest::v1; +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(30, "default_auto"); return verbose_test_setup_handler(number_of_cases); @@ -39,11 +50,11 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L2 - Analog Input full API test all pins", FindAndRunPins, greentea_failure_handler), + Case("L2 - Analog Input Range test (all pins)", TestFramework::test_l2_analogin, greentea_failure_handler), }; -Specification specification(test_setup, cases); - int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TestFramework.cpp b/TestFramework.cpp index 8683d4a..c93aebd 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -19,7 +19,6 @@ TestFramework::TestFramework() { map_pins(PinMap_ADC, AnalogInput); map_pins(PinMap_DAC, AnalogOutput); setup_cits_pins(); - DEBUG_PRINTF("HERE\n"); } void TestFramework::setup_cits_pins() { @@ -49,17 +48,16 @@ int TestFramework::find_pin(PinName pin, Type pintype) { } utest::v1::control_t TestFramework::reset_iterator(Type pintype) { - if (pin_iterators[pintype] < pinout[pintype].size()) { - pin_iterators[pintype]++; + if (pin_iterators[pintype] < pinout[pintype].size()) return utest::v1::CaseRepeatAll; - } else { + else { pin_iterators[pintype] = 0; return utest::v1::CaseNext; } } utest::v1::control_t TestFramework::test_l0_analogin(const size_t call_count) { - PinName pin = pinout[AnalogInput][pin_iterators[AnalogInput]]; + PinName pin = pinout[AnalogInput][pin_iterators[AnalogInput]++]; DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -70,7 +68,7 @@ utest::v1::control_t TestFramework::test_l0_analogin(const size_t call_count) { } utest::v1::control_t TestFramework::test_l0_analogout(const size_t call_count) { - PinName pin = pinout[AnalogOutput][pin_iterators[AnalogOutput]]; + PinName pin = pinout[AnalogOutput][pin_iterators[AnalogOutput]++]; DEBUG_PRINTF("Running analog output constructor on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -86,9 +84,35 @@ utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { int tag = 0; // State: Execute if (index != -1) { - test_analogin_execute(pin); - tag = 1; + test_analogin_execute(pin, 0.10); + pin_iterators[AnalogInput] = 0; + return utest::v1::CaseNext; + } + while (pin_iterators[AnalogInput] < pinout[AnalogInput].size()) { + // State: Increment iterator + pin_iterators[AnalogInput]++; + pin = pinout[AnalogInput][pin_iterators[AnalogInput]]; + index = find_pin(pin, CITS_AnalogInput); + + if (index != -1) { + // State: Execute + test_analogin_execute(pin, 0.10); + pin_iterators[AnalogInput] = 0; + return utest::v1::CaseNext; + } + } + // State: End test + return reset_iterator(AnalogInput); +} +utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { + PinName pin = pinout[AnalogInput][pin_iterators[AnalogInput]]; + int index = find_pin(pin, CITS_AnalogInput); + int tag = 0; + // State: Execute + if (index != -1) { + test_analogin_execute(pin, 0.05); + tag = 1; } while (pin_iterators[AnalogInput] < pinout[AnalogInput].size()) { // State: Increment iterator @@ -103,7 +127,7 @@ utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { return utest::v1::CaseRepeatAll; // State: Execute } else { - test_analogin_execute(pin); + test_analogin_execute(pin, 0.05); tag = 1; } } @@ -112,51 +136,38 @@ utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { return reset_iterator(AnalogInput); } -void TestFramework::test_analogin_execute(PinName pin) { +void TestFramework::test_analogin_execute(PinName pin, float tolerance) { DEBUG_PRINTF("Running analog input range test on pin %d\n", pin); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + // Case 1: Digital and Analog non-conflicting AnalogIn ain(pin); DigitalOut dout(MBED_CONF_APP_DIO_0); - dout=0; - ain.read(); + float compare1 = ain.read(); dout=1; - ain.read(); + float compare2 = ain.read(); TEST_ASSERT_MESSAGE(true, "Digital writes prevent analog inputs"); - - DigitalOut dout2(pin); - dout2=0; - dout2=1; - TEST_ASSERT_MESSAGE(true, "Analog pins do not dual purpose as digital IO"); - TEST_ASSERT_MESSAGE(ain.read(), "Analog pin did not match digital output"); -} - -// void Analog_RangeTest(PinName pin, float tolerance) { -// AnalogIn ain(pin); -// AnalogOut aout(pin); -// for (float i=0; i<=1; i+=0.1) { -// aout=i; -// float input = ain.read(); -// DEBUG_PRINTF("Is input (%f) between %f and %f?\n", input, i-tolerance, i+tolerance); -// TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); - -// // AnalogIn ain(ain_pin); -// // AnalogOut aout(aout_pin); -// // float valueOff = 0; -// // float valueOn = 0; -// // aout = 0; -// // valueOff = ain.read(); -// // aout = 0.5; -// // valueOn = ain.read(); -// // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); -// // TEST_ASSERT_MESSAGE((0.4f < valueOn) && (0.6f > valueOn), "Value is not in expected range of ~0.5f"); -// // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 0.5"); -// // valueOff = ain.read(); -// // aout = 1.0; -// // valueOn = ain.read(); -// // DEBUG_PRINTF("\r\n***** valueOff = %f, valueOn = %f \r\n",valueOff, valueOn); -// // TEST_ASSERT_MESSAGE((0.9f < valueOn) && (1.1f > valueOn), "Value is not in expected range of ~0.5f"); -// // TEST_ASSERT_MESSAGE(valueOn > valueOff,"Value has not increased, expected 1.0"); -// } -// } \ No newline at end of file + TEST_ASSERT_MESSAGE(abs(compare1-compare2) (1-tolerance) && input < (1+tolerance), "Analog pin did not match digital output"); + + float input = 0.0f; + AnalogOut aout(MBED_CONF_APP_AOUT); + aout = 0.5; + + TEST_ASSERT_MESSAGE(true, "Analog input pins do not dual purpose as analog output pins"); + for (float i=0.0f; i<=1.0f; i+=0.1f) { + aout=i; + input = ain.read(); + DEBUG_PRINTF("Is input (%f) between %f and %f?\n", input, i-tolerance, i+tolerance); + TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + } +} \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp index 314e931..a44f715 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -27,6 +27,7 @@ #include "ci_test_config.h" #include +#include using namespace std; @@ -46,6 +47,7 @@ class TestFramework { // Analog In tests static utest::v1::control_t test_l0_analogin(const size_t call_count); static utest::v1::control_t test_l1_analogin(const size_t call_count); + static utest::v1::control_t test_l2_analogin(const size_t call_count); // Analog Out tests static utest::v1::control_t test_l0_analogout(const size_t call_count); @@ -70,7 +72,8 @@ class TestFramework { static utest::v1::control_t reset_iterator(Type pintype); - static void test_analogin_execute(PinName pin); + // Analog helper functions + static void test_analogin_execute(PinName pin, float tolerance); }; From 567634caade61925987e144e79a3f21303c3efe1 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Fri, 24 Feb 2017 14:23:26 -0600 Subject: [PATCH 05/28] Working L0-L2 for AnalogIn/Out - intended as the starting framework --- TestFramework.cpp | 70 ++++++++++++++++++++++++----------------------- TestFramework.hpp | 2 +- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index c93aebd..aa89958 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -84,7 +84,7 @@ utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { int tag = 0; // State: Execute if (index != -1) { - test_analogin_execute(pin, 0.10); + test_analogin_execute(pin, 0.10, 10); pin_iterators[AnalogInput] = 0; return utest::v1::CaseNext; } @@ -96,7 +96,7 @@ utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { if (index != -1) { // State: Execute - test_analogin_execute(pin, 0.10); + test_analogin_execute(pin, 0.10, 10); pin_iterators[AnalogInput] = 0; return utest::v1::CaseNext; } @@ -111,7 +111,7 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { int tag = 0; // State: Execute if (index != -1) { - test_analogin_execute(pin, 0.05); + test_analogin_execute(pin, 0.05, 100); tag = 1; } while (pin_iterators[AnalogInput] < pinout[AnalogInput].size()) { @@ -127,7 +127,7 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { return utest::v1::CaseRepeatAll; // State: Execute } else { - test_analogin_execute(pin, 0.05); + test_analogin_execute(pin, 0.05, 100); tag = 1; } } @@ -136,38 +136,40 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { return reset_iterator(AnalogInput); } -void TestFramework::test_analogin_execute(PinName pin, float tolerance) { +void TestFramework::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"); - // Case 1: Digital and Analog non-conflicting - AnalogIn ain(pin); - DigitalOut dout(MBED_CONF_APP_DIO_0); - dout=0; - float compare1 = ain.read(); - dout=1; - float compare2 = ain.read(); - TEST_ASSERT_MESSAGE(true, "Digital writes prevent analog inputs"); - TEST_ASSERT_MESSAGE(abs(compare1-compare2) (1-tolerance) && input < (1+tolerance), "Analog pin did not match digital output"); - - float input = 0.0f; - AnalogOut aout(MBED_CONF_APP_AOUT); - aout = 0.5; - - TEST_ASSERT_MESSAGE(true, "Analog input pins do not dual purpose as analog output pins"); - for (float i=0.0f; i<=1.0f; i+=0.1f) { - aout=i; - input = ain.read(); - DEBUG_PRINTF("Is input (%f) between %f and %f?\n", input, i-tolerance, i+tolerance); - TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + for (int i=0; i (1-tolerance) && input < (1+tolerance), "Analog pin did not match digital output"); + + // Case 3: Range test + float input = 0.0f; + AnalogOut aout(MBED_CONF_APP_AOUT); + aout = 0.5; + TEST_ASSERT_MESSAGE(true, "Analog input pins do not dual purpose as analog output pins"); + for (float i=0.0f; i<=1.0f; i+=0.1f) { + aout=i; + input = ain.read(); + TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + } } } \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp index a44f715..ea57b92 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -73,7 +73,7 @@ class TestFramework { static utest::v1::control_t reset_iterator(Type pintype); // Analog helper functions - static void test_analogin_execute(PinName pin, float tolerance); + static void test_analogin_execute(PinName pin, float tolerance, int iterations); }; From 3d4b143f728b71ce6455ad96d2842c11bfa3639e Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Fri, 24 Feb 2017 16:12:06 -0600 Subject: [PATCH 06/28] DigitalIO framework setup --- TestFramework.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++--- TestFramework.hpp | 8 +++++- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index aa89958..2a42e65 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -18,6 +18,8 @@ TestFramework::TestFramework() { map_pins(PinMap_ADC, AnalogInput); map_pins(PinMap_DAC, AnalogOutput); + map_pins(PinMap_PWM, DigitalIO); + map_pins(PinMap_ADC, DigitalIO); setup_cits_pins(); } @@ -29,6 +31,16 @@ void TestFramework::setup_cits_pins() { pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_4); pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_5); pinout[CITS_AnalogOutput].push_back(MBED_CONF_APP_AOUT); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_0); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_1); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_2); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_3); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_4); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_5); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_6); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_7); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_8); + pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_9); } void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { @@ -78,13 +90,52 @@ utest::v1::control_t TestFramework::test_l0_analogout(const size_t call_count) { return reset_iterator(AnalogOutput); } +utest::v1::control_t TestFramework::test_l0_digitalio(const size_t call_count) { + PinName pin = pinout[DigitalIO][pin_iterators[DigitalIO]++]; + DEBUG_PRINTF("Running digital io constructor on pin %d\n", pin); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + + DigitalOut dout(pin); + DigitalIn din(pin); + + TEST_ASSERT(true); + return reset_iterator(DigitalIO); +} + +utest::v1::control_t TestFramework::test_l1_digitalio(const size_t call_count) { + PinName pin = pinout[DigitalIO][pin_iterators[DigitalIO]]; + int index = find_pin(pin, CITS_DigitalIO); + int tag = 0; + // State: Execute + if (index != -1) { + test_digitalio_execute(pin, 10); + pin_iterators[DigitalIO] = 0; + return utest::v1::CaseNext; + } + while (pin_iterators[DigitalIO] < pinout[DigitalIO].size()) { + // State: Increment iterator + pin_iterators[DigitalIO]++; + pin = pinout[DigitalIO][pin_iterators[DigitalIO]]; + index = find_pin(pin, CITS_DigitalIO); + + if (index != -1) { + // State: Execute + test_digitalio_execute(pin, 10); + pin_iterators[DigitalIO] = 0; + return utest::v1::CaseNext; + } + } + // State: End test + return reset_iterator(DigitalIO); +} + utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { PinName pin = pinout[AnalogInput][pin_iterators[AnalogInput]]; int index = find_pin(pin, CITS_AnalogInput); int tag = 0; // State: Execute if (index != -1) { - test_analogin_execute(pin, 0.10, 10); + test_analogin_execute(pin, 0.05, 10); pin_iterators[AnalogInput] = 0; return utest::v1::CaseNext; } @@ -96,7 +147,7 @@ utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { if (index != -1) { // State: Execute - test_analogin_execute(pin, 0.10, 10); + test_analogin_execute(pin, 0.05, 10); pin_iterators[AnalogInput] = 0; return utest::v1::CaseNext; } @@ -111,7 +162,7 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { int tag = 0; // State: Execute if (index != -1) { - test_analogin_execute(pin, 0.05, 100); + test_analogin_execute(pin, 0.01, 100); tag = 1; } while (pin_iterators[AnalogInput] < pinout[AnalogInput].size()) { @@ -127,7 +178,7 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { return utest::v1::CaseRepeatAll; // State: Execute } else { - test_analogin_execute(pin, 0.05, 100); + test_analogin_execute(pin, 0.01, 100); tag = 1; } } @@ -172,4 +223,18 @@ void TestFramework::test_analogin_execute(PinName pin, float tolerance, int iter TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); } } +} + +void TestFramework::test_digitalio_execute(PinName pin, int iterations) { + DEBUG_PRINTF("Running digital io test on pin %d\n", pin); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + + for (int i=0; i > pinout; static vector pin_iterators; @@ -72,8 +77,9 @@ class TestFramework { static utest::v1::control_t reset_iterator(Type pintype); - // Analog helper functions + // Helper functions static void test_analogin_execute(PinName pin, float tolerance, int iterations); + static void test_digitalio_execute(PinName pin, int iterations); }; From 9be016faedc27b016072aebb80f9037149f62602 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Wed, 1 Mar 2017 14:04:28 -0600 Subject: [PATCH 07/28] Added PWM and DigitalIO tests --- TESTS/L0/DigitalIO/DigitalIO.cpp | 57 ++++++++ TESTS/L0/Pwm/Pwm.cpp | 60 ++++++++ TESTS/L1/DigitalIO/DigitalIO.cpp | 57 ++++++++ TESTS/L1/Pwm/Pwm.cpp | 66 +++++++++ TESTS/L2/DigitalIO/DigitalIO.cpp | 57 ++++++++ TESTS/L2/Pwm/Pwm.cpp | 66 +++++++++ TestFramework.cpp | 226 ++++++++++++++++++++++++------- TestFramework.hpp | 43 +++++- 8 files changed, 574 insertions(+), 58 deletions(-) create mode 100644 TESTS/L0/DigitalIO/DigitalIO.cpp create mode 100644 TESTS/L0/Pwm/Pwm.cpp create mode 100644 TESTS/L1/DigitalIO/DigitalIO.cpp create mode 100644 TESTS/L1/Pwm/Pwm.cpp create mode 100644 TESTS/L2/DigitalIO/DigitalIO.cpp create mode 100644 TESTS/L2/Pwm/Pwm.cpp diff --git a/TESTS/L0/DigitalIO/DigitalIO.cpp b/TESTS/L0/DigitalIO/DigitalIO.cpp new file mode 100644 index 0000000..8b5f9a5 --- /dev/null +++ b/TESTS/L0/DigitalIO/DigitalIO.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L0 - DigitalIO Constructor", TestFramework::test_l0_digitalio, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L0/Pwm/Pwm.cpp b/TESTS/L0/Pwm/Pwm.cpp new file mode 100644 index 0000000..ad21a88 --- /dev/null +++ b/TESTS/L0/Pwm/Pwm.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L0 - PWM Constructor", TestFramework::test_l0_pwm, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L1/DigitalIO/DigitalIO.cpp b/TESTS/L1/DigitalIO/DigitalIO.cpp new file mode 100644 index 0000000..280d97c --- /dev/null +++ b/TESTS/L1/DigitalIO/DigitalIO.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L1 - DigitalIO Range test (single pin)", TestFramework::test_l1_digitalio, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L1/Pwm/Pwm.cpp b/TESTS/L1/Pwm/Pwm.cpp new file mode 100644 index 0000000..e70be4a --- /dev/null +++ b/TESTS/L1/Pwm/Pwm.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); +Timer TestFramework::duty_timer; + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L1 - PWM Range test (single pin) - 10ms", TestFramework::test_l1_pwm<50, 10>, greentea_failure_handler), + Case("L1 - PWM Range test (single pin) - 30ms", TestFramework::test_l1_pwm<50, 30>, greentea_failure_handler), + // Case("L1 - PWM Range test (single pin) - 100ms", TestFramework::test_l1_pwm<50, 100>, greentea_failure_handler), + Case("L1 - PWM Range test (single pin) - 10%", TestFramework::test_l1_pwm<10, 10>, greentea_failure_handler), + Case("L1 - PWM Range test (single pin) - 50%", TestFramework::test_l1_pwm<50, 10>, greentea_failure_handler), + Case("L1 - PWM Range test (single pin) - 90%", TestFramework::test_l1_pwm<90, 10>, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L2/DigitalIO/DigitalIO.cpp b/TESTS/L2/DigitalIO/DigitalIO.cpp new file mode 100644 index 0000000..969ffe0 --- /dev/null +++ b/TESTS/L2/DigitalIO/DigitalIO.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L2 - DigitalIO Range test (all pins)", TestFramework::test_l2_digitalio, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L2/Pwm/Pwm.cpp b/TESTS/L2/Pwm/Pwm.cpp new file mode 100644 index 0000000..5ae9e7f --- /dev/null +++ b/TESTS/L2/Pwm/Pwm.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); +Timer TestFramework::duty_timer; + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(60, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L2 - PWM Range test (all pins) - 10ms", TestFramework::test_l2_pwm<50, 10>, greentea_failure_handler), + Case("L2 - PWM Range test (all pins) - 30ms", TestFramework::test_l2_pwm<50, 30>, greentea_failure_handler), + // Case("L2 - PWM Range test (all pins) - 100ms", TestFramework::test_l2_pwm<50, 100>, greentea_failure_handler), + Case("L2 - PWM Range test (all pins) - 10%", TestFramework::test_l2_pwm<10, 10>, greentea_failure_handler), + Case("L2 - PWM Range test (all pins) - 50%", TestFramework::test_l2_pwm<50, 10>, greentea_failure_handler), + Case("L2 - PWM Range test (all pins) - 90%", TestFramework::test_l2_pwm<90, 10>, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TestFramework.cpp b/TestFramework.cpp index 2a42e65..f953c5e 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -15,11 +15,16 @@ */ #include "TestFramework.hpp" +/////////////////////////////////////////////////////////////////////////////// +// 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_PWM, PWM); setup_cits_pins(); } @@ -41,24 +46,47 @@ void TestFramework::setup_cits_pins() { pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_7); pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_8); pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_9); + pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_0); + pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_1); + pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_2); + pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_3); + } void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { int i = 0; while(pinmap[i].pin != (PinName)NC) { - pinout[pintype].push_back(pinmap[i].pin); + bool alreadyExists = false; + for (unsigned int j=0; j +// utest::v1::control_t TestFramework::test_l1_pwm(const size_t call_count) { +// return test_l1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); +// } + +/////////////////////////////////////////////////////////////////////////////// +// L2 // +/////////////////////////////////////////////////////////////////////////////// + +utest::v1::control_t TestFramework::test_l2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) { + PinName pin = pinout[pintype][pin_iterators[pintype]]; + int index = find_pin(pin, testtype); int tag = 0; // State: Execute if (index != -1) { - test_analogin_execute(pin, 0.01, 100); + execution_callback(pin, floatdata, intdata); tag = 1; } - while (pin_iterators[AnalogInput] < pinout[AnalogInput].size()) { + while (pin_iterators[pintype] < pinout[pintype].size()) { // State: Increment iterator - pin_iterators[AnalogInput]++; - pin = pinout[AnalogInput][pin_iterators[AnalogInput]]; - index = find_pin(pin, CITS_AnalogInput); + pin_iterators[pintype]++; + pin = pinout[pintype][pin_iterators[pintype]]; + index = find_pin(pin, testtype); if (index != -1) { // State: End case @@ -178,20 +222,42 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { return utest::v1::CaseRepeatAll; // State: Execute } else { - test_analogin_execute(pin, 0.01, 100); + execution_callback(pin, floatdata, intdata); tag = 1; } } } // State: End test - return reset_iterator(AnalogInput); + return reset_iterator(pintype); } +utest::v1::control_t TestFramework::test_l2_digitalio(const size_t call_count) { + return test_l2_framework(DigitalIO, CITS_DigitalIO, &test_digitalio_execute, 0.01, 100); +} + +utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { + return test_l2_framework(AnalogInput, CITS_AnalogInput, &test_analogin_execute, 0.01, 100); +} + +utest::v1::control_t TestFramework::test_l2_analogout(const size_t call_count) { + return test_l1_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.01, 100); +} + +// EXISTS IN HEADER - DO NOT UNCOMMENT - HERE FOR REFERENCE +// template +// utest::v1::control_t TestFramework::test_l2_pwm(const size_t call_count) { +// return test_l2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); +// } + +/////////////////////////////////////////////////////////////////////////////// +// Tests // +/////////////////////////////////////////////////////////////////////////////// + void TestFramework::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"); - for (int i=0; i #include -using namespace std; - class TestFramework { public: @@ -38,9 +36,15 @@ class TestFramework { AnalogInput, AnalogOutput, DigitalIO, + PWM, CITS_AnalogInput, CITS_AnalogOutput, CITS_DigitalIO, + CITS_PWM, + RiseCount, + FallCount, + DutyCount, + LastRiseTime, TS_NC }; @@ -51,14 +55,30 @@ class TestFramework { // Analog Out tests static utest::v1::control_t test_l0_analogout(const size_t call_count); + static utest::v1::control_t test_l1_analogout(const size_t call_count); + static utest::v1::control_t test_l2_analogout(const size_t call_count); // Digitial IO tests static utest::v1::control_t test_l0_digitalio(const size_t call_count); static utest::v1::control_t test_l1_digitalio(const size_t call_count); + static utest::v1::control_t test_l2_digitalio(const size_t call_count); + + // PWM tests + static utest::v1::control_t test_l0_pwm(const size_t call_count); + + template + static utest::v1::control_t test_l1_pwm(const size_t call_count) { + return test_l1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); + } + template + static utest::v1::control_t test_l2_pwm(const size_t call_count) { + return test_l2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); + } - static vector< vector > pinout; - static vector pin_iterators; + static std::vector< std::vector > pinout; + static std::vector pin_iterators; + static Timer duty_timer; TestFramework(); @@ -70,16 +90,25 @@ class TestFramework { * @param Type specifying which pin type to save the pins as **/ void map_pins(const PinMap pinmap[], Type pintype); - void setup_cits_pins(); - static int find_pin(PinName pin, Type pintype); + static PinName find_pin_pair(PinName pin); static utest::v1::control_t reset_iterator(Type pintype); + static utest::v1::control_t test_l1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); + static utest::v1::control_t test_l2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); + // Helper functions static void test_analogin_execute(PinName pin, float tolerance, int iterations); - static void test_digitalio_execute(PinName pin, int iterations); + static void test_digitalio_execute(PinName pin, float tolerance, int iterations); + static void test_analogout_execute(PinName pin, float tolerance, int iterations); + static void test_pwm_execute(PinName pin, float dutycycle, int period); + + static volatile int fall_count; + static volatile int rise_count; + static void callback_pwm_fall(void); + static void callback_pwm_rise(void); }; From dac97ca4dee02cb5ff605548819c2548b9854a22 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Thu, 2 Mar 2017 16:59:59 -0600 Subject: [PATCH 08/28] Added I2C and SPI base tests --- TESTS/L0/I2C/I2C.cpp | 60 ++++++++++++++++++++++ TESTS/L0/SPI/SPI.cpp | 62 +++++++++++++++++++++++ TESTS/L1/I2C/I2C.cpp | 60 ++++++++++++++++++++++ TESTS/L1/SPI/SPI.cpp | 62 +++++++++++++++++++++++ TestFramework.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++- TestFramework.hpp | 30 +++++++++++ 6 files changed, 389 insertions(+), 2 deletions(-) create mode 100644 TESTS/L0/I2C/I2C.cpp create mode 100644 TESTS/L0/SPI/SPI.cpp create mode 100644 TESTS/L1/I2C/I2C.cpp create mode 100644 TESTS/L1/SPI/SPI.cpp diff --git a/TESTS/L0/I2C/I2C.cpp b/TESTS/L0/I2C/I2C.cpp new file mode 100644 index 0000000..571e742 --- /dev/null +++ b/TESTS/L0/I2C/I2C.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_I2C + #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L0 - I2C constructor", TestFramework::test_l0_i2c, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L0/SPI/SPI.cpp b/TESTS/L0/SPI/SPI.cpp new file mode 100644 index 0000000..67b27ee --- /dev/null +++ b/TESTS/L0/SPI/SPI.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// check if SPI is supported on this device +#if !DEVICE_SPI + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L0 - SPI Constructor", TestFramework::test_l0_spi, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L1/I2C/I2C.cpp b/TESTS/L1/I2C/I2C.cpp new file mode 100644 index 0000000..deb62b4 --- /dev/null +++ b/TESTS/L1/I2C/I2C.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_I2C + #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L1 - I2C Range test (single pin set)", TestFramework::test_l1_i2c, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L1/SPI/SPI.cpp b/TESTS/L1/SPI/SPI.cpp new file mode 100644 index 0000000..29a53bf --- /dev/null +++ b/TESTS/L1/SPI/SPI.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// check if SPI is supported on this device +#if !DEVICE_SPI + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("L1 - SPI Range test (single pin)", TestFramework::test_l1_spi, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TestFramework.cpp b/TestFramework.cpp index f953c5e..f11e2b9 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -25,6 +25,12 @@ TestFramework::TestFramework() { map_pins(PinMap_PWM, DigitalIO); map_pins(PinMap_ADC, 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(); } @@ -50,7 +56,12 @@ void TestFramework::setup_cits_pins() { pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_1); pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_2); pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_3); - + pinout[CITS_I2C_SDA].push_back(MBED_CONF_APP_I2C_SDA); + pinout[CITS_I2C_SCL].push_back(MBED_CONF_APP_I2C_SCL); + pinout[CITS_SPI_CLK].push_back(MBED_CONF_APP_SPI_CLK); + pinout[CITS_SPI_MISO].push_back(MBED_CONF_APP_SPI_MISO); + pinout[CITS_SPI_MOSI].push_back(MBED_CONF_APP_SPI_MOSI); + pinout[CITS_SPI_CS].push_back(MBED_CONF_APP_SPI_CS); } void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { @@ -147,6 +158,41 @@ utest::v1::control_t TestFramework::test_l0_pwm(const size_t call_count) { return reset_iterator(PWM); } +utest::v1::control_t TestFramework::test_l0_i2c(const size_t call_count) { + PinName pin_sda = pinout[I2C_SDA][pin_iterators[I2C_SDA]++]; + PinName pin_scl = pinout[I2C_SCL][pin_iterators[I2C_SCL]++]; + 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"); + + I2C i2c(pin_sda, pin_scl); + + TEST_ASSERT(true); + reset_iterator(I2C_SDA); + return reset_iterator(I2C_SCL); +} + +utest::v1::control_t TestFramework::test_l0_spi(const size_t call_count) { + PinName pin_clk = pinout[SPI_CLK][pin_iterators[SPI_CLK]++]; + PinName pin_mosi = pinout[SPI_MOSI][pin_iterators[SPI_MOSI]++]; + PinName pin_miso = pinout[SPI_MISO][pin_iterators[SPI_MISO]++]; + PinName pin_cs = pinout[SPI_CS][pin_iterators[SPI_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); + 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(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK); + DigitalOut cs(MBED_CONF_APP_SPI_CS); + + TEST_ASSERT(true); + reset_iterator(SPI_MOSI); + reset_iterator(SPI_MISO); + reset_iterator(SPI_CS); + return reset_iterator(SPI_CLK); +} + /////////////////////////////////////////////////////////////////////////////// // L1 // /////////////////////////////////////////////////////////////////////////////// @@ -196,6 +242,14 @@ utest::v1::control_t TestFramework::test_l1_analogout(const size_t call_count) { // return test_l1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); // } +utest::v1::control_t TestFramework::test_l1_i2c(const size_t call_count) { + return test_l1_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.05, 10); +} + +utest::v1::control_t TestFramework::test_l1_spi(const size_t call_count) { + return test_l1_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.05, 10); +} + /////////////////////////////////////////////////////////////////////////////// // L2 // /////////////////////////////////////////////////////////////////////////////// @@ -240,7 +294,7 @@ utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { } utest::v1::control_t TestFramework::test_l2_analogout(const size_t call_count) { - return test_l1_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.01, 100); + return test_l2_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.01, 100); } // EXISTS IN HEADER - DO NOT UNCOMMENT - HERE FOR REFERENCE @@ -249,6 +303,14 @@ utest::v1::control_t TestFramework::test_l2_analogout(const size_t call_count) { // return test_l2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); // } +utest::v1::control_t TestFramework::test_l2_i2c(const size_t call_count) { + return test_l2_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.01, 100); +} + +utest::v1::control_t TestFramework::test_l2_spi(const size_t call_count) { + return test_l2_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.01, 100); +} + /////////////////////////////////////////////////////////////////////////////// // Tests // /////////////////////////////////////////////////////////////////////////////// @@ -361,4 +423,55 @@ void TestFramework::test_pwm_execute(PinName pin, float dutycycle, int period) { 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."); TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= calculated_percent,"Greater than a specific variance between expected and measured duty cycle"); +} + +void TestFramework::test_i2c_execute(PinName pin_scl, float null_float, int null_int) { + PinName pin_sda = pinout[I2C_SDA][pin_iterators[I2C_SCL]]; + 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"); + + I2C i2c(pin_sda, pin_scl); + I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + char test = 'A' + rand()%26; + char read; + int r = 0; + int w = 0; + w = memory.write(1,test); + r = memory.read(1,read); + DEBUG_PRINTF("Num Bytes Read = %d\nNum Bytes Written = %d\nRead byte = `%c`\nWritten Byte = `%c`\n",r,w,read,test); + + TEST_ASSERT_EQUAL_MESSAGE(test,read,"Character Read does not equal character written!"); + TEST_ASSERT_MESSAGE(test == read, "character written does not match character read") + + TEST_ASSERT(true); +} + +void TestFramework::test_spi_execute(PinName pin_clk, float null_float, int null_int) { + char test_string_write[TEST_STRING_MAX] = {0}; + + PinName pin_mosi = pinout[SPI_MOSI][pin_iterators[SPI_CLK]]; + PinName pin_miso = pinout[SPI_MISO][pin_iterators[SPI_CLK]]; + PinName pin_cs = pinout[SPI_CS][pin_iterators[SPI_CLK]]; + 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"); + + SDFileSystem sd(pin_mosi, pin_miso, pin_clk, pin_cs, "sd"); + FILE *File_write = fopen("/sd/test_card.txt", "w"); // open File_write + TEST_ASSERT_MESSAGE(File_write != NULL,"SD Card is not present. Please insert an SD Card."); + TEST_ASSERT_MESSAGE(fprintf(File_write, test_string_write) > 0,"Writing File to sd card failed"); // write data + fclose(File_write);// close file on SD + + FILE *File_read = fopen("/sd/test_card.txt", "r"); // open File_read + char test_string_read [TEST_STRING_MAX] = {0}; + fgets(test_string_read,TEST_STRING_MAX,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_write)); + TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string_write) == 0,"String read does not match string written"); // test that strings match + + // fclose(File);// close file on SD + + TEST_ASSERT(true); } \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp index 7b52e2a..f49b242 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -25,9 +25,14 @@ #include "unity.h" #include "utest.h" #include "ci_test_config.h" +#include +#include "SDFileSystem.h" #include #include +#include + +#define TEST_STRING_MAX 100 class TestFramework { public: @@ -37,10 +42,22 @@ class TestFramework { AnalogOutput, DigitalIO, PWM, + I2C_SDA, + I2C_SCL, + SPI_MISO, + SPI_MOSI, + SPI_CLK, + SPI_CS, CITS_AnalogInput, CITS_AnalogOutput, CITS_DigitalIO, CITS_PWM, + CITS_I2C_SDA, + CITS_I2C_SCL, + CITS_SPI_MOSI, + CITS_SPI_MISO, + CITS_SPI_CLK, + CITS_SPI_CS, RiseCount, FallCount, DutyCount, @@ -76,6 +93,17 @@ class TestFramework { return test_l2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); } + // I2C tests + static utest::v1::control_t test_l0_i2c(const size_t call_count); + static utest::v1::control_t test_l1_i2c(const size_t call_count); + static utest::v1::control_t test_l2_i2c(const size_t call_count); + + // SPI tests + static utest::v1::control_t test_l0_spi(const size_t call_count); + static utest::v1::control_t test_l1_spi(const size_t call_count); + static utest::v1::control_t test_l2_spi(const size_t call_count); + + // Static variables static std::vector< std::vector > pinout; static std::vector pin_iterators; static Timer duty_timer; @@ -104,6 +132,8 @@ class TestFramework { static void test_digitalio_execute(PinName pin, float tolerance, int iterations); static void test_analogout_execute(PinName pin, float tolerance, int iterations); static void test_pwm_execute(PinName pin, float dutycycle, int period); + static void test_i2c_execute(PinName pin, float tolerance, int iterations); + static void test_spi_execute(PinName pin, float tolerance, int iterations); static volatile int fall_count; static volatile int rise_count; From e49460f42797e69ef9a272f5f88b2b7a8f2a0002 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Fri, 10 Mar 2017 19:57:34 +0000 Subject: [PATCH 09/28] Finished Level0 tests --- TESTS/L2/DigitalIO/DigitalIO.cpp | 57 --- TESTS/{L2 => Level0}/AnalogIn/AnalogIn.cpp | 15 +- TESTS/{L0 => Level0}/AnalogOut/AnalogOut.cpp | 15 +- .../DigitalIO/DigitalIO.cpp} | 21 +- TESTS/{L0 => Level0}/I2C/I2C.cpp | 18 +- TESTS/{L0 => Level0}/Pwm/Pwm.cpp | 17 +- TESTS/Level0/SPI/SPI.cpp | 80 ++++ TESTS/{L1 => Level1}/AnalogIn/AnalogIn.cpp | 2 +- TESTS/{L0 => Level1}/DigitalIO/DigitalIO.cpp | 2 +- TESTS/{L1 => Level1}/I2C/I2C.cpp | 2 +- TESTS/{L1 => Level1}/Pwm/Pwm.cpp | 12 +- TESTS/{L1 => Level1}/SPI/SPI.cpp | 2 +- TESTS/{L0 => Level2}/AnalogIn/AnalogIn.cpp | 2 +- TESTS/{L1 => Level2}/DigitalIO/DigitalIO.cpp | 2 +- TESTS/{L2 => Level2}/Pwm/Pwm.cpp | 12 +- TestFramework.cpp | 375 ++++++++++-------- TestFramework.hpp | 60 +-- 17 files changed, 418 insertions(+), 276 deletions(-) delete mode 100644 TESTS/L2/DigitalIO/DigitalIO.cpp rename TESTS/{L2 => Level0}/AnalogIn/AnalogIn.cpp (76%) rename TESTS/{L0 => Level0}/AnalogOut/AnalogOut.cpp (76%) rename TESTS/{L0/SPI/SPI.cpp => Level0/DigitalIO/DigitalIO.cpp} (73%) rename TESTS/{L0 => Level0}/I2C/I2C.cpp (76%) rename TESTS/{L0 => Level0}/Pwm/Pwm.cpp (76%) create mode 100644 TESTS/Level0/SPI/SPI.cpp rename TESTS/{L1 => Level1}/AnalogIn/AnalogIn.cpp (93%) rename TESTS/{L0 => Level1}/DigitalIO/DigitalIO.cpp (93%) rename TESTS/{L1 => Level1}/I2C/I2C.cpp (94%) rename TESTS/{L1 => Level1}/Pwm/Pwm.cpp (71%) rename TESTS/{L1 => Level1}/SPI/SPI.cpp (94%) rename TESTS/{L0 => Level2}/AnalogIn/AnalogIn.cpp (93%) rename TESTS/{L1 => Level2}/DigitalIO/DigitalIO.cpp (93%) rename TESTS/{L2 => Level2}/Pwm/Pwm.cpp (71%) diff --git a/TESTS/L2/DigitalIO/DigitalIO.cpp b/TESTS/L2/DigitalIO/DigitalIO.cpp deleted file mode 100644 index 969ffe0..0000000 --- a/TESTS/L2/DigitalIO/DigitalIO.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - -#include "mbed.h" -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "ci_test_config.h" - -#include "TestFramework.hpp" -#include - -using namespace utest::v1; - -// Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); - -// Initialize a test framework object -TestFramework test_framework; - -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - -Case cases[] = { - Case("L2 - DigitalIO Range test (all pins)", TestFramework::test_l2_digitalio, greentea_failure_handler), -}; - -int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); -} diff --git a/TESTS/L2/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp similarity index 76% rename from TESTS/L2/AnalogIn/AnalogIn.cpp rename to TESTS/Level0/AnalogIn/AnalogIn.cpp index 31068ab..a192341 100644 --- a/TESTS/L2/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -33,7 +33,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -49,8 +49,19 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +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); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + + AnalogIn ain(pin.pin); + + TEST_ASSERT(true); + return test_framework.reset_iterator(TestFramework::AnalogInput); +} + Case cases[] = { - Case("L2 - Analog Input Range test (all pins)", TestFramework::test_l2_analogin, greentea_failure_handler), + Case("Level 0 - Analog Input Constructor", test_level0_analogin, greentea_failure_handler), }; int main() { diff --git a/TESTS/L0/AnalogOut/AnalogOut.cpp b/TESTS/Level0/AnalogOut/AnalogOut.cpp similarity index 76% rename from TESTS/L0/AnalogOut/AnalogOut.cpp rename to TESTS/Level0/AnalogOut/AnalogOut.cpp index 0f6bdde..18b5d53 100644 --- a/TESTS/L0/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level0/AnalogOut/AnalogOut.cpp @@ -33,7 +33,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -49,8 +49,19 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +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); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + + AnalogOut ain(pin.pin); + + TEST_ASSERT(true); + return test_framework.reset_iterator(TestFramework::AnalogOutput); +} + Case cases[] = { - Case("L0 - Analog Output Constructor", TestFramework::test_l0_analogout, greentea_failure_handler), + Case("Level 0 - Analog Output Constructor", test_level0_analogout, greentea_failure_handler), }; int main() { diff --git a/TESTS/L0/SPI/SPI.cpp b/TESTS/Level0/DigitalIO/DigitalIO.cpp similarity index 73% rename from TESTS/L0/SPI/SPI.cpp rename to TESTS/Level0/DigitalIO/DigitalIO.cpp index 67b27ee..f0f87de 100644 --- a/TESTS/L0/SPI/SPI.cpp +++ b/TESTS/Level0/DigitalIO/DigitalIO.cpp @@ -14,11 +14,6 @@ * limitations under the License. */ -// check if SPI is supported on this device -#if !DEVICE_SPI - #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. -#endif - #include "cmsis.h" #include "pinmap.h" #include "PeripheralPins.h" @@ -35,7 +30,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -51,8 +46,20 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +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); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + + DigitalOut dout(pin.pin); + DigitalIn din(pin.pin); + + TEST_ASSERT(true); + return test_framework.reset_iterator(TestFramework::DigitalIO); +} + Case cases[] = { - Case("L0 - SPI Constructor", TestFramework::test_l0_spi, greentea_failure_handler), + Case("Level 0 - DigitalIO Constructor", test_level0_digitalio, greentea_failure_handler), }; int main() { diff --git a/TESTS/L0/I2C/I2C.cpp b/TESTS/Level0/I2C/I2C.cpp similarity index 76% rename from TESTS/L0/I2C/I2C.cpp rename to TESTS/Level0/I2C/I2C.cpp index 571e742..f719b5b 100644 --- a/TESTS/L0/I2C/I2C.cpp +++ b/TESTS/Level0/I2C/I2C.cpp @@ -33,7 +33,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -49,8 +49,22 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +void construct_i2c(PinName sda, PinName scl) { + DEBUG_PRINTF("Running I2C Constructor on SDA pin %d and SCL pin %d\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); + + TEST_ASSERT(true); +} + +utest::v1::control_t test_level0_i2c(const size_t call_count) { + return test_framework.run_i2c(&construct_i2c); +} + Case cases[] = { - Case("L0 - I2C constructor", TestFramework::test_l0_i2c, greentea_failure_handler), + Case("Level 0 - I2C Constructor", test_level0_i2c, greentea_failure_handler), }; int main() { diff --git a/TESTS/L0/Pwm/Pwm.cpp b/TESTS/Level0/Pwm/Pwm.cpp similarity index 76% rename from TESTS/L0/Pwm/Pwm.cpp rename to TESTS/Level0/Pwm/Pwm.cpp index ad21a88..90026a3 100644 --- a/TESTS/L0/Pwm/Pwm.cpp +++ b/TESTS/Level0/Pwm/Pwm.cpp @@ -33,7 +33,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -49,8 +49,21 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +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); + TEST_ASSERT_MESSAGE(pin.pin != NC, "pin is NC"); + + PwmOut pwm(pin.pin); + pwm.period(1.0f); + pwm.write(0.5f); + + TEST_ASSERT(true); + return test_framework.reset_iterator(TestFramework::PWM); +} + Case cases[] = { - Case("L0 - PWM Constructor", TestFramework::test_l0_pwm, greentea_failure_handler), + Case("Level 0 - PWM Constructor", test_level0_pwm, greentea_failure_handler), }; int main() { diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp new file mode 100644 index 0000000..bebaab4 --- /dev/null +++ b/TESTS/Level0/SPI/SPI.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// check if SPI is supported on this device +#if !DEVICE_SPI + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +void construct_i2c(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); + 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); + + TEST_ASSERT(true); +} + +utest::v1::control_t test_level0_spi(const size_t call_count) { + return test_framework.run_spi(&construct_i2c); +} + + +Case cases[] = { + Case("Level 0 - SPI Constructor", test_level0_spi, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/L1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp similarity index 93% rename from TESTS/L1/AnalogIn/AnalogIn.cpp rename to TESTS/Level1/AnalogIn/AnalogIn.cpp index 963c96e..5ecdf30 100644 --- a/TESTS/L1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -50,7 +50,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L1 - Analog Input Range test (single pin)", TestFramework::test_l1_analogin, greentea_failure_handler), + Case("Level 1 - Analog Input Range test (single pin)", TestFramework::test_level1_analogin, greentea_failure_handler), }; int main() { diff --git a/TESTS/L0/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp similarity index 93% rename from TESTS/L0/DigitalIO/DigitalIO.cpp rename to TESTS/Level1/DigitalIO/DigitalIO.cpp index 8b5f9a5..47c55bf 100644 --- a/TESTS/L0/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -47,7 +47,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L0 - DigitalIO Constructor", TestFramework::test_l0_digitalio, greentea_failure_handler), + Case("Level 1 - DigitalIO Range test (single pin)", TestFramework::test_level1_digitalio, greentea_failure_handler), }; int main() { diff --git a/TESTS/L1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp similarity index 94% rename from TESTS/L1/I2C/I2C.cpp rename to TESTS/Level1/I2C/I2C.cpp index deb62b4..8873beb 100644 --- a/TESTS/L1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -50,7 +50,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L1 - I2C Range test (single pin set)", TestFramework::test_l1_i2c, greentea_failure_handler), + Case("Level 1 - I2C Range test (single pin set)", TestFramework::test_level1_i2c, greentea_failure_handler), }; int main() { diff --git a/TESTS/L1/Pwm/Pwm.cpp b/TESTS/Level1/Pwm/Pwm.cpp similarity index 71% rename from TESTS/L1/Pwm/Pwm.cpp rename to TESTS/Level1/Pwm/Pwm.cpp index e70be4a..ee83a64 100644 --- a/TESTS/L1/Pwm/Pwm.cpp +++ b/TESTS/Level1/Pwm/Pwm.cpp @@ -51,12 +51,12 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L1 - PWM Range test (single pin) - 10ms", TestFramework::test_l1_pwm<50, 10>, greentea_failure_handler), - Case("L1 - PWM Range test (single pin) - 30ms", TestFramework::test_l1_pwm<50, 30>, greentea_failure_handler), - // Case("L1 - PWM Range test (single pin) - 100ms", TestFramework::test_l1_pwm<50, 100>, greentea_failure_handler), - Case("L1 - PWM Range test (single pin) - 10%", TestFramework::test_l1_pwm<10, 10>, greentea_failure_handler), - Case("L1 - PWM Range test (single pin) - 50%", TestFramework::test_l1_pwm<50, 10>, greentea_failure_handler), - Case("L1 - PWM Range test (single pin) - 90%", TestFramework::test_l1_pwm<90, 10>, greentea_failure_handler), + Case("Level 1 - PWM Range test (single pin) - 10ms", TestFramework::test_level1_pwm<50, 10>, greentea_failure_handler), + Case("Level 1 - PWM Range test (single pin) - 30ms", TestFramework::test_level1_pwm<50, 30>, greentea_failure_handler), + // Case("Level 1 - PWM Range test (single pin) - 100ms", TestFramework::test_level1_pwm<50, 100>, greentea_failure_handler), + Case("Level 1 - PWM Range test (single pin) - 10%", TestFramework::test_level1_pwm<10, 10>, greentea_failure_handler), + Case("Level 1 - PWM Range test (single pin) - 50%", TestFramework::test_level1_pwm<50, 10>, greentea_failure_handler), + Case("Level 1 - PWM Range test (single pin) - 90%", TestFramework::test_level1_pwm<90, 10>, greentea_failure_handler), }; int main() { diff --git a/TESTS/L1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp similarity index 94% rename from TESTS/L1/SPI/SPI.cpp rename to TESTS/Level1/SPI/SPI.cpp index 29a53bf..c9bb817 100644 --- a/TESTS/L1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -52,7 +52,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L1 - SPI Range test (single pin)", TestFramework::test_l1_spi, greentea_failure_handler), + Case("Level 1 - SPI Range test (single pin)", TestFramework::test_level1_spi, greentea_failure_handler), }; int main() { diff --git a/TESTS/L0/AnalogIn/AnalogIn.cpp b/TESTS/Level2/AnalogIn/AnalogIn.cpp similarity index 93% rename from TESTS/L0/AnalogIn/AnalogIn.cpp rename to TESTS/Level2/AnalogIn/AnalogIn.cpp index 8c2cb4c..a3eb250 100644 --- a/TESTS/L0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level2/AnalogIn/AnalogIn.cpp @@ -50,7 +50,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L0 - Analog Input Constructor", TestFramework::test_l0_analogin, greentea_failure_handler), + Case("Level 2 - Analog Input Range test (all pins)", TestFramework::test_level2_analogin, greentea_failure_handler), }; int main() { diff --git a/TESTS/L1/DigitalIO/DigitalIO.cpp b/TESTS/Level2/DigitalIO/DigitalIO.cpp similarity index 93% rename from TESTS/L1/DigitalIO/DigitalIO.cpp rename to TESTS/Level2/DigitalIO/DigitalIO.cpp index 280d97c..c8870d2 100644 --- a/TESTS/L1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -47,7 +47,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L1 - DigitalIO Range test (single pin)", TestFramework::test_l1_digitalio, greentea_failure_handler), + Case("Level 2 - DigitalIO Range test (all pins)", TestFramework::test_level2_digitalio, greentea_failure_handler), }; int main() { diff --git a/TESTS/L2/Pwm/Pwm.cpp b/TESTS/Level2/Pwm/Pwm.cpp similarity index 71% rename from TESTS/L2/Pwm/Pwm.cpp rename to TESTS/Level2/Pwm/Pwm.cpp index 5ae9e7f..f86e2f5 100644 --- a/TESTS/L2/Pwm/Pwm.cpp +++ b/TESTS/Level2/Pwm/Pwm.cpp @@ -51,12 +51,12 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("L2 - PWM Range test (all pins) - 10ms", TestFramework::test_l2_pwm<50, 10>, greentea_failure_handler), - Case("L2 - PWM Range test (all pins) - 30ms", TestFramework::test_l2_pwm<50, 30>, greentea_failure_handler), - // Case("L2 - PWM Range test (all pins) - 100ms", TestFramework::test_l2_pwm<50, 100>, greentea_failure_handler), - Case("L2 - PWM Range test (all pins) - 10%", TestFramework::test_l2_pwm<10, 10>, greentea_failure_handler), - Case("L2 - PWM Range test (all pins) - 50%", TestFramework::test_l2_pwm<50, 10>, greentea_failure_handler), - Case("L2 - PWM Range test (all pins) - 90%", TestFramework::test_l2_pwm<90, 10>, greentea_failure_handler), + Case("Level 2 - PWM Range test (all pins) - 10ms", TestFramework::test_level2_pwm<50, 10>, greentea_failure_handler), + Case("Level 2 - PWM Range test (all pins) - 30ms", TestFramework::test_level2_pwm<50, 30>, greentea_failure_handler), + // Case("Level 2 - PWM Range test (all pins) - 100ms", TestFramework::test_level2_pwm<50, 100>, greentea_failure_handler), + Case("Level 2 - PWM Range test (all pins) - 10%", TestFramework::test_level2_pwm<10, 10>, greentea_failure_handler), + Case("Level 2 - PWM Range test (all pins) - 50%", TestFramework::test_level2_pwm<50, 10>, greentea_failure_handler), + Case("Level 2 - PWM Range test (all pins) - 90%", TestFramework::test_level2_pwm<90, 10>, greentea_failure_handler), }; int main() { diff --git a/TestFramework.cpp b/TestFramework.cpp index f11e2b9..65eeb7c 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -15,9 +15,9 @@ */ #include "TestFramework.hpp" -/////////////////////////////////////////////////////////////////////////////// +/*///////////////////////////////////////////////////////////////////////////// // Initialization // -/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////*/ TestFramework::TestFramework() { map_pins(PinMap_ADC, AnalogInput); @@ -35,45 +35,46 @@ TestFramework::TestFramework() { } void TestFramework::setup_cits_pins() { - pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_0); - pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_1); - pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_2); - pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_3); - pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_4); - pinout[CITS_AnalogInput].push_back(MBED_CONF_APP_AIN_5); - pinout[CITS_AnalogOutput].push_back(MBED_CONF_APP_AOUT); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_0); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_1); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_2); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_3); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_4); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_5); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_6); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_7); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_8); - pinout[CITS_DigitalIO].push_back(MBED_CONF_APP_DIO_9); - pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_0); - pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_1); - pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_2); - pinout[CITS_PWM].push_back(MBED_CONF_APP_PWM_3); - pinout[CITS_I2C_SDA].push_back(MBED_CONF_APP_I2C_SDA); - pinout[CITS_I2C_SCL].push_back(MBED_CONF_APP_I2C_SCL); - pinout[CITS_SPI_CLK].push_back(MBED_CONF_APP_SPI_CLK); - pinout[CITS_SPI_MISO].push_back(MBED_CONF_APP_SPI_MISO); - pinout[CITS_SPI_MOSI].push_back(MBED_CONF_APP_SPI_MOSI); - pinout[CITS_SPI_CS].push_back(MBED_CONF_APP_SPI_CS); + pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_0, 0, 0}); + pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_1, 0, 0}); + pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_2, 0, 0}); + pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_3, 0, 0}); + pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_4, 0, 0}); + pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_5, 0, 0}); + pinout[CITS_AnalogOutput].push_back({MBED_CONF_APP_AOUT, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_0, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_1, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_2, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_3, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_4, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_5, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_6, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_7, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_8, 0, 0}); + pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_9, 0, 0}); + pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_0, 0, 0}); + pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_1, 0, 0}); + pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_2, 0, 0}); + pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_3, 0, 0}); + pinout[CITS_I2C_SDA].push_back({MBED_CONF_APP_I2C_SDA, 0, 0}); + pinout[CITS_I2C_SCL].push_back({MBED_CONF_APP_I2C_SCL, 0, 0}); + pinout[CITS_SPI_CLK].push_back({MBED_CONF_APP_SPI_CLK, 0, 0}); + pinout[CITS_SPI_MISO].push_back({MBED_CONF_APP_SPI_MISO, 0, 0}); + pinout[CITS_SPI_MOSI].push_back({MBED_CONF_APP_SPI_MOSI, 0, 0}); + pinout[CITS_SPI_CS].push_back({MBED_CONF_APP_SPI_CS, 0, 0}); } void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { int i = 0; while(pinmap[i].pin != (PinName)NC) { + // printf("Pin %d\n", pinmap[i].pin); bool alreadyExists = false; for (unsigned int j=0; j + * or proceed to the next pin of the pin type if there are remaining pins + * @param Type pin type to reset + * @return control_t Case control statement to repeat or move on to the next case +**/ utest::v1::control_t TestFramework::reset_iterator(Type pintype) { if (pin_iterators[pintype] < pinout[pintype].size()) return utest::v1::CaseRepeatAll; @@ -107,98 +114,123 @@ utest::v1::control_t TestFramework::reset_iterator(Type pintype) { } } -/////////////////////////////////////////////////////////////////////////////// -// L0 // -/////////////////////////////////////////////////////////////////////////////// - -utest::v1::control_t TestFramework::test_l0_analogin(const size_t call_count) { - PinName pin = pinout[AnalogInput][pin_iterators[AnalogInput]++]; - DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - - AnalogIn ain(pin); - - TEST_ASSERT(true); - return reset_iterator(AnalogInput); -} - -utest::v1::control_t TestFramework::test_l0_analogout(const size_t call_count) { - PinName pin = pinout[AnalogOutput][pin_iterators[AnalogOutput]++]; - DEBUG_PRINTF("Running analog output constructor on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - - AnalogOut ain(pin); - - TEST_ASSERT(true); - return reset_iterator(AnalogOutput); -} - -utest::v1::control_t TestFramework::test_l0_digitalio(const size_t call_count) { - PinName pin = pinout[DigitalIO][pin_iterators[DigitalIO]++]; - DEBUG_PRINTF("Running digital io constructor on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - - DigitalOut dout(pin); - DigitalIn din(pin); - - TEST_ASSERT(true); - return reset_iterator(DigitalIO); +/** + * 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 + * @return PinName current pin +**/ +PinMap TestFramework::get_increment_pin(Type pintype) { + return pinout[pintype][pin_iterators[pintype]++]; } -utest::v1::control_t TestFramework::test_l0_pwm(const size_t call_count) { - PinName pin = pinout[PWM][pin_iterators[PWM]++]; - DEBUG_PRINTF("Running pwm constructor on pin %d\n", pin); - TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); - - PwmOut pwm(pin); - pwm.period(1.0f); - pwm.write(0.5f); +/** + * 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 + * @return control_t Case control to repeat or move on to next test cases +**/ +utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, PinName)) { + PinMap sda_pin = pinout[I2C_SDA][pin_iterators[I2C_SDA]]; + int tag = 0; - TEST_ASSERT(true); - return reset_iterator(PWM); + while (pin_iterators[I2C_SCL] < pinout[I2C_SCL].size()) { + if (pinout[I2C_SCL][pin_iterators[I2C_SCL]].peripheral == sda_pin.peripheral) { + if (tag) + return utest::v1::CaseRepeatAll; + else { + execution_callback(sda_pin.pin, pinout[I2C_SCL][pin_iterators[I2C_SCL]].pin); + tag = 1; + } + } + pin_iterators[I2C_SCL]++; + } + if (!tag) TEST_ASSERT(false); + pin_iterators[I2C_SDA]++; + pin_iterators[I2C_SCL] = 0; + return reset_iterator(I2C_SDA); } -utest::v1::control_t TestFramework::test_l0_i2c(const size_t call_count) { - PinName pin_sda = pinout[I2C_SDA][pin_iterators[I2C_SDA]++]; - PinName pin_scl = pinout[I2C_SCL][pin_iterators[I2C_SCL]++]; - 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"); - - I2C i2c(pin_sda, pin_scl); +/** + * (DEPRECATED) Iterate through every combination of SPI pins on the same HW block and execute a callback with that pinset + * Reasoning for deprecation: On K64F, there were 1300 combinations and it takes forever to run tests for each combination + * Note + * @param Callback to a function to run once a pin set has been found + * @param int representing which pin type the recursive function is currently looking at (SCLK, MISO, MOSI, CS) + * @param int tag identifying if looking for a pin to execute, or if the function is looking for the next case + * @return +**/ +// int TestFramework::spi_helper(void (*execution_callback)(PinName, PinName, PinName, PinName), int pin_iterator, int * tag) { + +// if (pin_iterator >= 4) { +// if (*tag == 1) +// return 1; +// execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin, pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, pinout[SPI_CS][pin_iterators[SPI_CS]].pin); +// *tag = 1; +// return 0; +// } + +// while (pin_iterators[pin_iterator] < pinout[pin_iterator].size()) { +// if (pinout[pin_iterator][pin_iterators[pin_iterator]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { +// int status = spi_helper(execution_callback, pin_iterator+1, tag); +// if (status == 1) +// return 1; +// } +// pin_iterators[pin_iterator]++; +// } + +// DEBUG_PRINTF("Pin iterator: %d\n", pin_iterator); +// if (pin_iterator == SPI_CLK) +// return 2; +// pin_iterators[pin_iterator] = 0; +// return 0; +// } - TEST_ASSERT(true); - reset_iterator(I2C_SDA); - return reset_iterator(I2C_SCL); +/** + * 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 + * @return control_t Case control to repeat or move on to the next test cases +**/ +utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)) { + if (pin_iterators[SPI_CLK] < pinout[SPI_CLK].size()) { + while (pin_iterators[SPI_MISO] < pinout[SPI_MISO].size()) { + if (pinout[SPI_MISO][pin_iterators[SPI_MISO]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + while (pin_iterators[SPI_MOSI] < pinout[SPI_MOSI].size()) { + if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + while (pin_iterators[SPI_CS] < pinout[SPI_CS].size()) { + if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]++].pin, + pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, + pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, + pinout[SPI_CS][pin_iterators[SPI_CS]].pin); + pin_iterators[SPI_MISO] = 0; + pin_iterators[SPI_MOSI] = 0; + pin_iterators[SPI_CS] = 0; + return utest::v1::CaseRepeatAll; + } + pin_iterators[SPI_CS]++; + } + TEST_ASSERT(false); + } + pin_iterators[SPI_MOSI]++; + } + TEST_ASSERT(false); + } + pin_iterators[SPI_MISO]++; + } + TEST_ASSERT(false); + } + pin_iterators[SPI_CLK] = 0; + execution_callback(MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_CS); + return utest::v1::CaseNext; } -utest::v1::control_t TestFramework::test_l0_spi(const size_t call_count) { - PinName pin_clk = pinout[SPI_CLK][pin_iterators[SPI_CLK]++]; - PinName pin_mosi = pinout[SPI_MOSI][pin_iterators[SPI_MOSI]++]; - PinName pin_miso = pinout[SPI_MISO][pin_iterators[SPI_MISO]++]; - PinName pin_cs = pinout[SPI_CS][pin_iterators[SPI_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); - 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(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK); - DigitalOut cs(MBED_CONF_APP_SPI_CS); - TEST_ASSERT(true); - reset_iterator(SPI_MOSI); - reset_iterator(SPI_MISO); - reset_iterator(SPI_CS); - return reset_iterator(SPI_CLK); -} - -/////////////////////////////////////////////////////////////////////////////// -// L1 // -/////////////////////////////////////////////////////////////////////////////// +/*///////////////////////////////////////////////////////////////////////////// +// level1 // +/////////////////////////////////////////////////////////////////////////////*/ -utest::v1::control_t TestFramework::test_l1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) { - PinName pin = pinout[pintype][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) { + PinName pin = pinout[pintype][pin_iterators[pintype]].pin; int index = find_pin(pin, testtype); int tag = 0; // State: Execute @@ -210,7 +242,7 @@ utest::v1::control_t TestFramework::test_l1_framework(Type pintype, Type testtyp while (pin_iterators[pintype] < pinout[pintype].size()) { // State: Increment iterator pin_iterators[pintype]++; - pin = pinout[pintype][pin_iterators[pintype]]; + pin = pinout[pintype][pin_iterators[pintype]].pin; index = find_pin(pin, testtype); if (index != -1) { @@ -224,38 +256,38 @@ utest::v1::control_t TestFramework::test_l1_framework(Type pintype, Type testtyp return reset_iterator(pintype); } -utest::v1::control_t TestFramework::test_l1_digitalio(const size_t call_count) { - return test_l1_framework(DigitalIO, CITS_DigitalIO, &test_digitalio_execute, 0.05, 10); +utest::v1::control_t TestFramework::test_level1_digitalio(const size_t call_count) { + return test_level1_framework(DigitalIO, CITS_DigitalIO, &test_digitalio_execute, 0.05, 10); } -utest::v1::control_t TestFramework::test_l1_analogin(const size_t call_count) { - return test_l1_framework(AnalogInput, CITS_AnalogInput, &test_analogin_execute, 0.05, 10); +utest::v1::control_t TestFramework::test_level1_analogin(const size_t call_count) { + return test_level1_framework(AnalogInput, CITS_AnalogInput, &test_analogin_execute, 0.05, 10); } -utest::v1::control_t TestFramework::test_l1_analogout(const size_t call_count) { - return test_l1_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.05, 10); +utest::v1::control_t TestFramework::test_level1_analogout(const size_t call_count) { + return test_level1_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.05, 10); } // EXISTS IN HEADER - DO NOT UNCOMMENT - HERE FOR REFERENCE // template -// utest::v1::control_t TestFramework::test_l1_pwm(const size_t call_count) { -// return test_l1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); +// utest::v1::control_t TestFramework::test_level1_pwm(const size_t call_count) { +// return test_level1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); // } -utest::v1::control_t TestFramework::test_l1_i2c(const size_t call_count) { - return test_l1_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.05, 10); +utest::v1::control_t TestFramework::test_level1_i2c(const size_t call_count) { + return test_level1_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.05, 10); } -utest::v1::control_t TestFramework::test_l1_spi(const size_t call_count) { - return test_l1_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.05, 10); +utest::v1::control_t TestFramework::test_level1_spi(const size_t call_count) { + return test_level1_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.05, 10); } -/////////////////////////////////////////////////////////////////////////////// -// L2 // -/////////////////////////////////////////////////////////////////////////////// +/*///////////////////////////////////////////////////////////////////////////// +// level2 // +/////////////////////////////////////////////////////////////////////////////*/ -utest::v1::control_t TestFramework::test_l2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) { - PinName pin = pinout[pintype][pin_iterators[pintype]]; +utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata) { + PinName pin = pinout[pintype][pin_iterators[pintype]].pin; int index = find_pin(pin, testtype); int tag = 0; // State: Execute @@ -266,7 +298,7 @@ utest::v1::control_t TestFramework::test_l2_framework(Type pintype, Type testtyp while (pin_iterators[pintype] < pinout[pintype].size()) { // State: Increment iterator pin_iterators[pintype]++; - pin = pinout[pintype][pin_iterators[pintype]]; + pin = pinout[pintype][pin_iterators[pintype]].pin; index = find_pin(pin, testtype); if (index != -1) { @@ -285,35 +317,56 @@ utest::v1::control_t TestFramework::test_l2_framework(Type pintype, Type testtyp return reset_iterator(pintype); } -utest::v1::control_t TestFramework::test_l2_digitalio(const size_t call_count) { - return test_l2_framework(DigitalIO, CITS_DigitalIO, &test_digitalio_execute, 0.01, 100); +utest::v1::control_t TestFramework::test_level2_digitalio(const size_t call_count) { + return test_level2_framework(DigitalIO, CITS_DigitalIO, &test_digitalio_execute, 0.01, 100); } -utest::v1::control_t TestFramework::test_l2_analogin(const size_t call_count) { - return test_l2_framework(AnalogInput, CITS_AnalogInput, &test_analogin_execute, 0.01, 100); +utest::v1::control_t TestFramework::test_level2_analogin(const size_t call_count) { + return test_level2_framework(AnalogInput, CITS_AnalogInput, &test_analogin_execute, 0.01, 100); } -utest::v1::control_t TestFramework::test_l2_analogout(const size_t call_count) { - return test_l2_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.01, 100); +utest::v1::control_t TestFramework::test_level2_analogout(const size_t call_count) { + return test_level2_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.01, 100); } // EXISTS IN HEADER - DO NOT UNCOMMENT - HERE FOR REFERENCE // template -// utest::v1::control_t TestFramework::test_l2_pwm(const size_t call_count) { -// return test_l2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); +// utest::v1::control_t TestFramework::test_level2_pwm(const size_t call_count) { +// return test_level2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); // } -utest::v1::control_t TestFramework::test_l2_i2c(const size_t call_count) { - return test_l2_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.01, 100); +utest::v1::control_t TestFramework::test_level2_i2c(const size_t call_count) { + return test_level2_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.01, 100); } -utest::v1::control_t TestFramework::test_l2_spi(const size_t call_count) { - return test_l2_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.01, 100); +utest::v1::control_t TestFramework::test_level2_spi(const size_t call_count) { + return test_level2_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.01, 100); } -/////////////////////////////////////////////////////////////////////////////// +/*///////////////////////////////////////////////////////////////////////////// // Tests // -/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////*/ + + + // AnalogIn ain(ain_pin); + // BusInOut outputs(dout_pin1,dout_pin2,dout_pin3,dout_pin4,dout_pin5); + // outputs.output(); + // int x = 0; + // int y= 0; + // outputs = 0; + // float prev_value = 0; + // for(x = 0; x<5; x++) { + // DEBUG_PRINTF("X=%d\n",x); + // prev_value = ain.read(); + // y = (y<<1) + 1; + // outputs = y; + // DEBUG_PRINTF("outputs=0x%x\nprevValue=%f\nain=%f\n\n",y,prev_value,ain.read()); + // TEST_ASSERT_MESSAGE(ain.read() > prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file") + // } + // DEBUG_PRINTF("Finished the Test\n"); + // TEST_ASSERT(true); + + void TestFramework::test_analogin_execute(PinName pin, float tolerance, int iterations) { DEBUG_PRINTF("Running analog input range test on pin %d\n", pin); @@ -339,12 +392,20 @@ void TestFramework::test_analogin_execute(PinName pin, float tolerance, int iter // float input = ain.read(); // dout2=0; // TEST_ASSERT_MESSAGE(input > (1-tolerance) && input < (1+tolerance), "Analog pin did not match digital output"); + } +} - // Case 3: Range test +void TestFramework::test_analogout_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"); + + for (unsigned int i=0; i - static utest::v1::control_t test_l1_pwm(const size_t call_count) { - return test_l1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); + static utest::v1::control_t test_level1_pwm(const size_t call_count) { + return test_level1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); } template - static utest::v1::control_t test_l2_pwm(const size_t call_count) { - return test_l2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); + static utest::v1::control_t test_level2_pwm(const size_t call_count) { + return test_level2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); } // I2C tests - static utest::v1::control_t test_l0_i2c(const size_t call_count); - static utest::v1::control_t test_l1_i2c(const size_t call_count); - static utest::v1::control_t test_l2_i2c(const size_t call_count); + static utest::v1::control_t test_level1_i2c(const size_t call_count); + static utest::v1::control_t test_level2_i2c(const size_t call_count); // SPI tests - static utest::v1::control_t test_l0_spi(const size_t call_count); - static utest::v1::control_t test_l1_spi(const size_t call_count); - static utest::v1::control_t test_l2_spi(const size_t call_count); + static utest::v1::control_t test_level1_spi(const size_t call_count); + static utest::v1::control_t test_level2_spi(const size_t call_count); // Static variables - static std::vector< std::vector > pinout; + static std::vector< std::vector > pinout; static std::vector pin_iterators; static Timer duty_timer; TestFramework(); + static utest::v1::control_t reset_iterator(Type pintype); + + PinMap get_increment_pin(Type pintype); + + + + static utest::v1::control_t run_i2c(void (*execution_callback)(PinName, PinName)); + + static utest::v1::control_t run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)); + + // static int spi_helper(void (*execution_callback)(PinName, PinName, PinName, PinName), int pin_iterator, int * tag); + + static utest::v1::control_t test_level1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); + + static utest::v1::control_t test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); + + private: /** @@ -122,11 +133,6 @@ class TestFramework { static int find_pin(PinName pin, Type pintype); static PinName find_pin_pair(PinName pin); - static utest::v1::control_t reset_iterator(Type pintype); - - static utest::v1::control_t test_l1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); - static utest::v1::control_t test_l2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); - // Helper functions static void test_analogin_execute(PinName pin, float tolerance, int iterations); static void test_digitalio_execute(PinName pin, float tolerance, int iterations); From a135774c513018463b935fa79fbb7cf7f9782124 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Tue, 14 Mar 2017 22:07:03 +0100 Subject: [PATCH 10/28] Added arduino tests --- TESTS/Arduino/AnalogIn/AnalogIn.cpp | 61 +++++++++++++++++++++++++++ TESTS/Arduino/AnalogOut/AnalogOut.cpp | 54 ++++++++++++++++++++++++ TESTS/Arduino/DigitalIO/DigitalIO.cpp | 61 +++++++++++++++++++++++++++ TESTS/Arduino/I2C/I2C.cpp | 54 ++++++++++++++++++++++++ TESTS/Arduino/Pwm/Pwm.cpp | 57 +++++++++++++++++++++++++ TESTS/Arduino/SPI/SPI.cpp | 57 +++++++++++++++++++++++++ TestFramework.cpp | 35 --------------- 7 files changed, 344 insertions(+), 35 deletions(-) create mode 100644 TESTS/Arduino/AnalogIn/AnalogIn.cpp create mode 100644 TESTS/Arduino/AnalogOut/AnalogOut.cpp create mode 100644 TESTS/Arduino/DigitalIO/DigitalIO.cpp create mode 100644 TESTS/Arduino/I2C/I2C.cpp create mode 100644 TESTS/Arduino/Pwm/Pwm.cpp create mode 100644 TESTS/Arduino/SPI/SPI.cpp diff --git a/TESTS/Arduino/AnalogIn/AnalogIn.cpp b/TESTS/Arduino/AnalogIn/AnalogIn.cpp new file mode 100644 index 0000000..e131c95 --- /dev/null +++ b/TESTS/Arduino/AnalogIn/AnalogIn.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_ANALOGIN + #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +// Template to set one Analog pin as input and then cycle through the rest as outputs. +// As you turn more pins on the voltage on the ain pin will go up. +template +void AnalogInput_Test() +{ + AnalogIn ain(ain_pin); + DEBUG_PRINTF("Tested pin %d for Arduino analog in capabilities\n", ain_pin); + TEST_ASSERT(true); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("Arduino - Analog Input Constructor on AIN_0", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_1", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_2", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_3", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_4", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_5", AnalogInput_Test, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Arduino/AnalogOut/AnalogOut.cpp b/TESTS/Arduino/AnalogOut/AnalogOut.cpp new file mode 100644 index 0000000..1733042 --- /dev/null +++ b/TESTS/Arduino/AnalogOut/AnalogOut.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_ANALOGOUT + #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +template +void AnalogOutput_Test() +{ + AnalogOut ain(aout_pin); + DEBUG_PRINTF("Tested pin %d for Arduino analog out capabilities\n", aout_pin); + TEST_ASSERT(true); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("Arduino - Analog Output Constructor on AOUT_0", AnalogOutput_Test, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Arduino/DigitalIO/DigitalIO.cpp b/TESTS/Arduino/DigitalIO/DigitalIO.cpp new file mode 100644 index 0000000..4a9da99 --- /dev/null +++ b/TESTS/Arduino/DigitalIO/DigitalIO.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +template +void DigitalIO_Test() +{ + DigitalOut dout(dio_pin); + DigitalIn din(dio_pin); + DEBUG_PRINTF("Tested pin %d for Arduino digital in/out capabilities\n", dio_pin); + TEST_ASSERT(true); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("Arduino - Digital IO Constructor on DIO_0", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_1", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_2", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_3", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_4", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_5", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_6", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_7", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_8", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_9", DigitalIO_Test, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Arduino/I2C/I2C.cpp b/TESTS/Arduino/I2C/I2C.cpp new file mode 100644 index 0000000..fbbce13 --- /dev/null +++ b/TESTS/Arduino/I2C/I2C.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_I2C + #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +template +void I2C_Test() +{ + I2C i2c(sda, scl); + DEBUG_PRINTF("Tested sda pin %d and scl pin %d for Arduino I2C capabilities\n", sda, scl); + TEST_ASSERT(true); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("Arduino - I2C Constructor on I2C_SDA/I2C_SCL", I2C_Test, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Arduino/Pwm/Pwm.cpp b/TESTS/Arduino/Pwm/Pwm.cpp new file mode 100644 index 0000000..fea3692 --- /dev/null +++ b/TESTS/Arduino/Pwm/Pwm.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +template +void PWM_Test() +{ + PwmOut pwm(pwm_pin); + DEBUG_PRINTF("Tested pin %d for Arduino digital in/out capabilities\n", pwm_pin); + TEST_ASSERT(true); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("Arduino - PWM Constructor on PWM_0", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_1", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_2", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_3", PWM_Test, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Arduino/SPI/SPI.cpp b/TESTS/Arduino/SPI/SPI.cpp new file mode 100644 index 0000000..a900c3c --- /dev/null +++ b/TESTS/Arduino/SPI/SPI.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// check if SPI is supported on this device +#if !DEVICE_SPI + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +template +void SPI_Test() +{ + SPI(mosi_pin, miso_pin, clk_pin); + DigitalOut cs(cs_pin); + DEBUG_PRINTF("Tested pins %d, %d, %d, and %d for Arduino SPI capabilities\n", mosi_pin, miso_pin, clk_pin, cs_pin); + TEST_ASSERT(true); +} + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +Case cases[] = { + Case("Arduino - SPI Constructor", SPI_Test, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TestFramework.cpp b/TestFramework.cpp index 65eeb7c..b68ee46 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -149,41 +149,6 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, return reset_iterator(I2C_SDA); } -/** - * (DEPRECATED) Iterate through every combination of SPI pins on the same HW block and execute a callback with that pinset - * Reasoning for deprecation: On K64F, there were 1300 combinations and it takes forever to run tests for each combination - * Note - * @param Callback to a function to run once a pin set has been found - * @param int representing which pin type the recursive function is currently looking at (SCLK, MISO, MOSI, CS) - * @param int tag identifying if looking for a pin to execute, or if the function is looking for the next case - * @return -**/ -// int TestFramework::spi_helper(void (*execution_callback)(PinName, PinName, PinName, PinName), int pin_iterator, int * tag) { - -// if (pin_iterator >= 4) { -// if (*tag == 1) -// return 1; -// execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin, pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, pinout[SPI_CS][pin_iterators[SPI_CS]].pin); -// *tag = 1; -// return 0; -// } - -// while (pin_iterators[pin_iterator] < pinout[pin_iterator].size()) { -// if (pinout[pin_iterator][pin_iterators[pin_iterator]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { -// int status = spi_helper(execution_callback, pin_iterator+1, tag); -// if (status == 1) -// return 1; -// } -// pin_iterators[pin_iterator]++; -// } - -// DEBUG_PRINTF("Pin iterator: %d\n", pin_iterator); -// if (pin_iterator == SPI_CLK) -// return 2; -// pin_iterators[pin_iterator] = 0; -// return 0; -// } - /** * 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 From 401ea3f9fbd40d434c7f42c628fb344bd460f276 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Tue, 21 Mar 2017 19:39:05 +0100 Subject: [PATCH 11/28] Additional Level1 and Level2 tests added --- I2CEeprom.lib | 1 - LM75B.lib | 1 - SDFileSystem.lib | 1 - TESTS/Level1/AnalogIn/AnalogIn.cpp | 41 +++- TESTS/Level1/AnalogOut/AnalogOut.cpp | 81 ++++++++ TESTS/Level1/DigitalIO/DigitalIO.cpp | 46 ++++- TESTS/Level1/I2C/I2C.cpp | 52 ++++- TESTS/Level1/Pwm/Pwm.cpp | 82 +++++++- TESTS/Level2/AnalogIn/AnalogIn.cpp | 41 +++- TESTS/Level2/AnalogOut/AnalogOut.cpp | 81 ++++++++ TESTS/Level2/DigitalIO/DigitalIO.cpp | 46 ++++- TESTS/Level2/Pwm/Pwm.cpp | 114 +++++++++- TESTS/host_tests/rand_provider.py | 42 ++++ TestFramework.cpp | 299 ++++++--------------------- TestFramework.hpp | 70 ++----- mbed-os.lib | 2 +- 16 files changed, 679 insertions(+), 321 deletions(-) delete mode 100755 I2CEeprom.lib delete mode 100644 LM75B.lib delete mode 100644 SDFileSystem.lib create mode 100644 TESTS/Level1/AnalogOut/AnalogOut.cpp create mode 100644 TESTS/Level2/AnalogOut/AnalogOut.cpp create mode 100644 TESTS/host_tests/rand_provider.py diff --git a/I2CEeprom.lib b/I2CEeprom.lib deleted file mode 100755 index bc74cea..0000000 --- a/I2CEeprom.lib +++ /dev/null @@ -1 +0,0 @@ -https://developer.mbed.org/users/rhourahane/code/I2CEeprom/#b23f5561266c diff --git a/LM75B.lib b/LM75B.lib deleted file mode 100644 index 500691f..0000000 --- a/LM75B.lib +++ /dev/null @@ -1 +0,0 @@ -https://developer.mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac diff --git a/SDFileSystem.lib b/SDFileSystem.lib deleted file mode 100644 index c247b55..0000000 --- a/SDFileSystem.lib +++ /dev/null @@ -1 +0,0 @@ -https://developer.mbed.org/teams/mbed/code/SDFileSystem/#8db0d3b02cec diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index 5ecdf30..cfea6f7 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -33,7 +33,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -49,8 +49,45 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +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"); + + 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"); + BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + outputs.output(); + + 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") + for (unsigned int j = 0; j + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +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"); + AnalogIn ain(TestFramework::find_resistor_ladder_pins(pin)[0]); + + for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + } + } +} + +utest::v1::control_t test_level1_analogout(const size_t call_count) { + return TestFramework::test_level1_framework(TestFramework::AnalogOutput, TestFramework::CITS_AnalogOutput, &test_analogout_execute, 0.05, 10); +} + +Case cases[] = { + Case("Level 1 - Analog Output Range test (single pin)", test_level1_analogout, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index 47c55bf..8834128 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -30,8 +30,9 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); +Timer TestFramework::all_purpose_timer; // Initialize a test framework object TestFramework test_framework; @@ -46,8 +47,49 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +int clocked_dio_toggle; + +void dio_toggled(void) { + clocked_dio_toggle = TestFramework::all_purpose_timer.read_us(); +} + +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"); + + PinName pinpair = TestFramework::find_pin_pair(pin); + printf("Pinpair: %d\n", pinpair); + + DigitalOut dout(pinpair); + DigitalIn din(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"); + int us_timeout = 10; + + for (unsigned int i=0; i +#include +#include +#include using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); + GREENTEA_SETUP(30, "rand_provider"); return verbose_test_setup_handler(number_of_cases); } @@ -49,8 +52,51 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +void test_i2c_execute(PinName pin_scl, float null_float, int iterations) { + PinName pin_sda = TestFramework::pinout[TestFramework::I2C_SDA][TestFramework::pin_iterators[TestFramework::I2C_SCL]].pin; + 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"); + + greentea_send_kv("return_rand", "seed"); + char key[16] = {0}; + char value[32] = {0}; + unsigned int seed; + greentea_parse_kv(key, value, sizeof(key), sizeof(value)); + stringstream strValue; + strValue << value; + strValue >> seed; + srand(seed); + + I2C i2c(pin_sda, pin_scl); + I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + + std::vector test_string; + for (int i=0; i +utest::v1::control_t test_level1_i2c(const size_t call_count) { + return TestFramework::test_level1_framework(TestFramework::I2C_SCL, TestFramework::CITS_I2C_SCL, &test_i2c_execute, 0.0f, iterations); +} + Case cases[] = { - Case("Level 1 - I2C Range test (single pin set)", TestFramework::test_level1_i2c, greentea_failure_handler), + Case("Level 1 - I2C test - 1 byte (single pin set)", test_level1_i2c<1>, greentea_failure_handler), + Case("Level 1 - I2C test - 10 byte (single pin set)", test_level1_i2c<10>, greentea_failure_handler), + Case("Level 1 - I2C test - 100 byte (single pin set)", test_level1_i2c<100>, greentea_failure_handler), }; int main() { diff --git a/TESTS/Level1/Pwm/Pwm.cpp b/TESTS/Level1/Pwm/Pwm.cpp index ee83a64..69087fa 100644 --- a/TESTS/Level1/Pwm/Pwm.cpp +++ b/TESTS/Level1/Pwm/Pwm.cpp @@ -33,13 +33,18 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer TestFramework::duty_timer; +Timer TestFramework::all_purpose_timer; // Initialize a test framework object TestFramework test_framework; +int rise_count; +int fall_count; +int last_rise_time; +int duty_count; + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(30, "default_auto"); return verbose_test_setup_handler(number_of_cases); @@ -50,13 +55,74 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +void callback_pwm_rise(void) { + rise_count++; + last_rise_time = TestFramework::all_purpose_timer.read_ms(); +} + +void callback_pwm_fall(void) { + fall_count++; + if (last_rise_time != 0) + duty_count = duty_count + (TestFramework::all_purpose_timer.read_ms() - last_rise_time); +} + +void test_pwm_execute(PinName pin, float dutycycle, int period) { + DEBUG_PRINTF("Running pwm test on pin %d\n", pin); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + + float tolerance = 0.05; + int iterations = 20; + float calculated_percent = iterations * tolerance; + if (calculated_percent < 1) calculated_percent = 1.0f; + + // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts + fall_count = 0; + rise_count = 0; + last_rise_time = 0; + duty_count = 0; + PwmOut pwm(pin); + + TestFramework::all_purpose_timer.reset(); + InterruptIn iin(TestFramework::find_pin_pair(pin)); + iin.rise(callback_pwm_rise); + iin.fall(callback_pwm_fall); + + DEBUG_PRINTF("Period set to: %f, duty cycle set to: %f\n", (float)period/1000, dutycycle); + pwm.period((float)period/1000); + + //Start Testing + pwm.write(0); + DEBUG_PRINTF("Waiting for %dms\n", iterations * period); + TestFramework::all_purpose_timer.start(); + pwm.write(dutycycle); // 50% duty cycle + wait_ms(iterations * period); // wait for pwm to run and counts to add up + pwm.write(0); + iin.disable_irq(); // This is here because otherwise it fails on some platforms + TestFramework::all_purpose_timer.stop(); + int rc = rise_count; // grab the numbers to work with as the pwm may continue going + 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."); + // 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); +} + Case cases[] = { - Case("Level 1 - PWM Range test (single pin) - 10ms", TestFramework::test_level1_pwm<50, 10>, greentea_failure_handler), - Case("Level 1 - PWM Range test (single pin) - 30ms", TestFramework::test_level1_pwm<50, 30>, greentea_failure_handler), - // Case("Level 1 - PWM Range test (single pin) - 100ms", TestFramework::test_level1_pwm<50, 100>, greentea_failure_handler), - Case("Level 1 - PWM Range test (single pin) - 10%", TestFramework::test_level1_pwm<10, 10>, greentea_failure_handler), - Case("Level 1 - PWM Range test (single pin) - 50%", TestFramework::test_level1_pwm<50, 10>, greentea_failure_handler), - Case("Level 1 - PWM Range test (single pin) - 90%", TestFramework::test_level1_pwm<90, 10>, greentea_failure_handler), + Case("Level 1 - PWM Frequency test (single pin) - 10ms", test_level1_pwm<50, 10>, greentea_failure_handler), + Case("Level 1 - PWM Frequency test (single pin) - 30ms", test_level1_pwm<50, 30>, greentea_failure_handler), + // Case("Level 1 - PWM Frequency test (single pin) - 100ms", test_level1_pwm<50, 100>, greentea_failure_handler), + Case("Level 1 - PWM Duty cycle test (single pin) - 10%", test_level1_pwm<10, 10>, greentea_failure_handler), + Case("Level 1 - PWM Duty cycle test (single pin) - 50%", test_level1_pwm<50, 10>, greentea_failure_handler), + Case("Level 1 - PWM Duty cycle test (single pin) - 90%", test_level1_pwm<90, 10>, greentea_failure_handler), }; int main() { diff --git a/TESTS/Level2/AnalogIn/AnalogIn.cpp b/TESTS/Level2/AnalogIn/AnalogIn.cpp index a3eb250..e3af429 100644 --- a/TESTS/Level2/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level2/AnalogIn/AnalogIn.cpp @@ -33,7 +33,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object @@ -49,8 +49,45 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +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"); + + 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"); + BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + outputs.output(); + + 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") + for (unsigned int j = 0; j + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +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"); + AnalogIn ain(TestFramework::find_resistor_ladder_pins(pin)[0]); + + for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + } + } +} + +utest::v1::control_t test_level2_analogout(const size_t call_count) { + return TestFramework::test_level2_framework(TestFramework::AnalogOutput, TestFramework::CITS_AnalogOutput, &test_analogout_execute, 0.02, 100); +} + +Case cases[] = { + Case("Level 1 - Analog Output Range test (single pin)", test_level2_analogout, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Level2/DigitalIO/DigitalIO.cpp b/TESTS/Level2/DigitalIO/DigitalIO.cpp index c8870d2..ab9e304 100644 --- a/TESTS/Level2/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -30,8 +30,9 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); +Timer TestFramework::all_purpose_timer; // Initialize a test framework object TestFramework test_framework; @@ -46,8 +47,49 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +int clocked_dio_toggle; + +void dio_toggled(void) { + clocked_dio_toggle = TestFramework::all_purpose_timer.read_us(); +} + +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"); + + PinName pinpair = TestFramework::find_pin_pair(pin); + printf("Pinpair: %d\n", pinpair); + + DigitalOut dout(pinpair); + DigitalIn din(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"); + int us_timeout = 10; + + for (unsigned int i=0; i > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer TestFramework::duty_timer; +Timer TestFramework::all_purpose_timer; // Initialize a test framework object TestFramework test_framework; +int rise_count; +int fall_count; +int last_rise_time; +int duty_count; + utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(60, "default_auto"); + GREENTEA_SETUP(200, "default_auto"); return verbose_test_setup_handler(number_of_cases); } @@ -50,13 +55,104 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +void callback_pwm_rise(void) { + rise_count++; + last_rise_time = TestFramework::all_purpose_timer.read_ms(); +} + +void callback_pwm_fall(void) { + fall_count++; + if (last_rise_time != 0) + duty_count = duty_count + (TestFramework::all_purpose_timer.read_ms() - last_rise_time); +} + +void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycycle, int period) { + float calculated_percent = iterations * tolerance; + if (calculated_percent < 1) calculated_percent = 1.0f; + + // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts + fall_count = 0; + rise_count = 0; + last_rise_time = 0; + duty_count = 0; + PwmOut pwm(pin); + + TestFramework::all_purpose_timer.reset(); + InterruptIn iin(TestFramework::find_pin_pair(pin)); + iin.rise(callback_pwm_rise); + iin.fall(callback_pwm_fall); + + DEBUG_PRINTF("Duty cycle: %f, Period: %d\n", dutycycle, period); + + pwm.period((float)period/1000); + + //Start Testing + pwm.write(0); + TestFramework::all_purpose_timer.start(); + pwm.write(dutycycle); // 50% duty cycle + wait_ms(iterations * period); // wait for pwm to run and counts to add up + pwm.write(0); + iin.disable_irq(); // This is here because otherwise it fails on some platforms + TestFramework::all_purpose_timer.stop(); + int rc = rise_count; // grab the numbers to work with as the pwm may continue going + 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."); + // TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= calculated_percent,"Greater than a specific variance between expected and measured duty cycle"); + +} + +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); + } + +} + +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"); + + for (int period=10; period<=200; period+=40) { + test_pwm_execute(pin, tolerance, iterations, 0.5f, period); + } +} + +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"); + + for (float dutycycle=0.2f; dutycycle <= 0.8f; dutycycle+=0.2f) { + for (int period=10; period<=200; period+=40) { + test_pwm_execute(pin, tolerance, iterations, dutycycle, period); + } + } +} + +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) { + 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); +} + Case cases[] = { - Case("Level 2 - PWM Range test (all pins) - 10ms", TestFramework::test_level2_pwm<50, 10>, greentea_failure_handler), - Case("Level 2 - PWM Range test (all pins) - 30ms", TestFramework::test_level2_pwm<50, 30>, greentea_failure_handler), - // Case("Level 2 - PWM Range test (all pins) - 100ms", TestFramework::test_level2_pwm<50, 100>, greentea_failure_handler), - Case("Level 2 - PWM Range test (all pins) - 10%", TestFramework::test_level2_pwm<10, 10>, greentea_failure_handler), - Case("Level 2 - PWM Range test (all pins) - 50%", TestFramework::test_level2_pwm<50, 10>, greentea_failure_handler), - Case("Level 2 - PWM Range test (all pins) - 90%", TestFramework::test_level2_pwm<90, 10>, greentea_failure_handler), + Case("Level 2 - PWM Frequency test (all pins)", test_level2_pwm_frequency, greentea_failure_handler), + Case("Level 2 - PWM Dutycycle test (all pins)", test_level2_pwm_dutycycle, greentea_failure_handler), + Case("Level 2 - PWM all tests (all pins)", test_level2_pwm, greentea_failure_handler), }; int main() { diff --git a/TESTS/host_tests/rand_provider.py b/TESTS/host_tests/rand_provider.py new file mode 100644 index 0000000..cbf7968 --- /dev/null +++ b/TESTS/host_tests/rand_provider.py @@ -0,0 +1,42 @@ +from mbed_host_tests import BaseHostTest +import random +import sys + +class RandProvider(BaseHostTest): + """ Simple, basic host test's test runner waiting for serial port + output from MUT, no supervision over test running in MUT is executed. + """ + + __result = None + name = "rand_provider" + + def _callback_return_rand(self, key, value, timestamp): + # You've received {{return_rand;*}} + + # We will send DUT some data back... + # And now decide about test case result + if value == 'seed': + # Message payload/value was 'some_stuff' + # We can for example return true from test + seed = random.randint(0, sys.maxint) + self.send_kv("seed", "%d" % seed) + self.notify_complete(True) + else: + self.send_kv("print_this", "This not what I wanted :(") + self.notify_complete(False) + + def setup(self): + # Register callback for message 'return_rand' from DUT + self.register_callback("return_rand", self._callback_return_rand) + + # Initialize your host test here + # ... + + def result(self): + # Define your test result here + # Or use self.notify_complete(bool) to pass result anytime! + return self.__result + + def teardown(self): + # Release resources here after test is completed + pass \ No newline at end of file diff --git a/TestFramework.cpp b/TestFramework.cpp index b68ee46..2dc785b 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -64,6 +64,11 @@ void TestFramework::setup_cits_pins() { pinout[CITS_SPI_CS].push_back({MBED_CONF_APP_SPI_CS, 0, 0}); } +/** + * 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 + * @param Type which type the pins belong to (used to index into pinout) +**/ void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { int i = 0; while(pinmap[i].pin != (PinName)NC) { @@ -80,6 +85,12 @@ void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { } } +/** + * Find a pin within the array of type pintype + * @param PinName pin to search for + * @param Type pin type to in which the pin has to be a part of + * @return index where the pin is found. Returns -1 if can't be found +**/ int TestFramework::find_pin(PinName pin, Type pintype) { for (unsigned int i=0; i list of resistor ladder pins +**/ +std::vector TestFramework::find_resistor_ladder_pins(PinName pin) { + std::vector resistor_ladder_pins; + for (unsigned int i = 0; i -// utest::v1::control_t TestFramework::test_level1_pwm(const size_t call_count) { -// return test_level1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); +// utest::v1::control_t TestFramework::test_level1_spi(const size_t call_count) { +// return test_level1_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.05, 10); // } -utest::v1::control_t TestFramework::test_level1_i2c(const size_t call_count) { - return test_level1_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.05, 10); -} - -utest::v1::control_t TestFramework::test_level1_spi(const size_t call_count) { - return test_level1_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.05, 10); -} - /*///////////////////////////////////////////////////////////////////////////// // level2 // /////////////////////////////////////////////////////////////////////////////*/ @@ -282,218 +286,43 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes return reset_iterator(pintype); } -utest::v1::control_t TestFramework::test_level2_digitalio(const size_t call_count) { - return test_level2_framework(DigitalIO, CITS_DigitalIO, &test_digitalio_execute, 0.01, 100); -} - -utest::v1::control_t TestFramework::test_level2_analogin(const size_t call_count) { - return test_level2_framework(AnalogInput, CITS_AnalogInput, &test_analogin_execute, 0.01, 100); -} - -utest::v1::control_t TestFramework::test_level2_analogout(const size_t call_count) { - return test_level2_framework(AnalogOutput, CITS_AnalogOutput, &test_analogout_execute, 0.01, 100); -} - -// EXISTS IN HEADER - DO NOT UNCOMMENT - HERE FOR REFERENCE -// template -// utest::v1::control_t TestFramework::test_level2_pwm(const size_t call_count) { -// return test_level2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); +// utest::v1::control_t TestFramework::test_level2_i2c(const size_t call_count) { +// return test_level2_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.01, 100); // } -utest::v1::control_t TestFramework::test_level2_i2c(const size_t call_count) { - return test_level2_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.01, 100); -} - -utest::v1::control_t TestFramework::test_level2_spi(const size_t call_count) { - return test_level2_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.01, 100); -} +// utest::v1::control_t TestFramework::test_level2_spi(const size_t call_count) { +// return test_level2_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.01, 100); +// } /*///////////////////////////////////////////////////////////////////////////// // Tests // /////////////////////////////////////////////////////////////////////////////*/ - - // AnalogIn ain(ain_pin); - // BusInOut outputs(dout_pin1,dout_pin2,dout_pin3,dout_pin4,dout_pin5); - // outputs.output(); - // int x = 0; - // int y= 0; - // outputs = 0; - // float prev_value = 0; - // for(x = 0; x<5; x++) { - // DEBUG_PRINTF("X=%d\n",x); - // prev_value = ain.read(); - // y = (y<<1) + 1; - // outputs = y; - // DEBUG_PRINTF("outputs=0x%x\nprevValue=%f\nain=%f\n\n",y,prev_value,ain.read()); - // TEST_ASSERT_MESSAGE(ain.read() > prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file") - // } - // DEBUG_PRINTF("Finished the Test\n"); - // TEST_ASSERT(true); - - - -void TestFramework::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"); - - for (unsigned int i=0; i (1-tolerance) && input < (1+tolerance), "Analog pin did not match digital output"); - } -} - -void TestFramework::test_analogout_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"); - - for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); - } - } -} - -void TestFramework::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"); - - PinName pinpair = find_pin_pair(pin); - - for (unsigned int i=0; i 0,"Writing File to sd card failed"); // write data - fclose(File_write);// close file on SD - - FILE *File_read = fopen("/sd/test_card.txt", "r"); // open File_read - char test_string_read [TEST_STRING_MAX] = {0}; - fgets(test_string_read,TEST_STRING_MAX,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_write)); - TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string_write) == 0,"String read does not match string written"); // test that strings match - - // fclose(File);// close file on SD - - TEST_ASSERT(true); -} \ No newline at end of file +// void TestFramework::test_spi_execute(PinName pin_clk, float null_float, int null_int) { +// char test_string_write[TEST_STRING_MAX] = "TestFramework test"; + +// PinName pin_mosi = pinout[SPI_MOSI][pin_iterators[SPI_CLK]].pin; +// PinName pin_miso = pinout[SPI_MISO][pin_iterators[SPI_CLK]].pin; +// PinName pin_cs = pinout[SPI_CS][pin_iterators[SPI_CLK]].pin; +// 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"); + +// SDFileSystem sd(pin_mosi, pin_miso, pin_clk, pin_cs, "sd"); +// FILE *File_write = fopen("/sd/test_card.txt", "w"); // open File_write +// TEST_ASSERT_MESSAGE(File_write != NULL,"SD Card is not present. Please insert an SD Card."); +// TEST_ASSERT_MESSAGE(fprintf(File_write, test_string_write) > 0,"Writing File to sd card failed"); // write data +// fclose(File_write);// close file on SD + +// FILE *File_read = fopen("/sd/test_card.txt", "r"); // open File_read +// char test_string_read [TEST_STRING_MAX] = {0}; +// fgets(test_string_read,TEST_STRING_MAX,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_write)); +// TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string_write) == 0,"String read does not match string written"); // test that strings match + +// // fclose(File);// close file on SD + +// TEST_ASSERT(true); +// } \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp index 0f0da82..fda3bc5 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -25,8 +25,6 @@ #include "unity.h" #include "utest.h" #include "ci_test_config.h" -#include -#include "SDFileSystem.h" #include #include @@ -58,64 +56,41 @@ class TestFramework { CITS_SPI_MISO, CITS_SPI_CLK, CITS_SPI_CS, - RiseCount, - FallCount, - DutyCount, - LastRiseTime, TS_NC }; - // Analog In tests - static utest::v1::control_t test_level1_analogin(const size_t call_count); - static utest::v1::control_t test_level2_analogin(const size_t call_count); - - // Analog Out tests - static utest::v1::control_t test_level1_analogout(const size_t call_count); - static utest::v1::control_t test_level2_analogout(const size_t call_count); - - // Digitial IO tests - static utest::v1::control_t test_level1_digitalio(const size_t call_count); - static utest::v1::control_t test_level2_digitalio(const size_t call_count); - - // PWM tests - - template - static utest::v1::control_t test_level1_pwm(const size_t call_count) { - return test_level1_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); - } - - template - static utest::v1::control_t test_level2_pwm(const size_t call_count) { - return test_level2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); - } + // template + // static utest::v1::control_t test_level2_pwm(const size_t call_count) { + // return test_level2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); + // } // I2C tests - static utest::v1::control_t test_level1_i2c(const size_t call_count); - static utest::v1::control_t test_level2_i2c(const size_t call_count); + // static utest::v1::control_t test_level1_i2c(const size_t call_count); + // static utest::v1::control_t test_level2_i2c(const size_t call_count); // SPI tests - static utest::v1::control_t test_level1_spi(const size_t call_count); - static utest::v1::control_t test_level2_spi(const size_t call_count); + // static utest::v1::control_t test_level1_spi(const size_t call_count); + // static utest::v1::control_t test_level2_spi(const size_t call_count); // Static variables static std::vector< std::vector > pinout; static std::vector pin_iterators; - static Timer duty_timer; + static Timer all_purpose_timer; TestFramework(); static utest::v1::control_t reset_iterator(Type pintype); PinMap get_increment_pin(Type pintype); + + static PinName find_pin_pair(PinName pin); - + static std::vector find_resistor_ladder_pins(PinName pin); static utest::v1::control_t run_i2c(void (*execution_callback)(PinName, PinName)); static utest::v1::control_t run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)); - // static int spi_helper(void (*execution_callback)(PinName, PinName, PinName, PinName), int pin_iterator, int * tag); - static utest::v1::control_t test_level1_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); static utest::v1::control_t test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); @@ -123,28 +98,15 @@ class TestFramework { private: - /** - * Gather all pins in a pinmap defined by the HAL and store them in the corresponding allPins vector - * @param PinMap[] from the HAL - * @param Type specifying which pin type to save the pins as - **/ void map_pins(const PinMap pinmap[], Type pintype); + void setup_cits_pins(); + static int find_pin(PinName pin, Type pintype); - static PinName find_pin_pair(PinName pin); // Helper functions - static void test_analogin_execute(PinName pin, float tolerance, int iterations); - static void test_digitalio_execute(PinName pin, float tolerance, int iterations); - static void test_analogout_execute(PinName pin, float tolerance, int iterations); - static void test_pwm_execute(PinName pin, float dutycycle, int period); - static void test_i2c_execute(PinName pin, float tolerance, int iterations); - static void test_spi_execute(PinName pin, float tolerance, int iterations); - - static volatile int fall_count; - static volatile int rise_count; - static void callback_pwm_fall(void); - static void callback_pwm_rise(void); + // static void test_i2c_execute(PinName pin, float tolerance, int iterations); + // static void test_spi_execute(PinName pin, float tolerance, int iterations); }; diff --git a/mbed-os.lib b/mbed-os.lib index 3a4b307..e394820 100644 --- a/mbed-os.lib +++ b/mbed-os.lib @@ -1 +1 @@ -https://github.com/mray19027/mbed-os/#defc1842331ac39ed0658ca99f14c8a4224d03b2 +https://github.com/ARMmbed/mbed-os/#cc58a7fb0c979440ab13a7fb25c4acd12009ae1c From 64e3bdcf23d992ba9b3ce820e22d675e86d16333 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Wed, 22 Mar 2017 20:40:49 +0100 Subject: [PATCH 12/28] Halfway through porting over to final version --- I2CEeprom.lib | 1 + TESTS/Level0/AnalogIn/AnalogIn.cpp | 26 ++-- TESTS/Level0/AnalogOut/AnalogOut.cpp | 25 +--- TESTS/Level0/DigitalIO/DigitalIO.cpp | 25 +--- TESTS/Level0/I2C/I2C.cpp | 28 ++-- TESTS/Level0/Pwm/Pwm.cpp | 26 ++-- TESTS/Level0/SPI/SPI.cpp | 27 +--- TESTS/Level1/AnalogIn/AnalogIn.cpp | 39 ++--- TESTS/Level1/AnalogOut/AnalogOut.cpp | 49 +++--- TESTS/Level1/DigitalIO/DigitalIO.cpp | 10 +- TESTS/Level1/I2C/I2C.cpp | 64 ++++---- TESTS/Level1/Pwm/Pwm.cpp | 12 +- TESTS/Level1/SPI/SPI.cpp | 74 +++++++++- TESTS/Level2/DigitalIO/DigitalIO.cpp | 10 +- TESTS/Level2/I2C/I2C.cpp | 105 +++++++++++++ TESTS/Level2/Pwm/Pwm.cpp | 12 +- TESTS/Level2/SPI/SPI.cpp | 129 ++++++++++++++++ TestFramework.cpp | 213 +++++++++++++++++---------- TestFramework.hpp | 46 +++--- 19 files changed, 621 insertions(+), 300 deletions(-) create mode 100644 I2CEeprom.lib create mode 100644 TESTS/Level2/I2C/I2C.cpp create mode 100644 TESTS/Level2/SPI/SPI.cpp diff --git a/I2CEeprom.lib b/I2CEeprom.lib new file mode 100644 index 0000000..4ac083b --- /dev/null +++ b/I2CEeprom.lib @@ -0,0 +1 @@ +https://developer.mbed.org/users/mbed_official/code/I2CEeprom/#973c4289c44c diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index a192341..69e10ac 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_ANALOGIN #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,21 +36,11 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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); @@ -61,11 +53,11 @@ utest::v1::control_t test_level0_analogin(const size_t call_count) { } Case cases[] = { - Case("Level 0 - Analog Input Constructor", test_level0_analogin, greentea_failure_handler), + Case("Level 0 - Analog Input Constructor", test_level0_analogin, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level0/AnalogOut/AnalogOut.cpp b/TESTS/Level0/AnalogOut/AnalogOut.cpp index 18b5d53..addf386 100644 --- a/TESTS/Level0/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level0/AnalogOut/AnalogOut.cpp @@ -12,15 +12,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ #if !DEVICE_ANALOGOUT #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,21 +35,11 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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); @@ -61,11 +52,11 @@ utest::v1::control_t test_level0_analogout(const size_t call_count) { } Case cases[] = { - Case("Level 0 - Analog Output Constructor", test_level0_analogout, greentea_failure_handler), + Case("Level 0 - Analog Output Constructor", test_level0_analogout, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level0/DigitalIO/DigitalIO.cpp b/TESTS/Level0/DigitalIO/DigitalIO.cpp index f0f87de..4a0f76a 100644 --- a/TESTS/Level0/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level0/DigitalIO/DigitalIO.cpp @@ -12,12 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -31,21 +32,11 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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); @@ -59,11 +50,11 @@ utest::v1::control_t test_level0_digitalio(const size_t call_count) { } Case cases[] = { - Case("Level 0 - DigitalIO Constructor", test_level0_digitalio, greentea_failure_handler), + Case("Level 0 - DigitalIO Constructor", test_level0_digitalio, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level0/I2C/I2C.cpp b/TESTS/Level0/I2C/I2C.cpp index f719b5b..71e5dd1 100644 --- a/TESTS/Level0/I2C/I2C.cpp +++ b/TESTS/Level0/I2C/I2C.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_I2C #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,21 +36,11 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - void construct_i2c(PinName sda, PinName scl) { DEBUG_PRINTF("Running I2C Constructor on SDA pin %d and SCL pin %d\n", sda, scl); TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC"); @@ -60,15 +52,15 @@ void construct_i2c(PinName sda, PinName scl) { } utest::v1::control_t test_level0_i2c(const size_t call_count) { - return test_framework.run_i2c(&construct_i2c); + return TestFramework::run_i2c(&construct_i2c); } Case cases[] = { - Case("Level 0 - I2C Constructor", test_level0_i2c, greentea_failure_handler), + Case("Level 0 - I2C Constructor", test_level0_i2c, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level0/Pwm/Pwm.cpp b/TESTS/Level0/Pwm/Pwm.cpp index 90026a3..3bd994c 100644 --- a/TESTS/Level0/Pwm/Pwm.cpp +++ b/TESTS/Level0/Pwm/Pwm.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_PWMOUT #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,21 +36,11 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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); @@ -63,11 +55,11 @@ utest::v1::control_t test_level0_pwm(const size_t call_count) { } Case cases[] = { - Case("Level 0 - PWM Constructor", test_level0_pwm, greentea_failure_handler), + Case("Level 0 - PWM Constructor", test_level0_pwm, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index bebaab4..a3f9cb0 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -12,17 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ -// check if SPI is supported on this device #if !DEVICE_SPI #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -36,21 +36,11 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - void construct_i2c(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); TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC"); @@ -68,13 +58,12 @@ utest::v1::control_t test_level0_spi(const size_t call_count) { return test_framework.run_spi(&construct_i2c); } - Case cases[] = { - Case("Level 0 - SPI Constructor", test_level0_spi, greentea_failure_handler), + Case("Level 0 - SPI Constructor", test_level0_spi, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index cfea6f7..96a7a5b 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_ANALOGIN #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,46 +36,49 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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 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"); + + // 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(); 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, cases); return !Harness::run(specification); } diff --git a/TESTS/Level1/AnalogOut/AnalogOut.cpp b/TESTS/Level1/AnalogOut/AnalogOut.cpp index 537c674..b67a499 100644 --- a/TESTS/Level1/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/AnalogOut/AnalogOut.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_ANALOGOUT #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,34 +36,39 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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"); - AnalogIn ain(TestFramework::find_resistor_ladder_pins(pin)[0]); + // 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"); + + // Float the remaining pins so that they don't drive the input wire to a specific voltage + BusInOut inputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); + inputs.input(); + + AnalogIn ain(MBED_CONF_APP_AIN_0); + + // Repeat to guarentee consistency for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); + DEBUG_PRINTF("Input voltage: %f, Output voltage: %f\n", input, i); + // Verify input matches expected output within a certain tolerance + // TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input does not match analog output"); } } } @@ -71,11 +78,11 @@ utest::v1::control_t test_level1_analogout(const size_t call_count) { } Case cases[] = { - Case("Level 1 - Analog Output Range test (single pin)", test_level1_analogout, greentea_failure_handler), + Case("Level 1 - Analog Output Range test (single pin)", test_level1_analogout, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + 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 8834128..4f6661e 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -32,7 +32,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer TestFramework::all_purpose_timer; +Timer timer; // Initialize a test framework object TestFramework test_framework; @@ -50,7 +50,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai int clocked_dio_toggle; void dio_toggled(void) { - clocked_dio_toggle = TestFramework::all_purpose_timer.read_us(); + clocked_dio_toggle = timer.read_us(); } void test_digitalio_execute(PinName pin, float tolerance, int iterations) { @@ -71,14 +71,14 @@ void test_digitalio_execute(PinName pin, float tolerance, int iterations) { for (unsigned int i=0; i #include #include -#include -#include using namespace utest::v1; @@ -52,45 +51,44 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } -void test_i2c_execute(PinName pin_scl, float null_float, int iterations) { - PinName pin_sda = TestFramework::pinout[TestFramework::I2C_SDA][TestFramework::pin_iterators[TestFramework::I2C_SCL]].pin; +template +utest::v1::control_t test_level1_i2c(const size_t call_count) { + + PinName pin_scl = MBED_CONF_APP_I2C_SCL; + PinName pin_sda = MBED_CONF_APP_I2C_SDA; + printf("SCL pin: %d\n", pin_scl); + printf("SDA pin: %d\n", pin_sda); + if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || + TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { + TEST_ASSERT(false); + return utest::v1::CaseNext; + } + 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"); - greentea_send_kv("return_rand", "seed"); - char key[16] = {0}; - char value[32] = {0}; - unsigned int seed; - greentea_parse_kv(key, value, sizeof(key), sizeof(value)); - stringstream strValue; - strValue << value; - strValue >> seed; - srand(seed); - - I2C i2c(pin_sda, pin_scl); + srand(TestFramework::get_seed()); + I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); - std::vector test_string; - for (int i=0; i -utest::v1::control_t test_level1_i2c(const size_t call_count) { - return TestFramework::test_level1_framework(TestFramework::I2C_SCL, TestFramework::CITS_I2C_SCL, &test_i2c_execute, 0.0f, iterations); + return utest::v1::CaseNext; } Case cases[] = { @@ -99,8 +97,8 @@ Case cases[] = { Case("Level 1 - I2C test - 100 byte (single pin set)", test_level1_i2c<100>, greentea_failure_handler), }; +Specification specification(test_setup, cases); + int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Level1/Pwm/Pwm.cpp b/TESTS/Level1/Pwm/Pwm.cpp index 69087fa..6075e76 100644 --- a/TESTS/Level1/Pwm/Pwm.cpp +++ b/TESTS/Level1/Pwm/Pwm.cpp @@ -35,7 +35,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer TestFramework::all_purpose_timer; +Timer timer; // Initialize a test framework object TestFramework test_framework; @@ -57,13 +57,13 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai void callback_pwm_rise(void) { rise_count++; - last_rise_time = TestFramework::all_purpose_timer.read_ms(); + last_rise_time = timer.read_ms(); } void callback_pwm_fall(void) { fall_count++; if (last_rise_time != 0) - duty_count = duty_count + (TestFramework::all_purpose_timer.read_ms() - last_rise_time); + duty_count = duty_count + (timer.read_ms() - last_rise_time); } void test_pwm_execute(PinName pin, float dutycycle, int period) { @@ -82,7 +82,7 @@ void test_pwm_execute(PinName pin, float dutycycle, int period) { duty_count = 0; PwmOut pwm(pin); - TestFramework::all_purpose_timer.reset(); + timer.reset(); InterruptIn iin(TestFramework::find_pin_pair(pin)); iin.rise(callback_pwm_rise); iin.fall(callback_pwm_fall); @@ -93,12 +93,12 @@ void test_pwm_execute(PinName pin, float dutycycle, int period) { //Start Testing pwm.write(0); DEBUG_PRINTF("Waiting for %dms\n", iterations * period); - TestFramework::all_purpose_timer.start(); + timer.start(); pwm.write(dutycycle); // 50% duty cycle wait_ms(iterations * period); // wait for pwm to run and counts to add up pwm.write(0); iin.disable_irq(); // This is here because otherwise it fails on some platforms - TestFramework::all_purpose_timer.stop(); + timer.stop(); int rc = rise_count; // grab the numbers to work with as the pwm may continue going int fc = fall_count; float avgTime = (float)duty_count / iterations; diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index c9bb817..e7bc291 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -13,8 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -// check if SPI is supported on this device #if !DEVICE_SPI #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif @@ -31,18 +29,20 @@ #include "TestFramework.hpp" #include +#include "FATFileSystem.h" +#include "SDBlockDevice.h" using namespace utest::v1; // Static variables for managing the dynamic list of pins -std::vector< vector > TestFramework::pinout(TS_NC); +std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); + GREENTEA_SETUP(30, "rand_provider"); return verbose_test_setup_handler(number_of_cases); } @@ -51,8 +51,72 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai return STATUS_ABORT; } +void test_spi_execute(PinName pin_clk, float null_float, int iterations) { + + PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; + PinName pin_miso = MBED_CONF_APP_SPI_MISO; + PinName pin_cs = MBED_CONF_APP_SPI_CS; + 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) { + TEST_ASSERT(false); + return; + } + + 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"); + + srand(TestFramework::get_seed()); + + 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."); + + + + for (int i=0; i<2; i++) { + + 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 + + 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"); + } + + error = fs.unmount(); + TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); + + sd.deinit(); + TEST_ASSERT(true); +} + +template +utest::v1::control_t test_level1_spi(const size_t call_count) { + return TestFramework::test_level1_framework(TestFramework::SPI_CLK, TestFramework::CITS_SPI_CLK, &test_spi_execute, 0.05, iterations); +} + Case cases[] = { - Case("Level 1 - SPI Range test (single pin)", TestFramework::test_level1_spi, greentea_failure_handler), + Case("Level 1 - SPI test - 1 byte (single pin set)", test_level1_spi<1>, greentea_failure_handler), + Case("Level 1 - SPI test - 10 byte (single pin set)", test_level1_spi<10>, greentea_failure_handler), + Case("Level 1 - SPI test - 100 byte (single pin set)", test_level1_spi<100>, greentea_failure_handler), }; int main() { diff --git a/TESTS/Level2/DigitalIO/DigitalIO.cpp b/TESTS/Level2/DigitalIO/DigitalIO.cpp index ab9e304..cf779b0 100644 --- a/TESTS/Level2/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -32,7 +32,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer TestFramework::all_purpose_timer; +Timer timer; // Initialize a test framework object TestFramework test_framework; @@ -50,7 +50,7 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai int clocked_dio_toggle; void dio_toggled(void) { - clocked_dio_toggle = TestFramework::all_purpose_timer.read_us(); + clocked_dio_toggle = timer.read_us(); } void test_digitalio_execute(PinName pin, float tolerance, int iterations) { @@ -71,14 +71,14 @@ void test_digitalio_execute(PinName pin, float tolerance, int iterations) { for (unsigned int i=0; i +#include +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "rand_provider"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +template +utest::v1::control_t test_level2_i2c(const size_t call_count) { + + PinName pin_scl = MBED_CONF_APP_I2C_SCL; + PinName pin_sda = MBED_CONF_APP_I2C_SDA; + printf("SCL pin: %d\n", pin_scl); + printf("SDA pin: %d\n", pin_sda); + if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || + TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { + TEST_ASSERT(false); + return utest::v1::CaseNext; + } + + 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"); + + srand(TestFramework::get_seed()); + + I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + + for (int i=0; i<2; i++) { + + char test_string[128] = {0}; + for (int i=0; i, greentea_failure_handler), + Case("Level 2 - I2C test - 10 byte (all pin set)", test_level2_i2c<10>, greentea_failure_handler), + Case("Level 2 - I2C test - 100 byte (all pin set)", test_level2_i2c<100>, greentea_failure_handler), +}; + +Specification specification(test_setup, cases); + +int main() { + return !Harness::run(specification); +} diff --git a/TESTS/Level2/Pwm/Pwm.cpp b/TESTS/Level2/Pwm/Pwm.cpp index fe6aff7..b60cdba 100644 --- a/TESTS/Level2/Pwm/Pwm.cpp +++ b/TESTS/Level2/Pwm/Pwm.cpp @@ -35,7 +35,7 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); std::vector TestFramework::pin_iterators(TS_NC); -Timer TestFramework::all_purpose_timer; +Timer timer; // Initialize a test framework object TestFramework test_framework; @@ -57,13 +57,13 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai void callback_pwm_rise(void) { rise_count++; - last_rise_time = TestFramework::all_purpose_timer.read_ms(); + last_rise_time = timer.read_ms(); } void callback_pwm_fall(void) { fall_count++; if (last_rise_time != 0) - duty_count = duty_count + (TestFramework::all_purpose_timer.read_ms() - last_rise_time); + duty_count = duty_count + (timer.read_ms() - last_rise_time); } void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycycle, int period) { @@ -77,7 +77,7 @@ void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycy duty_count = 0; PwmOut pwm(pin); - TestFramework::all_purpose_timer.reset(); + timer.reset(); InterruptIn iin(TestFramework::find_pin_pair(pin)); iin.rise(callback_pwm_rise); iin.fall(callback_pwm_fall); @@ -88,12 +88,12 @@ void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycy //Start Testing pwm.write(0); - TestFramework::all_purpose_timer.start(); + timer.start(); pwm.write(dutycycle); // 50% duty cycle wait_ms(iterations * period); // wait for pwm to run and counts to add up pwm.write(0); iin.disable_irq(); // This is here because otherwise it fails on some platforms - TestFramework::all_purpose_timer.stop(); + timer.stop(); int rc = rise_count; // grab the numbers to work with as the pwm may continue going int fc = fall_count; float avgTime = (float)duty_count / iterations; diff --git a/TESTS/Level2/SPI/SPI.cpp b/TESTS/Level2/SPI/SPI.cpp new file mode 100644 index 0000000..845a035 --- /dev/null +++ b/TESTS/Level2/SPI/SPI.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !DEVICE_SPI + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. +#endif + +#include "cmsis.h" +#include "pinmap.h" +#include "PeripheralPins.h" + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include +#include "FATFileSystem.h" +#include "SDBlockDevice.h" + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +utest::v1::status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(30, "rand_provider"); + return verbose_test_setup_handler(number_of_cases); +} + +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; +} + +void test_spi_execute(PinName pin_clk, float null_float, int iterations) { + + PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; + PinName pin_miso = MBED_CONF_APP_SPI_MISO; + PinName pin_cs = MBED_CONF_APP_SPI_CS; + 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) { + TEST_ASSERT(false); + return; + } + + 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"); + + srand(TestFramework::get_seed()); + + 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."); + + for (int i=0; i<2; i++) { + + 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 + + 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); + } + + error = fs.unmount(); + TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); + + sd.deinit(); + TEST_ASSERT(true); +} + +template +utest::v1::control_t test_level1_spi(const size_t call_count) { + return TestFramework::test_level1_framework(TestFramework::SPI_CLK, TestFramework::CITS_SPI_CLK, &test_spi_execute, 0.05, iterations); +} + +Case cases[] = { + Case("Level 1 - SPI test - 1 byte (single pin set)", test_level1_spi<1>, greentea_failure_handler), + Case("Level 1 - SPI test - 10 byte (single pin set)", test_level1_spi<10>, greentea_failure_handler), + Case("Level 1 - SPI test - 100 byte (single pin set)", test_level1_spi<100>, greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); +} diff --git a/TestFramework.cpp b/TestFramework.cpp index 2dc785b..ccbb33c 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -12,6 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ #include "TestFramework.hpp" @@ -19,6 +24,9 @@ // Initialization // /////////////////////////////////////////////////////////////////////////////*/ +/** + * Constructor for the test framework. Add all of the PinMaps to the pinout, as well as CI test shield pins +**/ TestFramework::TestFramework() { map_pins(PinMap_ADC, AnalogInput); map_pins(PinMap_DAC, AnalogOutput); @@ -34,34 +42,42 @@ TestFramework::TestFramework() { setup_cits_pins(); } +/** + * Add all of the CI Test Shield pins to the pinout vector +**/ void TestFramework::setup_cits_pins() { - pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_0, 0, 0}); - pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_1, 0, 0}); - pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_2, 0, 0}); - pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_3, 0, 0}); - pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_4, 0, 0}); - pinout[CITS_AnalogInput].push_back({MBED_CONF_APP_AIN_5, 0, 0}); - pinout[CITS_AnalogOutput].push_back({MBED_CONF_APP_AOUT, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_0, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_1, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_2, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_3, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_4, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_5, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_6, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_7, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_8, 0, 0}); - pinout[CITS_DigitalIO].push_back({MBED_CONF_APP_DIO_9, 0, 0}); - pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_0, 0, 0}); - pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_1, 0, 0}); - pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_2, 0, 0}); - pinout[CITS_PWM].push_back({MBED_CONF_APP_PWM_3, 0, 0}); - pinout[CITS_I2C_SDA].push_back({MBED_CONF_APP_I2C_SDA, 0, 0}); - pinout[CITS_I2C_SCL].push_back({MBED_CONF_APP_I2C_SCL, 0, 0}); - pinout[CITS_SPI_CLK].push_back({MBED_CONF_APP_SPI_CLK, 0, 0}); - pinout[CITS_SPI_MISO].push_back({MBED_CONF_APP_SPI_MISO, 0, 0}); - pinout[CITS_SPI_MOSI].push_back({MBED_CONF_APP_SPI_MOSI, 0, 0}); - pinout[CITS_SPI_CS].push_back({MBED_CONF_APP_SPI_CS, 0, 0}); + 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)); + pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_3)); + pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_4)); + pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_5)); + pinout[CITS_AnalogOutput].push_back(construct_pinmap(MBED_CONF_APP_AOUT)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_0)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_1)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_2)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_3)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_4)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_5)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_6)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_7)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_8)); + pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_9)); + pinout[CITS_PWM].push_back(construct_pinmap(MBED_CONF_APP_PWM_0)); + pinout[CITS_PWM].push_back(construct_pinmap(MBED_CONF_APP_PWM_1)); + pinout[CITS_PWM].push_back(construct_pinmap(MBED_CONF_APP_PWM_2)); + pinout[CITS_PWM].push_back(construct_pinmap(MBED_CONF_APP_PWM_3)); + pinout[CITS_I2C_SDA].push_back(construct_pinmap(MBED_CONF_APP_I2C_SDA)); + pinout[CITS_I2C_SCL].push_back(construct_pinmap(MBED_CONF_APP_I2C_SCL)); + pinout[CITS_SPI_CLK].push_back(construct_pinmap(MBED_CONF_APP_SPI_CLK)); + pinout[CITS_SPI_MISO].push_back(construct_pinmap(MBED_CONF_APP_SPI_MISO)); + pinout[CITS_SPI_MOSI].push_back(construct_pinmap(MBED_CONF_APP_SPI_MOSI)); + pinout[CITS_SPI_CS].push_back(construct_pinmap(MBED_CONF_APP_SPI_CS)); +} + +PinMap TestFramework::construct_pinmap(PinName pin) { + PinMap pinmap = {pin, 0, 0}; + return pinmap; } /** @@ -99,6 +115,11 @@ int TestFramework::find_pin(PinName pin, Type pintype) { return -1; } +/** + * 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 + * @return PinName pin that is connected to the input pin +**/ PinName TestFramework::find_pin_pair(PinName pin) { PinName pinpair = pin; for (unsigned int i=0; i TestFramework::find_resistor_ladder_pins(PinName pin) { return resistor_ladder_pins; } +/** + * Get a randomized seed from Greentea's host test + * @return unsigned int random seed +**/ +unsigned int TestFramework::get_seed() { + // Send key value pair to greentea host tests + greentea_send_kv("return_rand", "seed"); + char key[16] = {0}; + char value[32] = {0}; + unsigned int seed; + // Gather the response from the host test + greentea_parse_kv(key, value, sizeof(key), sizeof(value)); + // Convert the string result to an unsigned int + stringstream strValue; + strValue << value; + strValue >> seed; + return seed; +} + /*///////////////////////////////////////////////////////////////////////////// // 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. // /////////////////////////////////////////////////////////////////////////////*/ /** @@ -161,10 +206,14 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, PinMap sda_pin = pinout[I2C_SDA][pin_iterators[I2C_SDA]]; int tag = 0; + // 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 else { execution_callback(sda_pin.pin, pinout[I2C_SCL][pin_iterators[I2C_SCL]].pin); tag = 1; @@ -172,9 +221,11 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, } pin_iterators[I2C_SCL]++; } - if (!tag) TEST_ASSERT(false); + // All the SCL pins have been found for the identified SDA pin. Increment the SDA pin + if (!tag) { TEST_ASSERT(false);} pin_iterators[I2C_SDA]++; pin_iterators[I2C_SCL] = 0; + // Check to see if the SDA pin. Move on to the next test case if invalid and reset the counters return reset_iterator(I2C_SDA); } @@ -184,17 +235,27 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, * @return control_t Case control to repeat or move on to the next test cases **/ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)) { + // Check to make sure a CLK pin is still available if (pin_iterators[SPI_CLK] < pinout[SPI_CLK].size()) { + + // Iterate through the MISO pins to find a matching HW block pin to the CLK pin while (pin_iterators[SPI_MISO] < pinout[SPI_MISO].size()) { if (pinout[SPI_MISO][pin_iterators[SPI_MISO]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + + // Iterate through the MOSI pins to find a matching HW block pin to the CLK pin while (pin_iterators[SPI_MOSI] < pinout[SPI_MOSI].size()) { if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + + // Iterate through the CS pins to find a matching HW block pin to the CLK pin while (pin_iterators[SPI_CS] < pinout[SPI_CS].size()) { if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + + // Found all matching HW block pins. Run the execution callback with the identified pins execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]++].pin, pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, pinout[SPI_CS][pin_iterators[SPI_CS]].pin); + // Reset the iterators pin_iterators[SPI_MISO] = 0; pin_iterators[SPI_MOSI] = 0; pin_iterators[SPI_CS] = 0; @@ -212,6 +273,7 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, } TEST_ASSERT(false); } + // All CLK pins have been iterated through. Reset the CLK pin iterator, run the CI test shield pin pair, and then move on to the next test case pin_iterators[SPI_CLK] = 0; execution_callback(MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_CS); return utest::v1::CaseNext; @@ -219,14 +281,32 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, /*///////////////////////////////////////////////////////////////////////////// // 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 to find pins 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. // /////////////////////////////////////////////////////////////////////////////*/ +/** + * 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 + * @param Type corresponding type of pin on the CI test shield + * @param Callback to the test case to run once a pin is found + * @param float data in float form to pass to the execution callback. Depends on callback + * @param int data in int form to pass to the execution callback. Depends on callback + * @return control_t identify to repeat or proceed to the next test case corresponding to the Specification +**/ utest::v1::control_t TestFramework::test_level1_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 int index = find_pin(pin, testtype); - int tag = 0; // State: Execute if (index != -1) { + // Current pin was mapped to the CI test shield so run the callback and reset the iterator execution_callback(pin, floatdata, intdata); pin_iterators[pintype] = 0; return utest::v1::CaseNext; @@ -235,47 +315,70 @@ utest::v1::control_t TestFramework::test_level1_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 index = find_pin(pin, testtype); + if (index != -1) { // State: Execute + // Pin was found, so execute the callback and end the test case. Make sure to reset the iterator execution_callback(pin, floatdata, intdata); pin_iterators[pintype] = 0; return utest::v1::CaseNext; } } // State: End test + // All pins have been identified and run, reset the iterators and return back return reset_iterator(pintype); } -// utest::v1::control_t TestFramework::test_level1_spi(const size_t call_count) { -// return test_level1_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.05, 10); -// } - /*///////////////////////////////////////////////////////////////////////////// // 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. // /////////////////////////////////////////////////////////////////////////////*/ +/** + * 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 + * @param Type type of pin to find to run the callback + * @param Type corresponding type of pin on the CI test shield + * @param Callback to the test case to run once a pin is found + * @param float data in float form to pass to the execution callback. Depends on callback + * @param int data in int form to pass to the execution callback. Depends on callback + * @return control_t identify to repeat or proceed to the next test case corresponding to the Specification +**/ 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 int index = find_pin(pin, testtype); + // Tag is used to identify if a test case had been executed (1) or not (0) int tag = 0; // State: Execute if (index != -1) { + // Pin was found, run the callback and specify the tag to 1 (run) execution_callback(pin, floatdata, intdata); tag = 1; } + // Search the remaining pins of the pintype to find a pin on the CI test shield while (pin_iterators[pintype] < pinout[pintype].size()) { // 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 index = find_pin(pin, testtype); if (index != -1) { // State: End case + // Pin was found, but execution had already occurred so queue up another test case if (tag) { TEST_ASSERT(true); return utest::v1::CaseRepeatAll; // State: Execute + // Pin was found and execution has not occurred yet } else { execution_callback(pin, floatdata, intdata); tag = 1; @@ -283,46 +386,6 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes } } // State: End test + // All pins have been identified and run, reset the iterators and return back return reset_iterator(pintype); -} - -// utest::v1::control_t TestFramework::test_level2_i2c(const size_t call_count) { -// return test_level2_framework(I2C_SCL, CITS_I2C_SCL, &test_i2c_execute, 0.01, 100); -// } - -// utest::v1::control_t TestFramework::test_level2_spi(const size_t call_count) { -// return test_level2_framework(SPI_CLK, CITS_SPI_CLK, &test_spi_execute, 0.01, 100); -// } - -/*///////////////////////////////////////////////////////////////////////////// -// Tests // -/////////////////////////////////////////////////////////////////////////////*/ - -// void TestFramework::test_spi_execute(PinName pin_clk, float null_float, int null_int) { -// char test_string_write[TEST_STRING_MAX] = "TestFramework test"; - -// PinName pin_mosi = pinout[SPI_MOSI][pin_iterators[SPI_CLK]].pin; -// PinName pin_miso = pinout[SPI_MISO][pin_iterators[SPI_CLK]].pin; -// PinName pin_cs = pinout[SPI_CS][pin_iterators[SPI_CLK]].pin; -// 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"); - -// SDFileSystem sd(pin_mosi, pin_miso, pin_clk, pin_cs, "sd"); -// FILE *File_write = fopen("/sd/test_card.txt", "w"); // open File_write -// TEST_ASSERT_MESSAGE(File_write != NULL,"SD Card is not present. Please insert an SD Card."); -// TEST_ASSERT_MESSAGE(fprintf(File_write, test_string_write) > 0,"Writing File to sd card failed"); // write data -// fclose(File_write);// close file on SD - -// FILE *File_read = fopen("/sd/test_card.txt", "r"); // open File_read -// char test_string_read [TEST_STRING_MAX] = {0}; -// fgets(test_string_read,TEST_STRING_MAX,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_write)); -// TEST_ASSERT_MESSAGE(strcmp(test_string_read,test_string_write) == 0,"String read does not match string written"); // test that strings match - -// // fclose(File);// close file on SD - -// TEST_ASSERT(true); -// } \ No newline at end of file +} \ No newline at end of file diff --git a/TestFramework.hpp b/TestFramework.hpp index fda3bc5..c6594c0 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -12,6 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ #ifndef TESTFRAMEWORK_H #define TESTFRAMEWORK_H @@ -29,6 +34,8 @@ #include #include #include +#include +#include #define TEST_STRING_MAX 100 @@ -59,32 +66,19 @@ class TestFramework { TS_NC }; - // template - // static utest::v1::control_t test_level2_pwm(const size_t call_count) { - // return test_level2_framework(PWM, CITS_PWM, &test_pwm_execute, dutycycle*0.01f, period); - // } - - // I2C tests - // static utest::v1::control_t test_level1_i2c(const size_t call_count); - // static utest::v1::control_t test_level2_i2c(const size_t call_count); - - // SPI tests - // static utest::v1::control_t test_level1_spi(const size_t call_count); - // static utest::v1::control_t test_level2_spi(const size_t call_count); - - // Static variables static std::vector< std::vector > pinout; - static std::vector pin_iterators; - static Timer all_purpose_timer; + static std::vector pin_iterators; TestFramework(); static utest::v1::control_t reset_iterator(Type pintype); - PinMap get_increment_pin(Type pintype); + static PinMap get_increment_pin(Type pintype); static PinName find_pin_pair(PinName pin); + static int find_pin(PinName pin, Type pintype); + static std::vector find_resistor_ladder_pins(PinName pin); static utest::v1::control_t run_i2c(void (*execution_callback)(PinName, PinName)); @@ -95,6 +89,18 @@ class TestFramework { static utest::v1::control_t test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); + static unsigned int get_seed(); + + template + 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) { + greentea_case_failure_abort_handler(source, reason); + return utest::v1::STATUS_ABORT; + } private: @@ -102,11 +108,7 @@ class TestFramework { void setup_cits_pins(); - static int find_pin(PinName pin, Type pintype); - - // Helper functions - // static void test_i2c_execute(PinName pin, float tolerance, int iterations); - // static void test_spi_execute(PinName pin, float tolerance, int iterations); + PinMap construct_pinmap(PinName pin); }; From 786ad089c2ac636c1b410e6dafa848228922c4e8 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Thu, 23 Mar 2017 00:03:12 +0100 Subject: [PATCH 13/28] Final commit for up to level 2 --- TESTS/Level1/AnalogOut/AnalogOut.cpp | 9 +--- TESTS/Level1/DigitalIO/DigitalIO.cpp | 49 ++++++---------------- TESTS/Level1/I2C/I2C.cpp | 37 ++++++++--------- TESTS/Level1/Pwm/Pwm.cpp | 62 ++++++++++++++-------------- TESTS/Level1/SPI/SPI.cpp | 40 +++++++++--------- TESTS/Level2/AnalogIn/AnalogIn.cpp | 34 +++++++-------- TESTS/Level2/AnalogOut/AnalogOut.cpp | 39 +++++++++-------- TESTS/Level2/DigitalIO/DigitalIO.cpp | 39 ++++++++--------- TESTS/Level2/I2C/I2C.cpp | 38 ++++++++--------- TESTS/Level2/Pwm/Pwm.cpp | 62 ++++++++++++++-------------- TESTS/Level2/SPI/SPI.cpp | 39 ++++++++--------- 11 files changed, 206 insertions(+), 242 deletions(-) diff --git a/TESTS/Level1/AnalogOut/AnalogOut.cpp b/TESTS/Level1/AnalogOut/AnalogOut.cpp index b67a499..01a7784 100644 --- a/TESTS/Level1/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/AnalogOut/AnalogOut.cpp @@ -50,11 +50,7 @@ void test_analogout_execute(PinName pin, float tolerance, int iterations) { if (resistor_ladder_pins.size() < 5) TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); - // Float the remaining pins so that they don't drive the input wire to a specific voltage - BusInOut inputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]); - inputs.input(); - - AnalogIn ain(MBED_CONF_APP_AIN_0); + AnalogIn ain(resistor_ladder_pins[0]); // Repeat to guarentee consistency for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input does not match analog output"); + TEST_ASSERT_MESSAGE(input>=(i-tolerance) && input<=(i+tolerance), "Analog input does not match analog output"); } } } diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index 4f6661e..a9af947 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -12,12 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -31,24 +32,14 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + Timer timer; +int clocked_dio_toggle; // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - -int clocked_dio_toggle; - void dio_toggled(void) { clocked_dio_toggle = timer.read_us(); } @@ -58,30 +49,14 @@ 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); - printf("Pinpair: %d\n", pinpair); - 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"); - int us_timeout = 10; - - for (unsigned int i=0; i, cases); return !Harness::run(specification); } diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index ef19de9..3ea6e4e 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_I2C #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -36,24 +38,15 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "rand_provider"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - template 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; printf("SCL pin: %d\n", pin_scl); @@ -68,16 +61,20 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) { 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()); I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + // Run twice for (int i=0; i<2; i++) { + // Generate a random string char test_string[128] = {0}; for (int i=0; i, greentea_failure_handler), - Case("Level 1 - I2C test - 10 byte (single pin set)", test_level1_i2c<10>, greentea_failure_handler), - Case("Level 1 - I2C test - 100 byte (single pin set)", test_level1_i2c<100>, greentea_failure_handler), + Case("Level 1 - I2C test - 1 byte (single pin set)", test_level1_i2c<1>, 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), }; -Specification specification(test_setup, 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/Pwm/Pwm.cpp b/TESTS/Level1/Pwm/Pwm.cpp index 6075e76..7f58cbb 100644 --- a/TESTS/Level1/Pwm/Pwm.cpp +++ b/TESTS/Level1/Pwm/Pwm.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_PWMOUT #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,32 +36,24 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); -Timer timer; +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; +Timer timer; int rise_count; int fall_count; int last_rise_time; int duty_count; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - +// Callback for a PWM rising edge 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) @@ -70,36 +64,40 @@ void test_pwm_execute(PinName pin, float dutycycle, int period) { DEBUG_PRINTF("Running pwm test on pin %d\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; - - // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts fall_count = 0; rise_count = 0; last_rise_time = 0; duty_count = 0; - PwmOut pwm(pin); + 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); - - //Start Testing 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); // 50% duty cycle - wait_ms(iterations * period); // wait for pwm to run and counts to add up + 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(); // This is here because otherwise it fails on some platforms + iin.disable_irq(); timer.stop(); - int rc = rise_count; // grab the numbers to work with as the pwm may continue going + + // Run post calculations for verification + int rc = rise_count; int fc = fall_count; float avgTime = (float)duty_count / iterations; float expectedTime = (float)period * dutycycle; @@ -117,16 +115,16 @@ utest::v1::control_t test_level1_pwm(const size_t call_count) { } Case cases[] = { - Case("Level 1 - PWM Frequency test (single pin) - 10ms", test_level1_pwm<50, 10>, greentea_failure_handler), - Case("Level 1 - PWM Frequency test (single pin) - 30ms", test_level1_pwm<50, 30>, greentea_failure_handler), - // Case("Level 1 - PWM Frequency test (single pin) - 100ms", test_level1_pwm<50, 100>, greentea_failure_handler), - Case("Level 1 - PWM Duty cycle test (single pin) - 10%", test_level1_pwm<10, 10>, greentea_failure_handler), - Case("Level 1 - PWM Duty cycle test (single pin) - 50%", test_level1_pwm<50, 10>, greentea_failure_handler), - Case("Level 1 - PWM Duty cycle test (single pin) - 90%", test_level1_pwm<90, 10>, greentea_failure_handler), + 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), + Case("Level 1 - PWM Frequency test (single pin) - 100ms", test_level1_pwm<50, 100>, TestFramework::greentea_failure_handler), + Case("Level 1 - PWM Duty cycle test (single pin) - 10%", test_level1_pwm<10, 10>, TestFramework::greentea_failure_handler), + Case("Level 1 - PWM Duty cycle test (single pin) - 50%", test_level1_pwm<50, 10>, TestFramework::greentea_failure_handler), + 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(test_setup, cases); + 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 e7bc291..1ebcb2b 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_SPI #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -36,23 +38,14 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "rand_provider"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - void test_spi_execute(PinName pin_clk, float null_float, int iterations) { + // Verify that the CI test shield pins are connected to the SPI pins PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; PinName pin_miso = MBED_CONF_APP_SPI_MISO; PinName pin_cs = MBED_CONF_APP_SPI_CS; @@ -70,8 +63,10 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { 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"); @@ -79,19 +74,21 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { 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 @@ -101,6 +98,7 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { 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."); @@ -114,13 +112,13 @@ utest::v1::control_t test_level1_spi(const size_t call_count) { } Case cases[] = { - Case("Level 1 - SPI test - 1 byte (single pin set)", test_level1_spi<1>, greentea_failure_handler), - Case("Level 1 - SPI test - 10 byte (single pin set)", test_level1_spi<10>, greentea_failure_handler), - Case("Level 1 - SPI test - 100 byte (single pin set)", test_level1_spi<100>, greentea_failure_handler), + 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() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level2/AnalogIn/AnalogIn.cpp b/TESTS/Level2/AnalogIn/AnalogIn.cpp index e3af429..1600a11 100644 --- a/TESTS/Level2/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level2/AnalogIn/AnalogIn.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_ANALOGIN #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,25 +36,16 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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) TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins"); @@ -62,18 +55,25 @@ void test_analogin_execute(PinName pin, float tolerance, int iterations) { 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 for (unsigned int j = 0; j, cases); return !Harness::run(specification); } diff --git a/TESTS/Level2/AnalogOut/AnalogOut.cpp b/TESTS/Level2/AnalogOut/AnalogOut.cpp index ecf0c5a..1181728 100644 --- a/TESTS/Level2/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level2/AnalogOut/AnalogOut.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_ANALOGOUT #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,33 +36,34 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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"); - AnalogIn ain(TestFramework::find_resistor_ladder_pins(pin)[0]); + // 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"); + + AnalogIn ain(resistor_ladder_pins[0]); + + // Repeat to guarentee consistency for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); } } @@ -71,11 +74,11 @@ utest::v1::control_t test_level2_analogout(const size_t call_count) { } Case cases[] = { - Case("Level 1 - Analog Output Range test (single pin)", test_level2_analogout, greentea_failure_handler), + Case("Level 2 - Analog Output Range test (all pins)", test_level2_analogout, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + 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 cf779b0..04307d6 100644 --- a/TESTS/Level2/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -12,12 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -31,24 +32,14 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + Timer timer; +int clocked_dio_toggle; // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - -int clocked_dio_toggle; - void dio_toggled(void) { clocked_dio_toggle = timer.read_us(); } @@ -58,10 +49,10 @@ 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); - printf("Pinpair: %d\n", pinpair); - 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; @@ -69,14 +60,20 @@ void test_digitalio_execute(PinName pin, float tolerance, int iterations) { int us_timeout = 10; for (unsigned int i=0; i, cases); return !Harness::run(specification); } diff --git a/TESTS/Level2/I2C/I2C.cpp b/TESTS/Level2/I2C/I2C.cpp index eb73916..6498f91 100644 --- a/TESTS/Level2/I2C/I2C.cpp +++ b/TESTS/Level2/I2C/I2C.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_I2C #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -36,24 +38,15 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "rand_provider"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - 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 PinName pin_scl = MBED_CONF_APP_I2C_SCL; PinName pin_sda = MBED_CONF_APP_I2C_SDA; printf("SCL pin: %d\n", pin_scl); @@ -68,19 +61,24 @@ utest::v1::control_t test_level2_i2c(const size_t call_count) { 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()); I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + // Run twice for (int i=0; i<2; i++) { + // Generate a random string char test_string[128] = {0}; for (int i=0; i, greentea_failure_handler), - Case("Level 2 - I2C test - 10 byte (all pin set)", test_level2_i2c<10>, greentea_failure_handler), - Case("Level 2 - I2C test - 100 byte (all pin set)", test_level2_i2c<100>, greentea_failure_handler), + Case("Level 2 - I2C test - 1 byte (all pin set)", test_level2_i2c<1>, 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), }; -Specification specification(test_setup, 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/Level2/Pwm/Pwm.cpp b/TESTS/Level2/Pwm/Pwm.cpp index b60cdba..bb9430c 100644 --- a/TESTS/Level2/Pwm/Pwm.cpp +++ b/TESTS/Level2/Pwm/Pwm.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_PWMOUT #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -34,32 +36,24 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); -Timer timer; +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; +Timer timer; int rise_count; int fall_count; int last_rise_time; int duty_count; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(200, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - +// Callback for a PWM rising edge 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) @@ -67,34 +61,39 @@ void callback_pwm_fall(void) { } 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; - - // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts fall_count = 0; rise_count = 0; last_rise_time = 0; duty_count = 0; - PwmOut pwm(pin); + 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("Duty cycle: %f, Period: %d\n", dutycycle, period); - pwm.period((float)period/1000); - - //Start Testing 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); // 50% duty cycle - wait_ms(iterations * period); // wait for pwm to run and counts to add up + 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(); // This is here because otherwise it fails on some platforms timer.stop(); - int rc = rise_count; // grab the numbers to work with as the pwm may continue going + + // Run post calculations for verification + int rc = rise_count; int fc = fall_count; float avgTime = (float)duty_count / iterations; float expectedTime = (float)period * dutycycle; @@ -107,6 +106,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); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -117,6 +117,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); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); @@ -126,12 +127,13 @@ 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); TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); for (float dutycycle=0.2f; dutycycle <= 0.8f; dutycycle+=0.2f) { - for (int period=10; period<=200; period+=40) { + for (int period=10; period<=210; period+=40) { test_pwm_execute(pin, tolerance, iterations, dutycycle, period); } } @@ -150,13 +152,13 @@ utest::v1::control_t test_level2_pwm(const size_t call_count) { } Case cases[] = { - Case("Level 2 - PWM Frequency test (all pins)", test_level2_pwm_frequency, greentea_failure_handler), - Case("Level 2 - PWM Dutycycle test (all pins)", test_level2_pwm_dutycycle, greentea_failure_handler), - Case("Level 2 - PWM all tests (all pins)", test_level2_pwm, greentea_failure_handler), + 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() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<200>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level2/SPI/SPI.cpp b/TESTS/Level2/SPI/SPI.cpp index 845a035..8e7bd15 100644 --- a/TESTS/Level2/SPI/SPI.cpp +++ b/TESTS/Level2/SPI/SPI.cpp @@ -12,15 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * */ + #if !DEVICE_SPI #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralPins.h" - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -36,23 +38,14 @@ using namespace utest::v1; // Static variables for managing the dynamic list of pins std::vector< vector > TestFramework::pinout(TS_NC); -std::vector TestFramework::pin_iterators(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "rand_provider"); - return verbose_test_setup_handler(number_of_cases); -} - -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - void test_spi_execute(PinName pin_clk, float null_float, int iterations) { + // Verify that the CI test shield pins are connected to the SPI pins PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; PinName pin_miso = MBED_CONF_APP_SPI_MISO; PinName pin_cs = MBED_CONF_APP_SPI_CS; @@ -70,8 +63,10 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { 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"); @@ -79,21 +74,26 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { 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 @@ -104,6 +104,7 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { remove(file_name); } + // Unmount and de-initialize the SD card error = fs.unmount(); TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); @@ -117,13 +118,13 @@ utest::v1::control_t test_level1_spi(const size_t call_count) { } Case cases[] = { - Case("Level 1 - SPI test - 1 byte (single pin set)", test_level1_spi<1>, greentea_failure_handler), - Case("Level 1 - SPI test - 10 byte (single pin set)", test_level1_spi<10>, greentea_failure_handler), - Case("Level 1 - SPI test - 100 byte (single pin set)", test_level1_spi<100>, greentea_failure_handler), + Case("Level 2 - SPI test - 1 byte (all pin sets)", test_level1_spi<1>, TestFramework::greentea_failure_handler), + Case("Level 2 - SPI test - 10 byte (all pin sets)", test_level1_spi<10>, TestFramework::greentea_failure_handler), + Case("Level 2 - SPI test - 100 byte (all pin sets)", test_level1_spi<100>, TestFramework::greentea_failure_handler), }; int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + Specification specification(TestFramework::test_setup<30>, cases); return !Harness::run(specification); } From 6f6a274a14cfb8089d8ff14ecfb1732debc6473f Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Mon, 27 Mar 2017 23:59:18 +0100 Subject: [PATCH 14/28] Finished Level 3 tests --- TESTS/API/BusInOut/BusInOut.cpp | 2 +- TESTS/Level0/BusInOut/BusInOut.cpp | 66 +++++++++ .../BusInOut/BusInOut.cpp} | 44 ++---- TESTS/Level1/I2C/I2C.cpp | 44 +++--- TESTS/Level1/SPI/SPI.cpp | 11 +- TESTS/Level2/BusInOut/BusInOut.cpp | 121 ++++++++++++++++ TESTS/Level2/I2C/I2C.cpp | 43 +++--- TESTS/Level2/SPI/SPI.cpp | 17 +-- TESTS/Level3/I2C/I2C.cpp | 105 ++++++++++++++ TESTS/Level3/Pwm/Pwm.cpp | 137 ++++++++++++++++++ TESTS/Level3/SPI/SPI.cpp | 130 +++++++++++++++++ TestFramework.cpp | 25 +++- TestFramework.hpp | 3 + 13 files changed, 655 insertions(+), 93 deletions(-) create mode 100644 TESTS/Level0/BusInOut/BusInOut.cpp rename TESTS/{Level2/AnalogOut/AnalogOut.cpp => Level1/BusInOut/BusInOut.cpp} (50%) create mode 100644 TESTS/Level2/BusInOut/BusInOut.cpp create mode 100644 TESTS/Level3/I2C/I2C.cpp create mode 100644 TESTS/Level3/Pwm/Pwm.cpp create mode 100644 TESTS/Level3/SPI/SPI.cpp diff --git a/TESTS/API/BusInOut/BusInOut.cpp b/TESTS/API/BusInOut/BusInOut.cpp index d9f19ed..a346d0d 100644 --- a/TESTS/API/BusInOut/BusInOut.cpp +++ b/TESTS/API/BusInOut/BusInOut.cpp @@ -87,7 +87,7 @@ void businout_bidirectional_test(){ BusOut bout(MBED_CONF_APP_DIO_3,MBED_CONF_APP_DIO_5,MBED_CONF_APP_DIO_7,MBED_CONF_APP_DIO_9); bout = 0; volatile int x = 0; - while(x < 0x0F){ + while(x < 0x0F) { x++; bout.write(x); DEBUG_PRINTF("\r\n*********\r\nvalue of bin,bout,x is: 0x%x, 0x%x, 0x%x\r\n********\r\n",bin.read(),bout.read(),x); diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp new file mode 100644 index 0000000..21932d8 --- /dev/null +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * + */ + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +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) { + DEBUG_PRINTF("Running bus input/output constructor\n"); + + std::vector pins; + for (int i=0; i<15; i++) { + if (TestFramework::check_size(TestFramework::BusIO)) { + pins.push_back(test_framework.get_increment_pin(TestFramework::BusIO).pin); + } else { + pins.push_back((PinName)NC); + } + } + + 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]); + + TEST_ASSERT(true); + return test_framework.reset_iterator(TestFramework::BusIO); +} + +Case cases[] = { + Case("Level 0 - Bus Input/Output Constructor", test_level0_businout, 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); +} diff --git a/TESTS/Level2/AnalogOut/AnalogOut.cpp b/TESTS/Level1/BusInOut/BusInOut.cpp similarity index 50% rename from TESTS/Level2/AnalogOut/AnalogOut.cpp rename to TESTS/Level1/BusInOut/BusInOut.cpp index 1181728..d90c1c2 100644 --- a/TESTS/Level2/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/BusInOut/BusInOut.cpp @@ -19,10 +19,6 @@ * */ -#if !DEVICE_ANALOGOUT - #error [NOT_SUPPORTED] AnalogOut not supported on this platform, add 'DEVICE_ANALOGOUT' definition to your platform. -#endif - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -41,40 +37,28 @@ 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 %d\n", pin); +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"); - // 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"); - - AnalogIn ain(resistor_ladder_pins[0]); - - // Repeat to guarentee consistency - for (unsigned int i=0; i=(i-tolerance) && input<=(i+tolerance), "Analog input matches analog output"); - } - } + 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_level2_analogout(const size_t call_count) { - return TestFramework::test_level2_framework(TestFramework::AnalogOutput, TestFramework::CITS_AnalogOutput, &test_analogout_execute, 0.02, 100); +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); } Case cases[] = { - Case("Level 2 - Analog Output Range test (all pins)", test_level2_analogout, TestFramework::greentea_failure_handler), + Case("Level 1 - Bus Input/Output pair test", test_level1_busio, TestFramework::greentea_failure_handler), }; int main() { diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index 3ea6e4e..9281417 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -42,6 +42,8 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; +char* DEADBEEF = "DEADBEEF"; +char NULL_STR[128] = {0}; template utest::v1::control_t test_level1_i2c(const size_t call_count) { @@ -49,8 +51,6 @@ 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; - printf("SCL pin: %d\n", pin_scl); - printf("SDA pin: %d\n", pin_sda); if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { TEST_ASSERT(false); @@ -61,28 +61,28 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) { 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()); - I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); - // Run twice - for (int i=0; i<2; i++) { - - // Generate a random string - char test_string[128] = {0}; - for (int i=0; i TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_spi_execute(PinName pin_clk, float null_float, int iterations) { +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 + PinName pin_clk = MBED_CONF_APP_SPI_CLK; PinName pin_mosi = MBED_CONF_APP_SPI_MOSI; PinName pin_miso = MBED_CONF_APP_SPI_MISO; PinName pin_cs = MBED_CONF_APP_SPI_CS; @@ -54,7 +56,7 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || TestFramework::find_pin(pin_cs, TestFramework::SPI_CS)==-1) { TEST_ASSERT(false); - return; + 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); @@ -104,11 +106,8 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { sd.deinit(); TEST_ASSERT(true); -} -template -utest::v1::control_t test_level1_spi(const size_t call_count) { - return TestFramework::test_level1_framework(TestFramework::SPI_CLK, TestFramework::CITS_SPI_CLK, &test_spi_execute, 0.05, iterations); + return utest::v1::CaseNext; } Case cases[] = { diff --git a/TESTS/Level2/BusInOut/BusInOut.cpp b/TESTS/Level2/BusInOut/BusInOut.cpp new file mode 100644 index 0000000..d63135d --- /dev/null +++ b/TESTS/Level2/BusInOut/BusInOut.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * + */ + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +// test that all pins can be marked as BusIn +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(){ + 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; + while(x < 0xFF){ + DEBUG_PRINTF("value of x is: 0x%x\r\n",x); + x++; + bout.write(x); + } + 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(){ + 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(); + bio2.input(); + bio1 = 0x00; + volatile int x = 0x00; + + while(x < 0xF){ + x = (x<<1) +1; + bio1.output(); + bio1 = x; + bio2.input(); + volatile int y = bio2.read(); + DEBUG_PRINTF("value of x,bio is: 0x%x, 0x%x\r\n",x,y); + TEST_ASSERT_MESSAGE(y == x,"Value read on bus does not equal value written. "); + } + + x = 0x00; + while(x < 0xF){ + x = (x<<1) +1; + bio2.output(); + bio2 = x; + bio1.input(); + volatile int y = bio1.read(); + DEBUG_PRINTF("value of x,bio is: 0x%x, 0x%x\r\n",x,y); + TEST_ASSERT_MESSAGE(y == x,"Value read on bus does not equal value written. "); + } + + TEST_ASSERT_MESSAGE(true,"The fact that it hasnt error out proves this passes the sniff test"); +} + +// Test writing from one bus to another +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; + volatile int x = 0; + while(x < 0x0F) { + x++; + bout.write(x); + DEBUG_PRINTF("value of bin,bout,x is: 0x%x, 0x%x, 0x%x\r\n",bin.read(),bout.read(),x); + TEST_ASSERT_MESSAGE(bin.read() == bout.read(),"Value read on bin does not equal value written on bout. ") + } + 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), + Case("Level 2 - Bus Input/Output range test", businout_define_test, TestFramework::greentea_failure_handler), + Case("Level 2 - Bus Input/Output range test 2", businout_bidirectional_test, TestFramework::greentea_failure_handler), +}; + +// Entry point into the tests +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 6498f91..3f05ab3 100644 --- a/TESTS/Level2/I2C/I2C.cpp +++ b/TESTS/Level2/I2C/I2C.cpp @@ -42,6 +42,7 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; +char NULL_STR[128] = {0}; template utest::v1::control_t test_level2_i2c(const size_t call_count) { @@ -49,8 +50,6 @@ 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; - printf("SCL pin: %d\n", pin_scl); - printf("SDA pin: %d\n", pin_sda); if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { TEST_ASSERT(false); @@ -66,25 +65,27 @@ utest::v1::control_t test_level2_i2c(const size_t call_count) { I2CEeprom memory(pin_sda,pin_scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); - // Run twice - for (int i=0; i<2; i++) { - - // Generate a random string - char test_string[128] = {0}; - for (int i=0; i TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void test_spi_execute(PinName pin_clk, float null_float, int iterations) { +template +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; PinName pin_miso = MBED_CONF_APP_SPI_MISO; PinName pin_cs = MBED_CONF_APP_SPI_CS; @@ -54,7 +56,7 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { TestFramework::find_pin(pin_clk, TestFramework::SPI_CLK)==-1 || TestFramework::find_pin(pin_cs, TestFramework::SPI_CS)==-1) { TEST_ASSERT(false); - return; + 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); @@ -110,17 +112,14 @@ void test_spi_execute(PinName pin_clk, float null_float, int iterations) { sd.deinit(); TEST_ASSERT(true); -} -template -utest::v1::control_t test_level1_spi(const size_t call_count) { - return TestFramework::test_level1_framework(TestFramework::SPI_CLK, TestFramework::CITS_SPI_CLK, &test_spi_execute, 0.05, iterations); + return utest::v1::CaseNext; } Case cases[] = { - Case("Level 2 - SPI test - 1 byte (all pin sets)", test_level1_spi<1>, TestFramework::greentea_failure_handler), - Case("Level 2 - SPI test - 10 byte (all pin sets)", test_level1_spi<10>, TestFramework::greentea_failure_handler), - Case("Level 2 - SPI test - 100 byte (all pin sets)", test_level1_spi<100>, TestFramework::greentea_failure_handler), + 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() { diff --git a/TESTS/Level3/I2C/I2C.cpp b/TESTS/Level3/I2C/I2C.cpp new file mode 100644 index 0000000..6d3ae12 --- /dev/null +++ b/TESTS/Level3/I2C/I2C.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * + */ + +#if !DEVICE_I2C + #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include +#include +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; +char NULL_STR[128] = {0}; + +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 + 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) { + TEST_ASSERT(false); + return utest::v1::CaseNext; + } + + 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"); + + // 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); + + // Generate a random string + char test_string[128] = {0}; + int rand_size = rand()%128+1; + for (int i=0; i, 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); +} diff --git a/TESTS/Level3/Pwm/Pwm.cpp b/TESTS/Level3/Pwm/Pwm.cpp new file mode 100644 index 0000000..37a231b --- /dev/null +++ b/TESTS/Level3/Pwm/Pwm.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * + */ + +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +Timer timer; +int rise_count; +int fall_count; +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(); +} + +// 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 test_pwm_execute(PinName pin, float tolerance, int waveform_count, float dutycycle, int period) { + + // Initialize + float calculated_percent = waveform_count * 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("Duty cycle: %f, Period: %d\n", dutycycle, period); + pwm.period((float)period/1000); + pwm.write(0); + DEBUG_PRINTF("Waiting for %dms\n", waveform_count * period); + + // Start the timer, write the duty cycle, and wait for completion + timer.start(); + pwm.write(dutycycle); + wait_ms(waveform_count * 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(); // This is here because otherwise it fails on some platforms + timer.stop(); + + // Run post calculations for verification + int rc = rise_count; + int fc = fall_count; + float avgTime = (float)duty_count / waveform_count; + 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, waveform_count); + 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(waveform_count - rc) <= calculated_percent, "There was more than a specific variance in number of rise cycles seen and number expected."); + TEST_ASSERT_MESSAGE( std::abs(waveform_count - fc) <= calculated_percent, "There was more than a specific variance in number of fall cycles seen and number expected."); + // TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= calculated_percent,"Greater than a specific variance between expected and measured duty cycle"); + +} + +// 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); + TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC"); + + // Get a random seed from the Greentea host test + srand(TestFramework::get_seed()); + + for (int i=0; i +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, iterations); +} + +Case cases[] = { + Case("Level 3 - PWM randomized", test_level2_pwm<10>, TestFramework::greentea_failure_handler), +}; + +int main() { + // Formulate a specification and run the tests based on the Case array + Specification specification(TestFramework::test_setup<200>, cases); + return !Harness::run(specification); +} diff --git a/TESTS/Level3/SPI/SPI.cpp b/TESTS/Level3/SPI/SPI.cpp new file mode 100644 index 0000000..904e583 --- /dev/null +++ b/TESTS/Level3/SPI/SPI.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Michael Ray + * @since 3/22/2017 + * @version 1.0.0 + * + */ + +#if !DEVICE_SPI + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +#include "TestFramework.hpp" +#include +#include "FATFileSystem.h" +#include "SDBlockDevice.h" + +using namespace utest::v1; + +// Static variables for managing the dynamic list of pins +std::vector< vector > TestFramework::pinout(TS_NC); +std::vector TestFramework::pin_iterators(TS_NC); + +// Initialize a test framework object +TestFramework test_framework; + +template +utest::v1::control_t test_level3_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; + PinName pin_miso = MBED_CONF_APP_SPI_MISO; + PinName pin_cs = MBED_CONF_APP_SPI_CS; + 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) { + TEST_ASSERT(false); + 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); + 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}; + int rand_size = rand()%128 + 1; + 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(); + TEST_ASSERT(true); + + if (call_count, 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); +} diff --git a/TestFramework.cpp b/TestFramework.cpp index ccbb33c..fafa6a1 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -32,6 +32,14 @@ TestFramework::TestFramework() { map_pins(PinMap_DAC, AnalogOutput); map_pins(PinMap_PWM, DigitalIO); map_pins(PinMap_ADC, DigitalIO); + // map_pins(PinMap_DAC, DigitalIO); + 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); + pinout[BusIO] = pinout[DigitalIO]; map_pins(PinMap_PWM, PWM); map_pins(PinMap_I2C_SDA, I2C_SDA); map_pins(PinMap_I2C_SCL, I2C_SCL); @@ -88,8 +96,8 @@ PinMap TestFramework::construct_pinmap(PinName pin) { void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { int i = 0; while(pinmap[i].pin != (PinName)NC) { - // printf("Pin %d\n", pinmap[i].pin); bool alreadyExists = false; + // printf("Pin %d\n", pinmap[i].pin); for (unsigned int j=0; j * or proceed to the next pin of the pin type if there are remaining pins @@ -138,7 +155,7 @@ PinName TestFramework::find_pin_pair(PinName pin) { * @return control_t Case control statement to repeat or move on to the next case **/ utest::v1::control_t TestFramework::reset_iterator(Type pintype) { - if (pin_iterators[pintype] < pinout[pintype].size()) + if (check_size(pintype)) return utest::v1::CaseRepeatAll; else { pin_iterators[pintype] = 0; @@ -311,7 +328,7 @@ utest::v1::control_t TestFramework::test_level1_framework(Type pintype, Type tes pin_iterators[pintype] = 0; return utest::v1::CaseNext; } - while (pin_iterators[pintype] < pinout[pintype].size()) { + while (check_size(pintype)) { // State: Increment iterator pin_iterators[pintype]++; pin = pinout[pintype][pin_iterators[pintype]].pin; @@ -364,7 +381,7 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes tag = 1; } // Search the remaining pins of the pintype to find a pin on the CI test shield - while (pin_iterators[pintype] < pinout[pintype].size()) { + while (check_size(pintype)) { // State: Increment iterator pin_iterators[pintype]++; pin = pinout[pintype][pin_iterators[pintype]].pin; diff --git a/TestFramework.hpp b/TestFramework.hpp index c6594c0..8720a7c 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -53,6 +53,7 @@ class TestFramework { SPI_MISO, SPI_MOSI, SPI_CS, + BusIO, CITS_AnalogInput, CITS_AnalogOutput, CITS_DigitalIO, @@ -71,6 +72,8 @@ class TestFramework { TestFramework(); + static bool check_size(Type pintype); + static utest::v1::control_t reset_iterator(Type pintype); static PinMap get_increment_pin(Type pintype); From 62b43d9ec053500927ae2e3a88f57cfb081ab453 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Wed, 5 Apr 2017 19:04:25 +0100 Subject: [PATCH 15/28] Made changes outlined in pull request #47 --- TESTS/Arduino/AnalogIn/AnalogIn.cpp | 16 ++-- TESTS/Arduino/AnalogOut/AnalogOut.cpp | 6 +- TESTS/Arduino/DigitalIO/DigitalIO.cpp | 24 ++--- TESTS/Arduino/I2C/I2C.cpp | 4 +- TESTS/Arduino/Pwm/Pwm.cpp | 4 +- TESTS/Arduino/SPI/SPI.cpp | 6 +- TESTS/Level0/AnalogIn/AnalogIn.cpp | 5 +- TESTS/Level0/AnalogOut/AnalogOut.cpp | 3 - TESTS/Level0/BusInOut/BusInOut.cpp | 3 - TESTS/Level0/DigitalIO/DigitalIO.cpp | 3 - TESTS/Level0/I2C/I2C.cpp | 3 - TESTS/Level0/Pwm/Pwm.cpp | 3 - TESTS/Level0/SPI/SPI.cpp | 3 - TESTS/Level1/AnalogIn/AnalogIn.cpp | 3 - TESTS/Level1/AnalogOut/AnalogOut.cpp | 3 - TESTS/Level1/BusInOut/BusInOut.cpp | 3 - TESTS/Level1/DigitalIO/DigitalIO.cpp | 3 - TESTS/Level1/I2C/I2C.cpp | 3 - TESTS/Level1/Pwm/Pwm.cpp | 4 +- TESTS/Level1/SPI/SPI.cpp | 3 - TESTS/Level2/AnalogIn/AnalogIn.cpp | 3 - TESTS/Level2/BusInOut/BusInOut.cpp | 3 - TESTS/Level2/DigitalIO/DigitalIO.cpp | 3 - TESTS/Level2/I2C/I2C.cpp | 3 - TESTS/Level2/Pwm/Pwm.cpp | 6 +- TESTS/Level2/SPI/SPI.cpp | 3 - TESTS/Level3/I2C/I2C.cpp | 3 - TESTS/Level3/Pwm/Pwm.cpp | 4 +- TESTS/Level3/SPI/SPI.cpp | 3 - TESTS/host_tests/rand_provider.py | 15 +++ TestFramework.cpp | 83 ----------------- TestFramework.hpp | 129 +++++++++++++++++++++----- mbed_app.json | 5 +- 33 files changed, 161 insertions(+), 207 deletions(-) diff --git a/TESTS/Arduino/AnalogIn/AnalogIn.cpp b/TESTS/Arduino/AnalogIn/AnalogIn.cpp index e131c95..187d7d7 100644 --- a/TESTS/Arduino/AnalogIn/AnalogIn.cpp +++ b/TESTS/Arduino/AnalogIn/AnalogIn.cpp @@ -46,16 +46,16 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("Arduino - Analog Input Constructor on AIN_0", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_1", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_2", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_3", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_4", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_5", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_0", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_1", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_2", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_3", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_4", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_5", AnalogInput_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Arduino/AnalogOut/AnalogOut.cpp b/TESTS/Arduino/AnalogOut/AnalogOut.cpp index 1733042..e06128b 100644 --- a/TESTS/Arduino/AnalogOut/AnalogOut.cpp +++ b/TESTS/Arduino/AnalogOut/AnalogOut.cpp @@ -44,11 +44,11 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("Arduino - Analog Output Constructor on AOUT_0", AnalogOutput_Test, greentea_failure_handler), + Case("Arduino - Analog Output Constructor on AOUT_0", AnalogOutput_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Arduino/DigitalIO/DigitalIO.cpp b/TESTS/Arduino/DigitalIO/DigitalIO.cpp index 4a9da99..171ccce 100644 --- a/TESTS/Arduino/DigitalIO/DigitalIO.cpp +++ b/TESTS/Arduino/DigitalIO/DigitalIO.cpp @@ -42,20 +42,20 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("Arduino - Digital IO Constructor on DIO_0", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_1", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_2", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_3", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_4", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_5", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_6", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_7", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_8", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_9", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_0", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_1", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_2", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_3", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_4", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_5", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_6", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_7", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_8", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_9", DigitalIO_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Arduino/I2C/I2C.cpp b/TESTS/Arduino/I2C/I2C.cpp index fbbce13..3532b34 100644 --- a/TESTS/Arduino/I2C/I2C.cpp +++ b/TESTS/Arduino/I2C/I2C.cpp @@ -48,7 +48,7 @@ Case cases[] = { }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Arduino/Pwm/Pwm.cpp b/TESTS/Arduino/Pwm/Pwm.cpp index fea3692..477fe17 100644 --- a/TESTS/Arduino/Pwm/Pwm.cpp +++ b/TESTS/Arduino/Pwm/Pwm.cpp @@ -51,7 +51,7 @@ Case cases[] = { }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Arduino/SPI/SPI.cpp b/TESTS/Arduino/SPI/SPI.cpp index a900c3c..dca320d 100644 --- a/TESTS/Arduino/SPI/SPI.cpp +++ b/TESTS/Arduino/SPI/SPI.cpp @@ -47,11 +47,11 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai } Case cases[] = { - Case("Arduino - SPI Constructor", SPI_Test, greentea_failure_handler), + Case("Arduino - SPI Constructor", SPI_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); return !Harness::run(specification); } diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index 69e10ac..a599169 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ @@ -43,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("%dRunning analog input constructor on pin %d\n", ANSI_COLOR_YELLOW, 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 addf386..a074128 100644 --- a/TESTS/Level0/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level0/AnalogOut/AnalogOut.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ #if !DEVICE_ANALOGOUT diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index 21932d8..776c8cd 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level0/DigitalIO/DigitalIO.cpp b/TESTS/Level0/DigitalIO/DigitalIO.cpp index 4a0f76a..7e04f62 100644 --- a/TESTS/Level0/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level0/DigitalIO/DigitalIO.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level0/I2C/I2C.cpp b/TESTS/Level0/I2C/I2C.cpp index 71e5dd1..242941c 100644 --- a/TESTS/Level0/I2C/I2C.cpp +++ b/TESTS/Level0/I2C/I2C.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level0/Pwm/Pwm.cpp b/TESTS/Level0/Pwm/Pwm.cpp index 3bd994c..f63759f 100644 --- a/TESTS/Level0/Pwm/Pwm.cpp +++ b/TESTS/Level0/Pwm/Pwm.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index a3f9cb0..594b12d 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index 96a7a5b..6e657f7 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level1/AnalogOut/AnalogOut.cpp b/TESTS/Level1/AnalogOut/AnalogOut.cpp index 01a7784..36a55dc 100644 --- a/TESTS/Level1/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level1/AnalogOut/AnalogOut.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level1/BusInOut/BusInOut.cpp b/TESTS/Level1/BusInOut/BusInOut.cpp index d90c1c2..c76f8e8 100644 --- a/TESTS/Level1/BusInOut/BusInOut.cpp +++ b/TESTS/Level1/BusInOut/BusInOut.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level1/DigitalIO/DigitalIO.cpp b/TESTS/Level1/DigitalIO/DigitalIO.cpp index a9af947..6147694 100644 --- a/TESTS/Level1/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level1/DigitalIO/DigitalIO.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level1/I2C/I2C.cpp b/TESTS/Level1/I2C/I2C.cpp index 9281417..0a7ac8b 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level1/Pwm/Pwm.cpp b/TESTS/Level1/Pwm/Pwm.cpp index 7f58cbb..c402623 100644 --- a/TESTS/Level1/Pwm/Pwm.cpp +++ b/TESTS/Level1/Pwm/Pwm.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ @@ -106,6 +103,7 @@ void test_pwm_execute(PinName pin, float dutycycle, int period) { 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"); } diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index 20129cc..5adcf73 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level2/AnalogIn/AnalogIn.cpp b/TESTS/Level2/AnalogIn/AnalogIn.cpp index 1600a11..5fcacd3 100644 --- a/TESTS/Level2/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level2/AnalogIn/AnalogIn.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level2/BusInOut/BusInOut.cpp b/TESTS/Level2/BusInOut/BusInOut.cpp index d63135d..809a653 100644 --- a/TESTS/Level2/BusInOut/BusInOut.cpp +++ b/TESTS/Level2/BusInOut/BusInOut.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level2/DigitalIO/DigitalIO.cpp b/TESTS/Level2/DigitalIO/DigitalIO.cpp index 04307d6..cda4a58 100644 --- a/TESTS/Level2/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level2/DigitalIO/DigitalIO.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level2/I2C/I2C.cpp b/TESTS/Level2/I2C/I2C.cpp index 3f05ab3..51eb37c 100644 --- a/TESTS/Level2/I2C/I2C.cpp +++ b/TESTS/Level2/I2C/I2C.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level2/Pwm/Pwm.cpp b/TESTS/Level2/Pwm/Pwm.cpp index bb9430c..59ab203 100644 --- a/TESTS/Level2/Pwm/Pwm.cpp +++ b/TESTS/Level2/Pwm/Pwm.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ @@ -102,6 +99,7 @@ void test_pwm_execute(PinName pin, float tolerance, int iterations, float dutycy 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"); } @@ -159,6 +157,6 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<200>, cases); + 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 f6a94b0..a91e78d 100644 --- a/TESTS/Level2/SPI/SPI.cpp +++ b/TESTS/Level2/SPI/SPI.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level3/I2C/I2C.cpp b/TESTS/Level3/I2C/I2C.cpp index 6d3ae12..967192f 100644 --- a/TESTS/Level3/I2C/I2C.cpp +++ b/TESTS/Level3/I2C/I2C.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/Level3/Pwm/Pwm.cpp b/TESTS/Level3/Pwm/Pwm.cpp index 37a231b..85a196b 100644 --- a/TESTS/Level3/Pwm/Pwm.cpp +++ b/TESTS/Level3/Pwm/Pwm.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ @@ -102,6 +99,7 @@ void test_pwm_execute(PinName pin, float tolerance, int waveform_count, float du 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(waveform_count - rc) <= calculated_percent, "There was more than a specific variance in number of rise cycles seen and number expected."); TEST_ASSERT_MESSAGE( std::abs(waveform_count - 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"); } diff --git a/TESTS/Level3/SPI/SPI.cpp b/TESTS/Level3/SPI/SPI.cpp index 904e583..b8bd3ac 100644 --- a/TESTS/Level3/SPI/SPI.cpp +++ b/TESTS/Level3/SPI/SPI.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ diff --git a/TESTS/host_tests/rand_provider.py b/TESTS/host_tests/rand_provider.py index cbf7968..ff11b9c 100644 --- a/TESTS/host_tests/rand_provider.py +++ b/TESTS/host_tests/rand_provider.py @@ -1,3 +1,18 @@ +# +# Copyright (c) 2016 ARM Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# from mbed_host_tests import BaseHostTest import random import sys diff --git a/TestFramework.cpp b/TestFramework.cpp index fafa6a1..53d560e 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ #include "TestFramework.hpp" @@ -24,9 +21,6 @@ // Initialization // /////////////////////////////////////////////////////////////////////////////*/ -/** - * Constructor for the test framework. Add all of the PinMaps to the pinout, as well as CI test shield pins -**/ TestFramework::TestFramework() { map_pins(PinMap_ADC, AnalogInput); map_pins(PinMap_DAC, AnalogOutput); @@ -50,9 +44,6 @@ TestFramework::TestFramework() { setup_cits_pins(); } -/** - * Add all of the CI Test Shield pins to the pinout vector -**/ 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)); @@ -61,8 +52,6 @@ void TestFramework::setup_cits_pins() { pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_4)); pinout[CITS_AnalogInput].push_back(construct_pinmap(MBED_CONF_APP_AIN_5)); pinout[CITS_AnalogOutput].push_back(construct_pinmap(MBED_CONF_APP_AOUT)); - pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_0)); - pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_1)); pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_2)); pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_3)); pinout[CITS_DigitalIO].push_back(construct_pinmap(MBED_CONF_APP_DIO_4)); @@ -88,16 +77,10 @@ PinMap TestFramework::construct_pinmap(PinName pin) { return pinmap; } -/** - * 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 - * @param Type which type the pins belong to (used to index into pinout) -**/ void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { int i = 0; while(pinmap[i].pin != (PinName)NC) { bool alreadyExists = false; - // printf("Pin %d\n", pinmap[i].pin); for (unsigned int j=0; j - * or proceed to the next pin of the pin type if there are remaining pins - * @param Type pin type to reset - * @return control_t Case control statement to repeat or move on to the next case -**/ utest::v1::control_t TestFramework::reset_iterator(Type pintype) { if (check_size(pintype)) return utest::v1::CaseRepeatAll; @@ -163,20 +124,10 @@ utest::v1::control_t TestFramework::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 - * @return PinName current pin -**/ PinMap TestFramework::get_increment_pin(Type pintype) { return pinout[pintype][pin_iterators[pintype]++]; } -/** - * Find the resistor ladder pins that are not the specified pin - * @param PinName pin that should not be included in the resistor ladder - * @return vector list of resistor ladder pins -**/ 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) { return resistor_ladder_pins; } -/** - * Get a randomized seed from Greentea's host test - * @return unsigned int random seed -**/ unsigned int TestFramework::get_seed() { // Send key value pair to greentea host tests greentea_send_kv("return_rand", "seed"); @@ -214,11 +161,6 @@ unsigned int TestFramework::get_seed() { // test shield. // /////////////////////////////////////////////////////////////////////////////*/ -/** - * 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 - * @return control_t Case control to repeat or move on to next test cases -**/ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, PinName)) { PinMap sda_pin = pinout[I2C_SDA][pin_iterators[I2C_SDA]]; int tag = 0; @@ -246,11 +188,6 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, return reset_iterator(I2C_SDA); } -/** - * 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 - * @return control_t Case control to repeat or move on to the next test cases -**/ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)) { // Check to make sure a CLK pin is still available if (pin_iterators[SPI_CLK] < pinout[SPI_CLK].size()) { @@ -307,15 +244,6 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, // for each hardware component. // /////////////////////////////////////////////////////////////////////////////*/ -/** - * 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 - * @param Type corresponding type of pin on the CI test shield - * @param Callback to the test case to run once a pin is found - * @param float data in float form to pass to the execution callback. Depends on callback - * @param int data in int form to pass to the execution callback. Depends on callback - * @return control_t identify to repeat or proceed to the next test case corresponding to the Specification -**/ utest::v1::control_t TestFramework::test_level1_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; @@ -357,16 +285,6 @@ utest::v1::control_t TestFramework::test_level1_framework(Type pintype, Type tes // get a little bit more intense. // /////////////////////////////////////////////////////////////////////////////*/ -/** - * 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 - * @param Type type of pin to find to run the callback - * @param Type corresponding type of pin on the CI test shield - * @param Callback to the test case to run once a pin is found - * @param float data in float form to pass to the execution callback. Depends on callback - * @param int data in int form to pass to the execution callback. Depends on callback - * @return control_t identify to repeat or proceed to the next test case corresponding to the Specification -**/ 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; @@ -392,7 +310,6 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes // State: End case // Pin was found, but execution had already occurred so queue up another test case if (tag) { - TEST_ASSERT(true); return utest::v1::CaseRepeatAll; // State: Execute // Pin was found and execution has not occurred yet diff --git a/TestFramework.hpp b/TestFramework.hpp index 8720a7c..e66264d 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * @author Michael Ray - * @since 3/22/2017 - * @version 1.0.0 * */ #ifndef TESTFRAMEWORK_H @@ -36,9 +33,18 @@ #include #include #include +#include #define TEST_STRING_MAX 100 +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_YELLOW "\x1b[33m" +#define ANSI_COLOR_BLUE "\x1b[34m" +#define ANSI_COLOR_MAGENTA "\x1b[35m" +#define ANSI_COLOR_CYAN "\x1b[36m" +#define ANSI_COLOR_RESET "\x1b[0m" + class TestFramework { public: @@ -70,49 +76,130 @@ class TestFramework { static std::vector< std::vector > pinout; static std::vector pin_iterators; + /** + * Constructor for the test framework. Add all of the PinMaps to the pinout, as well as CI test shield pins + **/ TestFramework(); - static bool check_size(Type pintype); - static utest::v1::control_t reset_iterator(Type pintype); + template + 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 PinMap get_increment_pin(Type pintype); + 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 + * @param Type pin type to in which the pin has to be a part of + * @return index where the pin is found. Returns -1 if can't be found + **/ + 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 + * @return PinName pin that is connected to the input pin + **/ static PinName find_pin_pair(PinName pin); - static int find_pin(PinName pin, Type pintype); + /** + * Check to see if the pin iterator is pointing at a valid pin in the pinout + * @param Type pin type to validate + * @return bool if the pin iterator is a valid pin in the pinout + **/ + 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 + * @param Type pin type to reset + * @return control_t Case control statement to repeat or move on to the next case + **/ + 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 + * @return PinName current pin + **/ + 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 + * @return vector list of resistor ladder pins + **/ 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 + * @return control_t Case control to repeat or move on to next test cases + **/ 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 + * @return control_t Case control to repeat or move on to the next test cases + **/ 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 + * @param Type corresponding type of pin on the CI test shield + * @param Callback to the test case to run once a pin is found + * @param float data in float form to pass to the execution callback. Depends on callback + * @param int data in int form to pass to the execution callback. Depends on callback + * @return control_t identify to repeat or proceed to the next test case corresponding to the Specification + **/ 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 + * @param Type type of pin to find to run the callback + * @param Type corresponding type of pin on the CI test shield + * @param Callback to the test case to run once a pin is found + * @param float data in float form to pass to the execution callback. Depends on callback + * @param int data in int form to pass to the execution callback. Depends on callback + * @return control_t identify to repeat or proceed to the next test case corresponding to the Specification + **/ static utest::v1::control_t test_level2_framework(Type pintype, Type testtype, void (*execution_callback)(PinName, float, int), float floatdata, int intdata); - static unsigned int get_seed(); - - template - 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) { - greentea_case_failure_abort_handler(source, reason); - return utest::v1::STATUS_ABORT; - } private: - void map_pins(const PinMap pinmap[], Type pintype); - + /** + * Add all of the CI Test Shield pins to the pinout vector + **/ 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 + * @param Type which type the pins belong to (used to index into pinout) + **/ + void map_pins(const PinMap pinmap[], Type pintype); + }; #endif //TESTFRAMEWORK_H \ No newline at end of file diff --git a/mbed_app.json b/mbed_app.json index 69512e1..a29fd76 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": { "NUCLEO_L476RG": { @@ -81,5 +81,6 @@ "DIO_8":"PTC12", "DIO_9":"PTC4" } - } + }, + "macros": ["IDB0XA1_D13_PATCH"] } From 8e1904d097ecc58b441f6ea34355b92d46aba722 Mon Sep 17 00:00:00 2001 From: Michael Ray Date: Wed, 5 Apr 2017 13:06:58 -0500 Subject: [PATCH 16/28] Update mbed_app.json --- mbed_app.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mbed_app.json b/mbed_app.json index a29fd76..2b481f2 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -81,6 +81,5 @@ "DIO_8":"PTC12", "DIO_9":"PTC4" } - }, - "macros": ["IDB0XA1_D13_PATCH"] + } } From 6b956e6924eef07667fde2a75fb32e045dcaf71d Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Wed, 28 Jun 2017 13:03:54 -0500 Subject: [PATCH 17/28] Formated code so that it is uniform between all the tests. Removed unnecessary TEST_ASSERT(true) from all tests --- TESTS/Arduino/AnalogIn/AnalogIn.cpp | 34 ++++---- TESTS/Arduino/AnalogOut/AnalogOut.cpp | 24 +++--- TESTS/Arduino/DigitalIO/DigitalIO.cpp | 44 +++++----- TESTS/Arduino/I2C/I2C.cpp | 22 +++-- TESTS/Arduino/Pwm/Pwm.cpp | 30 +++---- TESTS/Arduino/SPI/SPI.cpp | 28 +++--- TESTS/Level0/AnalogIn/AnalogIn.cpp | 7 +- TESTS/Level0/AnalogOut/AnalogOut.cpp | 5 +- TESTS/Level0/BusInOut/BusInOut.cpp | 3 +- TESTS/Level0/DigitalIO/DigitalIO.cpp | 5 +- TESTS/Level0/I2C/I2C.cpp | 10 +-- TESTS/Level0/Pwm/Pwm.cpp | 9 +- TESTS/Level0/SPI/SPI.cpp | 18 ++-- TESTS/Level1/I2C/I2C.cpp | 42 +++++---- TESTS/Level1/SPI/SPI.cpp | 92 ++++++++++---------- TESTS/Level2/I2C/I2C.cpp | 49 +++++------ TESTS/Level2/SPI/SPI.cpp | 102 +++++++++++----------- TESTS/Level3/I2C/I2C.cpp | 65 +++++++------- TESTS/Level3/SPI/SPI.cpp | 118 +++++++++++++------------- 19 files changed, 336 insertions(+), 371 deletions(-) diff --git a/TESTS/Arduino/AnalogIn/AnalogIn.cpp b/TESTS/Arduino/AnalogIn/AnalogIn.cpp index 187d7d7..e2c2e1b 100644 --- a/TESTS/Arduino/AnalogIn/AnalogIn.cpp +++ b/TESTS/Arduino/AnalogIn/AnalogIn.cpp @@ -28,34 +28,32 @@ using namespace utest::v1; // Template to set one Analog pin as input and then cycle through the rest as outputs. // As you turn more pins on the voltage on the ain pin will go up. template -void AnalogInput_Test() -{ - AnalogIn ain(ain_pin); - DEBUG_PRINTF("Tested pin %d for Arduino analog in capabilities\n", ain_pin); - TEST_ASSERT(true); +void AnalogInput_Test(){ + AnalogIn ain(ain_pin); + DEBUG_PRINTF("Tested pin %d for Arduino analog in capabilities\n", ain_pin); } utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); } utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; } Case cases[] = { - Case("Arduino - Analog Input Constructor on AIN_0", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_1", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_2", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_3", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_4", AnalogInput_Test, greentea_failure_handler), - Case("Arduino - Analog Input Constructor on AIN_5", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_0", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_1", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_2", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_3", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_4", AnalogInput_Test, greentea_failure_handler), + Case("Arduino - Analog Input Constructor on AIN_5", AnalogInput_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); } diff --git a/TESTS/Arduino/AnalogOut/AnalogOut.cpp b/TESTS/Arduino/AnalogOut/AnalogOut.cpp index e06128b..d1894ca 100644 --- a/TESTS/Arduino/AnalogOut/AnalogOut.cpp +++ b/TESTS/Arduino/AnalogOut/AnalogOut.cpp @@ -26,29 +26,27 @@ using namespace utest::v1; template -void AnalogOutput_Test() -{ - AnalogOut ain(aout_pin); - DEBUG_PRINTF("Tested pin %d for Arduino analog out capabilities\n", aout_pin); - TEST_ASSERT(true); +void AnalogOutput_Test(){ + AnalogOut ain(aout_pin); + DEBUG_PRINTF("Tested pin %d for Arduino analog out capabilities\n", aout_pin); } utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); } utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; } Case cases[] = { - Case("Arduino - Analog Output Constructor on AOUT_0", AnalogOutput_Test, greentea_failure_handler), + Case("Arduino - Analog Output Constructor on AOUT_0", AnalogOutput_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); } diff --git a/TESTS/Arduino/DigitalIO/DigitalIO.cpp b/TESTS/Arduino/DigitalIO/DigitalIO.cpp index 171ccce..ca028a5 100644 --- a/TESTS/Arduino/DigitalIO/DigitalIO.cpp +++ b/TESTS/Arduino/DigitalIO/DigitalIO.cpp @@ -23,39 +23,37 @@ using namespace utest::v1; template -void DigitalIO_Test() -{ - DigitalOut dout(dio_pin); - DigitalIn din(dio_pin); - DEBUG_PRINTF("Tested pin %d for Arduino digital in/out capabilities\n", dio_pin); - TEST_ASSERT(true); +void DigitalIO_Test(){ + DigitalOut dout(dio_pin); + DigitalIn din(dio_pin); + DEBUG_PRINTF("Tested pin %d for Arduino digital in/out capabilities\n", dio_pin); } utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); } utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; } Case cases[] = { - Case("Arduino - Digital IO Constructor on DIO_0", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_1", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_2", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_3", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_4", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_5", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_6", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_7", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_8", DigitalIO_Test, greentea_failure_handler), - Case("Arduino - Digital IO Constructor on DIO_9", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_0", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_1", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_2", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_3", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_4", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_5", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_6", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_7", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_8", DigitalIO_Test, greentea_failure_handler), + Case("Arduino - Digital IO Constructor on DIO_9", DigitalIO_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); } diff --git a/TESTS/Arduino/I2C/I2C.cpp b/TESTS/Arduino/I2C/I2C.cpp index 3532b34..99552b4 100644 --- a/TESTS/Arduino/I2C/I2C.cpp +++ b/TESTS/Arduino/I2C/I2C.cpp @@ -26,21 +26,19 @@ using namespace utest::v1; template -void I2C_Test() -{ - I2C i2c(sda, scl); - DEBUG_PRINTF("Tested sda pin %d and scl pin %d for Arduino I2C capabilities\n", sda, scl); - TEST_ASSERT(true); +void I2C_Test(){ + I2C i2c(sda, scl); + DEBUG_PRINTF("Tested sda pin %d and scl pin %d for Arduino I2C capabilities\n", sda, scl); } utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); } utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; } Case cases[] = { @@ -48,7 +46,7 @@ Case cases[] = { }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); } diff --git a/TESTS/Arduino/Pwm/Pwm.cpp b/TESTS/Arduino/Pwm/Pwm.cpp index 477fe17..9381d88 100644 --- a/TESTS/Arduino/Pwm/Pwm.cpp +++ b/TESTS/Arduino/Pwm/Pwm.cpp @@ -26,32 +26,30 @@ using namespace utest::v1; template -void PWM_Test() -{ - PwmOut pwm(pwm_pin); - DEBUG_PRINTF("Tested pin %d for Arduino digital in/out capabilities\n", pwm_pin); - TEST_ASSERT(true); +void PWM_Test(){ + PwmOut pwm(pwm_pin); + DEBUG_PRINTF("Tested pin %d for Arduino digital in/out capabilities\n", pwm_pin); } utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); } utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; } Case cases[] = { - Case("Arduino - PWM Constructor on PWM_0", PWM_Test, greentea_failure_handler), - Case("Arduino - PWM Constructor on PWM_1", PWM_Test, greentea_failure_handler), - Case("Arduino - PWM Constructor on PWM_2", PWM_Test, greentea_failure_handler), - Case("Arduino - PWM Constructor on PWM_3", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_0", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_1", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_2", PWM_Test, greentea_failure_handler), + Case("Arduino - PWM Constructor on PWM_3", PWM_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); } diff --git a/TESTS/Arduino/SPI/SPI.cpp b/TESTS/Arduino/SPI/SPI.cpp index dca320d..d2b06e4 100644 --- a/TESTS/Arduino/SPI/SPI.cpp +++ b/TESTS/Arduino/SPI/SPI.cpp @@ -16,7 +16,7 @@ // check if SPI is supported on this device #if !DEVICE_SPI - #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif #include "mbed.h" @@ -28,30 +28,28 @@ using namespace utest::v1; template -void SPI_Test() -{ - SPI(mosi_pin, miso_pin, clk_pin); - DigitalOut cs(cs_pin); - DEBUG_PRINTF("Tested pins %d, %d, %d, and %d for Arduino SPI capabilities\n", mosi_pin, miso_pin, clk_pin, cs_pin); - TEST_ASSERT(true); +void SPI_Test(){ + SPI(mosi_pin, miso_pin, clk_pin); + DigitalOut cs(cs_pin); + DEBUG_PRINTF("Tested pins %d, %d, %d, and %d for Arduino SPI capabilities\n", mosi_pin, miso_pin, clk_pin, cs_pin); } utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); - return verbose_test_setup_handler(number_of_cases); + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); } utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; + greentea_case_failure_abort_handler(source, reason); + return STATUS_ABORT; } Case cases[] = { - Case("Arduino - SPI Constructor", SPI_Test, greentea_failure_handler), + Case("Arduino - SPI Constructor", SPI_Test, greentea_failure_handler), }; int main() { - // Formulate a specification and run the tests based on the Case array - Specification specification(test_setup, cases); - return !Harness::run(specification); + // Formulate a specification and run the tests based on the Case array + Specification specification(test_setup, cases); + return !Harness::run(specification); } diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index a599169..82d62cd 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -40,12 +40,11 @@ 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("%dRunning analog input constructor on pin %d\n", ANSI_COLOR_YELLOW, pin.pin); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin.pin); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); AnalogIn ain(pin.pin); - TEST_ASSERT(true); return test_framework.reset_iterator(TestFramework::AnalogInput); } @@ -56,5 +55,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/Level0/AnalogOut/AnalogOut.cpp b/TESTS/Level0/AnalogOut/AnalogOut.cpp index a074128..ac767c3 100644 --- a/TESTS/Level0/AnalogOut/AnalogOut.cpp +++ b/TESTS/Level0/AnalogOut/AnalogOut.cpp @@ -40,11 +40,10 @@ 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); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); AnalogOut ain(pin.pin); - TEST_ASSERT(true); return test_framework.reset_iterator(TestFramework::AnalogOutput); } @@ -55,5 +54,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/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index 776c8cd..5b2886b 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -48,7 +48,6 @@ utest::v1::control_t test_level0_businout(const size_t call_count) { 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]); - TEST_ASSERT(true); return test_framework.reset_iterator(TestFramework::BusIO); } @@ -59,5 +58,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/Level0/DigitalIO/DigitalIO.cpp b/TESTS/Level0/DigitalIO/DigitalIO.cpp index 7e04f62..30c1e58 100644 --- a/TESTS/Level0/DigitalIO/DigitalIO.cpp +++ b/TESTS/Level0/DigitalIO/DigitalIO.cpp @@ -37,12 +37,11 @@ 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); - 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); - TEST_ASSERT(true); return test_framework.reset_iterator(TestFramework::DigitalIO); } @@ -53,5 +52,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/Level0/I2C/I2C.cpp b/TESTS/Level0/I2C/I2C.cpp index 242941c..04b351c 100644 --- a/TESTS/Level0/I2C/I2C.cpp +++ b/TESTS/Level0/I2C/I2C.cpp @@ -40,12 +40,10 @@ 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); - TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC"); - TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC"); + TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC"); + TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC"); - I2C i2c(sda, scl); - - TEST_ASSERT(true); + I2C i2c(sda, scl); } utest::v1::control_t test_level0_i2c(const size_t call_count) { @@ -59,5 +57,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/Level0/Pwm/Pwm.cpp b/TESTS/Level0/Pwm/Pwm.cpp index f63759f..4b80a61 100644 --- a/TESTS/Level0/Pwm/Pwm.cpp +++ b/TESTS/Level0/Pwm/Pwm.cpp @@ -41,13 +41,12 @@ 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); - 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); - TEST_ASSERT(true); return test_framework.reset_iterator(TestFramework::PWM); } @@ -58,5 +57,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/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index 594b12d..bc353fb 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -17,7 +17,7 @@ */ #if !DEVICE_SPI - #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif #include "mbed.h" @@ -40,15 +40,13 @@ TestFramework test_framework; void construct_i2c(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); - 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); - - TEST_ASSERT(true); + SPI(pin_mosi, pin_miso, pin_clk); + DigitalOut cs(pin_cs); } utest::v1::control_t test_level0_spi(const size_t call_count) { @@ -62,5 +60,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 0a7ac8b..13b9c2b 100644 --- a/TESTS/Level1/I2C/I2C.cpp +++ b/TESTS/Level1/I2C/I2C.cpp @@ -50,39 +50,37 @@ utest::v1::control_t test_level1_i2c(const size_t call_count) { 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) { - TEST_ASSERT(false); return utest::v1::CaseNext; } 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"); - 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, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level1/SPI/SPI.cpp b/TESTS/Level1/SPI/SPI.cpp index 5adcf73..8da1d12 100644 --- a/TESTS/Level1/SPI/SPI.cpp +++ b/TESTS/Level1/SPI/SPI.cpp @@ -17,7 +17,7 @@ */ #if !DEVICE_SPI - #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif #include "mbed.h" @@ -52,59 +52,57 @@ 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) { - TEST_ASSERT(false); 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); - 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"); + 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."); + // Unmount and de-initialize the SD card + error = fs.unmount(); + TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); - sd.deinit(); - TEST_ASSERT(true); + sd.deinit(); - return utest::v1::CaseNext; + return utest::v1::CaseNext; } Case cases[] = { @@ -116,5 +114,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/Level2/I2C/I2C.cpp b/TESTS/Level2/I2C/I2C.cpp index 51eb37c..9277fe5 100644 --- a/TESTS/Level2/I2C/I2C.cpp +++ b/TESTS/Level2/I2C/I2C.cpp @@ -47,45 +47,42 @@ 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; - if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || - TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { - TEST_ASSERT(false); + 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); - 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, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level2/SPI/SPI.cpp b/TESTS/Level2/SPI/SPI.cpp index a91e78d..fe08e64 100644 --- a/TESTS/Level2/SPI/SPI.cpp +++ b/TESTS/Level2/SPI/SPI.cpp @@ -52,65 +52,63 @@ 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::SPI_CS)==-1) { - TEST_ASSERT(false); 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); - 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); - } + 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."); + error = fs.unmount(); + TEST_ASSERT_MESSAGE(error==0,"SD file system unmount failed."); - sd.deinit(); - TEST_ASSERT(true); + sd.deinit(); - return utest::v1::CaseNext; + return utest::v1::CaseNext; } Case cases[] = { @@ -122,5 +120,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/Level3/I2C/I2C.cpp b/TESTS/Level3/I2C/I2C.cpp index 967192f..c4fde1e 100644 --- a/TESTS/Level3/I2C/I2C.cpp +++ b/TESTS/Level3/I2C/I2C.cpp @@ -47,48 +47,45 @@ 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; - if (TestFramework::find_pin(pin_scl, TestFramework::I2C_SCL)==-1 || - TestFramework::find_pin(pin_sda, TestFramework::I2C_SDA)==-1) { - TEST_ASSERT(false); + 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); - 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}; - int rand_size = rand()%128+1; - for (int i=0; i, cases); - return !Harness::run(specification); + return !Harness::run(specification); } diff --git a/TESTS/Level3/SPI/SPI.cpp b/TESTS/Level3/SPI/SPI.cpp index b8bd3ac..af1ea3c 100644 --- a/TESTS/Level3/SPI/SPI.cpp +++ b/TESTS/Level3/SPI/SPI.cpp @@ -17,7 +17,7 @@ */ #if !DEVICE_SPI - #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. + #error SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. #endif #include "mbed.h" @@ -52,68 +52,66 @@ utest::v1::control_t test_level3_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) { - TEST_ASSERT(false); 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); - 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}; - int rand_size = rand()%128 + 1; - 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(); - TEST_ASSERT(true); - - if (call_count 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(); + + if (call_count, cases); - return !Harness::run(specification); + return !Harness::run(specification); } From 4846b7bed5e2e888d5d0d5ef77f85838fcbd65da Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 29 Jun 2017 09:57:34 -0500 Subject: [PATCH 18/28] Removed unused ANSI_COLOR_ defs from TestFramework.hpp --- TestFramework.hpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/TestFramework.hpp b/TestFramework.hpp index e66264d..2166645 100644 --- a/TestFramework.hpp +++ b/TestFramework.hpp @@ -37,14 +37,6 @@ #define TEST_STRING_MAX 100 -#define ANSI_COLOR_RED "\x1b[31m" -#define ANSI_COLOR_GREEN "\x1b[32m" -#define ANSI_COLOR_YELLOW "\x1b[33m" -#define ANSI_COLOR_BLUE "\x1b[34m" -#define ANSI_COLOR_MAGENTA "\x1b[35m" -#define ANSI_COLOR_CYAN "\x1b[36m" -#define ANSI_COLOR_RESET "\x1b[0m" - class TestFramework { public: @@ -202,4 +194,4 @@ class TestFramework { }; -#endif //TESTFRAMEWORK_H \ No newline at end of file +#endif //TESTFRAMEWORK_H From d093ddcc9340c096cfc8d95b5e75ed567e9dfc17 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 29 Jun 2017 14:47:28 -0500 Subject: [PATCH 19/28] Changed BusInOut so that it creates a bus of 16 pins instead of 15. Slight formatting corrections to TestFramework.cpp --- TESTS/Level0/BusInOut/BusInOut.cpp | 4 ++-- TestFramework.cpp | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index 5b2886b..ff723e5 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -38,7 +38,7 @@ utest::v1::control_t test_level0_businout(const size_t call_count) { DEBUG_PRINTF("Running bus input/output constructor\n"); std::vector pins; - for (int i=0; i<15; i++) { + for (int i=0; i<16; i++) { if (TestFramework::check_size(TestFramework::BusIO)) { pins.push_back(test_framework.get_increment_pin(TestFramework::BusIO).pin); } else { @@ -46,7 +46,7 @@ utest::v1::control_t test_level0_businout(const size_t call_count) { } } - 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]); + 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); } diff --git a/TestFramework.cpp b/TestFramework.cpp index 53d560e..aa7b6b0 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -167,21 +167,20 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, // 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) { + 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 - else { - execution_callback(sda_pin.pin, pinout[I2C_SCL][pin_iterators[I2C_SCL]].pin); - tag = 1; - } - } - pin_iterators[I2C_SCL]++; + // 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 + else { + execution_callback(sda_pin.pin, pinout[I2C_SCL][pin_iterators[I2C_SCL]].pin); + tag = 1; + } + } + pin_iterators[I2C_SCL]++; } // All the SCL pins have been found for the identified SDA pin. Increment the SDA pin - if (!tag) { TEST_ASSERT(false);} + if (!tag) TEST_ASSERT(false); pin_iterators[I2C_SDA]++; pin_iterators[I2C_SCL] = 0; // Check to see if the SDA pin. Move on to the next test case if invalid and reset the counters @@ -322,4 +321,4 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes // State: End test // All pins have been identified and run, reset the iterators and return back return reset_iterator(pintype); -} \ No newline at end of file +} From d15893dc24e9058391c97d998ecb1f606c9937c8 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 29 Jun 2017 15:30:47 -0500 Subject: [PATCH 20/28] Changed tag from unnecessary int to a bool instead. Updated some comments --- TestFramework.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index aa7b6b0..40e7bab 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -163,7 +163,8 @@ unsigned int TestFramework::get_seed() { utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, PinName)) { PinMap sda_pin = pinout[I2C_SDA][pin_iterators[I2C_SDA]]; - int tag = 0; + // 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()) { @@ -174,7 +175,7 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, // Matching SCL pin was found. Run the callback with the found pins else { execution_callback(sda_pin.pin, pinout[I2C_SCL][pin_iterators[I2C_SCL]].pin); - tag = 1; + tag = true; } } pin_iterators[I2C_SCL]++; @@ -183,7 +184,7 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, if (!tag) TEST_ASSERT(false); pin_iterators[I2C_SDA]++; pin_iterators[I2C_SCL] = 0; - // Check to see if the SDA pin. Move on to the next test case if invalid and reset the counters + // Check to see if there are any more SDA pins available. Move on to the next test case if invalid and reset the counters return reset_iterator(I2C_SDA); } @@ -289,13 +290,13 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes PinName pin = pinout[pintype][pin_iterators[pintype]].pin; // 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 (1) or not (0) - int tag = 0; + // Tag is used to identify if a test case had been executed (true) or not (false) + bool tag = false; // State: Execute if (index != -1) { - // Pin was found, run the callback and specify the tag to 1 (run) + // Pin was found, run the callback and specify the tag to true (run) execution_callback(pin, floatdata, intdata); - tag = 1; + tag = true; } // Search the remaining pins of the pintype to find a pin on the CI test shield while (check_size(pintype)) { @@ -314,7 +315,7 @@ utest::v1::control_t TestFramework::test_level2_framework(Type pintype, Type tes // Pin was found and execution has not occurred yet } else { execution_callback(pin, floatdata, intdata); - tag = 1; + tag = true; } } } From df47ace6a2078e4f2d07c5f597b9bdd63f68d98e Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 30 Jun 2017 10:29:42 -0500 Subject: [PATCH 21/28] Fixed some bugs in TestFramework::run_spi. SPI_CS was not switching pins throughout the different test iterations --- TestFramework.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index 40e7bab..ef366ee 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -202,13 +202,13 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, // Iterate through the CS pins to find a matching HW block pin to the CLK pin while (pin_iterators[SPI_CS] < pinout[SPI_CS].size()) { - if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + if (pinout[SPI_CS][pin_iterators[SPI_CS]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { - // Found all matching HW block pins. Run the execution callback with the identified pins + // Found all matching HW block pins. Run the execution callback with the identified pins. Also increments SPI_CLK pin in preparation for next iteration execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]++].pin, - pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, - pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, - pinout[SPI_CS][pin_iterators[SPI_CS]].pin); + pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, + pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, + pinout[SPI_CS][pin_iterators[SPI_CS]].pin); // Reset the iterators pin_iterators[SPI_MISO] = 0; pin_iterators[SPI_MOSI] = 0; @@ -217,18 +217,21 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, } pin_iterators[SPI_CS]++; } - TEST_ASSERT(false); + TEST_ASSERT_MESSAGE(false, "No matching SPI_CS pins found"); } pin_iterators[SPI_MOSI]++; } - TEST_ASSERT(false); + TEST_ASSERT_MESSAGE(false, "No matching SPI_MOSI pins found"); } pin_iterators[SPI_MISO]++; } - TEST_ASSERT(false); + TEST_ASSERT_MESSAGE(false, "No matching SPI_MISO pins found"); } - // All CLK pins have been iterated through. Reset the CLK pin iterator, run the CI test shield pin pair, and then move on to the next test case + // All CLK pins have been iterated through. Reset the pin iterators, run the CI test shield pin pair, and then move on to the next test case pin_iterators[SPI_CLK] = 0; + pin_iterators[SPI_MISO] = 0; + pin_iterators[SPI_MOSI] = 0; + pin_iterators[SPI_CS] = 0; execution_callback(MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_CS); return utest::v1::CaseNext; } From c9f75d4988279d91f37d2822179dfbfcba131deb Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Mon, 3 Jul 2017 14:46:21 -0500 Subject: [PATCH 22/28] Added greater coverage for level0/SPI testing. It now tests all possible pin assignments that a user could configure. Fixed typo found in SPI.cpp, construct_i2c->construct_spi. Added wait(0.1) to SPI.cpp so that the print statement can finish printing in the event of an error --- TESTS/Level0/SPI/SPI.cpp | 7 ++- TestFramework.cpp | 115 +++++++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 49 deletions(-) diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index bc353fb..b8764dc 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -38,8 +38,9 @@ std::vector TestFramework::pin_iterators(TS_NC); // Initialize a test framework object TestFramework test_framework; -void construct_i2c(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 %d, MISO pin %d, MOSI pin %d, and CS pin %d\n", pin_clk, pin_miso, pin_mosi, pin_cs); + wait(0.1); // Make sure system has time to print above message in case of error 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"); @@ -50,7 +51,7 @@ void construct_i2c(PinName pin_clk, PinName pin_miso, PinName pin_mosi, PinName } utest::v1::control_t test_level0_spi(const size_t call_count) { - return test_framework.run_spi(&construct_i2c); + return test_framework.run_spi(&construct_spi); } Case cases[] = { @@ -59,6 +60,6 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<30>, cases); + Specification specification(TestFramework::test_setup<120>, cases); return !Harness::run(specification); } diff --git a/TestFramework.cpp b/TestFramework.cpp index ef366ee..f4f640e 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -18,7 +18,7 @@ #include "TestFramework.hpp" /*///////////////////////////////////////////////////////////////////////////// -// Initialization // +// Initialization // /////////////////////////////////////////////////////////////////////////////*/ TestFramework::TestFramework() { @@ -153,12 +153,12 @@ 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)) { @@ -171,7 +171,7 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, 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; + if (tag) {return utest::v1::CaseRepeatAll;} // Matching SCL pin was found. Run the callback with the found pins else { execution_callback(sda_pin.pin, pinout[I2C_SCL][pin_iterators[I2C_SCL]].pin); @@ -181,53 +181,76 @@ utest::v1::control_t TestFramework::run_i2c(void (*execution_callback)(PinName, pin_iterators[I2C_SCL]++; } // All the SCL pins have been found for the identified SDA pin. Increment the SDA pin - if (!tag) TEST_ASSERT(false); + if (!tag) {TEST_ASSERT(false);} pin_iterators[I2C_SDA]++; pin_iterators[I2C_SCL] = 0; // Check to see if there are any more SDA pins available. Move on to the next test case if invalid and reset the counters return reset_iterator(I2C_SDA); } + utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, PinName, PinName, PinName)) { - // Check to make sure a CLK pin is still available - if (pin_iterators[SPI_CLK] < pinout[SPI_CLK].size()) { + bool tag = false; + + // 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 the MISO pins to find a matching HW block pin to the CLK pin + // Iterate through all the MISO pins while (pin_iterators[SPI_MISO] < pinout[SPI_MISO].size()) { - if (pinout[SPI_MISO][pin_iterators[SPI_MISO]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + + // Iterate through all the MOSI pins + while (pin_iterators[SPI_MOSI] < pinout[SPI_MOSI].size()) { + + // Iterate through all the CS pins + while (pin_iterators[SPI_CS] < pinout[SPI_CS].size()) { - // Iterate through the MOSI pins to find a matching HW block pin to the CLK pin - while (pin_iterators[SPI_MOSI] < pinout[SPI_MOSI].size()) { - if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + // ensure that chosen MISO, MOSI, and CS pins match the CLK pin's HW block + if (pinout[SPI_MISO][pin_iterators[SPI_MISO]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + if (pinout[SPI_CS][pin_iterators[SPI_CS]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { - // Iterate through the CS pins to find a matching HW block pin to the CLK pin - while (pin_iterators[SPI_CS] < pinout[SPI_CS].size()) { - if (pinout[SPI_CS][pin_iterators[SPI_CS]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + // ensure that chosen SPI_CLK pin is not already assigned to another peripheral + if((pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != pinout[SPI_CS][pin_iterators[SPI_CS]].pin) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != USBTX) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != USBRX)){ - // Found all matching HW block pins. Run the execution callback with the identified pins. Also increments SPI_CLK pin in preparation for next iteration - execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]++].pin, - pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, - pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, - pinout[SPI_CS][pin_iterators[SPI_CS]].pin); - // Reset the iterators - pin_iterators[SPI_MISO] = 0; - pin_iterators[SPI_MOSI] = 0; - pin_iterators[SPI_CS] = 0; - return utest::v1::CaseRepeatAll; - } - pin_iterators[SPI_CS]++; - } - TEST_ASSERT_MESSAGE(false, "No matching SPI_CS pins found"); - } - pin_iterators[SPI_MOSI]++; - } - TEST_ASSERT_MESSAGE(false, "No matching SPI_MOSI pins found"); - } - pin_iterators[SPI_MISO]++; - } - TEST_ASSERT_MESSAGE(false, "No matching SPI_MISO pins found"); - } - // All CLK pins have been iterated through. Reset the pin iterators, run the CI test shield pin pair, and then move on to the next test case + // ensure that chosen SPI_MISO pin is not already assigned to another peripheral + if((pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != pinout[SPI_CS][pin_iterators[SPI_CS]].pin) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != USBTX) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != USBRX)){ + + // ensure that chosen SPI_MOSI pin is not already assigned to another peripheral + if((pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != pinout[SPI_CS][pin_iterators[SPI_CS]].pin) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != USBTX) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != USBRX)){ + + // ensure that chosen SPI_CS pin is not already assigned to another peripheral + if((pinout[SPI_CS][pin_iterators[SPI_CS]].pin != pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != USBTX) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != USBRX)){ + + // Found matching HW block pins. Run execution callback with them. + execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin, + pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, + pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, + pinout[SPI_CS][pin_iterators[SPI_CS]].pin); + tag = true; + } + } + } + } + } + } + } + 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 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; pin_iterators[SPI_MISO] = 0; pin_iterators[SPI_MOSI] = 0; @@ -237,14 +260,14 @@ 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 to find pins 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. // +// 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) { @@ -280,12 +303,12 @@ utest::v1::control_t TestFramework::test_level1_framework(Type pintype, Type tes } /*///////////////////////////////////////////////////////////////////////////// -// 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) { From 169500e8abe4f1003e6d6422143d5383d7376047 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 6 Jul 2017 10:05:16 -0500 Subject: [PATCH 23/28] Cleaned up SPI code in TestFramework to make it easier to read and follow along. --- TestFramework.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index f4f640e..aa422b7 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -203,29 +203,31 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, // 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 (pinout[SPI_MISO][pin_iterators[SPI_MISO]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { - if (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { - if (pinout[SPI_CS][pin_iterators[SPI_CS]].peripheral == pinout[SPI_CLK][pin_iterators[SPI_CLK]].peripheral) { + if (MISO.peripheral == CLK.peripheral) { + if (MOSI.peripheral == CLK.peripheral) { + if (CS.peripheral == CLK.peripheral) { // ensure that chosen SPI_CLK pin is not already assigned to another peripheral - if((pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != pinout[SPI_CS][pin_iterators[SPI_CS]].pin) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != USBTX) && (pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin != USBRX)){ + if((CLK.pin != MISO.pin) && (CLK.pin != MOSI.pin) && (CLK.pin != CS.pin) && (CLK.pin != USBTX) && (CLK.pin != USBRX)){ // ensure that chosen SPI_MISO pin is not already assigned to another peripheral - if((pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != pinout[SPI_CS][pin_iterators[SPI_CS]].pin) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != USBTX) && (pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin != USBRX)){ + if((MISO.pin != CLK.pin) && (MISO.pin != MOSI.pin) && (MISO.pin != CS.pin) && (MISO.pin != USBTX) && (MISO.pin != USBRX)){ // ensure that chosen SPI_MOSI pin is not already assigned to another peripheral - if((pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != pinout[SPI_CS][pin_iterators[SPI_CS]].pin) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != USBTX) && (pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin != USBRX)){ + if((MOSI.pin != CLK.pin) && (MOSI.pin != MISO.pin) && (MOSI.pin != CS.pin) && (MOSI.pin != USBTX) && (MOSI.pin != USBRX)){ // ensure that chosen SPI_CS pin is not already assigned to another peripheral - if((pinout[SPI_CS][pin_iterators[SPI_CS]].pin != pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != USBTX) && (pinout[SPI_CS][pin_iterators[SPI_CS]].pin != USBRX)){ + if((CS.pin != CLK.pin) && (CS.pin != MOSI.pin) && (CS.pin != MISO.pin) && (CS.pin != USBTX) && (CS.pin != USBRX)){ // Found matching HW block pins. Run execution callback with them. - execution_callback(pinout[SPI_CLK][pin_iterators[SPI_CLK]].pin, - pinout[SPI_MISO][pin_iterators[SPI_MISO]].pin, - pinout[SPI_MOSI][pin_iterators[SPI_MOSI]].pin, - pinout[SPI_CS][pin_iterators[SPI_CS]].pin); + execution_callback(CLK.pin, MISO.pin, MOSI.pin, CS.pin); tag = true; } } From c7ca382a7df8926d84bbed473ad4465a69cd4a91 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Thu, 6 Jul 2017 15:35:16 -0500 Subject: [PATCH 24/28] Added K22F to mbed_app.json. Formated Level1/AnalogIn. Added USBTX && USBRX check in Level0/AnalogIn as it was failing when running on the K22F. It was failing because one of its analogIn in pins is tied and already assigned to USBTX --- TESTS/Level0/AnalogIn/AnalogIn.cpp | 8 ++-- TESTS/Level1/AnalogIn/AnalogIn.cpp | 62 +++++++++++++++--------------- mbed_app.json | 5 ++- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index 82d62cd..4bccc66 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -40,10 +40,12 @@ 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); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + if(pin.pin != USBTX && pin.pin != USBRX){ // make sure pin is not already being used + DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin.pin); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); - AnalogIn ain(pin.pin); + AnalogIn ain(pin.pin); + } return test_framework.reset_iterator(TestFramework::AnalogInput); } diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index 6e657f7..a287ce9 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -40,47 +40,47 @@ 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); - 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"); // 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(); 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); + return !Harness::run(specification); } diff --git a/mbed_app.json b/mbed_app.json index 2b481f2..8130454 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -31,7 +31,7 @@ "PWM_1": "D5", "PWM_2": "D6", "PWM_3": "D9", - "DEBUG_MSG": 0 + "DEBUG_MSG": 1 }, "target_overrides": { "NUCLEO_L476RG": { @@ -80,6 +80,9 @@ "AOUT": "DAC0_OUT", "DIO_8":"PTC12", "DIO_9":"PTC4" + }, + "K22F": { + "AOUT": "DAC0_OUT" } } } From f3c379aed679954e5f9aa29231c88d5c3fa4d058 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 7 Jul 2017 13:18:18 -0500 Subject: [PATCH 25/28] Added check to prevent pins already assigned to USBTX && USBRX from getting reassigned --- TESTS/Level0/BusInOut/BusInOut.cpp | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index ff723e5..831b8b1 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -25,6 +25,8 @@ #include "TestFramework.hpp" #include +#define BUS_SIZE 16 + using namespace utest::v1; // Static variables for managing the dynamic list of pins @@ -37,16 +39,29 @@ TestFramework test_framework; utest::v1::control_t test_level0_businout(const size_t call_count) { DEBUG_PRINTF("Running bus input/output constructor\n"); - std::vector pins; - for (int i=0; i<16; i++) { - if (TestFramework::check_size(TestFramework::BusIO)) { - pins.push_back(test_framework.get_increment_pin(TestFramework::BusIO).pin); - } else { - pins.push_back((PinName)NC); - } + std::vector pins; // vector of pins that the bus will contain + while(pins.size() < BUS_SIZE){ // continually add pins until the bus is full + // check if more pins are available to add to bus + if(TestFramework::check_size(TestFramework::BusIO)) { + // fetch new pin + PinMap newPin = test_framework.get_increment_pin(TestFramework::BusIO); + + // ensure new pin is not already assigned to another peripheral + if((newPin.pin != USBTX) && (newPin.pin != USBRX)){ + pins.push_back(newPin.pin); // add pin to bus + } + } + + // if no more suitable pins are available, then add No-Connects until bus is full + else{ + pins.push_back((PinName)NC); + } } - 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]); + 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]); + + // 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); } From 285d38579ca7104b4775d6a439ecab08c5336d5a Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Fri, 7 Jul 2017 14:20:06 -0500 Subject: [PATCH 26/28] Modified TestFramework::map_pins so that it no longer adds pins if they are already assigned to the USB_UART. I check here now instead of the individual tests since we should never be reassigning the USB_UART pins in any test --- TESTS/Level0/AnalogIn/AnalogIn.cpp | 8 +++----- TESTS/Level0/BusInOut/BusInOut.cpp | 9 ++------- TestFramework.cpp | 11 ++++++----- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/TESTS/Level0/AnalogIn/AnalogIn.cpp b/TESTS/Level0/AnalogIn/AnalogIn.cpp index 4bccc66..82d62cd 100644 --- a/TESTS/Level0/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level0/AnalogIn/AnalogIn.cpp @@ -40,12 +40,10 @@ TestFramework test_framework; utest::v1::control_t test_level0_analogin(const size_t call_count) { PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogInput); - if(pin.pin != USBTX && pin.pin != USBRX){ // make sure pin is not already being used - DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin.pin); - TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); + DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin.pin); + TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC"); - AnalogIn ain(pin.pin); - } + AnalogIn ain(pin.pin); return test_framework.reset_iterator(TestFramework::AnalogInput); } diff --git a/TESTS/Level0/BusInOut/BusInOut.cpp b/TESTS/Level0/BusInOut/BusInOut.cpp index 831b8b1..cf61a5c 100644 --- a/TESTS/Level0/BusInOut/BusInOut.cpp +++ b/TESTS/Level0/BusInOut/BusInOut.cpp @@ -44,13 +44,8 @@ utest::v1::control_t test_level0_businout(const size_t call_count) { // check if more pins are available to add to bus if(TestFramework::check_size(TestFramework::BusIO)) { // fetch new pin - PinMap newPin = test_framework.get_increment_pin(TestFramework::BusIO); - - // ensure new pin is not already assigned to another peripheral - if((newPin.pin != USBTX) && (newPin.pin != USBRX)){ - pins.push_back(newPin.pin); // add pin to bus - } - } + 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{ diff --git a/TestFramework.cpp b/TestFramework.cpp index aa422b7..4dd6075 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -85,7 +85,8 @@ void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { if (pinout[pintype][j].pin == pinmap[i].pin) alreadyExists = true; } - if (!alreadyExists) { + // 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]); } i++; @@ -215,16 +216,16 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, if (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) && (CLK.pin != USBTX) && (CLK.pin != USBRX)){ + 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) && (MISO.pin != USBTX) && (MISO.pin != USBRX)){ + 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) && (MOSI.pin != USBTX) && (MOSI.pin != USBRX)){ + 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) && (CS.pin != USBTX) && (CS.pin != USBRX)){ + 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); From 3053b8d4c6f9fbe861ca11ac26c32038a01891be Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Tue, 11 Jul 2017 10:51:53 -0500 Subject: [PATCH 27/28] Condensed code in TestFramework for level1 testing --- TestFramework.cpp | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/TestFramework.cpp b/TestFramework.cpp index 4dd6075..d514827 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -20,7 +20,6 @@ /*///////////////////////////////////////////////////////////////////////////// // Initialization // /////////////////////////////////////////////////////////////////////////////*/ - TestFramework::TestFramework() { map_pins(PinMap_ADC, AnalogInput); map_pins(PinMap_DAC, AnalogOutput); @@ -44,6 +43,7 @@ TestFramework::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)); @@ -72,11 +72,13 @@ void TestFramework::setup_cits_pins() { pinout[CITS_SPI_CS].push_back(construct_pinmap(MBED_CONF_APP_SPI_CS)); } + 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) { @@ -93,14 +95,19 @@ void TestFramework::map_pins(const PinMap pinmap[], Type pintype) { } } + int TestFramework::find_pin(PinName pin, Type pintype) { + // scan through all pins of specified type looking for a match for (unsigned int i=0; i 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) { return resistor_ladder_pins; } + unsigned int TestFramework::get_seed() { // Send key value pair to greentea host tests greentea_send_kv("return_rand", "seed"); @@ -153,6 +165,7 @@ unsigned int TestFramework::get_seed() { return seed; } + /*///////////////////////////////////////////////////////////////////////////// // level0 // // // @@ -161,7 +174,6 @@ unsigned int TestFramework::get_seed() { // digital io, SPI), gets tested regardless of if it is connected to the CI // // test shield. // /////////////////////////////////////////////////////////////////////////////*/ - 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) @@ -262,6 +274,7 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, return utest::v1::CaseNext; } + /*///////////////////////////////////////////////////////////////////////////// // level1 // // // @@ -272,39 +285,28 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, // is found, it runs the callback passed in. Note that 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) { - // 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 - int index = find_pin(pin, testtype); - // State: Execute - if (index != -1) { - // Current pin was mapped to the CI test shield so run the callback and reset the iterator - execution_callback(pin, floatdata, intdata); - pin_iterators[pintype] = 0; - return utest::v1::CaseNext; - } - while (check_size(pintype)) { - // 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 - index = find_pin(pin, testtype); + while(check_size(pintype)) { + // Get current pin specified by the stored iterator + PinName pin = pinout[pintype][pin_iterators[pintype]].pin; + DEBUG_PRINTF("In while loop pin %d\n", pin); - if (index != -1) { - // State: Execute - // Pin was found, so execute the callback and end the test case. Make sure to reset the iterator - execution_callback(pin, floatdata, intdata); - pin_iterators[pintype] = 0; - return utest::v1::CaseNext; - } - } - // State: End test - // All pins have been identified and run, reset the iterators and return back - return reset_iterator(pintype); + // Check to see if that 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 // // // @@ -313,7 +315,6 @@ utest::v1::control_t TestFramework::test_level1_framework(Type pintype, Type tes // just a single pin) is tested. In addition, the tolerance and iterations // // 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) { // Get current pin specified by the stored iterator PinName pin = pinout[pintype][pin_iterators[pintype]].pin; From 9919bb115efc23af3e8f6c5f8f337eff28e65177 Mon Sep 17 00:00:00 2001 From: brandonboesch Date: Wed, 12 Jul 2017 12:48:44 -0500 Subject: [PATCH 28/28] Removed wait() from Level0-spi test, and changed timeout value. Added DebugPrintf to Level1-AnalogIn. Uncommented line in constructor so that more spi pins get added to DIO map. --- TESTS/Level0/SPI/SPI.cpp | 3 +- TESTS/Level1/AnalogIn/AnalogIn.cpp | 4 ++ TestFramework.cpp | 71 ++++++++++++++---------------- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/TESTS/Level0/SPI/SPI.cpp b/TESTS/Level0/SPI/SPI.cpp index b8764dc..27d907f 100644 --- a/TESTS/Level0/SPI/SPI.cpp +++ b/TESTS/Level0/SPI/SPI.cpp @@ -40,7 +40,6 @@ 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); - wait(0.1); // Make sure system has time to print above message in case of error 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"); @@ -60,6 +59,6 @@ Case cases[] = { int main() { // Formulate a specification and run the tests based on the Case array - Specification specification(TestFramework::test_setup<120>, cases); + Specification specification(TestFramework::test_setup<60>, cases); return !Harness::run(specification); } diff --git a/TESTS/Level1/AnalogIn/AnalogIn.cpp b/TESTS/Level1/AnalogIn/AnalogIn.cpp index a287ce9..13718b2 100644 --- a/TESTS/Level1/AnalogIn/AnalogIn.cpp +++ b/TESTS/Level1/AnalogIn/AnalogIn.cpp @@ -51,6 +51,9 @@ 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]); + + // 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 diff --git a/TestFramework.cpp b/TestFramework.cpp index d514827..89ebe3e 100644 --- a/TestFramework.cpp +++ b/TestFramework.cpp @@ -25,12 +25,12 @@ TestFramework::TestFramework() { map_pins(PinMap_DAC, AnalogOutput); map_pins(PinMap_PWM, DigitalIO); map_pins(PinMap_ADC, DigitalIO); - // map_pins(PinMap_DAC, 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_MISO, DigitalIO); map_pins(PinMap_SPI_SSEL, DigitalIO); pinout[BusIO] = pinout[DigitalIO]; map_pins(PinMap_PWM, PWM); @@ -203,7 +203,7 @@ 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; + bool tag = false; // determines if execution_callback() was ran // Iterate through all CLK pins, finding the remaining SPI pins that have matching HW blocks while (pin_iterators[SPI_CLK] < pinout[SPI_CLK].size()) { @@ -223,30 +223,26 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, 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) { - if (MOSI.peripheral == CLK.peripheral) { - if (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; - } - } - } + 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 @@ -275,23 +271,22 @@ utest::v1::control_t TestFramework::run_spi(void (*execution_callback)(PinName, } -/*///////////////////////////////////////////////////////////////////////////// -// 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 to find pins 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. // -/////////////////////////////////////////////////////////////////////////////*/ +/*////////////////////////////////////////////////////////////////////////////// +// 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. // +//////////////////////////////////////////////////////////////////////////////*/ 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; - DEBUG_PRINTF("In while loop pin %d\n", pin); - // Check to see if that current pin is available on the CI test shield + // 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