leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Committer:
leothedragon
Date:
Tue May 04 08:55:12 2021 +0000
Revision:
0:8f0bb79ddd48
nmn

Who changed what in which revision?

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