Unit Tests: provide correct filename in test messages (#1211)

* Make Unity print the correct file name - VS code output will then provide a clickable link :-)

* Provide macro to save, set & restore Unity filename
This commit is contained in:
tx_haggis 2024-05-29 00:27:50 -05:00 committed by GitHub
parent 40463c51d6
commit cb78a45326
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 126 additions and 9 deletions

View File

@ -4,6 +4,7 @@
#include "FordST170.h"
#include "scheduler.h"
#include "schedule_calcs.h"
#include "../../test_utils.h"
extern uint16_t ignition1EndTooth;
extern uint16_t ignition2EndTooth;
@ -159,6 +160,8 @@ void test_fordst170_newIgn_12_trigNeg360_1()
void testFordST170()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_fordst170_newIgn_12_trig0_1);
RUN_TEST(test_fordst170_newIgn_12_trig90_1);
RUN_TEST(test_fordst170_newIgn_12_trig180_1);
@ -168,4 +171,6 @@ void testFordST170()
RUN_TEST(test_fordst170_newIgn_12_trigNeg180_1);
RUN_TEST(test_fordst170_newIgn_12_trigNeg270_1);
RUN_TEST(test_fordst170_newIgn_12_trigNeg360_1);
}
}

View File

@ -4,6 +4,7 @@
#include "test_ngc.h"
#include "scheduler.h"
#include "schedule_calcs.h"
#include "../../test_utils.h"
extern uint16_t ignition1EndTooth;
extern uint16_t ignition2EndTooth;
@ -133,6 +134,8 @@ void test_ngc_newIgn_12_trigNeg360_1()
void testNGC()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_ngc_newIgn_12_trig0_1);
RUN_TEST(test_ngc_newIgn_12_trig90_1);
RUN_TEST(test_ngc_newIgn_12_trig180_1);
@ -143,3 +146,4 @@ void testNGC()
RUN_TEST(test_ngc_newIgn_12_trigNeg270_1);
RUN_TEST(test_ngc_newIgn_12_trigNeg360_1);
}
}

View File

@ -4,6 +4,7 @@
#include "Nissan360.h"
#include "scheduler.h"
#include "schedule_calcs.h"
#include "../../test_utils.h"
extern uint16_t ignition1EndTooth;
extern uint16_t ignition2EndTooth;
@ -157,6 +158,9 @@ void test_nissan360_newIgn_12_trigNeg360_1()
void testNissan360()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_nissan360_newIgn_12_trig0_1);
RUN_TEST(test_nissan360_newIgn_12_trig90_1);
RUN_TEST(test_nissan360_newIgn_12_trig180_1);
@ -167,3 +171,4 @@ void testNissan360()
RUN_TEST(test_nissan360_newIgn_12_trigNeg270_1);
RUN_TEST(test_nissan360_newIgn_12_trigNeg360_1);
}
}

View File

@ -3,6 +3,7 @@
#include <unity.h>
#include "dual_wheel.h"
#include "schedule_calcs.h"
#include "../../test_utils.h"
void test_setup_dualwheel_12_1()
@ -324,6 +325,8 @@ void test_dualwheel_newIgn_4()
void testDualWheel()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_dualwheel_newIgn_12_1_trig0_1);
RUN_TEST(test_dualwheel_newIgn_12_1_trig90_1);
RUN_TEST(test_dualwheel_newIgn_12_1_trig180_1);
@ -347,4 +350,6 @@ void testDualWheel()
*/
//RUN_TEST(test_dualwheel_newIgn_60_2_trig181_2);
//RUN_TEST(test_dualwheel_newIgn_60_2_trig182_2);
}
}

View File

@ -3,6 +3,7 @@
#include <unity.h>
#include "missing_tooth.h"
#include "schedule_calcs.h"
#include "../../test_utils.h"
void test_setup_36_1()
{
@ -344,6 +345,8 @@ void test_missingtooth_newIgn_4()
void testMissingTooth()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_missingtooth_newIgn_36_1_trig0_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig90_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig180_1);
@ -367,3 +370,4 @@ void testMissingTooth()
//RUN_TEST(test_missingtooth_newIgn_60_2_trig181_2);
//RUN_TEST(test_missingtooth_newIgn_60_2_trig182_2);
}
}

View File

@ -3,6 +3,7 @@
#include <unity.h>
#include "renix.h"
#include "schedule_calcs.h"
#include "../../test_utils.h"
void test_setup_renix44()
{
@ -310,6 +311,8 @@ void test_Renix_newIgn_66_trig181_2()
void testRenix()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_Renix_newIgn_44_trig0_1);
RUN_TEST(test_Renix_newIgn_44_trig90_1);
RUN_TEST(test_Renix_newIgn_44_trig180_1);
@ -332,5 +335,5 @@ void testRenix()
RUN_TEST(test_Renix_newIgn_66_trig0_2);
RUN_TEST(test_Renix_newIgn_66_trig181_2);
}
}

View File

@ -2,11 +2,14 @@
#include <speeduino.h>
#include <unity.h>
#include "test_PW.h"
#include "../test_utils.h"
#define PW_ALLOWED_ERROR 30
void testPW(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_PW_No_Multiply);
RUN_TEST(test_PW_MAP_Multiply);
RUN_TEST(test_PW_MAP_Multiply_Compatibility);
@ -17,6 +20,7 @@ void testPW(void)
RUN_TEST(test_PW_Limit_Long_Revolution);
RUN_TEST(test_PW_Limit_90pct);
}
}
int16_t REQ_FUEL;
byte VE;

View File

@ -2,10 +2,13 @@
#include <corrections.h>
#include <unity.h>
#include "test_corrections.h"
#include "../test_utils.h"
void testCorrections()
{
SET_UNITY_FILENAME() {
test_corrections_WUE();
test_corrections_dfco();
test_corrections_TAE(); //TPS based accel enrichment corrections
@ -22,6 +25,7 @@ void testCorrections()
RUN_TEST(test_corrections_dfco); //Not written yet
*/
}
}
void test_corrections_WUE_active(void)
{

View File

@ -2,9 +2,12 @@
#include <speeduino.h>
#include <unity.h>
#include "test_staging.h"
#include "../test_utils.h"
void testStaging(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_Staging_Off);
RUN_TEST(test_Staging_4cyl_Auto_Inactive);
RUN_TEST(test_Staging_4cyl_Table_Inactive);
@ -12,6 +15,7 @@ void testStaging(void)
RUN_TEST(test_Staging_4cyl_Auto_33pct);
RUN_TEST(test_Staging_4cyl_Table_50pct);
}
}
void test_Staging_setCommon()
{

View File

@ -982,6 +982,8 @@ static void test_partial_sync(void)
void testFuelScheduleInit()
{
SET_UNITY_FILENAME() {
run_1_cylinder_4stroke_tests();
run_1_cylinder_2stroke_tests();
run_2_cylinder_4stroke_tests();
@ -1000,3 +1002,4 @@ void testFuelScheduleInit()
RUN_TEST_P(test_partial_sync);
}
}

View File

@ -336,6 +336,8 @@ static void test_partial_sync(void)
void testIgnitionScheduleInit()
{
SET_UNITY_FILENAME() {
run_1_cylinder_4stroke_tests();
run_2_cylinder_4stroke_tests();
run_3_cylinder_4stroke_tests();
@ -346,3 +348,4 @@ void testIgnitionScheduleInit()
RUN_TEST_P(test_partial_sync);
}
}

View File

@ -304,6 +304,8 @@ void test_initialisation_input_user_pin_does_not_override_outputpin(void)
void testInitialisation()
{
SET_UNITY_FILENAME() {
RUN_TEST_P(test_initialisation_complete);
RUN_TEST_P(test_initialisation_ports);
RUN_TEST_P(test_initialisation_outputs_V03);
@ -317,3 +319,4 @@ void testInitialisation()
RUN_TEST_P(test_initialisation_user_pin_override_board_default);
RUN_TEST_P(test_initialisation_input_user_pin_does_not_override_outputpin);
}
}

View File

@ -3,6 +3,7 @@
#include "maths.h"
#include "crankMaths.h"
#include "../timer.hpp"
#include "../test_utils.h"
template <typename T>
@ -222,6 +223,8 @@ void test_maths_div100_s32_perf(void)
}
void testDivision(void) {
SET_UNITY_FILENAME() {
RUN_TEST(test_maths_div100_U16);
RUN_TEST(test_maths_div100_U32);
RUN_TEST(test_maths_div100_S16);
@ -233,3 +236,4 @@ void testDivision(void) {
RUN_TEST(test_maths_div100_s16_perf);
RUN_TEST(test_maths_div100_s32_perf);
}
}

View File

@ -2,6 +2,7 @@
#include "test_fp_support.h"
#include "maths.h"
#include "../timer.hpp"
#include "../test_utils.h"
static void test_percent(uint8_t percent, uint16_t value) {
assert_rounded_div((uint32_t)percent*value, 100, percentage(percent, value));
@ -107,6 +108,8 @@ void test_maths_percentage_perf(void)
void testPercent()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_maths_percent_U8);
RUN_TEST(test_maths_percent_U16);
RUN_TEST(test_maths_halfpercent_U8);
@ -114,3 +117,4 @@ void testPercent()
RUN_TEST(test_maths_halfPercentage_perf);
RUN_TEST(test_maths_percentage_perf);
}
}

View File

@ -1,6 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "schedule_calcs.h"
#include "../test_utils.h"
static void nullIgnCallback(void) {};
@ -75,7 +76,10 @@ void test_adjust_crank_angle_running()
void test_adjust_crank_angle()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_adjust_crank_angle_pending_below_minrevolutions);
RUN_TEST(test_adjust_crank_angle_pending_above_minrevolutions);
RUN_TEST(test_adjust_crank_angle_running);
}
}

View File

@ -4,6 +4,7 @@
#include "schedule_calcs.h"
#include "crankMaths.h"
#include "decoders.h"
#include "../test_utils.h"
#define _countof(x) (sizeof(x) / sizeof (x[0]))
@ -612,7 +613,10 @@ void test_rotary_channel_calcs(void)
void test_calc_ign_timeout(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_calc_ign_timeout_360);
RUN_TEST(test_calc_ign_timeout_720);
RUN_TEST(test_rotary_channel_calcs);
}
}

View File

@ -3,6 +3,7 @@
#include "test_calcs_common.h"
#include "schedule_calcs.h"
#include "crankMaths.h"
#include "../test_utils.h"
#define _countof(x) (sizeof(x) / sizeof (x[0]))
@ -279,6 +280,9 @@ static void test_calc_inj_timeout_720()
//
void test_calc_inj_timeout(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_calc_inj_timeout_360);
RUN_TEST(test_calc_inj_timeout_720);
}
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
#define TIMEOUT 1000
@ -130,6 +130,8 @@ void test_accuracy_duration_ign8(void)
void test_accuracy_duration(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_accuracy_duration_inj1);
RUN_TEST(test_accuracy_duration_inj2);
RUN_TEST(test_accuracy_duration_inj3);
@ -164,3 +166,4 @@ void test_accuracy_duration(void)
RUN_TEST(test_accuracy_duration_ign8);
#endif
}
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
#include "scheduledIO.h"
@ -133,6 +133,8 @@ void test_accuracy_timeout_ign8(void)
void test_accuracy_timeout(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_accuracy_timeout_inj1);
RUN_TEST(test_accuracy_timeout_inj2);
RUN_TEST(test_accuracy_timeout_inj3);
@ -167,3 +169,4 @@ void test_accuracy_timeout(void)
RUN_TEST(test_accuracy_timeout_ign8);
#endif
}
}

View File

@ -1,6 +1,6 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
void test_status_initial_off_inj1(void)
@ -118,6 +118,8 @@ void test_status_initial_off_ign8(void)
void test_status_initial_off(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_status_initial_off_inj1);
RUN_TEST(test_status_initial_off_inj2);
RUN_TEST(test_status_initial_off_inj3);
@ -152,3 +154,4 @@ void test_status_initial_off(void)
RUN_TEST(test_status_initial_off_ign8);
#endif
}
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
#define TIMEOUT 1000
@ -156,6 +156,8 @@ void test_status_off_to_pending_ign8(void)
void test_status_off_to_pending(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_status_off_to_pending_inj1);
RUN_TEST(test_status_off_to_pending_inj2);
RUN_TEST(test_status_off_to_pending_inj3);
@ -190,3 +192,4 @@ void test_status_off_to_pending(void)
RUN_TEST(test_status_off_to_pending_ign8);
#endif
}
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
#define TIMEOUT 1000
@ -172,6 +172,8 @@ void test_status_pending_to_running_ign8(void)
void test_status_pending_to_running(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_status_pending_to_running_inj1);
RUN_TEST(test_status_pending_to_running_inj2);
RUN_TEST(test_status_pending_to_running_inj3);
@ -190,3 +192,4 @@ void test_status_pending_to_running(void)
RUN_TEST(test_status_pending_to_running_ign7);
RUN_TEST(test_status_pending_to_running_ign8);
}
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
#define TIMEOUT 1000
@ -172,6 +172,8 @@ void test_status_running_to_off_ign8(void)
void test_status_running_to_off(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_status_running_to_off_inj1);
RUN_TEST(test_status_running_to_off_inj2);
RUN_TEST(test_status_running_to_off_inj3);
@ -190,3 +192,4 @@ void test_status_running_to_off(void)
RUN_TEST(test_status_running_to_off_ign7);
RUN_TEST(test_status_running_to_off_ign8);
}
}

View File

@ -1,7 +1,7 @@
#include <Arduino.h>
#include <unity.h>
#include "../test_utils.h"
#include "scheduler.h"
#define TIMEOUT 1000
@ -204,6 +204,8 @@ void test_status_running_to_pending_ign8(void)
void test_status_running_to_pending(void)
{
SET_UNITY_FILENAME() {
RUN_TEST(test_status_running_to_pending_inj1);
RUN_TEST(test_status_running_to_pending_inj2);
RUN_TEST(test_status_running_to_pending_inj3);
@ -222,3 +224,4 @@ void test_status_running_to_pending(void)
RUN_TEST(test_status_running_to_pending_ign7);
RUN_TEST(test_status_running_to_pending_ign8);
}
}

View File

@ -4,6 +4,7 @@
typedef uint8_t byte;
#include "test_table2d.h"
#include "table2d.h"
#include "../test_utils.h"
static constexpr uint8_t TEST_TABLE2D_SIZE = 9;
@ -147,9 +148,12 @@ void test_table2d_all_decrementing(void)
void testTable2d()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_table2dLookup_50pct);
RUN_TEST(test_table2dLookup_exactAxis);
RUN_TEST(test_table2dLookup_overMax);
RUN_TEST(test_table2dLookup_underMin);
RUN_TEST(test_table2d_all_decrementing);
}
}

View File

@ -4,6 +4,7 @@
#include <stdio.h>
#include "tests_tables.h"
#include "table3d.h"
#include "../test_utils.h"
#define _countof(x) (sizeof(x) / sizeof (x[0]))
@ -113,6 +114,8 @@ void setup_TestTable(void)
void testTables()
{
SET_UNITY_FILENAME() {
RUN_TEST(test_tableLookup_50pct);
RUN_TEST(test_tableLookup_exact1Axis);
RUN_TEST(test_tableLookup_exact2Axis);
@ -124,6 +127,7 @@ void testTables()
//RUN_TEST(test_all_incrementing);
}
}
void test_tableLookup_50pct(void)
{

View File

@ -1,6 +1,9 @@
#pragma once
#include <stdint.h>
#include <unity.h>
// Unity macro to reduce memory usage (RAM, .bss)
//
// Unity supplied RUN_TEST captures the function name
@ -16,3 +19,21 @@
strcpy_P(funcName, PSTR(#func)); \
UnityDefaultTestRun(func, funcName, __LINE__); \
}
static __inline__ uint8_t ufname_set(const char *newFName)
{
Unity.TestFile = newFName;
return 1;
}
static __inline__ void ufname_szrestore(char** __s)
{
Unity.TestFile = *__s;
__asm__ volatile ("" ::: "memory");
}
#define UNITY_FILENAME_RESTORE char* _ufname_saved \
__attribute__((__cleanup__(ufname_szrestore))) = (char*)Unity.TestFile
#define SET_UNITY_FILENAME() \
for ( UNITY_FILENAME_RESTORE, _ufname_done = ufname_set(__FILE__); \
_ufname_done; _ufname_done = 0 )