Skip to content

Commit b141582

Browse files
committed
Updated to latest core test code, and changed the examples to match. Memory testing added. String library test suffers from some kind of memory corruption. eed test to isolate the problem.
1 parent 7ed56a3 commit b141582

File tree

7 files changed

+233
-329
lines changed

7 files changed

+233
-329
lines changed

libraries/ArduinoTestSuite/ArduinoTestSuite.cpp

Lines changed: 108 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@
1414
//* Lesser General Public License for more details.
1515
//************************************************************************
1616
//* Aug 31, 2010 <MLS> Started on TestArduino
17+
//* Oct 18, 2010 <MLS> Added memory testing
1718
//************************************************************************
1819

19-
#ifdef __MWERKS__
20-
#include "codewarrior.h"
21-
// #include <stdlib.h>
22-
#else
23-
#include <avr/pgmspace.h>
24-
#endif
25-
20+
#include <avr/pgmspace.h>
2621
#include <avr/io.h>
2722
#include <avr/eeprom.h>
2823

29-
#include <ArduinoTestSuite.h>
24+
25+
26+
#include "ArduinoTestSuite.h"
3027

3128

3229
#include "WProgram.h"
@@ -56,7 +53,7 @@ enum
5653
ATS_LIBC_version,
5754
ATS_CompiledDate,
5855
ATS_TestSuiteName,
59-
ATS_ElapsedTime,
56+
ATS_FreeMemory,
6057

6158

6259
};
@@ -73,7 +70,7 @@ prog_char gTextMsg_GCC_VERSION[] PROGMEM = "GCC-Version";
7370
prog_char gTextMsg_AVR_LIBC[] PROGMEM = "AVR-LibC-Ver";
7471
prog_char gTextMsg_COMPILED_DATE[] PROGMEM = "Compiled-date";
7572
prog_char gTextMsg_TEST_SUITE_NAME[] PROGMEM = "Test-Suite-Name";
76-
prog_char gTextMsg_ELAPSED_TIME[] PROGMEM = "Elapsed-time";
73+
prog_char gTextMsg_memoryUsage[] PROGMEM = "Free-memory";
7774
prog_char gTextMsg_dotdotdot[] PROGMEM = "... ";
7875
prog_char gTextMsg_ok[] PROGMEM = "ok";
7976
prog_char gTextMsg_FAIL[] PROGMEM = "FAIL";
@@ -108,10 +105,81 @@ void Serial_println_P(prog_char *flashMemStr)
108105
Serial.println();
109106
}
110107

108+
//************************************************************************
109+
//* this is for internal use only, not made pubic to the API
110+
static void ATS_PrintProperty( int propertyTagNum,
111+
char *propertyName,
112+
char *propertyValue)
113+
{
114+
char lineBuffer[64];
115+
116+
strcpy_P(lineBuffer, gTextMsg_info);
117+
switch(propertyTagNum)
118+
{
119+
case 0:
120+
strcat(lineBuffer, propertyName);
121+
break;
122+
123+
case ATS_Manufacturer:
124+
strcat_P(lineBuffer, gTextMsg_Manufacturer);
125+
break;
126+
127+
case ATS_CPU:
128+
strcat_P(lineBuffer, gTextMsg_CPUname);
129+
break;
130+
131+
case ATS_GCC_version:
132+
strcat_P(lineBuffer, gTextMsg_GCC_VERSION);
133+
break;
134+
135+
case ATS_LIBC_version:
136+
strcat_P(lineBuffer, gTextMsg_AVR_LIBC);
137+
break;
138+
139+
case ATS_CompiledDate:
140+
strcat_P(lineBuffer, gTextMsg_COMPILED_DATE);
141+
break;
142+
143+
case ATS_TestSuiteName:
144+
strcat_P(lineBuffer, gTextMsg_TEST_SUITE_NAME);
145+
break;
146+
147+
case ATS_FreeMemory:
148+
strcat_P(lineBuffer, gTextMsg_memoryUsage);
149+
break;
150+
}
151+
152+
while (strlen(lineBuffer) < 20)
153+
{
154+
strcat(lineBuffer, " ");
155+
}
156+
157+
strcat_P(lineBuffer, gTextMsg_spaceEqual);
158+
if (propertyValue != 0)
159+
{
160+
strcat(lineBuffer, propertyValue);
161+
}
162+
Serial.println(lineBuffer);
163+
164+
}
165+
166+
167+
111168

112169
//************************************************************************
113-
void ATS_PrintTestStart(char *manufName, char *testSuiteName)
170+
void ATS_begin(char *manufName, char *testSuiteName)
114171
{
172+
int freeMemory;
173+
char memoryMsg[48];
174+
175+
gYotalErrors = 0;
176+
gTestCount = 0;
177+
178+
Serial.begin(9600);
179+
delay(1000);
180+
181+
gTestStartTime = millis();
182+
115183
Serial.println();
116184
Serial.println();
117185
Serial.println();
@@ -123,17 +191,21 @@ void ATS_PrintTestStart(char *manufName, char *testSuiteName)
123191
ATS_PrintProperty(ATS_CompiledDate, 0, __DATE__);
124192
ATS_PrintProperty(ATS_TestSuiteName, 0, testSuiteName);
125193

194+
freeMemory = ATS_GetFreeMemory();
195+
sprintf(memoryMsg, "%d bytes", freeMemory);
196+
ATS_PrintProperty(ATS_FreeMemory, 0, memoryMsg);
126197

127198
randomSeed(analogRead(0));
128199

129200
}
130201

131202
//************************************************************************
132-
void ATS_PrintTestEnd()
203+
void ATS_end()
133204
{
134205
long seconds;
135206
long milliSecs;
136207

208+
137209
Serial_println_P(gTextMsg_dashLine);
138210

139211
// Ran 4 tests in 0.000s
@@ -196,66 +268,6 @@ int sLen;
196268
}
197269

198270

199-
//************************************************************************
200-
//* this is for internal use only, not made pubic to the API
201-
static void ATS_PrintProperty( int propertyTagNum,
202-
char *propertyName,
203-
char *propertyValue)
204-
{
205-
char lineBuffer[64];
206-
207-
strcpy_P(lineBuffer, gTextMsg_info);
208-
switch(propertyTagNum)
209-
{
210-
case 0:
211-
strcat(lineBuffer, propertyName);
212-
break;
213-
214-
case ATS_Manufacturer:
215-
strcat_P(lineBuffer, gTextMsg_Manufacturer);
216-
break;
217-
218-
case ATS_CPU:
219-
strcat_P(lineBuffer, gTextMsg_CPUname);
220-
break;
221-
222-
case ATS_GCC_version:
223-
strcat_P(lineBuffer, gTextMsg_GCC_VERSION);
224-
break;
225-
226-
case ATS_LIBC_version:
227-
strcat_P(lineBuffer, gTextMsg_AVR_LIBC);
228-
break;
229-
230-
case ATS_CompiledDate:
231-
strcat_P(lineBuffer, gTextMsg_COMPILED_DATE);
232-
break;
233-
234-
case ATS_TestSuiteName:
235-
strcat_P(lineBuffer, gTextMsg_TEST_SUITE_NAME);
236-
break;
237-
238-
case ATS_ElapsedTime:
239-
strcat_P(lineBuffer, gTextMsg_ELAPSED_TIME);
240-
break;
241-
}
242-
243-
while (strlen(lineBuffer) < 20)
244-
{
245-
strcat(lineBuffer, " ");
246-
}
247-
248-
strcat_P(lineBuffer, gTextMsg_spaceEqual);
249-
if (propertyValue != 0)
250-
{
251-
strcat(lineBuffer, propertyValue);
252-
}
253-
Serial.println(lineBuffer);
254-
// ATS_PrintTestStatus(lineBuffer, PASSED);
255-
256-
}
257-
258-
259271

260272
//************************************************************************
261273
//* returns true if no errors, false if there is an error
@@ -674,6 +686,30 @@ char reportString[48];
674686

675687

676688

689+
//************************************************************************
690+
extern unsigned int __data_start;
691+
extern unsigned int __data_end;
692+
extern unsigned int __bss_start;
693+
extern unsigned int __bss_end;
694+
extern unsigned int __heap_start;
695+
extern void *__brkval;
696+
677697

678698

699+
//************************************************************************
700+
int ATS_GetFreeMemory()
701+
{
702+
int free_memory;
703+
704+
if((int)__brkval == 0)
705+
{
706+
free_memory = ((int)&free_memory) - ((int)&__bss_end);
707+
}
708+
else
709+
{
710+
free_memory = ((int)&free_memory) - ((int)__brkval);
711+
}
712+
return free_memory;
713+
}
714+
679715

libraries/ArduinoTestSuite/ArduinoTestSuite.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,44 @@
2424
#endif
2525

2626

27-
void ATS_PrintTestStart(char *manufName, char *testSuiteName);
28-
void ATS_PrintTestEnd();
27+
void ATS_begin(char *manufName, char *testSuiteName);
28+
void ATS_end();
29+
2930
void ATS_PrintTestStatus(char *testString, boolean passed);
3031
boolean ATS_Test_DigitalPin(uint8_t digitalPinToTest);
3132
boolean ATS_Test_PWM_Pin(uint8_t digitalPinToTest);
3233
boolean ATS_Test_AnalogInput(uint8_t analogPintoTest);
3334
boolean ATS_Test_EEPROM(void);
3435

35-
static void ATS_PrintProperty( int propertyTagNum,
36-
char *propertyName,
37-
char *propertyValue);
38-
3936
short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, char *serialPortName);
4037

4138

39+
int ATS_GetFreeMemory();
40+
41+
//************************************************************************
42+
//* this has to be an inline function because calling subroutines affects free memory
43+
inline void ATS_ReportMemoryUsage(int _memoryUsageAtStart)
44+
{
45+
int freeMemoryAtEnd;
46+
int lostMemory;
47+
boolean memoryOK;
48+
char memoryUsage[48];
49+
50+
freeMemoryAtEnd = ATS_GetFreeMemory();
51+
lostMemory = _memoryUsageAtStart - freeMemoryAtEnd;
52+
if (lostMemory == 0)
53+
{
54+
strcpy(memoryUsage, "Memory Usage");
55+
memoryOK = true;
56+
}
57+
else
58+
{
59+
sprintf(memoryUsage, "Memory Usage (lost %d bytes)", lostMemory);
60+
memoryOK = false;
61+
}
62+
ATS_PrintTestStatus(memoryUsage, memoryOK);
63+
}
64+
4265

4366

4467
extern unsigned long gTestStartTime;

libraries/ArduinoTestSuite/examples/ATS_Constants/ATS_Constants.pde

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,19 @@
77
//* Oct 16, 2010 <ROA> Started on String Test
88
//************************************************************************
99

10-
11-
12-
1310
#include "WProgram.h"
1411
#include "HardwareSerial.h"
1512
#include <ArduinoTestSuite.h>
1613

1714
//************************************************************************
1815
void setup()
1916
{
20-
short ii;
21-
uint8_t timerNumber;
2217
char testName[64];
18+
int startMemoryUsage;
2319

24-
gYotalErrors = 0;
25-
gTestCount = 0;
26-
27-
/*
28-
* Test Variable Setup
29-
*/
20+
startMemoryUsage = ATS_GetFreeMemory();
3021

31-
Serial.begin(9600);
32-
delay(1000);
33-
34-
gTestStartTime = millis();
35-
ATS_PrintTestStart("Arduino", "Test of Arduino Constants");
22+
ATS_begin("Arduino", "Test of Arduino Constants");
3623

3724
/*
3825
* Run the tests
@@ -72,7 +59,8 @@ void setup()
7259
/*
7360
* Test complete
7461
*/
75-
ATS_PrintTestEnd();
62+
ATS_ReportMemoryUsage(startMemoryUsage);
63+
ATS_end();
7664

7765
}
7866

@@ -87,3 +75,4 @@ void loop()
8775

8876

8977

78+

0 commit comments

Comments
 (0)