Small refactoring + code indent

pull/275/head^2
Przemek Wirkus 2014-04-24 14:41:53 +01:00
parent 4927a9d7e3
commit 5eb40d38ca
4 changed files with 45 additions and 42 deletions

View File

@ -1,73 +1,78 @@
#include "test_env.h"
#include "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;
f = fopen(FILENAME, mode);
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) {
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) {
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) {
void test_close(FILE *f)
{
int rc = fclose(f);
if (rc != 0) {
printf("Error closing file"NL);
notify_completion(false);
}
}
int main() {
int main()
{
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]);
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));
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
notify_completion((strncmp(buffer, str, str_len) == 0));
}

View File

@ -1,11 +1,7 @@
#include "mbed.h"
#include "test_env.h"
DigitalOut myled(LED1);
int main() {
int main()
{
printf("Hello World\n");
while (true) {
wait(0.5);
myled = !myled;
}
notify_completion(true);
}

View File

@ -7,18 +7,23 @@ DigitalOut led2(LED2);
#define SIZE 120
void sd_thread(void const *argument) {
void sd_thread(void const *argument)
{
const char *FILE_NAME = "/sd/out.txt";
#if defined(TARGET_KL25Z)
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#elif defined(TARGET_KL46Z)
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
#else
SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
// Allocate data buffers
uint8_t data_written[SIZE] = {0};
uint8_t data_read[SIZE] = {0};
uint8_t data_written[SIZE] = { 0 };
uint8_t data_read[SIZE] = { 0 };
{
// fill data_written buffer with random data
@ -30,13 +35,11 @@ void sd_thread(void const *argument) {
data_written[i] = rand() % 0xff;
fprintf(f, "%c", data_written[i]);
printf("%02X ", data_written[i]);
if (i && ((i % 20) == 19)) {
if (i && ((i % 20) == 19))
printf("\r\n");
}
}
fclose(f);
}
else {
} else {
notify_completion(false);
return;
}
@ -51,13 +54,11 @@ void sd_thread(void const *argument) {
for (int i = 0; i < SIZE; i++) {
data_read[i] = fgetc(f);
printf("%02X ", data_read[i]);
if (i && ((i % 20) == 19)) {
if (i && ((i % 20) == 19))
printf("\r\n");
}
}
fclose(f);
}
else {
} else {
notify_completion(false);
return;
}
@ -74,7 +75,8 @@ void sd_thread(void const *argument) {
notify_completion(true);
}
int main() {
int main()
{
Thread t(sd_thread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25));
while (true) {

View File

@ -329,7 +329,7 @@ TESTS = [
{
"id": "MBED_10", "description": "Hello World",
"source_dir": join(TEST_DIR, "mbed", "hello"),
"dependencies": [MBED_LIBRARIES],
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"automated": True,
"host_test": "hello_auto",
},
@ -339,7 +339,7 @@ TESTS = [
"dependencies": [MBED_LIBRARIES],
"automated": True,
"host_test": "wait_us_auto",
"duration": 20
"duration": 20,
},
{
"id": "MBED_12", "description": "C++",