init
Embed:
(wiki syntax)
Show/hide line numbers
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 #include "LittleFileSystem.h" 00024 00025 #include <string.h> 00026 00027 using namespace utest::v1; 00028 00029 00030 // test configuration 00031 #ifndef MBED_TEST_BLOCKDEVICE 00032 #error [NOT_SUPPORTED] Non-volatile block device required for resilience_functional tests 00033 #endif 00034 00035 #ifndef MBED_TEST_BLOCKDEVICE_DECL 00036 #define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd 00037 #endif 00038 00039 #ifndef MBED_TEST_BLOCK_COUNT 00040 #define MBED_TEST_BLOCK_COUNT 64 00041 #endif 00042 00043 #ifndef MBED_TEST_CYCLES 00044 #define MBED_TEST_CYCLES 10 00045 #endif 00046 00047 #ifndef MBED_TEST_TIMEOUT 00048 #define MBED_TEST_TIMEOUT 480 00049 #endif 00050 00051 // declarations 00052 #define STRINGIZE(x) STRINGIZE2(x) 00053 #define STRINGIZE2(x) #x 00054 #define INCLUDE(x) STRINGIZE(x.h) 00055 00056 #include INCLUDE(MBED_TEST_BLOCKDEVICE) 00057 00058 MBED_TEST_BLOCKDEVICE_DECL; 00059 00060 typedef enum { 00061 CMD_STATUS_PASS, 00062 CMD_STATUS_FAIL, 00063 CMD_STATUS_CONTINUE, 00064 CMD_STATUS_ERROR 00065 } cmd_status_t; 00066 00067 void use_filesystem() 00068 { 00069 // Perform operations 00070 while (true) { 00071 int64_t ret = perform_atomic_operations(&bd); 00072 TEST_ASSERT(ret > 0); 00073 } 00074 } 00075 00076 static cmd_status_t handle_command(const char *key, const char *value) 00077 { 00078 if (strcmp(key, "format") == 0) { 00079 setup_atomic_operations(&bd, true); 00080 greentea_send_kv("format_done", 1); 00081 return CMD_STATUS_CONTINUE; 00082 00083 } else if (strcmp(key, "run") == 0) { 00084 use_filesystem(); 00085 return CMD_STATUS_CONTINUE; 00086 00087 } else if (strcmp(key, "exit") == 0) { 00088 if (strcmp(value, "pass") != 0) { 00089 return CMD_STATUS_FAIL; 00090 } 00091 check_atomic_operations(&bd); 00092 return CMD_STATUS_PASS; 00093 00094 } else { 00095 return CMD_STATUS_ERROR; 00096 00097 } 00098 } 00099 00100 int main() 00101 { 00102 GREENTEA_SETUP(MBED_TEST_TIMEOUT, "unexpected_reset"); 00103 00104 static char _key[10 + 1] = {}; 00105 static char _value[128 + 1] = {}; 00106 00107 greentea_send_kv("start", 1); 00108 00109 // Handshake with host 00110 cmd_status_t cmd_status = CMD_STATUS_CONTINUE; 00111 while (CMD_STATUS_CONTINUE == cmd_status) { 00112 memset(_key, 0, sizeof(_key)); 00113 memset(_value, 0, sizeof(_value)); 00114 greentea_parse_kv(_key, _value, sizeof(_key) - 1, sizeof(_value) - 1); 00115 cmd_status = handle_command(_key, _value); 00116 } 00117 00118 GREENTEA_TESTSUITE_RESULT(CMD_STATUS_PASS == cmd_status); 00119 }
Generated on Tue Jul 12 2022 13:24:53 by
1.7.2