[ion] test.external_flash: split this test target into two targets -

test.external_flash.write and test.external_flash.read
This commit is contained in:
Émilie Feral
2019-07-11 11:13:29 +02:00
parent e89389591d
commit 6b3d2cc8df
7 changed files with 93 additions and 72 deletions

View File

@@ -1,4 +1,12 @@
TEST_EXT_FLASH_REPROGRAM ?= 0
SFLAGS += -DTEST_EXT_FLASH_REPROGRAM=$(TEST_EXT_FLASH_REPROGRAM)
test_ion_external_flash_src += ion/test/$(PLATFORM)/$(MODEL)/external_flash.cpp
test_ion_external_flash_read_src += $(addprefix ion/test/$(PLATFORM)/$(MODEL)/, \
external_flash_helper.cpp \
external_flash_read.cpp \
)
test_ion_external_flash_write_src += $(addprefix ion/test/$(PLATFORM)/$(MODEL)/, \
external_flash_helper.cpp \
external_flash_write.cpp \
)
test_ion_external_flash_src += $(test_ion_external_flash_read_src) $(test_ion_external_flash_write_src)
$(call object_for,$(test_ion_external_flash_src)): SFLAGS += $(ION_DEVICE_SFLAGS)

View File

@@ -0,0 +1,26 @@
#include "ion/include/ion/timing.h"
#include <quiz.h>
#include <stddef.h>
size_t uint64ToString(uint64_t n, char buffer[]) {
size_t len = 0;
do {
buffer[len++] = (n % 10) + '0';
} while ((n /= 10) > 0);
int i = 0;
int j = len - 1;
while (i < j) {
char c = buffer[i];
buffer[i++] = buffer[j];
buffer[j--] = c;
}
return len;
}
void printElapsedTime(uint64_t startTime) {
char buffer[7+26+2] = " time: ";
size_t len = uint64ToString((Ion::Timing::millis() - startTime)/1000, buffer+7);
buffer[7+len] = 's';
buffer[7+len+1] = 0;
quiz_print(buffer);
}

View File

@@ -0,0 +1,22 @@
#include <drivers/config/external_flash.h>
// Choose some not too uniform data to program and test the external flash memory with.
inline uint8_t expected_value_at(uint8_t * ptr) {
uint32_t address = reinterpret_cast<uint32_t>(ptr) - Ion::Device::ExternalFlash::Config::StartAddress;
return (address / 0x10000) + (address / 0x100) + address;
// Example: the value expected at the address 0x123456 is 0x12 + 0x34 + 0x56.
}
inline uint16_t expected_value_at(uint16_t * ptr) {
uint8_t * ptr8 = reinterpret_cast<uint8_t *>(ptr);
return (static_cast<uint16_t>(expected_value_at(ptr8+1)) << 8) | static_cast<uint16_t>(expected_value_at(ptr8));
}
inline uint32_t expected_value_at(uint32_t * ptr) {
uint16_t * ptr16 = reinterpret_cast<uint16_t *>(ptr);
return (static_cast<uint32_t>(expected_value_at(ptr16+1)) << 16) + static_cast<uint32_t>(expected_value_at(ptr16));
}
size_t uint64ToString(uint64_t n, char buffer[]);
void printElapsedTime(uint64_t startTime);

View File

@@ -3,25 +3,7 @@
#include <assert.h>
#include <drivers/config/external_flash.h>
#include <drivers/external_flash.h>
#include "ion/include/ion/timing.h"
// Choose some not too uniform data to program and test the external flash memory with.
static inline uint8_t expected_value_at(uint8_t * ptr) {
uint32_t address = reinterpret_cast<uint32_t>(ptr) - Ion::Device::ExternalFlash::Config::StartAddress;
return (address / 0x10000) + (address / 0x100) + address;
// Example: the value expected at the address 0x123456 is 0x12 + 0x34 + 0x56.
}
static inline uint16_t expected_value_at(uint16_t * ptr) {
uint8_t * ptr8 = reinterpret_cast<uint8_t *>(ptr);
return (static_cast<uint16_t>(expected_value_at(ptr8+1)) << 8) | static_cast<uint16_t>(expected_value_at(ptr8));
}
static inline uint32_t expected_value_at(uint32_t * ptr) {
uint16_t * ptr16 = reinterpret_cast<uint16_t *>(ptr);
return (static_cast<uint32_t>(expected_value_at(ptr16+1)) << 16) + static_cast<uint32_t>(expected_value_at(ptr16));
}
#include "external_flash_helper.h"
template <typename T>
static inline void check(volatile T * p, int repeat) {
@@ -64,52 +46,6 @@ void test(int accessType, int repeat) {
}
}
static size_t uint64ToString(uint64_t n, char buffer[]) {
size_t len = 0;
do {
buffer[len++] = (n % 10) + '0';
} while ((n /= 10) > 0);
int i = 0;
int j = len - 1;
while (i < j) {
char c = buffer[i];
buffer[i++] = buffer[j];
buffer[j--] = c;
}
return len;
}
static void printElapsedTime(uint64_t startTime) {
char buffer[7+26+2] = " time: ";
size_t len = uint64ToString((Ion::Timing::millis() - startTime)/1000, buffer+7);
buffer[7+len] = 's';
buffer[7+len+1] = 0;
quiz_print(buffer);
}
QUIZ_CASE(ion_ext_flash_erase) {
#if TEST_EXT_FLASH_REPROGRAM
uint64_t startTime = Ion::Timing::millis();
Ion::Device::ExternalFlash::MassErase();
printElapsedTime(startTime);
#endif
}
QUIZ_CASE(ion_ext_flash_program) {
#if TEST_EXT_FLASH_REPROGRAM
// Program separately each page of the flash memory
uint64_t startTime = Ion::Timing::millis();
for (int page = 0; page < (1<<15); page++) {
uint8_t buffer[256];
for (int byte = 0; byte < 256; byte++) {
buffer[byte] = expected_value_at(reinterpret_cast<uint8_t *>(Ion::Device::ExternalFlash::Config::StartAddress + page * 256 + byte));
}
Ion::Device::ExternalFlash::WriteMemory(reinterpret_cast<uint8_t *>(page * 256), buffer, 256);
}
printElapsedTime(startTime);
#endif
}
QUIZ_CASE(ion_extflash_read_byte_fwd) {
uint64_t startTime = Ion::Timing::millis();
test<uint8_t>(0, 1);

View File

@@ -0,0 +1,26 @@
#include <quiz.h>
#include <drivers/config/external_flash.h>
#include <drivers/external_flash.h>
#include "ion/include/ion/timing.h"
#include "external_flash_helper.h"
// Choose some not too uniform data to program the external flash memory with.
QUIZ_CASE(ion_ext_flash_erase) {
uint64_t startTime = Ion::Timing::millis();
Ion::Device::ExternalFlash::MassErase();
printElapsedTime(startTime);
}
QUIZ_CASE(ion_ext_flash_program) {
// Program separately each page of the flash memory
uint64_t startTime = Ion::Timing::millis();
for (int page = 0; page < (1<<15); page++) {
uint8_t buffer[256];
for (int byte = 0; byte < 256; byte++) {
buffer[byte] = expected_value_at(reinterpret_cast<uint8_t *>(Ion::Device::ExternalFlash::Config::StartAddress + page * 256 + byte));
}
Ion::Device::ExternalFlash::WriteMemory(reinterpret_cast<uint8_t *>(page * 256), buffer, 256);
}
printElapsedTime(startTime);
}

View File

@@ -10,7 +10,8 @@ $$(BUILD_DIR)/quiz/src/$(subst _src,,$(1))_symbols.c: $$($(1)) | $$$$(@D)/.
endef
$(eval $(call rule_for_quiz_symbols,tests))
$(eval $(call rule_for_quiz_symbols,test_ion_external_flash_src))
$(eval $(call rule_for_quiz_symbols,test_ion_external_flash_write_src))
$(eval $(call rule_for_quiz_symbols,test_ion_external_flash_read_src))
runner_src += $(addprefix quiz/src/, \
assertions.cpp \

View File

@@ -1,4 +1,6 @@
executables += test.external_flash
executables += test.external_flash.write test.external_flash.read
$(BUILD_DIR)/test.external_flash.$(EXE): LDSCRIPT = ion/test/device/n0110/external_flash_tests.ld
$(BUILD_DIR)/test.external_flash.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_external_flash_symbols.o $(call object_for,$(src) $(ion_device_dfu_relocated_src) $(test_ion_external_flash_src) $(runner_src))
$(BUILD_DIR)/test.external_flash.%.$(EXE): LDSCRIPT = ion/test/device/n0110/external_flash_tests.ld
test_external_flash_src = $(src) $(ion_device_dfu_relogated_src) $(runner_src)
$(BUILD_DIR)/test.external_flash.read.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_external_flash_read_symbols.o $(call object_for,$(test_external_flash_src) $(test_ion_external_flash_read_src))
$(BUILD_DIR)/test.external_flash.write.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_external_flash_write_symbols.o $(call object_for,$(test_external_flash_src) $(test_ion_external_flash_write_src))