Improved metest. Added copyright notes.

This commit is contained in:
barthess 2015-04-28 10:10:09 +03:00
parent adfa3f75e8
commit 955b790137
6 changed files with 141 additions and 53 deletions

View File

@ -10,7 +10,7 @@ endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT =
USE_COPT =
endif
# C++ specific options here (added to USE_OPT).

View File

@ -41,7 +41,7 @@
******************************************************************************
*/
static void mem_error_cb(memtest_t *memp, testtype_t e, size_t address);
static void mem_error_cb(memtest_t *memp, testtype e, size_t address);
/*
******************************************************************************
@ -110,7 +110,7 @@ static inline void green_led_on(void) {palSetPad(GPIOI, GPIOI_LED_G);}
static inline void green_led_off(void) {palClearPad(GPIOI, GPIOI_LED_G);}
static inline void green_led_toggle(void) {palTogglePad(GPIOI, GPIOI_LED_G);}
void mem_error_cb(memtest_t *memp, testtype_t e, size_t address) {
void mem_error_cb(memtest_t *memp, testtype e, size_t address) {
(void)memp;
(void)e;
(void)address;

View File

@ -1,3 +1,19 @@
/*
ChibiOS/RT - Copyright (C) 2013-2014 Uladzimir Pylinsky aka barthess
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef MEMBENCH_H_
#define MEMBENCH_H_

View File

@ -1,3 +1,19 @@
/*
ChibiOS/RT - Copyright (C) 2013-2014 Uladzimir Pylinsky aka barthess
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef MEMCPY_DMA_H_
#define MEMCPY_DMA_H_

View File

@ -1,3 +1,19 @@
/*
ChibiOS/RT - Copyright (C) 2013-2014 Uladzimir Pylinsky aka barthess
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
@ -12,6 +28,7 @@ class Generator {
public:
Generator(void) : pattern(0) {;}
virtual T get(void) = 0;
virtual testtype get_type(void) = 0;
virtual void init(T seed) {
pattern = seed;
}
@ -33,6 +50,10 @@ class GeneratorWalkingOne : public Generator<T> {
return ret;
}
testtype get_type(void) {
return MEMTEST_WALKING_ONE;
}
};
/*
@ -49,6 +70,10 @@ class GeneratorWalkingZero : public Generator<T> {
return ret;
}
testtype get_type(void) {
return MEMTEST_WALKING_ZERO;
}
};
/*
@ -61,6 +86,10 @@ class GeneratorOwnAddress : public Generator<T> {
this->pattern++;
return ret;
}
testtype get_type(void) {
return MEMTEST_OWN_ADDRESS;
}
};
/*
@ -73,6 +102,13 @@ class GeneratorMovingInv : public Generator<T> {
this->pattern = ~this->pattern;
return ret;
}
testtype get_type(void) {
if ((this->pattern == 0) || ((this->pattern & 0xFF) == 0xFF))
return MEMTEST_MOVING_INVERSION_ZERO;
else
return MEMTEST_MOVING_INVERSION_55AA;
}
};
/*
@ -103,6 +139,10 @@ public:
return ret;
}
testtype get_type(void) {
return MEMTEST_MOVING_INVERSION_RAND;
}
private:
size_t step;
T prev;
@ -112,10 +152,10 @@ private:
*
*/
template <typename T>
static void memtest_sequential(memtest_t *memp, Generator<T> &generator, T seed) {
const size_t steps = memp->size / sizeof(T);
static void memtest_sequential(memtest_t *testp, Generator<T> &generator, T seed) {
const size_t steps = testp->size / sizeof(T);
size_t i;
T *mem = static_cast<T *>(memp->start);
T *mem = static_cast<T *>(testp->start);
/* fill ram */
generator.init(seed);
@ -126,72 +166,72 @@ static void memtest_sequential(memtest_t *memp, Generator<T> &generator, T seed)
generator.init(seed);
for (i=0; i<steps; i++) {
if (mem[i] != generator.get()) {
memp->ecb(memp, MEMTEST_WALKING_ONE, i*sizeof(T));
testp->ecb(testp, generator.get_type(), i*sizeof(T));
return;
}
}
}
template <typename T>
static void walking_one(memtest_t *memp) {
static void walking_one(memtest_t *testp) {
GeneratorWalkingOne<T> generator;
memtest_sequential<T>(memp, generator, 1);
memtest_sequential<T>(testp, generator, 1);
}
template <typename T>
static void walking_zero(memtest_t *memp) {
static void walking_zero(memtest_t *testp) {
GeneratorWalkingZero<T> generator;
memtest_sequential<T>(memp, generator, 1);
memtest_sequential<T>(testp, generator, 1);
}
template <typename T>
static void own_address(memtest_t *memp) {
static void own_address(memtest_t *testp) {
GeneratorOwnAddress<T> generator;
memtest_sequential<T>(memp, generator, 0);
memtest_sequential<T>(testp, generator, 0);
}
template <typename T>
static void moving_inversion_zero(memtest_t *memp) {
static void moving_inversion_zero(memtest_t *testp) {
GeneratorMovingInv<T> generator;
T mask = -1;
memtest_sequential<T>(memp, generator, 0);
memtest_sequential<T>(memp, generator, 0xFFFFFFFF & mask);
memtest_sequential<T>(testp, generator, 0);
memtest_sequential<T>(testp, generator, 0xFFFFFFFF & mask);
}
template <typename T>
static void moving_inversion_55aa(memtest_t *memp) {
static void moving_inversion_55aa(memtest_t *testp) {
GeneratorMovingInv<T> generator;
T mask = -1;
memtest_sequential<T>(memp, generator, 0x55555555 & mask);
memtest_sequential<T>(memp, generator, 0xAAAAAAAA & mask);
memtest_sequential<T>(testp, generator, 0x55555555 & mask);
memtest_sequential<T>(testp, generator, 0xAAAAAAAA & mask);
}
template <typename T>
static void moving_inversion_rand(memtest_t *memp) {
static void moving_inversion_rand(memtest_t *testp) {
GeneratorMovingInvRand<T> generator;
T mask = -1;
memtest_sequential<T>(memp, generator, memp->rand_seed & mask);
memtest_sequential<T>(testp, generator, testp->rand_seed & mask);
}
/*
*
*/
static void memtest_wrapper(memtest_t *memp,
void (*p_u8)(memtest_t *memp),
void (*p_u16)(memtest_t *memp),
void (*p_u32)(memtest_t *memp)) {
switch(memp->width){
static void memtest_wrapper(memtest_t *testp,
void (*p_u8)(memtest_t *testp),
void (*p_u16)(memtest_t *testp),
void (*p_u32)(memtest_t *testp)) {
switch(testp->width){
case MEMTEST_WIDTH_32:
p_u8(memp);
p_u16(memp);
p_u32(memp);
p_u8(testp);
p_u16(testp);
p_u32(testp);
break;
case MEMTEST_WIDTH_16:
p_u8(memp);
p_u16(memp);
p_u8(testp);
p_u16(testp);
break;
case MEMTEST_WIDTH_8:
p_u8(memp);
p_u8(testp);
break;
}
}
@ -199,45 +239,45 @@ static void memtest_wrapper(memtest_t *memp,
/*
*
*/
void memtest_run(memtest_t *memp, uint32_t testmask) {
void memtest_run(memtest_t *testp, uint32_t testmask) {
if ((testmask & MEMTEST_WALKING_ONE) == MEMTEST_WALKING_ONE) {
memtest_wrapper(memp,
if (testmask & MEMTEST_WALKING_ONE) {
memtest_wrapper(testp,
walking_one<uint8_t>,
walking_one<uint16_t>,
walking_one<uint32_t>);
}
if ((testmask & MEMTEST_WALKING_ZERO) == MEMTEST_WALKING_ZERO) {
memtest_wrapper(memp,
if (testmask & MEMTEST_WALKING_ZERO) {
memtest_wrapper(testp,
walking_zero<uint8_t>,
walking_zero<uint16_t>,
walking_zero<uint32_t>);
}
if ((testmask & MEMTEST_OWN_ADDRESS) == MEMTEST_OWN_ADDRESS) {
memtest_wrapper(memp,
if (testmask & MEMTEST_OWN_ADDRESS) {
memtest_wrapper(testp,
own_address<uint8_t>,
own_address<uint16_t>,
own_address<uint32_t>);
}
if ((testmask & MEMTEST_MOVING_INVERSION_ZERO) == MEMTEST_MOVING_INVERSION_ZERO) {
memtest_wrapper(memp,
if (testmask & MEMTEST_MOVING_INVERSION_ZERO) {
memtest_wrapper(testp,
moving_inversion_zero<uint8_t>,
moving_inversion_zero<uint16_t>,
moving_inversion_zero<uint32_t>);
}
if ((testmask & MEMTEST_MOVING_INVERSION_55AA) == MEMTEST_MOVING_INVERSION_55AA) {
memtest_wrapper(memp,
if (testmask & MEMTEST_MOVING_INVERSION_55AA) {
memtest_wrapper(testp,
moving_inversion_55aa<uint8_t>,
moving_inversion_55aa<uint16_t>,
moving_inversion_55aa<uint32_t>);
}
if ((testmask & MEMTEST_MOVING_INVERSION_RAND) == MEMTEST_MOVING_INVERSION_RAND) {
memtest_wrapper(memp,
if (testmask & MEMTEST_MOVING_INVERSION_RAND) {
memtest_wrapper(testp,
moving_inversion_rand<uint8_t>,
moving_inversion_rand<uint16_t>,
moving_inversion_rand<uint32_t>);

View File

@ -1,3 +1,19 @@
/*
ChibiOS/RT - Copyright (C) 2013-2014 Uladzimir Pylinsky aka barthess
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef MEMTEST_HPP_
#define MEMTEST_HPP_
@ -8,20 +24,20 @@
#define MEMTEST_MOVING_INVERSION_55AA (1 << 4)
#define MEMTEST_MOVING_INVERSION_RAND (1 << 5)
#define MEMTEST_RUN_ALL (MEMTEST_WALKING_ONE | \
MEMTEST_WALKING_ZERO | \
MEMTEST_OWN_ADDRESS | \
MEMTEST_MOVING_INVERSION_ZERO | \
MEMTEST_MOVING_INVERSION_55AA | \
#define MEMTEST_RUN_ALL (MEMTEST_WALKING_ONE | \
MEMTEST_WALKING_ZERO | \
MEMTEST_OWN_ADDRESS | \
MEMTEST_MOVING_INVERSION_ZERO | \
MEMTEST_MOVING_INVERSION_55AA | \
MEMTEST_MOVING_INVERSION_RAND)
typedef struct memtest_t memtest_t;
typedef uint32_t testtype_t;
typedef uint32_t testtype;
/*
* Error call back.
*/
typedef void (*memtestecb_t)(memtest_t *memp, testtype_t e, size_t address);
typedef void (*memtestecb_t)(memtest_t *testp, testtype type, size_t address);
/*
*
@ -49,7 +65,7 @@ struct memtest_t {
#ifdef __cplusplus
extern "C" {
#endif
void memtest_run(memtest_t *memp, uint32_t testmask);
void memtest_run(memtest_t *testp, uint32_t testmask);
#ifdef __cplusplus
}
#endif