init

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "mbed.h"
00017 #include "unity.h"
00018 #include "utest.h"
00019 #include "test_env.h"
00020 
00021 #include "atomic_usage.h"
00022 #include "ObservingBlockDevice.h"
00023 
00024 using namespace utest::v1;
00025 
00026 // test configuration
00027 #ifndef MBED_TEST_SIM_BLOCKDEVICE
00028 #error [NOT_SUPPORTED] Simulation block device required for resilience tests
00029 #endif
00030 
00031 #ifndef MBED_TEST_SIM_BLOCKDEVICE_DECL
00032 #define MBED_TEST_SIM_BLOCKDEVICE_DECL MBED_TEST_SIM_BLOCKDEVICE bd(MBED_TEST_BLOCK_COUNT*512, 1, 1, 512)
00033 #endif
00034 
00035 #ifndef MBED_TEST_BLOCK_COUNT
00036 #define MBED_TEST_BLOCK_COUNT 64
00037 #endif
00038 
00039 #ifndef MBED_TEST_CYCLES
00040 #define MBED_TEST_CYCLES 10
00041 #endif
00042 
00043 #ifndef MBED_TEST_TIMEOUT
00044 #define MBED_TEST_TIMEOUT 480
00045 #endif
00046 
00047 // declarations
00048 #define STRINGIZE(x) STRINGIZE2(x)
00049 #define STRINGIZE2(x) #x
00050 #define INCLUDE(x) STRINGIZE(x.h)
00051 
00052 #include INCLUDE(MBED_TEST_SIM_BLOCKDEVICE)
00053 
00054 
00055 /**
00056  * Check that the filesystem is valid after every change
00057  *
00058  * This test is to ensure that littlefs contains a valid filesystem at
00059  * all times. This property is required for handling unexpected power
00060  * loss.
00061  */
00062 void test_resilience()
00063 {
00064     MBED_TEST_SIM_BLOCKDEVICE_DECL;
00065 
00066     // bring up to get block size
00067     bd.init();
00068     bd_size_t block_size = bd.get_erase_size();
00069     bd.deinit();
00070 
00071     SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT*block_size);
00072 
00073     // Setup the test
00074     setup_atomic_operations(&slice, true);
00075 
00076     // Run check on every write operation
00077     ObservingBlockDevice observer(&slice);
00078     observer.attach(check_atomic_operations);
00079 
00080     // Perform operations
00081     printf("Performing %i operations on flash\n", MBED_TEST_CYCLES);
00082     for (int i = 1; i <= MBED_TEST_CYCLES; i++) {
00083         int64_t ret = perform_atomic_operations(&observer);
00084         TEST_ASSERT_EQUAL(i, ret);
00085     }
00086     printf("No errors detected\n");
00087 }
00088 
00089 Case cases[] = {
00090     Case("test resilience", test_resilience),
00091 };
00092 
00093 utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
00094 {
00095     GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
00096     return greentea_test_setup_handler(number_of_cases);
00097 }
00098 
00099 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
00100 
00101 int main()
00102 {
00103     Harness::run(specification);
00104 }