From 5eb40d38ca22411058093f5e9ee6313bae6c8deb Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Thu, 24 Apr 2014 14:41:53 +0100 Subject: [PATCH] Small refactoring + code indent --- libraries/tests/mbed/file/main.cpp | 45 ++++++++++++++----------- libraries/tests/mbed/hello/main.cpp | 12 +++---- libraries/tests/rtos/mbed/file/main.cpp | 26 +++++++------- workspace_tools/tests.py | 4 +-- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/libraries/tests/mbed/file/main.cpp b/libraries/tests/mbed/file/main.cpp index 992f936579..4e237a6be7 100644 --- a/libraries/tests/mbed/file/main.cpp +++ b/libraries/tests/mbed/file/main.cpp @@ -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)); } diff --git a/libraries/tests/mbed/hello/main.cpp b/libraries/tests/mbed/hello/main.cpp index 578eafbab0..b20fc02ec6 100644 --- a/libraries/tests/mbed/hello/main.cpp +++ b/libraries/tests/mbed/hello/main.cpp @@ -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); } diff --git a/libraries/tests/rtos/mbed/file/main.cpp b/libraries/tests/rtos/mbed/file/main.cpp index dd08557142..017040dfdb 100644 --- a/libraries/tests/rtos/mbed/file/main.cpp +++ b/libraries/tests/rtos/mbed/file/main.cpp @@ -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) { diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index cc221202d0..2468850917 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -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++",