Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers init.cpp Source File

init.cpp

Go to the documentation of this file.
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 #ifdef YOTTA_CFG_CONFIG_UVISOR
00034 #include "uvisor-lib/uvisor-lib.h"
00035 #endif /* YOTTA_CFG_CONFIG_UVISOR */
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <inttypes.h>
00041 
00042 using namespace utest::v1;
00043 
00044 static char cfstore_init_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE];
00045 
00046 /// @cond CFSTORE_DOXYGEN_DISABLE
00047 typedef struct cfstore_init_ctx_t
00048 {
00049     ARM_CFSTORE_CAPABILITIES caps;
00050 } cfstore_init_ctx_t;
00051 
00052 static cfstore_init_ctx_t cfstore_init_ctx_g;
00053 extern ARM_CFSTORE_DRIVER cfstore_driver;
00054 ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver;
00055 /// @endcond
00056 
00057 
00058 /* report whether built/configured for flash sync or async mode */
00059 static control_t cfstore_init_test_00(const size_t call_count)
00060 {
00061     int32_t ret = ARM_DRIVER_ERROR;
00062 
00063     (void) call_count;
00064     ret = cfstore_test_startup();
00065     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);
00066     TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g);
00067     return CaseNext;
00068 }
00069 
00070 static void cfstore_init_test_01(cfstore_init_ctx_t* ctx)
00071 {
00072     int32_t ret;
00073 
00074     (void) ctx;
00075     CFSTORE_DBGLOG("INITIALIZING%s", "\r\n");
00076     ret = cfstore_drv->Initialize(NULL, NULL);
00077     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);
00078     TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g);
00079 
00080     CFSTORE_DBGLOG("FLUSHING1%s", "\r\n");
00081     ret = cfstore_drv->Flush();
00082     CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret);
00083     TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g);
00084 
00085     CFSTORE_DBGLOG("UNINITIALIZING%s", "\r\n");
00086     ret = cfstore_drv->Uninitialize();
00087     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);
00088     TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g);
00089 
00090     CFSTORE_DBGLOG("***************%s", "\r\n");
00091     CFSTORE_DBGLOG("*** SUCCESS ***%s", "\r\n");
00092     CFSTORE_DBGLOG("***************%s", "\r\n");
00093     return;
00094 }
00095 
00096 static control_t cfstore_init_app_start(const size_t call_count)
00097 {
00098     cfstore_init_ctx_t* ctx = &cfstore_init_ctx_g;
00099 
00100     (void) call_count;
00101 
00102     /* initialise the context */
00103     memset(ctx, 0, sizeof(cfstore_init_ctx_t));
00104     ctx->caps = cfstore_drv->GetCapabilities();
00105     CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops);
00106     if(ctx->caps.asynchronous_ops == 1){
00107         /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true
00108          * This means the test will conveniently pass when run in CI as part of async mode testing */
00109         CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n");
00110         return CaseNext;
00111     }
00112     cfstore_init_test_01(ctx);
00113     return CaseNext;
00114 }
00115 
00116 #ifndef YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING
00117 
00118 
00119 /* when built as Configuration-Store example, include greentea support otherwise omit */
00120 
00121 /// @cond CFSTORE_DOXYGEN_DISABLE
00122 utest::v1::status_t greentea_setup(const size_t number_of_cases)
00123 {
00124     GREENTEA_SETUP(100, "default_auto");
00125     return greentea_test_setup_handler(number_of_cases);
00126 }
00127 
00128 Case cases[] = {
00129            /*          1         2         3         4         5         6        7  */
00130            /* 1234567890123456789012345678901234567890123456789012345678901234567890 */
00131         Case("INIT_test_00", cfstore_init_test_00),
00132         Case("INIT_test_01_start", cfstore_init_app_start),
00133 };
00134 
00135 
00136 /* Declare your test specification with a custom setup handler */
00137 Specification specification(greentea_setup, cases);
00138 
00139 int main()
00140 {
00141     return !Harness::run(specification);
00142 }
00143 /// @endcond
00144 
00145 
00146 #else   // YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING
00147 
00148 
00149 // stand alone Configuration-Store-Example
00150 void app_start(int argc __unused, char** argv __unused)
00151 {
00152     cfstore_init_app_start(0);
00153 }
00154 
00155 
00156 #endif // YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING