Merge remote-tracking branch 'ricklon/atsupdatefor0100' into new-extension

This commit is contained in:
David A. Mellis 2011-09-01 11:20:00 -04:00
commit 33146ca75a
10 changed files with 251 additions and 105 deletions

View File

@ -1,6 +1,7 @@
//************************************************************************
//* Arduino Test Suite
//* (C) 2010 by Mark Sproul
//* (C) 2011 by Matthew Murdoch
//* Open source as per standard Arduino code
//*
//* This library is free software; you can redistribute it and/or
@ -15,6 +16,7 @@
//************************************************************************
//* Aug 31, 2010 <MLS> Started on TestArduino
//* Oct 18, 2010 <MLS> Added memory testing
//* Jun 10, 2011 <MEM> Added free list to memory usage calculation
//************************************************************************
#include <avr/pgmspace.h>
@ -26,11 +28,6 @@
#include "ArduinoTestSuite.h"
#include "Arduino.h"
#include "HardwareSerial.h"
#include "pins_arduino.h"
#include "avr_cpunames.h"
#if defined(USART3_RX_vect)
@ -58,6 +55,7 @@ enum
};
unsigned long gTestStartTime;
unsigned long gTestTotalElapsedTime;
short gTagIndent;
int gYotalErrors;
int gTestCount;
@ -176,9 +174,9 @@ char memoryMsg[48];
gTestCount = 0;
Serial.begin(9600);
delay(1000);
delay(100);
gTestStartTime = millis();
gTestTotalElapsedTime = 0;
Serial.println();
Serial.println();
@ -197,14 +195,17 @@ char memoryMsg[48];
randomSeed(analogRead(0));
gTestStartTime = micros();
}
//************************************************************************
void ATS_end()
{
long seconds;
long milliSecs;
unsigned long seconds;
unsigned long microSecs;
char buf[8];
gTestTotalElapsedTime += (micros() - gTestStartTime);
Serial_println_P(gTextMsg_dashLine);
@ -212,14 +213,22 @@ long milliSecs;
Serial.print("Ran ");
Serial.print(gTestCount);
Serial.print(" tests in ");
seconds = gTestTotalElapsedTime / 1000000;
microSecs = gTestTotalElapsedTime % 1000000;
seconds = millis() / 1000;
milliSecs = millis() % 1000;
Serial.print(seconds);
Serial.print('.');
Serial.print(milliSecs);
ultoa(microSecs + 1000000, buf, 10); // add forces leading zeros
buf[0] = '.'; // replace leading '1' with decimal point
Serial.print(buf);
Serial.print('s');
Serial.println();
int used = ATS_GetMaximumMemoryAllocated();
if (used >= 0) {
Serial.print("Maximum heap memory: ");
Serial.println(used);
}
Serial.println();
if (gYotalErrors == 0)
@ -245,6 +254,9 @@ void ATS_PrintTestStatus(char *testString, boolean passed)
{
int sLen;
// do not include time printing status in total test time
gTestTotalElapsedTime += (micros() - gTestStartTime);
Serial.print(testString);
sLen = strlen(testString);
while (sLen < 60)
@ -265,6 +277,9 @@ int sLen;
Serial.println();
gTestCount++;
// begin counting total test time again
gTestStartTime = micros();
}
@ -474,8 +489,15 @@ uint8_t helperpin;
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define kAnalogPinOffset 54
#define DIGITAL_ANAPIN(a) ((a) + kAnalogPinOffset)
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define kAnalogPinOffset 38
#define DIGITAL_ANAPIN(a) ((a) + kAnalogPinOffset)
#elif defined(__AVR_ATmega32U4__)
#define DIGITAL_ANAPIN(a) ((a) < 11 ? 21 - (a) : 22)
#else
#define kAnalogPinOffset 14
#define DIGITAL_ANAPIN(a) ((a) + kAnalogPinOffset)
#endif
@ -490,7 +512,7 @@ int analogValueLow;
//* first we have to set the ANALOG pin to INPUT
pinMode(analogPintoTest + kAnalogPinOffset, INPUT);
pinMode(DIGITAL_ANAPIN(analogPintoTest), INPUT);
passedOK = true;
@ -532,15 +554,15 @@ boolean ATS_Test_AnalogInput(uint8_t analogPinToTest)
boolean passedOK;
uint8_t helperpin;
if ((analogPinToTest % 2) == 0)
if ((DIGITAL_ANAPIN(analogPinToTest) % 2) == 0)
{
//* if its EVEN, add 1
helperpin = kAnalogPinOffset + analogPinToTest + 1;
helperpin = DIGITAL_ANAPIN(analogPinToTest) + 1;
}
else
{
//* if its ODD
helperpin = kAnalogPinOffset + analogPinToTest - 1;
helperpin = DIGITAL_ANAPIN(analogPinToTest) - 1;
}
passedOK = ATS_Test_AnalogInputWithHelper(analogPinToTest, helperpin);
return(passedOK);
@ -551,7 +573,7 @@ uint8_t helperpin;
#define kSerialTestDelay 3
#if (SERIAL_PORT_COUNT > 1) && !defined(__AVR_ATmega32U4__)
#if (SERIAL_PORT_COUNT > 1)
//************************************************************************
//* retunrs 0 if no errors, 1 if an error occured
short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, char *serialPortName)
@ -693,8 +715,32 @@ extern unsigned int __bss_start;
extern unsigned int __bss_end;
extern unsigned int __heap_start;
extern void *__brkval;
char *__brkval_maximum __attribute__((weak));
/*
* The free list structure as maintained by the avr-libc memory allocation routines.
*/
struct __freelist {
size_t sz;
struct __freelist *nx;
};
/* The head of the free list structure */
extern struct __freelist *__flp;
/* Calculates the size of the free list */
int ATS_FreeListSize()
{
struct __freelist* current;
int total = 0;
for (current = __flp; current; current = current->nx) {
total += 2; /* Add two bytes for the memory block's header */
total += (int) current->sz;
}
return total;
}
//************************************************************************
int ATS_GetFreeMemory()
@ -703,13 +749,21 @@ int free_memory;
if((int)__brkval == 0)
{
free_memory = ((int)&free_memory) - ((int)&__bss_end);
free_memory = ((int)&free_memory) - ((int)&__heap_start);
}
else
{
free_memory = ((int)&free_memory) - ((int)__brkval);
free_memory += ATS_FreeListSize();
}
return free_memory;
}
int ATS_GetMaximumMemoryAllocated()
{
if (__brkval_maximum) {
return (int)__brkval_maximum - (int)&__heap_start;
}
return -1;
}

View File

@ -3,15 +3,12 @@
//* Aug 31, 2010 <MLS> Started on TestArduino
//************************************************************************
#ifndef _AVR_IO_H_
#include <avr/io.h>
#endif
#ifndef Arduino_h
#include "Arduino.h"
#endif
#ifndef HardwareSerial_h
#include "HardwareSerial.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "pins_arduino.h"
#else
#include "WProgram.h"
#include "pins_arduino.h"
#endif
@ -37,9 +34,12 @@ short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, char *serialPortName
int ATS_GetFreeMemory();
int ATS_GetMaximumMemoryAllocated();
//************************************************************************
//* this has to be an inline function because calling subroutines affects free memory
inline void ATS_ReportMemoryUsage(int _memoryUsageAtStart) __attribute__((always_inline, unused));
inline void ATS_ReportMemoryUsage(int _memoryUsageAtStart)
{
int freeMemoryAtEnd;

View File

@ -7,7 +7,6 @@
//* Oct 16, 2010 <ROA> Test of Arduino Constants
//************************************************************************
#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>
//************************************************************************

View File

@ -1 +1,101 @@
//************************************************************************ //* Arduino Test Suite //* ATS_ToneTest //* //* Copyright (c) 2010 Mark Sproul All right reserved. //* //* This library is free software; you can redistribute it and/or //* modify it under the terms of the GNU Lesser General Public //* License as published by the Free Software Foundation; either //* version 2.1 of the License, or (at your option) any later version. //* //* This library is distributed in the hope that it will be useful, //* but WITHOUT ANY WARRANTY; without even the implied warranty of //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //* Lesser General Public License for more details. //* //* You should have received a copy of the GNU Lesser General Public //* License along with this library; if not, write to the Free Software //* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA //************************************************************************ //* Aug 31, 2010 <MLS> Started on TestArduino //* Oct 28, 2010 <MLS> Started on Delay //************************************************************************ #include "HardwareSerial.h" #include <ArduinoTestSuite.h> //************************************************************************ void setup() { short ii; short testNum; int startMemoryUsage; unsigned long startMillis; unsigned long endMillis; unsigned long deltaMillis; unsigned long errMillis; boolean passed; char testNameString[80]; startMemoryUsage = ATS_GetFreeMemory(); ATS_begin("Arduino", "DelayTest"); testNum = 1; //* we start at 2 because 0/1 are RXD/TXD for (ii=0; ii<1000; ii+= 15) { startMillis = millis(); delay(ii); endMillis = millis(); deltaMillis = endMillis - startMillis; if (deltaMillis >= ii) { errMillis = deltaMillis - ii; } else { errMillis = ii - deltaMillis; } if (errMillis <= 1) { passed = true; } else { passed = false; } sprintf(testNameString, "DelayTest.%02d (delay= %4d actual delay=%ld err=%ld)", testNum, ii, deltaMillis, errMillis); ATS_PrintTestStatus(testNameString, passed); testNum++; } ATS_ReportMemoryUsage(startMemoryUsage); ATS_end(); } //************************************************************************ void loop() { }
//************************************************************************
//* Arduino Test Suite
//* ATS_ToneTest
//*
//* Copyright (c) 2010 Mark Sproul All right reserved.
//*
//* This library is free software; you can redistribute it and/or
//* modify it under the terms of the GNU Lesser General Public
//* License as published by the Free Software Foundation; either
//* version 2.1 of the License, or (at your option) any later version.
//*
//* This library is distributed in the hope that it will be useful,
//* but WITHOUT ANY WARRANTY; without even the implied warranty of
//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//* Lesser General Public License for more details.
//*
//* You should have received a copy of the GNU Lesser General Public
//* License along with this library; if not, write to the Free Software
//* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//************************************************************************
//* Aug 31, 2010 <MLS> Started on TestArduino
//* Oct 28, 2010 <MLS> Started on Delay
//************************************************************************
#include <ArduinoTestSuite.h>
//************************************************************************
void setup()
{
short ii;
short testNum;
int startMemoryUsage;
unsigned long startMillis;
unsigned long endMillis;
unsigned long deltaMillis;
unsigned long errMillis;
boolean passed;
char testNameString[80];
startMemoryUsage = ATS_GetFreeMemory();
ATS_begin("Arduino", "DelayTest");
testNum = 1;
//* we start at 2 because 0/1 are RXD/TXD
for (ii=0; ii<1000; ii+= 15)
{
startMillis = millis();
delay(ii);
endMillis = millis();
deltaMillis = endMillis - startMillis;
if (deltaMillis >= ii)
{
errMillis = deltaMillis - ii;
}
else
{
errMillis = ii - deltaMillis;
}
if (errMillis <= 1)
{
passed = true;
}
else
{
passed = false;
}
sprintf(testNameString, "DelayTest.%02d (delay= %4d actual delay=%ld err=%ld)", testNum, ii, deltaMillis, errMillis);
ATS_PrintTestStatus(testNameString, passed);
testNum++;
}
ATS_ReportMemoryUsage(startMemoryUsage);
ATS_end();
}
//************************************************************************
void loop()
{
}

View File

@ -8,11 +8,7 @@
//* Oct 18, 2010 <MLS> Added memory testing
//************************************************************************
#include "HardwareSerial.h"
#include "pins_arduino.h"
#include <ArduinoTestSuite.h>
#include "avr_cpunames.h"
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
#define kBoard_PinCount 20
@ -20,6 +16,12 @@
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define kBoard_PinCount 70
#define kBoard_AnalogCount 16
#elif defined(CORE_TEENSY)
#define kBoard_PinCount CORE_NUM_TOTAL_PINS
#define kBoard_AnalogCount CORE_NUM_ANALOG
#define SERIAL_PORT_COUNT 2
HardwareSerial Serial1 = HardwareSerial();
#endif

View File

@ -7,7 +7,6 @@
//* Oct 16, 2010 <ROA> Started on String Test
//************************************************************************
#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>
//************************************************************************

View File

@ -7,19 +7,12 @@
//* Oct 16, 2010 <ROA> Started on String Test
//************************************************************************
#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>
//************************************************************************
void setup()
void do_string_operations(int startMemoryUsage)
{
char testName[64];
int startMemoryUsage;
/*
* Create variable for the tests.
*/
String stringOne;
int firstClosingBracket;
int firstOpeningBracket;
@ -31,67 +24,77 @@ void setup()
int lastOpeningBracket;
int lastListItem;
int lastParagraph;
int secondLastGraf;
/*;
* initiate the test run
*/
startMemoryUsage = ATS_GetFreeMemory();
ATS_begin("Arduino", "String Memory Test");
// indexOf() returns the position (i.e. index) of a particular character
// in a string. For example, if you were parsing HTML tags, you could use it:
int secondLastParagraph;
int thirdLastParagraph;
// 1111111111
// 01234567890123456789
stringOne = "<HTML><HEAD><BODY>";
firstClosingBracket = stringOne.indexOf('>');
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
ATS_PrintTestStatus("firstClosingBracket", firstClosingBracket == 5);
// 1111111111
// 01234567890123456789
stringOne = "<HTML><HEAD><BODY>";
secondOpeningBracket = firstClosingBracket + 1;
secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );
Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket);
ATS_PrintTestStatus("secondClosingBracket", secondClosingBracket == 11);
// you can also use indexOf() to search for Strings:
// 1111111111
// 01234567890123456789
stringOne = "<HTML><HEAD><BODY>";
bodyTag = stringOne.indexOf("<BODY>");
Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag);
ATS_PrintTestStatus("bodyTag", bodyTag == 12);
// 111111111122222222223333333333
// 0123456789012345678901234567890123456789
stringOne = "<UL><LI>item<LI>item<LI>item</UL>";
firstListItem = stringOne.indexOf("<LI>");
secondListItem = stringOne.indexOf("item", firstListItem + 1 );
Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket);
secondListItem = stringOne.indexOf("<LI>", firstListItem + 1 );
ATS_PrintTestStatus("firstListItem", firstListItem == 4);
ATS_PrintTestStatus("secondListItem", secondListItem == 12);
// lastIndexOf() gives you the last occurrence of a character or string:
lastOpeningBracket = stringOne.lastIndexOf('<');
Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket);
ATS_PrintTestStatus("lastOpeningBracket", lastOpeningBracket == 28);
lastListItem = stringOne.lastIndexOf("<LI>");
Serial.println("The index of the last list item in the string " + stringOne + " is " + lastListItem);
ATS_PrintTestStatus("lastListItem", lastListItem == 20);
// lastIndexOf() can also search for a string:
// 11111111112222222222333333333344444444445555555555
// 012345678901234567890123456789012345678901234567890123456789
stringOne = "<p>Lorem ipsum dolor sit amet</p><p>Ipsem</p><p>Quod</p>";
lastParagraph = stringOne.lastIndexOf("<p");
secondLastGraf = stringOne.lastIndexOf("<p", lastParagraph - 1);
Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf);
secondLastParagraph = stringOne.lastIndexOf("<p", lastParagraph - 1);
thirdLastParagraph = stringOne.lastIndexOf("<p", secondLastParagraph - 1);
ATS_PrintTestStatus("lastParagraph", lastParagraph == 45);
ATS_PrintTestStatus("secondLastParagraph", secondLastParagraph == 33);
ATS_PrintTestStatus("thirdLastParagraph", thirdLastParagraph == 0);
}
void setup()
{
int startMemoryUsage=0;
startMemoryUsage = ATS_GetFreeMemory();
ATS_begin("Arduino", "String Memory Test");
ATS_ReportMemoryUsage(startMemoryUsage);
/*
* Test complete
*/
// Run all the string functions. All string objects used are local variables,
// so they go out of scope upon return. Memory used should be fully released.
do_string_operations(startMemoryUsage);
ATS_ReportMemoryUsage(startMemoryUsage);
ATS_end();
}
//************************************************************************
void loop()
{
}

View File

@ -7,7 +7,6 @@
//* Oct 16, 2010 <ROA> Started on String Test
//************************************************************************
#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>
//************************************************************************
@ -101,10 +100,14 @@ void setup()
// or perhaps you want to ignore case:
ATS_PrintTestStatus("11. EqualsIgnoreCase() method equals", stringOne.equalsIgnoreCase(stringTwo));
#if ARDUINO < 100 || defined(CORE_TEENSY)
// David Mellis decided not to keep implicit string to number comparison operators
// in Arduino 1.0. Only run this test on older version, or if using Teensy
// a numeric string compared to the number it represents:
stringOne = "1";
int numberOne = 1;
ATS_PrintTestStatus("12. A numeric string compared to the number it represents", stringOne == numberOne);
#endif
// two numeric strings compared:
stringOne = "2";
@ -129,18 +132,18 @@ void setup()
ATS_PrintTestStatus("18. The compareTo() operator also allows you to compare strings", stringOne.compareTo(stringTwo) < 0);
// These two tests assume the string compare parses numbers
// within strings, but it does not actually do any such thing
// compareTo() String with numnber > String with number:
stringOne = "Sensor: 50";
stringTwo= "Sensor: 150";
ATS_PrintTestStatus("19. The compareTo() String with integers", stringOne.compareTo(stringTwo) < 0);
//stringOne = "Sensor: 50";
//stringTwo= "Sensor: 150";
//ATS_PrintTestStatus("19. The compareTo() String with integers", stringOne.compareTo(stringTwo) < 0);
// compareTo() String with numnber > String with number append integer, matches example code:
stringOne = "Sensor: ";
stringTwo= "Sensor: ";
stringOne += 50;
stringTwo += 150;
ATS_PrintTestStatus("20. The compareTo() compare strings with appended integers", stringOne.compareTo(stringTwo) < 0);
//stringOne = "Sensor: ";
//stringTwo= "Sensor: ";
//stringOne += 50;
//stringTwo += 150;
//ATS_PrintTestStatus("20. The compareTo() compare strings with appended integers", stringOne.compareTo(stringTwo) < 0);
/*

View File

@ -1,18 +1,5 @@
#include <ArduinoTestSuite.h>
void Test_Equal(char *testString, char *expected, const String &actual)
{
char buf[100]; actual.toCharArray(buf, 100);
boolean b = (strcmp(buf, expected) == 0);
ATS_PrintTestStatus(testString, b);
if (!b) {
Serial.print("expected '");
Serial.print(expected);
Serial.print("', actual '");
Serial.print(actual);
Serial.println("'");
}
}
#include "Test_Equal.h"
void setup()
{

View File

@ -22,11 +22,7 @@
//* Oct 23, 2010 <MLS> Started on ToneTest
//************************************************************************
#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
#define kBoard_PinCount 20
@ -34,10 +30,11 @@
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define kBoard_PinCount 70
#define kBoard_AnalogCount 16
#elif defined(CORE_TEENSY)
#define kBoard_PinCount CORE_NUM_TOTAL_PINS
#define kBoard_AnalogCount CORE_NUM_ANALOG
#endif
#include <ArduinoTestSuite.h>
//************************************************************************
void TestTonePin(uint8_t toneOutputPinNumber)
{
@ -63,6 +60,7 @@ long deltaFreq;
//* if its ODD
helperpin = toneOutputPinNumber - 1;
}
if (helperpin >= kBoard_PinCount) return;
//* dont set the mode of the OUTPUT pin, the tone command does that
@ -143,6 +141,7 @@ long durationTime;
//* if its ODD
helperpin = toneOutputPinNumber - 1;
}
if (helperpin >= kBoard_PinCount) return;
//* dont set the mode of the OUTPUT pin, the tone command does that