Skip to content

Commit 669d667

Browse files
author
dave
committed
Tests moved to IoAbstractions SimpleTest
1 parent becec52 commit 669d667

File tree

6 files changed

+31
-38
lines changed

6 files changed

+31
-38
lines changed

tests/taskMgrTests/HighThroughputTestCases.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class HighThroughputFixture : public UnitTestExecutor {
5959
// we then compare it in order, obviously millis tick slower than micros
6060
if(currentTaskMicros < prevTaskMicros && (prevTaskMicros - currentTaskMicros) > 1000) {
6161
inOrder = false;
62-
Serial.print("Failed prev "); Serial.print(prevTaskMicros);
63-
Serial.print(", current ");Serial.println(currentTaskMicros);
62+
serdebugF4("Failed prev ", prevTaskMicros, ", current ", currentTaskMicros);
6463
}
6564

6665
// get the next item and store this micros for next compare.
@@ -85,23 +84,23 @@ testF(HighThroughputFixture, taskManagerHighThroughputTest) {
8584
char slotData[32];
8685
clearCounts();
8786

88-
Serial.print("Dumping threads"); Serial.println(taskManager.checkAvailableSlots(slotData, sizeof slotData));
87+
serdebugF2("Dumping threads", taskManager.checkAvailableSlots(slotData, sizeof slotData));
8988

9089
taskManager.scheduleFixedRate(10, testCall1);
9190
taskManager.scheduleFixedRate(100, testCall2);
9291
taskManager.scheduleFixedRate(250, testCall3, TIME_MICROS);
9392
taskManager.scheduleOnce(1, testCall4, TIME_SECONDS);
9493
taskManager.scheduleOnce(10, testCall5, TIME_SECONDS);
9594

96-
Serial.print("Dumping threads"); Serial.println(taskManager.checkAvailableSlots(slotData, sizeof slotData));
95+
serdebugF2("Dumping threads", taskManager.checkAvailableSlots(slotData, sizeof slotData));
9796

9897
unsigned long start = millis();
9998
while(counts[5] < 10 && (millis() - start) < 25000) {
10099
taskManager.yieldForMicros(10000);
101100
assertTasksAreInOrder();
102101
}
103102

104-
Serial.print("Dumping threads"); Serial.println(taskManager.checkAvailableSlots(slotData, sizeof slotData));
103+
serdebugF2("Dumping threads", taskManager.checkAvailableSlots(slotData, sizeof slotData));
105104

106105
assertEquals(10, counts[5]); // should be 10 runs as it's manually repeating
107106
assertMoreThan(140, counts[1]); // should be at least 140 runs, scheduled every 100 millis,
@@ -167,7 +166,7 @@ testF(HighThroughputFixture, testCancellingsTasksWithinAnotherTask) {
167166
// in this case we dump the queue, something is wrong.
168167
if (counts[1] == storedCount1) {
169168
dumpTasks();
170-
Serial.print("Dumping threads"); Serial.println(taskManager.checkAvailableSlots(slotData, sizeof slotData));
169+
serdebugF2("Dumping threads", taskManager.checkAvailableSlots(slotData, sizeof slotData));
171170
}
172171

173172
assertNotEquals(counts[1], storedCount1);

tests/taskMgrTests/InterruptTestCases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class MockedInterruptAbstraction : public InterruptAbstraction {
4343
void intHandler(pinid_t pin) {
4444
scheduled = true;
4545
microsExecuted = micros();
46-
count++;
46+
count1++;
4747
pinNo = pin;
4848
}
4949

tests/taskMgrTests/taskManagerCoreTests.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
using namespace SimpleTest;
88

99
void dumpTasks() {
10-
Serial.println("Dumping the task queue contents");
10+
serdebugF("Dumping the task queue contents");
1111
TimerTask* task = taskManager.getFirstTask();
1212
while(task) {
13-
Serial.print(" - Task schedule "); Serial.print(task->microsFromNow());
14-
Serial.print(task->isRepeating() ? " Repeating ":" Once ");
15-
Serial.print(task->isMicrosSchedule() ? " Micros " : " Millis ");
16-
Serial.println(task->isInUse() ? " InUse":" Free");
13+
serdebugF4(" - Task schedule ", task->microsFromNow(), task->isRepeating() ? " Repeating ":" Once ", (task->isMicrosSchedule() ? " Micros " : " Millis "));
14+
serdebug(task->isInUse() ? " InUse":" Free");
1715
if(task->getNext() == task) {
18-
Serial.println("!!!Infinite loop found!!!");
16+
serdebugF("!!!Infinite loop found!!!");
1917
}
2018
task = task->getNext();
2119
}
@@ -25,12 +23,12 @@ void dumpTasks() {
2523
bool scheduled = false;
2624
bool scheduled2ndJob = false;
2725
unsigned long microsStarted = 0, microsExecuted = 0, microsExecuted2ndJob = 0;
28-
int count = 0, count2 = 0;
26+
int count1 = 0, count2 = 0;
2927
uint8_t pinNo = 0;
3028

3129
void recordingJob() {
3230
microsExecuted = micros();
33-
count++;
31+
count1++;
3432
scheduled = true;
3533
}
3634

@@ -149,7 +147,7 @@ testF(TimingHelpFixture, scheduleFixedRateTestCase) {
149147
assertMoreThan((uint32_t) 19, timeTaken);
150148

151149
// now make sure that we got in the right ball park of calls.
152-
assertMoreThan(1, count);
150+
assertMoreThan(1, count1);
153151
assertMoreThan(150, count2);
154152
}
155153

@@ -161,7 +159,7 @@ testF(TimingHelpFixture, cancellingAJobAfterCreation) {
161159
// now check the task registration in detail.
162160
assertNotEquals(taskId, TASKMGR_INVALIDID);
163161
TimerTask* task = taskManager.getFirstTask();
164-
assertNotEquals(task, NULL);
162+
assertNotEquals(task, nullptr);
165163
assertTrue(task->isMillisSchedule());
166164
assertFalse(task->isMicrosSchedule());
167165
assertMoreThan(8000UL, task->microsFromNow());

tests/taskMgrTests/taskMgrTests.ino renamed to tests/taskMgrTests/taskMgrTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
#include <Arduino.h>
2+
#include <IoAbstraction.h>
33
#include <testing/SimpleTest.h>
4-
#include <Wire.h>
54

65
using namespace SimpleTest;
76

7+
IOLOG_MBED_PORT_IF_NEEDED(USBTX, USBRX)
8+
89
void setup() {
9-
Serial.begin(115200);
10-
while (!Serial);
10+
IOLOG_START_SERIAL
1111
startTesting();
1212
}
1313

tests/taskMgrTests/test_utils.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern bool scheduled2ndJob;
1515
extern unsigned long microsStarted;
1616
extern unsigned long microsExecuted;
1717
extern unsigned long microsExecuted2ndJob;
18-
extern int count;
18+
extern int count1;
1919
extern int count2;
2020
extern uint8_t pinNo;
2121

@@ -48,7 +48,7 @@ class TimingHelpFixture : public SimpleTest::UnitTestExecutor {
4848
scheduled = scheduled2ndJob = false;
4949
microsExecuted = microsExecuted2ndJob = 0;
5050
microsStarted = micros();
51-
count = count2 = 0;
51+
count1 = count2 = 0;
5252
}
5353

5454
void assertThatTaskRunsOnTime(uint32_t minExpected, uint32_t allowanceOver) {
@@ -63,11 +63,9 @@ class TimingHelpFixture : public SimpleTest::UnitTestExecutor {
6363
assertTrue(scheduled);
6464

6565
// print information to help with diagnostics.
66-
Serial.print("Scheduled: "); Serial.print(microsStarted);
67-
Serial.print(" ExecAt: "); Serial.print(microsExecuted);
66+
serdebugF4("Scheduled: ", microsStarted, " exec:", microsExecuted);
6867
unsigned long howLong = microsExecuted - microsStarted;
69-
Serial.print(" difference "); Serial.print(howLong);
70-
Serial.print(" - expected "); Serial.println(minExpected);
68+
serdebugF4(" difference ", howLong, " expected:", minExpected);
7169

7270
// check that it has been executed within the allowable window.
7371
unsigned long minRange = (minExpected < allowanceOver) ? 0 : (minExpected - allowanceOver);
@@ -81,11 +79,9 @@ class TimingHelpFixture : public SimpleTest::UnitTestExecutor {
8179
// have been run first (ie the shorter task)
8280

8381
// print information to help with diagnostics.
84-
Serial.print("Scheduled: "); Serial.print(microsStarted);
85-
Serial.print(" ExecAt: "); Serial.print(microsExecuted2ndJob);
82+
serdebugF4("Scheduled: ", microsStarted, " ExecAt: ", microsExecuted2ndJob);
8683
long howLong = microsExecuted2ndJob - microsStarted;
87-
Serial.print(" difference "); Serial.print(howLong);
88-
Serial.print(" - expected "); Serial.println(minExpected);
84+
serdebugF4(" difference ", howLong, " - expected ", minExpected);
8985

9086
assertTrue(scheduled2ndJob);
9187
unsigned long minRange = (minExpected < allowanceOver) ? 0 : (minExpected - allowanceOver);
@@ -96,14 +92,14 @@ class TimingHelpFixture : public SimpleTest::UnitTestExecutor {
9692

9793
void assertTasksSpacesTaken(int taken) {
9894
char sz[32];
99-
int count = 0;
95+
int cnt = 0;
10096
char* taskData = taskManager.checkAvailableSlots(sz, sizeof sz);
10197
while(*taskData) {
102-
if(*taskData != 'F') count++;
98+
if(*taskData != 'F') cnt++;
10399
++taskData;
104100
}
105-
Serial.print("Tasks free "); Serial.println(count);
106-
assertEquals(taken, count);
101+
serdebugF2("Tasks free ", cnt);
102+
assertEquals(taken, cnt);
107103
}
108104
};
109105

tests/timerInterruptTest/timerInterruptTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using namespace SimpleTest;
55

6+
IOLOG_MBED_PORT_IF_NEEDED(USBTX, USBRX)
7+
68
HardwareTimer* myTimer;
79
int taskExec = 0;
810

@@ -34,8 +36,7 @@ void timerHasChanged() {
3436
}
3537

3638
void setup() {
37-
Serial.begin(115200);
38-
while (!Serial);
39+
IOLOG_START_SERIAL
3940
startTesting();
4041

4142
#if defined(TIM1)
@@ -44,7 +45,6 @@ void setup() {
4445
TIM_TypeDef *Instance = TIM2;
4546
#endif
4647

47-
// Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup() function is finished.
4848
myTimer = new HardwareTimer(Instance);
4949
pinMode(LED_BUILTIN, OUTPUT);
5050
myTimer->setOverflow(250, HERTZ_FORMAT);

0 commit comments

Comments
 (0)