mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
ArduinoTestSuite updates from Paul Stoffregen
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user