STORAGE: removal of unsupported tests having ported to https://github.com/ARMmbed/sd-driver basic.cpp test.

pull/3846/head
Simon Hughes 2017-02-27 17:37:30 +00:00
parent 3a27568a50
commit 8d084de412
7 changed files with 0 additions and 848 deletions

View File

@ -1,124 +0,0 @@
#include "mbed.h"
#include "SDFileSystem.h"
void led_blink(PinName led)
{
DigitalOut myled(led);
while (1) {
myled = !myled;
wait(1.0);
}
}
void notify_completion(bool success)
{
if (success)
printf("{success}\n");
else
printf("{failure}\n");
printf("{end}\n");
led_blink(success ? LED1 : LED4);
}
#define TEST_STRING "Hello World!"
FILE *test_open(char *path, const char *mode)
{
FILE *f;
f = fopen(path, mode);
if (f == NULL) {
printf("Error opening file\n");
notify_completion(false);
}
return f;
}
void test_write(FILE *f, const char *str)
{
int n = fprintf(f, str);
if (n != strlen(str)) {
printf("Error writing file\n");
notify_completion(false);
}
}
void test_close(FILE *f)
{
int rc = fclose(f);
if (rc != 0) {
printf("Error closing file\n");
notify_completion(false);
}
}
DigitalOut led2(LED2);
int main()
{
#if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#elif defined(TARGET_nRF51822)
//SDFileSystem sd(p20, p22, p25, p24, "sd");
SDFileSystem sd(p12, p13, p15, p14, "sd");
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC11U37H_401)
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
#elif defined(TARGET_NUMAKER_PFM_NUC472)
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
#elif defined(TARGET_NUMAKER_PFM_M453)
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
#else
SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
led2 = 1;
wait(0.5);
FILE *f;
char *str = TEST_STRING;
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
int str_len = strlen(TEST_STRING);
printf("Write files\n");
char filename[32];
for (int i = 0; i < 10; i++) {
sprintf(filename, "/sd/test_%d.txt", i);
printf("Creating file: %s\n", filename);
f = test_open(filename, "w");
led2 = 0;
test_write(f, str);
test_close(f);
}
printf("List files:\n");
DIR *d = opendir("/sd");
if (d == NULL) {
printf("Error opening directory\n");
notify_completion(false);
}
struct dirent *p;
while ((p = readdir(d)) != NULL)
printf("%s\n", p->d_name);
closedir(d);
notify_completion(true);
}

View File

@ -1,78 +0,0 @@
#include "test_env.h"
#include "mbed_semihost_api.h"
Serial pc(USBTX, USBRX);
#define FILENAME "/local/out.txt"
#define TEST_STRING "Hello World!"
FILE *test_open(const char *mode) {
FILE *f = fopen(FILENAME, mode);
if (f == NULL) {
printf("Error opening file"NL);
notify_completion(false);
}
return f;
}
void test_write(FILE *f, char *str, int str_len) {
int n = fprintf(f, str);
if (n != str_len) {
printf("Error writing file"NL);
notify_completion(false);
}
}
void test_read(FILE *f, char *str, int str_len) {
int n = fread(str, sizeof(unsigned char), str_len, f);
if (n != str_len) {
printf("Error reading file"NL);
notify_completion(false);
}
}
void test_close(FILE *f) {
int rc = fclose(f);
if (rc != 0) {
printf("Error closing file"NL);
notify_completion(false);
}
}
int main() {
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(Semihost file system);
MBED_HOSTTEST_START("MBED_A2");
pc.printf("Test the Stream class\n");
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
char mac[16];
mbed_mac_address(mac);
printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
LocalFileSystem local("local");
FILE *f;
char *str = TEST_STRING;
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
int str_len = strlen(TEST_STRING);
// Write
f = test_open("w");
test_write(f, str, str_len);
test_close(f);
// Read
f = test_open("r");
test_read(f, buffer, str_len);
test_close(f);
// Check the two strings are equal
MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0));
}

View File

@ -1,32 +0,0 @@
#include "mbed.h"
#include "rtos.h"
#include "SDFileSystem.h"
#define FILE_LOC "/sd/test.txt"
Serial pc(USBTX, USBRX);
Serial gps(p28, p27);
Serial test(p9,p10);
SDFileSystem sd(p11, p12, p13, p14, "sd");
DigitalOut myled(LED1);
DigitalOut sdled(LED2);
void sd_thread(void const *argument) {
while (true) {
sdled = !sdled;
FILE *fp = NULL;
fp = fopen(FILE_LOC, "w");
if( fp != NULL ) fclose(fp);
Thread::wait(1000);
}
}
int main() {
Thread sdTask(sd_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
while (true) {
myled = !myled;
Thread::wait(1000);
}
}

View File

@ -1,120 +0,0 @@
#include "mbed.h"
#include "SDFileSystem.h"
#include "test_env.h"
#if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
#elif defined(TARGET_K22F)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K20D50M)
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
#elif defined(TARGET_nRF51822)
SDFileSystem sd(p12, p13, p15, p14, "sd");
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_DISCO_F051R8) || \
defined(TARGET_NUCLEO_L031K6)
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
#elif defined(TARGET_LPC2368)
SDFileSystem sd(p11, p12, p13, p14, "sd");
#elif defined(TARGET_LPC11U68)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC1549)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_RZ_A1H)
SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd");
#elif defined(TARGET_LPC11U37H_401)
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
#elif defined(TARGET_NUMAKER_PFM_NUC472)
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
#elif defined(TARGET_NUMAKER_PFM_M453)
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
#else
SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
namespace {
const char *sd_file_path = "/sd/out.txt";
const int DATA_SIZE = 256;
}
int main() {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(SD File System);
MBED_HOSTTEST_START("MBED_A12");
uint8_t data_written[DATA_SIZE] = { 0 };
bool result = false;
// Fill data_written buffer with random data
// Write these data into the file
bool write_result = false;
{
printf("SD: Writing ... ");
FILE *f = fopen(sd_file_path, "w");
if (f) {
for (int i = 0; i < DATA_SIZE; i++) {
data_written[i] = rand() % 0XFF;
fprintf(f, "%c", data_written[i]);
}
write_result = true;
fclose(f);
}
printf("[%s]\r\n", write_result ? "OK" : "FAIL");
}
// Read back the data from the file and store them in data_read
bool read_result = false;
{
printf("SD: Reading data ... ");
FILE *f = fopen(sd_file_path, "r");
if (f) {
read_result = true;
for (int i = 0; i < DATA_SIZE; i++) {
uint8_t data = fgetc(f);
if (data != data_written[i]) {
read_result = false;
break;
}
}
fclose(f);
}
printf("[%s]\r\n", read_result ? "OK" : "FAIL");
}
result = write_result && read_result;
MBED_HOSTTEST_RESULT(result);
}

View File

@ -1,168 +0,0 @@
#include "mbed.h"
#include "SDFileSystem.h"
#include "test_env.h"
#include <algorithm>
#include <stdlib.h>
#if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
#elif defined(TARGET_K22F)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K20D50M)
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
#elif defined(TARGET_nRF51822)
SDFileSystem sd(p12, p13, p15, p14, "sd");
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_DISCO_F051R8)
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
#elif defined(TARGET_LPC2368)
SDFileSystem sd(p11, p12, p13, p14, "sd");
#elif defined(TARGET_LPC11U68)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC1549)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC11U37H_401)
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
#elif defined(TARGET_NUMAKER_PFM_NUC472)
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
#elif defined(TARGET_NUMAKER_PFM_M453)
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
#else
SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
namespace {
char buffer[1024];
const int KIB_RW = 128;
Timer timer;
const char *bin_filename = "0:testfile.bin";
}
bool test_sf_file_write_fatfs(const char *filename, const int kib_rw) {
FIL file;
bool result = true;
FRESULT res = f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
if (res == FR_OK) {
int byte_write = 0;
unsigned int bytes = 0;
timer.start();
for (int i = 0; i < kib_rw; i++) {
if (f_write(&file, buffer, sizeof(buffer), &bytes) != FR_OK) {
result = false;
f_close(&file);
printf("Write error!\r\n");
break;
} else {
byte_write++;
}
}
timer.stop();
f_close(&file);
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
notify_performance_coefficient("write_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
bool test_sf_file_read_fatfs(const char *filename, const int kib_rw) {
FIL file;
bool result = true;
FRESULT res = f_open(&file, filename, FA_READ | FA_OPEN_EXISTING);
if (res == FR_OK) {
timer.start();
int byte_read = 0;
unsigned int bytes = 0;
do {
res = f_read(&file, buffer, sizeof(buffer), &bytes);
byte_read++;
} while (res == FR_OK && bytes == sizeof(buffer));
timer.stop();
f_close(&file);
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
notify_performance_coefficient("fs_read_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
char RandomChar() {
return rand() % 100;
}
int main() {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(SD FatFS RW Speed);
MBED_HOSTTEST_START("PERF_3");
// Test header
printf("\r\n");
printf("SD Card FatFS Performance Test\r\n");
printf("File name: %s\r\n", bin_filename);
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
// Initialize buffer
srand(testenv_randseed());
char *buffer_end = buffer + sizeof(buffer);
std::generate (buffer, buffer_end, RandomChar);
bool result = true;
for (;;) {
printf("Write test...\r\n");
if (test_sf_file_write_fatfs(bin_filename, KIB_RW) == false) {
result = false;
break;
}
printf("Read test...\r\n");
if (test_sf_file_read_fatfs(bin_filename, KIB_RW) == false) {
result = false;
break;
}
break;
}
MBED_HOSTTEST_RESULT(result);
}

View File

@ -1,163 +0,0 @@
#include "mbed.h"
#include "SDFileSystem.h"
#include "test_env.h"
#include <algorithm>
#include <stdlib.h>
#if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
#elif defined(TARGET_K22F)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K20D50M)
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
#elif defined(TARGET_nRF51822)
SDFileSystem sd(p12, p13, p15, p14, "sd");
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_DISCO_F051R8)
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
#elif defined(TARGET_LPC2368)
SDFileSystem sd(p11, p12, p13, p14, "sd");
#elif defined(TARGET_LPC11U68)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC1549)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC11U37H_401)
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
#elif defined(TARGET_NUMAKER_PFM_NUC472)
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
#elif defined(TARGET_NUMAKER_PFM_M453)
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
#else
SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
namespace {
char buffer[1024];
const int KIB_RW = 128;
Timer timer;
const char *bin_filename = "testfile.bin";
}
bool test_sf_file_write_fhandle(const char *filename, const int kib_rw) {
bool result = true;
FileHandle* file = sd.open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (file != NULL) {
int byte_write = 0;
timer.start();
for (int i = 0; i < kib_rw; i++) {
if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
result = false;
file->close();
printf("Write error!\r\n");
break;
} else {
byte_write++;
}
}
timer.stop();
file->close();
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
notify_performance_coefficient("write_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
bool test_sf_file_read_fhandle(const char *filename, const int kib_rw) {
bool result = true;
FileHandle* file = sd.open(filename, O_RDONLY);
if (file) {
timer.start();
int byte_read = 0;
while (file->read(buffer, sizeof(buffer)) == sizeof(buffer)) {
byte_read++;
}
timer.stop();
file->close();
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
notify_performance_coefficient("fs_read_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
char RandomChar() {
return rand() % 100;
}
int main() {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(SD FileHandle RW Speed);
MBED_HOSTTEST_START("PERF_2");
// Test header
printf("\r\n");
printf("SD Card FileHandle Performance Test\r\n");
printf("File name: %s\r\n", bin_filename);
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
// Initialize buffer
srand(testenv_randseed());
char *buffer_end = buffer + sizeof(buffer);
std::generate (buffer, buffer_end, RandomChar);
bool result = true;
for (;;) {
printf("Write test...\r\n");
if (test_sf_file_write_fhandle(bin_filename, KIB_RW) == false) {
result = false;
break;
}
printf("Read test...\r\n");
if (test_sf_file_read_fhandle(bin_filename, KIB_RW) == false) {
result = false;
break;
}
break;
}
MBED_HOSTTEST_RESULT(result);
}

View File

@ -1,163 +0,0 @@
#include "mbed.h"
#include "SDFileSystem.h"
#include "test_env.h"
#include <algorithm>
#include <stdlib.h>
#if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
#elif defined(TARGET_K22F)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#elif defined(TARGET_K20D50M)
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
#elif defined(TARGET_nRF51822)
SDFileSystem sd(p12, p13, p15, p14, "sd");
#elif defined(TARGET_NUCLEO_F030R8) || \
defined(TARGET_NUCLEO_F070RB) || \
defined(TARGET_NUCLEO_F072RB) || \
defined(TARGET_NUCLEO_F091RC) || \
defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_F302R8) || \
defined(TARGET_NUCLEO_F303RE) || \
defined(TARGET_NUCLEO_F334R8) || \
defined(TARGET_NUCLEO_F401RE) || \
defined(TARGET_NUCLEO_F410RB) || \
defined(TARGET_NUCLEO_F411RE) || \
defined(TARGET_NUCLEO_L053R8) || \
defined(TARGET_NUCLEO_L073RZ) || \
defined(TARGET_NUCLEO_L152RE)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_DISCO_F051R8)
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
#elif defined(TARGET_LPC2368)
SDFileSystem sd(p11, p12, p13, p14, "sd");
#elif defined(TARGET_LPC11U68)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC1549)
SDFileSystem sd(D11, D12, D13, D10, "sd");
#elif defined(TARGET_LPC11U37H_401)
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
#elif defined(TARGET_NUMAKER_PFM_NUC472)
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
#elif defined(TARGET_NUMAKER_PFM_M453)
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
#else
SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
namespace {
char buffer[1024];
const int KIB_RW = 128;
Timer timer;
const char *bin_filename = "/sd/testfile.bin";
}
bool test_sf_file_write_stdio(const char *filename, const int kib_rw) {
bool result = true;
FILE* file = fopen(filename, "w");
if (file != NULL) {
int byte_write = 0;
timer.start();
for (int i = 0; i < kib_rw; i++) {
if (fwrite(buffer, sizeof(char), sizeof(buffer), file) != sizeof(buffer)) {
result = false;
fclose(file);
printf("Write error!\r\n");
break;
} else {
byte_write++;
}
}
timer.stop();
fclose(file);
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
notify_performance_coefficient("write_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
bool test_sf_file_read_stdio(const char *filename, const int kib_rw) {
bool result = true;
FILE* file = fopen(filename, "r");
if (file) {
timer.start();
int byte_read = 0;
while (fread(buffer, sizeof(char), sizeof(buffer), file) == sizeof(buffer)) {
byte_read++;
}
timer.stop();
fclose(file);
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
notify_performance_coefficient("fs_read_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
char RandomChar() {
return rand() % 100;
}
int main() {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(SD stdio RW Speed);
MBED_HOSTTEST_START("PERF_1");
// Test header
printf("\r\n");
printf("SD Card Stdio Performance Test\r\n");
printf("File name: %s\r\n", bin_filename);
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
// Initialize buffer
srand(testenv_randseed());
char *buffer_end = buffer + sizeof(buffer);
std::generate (buffer, buffer_end, RandomChar);
bool result = true;
for (;;) {
printf("Write test...\r\n");
if (test_sf_file_write_stdio(bin_filename, KIB_RW) == false) {
result = false;
break;
}
printf("Read test...\r\n");
if (test_sf_file_read_stdio(bin_filename, KIB_RW) == false) {
result = false;
break;
}
break;
}
MBED_HOSTTEST_RESULT(result);
}