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.
init.cpp
00001 /* 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2006-2016 ARM Limited 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /** @file init.cpp Test cases to test CFSTORE initialization/uninitialization code. 00019 * 00020 * Please consult the documentation under the test-case functions for 00021 * a description of the individual test case. 00022 */ 00023 00024 #include "mbed.h" 00025 #include "Driver_Common.h" 00026 #include "cfstore_config.h" 00027 #include "cfstore_test.h" 00028 #include "cfstore_debug.h" 00029 #include "configuration_store.h" 00030 #include "utest/utest.h" 00031 #include "unity/unity.h" 00032 #include "greentea-client/test_env.h" 00033 00034 #include <stdio.h> 00035 #include <stdlib.h> 00036 #include <string.h> 00037 #include <inttypes.h> 00038 00039 using namespace utest::v1; 00040 00041 static char cfstore_init_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; 00042 00043 /// @cond CFSTORE_DOXYGEN_DISABLE 00044 typedef struct cfstore_init_ctx_t 00045 { 00046 ARM_CFSTORE_CAPABILITIES caps; 00047 } cfstore_init_ctx_t; 00048 00049 static cfstore_init_ctx_t cfstore_init_ctx_g; 00050 extern ARM_CFSTORE_DRIVER cfstore_driver; 00051 ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver; 00052 /// @endcond 00053 00054 00055 /* report whether built/configured for flash sync or async mode */ 00056 static control_t cfstore_init_test_00(const size_t call_count) 00057 { 00058 int32_t ret = ARM_DRIVER_ERROR; 00059 00060 (void) call_count; 00061 ret = cfstore_test_startup(); 00062 CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); 00063 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); 00064 return CaseNext; 00065 } 00066 00067 static void cfstore_init_test_01(cfstore_init_ctx_t* ctx) 00068 { 00069 int32_t ret; 00070 00071 (void) ctx; 00072 CFSTORE_DBGLOG("INITIALIZING%s", "\r\n"); 00073 ret = cfstore_drv->Initialize(NULL, NULL); 00074 CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); 00075 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); 00076 00077 CFSTORE_DBGLOG("FLUSHING1%s", "\r\n"); 00078 ret = cfstore_drv->Flush(); 00079 CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret); 00080 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); 00081 00082 CFSTORE_DBGLOG("UNINITIALIZING%s", "\r\n"); 00083 ret = cfstore_drv->Uninitialize(); 00084 CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() should return ret >= 0 for synch mode(ret=%ld)\r\n", __func__, ret); 00085 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); 00086 00087 CFSTORE_DBGLOG("***************%s", "\r\n"); 00088 CFSTORE_DBGLOG("*** SUCCESS ***%s", "\r\n"); 00089 CFSTORE_DBGLOG("***************%s", "\r\n"); 00090 return; 00091 } 00092 00093 static control_t cfstore_init_app_start(const size_t call_count) 00094 { 00095 cfstore_init_ctx_t* ctx = &cfstore_init_ctx_g; 00096 00097 (void) call_count; 00098 00099 /* initialise the context */ 00100 memset(ctx, 0, sizeof(cfstore_init_ctx_t)); 00101 ctx->caps = cfstore_drv->GetCapabilities(); 00102 CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops); 00103 if(ctx->caps.asynchronous_ops == 1){ 00104 /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true 00105 * This means the test will conveniently pass when run in CI as part of async mode testing */ 00106 CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n"); 00107 return CaseNext; 00108 } 00109 cfstore_init_test_01(ctx); 00110 return CaseNext; 00111 } 00112 00113 #ifndef YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING 00114 00115 00116 /* when built as Configuration-Store example, include greentea support otherwise omit */ 00117 00118 /// @cond CFSTORE_DOXYGEN_DISABLE 00119 utest::v1::status_t greentea_setup(const size_t number_of_cases) 00120 { 00121 GREENTEA_SETUP(100, "default_auto"); 00122 return greentea_test_setup_handler(number_of_cases); 00123 } 00124 00125 Case cases[] = { 00126 /* 1 2 3 4 5 6 7 */ 00127 /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ 00128 Case("INIT_test_00", cfstore_init_test_00), 00129 Case("INIT_test_01_start", cfstore_init_app_start), 00130 }; 00131 00132 00133 /* Declare your test specification with a custom setup handler */ 00134 Specification specification(greentea_setup, cases); 00135 00136 int main() 00137 { 00138 return !Harness::run(specification); 00139 } 00140 /// @endcond 00141 00142 00143 #else // YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING 00144 00145 00146 // stand alone Configuration-Store-Example 00147 void app_start(int argc __unused, char** argv __unused) 00148 { 00149 cfstore_init_app_start(0); 00150 } 00151 00152 00153 #endif // YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING
Generated on Tue Aug 9 2022 00:37:09 by
1.7.2