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.
find2.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 00019 /** @file find2.cpp Test cases to find KVs in the CFSTORE using the drv->Find() interface. 00020 * 00021 * Please consult the documentation under the test-case functions for 00022 * a description of the individual test case. 00023 */ 00024 00025 #include "mbed.h" 00026 #include "cfstore_config.h" 00027 #include "cfstore_test.h" 00028 #include "cfstore_debug.h" 00029 #include "Driver_Common.h" 00030 #include "configuration_store.h" 00031 #include "utest/utest.h" 00032 #include "unity/unity.h" 00033 #include "greentea-client/test_env.h" 00034 00035 #include <stdio.h> 00036 #include <stdlib.h> 00037 #include <string.h> 00038 #include <assert.h> 00039 #include <inttypes.h> 00040 00041 using namespace utest::v1; 00042 00043 static char cfstore_find2_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; 00044 00045 00046 /// @cond CFSTORE_DOXYGEN_DISABLE 00047 #ifdef CFSTORE_DEBUG 00048 #define CFSTORE_FIND2_GREENTEA_TIMEOUT_S 360 00049 #else 00050 #define CFSTORE_FIND2_GREENTEA_TIMEOUT_S 60 00051 #endif 00052 #define CFSTORE_FIND2_TEST_02_VALUE_SIZE 191 00053 00054 extern ARM_CFSTORE_DRIVER cfstore_driver; 00055 00056 void cfstore_find2_callback(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *client_context, ARM_CFSTORE_HANDLE handle) 00057 { 00058 (void) status; 00059 (void) cmd_code; 00060 (void) client_context; 00061 (void) handle; 00062 return; 00063 } 00064 /// @endcond 00065 00066 /* report whether built/configured for flash sync or async mode */ 00067 static control_t cfstore_find2_test_00(const size_t call_count) 00068 { 00069 int32_t ret = ARM_DRIVER_ERROR; 00070 00071 (void) call_count; 00072 ret = cfstore_test_startup(); 00073 CFSTORE_TEST_UTEST_MESSAGE(cfstore_find2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); 00074 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find2_utest_msg_g); 00075 return CaseNext; 00076 } 00077 00078 00079 static control_t cfstore_find2_test_01(const size_t call_count) 00080 { 00081 char keyBuffer[128] = "com.arm.mbed.manifest-manager.root.AQAAAAAAAAA-.manifest"; 00082 int32_t rc; 00083 ARM_CFSTORE_HANDLE_INIT(hkey); 00084 ARM_CFSTORE_HANDLE_INIT(prev); 00085 00086 // Initialize the config store 00087 (void) call_count; 00088 cfstore_driver.Initialize(cfstore_find2_callback, NULL); 00089 cfstore_driver.PowerControl(ARM_POWER_FULL); 00090 00091 // Find the target key 00092 rc = cfstore_driver.Find(keyBuffer, prev, hkey); 00093 00094 // If the target key was not found 00095 if (rc == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { 00096 ARM_CFSTORE_KEYDESC kdesc = { 00097 .acl = { 00098 .perm_owner_read = 1, 00099 .perm_owner_write = 1, 00100 .perm_owner_execute = 0, 00101 .perm_other_read = 1, 00102 .perm_other_write = 0, 00103 .perm_other_execute = 0, 00104 /* added initialisers */ 00105 .reserved = 0 00106 }, .drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE, 00107 .security = { 00108 .acls = 1, 00109 .rollback_protection = 0, 00110 .tamper_proof = 0, 00111 .internal_flash = 0, 00112 /* added initialisers */ 00113 .reserved1 = 0, 00114 .software_attacks = 0, 00115 .board_level_attacks = 0, 00116 .chip_level_attacks = 0, 00117 .side_channel_attacks = 0, 00118 .reserved2 = 0 00119 }, 00120 .flags = { 00121 .continuous = 0, 00122 .lazy_flush = 1, 00123 .flush_on_close = 1, 00124 .read = 0, 00125 .write = 1, 00126 .execute = 0, 00127 .storage_detect = 1, 00128 /* added initialisers */ 00129 .reserved = 0 00130 } 00131 }; 00132 00133 // Create the target key 00134 rc = cfstore_driver.Create(keyBuffer, 191, &kdesc, hkey); 00135 } 00136 return CaseNext; 00137 } 00138 00139 00140 /* fixed version of brendans code */ 00141 static control_t cfstore_find2_test_02(const size_t call_count) 00142 { 00143 char keyBuffer[128] = "com.arm.mbed.manifest-manager.root.AQAAAAAAAAA-.manifest"; 00144 00145 int32_t rc; 00146 ARM_CFSTORE_HANDLE_INIT(hkey); 00147 ARM_CFSTORE_HANDLE_INIT(prev); 00148 ARM_CFSTORE_SIZE length; 00149 char value[CFSTORE_FIND2_TEST_02_VALUE_SIZE]; 00150 00151 // Initialize the config store 00152 (void) call_count; 00153 cfstore_driver.Initialize(NULL, NULL); /* non-null client_callback not supported for MBED_V_0_1_x */ 00154 cfstore_driver.PowerControl(ARM_POWER_FULL); 00155 memset(value, 0, 191); 00156 00157 // Find the target key 00158 rc = cfstore_driver.Find(keyBuffer, prev, hkey); 00159 00160 // If the target key was not found 00161 if (rc == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { 00162 ARM_CFSTORE_KEYDESC kdesc = { 00163 .acl = { 00164 .perm_owner_read = 1, 00165 .perm_owner_write = 1, 00166 .perm_owner_execute = 0, 00167 .perm_other_read = 1, 00168 .perm_other_write = 0, 00169 .perm_other_execute = 0, 00170 .reserved = 0 00171 }, .drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE, /* DATA_RETENTION_NVM not supported for MBED_V_0_1_x */ 00172 .security = { 00173 .acls = 0, /* protection against internal software attacks using ACLs not supported for MBED_V_0_1_x */ 00174 .rollback_protection = 0, 00175 .tamper_proof = 0, 00176 .internal_flash = 0, 00177 .reserved1 = 0, 00178 .software_attacks = 0, 00179 .board_level_attacks = 0, 00180 .chip_level_attacks = 0, 00181 .side_channel_attacks = 0, 00182 .reserved2 = 0 00183 }, 00184 .flags = { 00185 .continuous = 0, 00186 .lazy_flush = 0, /* lazy flush not supported for MBED_V_0_1_x */ 00187 .flush_on_close = 0, /* flush on close not supported for MBED_V_0_1_x */ 00188 .read = 0, 00189 .write = 1, 00190 .execute = 0, 00191 .storage_detect = 0, /* storage detect supported for MBED_V_0_1_x */ 00192 /* added initialisers */ 00193 .reserved = 0 00194 00195 } 00196 }; 00197 00198 // Create the target key 00199 rc = cfstore_driver.Create(keyBuffer, 191, &kdesc, hkey); 00200 CFSTORE_TEST_UTEST_MESSAGE(cfstore_find2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: failed to create key\n", __func__); 00201 TEST_ASSERT_MESSAGE(rc >= ARM_DRIVER_OK, cfstore_find2_utest_msg_g); 00202 00203 strncpy(value, "MyValueData", CFSTORE_FIND2_TEST_02_VALUE_SIZE); 00204 length = strlen(value); 00205 rc = cfstore_driver.Write(hkey, value, &length); 00206 CFSTORE_TEST_UTEST_MESSAGE(cfstore_find2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: failed to write key\n", __func__); 00207 TEST_ASSERT_MESSAGE(rc >= ARM_DRIVER_OK, cfstore_find2_utest_msg_g); 00208 /* revert to CFSTORE_LOG if more trace required */ 00209 CFSTORE_DBGLOG("Success!%s", "\n"); 00210 } 00211 return CaseNext; 00212 } 00213 00214 /// @cond CFSTORE_DOXYGEN_DISABLE 00215 utest::v1::status_t greentea_setup(const size_t number_of_cases) 00216 { 00217 GREENTEA_SETUP(CFSTORE_FIND2_GREENTEA_TIMEOUT_S, "default_auto"); 00218 return greentea_test_setup_handler(number_of_cases); 00219 } 00220 00221 Case cases[] = { 00222 /* 1 2 3 4 5 6 7 */ 00223 /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ 00224 Case("FIND2_test_00", cfstore_find2_test_00), 00225 Case("FIND2_test_01", cfstore_find2_test_01), 00226 Case("FIND2_test_02", cfstore_find2_test_02), 00227 }; 00228 00229 00230 /* Declare your test specification with a custom setup handler */ 00231 Specification specification(greentea_setup, cases); 00232 00233 int main() 00234 { 00235 return !Harness::run(specification); 00236 } 00237 /// @endcond
Generated on Tue Aug 9 2022 00:37:07 by
1.7.2