diff --git a/.travis.yml b/.travis.yml index 2d3743a8..b694caf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,7 +70,7 @@ script: curl --tlsv1.2 --ipv4 --user "speeduino_firmware@speeduino.com:$WEB_PWD" --basic -T "./reference/speeduino.ini" "https://speeduino.com:2078/master.ini" fi # Run the remote unit tests (only on master) - - 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then platformio remote test --environment megaatmega2560; fi' + - 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then platformio remote test --force-remote --environment megaatmega2560; fi' #Build the doxygen documentation and commit to its repo (Only on master) - | if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then diff --git a/speeduino/decoders.ino b/speeduino/decoders.ino index f8ccea40..ec5261f9 100644 --- a/speeduino/decoders.ino +++ b/speeduino/decoders.ino @@ -3810,7 +3810,7 @@ void triggerSec_Webber() } else { - if ( (toothCurrentCount != (configPage4.triggerTeeth-1)) && (currentStatus.startRevolutions > 2)) { currentStatus.syncLossCounter++; } //Indicates likely sync loss. + if ( (toothCurrentCount != (configPage4.triggerTeeth-1U)) && (currentStatus.startRevolutions > 2U)) { currentStatus.syncLossCounter++; } //Indicates likely sync loss. if (configPage4.useResync == 1) { toothCurrentCount = configPage4.triggerTeeth-1; } } revolutionOne = 1; //Sequential revolution reset diff --git a/speeduino/logger.h b/speeduino/logger.h index c9cb14c0..ea3e4d3a 100644 --- a/speeduino/logger.h +++ b/speeduino/logger.h @@ -9,8 +9,13 @@ #ifndef LOGGER_H #define LOGGER_H -#define LOG_ENTRY_SIZE 117 /**< The size of the live data packet. This MUST match ochBlockSize setting in the ini file */ -#define SD_LOG_ENTRY_SIZE 117 /**< The size of the live data packet used by the SD car.*/ +#ifndef UNIT_TEST // Scope guard for unit testing + #define LOG_ENTRY_SIZE 117 /**< The size of the live data packet. This MUST match ochBlockSize setting in the ini file */ + #define SD_LOG_ENTRY_SIZE 117 /**< The size of the live data packet used by the SD car.*/ +#else + #define LOG_ENTRY_SIZE 1 /**< The size of the live data packet. This MUST match ochBlockSize setting in the ini file */ + #define SD_LOG_ENTRY_SIZE 1 /**< The size of the live data packet used by the SD car.*/ +#endif void createLog(uint8_t *array); void createSDLog(uint8_t *array); diff --git a/test/tests/test_decoders/dual_wheel/dual_wheel.cpp b/test/test_decoders/dual_wheel/dual_wheel.cpp similarity index 100% rename from test/tests/test_decoders/dual_wheel/dual_wheel.cpp rename to test/test_decoders/dual_wheel/dual_wheel.cpp diff --git a/test/tests/test_decoders/dual_wheel/dual_wheel.h b/test/test_decoders/dual_wheel/dual_wheel.h similarity index 100% rename from test/tests/test_decoders/dual_wheel/dual_wheel.h rename to test/test_decoders/dual_wheel/dual_wheel.h diff --git a/test/tests/test_decoders/missing_tooth/missing_tooth.cpp b/test/test_decoders/missing_tooth/missing_tooth.cpp similarity index 100% rename from test/tests/test_decoders/missing_tooth/missing_tooth.cpp rename to test/test_decoders/missing_tooth/missing_tooth.cpp diff --git a/test/tests/test_decoders/missing_tooth/missing_tooth.h b/test/test_decoders/missing_tooth/missing_tooth.h similarity index 100% rename from test/tests/test_decoders/missing_tooth/missing_tooth.h rename to test/test_decoders/missing_tooth/missing_tooth.h diff --git a/test/test_decoders/test_decoders.cpp b/test/test_decoders/test_decoders.cpp new file mode 100644 index 00000000..109426c8 --- /dev/null +++ b/test/test_decoders/test_decoders.cpp @@ -0,0 +1,31 @@ + +#include +#include + +#include "missing_tooth/missing_tooth.h" +#include "dual_wheel/dual_wheel.h" + +void setup() +{ + pinMode(LED_BUILTIN, OUTPUT); + + // NOTE!!! Wait for >2 secs + // if board doesn't support software reset via Serial.DTR/RTS + delay(2000); + + UNITY_BEGIN(); // IMPORTANT LINE! + + testMissingTooth(); + testDualWheel(); + + UNITY_END(); // stop unit testing +} + +void loop() +{ + // Blink to indicate end of test + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + digitalWrite(LED_BUILTIN, LOW); + delay(250); +} \ No newline at end of file diff --git a/test/tests/test_misc/test_PW.cpp b/test/test_misc/test_PW.cpp similarity index 100% rename from test/tests/test_misc/test_PW.cpp rename to test/test_misc/test_PW.cpp diff --git a/test/tests/test_misc/tests_PW.h b/test/test_misc/tests_PW.h similarity index 100% rename from test/tests/test_misc/tests_PW.h rename to test/test_misc/tests_PW.h diff --git a/test/tests/test_misc/tests_corrections.cpp b/test/test_misc/tests_corrections.cpp similarity index 98% rename from test/tests/test_misc/tests_corrections.cpp rename to test/test_misc/tests_corrections.cpp index 76091414..3e7c7756 100644 --- a/test/tests/test_misc/tests_corrections.cpp +++ b/test/test_misc/tests_corrections.cpp @@ -172,8 +172,8 @@ void test_corrections_dfco_off_delay() //The steup function below simulates a 2 second delay setup_DFCO_on(); - //Set the threshold to be 3 seconds, above the simulated delay of 2s - configPage2.dfcoDelay = 300; + //Set the threshold to be 2.5 seconds, above the simulated delay of 2s + configPage2.dfcoDelay = 250; TEST_ASSERT_FALSE(correctionDFCO()); //Make sure DFCO does not come on } diff --git a/test/tests/test_misc/tests_corrections.h b/test/test_misc/tests_corrections.h similarity index 100% rename from test/tests/test_misc/tests_corrections.h rename to test/test_misc/tests_corrections.h diff --git a/test/test_misc/tests_init.cpp b/test/test_misc/tests_init.cpp new file mode 100644 index 00000000..ad14fce1 --- /dev/null +++ b/test/test_misc/tests_init.cpp @@ -0,0 +1,117 @@ +#include +#include +#include +#include "tests_init.h" + + +void testInitialisation() +{ + RUN_TEST(test_initialisation_complete); + RUN_TEST(test_initialisation_ports); + RUN_TEST(test_initialisation_outputs_V03); + RUN_TEST(test_initialisation_outputs_MX5_8995); +} + +void test_initialisation_complete(void) +{ + initialiseAll(); //Run the main initialise function + TEST_ASSERT_EQUAL(true, initialisationComplete); +} + +void test_initialisation_ports(void) +{ + //Test that all the port values have been set + initialiseAll(); //Run the main initialise function + TEST_ASSERT_NOT_EQUAL(0, inj1_pin_port); + TEST_ASSERT_NOT_EQUAL(0, inj2_pin_port); + TEST_ASSERT_NOT_EQUAL(0, inj3_pin_port); + TEST_ASSERT_NOT_EQUAL(0, inj4_pin_port); + TEST_ASSERT_NOT_EQUAL(0, ign1_pin_port); + TEST_ASSERT_NOT_EQUAL(0, ign2_pin_port); + TEST_ASSERT_NOT_EQUAL(0, ign3_pin_port); + TEST_ASSERT_NOT_EQUAL(0, ign4_pin_port); +} + +//Test that all mandatory output pins have their mode correctly set to output +void test_initialisation_outputs_V03(void) +{ + configPage2.pinMapping = 2; //Set the board number to test + initialiseAll(); //Run the main initialise function + + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil1), "Coil1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil2), "Coil2"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil3), "Coil3"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil4), "Coil4"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector1), "Injector 1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector2), "Injector 2"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector3), "Injector 3"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector4), "Injector 4"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinTachOut), "Tacho Out"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinIdle1), "Idle 1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinIdle2), "Idle 2"); + //if(configPage2.idleUpOutputEnabled) { TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinIdleUpOutput), "Idle Up"); } //This needs to have a default pin set + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinFuelPump), "Fuel Pump"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinFan), "Fan"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinStepperDir), "Stepper Dir"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinStepperStep), "Stepper Step"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinStepperEnable), "Stepper Enable"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinBoost), "Boost"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinVVT_1), "VVT1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinVVT_2), "VVT2"); + +} + +//Test that all mandatory output pins have their mode correctly set to output +void test_initialisation_outputs_MX5_8995(void) +{ + configPage2.pinMapping = 9; //Set the board number to test + initialiseAll(); //Run the main initialise function + + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil1), "Coil1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil2), "Coil2"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil3), "Coil3"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinCoil4), "Coil4"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector1), "Injector 1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector2), "Injector 2"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector3), "Injector 3"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinInjector4), "Injector 4"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinTachOut), "Tacho Out"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinIdle1), "Idle 1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinIdle2), "Idle 2"); + //if(configPage2.idleUpOutputEnabled) { TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinIdleUpOutput), "Idle Up"); } //This needs to have a default pin set + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinFuelPump), "Fuel Pump"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinFan), "Fan"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinStepperDir), "Stepper Dir"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinStepperStep), "Stepper Step"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinStepperEnable), "Stepper Enable"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinBoost), "Boost"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinVVT_1), "VVT1"); + TEST_ASSERT_EQUAL_MESSAGE(OUTPUT, getPinMode(pinVVT_2), "VVT2"); + +} + +uint8_t getPinMode(uint8_t pin) +{ + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + + // I don't see an option for mega to return this, but whatever... + if (NOT_A_PIN == port) return UNKNOWN_PIN; + + // Is there a bit we can check? + if (0 == bit) return UNKNOWN_PIN; + + // Is there only a single bit set? + if (bit & (bit - 1)) return UNKNOWN_PIN; + + volatile uint8_t *reg, *out; + reg = portModeRegister(port); + out = portOutputRegister(port); + + if (*reg & bit) + return OUTPUT; + else if (*out & bit) + return INPUT_PULLUP; + else + return INPUT; +} \ No newline at end of file diff --git a/test/test_misc/tests_init.h b/test/test_misc/tests_init.h new file mode 100644 index 00000000..3155d3d7 --- /dev/null +++ b/test/test_misc/tests_init.h @@ -0,0 +1,8 @@ +#define UNKNOWN_PIN 0xFF + +extern void testInitialisation(); +void test_initialisation_complete(void); +void test_initialisation_ports(void); +void test_initialisation_outputs_V03(void); +void test_initialisation_outputs_MX5_8995(void); +uint8_t getPinMode(uint8_t); \ No newline at end of file diff --git a/test/tests/tests_main.cpp b/test/test_misc/tests_misc.cpp similarity index 60% rename from test/tests/tests_main.cpp rename to test/test_misc/tests_misc.cpp index 535983d0..7be3c232 100644 --- a/test/tests/tests_main.cpp +++ b/test/test_misc/tests_misc.cpp @@ -1,23 +1,12 @@ #include #include -#include "test_misc/tests_corrections.h" -#include "test_misc/tests_init.h" -#include "test_misc/tests_tables.h" -#include "test_misc/tests_PW.h" -#include "test_schedules/test_schedules.h" -#include "test_decoders/test_decoders.h" +#include "tests_corrections.h" +#include "tests_init.h" +#include "tests_tables.h" +#include "tests_PW.h" - -void doTests() -{ - testInitialisation(); - testCorrections(); - testPW(); - //testSchedules(); //This is currently causing issues - testDecoders(); - testTables(); -} +#define UNITY_EXCLUDE_DETAILS void setup() { @@ -29,7 +18,10 @@ void setup() UNITY_BEGIN(); // IMPORTANT LINE! - doTests(); + testInitialisation(); + testCorrections(); + testPW(); + testTables(); UNITY_END(); // stop unit testing } diff --git a/test/tests/test_misc/tests_tables.cpp b/test/test_misc/tests_tables.cpp similarity index 100% rename from test/tests/test_misc/tests_tables.cpp rename to test/test_misc/tests_tables.cpp diff --git a/test/tests/test_misc/tests_tables.h b/test/test_misc/tests_tables.h similarity index 100% rename from test/tests/test_misc/tests_tables.h rename to test/test_misc/tests_tables.h diff --git a/test/tests/test_schedules/test_accuracy_duration.cpp b/test/test_schedules/test_accuracy_duration.cpp similarity index 100% rename from test/tests/test_schedules/test_accuracy_duration.cpp rename to test/test_schedules/test_accuracy_duration.cpp diff --git a/test/tests/test_schedules/test_accuracy_timeout.cpp b/test/test_schedules/test_accuracy_timeout.cpp similarity index 100% rename from test/tests/test_schedules/test_accuracy_timeout.cpp rename to test/test_schedules/test_accuracy_timeout.cpp diff --git a/test/test_schedules/test_schedules.cpp b/test/test_schedules/test_schedules.cpp new file mode 100644 index 00000000..3ef9304a --- /dev/null +++ b/test/test_schedules/test_schedules.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +#include "test_schedules.h" + +void setup() +{ + pinMode(LED_BUILTIN, OUTPUT); + delay(2000); + + UNITY_BEGIN(); // start unit testing + + initialiseAll(); //Run the main initialise function + test_status_initial_off(); + //test_status_off_to_pending(); + //test_status_pending_to_running(); + //test_status_running_to_pending(); + //test_status_running_to_off(); + test_accuracy_timeout(); + test_accuracy_duration(); + + UNITY_END(); // stop unit testing + +} + +void loop() +{ + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + digitalWrite(LED_BUILTIN, LOW); + delay(250); +} \ No newline at end of file diff --git a/test/tests/test_schedules/test_schedules.h b/test/test_schedules/test_schedules.h similarity index 100% rename from test/tests/test_schedules/test_schedules.h rename to test/test_schedules/test_schedules.h diff --git a/test/tests/test_schedules/test_status_initial_off.cpp b/test/test_schedules/test_status_initial_off.cpp similarity index 100% rename from test/tests/test_schedules/test_status_initial_off.cpp rename to test/test_schedules/test_status_initial_off.cpp diff --git a/test/tests/test_schedules/test_status_off_to_pending.cpp b/test/test_schedules/test_status_off_to_pending.cpp similarity index 100% rename from test/tests/test_schedules/test_status_off_to_pending.cpp rename to test/test_schedules/test_status_off_to_pending.cpp diff --git a/test/tests/test_schedules/test_status_pending_to_running.cpp b/test/test_schedules/test_status_pending_to_running.cpp similarity index 100% rename from test/tests/test_schedules/test_status_pending_to_running.cpp rename to test/test_schedules/test_status_pending_to_running.cpp diff --git a/test/tests/test_schedules/test_status_running_to_off.cpp b/test/test_schedules/test_status_running_to_off.cpp similarity index 100% rename from test/tests/test_schedules/test_status_running_to_off.cpp rename to test/test_schedules/test_status_running_to_off.cpp diff --git a/test/tests/test_schedules/test_status_running_to_pending.cpp b/test/test_schedules/test_status_running_to_pending.cpp similarity index 100% rename from test/tests/test_schedules/test_status_running_to_pending.cpp rename to test/test_schedules/test_status_running_to_pending.cpp diff --git a/test/tests/test_decoders/test_decoders.cpp b/test/tests/test_decoders/test_decoders.cpp deleted file mode 100644 index 91899c0c..00000000 --- a/test/tests/test_decoders/test_decoders.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include -#include - -#include "test_decoders.h" -#include "missing_tooth/missing_tooth.h" -#include "dual_wheel/dual_wheel.h" - -void testDecoders() -{ - testMissingTooth(); - testDualWheel(); -} \ No newline at end of file diff --git a/test/tests/test_decoders/test_decoders.h b/test/tests/test_decoders/test_decoders.h deleted file mode 100644 index d0baa1cb..00000000 --- a/test/tests/test_decoders/test_decoders.h +++ /dev/null @@ -1,6 +0,0 @@ -#if !defined(__TEST_DECODERS_H__) -#define __TEST_DECODERS_H__ - -void testDecoders(); - -#endif // __TEST_DECODERS_H__ \ No newline at end of file diff --git a/test/tests/test_misc/tests_init.cpp b/test/tests/test_misc/tests_init.cpp deleted file mode 100644 index ae3eb94f..00000000 --- a/test/tests/test_misc/tests_init.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include "tests_init.h" - - -void testInitialisation() -{ - RUN_TEST(test_initialisation_complete); - RUN_TEST(test_initialisation_ports); -} - -void test_initialisation_complete(void) -{ - initialiseAll(); //Run the main initialise function - TEST_ASSERT_EQUAL(true, initialisationComplete); -} - -void test_initialisation_ports(void) -{ - //Test that all the port values have been set - initialiseAll(); //Run the main initialise function - TEST_ASSERT_NOT_EQUAL(0, inj1_pin_port); - TEST_ASSERT_NOT_EQUAL(0, inj2_pin_port); - TEST_ASSERT_NOT_EQUAL(0, inj3_pin_port); - TEST_ASSERT_NOT_EQUAL(0, inj4_pin_port); - TEST_ASSERT_NOT_EQUAL(0, ign1_pin_port); - TEST_ASSERT_NOT_EQUAL(0, ign2_pin_port); - TEST_ASSERT_NOT_EQUAL(0, ign3_pin_port); - TEST_ASSERT_NOT_EQUAL(0, ign4_pin_port); -} \ No newline at end of file diff --git a/test/tests/test_misc/tests_init.h b/test/tests/test_misc/tests_init.h deleted file mode 100644 index 0ed14015..00000000 --- a/test/tests/test_misc/tests_init.h +++ /dev/null @@ -1,3 +0,0 @@ -extern void testInitialisation(); -void test_initialisation_complete(void); -void test_initialisation_ports(void); \ No newline at end of file diff --git a/test/tests/test_schedules/test_schedules.cpp b/test/tests/test_schedules/test_schedules.cpp deleted file mode 100644 index 1016ab87..00000000 --- a/test/tests/test_schedules/test_schedules.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include - -#include "test_schedules.h" -#include "globals.h" -/* -void two_second_blink() -{ - // NOTE!!! Wait for >2 secs - // if board doesn't support software reset via Serial.DTR/RTS - - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); - delay(667); - digitalWrite(LED_BUILTIN, LOW); - delay(667); - digitalWrite(LED_BUILTIN, HIGH); - delay(667); - digitalWrite(LED_BUILTIN, LOW); - -void test_schedules() -{ - test_status_initial_off(); - test_status_off_to_pending(); - test_status_pending_to_running(); - test_status_running_to_pending(); - test_status_running_to_off(); - - test_accuracy_timeout(); - test_accuracy_duration(); -} - -void setup() -{ - initBoard(); // Not using initialiseAll() as it will cause memory overflow - - two_second_blink(); // Very important line - - UNITY_BEGIN(); // start unit testing - - do_tests(); - - UNITY_END(); // stop unit testing - - pinMode(LED_BUILTIN, OUTPUT); -} - -void loop() -{ - digitalWrite(LED_BUILTIN, HIGH); - delay(250); - digitalWrite(LED_BUILTIN, LOW); - delay(250); -} -*/ -void testSchedules() -{ - - test_status_initial_off(); - test_status_off_to_pending(); - test_status_pending_to_running(); - test_status_running_to_pending(); - - TEST_ASSERT_GREATER_THAN(freeRam(), 100); - test_status_running_to_off(); - - test_accuracy_timeout(); - test_accuracy_duration(); -} \ No newline at end of file