Committer:
leothedragon
Date:
Sun Apr 18 15:20:23 2021 +0000
Revision:
0:25fa8795676b
DS

Who changed what in which revision?

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