Example

Dependencies:   FXAS21002 FXOS8700Q

Committer:
maygup01
Date:
Tue Nov 19 09:49:38 2019 +0000
Revision:
0:11cc2b7889af
Example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maygup01 0:11cc2b7889af 1 /*
maygup01 0:11cc2b7889af 2 * mbed Microcontroller Library
maygup01 0:11cc2b7889af 3 * Copyright (c) 2006-2018 ARM Limited
maygup01 0:11cc2b7889af 4 *
maygup01 0:11cc2b7889af 5 * SPDX-License-Identifier: Apache-2.0
maygup01 0:11cc2b7889af 6 *
maygup01 0:11cc2b7889af 7 * Licensed under the Apache License, Version 2.0 (the "License");
maygup01 0:11cc2b7889af 8 * you may not use this file except in compliance with the License.
maygup01 0:11cc2b7889af 9 * You may obtain a copy of the License at
maygup01 0:11cc2b7889af 10 *
maygup01 0:11cc2b7889af 11 * http://www.apache.org/licenses/LICENSE-2.0
maygup01 0:11cc2b7889af 12 *
maygup01 0:11cc2b7889af 13 * Unless required by applicable law or agreed to in writing, software
maygup01 0:11cc2b7889af 14 * distributed under the License is distributed on an "AS IS" BASIS,
maygup01 0:11cc2b7889af 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
maygup01 0:11cc2b7889af 16 * See the License for the specific language governing permissions and
maygup01 0:11cc2b7889af 17 * limitations under the License.
maygup01 0:11cc2b7889af 18 */
maygup01 0:11cc2b7889af 19
maygup01 0:11cc2b7889af 20 /*
maygup01 0:11cc2b7889af 21 * Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
maygup01 0:11cc2b7889af 22 */
maygup01 0:11cc2b7889af 23
maygup01 0:11cc2b7889af 24 #include "mbed.h"
maygup01 0:11cc2b7889af 25 #include "FATFileSystem.h"
maygup01 0:11cc2b7889af 26 #include "LittleFileSystem.h"
maygup01 0:11cc2b7889af 27 #include "utest/utest.h"
maygup01 0:11cc2b7889af 28 #include "unity/unity.h"
maygup01 0:11cc2b7889af 29 #include "greentea-client/test_env.h"
maygup01 0:11cc2b7889af 30 #include "common_defines_test.h"
maygup01 0:11cc2b7889af 31 #include "file_test.h"
maygup01 0:11cc2b7889af 32
maygup01 0:11cc2b7889af 33 #ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
maygup01 0:11cc2b7889af 34 #include MBED_CONF_APP_BASICS_TEST_FILENAME
maygup01 0:11cc2b7889af 35 #else
maygup01 0:11cc2b7889af 36 #include "alice.h"
maygup01 0:11cc2b7889af 37 #endif
maygup01 0:11cc2b7889af 38
maygup01 0:11cc2b7889af 39 #ifndef MBED_CONF_APP_TESTS_FS_SIZE
maygup01 0:11cc2b7889af 40 #define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
maygup01 0:11cc2b7889af 41 #endif
maygup01 0:11cc2b7889af 42
maygup01 0:11cc2b7889af 43 using namespace utest::v1;
maygup01 0:11cc2b7889af 44
maygup01 0:11cc2b7889af 45 #if !defined(MBED_CONF_APP_NO_LED)
maygup01 0:11cc2b7889af 46 DigitalOut led1(LED1);
maygup01 0:11cc2b7889af 47 DigitalOut led2(LED2);
maygup01 0:11cc2b7889af 48 void led_thread() {
maygup01 0:11cc2b7889af 49 led1 = !led1;
maygup01 0:11cc2b7889af 50 led2 = !led1;
maygup01 0:11cc2b7889af 51 }
maygup01 0:11cc2b7889af 52 #endif
maygup01 0:11cc2b7889af 53
maygup01 0:11cc2b7889af 54 BlockDevice* bd = BlockDevice::get_default_instance();
maygup01 0:11cc2b7889af 55 SlicingBlockDevice sd(bd, 0, MBED_CONF_APP_TESTS_FS_SIZE);
maygup01 0:11cc2b7889af 56 #if TEST_USE_FILESYSTEM == FS_FAT
maygup01 0:11cc2b7889af 57 FATFileSystem fs("sd");
maygup01 0:11cc2b7889af 58 #else
maygup01 0:11cc2b7889af 59 LittleFileSystem fs("sd");
maygup01 0:11cc2b7889af 60 #endif
maygup01 0:11cc2b7889af 61
maygup01 0:11cc2b7889af 62 static control_t test_format(const size_t call_count) {
maygup01 0:11cc2b7889af 63 int mount_err = fs.mount(&sd);
maygup01 0:11cc2b7889af 64 TEST_ASSERT_EQUAL_INT_MESSAGE(0, mount_err, "could not mount block device");
maygup01 0:11cc2b7889af 65
maygup01 0:11cc2b7889af 66 int format_err = fs.reformat(&sd);
maygup01 0:11cc2b7889af 67 TEST_ASSERT_EQUAL_INT_MESSAGE(0, format_err, "could not format block device");
maygup01 0:11cc2b7889af 68
maygup01 0:11cc2b7889af 69 return CaseNext;
maygup01 0:11cc2b7889af 70 }
maygup01 0:11cc2b7889af 71
maygup01 0:11cc2b7889af 72 static control_t test_block_size_1(const size_t call_count) {
maygup01 0:11cc2b7889af 73 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 1);
maygup01 0:11cc2b7889af 74 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 1);
maygup01 0:11cc2b7889af 75
maygup01 0:11cc2b7889af 76 return CaseNext;
maygup01 0:11cc2b7889af 77 }
maygup01 0:11cc2b7889af 78 static control_t test_block_size_4(const size_t call_count) {
maygup01 0:11cc2b7889af 79 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 4);
maygup01 0:11cc2b7889af 80 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 4);
maygup01 0:11cc2b7889af 81
maygup01 0:11cc2b7889af 82 return CaseNext;
maygup01 0:11cc2b7889af 83 }
maygup01 0:11cc2b7889af 84 static control_t test_block_size_16(const size_t call_count) {
maygup01 0:11cc2b7889af 85 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 16);
maygup01 0:11cc2b7889af 86 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 16);
maygup01 0:11cc2b7889af 87
maygup01 0:11cc2b7889af 88 return CaseNext;
maygup01 0:11cc2b7889af 89 }
maygup01 0:11cc2b7889af 90 static control_t test_block_size_64(const size_t call_count) {
maygup01 0:11cc2b7889af 91 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 64);
maygup01 0:11cc2b7889af 92 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 64);
maygup01 0:11cc2b7889af 93
maygup01 0:11cc2b7889af 94 return CaseNext;
maygup01 0:11cc2b7889af 95 }
maygup01 0:11cc2b7889af 96 static control_t test_block_size_256(const size_t call_count) {
maygup01 0:11cc2b7889af 97 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 256);
maygup01 0:11cc2b7889af 98 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 256);
maygup01 0:11cc2b7889af 99
maygup01 0:11cc2b7889af 100 return CaseNext;
maygup01 0:11cc2b7889af 101 }
maygup01 0:11cc2b7889af 102 static control_t test_block_size_1k(const size_t call_count) {
maygup01 0:11cc2b7889af 103 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 1024);
maygup01 0:11cc2b7889af 104 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 1024);
maygup01 0:11cc2b7889af 105
maygup01 0:11cc2b7889af 106 return CaseNext;
maygup01 0:11cc2b7889af 107 }
maygup01 0:11cc2b7889af 108 static control_t test_block_size_4k(const size_t call_count) {
maygup01 0:11cc2b7889af 109 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 4*1024);
maygup01 0:11cc2b7889af 110 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 4*1024);
maygup01 0:11cc2b7889af 111
maygup01 0:11cc2b7889af 112 return CaseNext;
maygup01 0:11cc2b7889af 113 }
maygup01 0:11cc2b7889af 114 static control_t test_block_size_16k(const size_t call_count) {
maygup01 0:11cc2b7889af 115 file_test_write("mbed-file-test-0.txt", 0, story, sizeof(story), 16*1024);
maygup01 0:11cc2b7889af 116 file_test_read("mbed-file-test-0.txt", 0, story, sizeof(story), 16*1024);
maygup01 0:11cc2b7889af 117
maygup01 0:11cc2b7889af 118 return CaseNext;
maygup01 0:11cc2b7889af 119 }
maygup01 0:11cc2b7889af 120
maygup01 0:11cc2b7889af 121 utest::v1::status_t greentea_setup(const size_t number_of_cases) {
maygup01 0:11cc2b7889af 122 GREENTEA_SETUP(5*60, "default_auto");
maygup01 0:11cc2b7889af 123 return greentea_test_setup_handler(number_of_cases);
maygup01 0:11cc2b7889af 124 }
maygup01 0:11cc2b7889af 125
maygup01 0:11cc2b7889af 126 Case cases[] = {
maygup01 0:11cc2b7889af 127 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " format", test_format),
maygup01 0:11cc2b7889af 128 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 1", test_block_size_1),
maygup01 0:11cc2b7889af 129 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 4", test_block_size_4),
maygup01 0:11cc2b7889af 130 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 16", test_block_size_16),
maygup01 0:11cc2b7889af 131 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 64", test_block_size_64),
maygup01 0:11cc2b7889af 132 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 256", test_block_size_256),
maygup01 0:11cc2b7889af 133 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 1024", test_block_size_1k),
maygup01 0:11cc2b7889af 134 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 4096", test_block_size_4k),
maygup01 0:11cc2b7889af 135 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 1 file, buff 16384", test_block_size_16k),
maygup01 0:11cc2b7889af 136 };
maygup01 0:11cc2b7889af 137
maygup01 0:11cc2b7889af 138 Specification specification(greentea_setup, cases);
maygup01 0:11cc2b7889af 139
maygup01 0:11cc2b7889af 140 int main() {
maygup01 0:11cc2b7889af 141 //Create a thread to blink an LED and signal that the device is alive
maygup01 0:11cc2b7889af 142 #if !defined(MBED_CONF_APP_NO_LED)
maygup01 0:11cc2b7889af 143 Ticker t;
maygup01 0:11cc2b7889af 144 t.attach(led_thread, 0.5);
maygup01 0:11cc2b7889af 145 #endif
maygup01 0:11cc2b7889af 146
maygup01 0:11cc2b7889af 147 return !Harness::run(specification);
maygup01 0:11cc2b7889af 148 }