mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[quiz][ion/test] Move time measurements to quiz
to be able to do measurements in any test
This commit is contained in:
committed by
Émilie Feral
parent
068ed96d79
commit
bc0b21463e
@@ -1,10 +1,8 @@
|
||||
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 \
|
||||
)
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -17,6 +17,3 @@ 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);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <quiz.h>
|
||||
#include <quiz/stopwatch.h>
|
||||
#include <ion.h>
|
||||
#include <assert.h>
|
||||
#include <drivers/config/external_flash.h>
|
||||
#include <drivers/external_flash.h>
|
||||
#include "external_flash_helper.h"
|
||||
|
||||
@@ -47,56 +46,56 @@ void test(int accessType, int repeat) {
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_byte_fwd) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint8_t>(0, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_byte_bck) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint8_t>(1, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_byte_rand) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint8_t>(2, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_half_fwd) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint16_t>(0, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_half_bck) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint16_t>(1, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_half_rand) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint16_t>(2, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_word_fwd) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint32_t>(0, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_word_bck) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint32_t>(1, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_extflash_read_word_rand) {
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
test<uint32_t>(2, 1);
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
Ion::Timing::msleep(3000);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
#include <quiz.h>
|
||||
#include <drivers/config/external_flash.h>
|
||||
#include <quiz/stopwatch.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();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
Ion::Device::ExternalFlash::MassErase();
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
QUIZ_CASE(ion_ext_flash_program) {
|
||||
// Program separately each page of the flash memory
|
||||
uint64_t startTime = Ion::Timing::millis();
|
||||
uint64_t startTime = quiz_stopwatch_start();
|
||||
for (int page = 0; page < (1<<15); page++) {
|
||||
uint8_t buffer[256];
|
||||
for (int byte = 0; byte < 256; byte++) {
|
||||
@@ -22,5 +21,5 @@ QUIZ_CASE(ion_ext_flash_program) {
|
||||
}
|
||||
Ion::Device::ExternalFlash::WriteMemory(reinterpret_cast<uint8_t *>(page * 256), buffer, 256);
|
||||
}
|
||||
printElapsedTime(startTime);
|
||||
quiz_stopwatch_print_lap(startTime);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ runner_src += $(addprefix quiz/src/, \
|
||||
assertions.cpp \
|
||||
i18n.cpp \
|
||||
runner.cpp \
|
||||
stopwatch.cpp \
|
||||
)
|
||||
|
||||
runner_src += $(BUILD_DIR)/quiz/src/tests_symbols.c
|
||||
|
||||
17
quiz/include/quiz/stopwatch.h
Normal file
17
quiz/include/quiz/stopwatch.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef QUIZ_STOPWATCH_H
|
||||
#define QUIZ_STOPWATCH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint64_t quiz_stopwatch_start();
|
||||
void quiz_stopwatch_print_lap(uint64_t startTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "quiz.h"
|
||||
#include "symbols.h"
|
||||
#include <string.h>
|
||||
#include <ion.h>
|
||||
#include <kandinsky.h>
|
||||
#include <poincare/init.h>
|
||||
#include <poincare/tree_pool.h>
|
||||
#include <poincare/exception_checkpoint.h>
|
||||
|
||||
36
quiz/src/stopwatch.cpp
Normal file
36
quiz/src/stopwatch.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <quiz/stopwatch.h>
|
||||
#include "quiz.h"
|
||||
#include <ion/timing.h>
|
||||
#include <string.h>
|
||||
|
||||
uint64_t quiz_stopwatch_start() {
|
||||
return Ion::Timing::millis();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void quiz_stopwatch_print_lap(uint64_t startTime) {
|
||||
constexpr char Time[] = " time: ";
|
||||
constexpr char Ms[] = "ms";
|
||||
constexpr size_t uint64ToStringMaxLength = 20;
|
||||
constexpr size_t MaxLength = sizeof(Time) + uint64ToStringMaxLength + sizeof(Ms) + 1;
|
||||
char buffer[MaxLength];
|
||||
char * position = buffer;
|
||||
position += strlcpy(position, Time, sizeof(Time));
|
||||
position += uint64ToString(Ion::Timing::millis() - startTime, position);
|
||||
position += strlcpy(position, Ms, sizeof(Ms));
|
||||
quiz_print(buffer);
|
||||
}
|
||||
Reference in New Issue
Block a user