Major revamp of unit testing framework

This commit is contained in:
Josh Stewart 2020-11-19 21:38:00 +11:00
parent bccf70f445
commit fd9fa36c29
31 changed files with 209 additions and 145 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -0,0 +1,31 @@
#include <Arduino.h>
#include <unity.h>
#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);
}

View File

@ -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
}

View File

@ -0,0 +1,117 @@
#include <globals.h>
#include <init.h>
#include <unity.h>
#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;
}

View File

@ -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);

View File

@ -1,23 +1,12 @@
#include <Arduino.h>
#include <unity.h>
#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
}

View File

@ -0,0 +1,33 @@
#include <Arduino.h>
#include <unity.h>
#include <init.h>
#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);
}

View File

@ -1,13 +0,0 @@
#include <Arduino.h>
#include <unity.h>
#include "test_decoders.h"
#include "missing_tooth/missing_tooth.h"
#include "dual_wheel/dual_wheel.h"
void testDecoders()
{
testMissingTooth();
testDualWheel();
}

View File

@ -1,6 +0,0 @@
#if !defined(__TEST_DECODERS_H__)
#define __TEST_DECODERS_H__
void testDecoders();
#endif // __TEST_DECODERS_H__

View File

@ -1,31 +0,0 @@
#include <globals.h>
#include <init.h>
#include <unity.h>
#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);
}

View File

@ -1,3 +0,0 @@
extern void testInitialisation();
void test_initialisation_complete(void);
void test_initialisation_ports(void);

View File

@ -1,69 +0,0 @@
#include <Arduino.h>
#include <unity.h>
#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();
}