Skip to content

Commit 85566ed

Browse files
authored
Test uniformity (speeduino#1352)
* Protect redefinition of _countof() * Rename unit test file. * Reorder test code to remove unnecessary #includes * Tests: remove forward declare headers * Follow convention - rename main test files "main.cpp" * Prevent division by zero when staging is enabled. * Put common device test code into device_test_harness.h * Tests wait for Serial monitor to connect instead of 2s delay * Explicitly set the half-sync flag (tests fail on native platform) * Prevent buffer overflow - increase size of buffer
1 parent dbc2497 commit 85566ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+214
-483
lines changed

speeduino/utilities.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ int16_t ProgrammableIOGetData(uint16_t index);
4141
#define UNUSED(x) (void)(x)
4242
#endif
4343

44+
#if !defined(_countof)
4445
#define _countof(x) (sizeof(x) / sizeof (x[0]))
46+
#endif
4547
#define _end_range_address(array) (array + _countof(array))
4648
#define _end_range_byte_address(array) (((byte*)array) + sizeof(array))
4749

Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
1-
#include <Arduino.h>
2-
#include <unity.h>
3-
#include <avr/sleep.h>
4-
5-
#define UNITY_EXCLUDE_DETAILS
1+
#pragma once
62

7-
extern void test_calculateSecondaryFuel(void);
8-
extern void test_calculateSecondarySpark(void);
3+
#if !defined(NATIVE_BOARD)
94

5+
#include <unity.h>
6+
#include <Arduino.h>
7+
#if defined(SIMULATOR)
8+
#include <avr/sleep.h>
9+
#endif
1010

11-
void setup()
11+
void setup(void (*runAllTests)(void))
1212
{
1313
pinMode(LED_BUILTIN, OUTPUT);
1414

15-
// NOTE!!! Wait for >2 secs
16-
// if board doesn't support software reset via Serial.DTR/RTS
17-
#if !defined(SIMULATOR)
18-
delay(2000);
19-
#endif
15+
// Wait for Serial Monitor connection
16+
while (!Serial) {
17+
;
18+
}
2019

2120
UNITY_BEGIN(); // IMPORTANT LINE!
2221

23-
test_calculateSecondaryFuel();
24-
test_calculateSecondarySpark();
22+
runAllTests();
2523

2624
UNITY_END(); // stop unit testing
2725

2826
#if defined(SIMULATOR) // Tell SimAVR we are done
2927
cli();
3028
sleep_enable();
3129
sleep_cpu();
32-
#endif
30+
#endif
31+
}
32+
33+
#define DEVICE_TEST(testRunner) \
34+
void setup() \
35+
{ \
36+
setup(testRunner); \
3337
}
3438

3539
void loop()
@@ -39,4 +43,7 @@ void loop()
3943
delay(250);
4044
digitalWrite(LED_BUILTIN, LOW);
4145
delay(250);
42-
}
46+
}
47+
#else
48+
#define DEVICE_TEST(testRunner)
49+
#endif

test/test_decoders/FordST170/ForsdST170.cpp renamed to test/test_decoders/FordST170/FordST170.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <decoders.h>
22
#include <globals.h>
33
#include <unity.h>
4-
#include "FordST170.h"
54
#include "scheduler.h"
65
#include "schedule_calcs.h"
76
#include "../../test_utils.h"

test/test_decoders/FordST170/FordST170.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_decoders/NGC/test_ngc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <decoders.h>
22
#include <globals.h>
33
#include <unity.h>
4-
#include "test_ngc.h"
54
#include "scheduler.h"
65
#include "schedule_calcs.h"
76
#include "../../test_utils.h"

test/test_decoders/NGC/test_ngc.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_decoders/Nissan360/Nissan360.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <decoders.h>
22
#include <globals.h>
33
#include <unity.h>
4-
#include "Nissan360.h"
54
#include "scheduler.h"
65
#include "schedule_calcs.h"
76
#include "../../test_utils.h"

test/test_decoders/Nissan360/Nissan360.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_decoders/SuzukiK6A/SuzukiK6A.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/test_decoders/dual_wheel/dual_wheel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <decoders.h>
22
#include <globals.h>
33
#include <unity.h>
4-
#include "dual_wheel.h"
54
#include "schedule_calcs.h"
65
#include "../../test_utils.h"
76

0 commit comments

Comments
 (0)