Skip to content

ArduinoTestSuite updates from Paul Stoffregen #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 73 additions & 19 deletions libraries/ArduinoTestSuite/ArduinoTestSuite.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>
Expand All @@ -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)
Expand Down Expand Up @@ -58,6 +55,7 @@ enum

};
unsigned long gTestStartTime;
unsigned long gTestTotalElapsedTime;
short gTagIndent;
int gYotalErrors;
int gTestCount;
Expand Down Expand Up @@ -176,9 +174,9 @@ char memoryMsg[48];
gTestCount = 0;

Serial.begin(9600);
delay(1000);
delay(100);

gTestStartTime = millis();
gTestTotalElapsedTime = 0;

Serial.println();
Serial.println();
Expand All @@ -197,29 +195,40 @@ 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);

// Ran 4 tests in 0.000s
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)
Expand All @@ -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)
Expand All @@ -265,6 +277,9 @@ int sLen;
Serial.println();

gTestCount++;

// begin counting total test time again
gTestStartTime = micros();
}


Expand Down Expand Up @@ -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


Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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;
}

18 changes: 9 additions & 9 deletions libraries/ArduinoTestSuite/ArduinoTestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//* Oct 16, 2010 <ROA> Test of Arduino Constants
//************************************************************************

#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>

//************************************************************************
Expand Down
102 changes: 101 additions & 1 deletion libraries/ArduinoTestSuite/examples/ATS_Delay/ATS_Delay.pde
Original file line number Diff line number Diff line change
@@ -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()
{


}




10 changes: 6 additions & 4 deletions libraries/ArduinoTestSuite/examples/ATS_General/ATS_General.pde
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
//* 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
#define kBoard_AnalogCount 6
#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


Expand Down
Loading