Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
main.cpp
00001 /* 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2006-2018 ARM Limited 00004 * 00005 * SPDX-License-Identifier: Apache-2.0 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); 00008 * you may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 */ 00019 00020 /* 00021 * Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test 00022 */ 00023 00024 #include "mbed.h" 00025 #include "FATFileSystem.h" 00026 #include "LittleFileSystem.h" 00027 #include "utest/utest.h" 00028 #include "unity/unity.h" 00029 #include "greentea-client/test_env.h" 00030 #include "common_defines_test.h" 00031 #include "file_test.h" 00032 00033 #ifdef MBED_CONF_APP_BASICS_TEST_FILENAME 00034 #include MBED_CONF_APP_BASICS_TEST_FILENAME 00035 #else 00036 #include "alice.h" 00037 #endif 00038 00039 #ifndef MBED_CONF_APP_TESTS_FS_SIZE 00040 #define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024) 00041 #endif 00042 00043 using namespace utest::v1; 00044 00045 #if !defined(MBED_CONF_APP_NO_LED) 00046 DigitalOut led1(LED1); 00047 DigitalOut led2(LED2); 00048 void led_thread() { 00049 led1 = !led1; 00050 led2 = !led1; 00051 } 00052 #endif 00053 00054 BlockDevice* bd = BlockDevice::get_default_instance(); 00055 SlicingBlockDevice sd(bd, 0, MBED_CONF_APP_TESTS_FS_SIZE); 00056 #if TEST_USE_FILESYSTEM == FS_FAT 00057 FATFileSystem fs("sd"); 00058 #else 00059 LittleFileSystem fs("sd"); 00060 #endif 00061 00062 static control_t test_format(const size_t call_count) { 00063 int format_err = fs.format(&sd); 00064 TEST_ASSERT_EQUAL_INT_MESSAGE(0, format_err, "could not format block device"); 00065 00066 int mount_err = fs.mount(&sd); 00067 TEST_ASSERT_EQUAL_INT_MESSAGE(0, mount_err, "could not mount block device"); 00068 00069 return CaseNext; 00070 } 00071 00072 static uint32_t thread_counter = 0; 00073 00074 void file_fn(size_t buffer) { 00075 uint32_t thread_id = core_util_atomic_incr_u32(&thread_counter, 1); 00076 char filename[255] = { 0 }; 00077 snprintf(filename, 255, "mbed-file-test-%d.txt", thread_id); 00078 file_test_write(filename, 0, story, sizeof(story), buffer); 00079 file_test_read(filename, 0, story, sizeof(story), buffer); 00080 } 00081 void file_4b_fn() { return file_fn(4); } 00082 void file_256b_fn() { return file_fn(256); } 00083 void file_1kb_fn() { return file_fn(1024); } 00084 void file_2kb_fn() { return file_fn(2048); } 00085 void file_4kb_fn() { return file_fn(4096); } 00086 00087 static control_t file_2_threads(const size_t call_count) { 00088 thread_counter = 0; 00089 00090 Thread t1; 00091 Thread t2; 00092 t1.start(file_4b_fn); 00093 t2.start(file_256b_fn); 00094 t1.join(); 00095 t2.join(); 00096 00097 return CaseNext; 00098 } 00099 00100 static control_t file_3_threads(const size_t call_count) { 00101 thread_counter = 0; 00102 00103 Thread t1; 00104 Thread t2; 00105 Thread t3; 00106 t1.start(file_256b_fn); 00107 t2.start(file_1kb_fn); 00108 t3.start(file_4kb_fn); 00109 t1.join(); 00110 t2.join(); 00111 t3.join(); 00112 00113 return CaseNext; 00114 } 00115 00116 static control_t file_4_threads(const size_t call_count) { 00117 thread_counter = 0; 00118 00119 Thread t1; 00120 Thread t2; 00121 Thread t3; 00122 Thread t4; 00123 t1.start(file_256b_fn); 00124 t2.start(file_256b_fn); 00125 t3.start(file_1kb_fn); 00126 t4.start(file_2kb_fn); 00127 t1.join(); 00128 t2.join(); 00129 t3.join(); 00130 t4.join(); 00131 00132 return CaseNext; 00133 } 00134 00135 utest::v1::status_t greentea_setup(const size_t number_of_cases) { 00136 GREENTEA_SETUP(10*60, "default_auto"); 00137 return greentea_test_setup_handler(number_of_cases); 00138 } 00139 00140 Case cases[] = { 00141 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " format", test_format), 00142 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 2 files, buff 4b/256b", file_2_threads), 00143 Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 3 files, buff 256b/1kb/4kb", file_3_threads), 00144 //Case(TEST_BLOCK_DEVICE_TYPE "+" TEST_FILESYSTEM_TYPE " 4 files, buff 256b/256b/1kb/2kb", file_4_threads), 00145 }; 00146 00147 Specification specification(greentea_setup, cases); 00148 00149 int main() { 00150 //Create a thread to blink an LED and signal that the device is alive 00151 #if !defined(MBED_CONF_APP_NO_LED) 00152 Ticker t; 00153 t.attach(led_thread, 0.5); 00154 #endif 00155 00156 return !Harness::run(specification); 00157 }
Generated on Tue Jul 12 2022 20:21:01 by
