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.
misc.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 misc.cpp Test cases for miscellaneous API drv->Xxx() functions. 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 "cfstore_config.h" 00026 #include "cfstore_test.h" 00027 #include "cfstore_debug.h" 00028 #include "Driver_Common.h" 00029 #include "cfstore_config.h" 00030 #include "configuration_store.h" 00031 #include "utest/utest.h" 00032 #include "unity/unity.h" 00033 #include "greentea-client/test_env.h" 00034 #include "cfstore_utest.h" 00035 #ifdef YOTTA_CFG_CFSTORE_UVISOR 00036 #include "uvisor-lib/uvisor-lib.h" 00037 #include "cfstore_uvisor.h" 00038 #endif /* YOTTA_CFG_CFSTORE_UVISOR */ 00039 00040 #include <stdio.h> 00041 #include <string.h> 00042 #include <inttypes.h> 00043 00044 using namespace utest::v1; 00045 00046 static char cfstore_misc_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; 00047 00048 #ifdef YOTTA_CFG_CFSTORE_UVISOR 00049 /* Create the main box ACL list for the application. 00050 * The main ACL gets inherited by all the other boxes 00051 */ 00052 CFSTORE_UVISOR_MAIN_ACL(cfstore_acl_uvisor_box_misc_g); 00053 00054 /* Enable uVisor. */ 00055 UVISOR_SET_MODE_ACL(UVISOR_ENABLED, cfstore_acl_uvisor_box_misc_g); 00056 #endif /* YOTTA_CFG_CFSTORE_UVISOR */ 00057 00058 00059 /* report whether built/configured for flash sync or async mode */ 00060 static control_t cfstore_misc_test_00(const size_t call_count) 00061 { 00062 int32_t ret = ARM_DRIVER_ERROR; 00063 00064 (void) call_count; 00065 ret = cfstore_test_startup(); 00066 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); 00067 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00068 return CaseNext; 00069 } 00070 00071 00072 /** @brief basic PowerControl() test 00073 * 00074 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00075 */ 00076 control_t cfstore_misc_test_00_start(const size_t call_count) 00077 { 00078 int32_t ret = ARM_DRIVER_ERROR; 00079 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00080 ARM_POWER_STATE state = ARM_POWER_OFF; 00081 00082 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00083 (void) call_count; 00084 00085 /* try setting the power control state before initialised, which should fail */ 00086 ret = drv->PowerControl(state); 00087 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Eror: PowerControl() call should have failed as CFSTORE not initialised, but the call succeeded\r\n", __func__); 00088 TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00089 00090 ret = drv->Initialize(cfstore_utest_default_callback, NULL); 00091 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret); 00092 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00093 return CaseTimeout(CFSTORE_UTEST_DEFAULT_TIMEOUT_MS); 00094 } 00095 00096 static control_t cfstore_misc_test_00_end(const size_t call_count) 00097 { 00098 int32_t ret = ARM_DRIVER_ERROR; 00099 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00100 ARM_POWER_STATE state = ARM_POWER_OFF; 00101 00102 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00103 (void) call_count; 00104 00105 while(state <= ARM_POWER_FULL) 00106 { 00107 ret = drv->PowerControl(state); 00108 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: PowerControl() call failed\r\n", __func__); 00109 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00110 state = (ARM_POWER_STATE)((uint32_t) state + 1); 00111 } 00112 /*try invalid value which should fail*/ 00113 ret = drv->PowerControl((ARM_POWER_STATE ) 0xffffffff); 00114 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:ERror: PowerControl() did not fail with bad value 0xffffffff (not as expected)\r\n", __func__); 00115 TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00116 00117 ret = drv->Uninitialize(); 00118 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00119 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00120 return CaseNext; 00121 } 00122 00123 00124 /** @brief basic GetVersion() test 00125 * 00126 */ 00127 control_t cfstore_misc_test_01(const size_t call_count) 00128 { 00129 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00130 ARM_DRIVER_VERSION version; 00131 00132 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00133 (void) call_count; 00134 memset(&version, 0, sizeof(version)); 00135 00136 version = drv->GetVersion(); 00137 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:GetVersion() failed to return correct API version.\r\n", __func__); 00138 TEST_ASSERT_MESSAGE(version.api == ARM_CFSTORE_API_VERSION, cfstore_misc_utest_msg_g); 00139 00140 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:GetVersion() to return correct driver version.\r\n", __func__); 00141 TEST_ASSERT_MESSAGE(version.drv == ARM_CFSTORE_DRV_VERSION, cfstore_misc_utest_msg_g); 00142 return CaseNext; 00143 } 00144 00145 00146 /* KV data for test_03 */ 00147 static cfstore_kv_data_t cfstore_misc_test_03_kv_data[] = { 00148 /* 1 2 3 4 5 6 7 */ 00149 /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ 00150 { "The.principles.of.least.action.in.quantum.mechanics", "DoctoralThesis"}, 00151 { "Space.Time.Approach.to.Quantum.Electrodynamic", " PhysicalReview766)"}, 00152 { "An.Operator.Calculus.Having.Applications.in.Quantum.Electrodynamics", "PhysicalReview84)"}, 00153 { NULL, NULL}, 00154 }; 00155 00156 00157 /** @brief basic GetKeyName() test 00158 * 00159 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00160 */ 00161 control_t cfstore_misc_test_02_end(const size_t call_count) 00162 { 00163 uint8_t key_name_len = 0; 00164 char key_name_buf[CFSTORE_KEY_NAME_MAX_LENGTH+1]; 00165 int32_t ret = ARM_DRIVER_ERROR; 00166 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00167 cfstore_kv_data_t* node = NULL; 00168 ARM_CFSTORE_HANDLE_INIT(hkey); 00169 ARM_CFSTORE_FMODE flags; 00170 00171 CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); 00172 (void) call_count; 00173 memset(key_name_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); 00174 /* dont set any flags to get default settings */ 00175 memset(&flags, 0, sizeof(flags)); 00176 00177 ret = cfstore_test_create_table(cfstore_misc_test_03_kv_data); 00178 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to create keys from table.\r\n", __func__); 00179 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00180 00181 node = cfstore_misc_test_03_kv_data; 00182 while(node->key_name != NULL) 00183 { 00184 CFSTORE_DBGLOG("%s:About to open KV (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00185 ret = drv->Open(node->key_name, flags, hkey); 00186 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\r\n", __func__, node->key_name, node->value, (int) ret); 00187 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00188 00189 key_name_len = CFSTORE_KEY_NAME_MAX_LENGTH+1; 00190 memset(key_name_buf, 0, key_name_len); 00191 drv->GetKeyName(hkey, key_name_buf, &key_name_len); 00192 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to GetKeyName() (key_name (expected)=\"%s\", key_name (returned)=\"%s\", value=\"%s\"), len return=%d, len expected=%d\r\n", __func__, node->key_name, key_name_buf, node->value, (int) key_name_len, (int) strlen(node->key_name)); 00193 TEST_ASSERT_MESSAGE(key_name_len == strlen(node->key_name)+1, cfstore_misc_utest_msg_g); 00194 00195 /* revert to CFSTORE_LOG if more trace required */ 00196 CFSTORE_DBGLOG("GetKeyName() successfully reported key_name (key_name=\"%s\")\r\n", key_name_buf); 00197 ret = drv->Close(hkey); 00198 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to close key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00199 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00200 node++; 00201 } 00202 00203 cfstore_test_delete_all(); 00204 ret = drv->Uninitialize(); 00205 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00206 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00207 return CaseNext; 00208 } 00209 00210 00211 /** @brief basic GetValueLen() test 00212 * 00213 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00214 */ 00215 control_t cfstore_misc_test_03_end(const size_t call_count) 00216 { 00217 int32_t ret = ARM_DRIVER_ERROR; 00218 ARM_CFSTORE_SIZE len = 0; 00219 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00220 cfstore_kv_data_t* node = NULL; 00221 ARM_CFSTORE_HANDLE_INIT(hkey); 00222 ARM_CFSTORE_FMODE flags; 00223 00224 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00225 (void) call_count; 00226 /* dont set any flags to get default settings */ 00227 memset(&flags, 0, sizeof(flags)); 00228 00229 ret = cfstore_test_create_table(cfstore_misc_test_03_kv_data); 00230 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to create keys from table.\r\n", __func__); 00231 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00232 00233 node = cfstore_misc_test_03_kv_data; 00234 while(node->key_name != NULL) 00235 { 00236 CFSTORE_DBGLOG("%s:About to open KV (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00237 ret = drv->Open(node->key_name, flags, hkey); 00238 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\r\n", __func__, node->key_name, node->value, (int) ret); 00239 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00240 00241 drv->GetValueLen(hkey, &len); 00242 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Errro: GetValueLen() retrieve incorrect length of value blob(expected=%d, returned=%d)\r\n", __func__, (int) strlen(node->value), (int) len); 00243 TEST_ASSERT_MESSAGE(len == strlen(node->value), cfstore_misc_utest_msg_g); 00244 /* revert to CFSTORE_LOG if more trace required */ 00245 CFSTORE_DBGLOG("GetValueLen() successfully reported correct value blob length%s", "\r\n"); 00246 00247 ret = drv->Close(hkey); 00248 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to close key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00249 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00250 node++; 00251 } 00252 cfstore_test_delete_all(); 00253 ret = drv->Uninitialize(); 00254 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00255 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00256 return CaseNext; 00257 } 00258 00259 00260 /** @brief basic GetStatus() test 00261 * 00262 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00263 */ 00264 control_t cfstore_misc_test_04_start(const size_t call_count) 00265 { 00266 int32_t ret = ARM_DRIVER_ERROR; 00267 ARM_CFSTORE_STATUS status; 00268 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00269 00270 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00271 (void) call_count; 00272 00273 status = drv->GetStatus(); 00274 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() before initialisation should have reported error, but reported no error.\r\n", __func__); 00275 TEST_ASSERT_MESSAGE(status.error == 1, cfstore_misc_utest_msg_g); 00276 00277 ret = drv->Initialize(cfstore_utest_default_callback, NULL); 00278 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret); 00279 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00280 return CaseTimeout(CFSTORE_UTEST_DEFAULT_TIMEOUT_MS); 00281 } 00282 00283 /** @brief basic GetStatus() test 00284 * 00285 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00286 */ 00287 control_t cfstore_misc_test_04_end(const size_t call_count) 00288 { 00289 int32_t ret = ARM_DRIVER_ERROR; 00290 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00291 ARM_CFSTORE_STATUS status; 00292 00293 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00294 (void) call_count; 00295 00296 status = drv->GetStatus(); 00297 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() but reported error.\r\n", __func__); 00298 TEST_ASSERT_MESSAGE(status.error == 0, cfstore_misc_utest_msg_g); 00299 00300 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() reported operation in progress.\r\n", __func__); 00301 TEST_ASSERT_MESSAGE(status.in_progress == 0, cfstore_misc_utest_msg_g); 00302 00303 ret = drv->Uninitialize(); 00304 CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00305 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); 00306 return CaseNext; 00307 } 00308 00309 00310 /// @cond CFSTORE_DOXYGEN_DISABLE 00311 utest::v1::status_t greentea_setup(const size_t number_of_cases) 00312 { 00313 GREENTEA_SETUP(200, "default_auto"); 00314 return greentea_test_setup_handler(number_of_cases); 00315 } 00316 00317 Case cases[] = { 00318 /* 1 2 3 4 5 6 7 */ 00319 /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ 00320 Case("MISC_test_00", cfstore_misc_test_00), 00321 Case("MISC_test_00_start", cfstore_misc_test_00_start), 00322 Case("MISC_test_00_end", cfstore_misc_test_00_end), 00323 Case("MISC_test_01", cfstore_misc_test_01), 00324 Case("MISC_test_02_start", cfstore_utest_default_start), 00325 Case("MISC_test_02_end", cfstore_misc_test_02_end), 00326 Case("MISC_test_03_start", cfstore_utest_default_start), 00327 Case("MISC_test_03_end", cfstore_misc_test_03_end), 00328 Case("MISC_test_04_start", cfstore_misc_test_04_start), 00329 Case("MISC_test_05_end", cfstore_misc_test_04_end), 00330 }; 00331 00332 00333 /* Declare your test specification with a custom setup handler */ 00334 Specification specification(greentea_setup, cases); 00335 00336 int main() 00337 { 00338 return !Harness::run(specification); 00339 } 00340 /// @endcond
Generated on Tue Jul 12 2022 14:24:28 by
