SDHI_driver patch (mbedOS 5.11.5)
mbed-os-program/mbed-os/components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/fopen/fopen.cpp@0:e1f465d87307, 2019-03-18 (annotated)
- Committer:
- tvendov
- Date:
- Mon Mar 18 16:54:40 2019 +0000
- Revision:
- 0:e1f465d87307
Initial_II
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tvendov | 0:e1f465d87307 | 1 | /* |
| tvendov | 0:e1f465d87307 | 2 | * mbed Microcontroller Library |
| tvendov | 0:e1f465d87307 | 3 | * Copyright (c) 2006-2016 ARM Limited |
| tvendov | 0:e1f465d87307 | 4 | * |
| tvendov | 0:e1f465d87307 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| tvendov | 0:e1f465d87307 | 6 | * you may not use this file except in compliance with the License. |
| tvendov | 0:e1f465d87307 | 7 | * You may obtain a copy of the License at |
| tvendov | 0:e1f465d87307 | 8 | * |
| tvendov | 0:e1f465d87307 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| tvendov | 0:e1f465d87307 | 10 | * |
| tvendov | 0:e1f465d87307 | 11 | * Unless required by applicable law or agreed to in writing, software |
| tvendov | 0:e1f465d87307 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| tvendov | 0:e1f465d87307 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| tvendov | 0:e1f465d87307 | 14 | * See the License for the specific language governing permissions and |
| tvendov | 0:e1f465d87307 | 15 | * limitations under the License. |
| tvendov | 0:e1f465d87307 | 16 | */ |
| tvendov | 0:e1f465d87307 | 17 | |
| tvendov | 0:e1f465d87307 | 18 | /** @file fopen.cpp Test cases to POSIX file fopen() interface. |
| tvendov | 0:e1f465d87307 | 19 | * |
| tvendov | 0:e1f465d87307 | 20 | * Please consult the documentation under the test-case functions for |
| tvendov | 0:e1f465d87307 | 21 | * a description of the individual test case. |
| tvendov | 0:e1f465d87307 | 22 | */ |
| tvendov | 0:e1f465d87307 | 23 | |
| tvendov | 0:e1f465d87307 | 24 | #include "mbed.h" |
| tvendov | 0:e1f465d87307 | 25 | #include "mbed_config.h" |
| tvendov | 0:e1f465d87307 | 26 | #if (defined(TARGET_VK_RZ_A1H) || defined(TARGET_VK_RZ_A1LU)) |
| tvendov | 0:e1f465d87307 | 27 | #include "SDHIBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 28 | #else |
| tvendov | 0:e1f465d87307 | 29 | #include "SDBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 30 | #endif |
| tvendov | 0:e1f465d87307 | 31 | #include "FATFileSystem.h" |
| tvendov | 0:e1f465d87307 | 32 | #include "fsfat_debug.h" |
| tvendov | 0:e1f465d87307 | 33 | #include "fsfat_test.h" |
| tvendov | 0:e1f465d87307 | 34 | #include "utest/utest.h" |
| tvendov | 0:e1f465d87307 | 35 | #include "unity/unity.h" |
| tvendov | 0:e1f465d87307 | 36 | #include "greentea-client/test_env.h" |
| tvendov | 0:e1f465d87307 | 37 | |
| tvendov | 0:e1f465d87307 | 38 | #include <stdio.h> |
| tvendov | 0:e1f465d87307 | 39 | #include <string.h> |
| tvendov | 0:e1f465d87307 | 40 | #include <stdlib.h> /*rand()*/ |
| tvendov | 0:e1f465d87307 | 41 | #include <inttypes.h> |
| tvendov | 0:e1f465d87307 | 42 | #include <errno.h> |
| tvendov | 0:e1f465d87307 | 43 | /* mbed_retarget.h is included after errno.h so symbols are mapped to |
| tvendov | 0:e1f465d87307 | 44 | * consistent values for all toolchains */ |
| tvendov | 0:e1f465d87307 | 45 | #include "platform/mbed_retarget.h" |
| tvendov | 0:e1f465d87307 | 46 | |
| tvendov | 0:e1f465d87307 | 47 | using namespace utest::v1; |
| tvendov | 0:e1f465d87307 | 48 | |
| tvendov | 0:e1f465d87307 | 49 | /// @cond FSFAT_DOXYGEN_DISABLE |
| tvendov | 0:e1f465d87307 | 50 | #ifdef FSFAT_DEBUG |
| tvendov | 0:e1f465d87307 | 51 | #define FSFAT_FOPEN_GREENTEA_TIMEOUT_S 3000 |
| tvendov | 0:e1f465d87307 | 52 | #else |
| tvendov | 0:e1f465d87307 | 53 | #define FSFAT_FOPEN_GREENTEA_TIMEOUT_S 1000 |
| tvendov | 0:e1f465d87307 | 54 | #endif |
| tvendov | 0:e1f465d87307 | 55 | /// @endcond |
| tvendov | 0:e1f465d87307 | 56 | |
| tvendov | 0:e1f465d87307 | 57 | |
| tvendov | 0:e1f465d87307 | 58 | /* DEVICE_SPI |
| tvendov | 0:e1f465d87307 | 59 | * This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support. |
| tvendov | 0:e1f465d87307 | 60 | * |
| tvendov | 0:e1f465d87307 | 61 | * MBED_CONF_APP_FSFAT_SDCARD_INSTALLED |
| tvendov | 0:e1f465d87307 | 62 | * For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed. |
| tvendov | 0:e1f465d87307 | 63 | * If the target has an SD card installed then the MBED_CONF_APP_FSFAT_SDCARD_INSTALLED will be generated |
| tvendov | 0:e1f465d87307 | 64 | * from the mbed_app.json, which includes the line |
| tvendov | 0:e1f465d87307 | 65 | * { |
| tvendov | 0:e1f465d87307 | 66 | * "config": { |
| tvendov | 0:e1f465d87307 | 67 | * "UART_RX": "D0", |
| tvendov | 0:e1f465d87307 | 68 | * <<< lines removed >>> |
| tvendov | 0:e1f465d87307 | 69 | * "DEVICE_SPI": 1, |
| tvendov | 0:e1f465d87307 | 70 | * "FSFAT_SDCARD_INSTALLED": 1 |
| tvendov | 0:e1f465d87307 | 71 | * }, |
| tvendov | 0:e1f465d87307 | 72 | * <<< lines removed >>> |
| tvendov | 0:e1f465d87307 | 73 | */ |
| tvendov | 0:e1f465d87307 | 74 | |
| tvendov | 0:e1f465d87307 | 75 | #if DEVICE_SPI && ( defined(MBED_CONF_APP_FSFAT_SDCARD_INSTALLED) || (MBED_CONF_SD_FSFAT_SDCARD_INSTALLED)) |
| tvendov | 0:e1f465d87307 | 76 | static char fsfat_fopen_utest_msg_g[FSFAT_UTEST_MSG_BUF_SIZE]; |
| tvendov | 0:e1f465d87307 | 77 | #define FSFAT_FOPEN_TEST_MOUNT_PT_NAME "sd" |
| tvendov | 0:e1f465d87307 | 78 | #define FSFAT_FOPEN_TEST_MOUNT_PT_PATH "/" FSFAT_FOPEN_TEST_MOUNT_PT_NAME |
| tvendov | 0:e1f465d87307 | 79 | #define FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1 64 |
| tvendov | 0:e1f465d87307 | 80 | #define FSFAT_FOPEN_TEST_FILEPATH_MAX_DEPTH 20 |
| tvendov | 0:e1f465d87307 | 81 | static const char *sd_badfile_path = "/sd/badfile.txt"; |
| tvendov | 0:e1f465d87307 | 82 | static const char *sd_testfile_path = "/sd/test.txt"; |
| tvendov | 0:e1f465d87307 | 83 | |
| tvendov | 0:e1f465d87307 | 84 | #if (defined(TARGET_VK_RZ_A1H) || defined(TARGET_VK_RZ_A1LU)) |
| tvendov | 0:e1f465d87307 | 85 | SDHIBlockDevice sd(MBED_CONF_SD_SDHI_CH); |
| tvendov | 0:e1f465d87307 | 86 | #else |
| tvendov | 0:e1f465d87307 | 87 | SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS); |
| tvendov | 0:e1f465d87307 | 88 | #endif |
| tvendov | 0:e1f465d87307 | 89 | FATFileSystem fs("sd", &sd); |
| tvendov | 0:e1f465d87307 | 90 | |
| tvendov | 0:e1f465d87307 | 91 | #define FSFAT_FOPEN_TEST_00 fsfat_fopen_test_00 |
| tvendov | 0:e1f465d87307 | 92 | #define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_01 |
| tvendov | 0:e1f465d87307 | 93 | #define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_02 |
| tvendov | 0:e1f465d87307 | 94 | #define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_03 |
| tvendov | 0:e1f465d87307 | 95 | #define FSFAT_FOPEN_TEST_04 fsfat_fopen_test_04 |
| tvendov | 0:e1f465d87307 | 96 | #define FSFAT_FOPEN_TEST_05 fsfat_fopen_test_05 |
| tvendov | 0:e1f465d87307 | 97 | #define FSFAT_FOPEN_TEST_06 fsfat_fopen_test_06 |
| tvendov | 0:e1f465d87307 | 98 | #define FSFAT_FOPEN_TEST_07 fsfat_fopen_test_07 |
| tvendov | 0:e1f465d87307 | 99 | #define FSFAT_FOPEN_TEST_08 fsfat_fopen_test_08 |
| tvendov | 0:e1f465d87307 | 100 | #define FSFAT_FOPEN_TEST_09 fsfat_fopen_test_09 |
| tvendov | 0:e1f465d87307 | 101 | #define FSFAT_FOPEN_TEST_10 fsfat_fopen_test_10 |
| tvendov | 0:e1f465d87307 | 102 | #define FSFAT_FOPEN_TEST_11 fsfat_fopen_test_11 |
| tvendov | 0:e1f465d87307 | 103 | #define FSFAT_FOPEN_TEST_12 fsfat_fopen_test_12 |
| tvendov | 0:e1f465d87307 | 104 | #define FSFAT_FOPEN_TEST_13 fsfat_fopen_test_13 |
| tvendov | 0:e1f465d87307 | 105 | #define FSFAT_FOPEN_TEST_14 fsfat_fopen_test_14 |
| tvendov | 0:e1f465d87307 | 106 | #define FSFAT_FOPEN_TEST_15 fsfat_fopen_test_15 |
| tvendov | 0:e1f465d87307 | 107 | #define FSFAT_FOPEN_TEST_16 fsfat_fopen_test_16 |
| tvendov | 0:e1f465d87307 | 108 | #define FSFAT_FOPEN_TEST_17 fsfat_fopen_test_17 |
| tvendov | 0:e1f465d87307 | 109 | #define FSFAT_FOPEN_TEST_18 fsfat_fopen_test_18 |
| tvendov | 0:e1f465d87307 | 110 | #define FSFAT_FOPEN_TEST_19 fsfat_fopen_test_19 |
| tvendov | 0:e1f465d87307 | 111 | #define FSFAT_FOPEN_TEST_20 fsfat_fopen_test_20 |
| tvendov | 0:e1f465d87307 | 112 | #define FSFAT_FOPEN_TEST_21 fsfat_fopen_test_21 |
| tvendov | 0:e1f465d87307 | 113 | #define FSFAT_FOPEN_TEST_22 fsfat_fopen_test_22 |
| tvendov | 0:e1f465d87307 | 114 | #define FSFAT_FOPEN_TEST_23 fsfat_fopen_test_23 |
| tvendov | 0:e1f465d87307 | 115 | #define FSFAT_FOPEN_TEST_24 fsfat_fopen_test_24 |
| tvendov | 0:e1f465d87307 | 116 | #define FSFAT_FOPEN_TEST_25 fsfat_fopen_test_25 |
| tvendov | 0:e1f465d87307 | 117 | #define FSFAT_FOPEN_TEST_26 fsfat_fopen_test_26 |
| tvendov | 0:e1f465d87307 | 118 | #define FSFAT_FOPEN_TEST_27 fsfat_fopen_test_27 |
| tvendov | 0:e1f465d87307 | 119 | #define FSFAT_FOPEN_TEST_28 fsfat_fopen_test_28 |
| tvendov | 0:e1f465d87307 | 120 | #define FSFAT_FOPEN_TEST_29 fsfat_fopen_test_29 |
| tvendov | 0:e1f465d87307 | 121 | #define FSFAT_FOPEN_TEST_30 fsfat_fopen_test_30 |
| tvendov | 0:e1f465d87307 | 122 | |
| tvendov | 0:e1f465d87307 | 123 | |
| tvendov | 0:e1f465d87307 | 124 | /* support functions */ |
| tvendov | 0:e1f465d87307 | 125 | |
| tvendov | 0:e1f465d87307 | 126 | /* |
| tvendov | 0:e1f465d87307 | 127 | * open tests that focus on testing fopen() |
| tvendov | 0:e1f465d87307 | 128 | * fsfat_handle_t fopen(const char* filename, char* data, size_t* len, fsfat_key_desc_t* kdesc) |
| tvendov | 0:e1f465d87307 | 129 | */ |
| tvendov | 0:e1f465d87307 | 130 | |
| tvendov | 0:e1f465d87307 | 131 | /* file data for test_01 */ |
| tvendov | 0:e1f465d87307 | 132 | static fsfat_kv_data_t fsfat_fopen_test_01_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 133 | { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/frontlft.txt", "missing"}, |
| tvendov | 0:e1f465d87307 | 134 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 135 | }; |
| tvendov | 0:e1f465d87307 | 136 | |
| tvendov | 0:e1f465d87307 | 137 | |
| tvendov | 0:e1f465d87307 | 138 | /** @brief |
| tvendov | 0:e1f465d87307 | 139 | * Split a file path into its component parts, setting '/' characters to '\0', and returning |
| tvendov | 0:e1f465d87307 | 140 | * pointers to the file path components in the parts array. For example, if |
| tvendov | 0:e1f465d87307 | 141 | * filepath = "/sd/fopentst/hello/world/animal/wobbly/dog/foot/frontlft.txt" then |
| tvendov | 0:e1f465d87307 | 142 | * *parts[0] = "sd" |
| tvendov | 0:e1f465d87307 | 143 | * *parts[1] = "fopentst" |
| tvendov | 0:e1f465d87307 | 144 | * *parts[2] = "hello" |
| tvendov | 0:e1f465d87307 | 145 | * *parts[3] = "world" |
| tvendov | 0:e1f465d87307 | 146 | * *parts[4] = "animal" |
| tvendov | 0:e1f465d87307 | 147 | * *parts[5] = "wobbly" |
| tvendov | 0:e1f465d87307 | 148 | * *parts[6] = "dog" |
| tvendov | 0:e1f465d87307 | 149 | * *parts[7] = "foot" |
| tvendov | 0:e1f465d87307 | 150 | * *parts[8] = "frontlft.txt" |
| tvendov | 0:e1f465d87307 | 151 | * parts[9] = NULL |
| tvendov | 0:e1f465d87307 | 152 | * |
| tvendov | 0:e1f465d87307 | 153 | * ARGUMENTS |
| tvendov | 0:e1f465d87307 | 154 | * @param filepath IN file path string to split into component parts. Expected to start with '/' |
| tvendov | 0:e1f465d87307 | 155 | * @param parts IN OUT array to hold pointers to parts |
| tvendov | 0:e1f465d87307 | 156 | * @param num IN number of components available in parts |
| tvendov | 0:e1f465d87307 | 157 | * |
| tvendov | 0:e1f465d87307 | 158 | * @return On success, this returns the number of components in the filepath Returns number of compoee |
| tvendov | 0:e1f465d87307 | 159 | */ |
| tvendov | 0:e1f465d87307 | 160 | static int32_t fsfat_filepath_split(char *filepath, char *parts[], uint32_t num) |
| tvendov | 0:e1f465d87307 | 161 | { |
| tvendov | 0:e1f465d87307 | 162 | uint32_t i = 0; |
| tvendov | 0:e1f465d87307 | 163 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 164 | char *z = filepath; |
| tvendov | 0:e1f465d87307 | 165 | |
| tvendov | 0:e1f465d87307 | 166 | while (i < num && *z != '\0') { |
| tvendov | 0:e1f465d87307 | 167 | if (*z == '/') { |
| tvendov | 0:e1f465d87307 | 168 | *z = '\0'; |
| tvendov | 0:e1f465d87307 | 169 | parts[i] = ++z; |
| tvendov | 0:e1f465d87307 | 170 | i++; |
| tvendov | 0:e1f465d87307 | 171 | } else { |
| tvendov | 0:e1f465d87307 | 172 | z++; |
| tvendov | 0:e1f465d87307 | 173 | } |
| tvendov | 0:e1f465d87307 | 174 | } |
| tvendov | 0:e1f465d87307 | 175 | if (*z == '\0' && i > 0) { |
| tvendov | 0:e1f465d87307 | 176 | ret = (int32_t) i; |
| tvendov | 0:e1f465d87307 | 177 | } |
| tvendov | 0:e1f465d87307 | 178 | return ret; |
| tvendov | 0:e1f465d87307 | 179 | } |
| tvendov | 0:e1f465d87307 | 180 | |
| tvendov | 0:e1f465d87307 | 181 | |
| tvendov | 0:e1f465d87307 | 182 | /** @brief |
| tvendov | 0:e1f465d87307 | 183 | * remove all directories and file in the given filepath |
| tvendov | 0:e1f465d87307 | 184 | * |
| tvendov | 0:e1f465d87307 | 185 | * ARGUMENTS |
| tvendov | 0:e1f465d87307 | 186 | * @param filepath IN file path string to split into component parts. Expected to start with '/' |
| tvendov | 0:e1f465d87307 | 187 | * |
| tvendov | 0:e1f465d87307 | 188 | * @return On success, this returns 0, otherwise < 0 is returned; |
| tvendov | 0:e1f465d87307 | 189 | */ |
| tvendov | 0:e1f465d87307 | 190 | int32_t fsfat_filepath_remove_all(char *filepath) |
| tvendov | 0:e1f465d87307 | 191 | { |
| tvendov | 0:e1f465d87307 | 192 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 193 | int32_t len = 0; |
| tvendov | 0:e1f465d87307 | 194 | char *fpathbuf = NULL; |
| tvendov | 0:e1f465d87307 | 195 | char *pos = NULL; |
| tvendov | 0:e1f465d87307 | 196 | |
| tvendov | 0:e1f465d87307 | 197 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 198 | len = strlen(filepath); |
| tvendov | 0:e1f465d87307 | 199 | fpathbuf = (char *) malloc(len + 1); |
| tvendov | 0:e1f465d87307 | 200 | if (fpathbuf == NULL) { |
| tvendov | 0:e1f465d87307 | 201 | FSFAT_DBGLOG("%s: failed to duplicate string (out of memory)\n", __func__); |
| tvendov | 0:e1f465d87307 | 202 | return ret; |
| tvendov | 0:e1f465d87307 | 203 | } |
| tvendov | 0:e1f465d87307 | 204 | memset(fpathbuf, 0, len + 1); |
| tvendov | 0:e1f465d87307 | 205 | memcpy(fpathbuf, filepath, len); |
| tvendov | 0:e1f465d87307 | 206 | |
| tvendov | 0:e1f465d87307 | 207 | /* delete the leaf node first, and then successively parent directories. */ |
| tvendov | 0:e1f465d87307 | 208 | pos = fpathbuf + strlen(fpathbuf); |
| tvendov | 0:e1f465d87307 | 209 | while (pos != fpathbuf) { |
| tvendov | 0:e1f465d87307 | 210 | /* If the remaining file path is the mount point path then finish as the mount point cannot be removed */ |
| tvendov | 0:e1f465d87307 | 211 | if (strlen(fpathbuf) == strlen(FSFAT_FOPEN_TEST_MOUNT_PT_PATH)) { |
| tvendov | 0:e1f465d87307 | 212 | if (strncmp(fpathbuf, FSFAT_FOPEN_TEST_MOUNT_PT_PATH, strlen(fpathbuf)) == 0) { |
| tvendov | 0:e1f465d87307 | 213 | break; |
| tvendov | 0:e1f465d87307 | 214 | } |
| tvendov | 0:e1f465d87307 | 215 | } |
| tvendov | 0:e1f465d87307 | 216 | ret = remove(fpathbuf); |
| tvendov | 0:e1f465d87307 | 217 | pos = strrchr(fpathbuf, '/'); |
| tvendov | 0:e1f465d87307 | 218 | *pos = '\0'; |
| tvendov | 0:e1f465d87307 | 219 | } |
| tvendov | 0:e1f465d87307 | 220 | if (fpathbuf) { |
| tvendov | 0:e1f465d87307 | 221 | free(fpathbuf); |
| tvendov | 0:e1f465d87307 | 222 | } |
| tvendov | 0:e1f465d87307 | 223 | return ret; |
| tvendov | 0:e1f465d87307 | 224 | } |
| tvendov | 0:e1f465d87307 | 225 | |
| tvendov | 0:e1f465d87307 | 226 | |
| tvendov | 0:e1f465d87307 | 227 | /** @brief |
| tvendov | 0:e1f465d87307 | 228 | * make all directories in the given filepath. Do not create the file if present at end of filepath |
| tvendov | 0:e1f465d87307 | 229 | * |
| tvendov | 0:e1f465d87307 | 230 | * ARGUMENTS |
| tvendov | 0:e1f465d87307 | 231 | * @param filepath IN file path containing directories and file |
| tvendov | 0:e1f465d87307 | 232 | * @param do_asserts IN set to true if function should assert on errors |
| tvendov | 0:e1f465d87307 | 233 | * |
| tvendov | 0:e1f465d87307 | 234 | * @return On success, this returns 0, otherwise < 0 is returned; |
| tvendov | 0:e1f465d87307 | 235 | */ |
| tvendov | 0:e1f465d87307 | 236 | static int32_t fsfat_filepath_make_dirs(char *filepath, bool do_asserts) |
| tvendov | 0:e1f465d87307 | 237 | { |
| tvendov | 0:e1f465d87307 | 238 | int32_t i = 0; |
| tvendov | 0:e1f465d87307 | 239 | int32_t num_parts = 0; |
| tvendov | 0:e1f465d87307 | 240 | int32_t len = 0; |
| tvendov | 0:e1f465d87307 | 241 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 242 | char *fpathbuf = NULL; |
| tvendov | 0:e1f465d87307 | 243 | char *buf = NULL; |
| tvendov | 0:e1f465d87307 | 244 | int pos = 0; |
| tvendov | 0:e1f465d87307 | 245 | char *parts[FSFAT_FOPEN_TEST_FILEPATH_MAX_DEPTH]; |
| tvendov | 0:e1f465d87307 | 246 | |
| tvendov | 0:e1f465d87307 | 247 | FSFAT_DBGLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 248 | /* find the dirs to create*/ |
| tvendov | 0:e1f465d87307 | 249 | memset(parts, 0, sizeof(parts)); |
| tvendov | 0:e1f465d87307 | 250 | len = strlen(filepath); |
| tvendov | 0:e1f465d87307 | 251 | fpathbuf = (char *) malloc(len + 1); |
| tvendov | 0:e1f465d87307 | 252 | if (fpathbuf == NULL) { |
| tvendov | 0:e1f465d87307 | 253 | FSFAT_DBGLOG("%s: failed to duplicate string (out of memory)\n", __func__); |
| tvendov | 0:e1f465d87307 | 254 | return ret; |
| tvendov | 0:e1f465d87307 | 255 | } |
| tvendov | 0:e1f465d87307 | 256 | memset(fpathbuf, 0, len + 1); |
| tvendov | 0:e1f465d87307 | 257 | memcpy(fpathbuf, filepath, len); |
| tvendov | 0:e1f465d87307 | 258 | num_parts = fsfat_filepath_split(fpathbuf, parts, FSFAT_FOPEN_TEST_FILEPATH_MAX_DEPTH); |
| tvendov | 0:e1f465d87307 | 259 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 260 | "%s:Error: failed to split filepath (filename=\"%s\", num_parts=%d)\n", __func__, filepath, (int) num_parts); |
| tvendov | 0:e1f465d87307 | 261 | TEST_ASSERT_MESSAGE(num_parts > 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 262 | |
| tvendov | 0:e1f465d87307 | 263 | /* Now create the directories on the directory path. |
| tvendov | 0:e1f465d87307 | 264 | * Skip creating dir for "/sd" which must be present */ |
| tvendov | 0:e1f465d87307 | 265 | buf = (char *) malloc(strlen(filepath) + 1); |
| tvendov | 0:e1f465d87307 | 266 | memset(buf, 0, strlen(filepath) + 1); |
| tvendov | 0:e1f465d87307 | 267 | pos = sprintf(buf, "/%s", parts[0]); |
| tvendov | 0:e1f465d87307 | 268 | for (i = 1; i < num_parts - 1; i++) { |
| tvendov | 0:e1f465d87307 | 269 | pos += sprintf(buf + pos, "/%s", parts[i]); |
| tvendov | 0:e1f465d87307 | 270 | FSFAT_DBGLOG("mkdir(%s)\n", buf); |
| tvendov | 0:e1f465d87307 | 271 | ret = mkdir(buf, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); |
| tvendov | 0:e1f465d87307 | 272 | if (do_asserts == true) { |
| tvendov | 0:e1f465d87307 | 273 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 274 | "%s:Error: failed to create directory (filepath2=\"%s\", ret=%d, errno=%d)\n", __func__, buf, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 275 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 276 | } |
| tvendov | 0:e1f465d87307 | 277 | } |
| tvendov | 0:e1f465d87307 | 278 | |
| tvendov | 0:e1f465d87307 | 279 | if (buf) { |
| tvendov | 0:e1f465d87307 | 280 | free(buf); |
| tvendov | 0:e1f465d87307 | 281 | } |
| tvendov | 0:e1f465d87307 | 282 | if (fpathbuf) { |
| tvendov | 0:e1f465d87307 | 283 | free(fpathbuf); |
| tvendov | 0:e1f465d87307 | 284 | } |
| tvendov | 0:e1f465d87307 | 285 | return ret; |
| tvendov | 0:e1f465d87307 | 286 | } |
| tvendov | 0:e1f465d87307 | 287 | |
| tvendov | 0:e1f465d87307 | 288 | /** @brief |
| tvendov | 0:e1f465d87307 | 289 | * First and last test must format the SD card to FAT FS format: |
| tvendov | 0:e1f465d87307 | 290 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 291 | */ |
| tvendov | 0:e1f465d87307 | 292 | control_t fsfat_fopen_test_00(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 293 | { |
| tvendov | 0:e1f465d87307 | 294 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 295 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 296 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 297 | |
| tvendov | 0:e1f465d87307 | 298 | fs.unmount(); |
| tvendov | 0:e1f465d87307 | 299 | ret = fs.format(&sd); |
| tvendov | 0:e1f465d87307 | 300 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 301 | "%s:Error: failed to format sdcard (ret=%d)\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 302 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 303 | fs.mount(&sd); |
| tvendov | 0:e1f465d87307 | 304 | |
| tvendov | 0:e1f465d87307 | 305 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 306 | } |
| tvendov | 0:e1f465d87307 | 307 | |
| tvendov | 0:e1f465d87307 | 308 | |
| tvendov | 0:e1f465d87307 | 309 | /* FIX ME: errno not set correctly when error occurs. This indicates a problem with the implementation. */ |
| tvendov | 0:e1f465d87307 | 310 | |
| tvendov | 0:e1f465d87307 | 311 | /** @brief |
| tvendov | 0:e1f465d87307 | 312 | * Basic fopen test which does the following: |
| tvendov | 0:e1f465d87307 | 313 | * - creates file and writes some data to the value blob. |
| tvendov | 0:e1f465d87307 | 314 | * - closes the newly created file. |
| tvendov | 0:e1f465d87307 | 315 | * - opens the file (r-only) |
| tvendov | 0:e1f465d87307 | 316 | * - reads the file data and checks its the same as the previously created data. |
| tvendov | 0:e1f465d87307 | 317 | * - closes the opened file |
| tvendov | 0:e1f465d87307 | 318 | * |
| tvendov | 0:e1f465d87307 | 319 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 320 | */ |
| tvendov | 0:e1f465d87307 | 321 | static control_t fsfat_fopen_test_01(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 322 | { |
| tvendov | 0:e1f465d87307 | 323 | char *read_buf; |
| tvendov | 0:e1f465d87307 | 324 | int32_t ret = 0; |
| tvendov | 0:e1f465d87307 | 325 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 326 | fsfat_kv_data_t *node; |
| tvendov | 0:e1f465d87307 | 327 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 328 | |
| tvendov | 0:e1f465d87307 | 329 | FSFAT_DBGLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 330 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 331 | node = fsfat_fopen_test_01_kv_data; |
| tvendov | 0:e1f465d87307 | 332 | |
| tvendov | 0:e1f465d87307 | 333 | /* remove file and directory from a previous failed test run, if present */ |
| tvendov | 0:e1f465d87307 | 334 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 335 | |
| tvendov | 0:e1f465d87307 | 336 | /* create dirs */ |
| tvendov | 0:e1f465d87307 | 337 | ret = fsfat_filepath_make_dirs((char *) node->filename, true); |
| tvendov | 0:e1f465d87307 | 338 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 339 | "%s:Error: failed to create dirs for filename (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 340 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 341 | |
| tvendov | 0:e1f465d87307 | 342 | FSFAT_DBGLOG("%s:About to create new file (filename=\"%s\", data=\"%s\")\n", __func__, node->filename, node->value); |
| tvendov | 0:e1f465d87307 | 343 | fp = fopen(node->filename, "w+"); |
| tvendov | 0:e1f465d87307 | 344 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 345 | "%s:Error: failed to create file (filename=\"%s\", data=\"%s\")(ret=%d, errno=%d)\n", __func__, node->filename, |
| tvendov | 0:e1f465d87307 | 346 | node->value, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 347 | TEST_ASSERT_MESSAGE(fp != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 348 | |
| tvendov | 0:e1f465d87307 | 349 | FSFAT_DBGLOG("%s:length of file=%d (filename=\"%s\", data=\"%s\")\n", __func__, (int) len, node->filename, node->value); |
| tvendov | 0:e1f465d87307 | 350 | len = strlen(node->value); |
| tvendov | 0:e1f465d87307 | 351 | ret = fwrite((const void *) node->value, len, 1, fp); |
| tvendov | 0:e1f465d87307 | 352 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 353 | "%s:Error: failed to write file (filename=\"%s\", data=\"%s\")(ret=%d)\n", __func__, node->filename, node->value, |
| tvendov | 0:e1f465d87307 | 354 | (int) ret); |
| tvendov | 0:e1f465d87307 | 355 | TEST_ASSERT_MESSAGE(ret == 1, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 356 | |
| tvendov | 0:e1f465d87307 | 357 | FSFAT_DBGLOG("Created file successfully (filename=\"%s\", data=\"%s\")\n", node->filename, node->value); |
| tvendov | 0:e1f465d87307 | 358 | ret = fclose(fp); |
| tvendov | 0:e1f465d87307 | 359 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 360 | "%s:Error: failed to close file (ret=%d, errno=%d)\n", __func__, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 361 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 362 | |
| tvendov | 0:e1f465d87307 | 363 | /* now open the newly created key */ |
| tvendov | 0:e1f465d87307 | 364 | fp = NULL; |
| tvendov | 0:e1f465d87307 | 365 | fp = fopen(node->filename, "r"); |
| tvendov | 0:e1f465d87307 | 366 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 367 | "%s:Error: failed to open file for reading (filename=\"%s\", data=\"%s\")(ret=%d)\n", __func__, node->filename, |
| tvendov | 0:e1f465d87307 | 368 | node->value, (int) ret); |
| tvendov | 0:e1f465d87307 | 369 | TEST_ASSERT_MESSAGE(fp != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 370 | |
| tvendov | 0:e1f465d87307 | 371 | len = strlen(node->value) + 1; |
| tvendov | 0:e1f465d87307 | 372 | read_buf = (char *) malloc(len); |
| tvendov | 0:e1f465d87307 | 373 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 374 | "%s:Error: failed to allocated read buffer \n", __func__); |
| tvendov | 0:e1f465d87307 | 375 | TEST_ASSERT_MESSAGE(read_buf != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 376 | |
| tvendov | 0:e1f465d87307 | 377 | FSFAT_DBGLOG("Opened file successfully (filename=\"%s\", data=\"%s\")\n", node->filename, node->value); |
| tvendov | 0:e1f465d87307 | 378 | memset(read_buf, 0, len); |
| tvendov | 0:e1f465d87307 | 379 | ret = fread((void *) read_buf, len, 1, fp); |
| tvendov | 0:e1f465d87307 | 380 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 381 | "%s:Error: failed to read file (filename=\"%s\", data=\"%s\", read_buf=\"%s\", ret=%d)\n", __func__, node->filename, |
| tvendov | 0:e1f465d87307 | 382 | node->value, read_buf, (int) ret); |
| tvendov | 0:e1f465d87307 | 383 | /* FIX ME: fread should return the number of items read, not 0 when an item is read successfully. |
| tvendov | 0:e1f465d87307 | 384 | * This indicates a problem with the implementation, as the correct data is read. The correct assert should be: |
| tvendov | 0:e1f465d87307 | 385 | * TEST_ASSERT_MESSAGE(ret == 1, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 386 | * The following assert is curerntly used until the implementation is fixed |
| tvendov | 0:e1f465d87307 | 387 | */ |
| tvendov | 0:e1f465d87307 | 388 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 389 | |
| tvendov | 0:e1f465d87307 | 390 | /* check read data is as expected */ |
| tvendov | 0:e1f465d87307 | 391 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 392 | "%s:Error: read value data (%s) != expected value data (filename=\"%s\", data=\"%s\", read_buf=\"%s\", ret=%d)\n", |
| tvendov | 0:e1f465d87307 | 393 | __func__, read_buf, node->filename, node->value, read_buf, (int) ret); |
| tvendov | 0:e1f465d87307 | 394 | TEST_ASSERT_MESSAGE(strncmp(read_buf, node->value, strlen(node->value)) == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 395 | |
| tvendov | 0:e1f465d87307 | 396 | if (read_buf) { |
| tvendov | 0:e1f465d87307 | 397 | free(read_buf); |
| tvendov | 0:e1f465d87307 | 398 | } |
| tvendov | 0:e1f465d87307 | 399 | ret = fclose(fp); |
| tvendov | 0:e1f465d87307 | 400 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 401 | "%s:Error: fclose() call failed (ret=%d, errno=%d).\n", __func__, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 402 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 403 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 404 | } |
| tvendov | 0:e1f465d87307 | 405 | |
| tvendov | 0:e1f465d87307 | 406 | static fsfat_kv_data_t fsfat_fopen_test_02_data[] = { |
| tvendov | 0:e1f465d87307 | 407 | FSFAT_INIT_1_TABLE_MID_NODE, |
| tvendov | 0:e1f465d87307 | 408 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 409 | }; |
| tvendov | 0:e1f465d87307 | 410 | |
| tvendov | 0:e1f465d87307 | 411 | /** |
| tvendov | 0:e1f465d87307 | 412 | * @brief test to fopen() a pre-existing key and try to write it, which should fail |
| tvendov | 0:e1f465d87307 | 413 | * as by default pre-existing keys are opened read-only |
| tvendov | 0:e1f465d87307 | 414 | * |
| tvendov | 0:e1f465d87307 | 415 | * Basic open test which does the following: |
| tvendov | 0:e1f465d87307 | 416 | * - creates file with default rw perms and writes some data to the value blob. |
| tvendov | 0:e1f465d87307 | 417 | * - closes the newly created file. |
| tvendov | 0:e1f465d87307 | 418 | * - opens the file with the default permissions (read-only) |
| tvendov | 0:e1f465d87307 | 419 | * - tries to write the file data which should fail because file was not opened with write flag set. |
| tvendov | 0:e1f465d87307 | 420 | * - closes the opened key |
| tvendov | 0:e1f465d87307 | 421 | * |
| tvendov | 0:e1f465d87307 | 422 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 423 | */ |
| tvendov | 0:e1f465d87307 | 424 | control_t fsfat_fopen_test_02(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 425 | { |
| tvendov | 0:e1f465d87307 | 426 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 427 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 428 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 429 | |
| tvendov | 0:e1f465d87307 | 430 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 431 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 432 | len = strlen(fsfat_fopen_test_02_data[0].value); |
| tvendov | 0:e1f465d87307 | 433 | ret = fsfat_test_create(fsfat_fopen_test_02_data[0].filename, (char *) fsfat_fopen_test_02_data[0].value, len); |
| tvendov | 0:e1f465d87307 | 434 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 435 | "%s:Error: failed to create file (ret=%d).\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 436 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 437 | |
| tvendov | 0:e1f465d87307 | 438 | /* by default, owner of key opens with read-only permissions*/ |
| tvendov | 0:e1f465d87307 | 439 | fp = fopen(fsfat_fopen_test_02_data[0].filename, "r"); |
| tvendov | 0:e1f465d87307 | 440 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 441 | "%s:Error: failed to open file (filename=\"%s\", ret=%d)\n", __func__, fsfat_fopen_test_02_data[0].filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 442 | TEST_ASSERT_MESSAGE(fp != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 443 | |
| tvendov | 0:e1f465d87307 | 444 | len = strlen(fsfat_fopen_test_02_data[0].value); |
| tvendov | 0:e1f465d87307 | 445 | ret = fwrite((const void *) fsfat_fopen_test_02_data[0].value, len, 1, fp); |
| tvendov | 0:e1f465d87307 | 446 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 447 | "%s:Error: call to fwrite() succeeded when should have failed for read-only file (filename=\"%s\")(ret=%d).\n", |
| tvendov | 0:e1f465d87307 | 448 | __func__, fsfat_fopen_test_02_data[0].filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 449 | TEST_ASSERT_MESSAGE(ret <= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 450 | |
| tvendov | 0:e1f465d87307 | 451 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: fclose() call failed.\n", |
| tvendov | 0:e1f465d87307 | 452 | __func__); |
| tvendov | 0:e1f465d87307 | 453 | TEST_ASSERT_MESSAGE(fclose(fp) == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 454 | |
| tvendov | 0:e1f465d87307 | 455 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 456 | } |
| tvendov | 0:e1f465d87307 | 457 | |
| tvendov | 0:e1f465d87307 | 458 | |
| tvendov | 0:e1f465d87307 | 459 | /** |
| tvendov | 0:e1f465d87307 | 460 | * @brief test to fopen() a pre-existing file and try to write it, which should succeed |
| tvendov | 0:e1f465d87307 | 461 | * because the key was opened read-write permissions explicitly |
| tvendov | 0:e1f465d87307 | 462 | * |
| tvendov | 0:e1f465d87307 | 463 | * Basic open test which does the following: |
| tvendov | 0:e1f465d87307 | 464 | * - creates file with default rw perms and writes some data to the value blob. |
| tvendov | 0:e1f465d87307 | 465 | * - closes the newly created file. |
| tvendov | 0:e1f465d87307 | 466 | * - opens the file with the rw permissions (non default) |
| tvendov | 0:e1f465d87307 | 467 | * - tries to write the file data which should succeeds because file was opened with write flag set. |
| tvendov | 0:e1f465d87307 | 468 | * - closes the opened key |
| tvendov | 0:e1f465d87307 | 469 | * |
| tvendov | 0:e1f465d87307 | 470 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 471 | */ |
| tvendov | 0:e1f465d87307 | 472 | control_t fsfat_fopen_test_03(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 473 | { |
| tvendov | 0:e1f465d87307 | 474 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 475 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 476 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 477 | |
| tvendov | 0:e1f465d87307 | 478 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 479 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 480 | len = strlen(fsfat_fopen_test_02_data[0].value); |
| tvendov | 0:e1f465d87307 | 481 | ret = fsfat_test_create(fsfat_fopen_test_02_data[0].filename, (char *) fsfat_fopen_test_02_data[0].value, len); |
| tvendov | 0:e1f465d87307 | 482 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 483 | "%s:Error: failed to create file in store (ret=%d).\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 484 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 485 | |
| tvendov | 0:e1f465d87307 | 486 | /* opens with read-write permissions*/ |
| tvendov | 0:e1f465d87307 | 487 | fp = fopen(fsfat_fopen_test_02_data[0].filename, "w+"); |
| tvendov | 0:e1f465d87307 | 488 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 489 | "%s:Error: failed to open file (filename=\"%s\")(ret=%d)\n", __func__, fsfat_fopen_test_02_data[0].filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 490 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 491 | |
| tvendov | 0:e1f465d87307 | 492 | len = strlen(fsfat_fopen_test_02_data[0].value); |
| tvendov | 0:e1f465d87307 | 493 | ret = fwrite((const void *) fsfat_fopen_test_02_data[0].value, len, 1, fp); |
| tvendov | 0:e1f465d87307 | 494 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 495 | "%s:Error: call to fwrite() failed when should have succeeded (filename=\"%s\", ret=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 496 | fsfat_fopen_test_02_data[0].filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 497 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 498 | |
| tvendov | 0:e1f465d87307 | 499 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: fclose() call failed.\n", |
| tvendov | 0:e1f465d87307 | 500 | __func__); |
| tvendov | 0:e1f465d87307 | 501 | TEST_ASSERT_MESSAGE(fclose(fp) >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 502 | |
| tvendov | 0:e1f465d87307 | 503 | /* clean-up */ |
| tvendov | 0:e1f465d87307 | 504 | ret = remove(fsfat_fopen_test_02_data[0].filename); |
| tvendov | 0:e1f465d87307 | 505 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 506 | "%s:Error: unable to delete file (filename=%s, ret=%d) .\n", __func__, fsfat_fopen_test_02_data[0].filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 507 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 508 | |
| tvendov | 0:e1f465d87307 | 509 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 510 | } |
| tvendov | 0:e1f465d87307 | 511 | |
| tvendov | 0:e1f465d87307 | 512 | |
| tvendov | 0:e1f465d87307 | 513 | /** @brief test to call fopen() with a filename string that exceeds the maximum length |
| tvendov | 0:e1f465d87307 | 514 | * - chanFS supports the exFAT format which should support 255 char filenames |
| tvendov | 0:e1f465d87307 | 515 | * - check that filenames of this length can be created |
| tvendov | 0:e1f465d87307 | 516 | * |
| tvendov | 0:e1f465d87307 | 517 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 518 | */ |
| tvendov | 0:e1f465d87307 | 519 | control_t fsfat_fopen_test_04(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 520 | { |
| tvendov | 0:e1f465d87307 | 521 | char filename_good[FSFAT_FILENAME_MAX_LENGTH + 1]; |
| tvendov | 0:e1f465d87307 | 522 | char filename_bad[FSFAT_FILENAME_MAX_LENGTH + 2]; |
| tvendov | 0:e1f465d87307 | 523 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 524 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 525 | |
| tvendov | 0:e1f465d87307 | 526 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 527 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 528 | |
| tvendov | 0:e1f465d87307 | 529 | memset(filename_good, 0, FSFAT_FILENAME_MAX_LENGTH + 1); |
| tvendov | 0:e1f465d87307 | 530 | memset(filename_bad, 0, FSFAT_FILENAME_MAX_LENGTH + 2); |
| tvendov | 0:e1f465d87307 | 531 | ret = fsfat_test_filename_gen(filename_good, FSFAT_FILENAME_MAX_LENGTH); |
| tvendov | 0:e1f465d87307 | 532 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 533 | "%s:Error: unable to generate filename_good.\n", __func__); |
| tvendov | 0:e1f465d87307 | 534 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 535 | |
| tvendov | 0:e1f465d87307 | 536 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 537 | "%s:Error: filename_good is not the correct length (filename_good=%s, len=%d, expected=%d).\n", __func__, filename_good, |
| tvendov | 0:e1f465d87307 | 538 | (int) strlen(filename_good), (int) FSFAT_FILENAME_MAX_LENGTH); |
| tvendov | 0:e1f465d87307 | 539 | TEST_ASSERT_MESSAGE(strlen(filename_good) == FSFAT_FILENAME_MAX_LENGTH, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 540 | |
| tvendov | 0:e1f465d87307 | 541 | ret = fsfat_test_filename_gen(filename_bad, FSFAT_FILENAME_MAX_LENGTH + 1); |
| tvendov | 0:e1f465d87307 | 542 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 543 | "%s:Error: unable to generate filename_bad.\n", __func__); |
| tvendov | 0:e1f465d87307 | 544 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 545 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 546 | "%s:Error: filename_bad is not the correct length (len=%d, expected=%d).\n", __func__, (int) strlen(filename_bad), |
| tvendov | 0:e1f465d87307 | 547 | (int) FSFAT_FILENAME_MAX_LENGTH + 1); |
| tvendov | 0:e1f465d87307 | 548 | TEST_ASSERT_MESSAGE(strlen(filename_bad) == FSFAT_FILENAME_MAX_LENGTH + 1, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 549 | |
| tvendov | 0:e1f465d87307 | 550 | len = strlen(filename_good); |
| tvendov | 0:e1f465d87307 | 551 | ret = fsfat_test_create(filename_good, filename_good, len); |
| tvendov | 0:e1f465d87307 | 552 | /* FIXME: |
| tvendov | 0:e1f465d87307 | 553 | * The current implementation can create file with a filename with 9 chars (more than the 8 restriction of FAT32 Short File Names). |
| tvendov | 0:e1f465d87307 | 554 | * However, the exFAT 255 char filesnames is not supported and hence the following is commented out. Find out what is |
| tvendov | 0:e1f465d87307 | 555 | * the supported max filename length and change this testcase according. |
| tvendov | 0:e1f465d87307 | 556 | * |
| tvendov | 0:e1f465d87307 | 557 | * FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create file (filename=%s, ret=%d).\n", __func__, filename_good, (int) ret); |
| tvendov | 0:e1f465d87307 | 558 | * TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 559 | */ |
| tvendov | 0:e1f465d87307 | 560 | |
| tvendov | 0:e1f465d87307 | 561 | len = strlen(filename_bad); |
| tvendov | 0:e1f465d87307 | 562 | ret = fsfat_test_create(filename_bad, filename_bad, len); |
| tvendov | 0:e1f465d87307 | 563 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 564 | "%s:Error: created file in store for filename_bad when should have failed (filename=%s, ret=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 565 | filename_bad, (int) ret); |
| tvendov | 0:e1f465d87307 | 566 | TEST_ASSERT_MESSAGE(ret < 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 567 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 568 | } |
| tvendov | 0:e1f465d87307 | 569 | |
| tvendov | 0:e1f465d87307 | 570 | |
| tvendov | 0:e1f465d87307 | 571 | /// @cond FSFAT_DOXYGEN_DISABLE |
| tvendov | 0:e1f465d87307 | 572 | typedef struct fsfat_fopen_kv_name_ascii_node { |
| tvendov | 0:e1f465d87307 | 573 | uint32_t code; |
| tvendov | 0:e1f465d87307 | 574 | uint32_t f_allowed : 1; |
| tvendov | 0:e1f465d87307 | 575 | } fsfat_fopen_kv_name_ascii_node; |
| tvendov | 0:e1f465d87307 | 576 | /// @endcond |
| tvendov | 0:e1f465d87307 | 577 | |
| tvendov | 0:e1f465d87307 | 578 | static const uint32_t fsfat_fopen_kv_name_ascii_table_code_sentinel_g = 256; |
| tvendov | 0:e1f465d87307 | 579 | |
| tvendov | 0:e1f465d87307 | 580 | /*@brief table recording ascii character codes permitted in kv names */ |
| tvendov | 0:e1f465d87307 | 581 | static fsfat_fopen_kv_name_ascii_node fsfat_fopen_kv_name_ascii_table[] = { |
| tvendov | 0:e1f465d87307 | 582 | {0, true}, /* code 0-33 allowed*/ |
| tvendov | 0:e1f465d87307 | 583 | {34, false}, /* '"' not allowed */ |
| tvendov | 0:e1f465d87307 | 584 | {35, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 585 | {42, false}, /* '*' not allowed */ |
| tvendov | 0:e1f465d87307 | 586 | {43, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 587 | {47, false}, /* '/' not allowed */ |
| tvendov | 0:e1f465d87307 | 588 | {48, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 589 | {58, false}, /* ':' not allowed */ |
| tvendov | 0:e1f465d87307 | 590 | {59, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 591 | {60, false}, /* '<' not allowed */ |
| tvendov | 0:e1f465d87307 | 592 | {61, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 593 | {62, false}, /* '?', '>' not allowed */ |
| tvendov | 0:e1f465d87307 | 594 | {64, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 595 | {92, false}, /* '\' not allowed */ |
| tvendov | 0:e1f465d87307 | 596 | {93, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 597 | {124, false}, /* '!' not allowed */ |
| tvendov | 0:e1f465d87307 | 598 | {125, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 599 | {127, false}, /* DEL not allowed */ |
| tvendov | 0:e1f465d87307 | 600 | {128, true}, /* allowed */ |
| tvendov | 0:e1f465d87307 | 601 | {fsfat_fopen_kv_name_ascii_table_code_sentinel_g, false}, /* sentinel */ |
| tvendov | 0:e1f465d87307 | 602 | }; |
| tvendov | 0:e1f465d87307 | 603 | |
| tvendov | 0:e1f465d87307 | 604 | |
| tvendov | 0:e1f465d87307 | 605 | /// @cond FSFAT_DOXYGEN_DISABLE |
| tvendov | 0:e1f465d87307 | 606 | enum fsfat_fopen_kv_name_pos { |
| tvendov | 0:e1f465d87307 | 607 | fsfat_fopen_kv_name_pos_start = 0x0, |
| tvendov | 0:e1f465d87307 | 608 | fsfat_fopen_kv_name_pos_mid, |
| tvendov | 0:e1f465d87307 | 609 | fsfat_fopen_kv_name_pos_end, |
| tvendov | 0:e1f465d87307 | 610 | fsfat_fopen_kv_name_pos_max |
| tvendov | 0:e1f465d87307 | 611 | }; |
| tvendov | 0:e1f465d87307 | 612 | /// @endcond |
| tvendov | 0:e1f465d87307 | 613 | |
| tvendov | 0:e1f465d87307 | 614 | /** @brief test to call fopen() with filename that in includes illegal characters |
| tvendov | 0:e1f465d87307 | 615 | * - the character(s) can be at the beginning of the filename |
| tvendov | 0:e1f465d87307 | 616 | * - the character(s) can be at the end of the filename |
| tvendov | 0:e1f465d87307 | 617 | * - the character(s) can be somewhere within the filename string |
| tvendov | 0:e1f465d87307 | 618 | * - a max-length string of random characters (legal and illegal) |
| tvendov | 0:e1f465d87307 | 619 | * - a max-length string of random illegal characters only |
| tvendov | 0:e1f465d87307 | 620 | * |
| tvendov | 0:e1f465d87307 | 621 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 622 | */ |
| tvendov | 0:e1f465d87307 | 623 | control_t fsfat_fopen_test_05(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 624 | { |
| tvendov | 0:e1f465d87307 | 625 | bool f_allowed = false; |
| tvendov | 0:e1f465d87307 | 626 | const char *mnt_pt = FSFAT_FOPEN_TEST_MOUNT_PT_PATH; |
| tvendov | 0:e1f465d87307 | 627 | const char *basename = "goodfile"; |
| tvendov | 0:e1f465d87307 | 628 | const char *extname = "txt"; |
| tvendov | 0:e1f465d87307 | 629 | const size_t basename_len = strlen(basename); |
| tvendov | 0:e1f465d87307 | 630 | const size_t filename_len = strlen(mnt_pt) + strlen(basename) + strlen(extname) + |
| tvendov | 0:e1f465d87307 | 631 | 2; /* extra 2 chars for '/' and '.' in "/sd/goodfile.txt" */ |
| tvendov | 0:e1f465d87307 | 632 | char filename[FSFAT_BUF_MAX_LENGTH]; |
| tvendov | 0:e1f465d87307 | 633 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 634 | uint32_t j = 0; |
| tvendov | 0:e1f465d87307 | 635 | int32_t ret = 0; |
| tvendov | 0:e1f465d87307 | 636 | fsfat_fopen_kv_name_ascii_node *node = NULL; |
| tvendov | 0:e1f465d87307 | 637 | uint32_t pos; |
| tvendov | 0:e1f465d87307 | 638 | |
| tvendov | 0:e1f465d87307 | 639 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 640 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 641 | |
| tvendov | 0:e1f465d87307 | 642 | #ifdef FSFAT_DEBUG |
| tvendov | 0:e1f465d87307 | 643 | /* symbol only used why debug is enabled */ |
| tvendov | 0:e1f465d87307 | 644 | const char *pos_str = NULL; |
| tvendov | 0:e1f465d87307 | 645 | #endif |
| tvendov | 0:e1f465d87307 | 646 | |
| tvendov | 0:e1f465d87307 | 647 | /* create bad keyname strings with invalid character code at start of keyname */ |
| tvendov | 0:e1f465d87307 | 648 | node = fsfat_fopen_kv_name_ascii_table; |
| tvendov | 0:e1f465d87307 | 649 | memset(filename, 0, FSFAT_BUF_MAX_LENGTH); |
| tvendov | 0:e1f465d87307 | 650 | while (node->code != fsfat_fopen_kv_name_ascii_table_code_sentinel_g) { |
| tvendov | 0:e1f465d87307 | 651 | /* loop over range */ |
| tvendov | 0:e1f465d87307 | 652 | for (j = node->code; j < (node + 1)->code; j++) { |
| tvendov | 0:e1f465d87307 | 653 | if ((j >= 48 && j <= 57) || (j >= 65 && j <= 90) || (j >= 97 && j <= 122)) { |
| tvendov | 0:e1f465d87307 | 654 | FSFAT_DBGLOG("%s: skipping alpha-numeric ascii character code %d (%c).\n", __func__, (int) j, (char) j); |
| tvendov | 0:e1f465d87307 | 655 | continue; |
| tvendov | 0:e1f465d87307 | 656 | } |
| tvendov | 0:e1f465d87307 | 657 | |
| tvendov | 0:e1f465d87307 | 658 | /* set the start, mid, last character of the name to the test char code */ |
| tvendov | 0:e1f465d87307 | 659 | for (pos = (uint32_t) fsfat_fopen_kv_name_pos_start; pos < (uint32_t) fsfat_fopen_kv_name_pos_max; pos++) { |
| tvendov | 0:e1f465d87307 | 660 | len = snprintf(filename, filename_len + 1, "%s/%s.%s", mnt_pt, basename, extname); |
| tvendov | 0:e1f465d87307 | 661 | /* overwrite a char at the pos start, mid, end of the filename with an ascii char code (both illegal and legal)*/ |
| tvendov | 0:e1f465d87307 | 662 | switch (pos) { |
| tvendov | 0:e1f465d87307 | 663 | case fsfat_fopen_kv_name_pos_start: |
| tvendov | 0:e1f465d87307 | 664 | filename[5] = (char) j; /* 5 so at to write the second basename char (bad chars as first char not accepted)*/ |
| tvendov | 0:e1f465d87307 | 665 | break; |
| tvendov | 0:e1f465d87307 | 666 | case fsfat_fopen_kv_name_pos_mid: |
| tvendov | 0:e1f465d87307 | 667 | /* create bad keyname strings with invalid character code in the middle of keyname */ |
| tvendov | 0:e1f465d87307 | 668 | filename[5 + basename_len / 2] = (char) j; |
| tvendov | 0:e1f465d87307 | 669 | break; |
| tvendov | 0:e1f465d87307 | 670 | case fsfat_fopen_kv_name_pos_end: |
| tvendov | 0:e1f465d87307 | 671 | /* create bad keyname strings with invalid character code at end of keyname */ |
| tvendov | 0:e1f465d87307 | 672 | filename[5 + basename_len - 1] = (char) j; |
| tvendov | 0:e1f465d87307 | 673 | break; |
| tvendov | 0:e1f465d87307 | 674 | default: |
| tvendov | 0:e1f465d87307 | 675 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 676 | "%s:Error: unexpected value of pos (pos=%d).\n", __func__, (int) pos); |
| tvendov | 0:e1f465d87307 | 677 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 678 | break; |
| tvendov | 0:e1f465d87307 | 679 | } |
| tvendov | 0:e1f465d87307 | 680 | |
| tvendov | 0:e1f465d87307 | 681 | #ifdef FSFAT_DEBUG |
| tvendov | 0:e1f465d87307 | 682 | /* processing only required when debug trace enabled */ |
| tvendov | 0:e1f465d87307 | 683 | switch (pos) { |
| tvendov | 0:e1f465d87307 | 684 | case fsfat_fopen_kv_name_pos_start: |
| tvendov | 0:e1f465d87307 | 685 | pos_str = "start"; |
| tvendov | 0:e1f465d87307 | 686 | break; |
| tvendov | 0:e1f465d87307 | 687 | case fsfat_fopen_kv_name_pos_mid: |
| tvendov | 0:e1f465d87307 | 688 | pos_str = "middle"; |
| tvendov | 0:e1f465d87307 | 689 | break; |
| tvendov | 0:e1f465d87307 | 690 | case fsfat_fopen_kv_name_pos_end: |
| tvendov | 0:e1f465d87307 | 691 | pos_str = "end"; |
| tvendov | 0:e1f465d87307 | 692 | break; |
| tvendov | 0:e1f465d87307 | 693 | default: |
| tvendov | 0:e1f465d87307 | 694 | break; |
| tvendov | 0:e1f465d87307 | 695 | } |
| tvendov | 0:e1f465d87307 | 696 | #endif |
| tvendov | 0:e1f465d87307 | 697 | ret = fsfat_test_create(filename, (const char *) filename, len); |
| tvendov | 0:e1f465d87307 | 698 | |
| tvendov | 0:e1f465d87307 | 699 | /* special cases */ |
| tvendov | 0:e1f465d87307 | 700 | switch (j) { |
| tvendov | 0:e1f465d87307 | 701 | //case 0 : |
| tvendov | 0:e1f465d87307 | 702 | //case 46 : |
| tvendov | 0:e1f465d87307 | 703 | // switch(pos) |
| tvendov | 0:e1f465d87307 | 704 | // { |
| tvendov | 0:e1f465d87307 | 705 | // /* for code = 0 (null terminator). permitted at mid and end of string */ |
| tvendov | 0:e1f465d87307 | 706 | // /* for code = 46 ('.'). permitted at mid and end of string but not at start */ |
| tvendov | 0:e1f465d87307 | 707 | // case fsfat_fopen_kv_name_pos_start: |
| tvendov | 0:e1f465d87307 | 708 | // f_allowed = false; |
| tvendov | 0:e1f465d87307 | 709 | // break; |
| tvendov | 0:e1f465d87307 | 710 | // case fsfat_fopen_kv_name_pos_mid: |
| tvendov | 0:e1f465d87307 | 711 | // case fsfat_fopen_kv_name_pos_end: |
| tvendov | 0:e1f465d87307 | 712 | // default: |
| tvendov | 0:e1f465d87307 | 713 | // f_allowed = true; |
| tvendov | 0:e1f465d87307 | 714 | // break; |
| tvendov | 0:e1f465d87307 | 715 | // } |
| tvendov | 0:e1f465d87307 | 716 | // break; |
| tvendov | 0:e1f465d87307 | 717 | default: |
| tvendov | 0:e1f465d87307 | 718 | f_allowed = node->f_allowed; |
| tvendov | 0:e1f465d87307 | 719 | break; |
| tvendov | 0:e1f465d87307 | 720 | } |
| tvendov | 0:e1f465d87307 | 721 | if (f_allowed == true) { |
| tvendov | 0:e1f465d87307 | 722 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 723 | "%s:Error: failed to create file in store when filename contains valid characters (code=%d, ret=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 724 | (int) j, (int) ret); |
| tvendov | 0:e1f465d87307 | 725 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 726 | /* revert FSFAT_LOG for more trace */ |
| tvendov | 0:e1f465d87307 | 727 | FSFAT_DBGLOG("Successfully created a file with valid keyname containing ascii character code %d (%c) at the %s of the keyname.\n", |
| tvendov | 0:e1f465d87307 | 728 | (int) j, (int) j, pos_str); |
| tvendov | 0:e1f465d87307 | 729 | FSFAT_LOG("%c", '.'); |
| tvendov | 0:e1f465d87307 | 730 | |
| tvendov | 0:e1f465d87307 | 731 | ret = fsfat_test_delete(filename); |
| tvendov | 0:e1f465d87307 | 732 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 733 | "%s:Error: failed to delete file previously created (code=%d, ret=%d).\n", __func__, (int) j, (int) ret); |
| tvendov | 0:e1f465d87307 | 734 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 735 | } else { |
| tvendov | 0:e1f465d87307 | 736 | /*node->f_allowed == false => not allowed to create kv name with ascii code */ |
| tvendov | 0:e1f465d87307 | 737 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 738 | "%s:Error: created file in store when filename contains an invalid character (code=%d, ret=%d).\n", __func__, (int) j, |
| tvendov | 0:e1f465d87307 | 739 | (int) ret); |
| tvendov | 0:e1f465d87307 | 740 | TEST_ASSERT_MESSAGE(ret < 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 741 | /* revert FSFAT_LOG for more trace */ |
| tvendov | 0:e1f465d87307 | 742 | FSFAT_DBGLOG("Successfully failed to create a file with an invalid keyname containing ascii character code %d at the %s of the keyname.\n", |
| tvendov | 0:e1f465d87307 | 743 | (int) j, pos_str); |
| tvendov | 0:e1f465d87307 | 744 | FSFAT_LOG("%c", '.'); |
| tvendov | 0:e1f465d87307 | 745 | } |
| tvendov | 0:e1f465d87307 | 746 | } |
| tvendov | 0:e1f465d87307 | 747 | } |
| tvendov | 0:e1f465d87307 | 748 | node++; |
| tvendov | 0:e1f465d87307 | 749 | } |
| tvendov | 0:e1f465d87307 | 750 | |
| tvendov | 0:e1f465d87307 | 751 | FSFAT_LOG("%c", '\n'); |
| tvendov | 0:e1f465d87307 | 752 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 753 | } |
| tvendov | 0:e1f465d87307 | 754 | |
| tvendov | 0:e1f465d87307 | 755 | |
| tvendov | 0:e1f465d87307 | 756 | static const char fsfat_fopen_ascii_illegal_buf_g[] = "\"�'*+,./:;<=>?[\\]|"; |
| tvendov | 0:e1f465d87307 | 757 | |
| tvendov | 0:e1f465d87307 | 758 | /** @brief test to call fopen() with filename that in includes |
| tvendov | 0:e1f465d87307 | 759 | * illegal characters |
| tvendov | 0:e1f465d87307 | 760 | * - a max-length string of random illegal characters only |
| tvendov | 0:e1f465d87307 | 761 | * |
| tvendov | 0:e1f465d87307 | 762 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 763 | */ |
| tvendov | 0:e1f465d87307 | 764 | control_t fsfat_fopen_test_06(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 765 | { |
| tvendov | 0:e1f465d87307 | 766 | const char *mnt_pt = FSFAT_FOPEN_TEST_MOUNT_PT_PATH; |
| tvendov | 0:e1f465d87307 | 767 | const char *extname = "txt"; |
| tvendov | 0:e1f465d87307 | 768 | const size_t filename_len = strlen(mnt_pt) + FSFAT_MAX_FILE_BASENAME + strlen(extname) + |
| tvendov | 0:e1f465d87307 | 769 | 2; /* extra 2 chars for '/' and '.' in "/sd/goodfile.txt" */ |
| tvendov | 0:e1f465d87307 | 770 | char filename[FSFAT_BUF_MAX_LENGTH]; |
| tvendov | 0:e1f465d87307 | 771 | int32_t i = 0; |
| tvendov | 0:e1f465d87307 | 772 | int32_t j = 0; |
| tvendov | 0:e1f465d87307 | 773 | uint32_t pos = 0; |
| tvendov | 0:e1f465d87307 | 774 | uint32_t len = 0; |
| tvendov | 0:e1f465d87307 | 775 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 776 | size_t buf_data_max = 0; |
| tvendov | 0:e1f465d87307 | 777 | |
| tvendov | 0:e1f465d87307 | 778 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 779 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 780 | |
| tvendov | 0:e1f465d87307 | 781 | memset(filename, 0, FSFAT_BUF_MAX_LENGTH); |
| tvendov | 0:e1f465d87307 | 782 | /* create bad keyname strings with invalid character code at start of keyname */ |
| tvendov | 0:e1f465d87307 | 783 | buf_data_max = strlen(fsfat_fopen_ascii_illegal_buf_g); |
| tvendov | 0:e1f465d87307 | 784 | |
| tvendov | 0:e1f465d87307 | 785 | /* generate a number of illegal filenames */ |
| tvendov | 0:e1f465d87307 | 786 | for (j = 0; i < FSFAT_MAX_FILE_BASENAME; j++) { |
| tvendov | 0:e1f465d87307 | 787 | /* generate a kv name of illegal chars*/ |
| tvendov | 0:e1f465d87307 | 788 | len = snprintf(filename, filename_len + 1, "%s/", mnt_pt); |
| tvendov | 0:e1f465d87307 | 789 | for (i = 0; i < FSFAT_MAX_FILE_BASENAME; i++) { |
| tvendov | 0:e1f465d87307 | 790 | pos = rand() % (buf_data_max + 1); |
| tvendov | 0:e1f465d87307 | 791 | len += snprintf(filename + len, filename_len + 1, "%c", fsfat_fopen_ascii_illegal_buf_g[pos]); |
| tvendov | 0:e1f465d87307 | 792 | |
| tvendov | 0:e1f465d87307 | 793 | } |
| tvendov | 0:e1f465d87307 | 794 | len += snprintf(filename + len, filename_len + 1, ".%s", extname); |
| tvendov | 0:e1f465d87307 | 795 | ret = fsfat_test_create(filename, filename, len); |
| tvendov | 0:e1f465d87307 | 796 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 797 | "%s:Error: created file when filename contains invalid characters (filename=%s, ret=%d).\n", __func__, filename, |
| tvendov | 0:e1f465d87307 | 798 | (int) ret); |
| tvendov | 0:e1f465d87307 | 799 | TEST_ASSERT_MESSAGE(ret < 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 800 | } |
| tvendov | 0:e1f465d87307 | 801 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 802 | } |
| tvendov | 0:e1f465d87307 | 803 | |
| tvendov | 0:e1f465d87307 | 804 | |
| tvendov | 0:e1f465d87307 | 805 | /** @brief test for errno reporting on a failed fopen()call |
| tvendov | 0:e1f465d87307 | 806 | * |
| tvendov | 0:e1f465d87307 | 807 | * This test does the following: |
| tvendov | 0:e1f465d87307 | 808 | * - tries to open a file that does not exist for reading, and checks that a NULL pointer is returned. |
| tvendov | 0:e1f465d87307 | 809 | * - checks that errno is not 0 as there is an error. |
| tvendov | 0:e1f465d87307 | 810 | * - checks that ferror() returns 1 indicating an error exists. |
| tvendov | 0:e1f465d87307 | 811 | * |
| tvendov | 0:e1f465d87307 | 812 | * Note: see NOTE_1 below. |
| tvendov | 0:e1f465d87307 | 813 | * |
| tvendov | 0:e1f465d87307 | 814 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 815 | */ |
| tvendov | 0:e1f465d87307 | 816 | control_t fsfat_fopen_test_07(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 817 | { |
| tvendov | 0:e1f465d87307 | 818 | FILE *f = NULL; |
| tvendov | 0:e1f465d87307 | 819 | int ret = -1; |
| tvendov | 0:e1f465d87307 | 820 | int errno_val = 0; |
| tvendov | 0:e1f465d87307 | 821 | const char *filename = sd_badfile_path; |
| tvendov | 0:e1f465d87307 | 822 | |
| tvendov | 0:e1f465d87307 | 823 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 824 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 825 | |
| tvendov | 0:e1f465d87307 | 826 | errno = 0; |
| tvendov | 0:e1f465d87307 | 827 | /* this is expect to fail as the file doesnt exist */ |
| tvendov | 0:e1f465d87307 | 828 | f = fopen(filename, "r"); |
| tvendov | 0:e1f465d87307 | 829 | |
| tvendov | 0:e1f465d87307 | 830 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 831 | "%s:Error: opened non-existent file for reading (filename=%s, f=%p).\n", __func__, filename, f); |
| tvendov | 0:e1f465d87307 | 832 | TEST_ASSERT_MESSAGE(f == NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 833 | |
| tvendov | 0:e1f465d87307 | 834 | /* check errno is set correctly */ |
| tvendov | 0:e1f465d87307 | 835 | #if ! defined(__ARMCC_VERSION) && defined(__GNUC__) |
| tvendov | 0:e1f465d87307 | 836 | /* Store errno so the current value set is not changed by new function call */ |
| tvendov | 0:e1f465d87307 | 837 | errno_val = errno; |
| tvendov | 0:e1f465d87307 | 838 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 839 | "%s:Error: errno has unexpected value (errno != 0 expected) (filename=%s, errno=%d).\n", __func__, filename, errno); |
| tvendov | 0:e1f465d87307 | 840 | TEST_ASSERT_MESSAGE(errno_val != 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 841 | #endif /* ! defined(__ARMCC_VERSION) && defined(__GNUC__) */ |
| tvendov | 0:e1f465d87307 | 842 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 843 | } |
| tvendov | 0:e1f465d87307 | 844 | |
| tvendov | 0:e1f465d87307 | 845 | |
| tvendov | 0:e1f465d87307 | 846 | /** @brief test for operation of clearerr() and ferror() |
| tvendov | 0:e1f465d87307 | 847 | * |
| tvendov | 0:e1f465d87307 | 848 | * The test does the following: |
| tvendov | 0:e1f465d87307 | 849 | * - opens and then closes a file, but keeps a copy of the FILE pointer fp. |
| tvendov | 0:e1f465d87307 | 850 | * - set errno to 0. |
| tvendov | 0:e1f465d87307 | 851 | * - write to the close file with fwrite(fp) which should return 0 (no writes) and set the errno. |
| tvendov | 0:e1f465d87307 | 852 | * - check the error condition is set with ferror(). |
| tvendov | 0:e1f465d87307 | 853 | * - clear the error with clearerr(). |
| tvendov | 0:e1f465d87307 | 854 | * - check the error condition is reset with ferror(). |
| tvendov | 0:e1f465d87307 | 855 | * |
| tvendov | 0:e1f465d87307 | 856 | * NOTE_1: GCC/ARMCC support for setting errno |
| tvendov | 0:e1f465d87307 | 857 | * - Documentation (e.g. fwrite() man page) does not explicity say fwrite() sets errno |
| tvendov | 0:e1f465d87307 | 858 | * (e.g. for an fwrite() on a read-only file). |
| tvendov | 0:e1f465d87307 | 859 | * - GCC libc fwrite() appears to set errno as expected. |
| tvendov | 0:e1f465d87307 | 860 | * - ARMCC & IAR libc fwrite() appears not to set errno. |
| tvendov | 0:e1f465d87307 | 861 | * |
| tvendov | 0:e1f465d87307 | 862 | * The following ARMCC documents are silent on whether fwrite() sets errno: |
| tvendov | 0:e1f465d87307 | 863 | * - "ARM C and C++ Libraries and Floating-Point Support". |
| tvendov | 0:e1f465d87307 | 864 | * - "RL-ARM User Guide fwrite() section". |
| tvendov | 0:e1f465d87307 | 865 | * |
| tvendov | 0:e1f465d87307 | 866 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 867 | */ |
| tvendov | 0:e1f465d87307 | 868 | control_t fsfat_fopen_test_08(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 869 | { |
| tvendov | 0:e1f465d87307 | 870 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 871 | int ret = -1; |
| tvendov | 0:e1f465d87307 | 872 | int ret_ferror = -1; |
| tvendov | 0:e1f465d87307 | 873 | const char *filename = sd_testfile_path; |
| tvendov | 0:e1f465d87307 | 874 | |
| tvendov | 0:e1f465d87307 | 875 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 876 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 877 | |
| tvendov | 0:e1f465d87307 | 878 | errno = 0; |
| tvendov | 0:e1f465d87307 | 879 | fp = fopen(filename, "w+"); |
| tvendov | 0:e1f465d87307 | 880 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 881 | "%s:Error: failed to open file (filename=%s, f=%p).\n", __func__, filename, fp); |
| tvendov | 0:e1f465d87307 | 882 | TEST_ASSERT_MESSAGE(fp != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 883 | |
| tvendov | 0:e1f465d87307 | 884 | /* close the fp but then try to read or write it */ |
| tvendov | 0:e1f465d87307 | 885 | ret = fclose(fp); |
| tvendov | 0:e1f465d87307 | 886 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 887 | "%s:Error: failed to close file (ret=%d, errno=%d)\n", __func__, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 888 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 889 | |
| tvendov | 0:e1f465d87307 | 890 | /* open file */ |
| tvendov | 0:e1f465d87307 | 891 | errno = 0; |
| tvendov | 0:e1f465d87307 | 892 | fp = fopen(filename, "r"); |
| tvendov | 0:e1f465d87307 | 893 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 894 | "%s:Error: failed to open file for reading (filename=\"%s\", ret=%d)\n", __func__, filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 895 | TEST_ASSERT_MESSAGE(fp != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 896 | |
| tvendov | 0:e1f465d87307 | 897 | /* Perform fwrite() operation that will fail. */ |
| tvendov | 0:e1f465d87307 | 898 | errno = 0; |
| tvendov | 0:e1f465d87307 | 899 | ret = fwrite("42!", 4, 1, fp); |
| tvendov | 0:e1f465d87307 | 900 | |
| tvendov | 0:e1f465d87307 | 901 | ret_ferror = ferror(fp); |
| tvendov | 0:e1f465d87307 | 902 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 903 | "%s:Error: ferror() failed to report error (filename=%s, ret_ferror=%d).\n", __func__, filename, (int) ret_ferror); |
| tvendov | 0:e1f465d87307 | 904 | TEST_ASSERT_MESSAGE(ret_ferror != 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 905 | |
| tvendov | 0:e1f465d87307 | 906 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 907 | "%s:Error: fwrite successfully wrote to read-only file (filename=%s, ret=%d).\n", __func__, filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 908 | /* the fwrite() should fail and return 0. */ |
| tvendov | 0:e1f465d87307 | 909 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 910 | |
| tvendov | 0:e1f465d87307 | 911 | #if ! defined(__ARMCC_VERSION) && defined(__GNUC__) |
| tvendov | 0:e1f465d87307 | 912 | /* check that errno is set. ARMCC appears not to set errno for fwrite() failure. */ |
| tvendov | 0:e1f465d87307 | 913 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 914 | "%s:Error: unexpected zero value for errno (filename=%s, ret=%d, errno=%d).\n", __func__, filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 915 | TEST_ASSERT_MESSAGE(errno != 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 916 | |
| tvendov | 0:e1f465d87307 | 917 | /* check that errno is set to the expected value (this may change differ for different libc's) */ |
| tvendov | 0:e1f465d87307 | 918 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 919 | "%s:Error: errno != EBADF (filename=%s, ret=%d, errno=%d).\n", __func__, filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 920 | TEST_ASSERT_MESSAGE(errno == EBADF, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 921 | #endif /* ! defined(__ARMCC_VERSION) && defined(__GNUC__) */ |
| tvendov | 0:e1f465d87307 | 922 | |
| tvendov | 0:e1f465d87307 | 923 | /* check clearerr() return clears the error */ |
| tvendov | 0:e1f465d87307 | 924 | clearerr(fp); |
| tvendov | 0:e1f465d87307 | 925 | ret = ferror(fp); |
| tvendov | 0:e1f465d87307 | 926 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 927 | "%s:Error: ferror() did not return zero value when error has been cleared (filename=%s, ret=%d).\n", __func__, filename, |
| tvendov | 0:e1f465d87307 | 928 | (int) ret); |
| tvendov | 0:e1f465d87307 | 929 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 930 | |
| tvendov | 0:e1f465d87307 | 931 | fclose(fp); |
| tvendov | 0:e1f465d87307 | 932 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 933 | } |
| tvendov | 0:e1f465d87307 | 934 | |
| tvendov | 0:e1f465d87307 | 935 | |
| tvendov | 0:e1f465d87307 | 936 | /** @brief test for operation of ftell() |
| tvendov | 0:e1f465d87307 | 937 | * |
| tvendov | 0:e1f465d87307 | 938 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 939 | */ |
| tvendov | 0:e1f465d87307 | 940 | control_t fsfat_fopen_test_09(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 941 | { |
| tvendov | 0:e1f465d87307 | 942 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 943 | int ret = -1; |
| tvendov | 0:e1f465d87307 | 944 | int32_t len = 0; |
| tvendov | 0:e1f465d87307 | 945 | |
| tvendov | 0:e1f465d87307 | 946 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 947 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 948 | |
| tvendov | 0:e1f465d87307 | 949 | /* create a file of a certain length */ |
| tvendov | 0:e1f465d87307 | 950 | len = strlen(fsfat_fopen_test_02_data[0].value); |
| tvendov | 0:e1f465d87307 | 951 | ret = fsfat_test_create(fsfat_fopen_test_02_data[0].filename, (char *) fsfat_fopen_test_02_data[0].value, len); |
| tvendov | 0:e1f465d87307 | 952 | |
| tvendov | 0:e1f465d87307 | 953 | errno = 0; |
| tvendov | 0:e1f465d87307 | 954 | /* Open the file for reading so the file is not truncated to 0 length. */ |
| tvendov | 0:e1f465d87307 | 955 | fp = fopen(fsfat_fopen_test_02_data[0].filename, "r"); |
| tvendov | 0:e1f465d87307 | 956 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 957 | "%s:Error: failed to open file (filename=%s, fp=%p, errno=%d).\n", __func__, fsfat_fopen_test_02_data[0].filename, fp, |
| tvendov | 0:e1f465d87307 | 958 | errno); |
| tvendov | 0:e1f465d87307 | 959 | TEST_ASSERT_MESSAGE(fp != NULL, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 960 | |
| tvendov | 0:e1f465d87307 | 961 | errno = 0; |
| tvendov | 0:e1f465d87307 | 962 | ret = fseek(fp, 0, SEEK_END); |
| tvendov | 0:e1f465d87307 | 963 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 964 | "%s:Error: fseek() failed to SEEK_END (filename=%s, ret=%d, errno=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 965 | fsfat_fopen_test_02_data[0].filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 966 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 967 | |
| tvendov | 0:e1f465d87307 | 968 | errno = 0; |
| tvendov | 0:e1f465d87307 | 969 | ret = ftell(fp); |
| tvendov | 0:e1f465d87307 | 970 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 971 | "%s:Error: ftell() failed to report correct offset value (filename=%s, ret=%d, errno=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 972 | fsfat_fopen_test_02_data[0].filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 973 | TEST_ASSERT_MESSAGE(ret == len, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 974 | |
| tvendov | 0:e1f465d87307 | 975 | errno = 0; |
| tvendov | 0:e1f465d87307 | 976 | ret = fclose(fp); |
| tvendov | 0:e1f465d87307 | 977 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 978 | "%s:Error: failed to close file (ret=%d, errno=%d)\n", __func__, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 979 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 980 | |
| tvendov | 0:e1f465d87307 | 981 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 982 | } |
| tvendov | 0:e1f465d87307 | 983 | |
| tvendov | 0:e1f465d87307 | 984 | |
| tvendov | 0:e1f465d87307 | 985 | /* file data for test_10 */ |
| tvendov | 0:e1f465d87307 | 986 | static fsfat_kv_data_t fsfat_fopen_test_10_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 987 | { "/sd/test_10/testfile.txt", "test_data"}, |
| tvendov | 0:e1f465d87307 | 988 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 989 | }; |
| tvendov | 0:e1f465d87307 | 990 | |
| tvendov | 0:e1f465d87307 | 991 | /** @brief test for operation of remove() |
| tvendov | 0:e1f465d87307 | 992 | * |
| tvendov | 0:e1f465d87307 | 993 | * Performs the following tests: |
| tvendov | 0:e1f465d87307 | 994 | * 1. test remove() on a file that exists. This should succeed. |
| tvendov | 0:e1f465d87307 | 995 | * 2. test remove() on a dir that exists. This should succeed. |
| tvendov | 0:e1f465d87307 | 996 | * 3. test remove() on a file that doesnt exist. This should fail. check errno set. |
| tvendov | 0:e1f465d87307 | 997 | * 4. test remove() on a dir that doesnt exist. This should fail. check errno set. |
| tvendov | 0:e1f465d87307 | 998 | * |
| tvendov | 0:e1f465d87307 | 999 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1000 | */ |
| tvendov | 0:e1f465d87307 | 1001 | control_t fsfat_fopen_test_10(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1002 | { |
| tvendov | 0:e1f465d87307 | 1003 | char buf[FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1]; |
| tvendov | 0:e1f465d87307 | 1004 | char *pos = NULL; |
| tvendov | 0:e1f465d87307 | 1005 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1006 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 1007 | fsfat_kv_data_t *node = fsfat_fopen_test_10_kv_data; |
| tvendov | 0:e1f465d87307 | 1008 | |
| tvendov | 0:e1f465d87307 | 1009 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1010 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1011 | |
| tvendov | 0:e1f465d87307 | 1012 | TEST_ASSERT(strlen(node->filename) < FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1); |
| tvendov | 0:e1f465d87307 | 1013 | |
| tvendov | 0:e1f465d87307 | 1014 | /* start from a known state i.e. directory to be created in not present */ |
| tvendov | 0:e1f465d87307 | 1015 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1016 | |
| tvendov | 0:e1f465d87307 | 1017 | /* (1) */ |
| tvendov | 0:e1f465d87307 | 1018 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1019 | ret = fsfat_filepath_make_dirs((char *) node->filename, false); |
| tvendov | 0:e1f465d87307 | 1020 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1021 | "%s:Error: failed to create dir (dirname=%s, ret=%d, errno=%d)\n", __func__, node->filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1022 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1023 | |
| tvendov | 0:e1f465d87307 | 1024 | len = strlen(node->value); |
| tvendov | 0:e1f465d87307 | 1025 | ret = fsfat_test_create(node->filename, (char *) node->value, len); |
| tvendov | 0:e1f465d87307 | 1026 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1027 | "%s:Error: failed to create file (ret=%d).\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 1028 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1029 | |
| tvendov | 0:e1f465d87307 | 1030 | ret = remove(node->filename); |
| tvendov | 0:e1f465d87307 | 1031 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1032 | "%s:Error: delete file operation failed (filename=%s, ret=%d) .\n", __func__, node->filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 1033 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1034 | |
| tvendov | 0:e1f465d87307 | 1035 | /* (3) */ |
| tvendov | 0:e1f465d87307 | 1036 | ret = remove(node->filename); |
| tvendov | 0:e1f465d87307 | 1037 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1038 | "%s:Error: deleted a file that doesn't exist (filename=%s, ret=%d, errno=%d) .\n", __func__, node->filename, (int) ret, |
| tvendov | 0:e1f465d87307 | 1039 | errno); |
| tvendov | 0:e1f465d87307 | 1040 | TEST_ASSERT_MESSAGE(ret != 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1041 | |
| tvendov | 0:e1f465d87307 | 1042 | /* (2) */ |
| tvendov | 0:e1f465d87307 | 1043 | memset(buf, 0, FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1); |
| tvendov | 0:e1f465d87307 | 1044 | memcpy(buf, node->filename, strlen(node->filename)); |
| tvendov | 0:e1f465d87307 | 1045 | pos = strrchr(buf, '/'); |
| tvendov | 0:e1f465d87307 | 1046 | *pos = '\0'; |
| tvendov | 0:e1f465d87307 | 1047 | ret = remove(buf); |
| tvendov | 0:e1f465d87307 | 1048 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1049 | "%s:Error: delete directory operation failed (directory name=%s, ret=%d, errno=%d).\n", __func__, buf, (int) ret, |
| tvendov | 0:e1f465d87307 | 1050 | errno); |
| tvendov | 0:e1f465d87307 | 1051 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1052 | |
| tvendov | 0:e1f465d87307 | 1053 | /* (4) */ |
| tvendov | 0:e1f465d87307 | 1054 | ret = remove(buf); |
| tvendov | 0:e1f465d87307 | 1055 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1056 | "%s:Error: deleted a directory that doesn't exist (directory name=%s, ret=%d, errno=%d).\n", __func__, buf, (int) ret, |
| tvendov | 0:e1f465d87307 | 1057 | errno); |
| tvendov | 0:e1f465d87307 | 1058 | TEST_ASSERT_MESSAGE(ret != 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1059 | |
| tvendov | 0:e1f465d87307 | 1060 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1061 | } |
| tvendov | 0:e1f465d87307 | 1062 | |
| tvendov | 0:e1f465d87307 | 1063 | |
| tvendov | 0:e1f465d87307 | 1064 | /* file data for test_11 */ |
| tvendov | 0:e1f465d87307 | 1065 | static fsfat_kv_data_t fsfat_fopen_test_11_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 1066 | { "/sd/test_11/step0.txt", "test_data"}, |
| tvendov | 0:e1f465d87307 | 1067 | { "/sd/test_11/step1.txt", "test_data"}, |
| tvendov | 0:e1f465d87307 | 1068 | { "/sd/test_11/subdir/step3.txt", "test_data"}, |
| tvendov | 0:e1f465d87307 | 1069 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 1070 | }; |
| tvendov | 0:e1f465d87307 | 1071 | |
| tvendov | 0:e1f465d87307 | 1072 | /** @brief test for operation of rename() |
| tvendov | 0:e1f465d87307 | 1073 | * |
| tvendov | 0:e1f465d87307 | 1074 | * This test does the following: |
| tvendov | 0:e1f465d87307 | 1075 | * 1) test rename() on a file that exists to a new filename within the same directory. |
| tvendov | 0:e1f465d87307 | 1076 | * 2) test rename() on a file that exists to a new filename within a different directory. |
| tvendov | 0:e1f465d87307 | 1077 | * |
| tvendov | 0:e1f465d87307 | 1078 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1079 | */ |
| tvendov | 0:e1f465d87307 | 1080 | control_t fsfat_fopen_test_11(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1081 | { |
| tvendov | 0:e1f465d87307 | 1082 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1083 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 1084 | fsfat_kv_data_t *node = fsfat_fopen_test_11_kv_data; |
| tvendov | 0:e1f465d87307 | 1085 | |
| tvendov | 0:e1f465d87307 | 1086 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1087 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1088 | |
| tvendov | 0:e1f465d87307 | 1089 | TEST_ASSERT(strlen(node->filename) < FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1); |
| tvendov | 0:e1f465d87307 | 1090 | |
| tvendov | 0:e1f465d87307 | 1091 | /* start from a known state i.e. directory to be created in not present, files not present */ |
| tvendov | 0:e1f465d87307 | 1092 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1093 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1094 | node++; |
| tvendov | 0:e1f465d87307 | 1095 | } |
| tvendov | 0:e1f465d87307 | 1096 | |
| tvendov | 0:e1f465d87307 | 1097 | /* create file and directories ready for rename() tests */ |
| tvendov | 0:e1f465d87307 | 1098 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1099 | node = fsfat_fopen_test_11_kv_data; |
| tvendov | 0:e1f465d87307 | 1100 | ret = fsfat_filepath_make_dirs((char *) node->filename, false); |
| tvendov | 0:e1f465d87307 | 1101 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1102 | "%s:Error: failed to create dir (dirname=%s, ret=%d, errno=%d)\n", __func__, node->filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1103 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1104 | |
| tvendov | 0:e1f465d87307 | 1105 | len = strlen(node->value); |
| tvendov | 0:e1f465d87307 | 1106 | ret = fsfat_test_create(node->filename, (char *) node->value, len); |
| tvendov | 0:e1f465d87307 | 1107 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1108 | "%s:Error: failed to create file (ret=%d).\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 1109 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1110 | |
| tvendov | 0:e1f465d87307 | 1111 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1112 | node = &fsfat_fopen_test_11_kv_data[2]; |
| tvendov | 0:e1f465d87307 | 1113 | ret = fsfat_filepath_make_dirs((char *) node->filename, false); |
| tvendov | 0:e1f465d87307 | 1114 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1115 | "%s:Error: failed to create dir (dirname=%s, ret=%d, errno=%d)\n", __func__, node->filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1116 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1117 | |
| tvendov | 0:e1f465d87307 | 1118 | /* (1) */ |
| tvendov | 0:e1f465d87307 | 1119 | ret = rename(fsfat_fopen_test_11_kv_data[0].filename, fsfat_fopen_test_11_kv_data[1].filename); |
| tvendov | 0:e1f465d87307 | 1120 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1121 | "%s:Error: unable to rename file from (%s) to (%s) (ret=%d, errno=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 1122 | fsfat_fopen_test_11_kv_data[0].filename, fsfat_fopen_test_11_kv_data[1].filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1123 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1124 | |
| tvendov | 0:e1f465d87307 | 1125 | /* (2) */ |
| tvendov | 0:e1f465d87307 | 1126 | ret = rename(fsfat_fopen_test_11_kv_data[1].filename, fsfat_fopen_test_11_kv_data[2].filename); |
| tvendov | 0:e1f465d87307 | 1127 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1128 | "%s:Error: unable to rename file from (%s) to (%s) (ret=%d, errno=%d).\n", __func__, |
| tvendov | 0:e1f465d87307 | 1129 | fsfat_fopen_test_11_kv_data[1].filename, fsfat_fopen_test_11_kv_data[2].filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1130 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1131 | |
| tvendov | 0:e1f465d87307 | 1132 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1133 | } |
| tvendov | 0:e1f465d87307 | 1134 | |
| tvendov | 0:e1f465d87307 | 1135 | |
| tvendov | 0:e1f465d87307 | 1136 | /* file data for test_12 */ |
| tvendov | 0:e1f465d87307 | 1137 | static fsfat_kv_data_t fsfat_fopen_test_12_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 1138 | { "/sd/test_12/subdir/testfil1.txt", "testfil1.txt"}, |
| tvendov | 0:e1f465d87307 | 1139 | { "/sd/test_12/testfil2.txt", "testfil2.txt"}, |
| tvendov | 0:e1f465d87307 | 1140 | { "/sd/test_12/testfil3.txt", "testfil3.txt"}, |
| tvendov | 0:e1f465d87307 | 1141 | { "/sd/test_12/testfil4.txt", "testfil4.txt"}, |
| tvendov | 0:e1f465d87307 | 1142 | { "/sd/test_12/testfil5.txt", "testfil5.txt"}, |
| tvendov | 0:e1f465d87307 | 1143 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 1144 | }; |
| tvendov | 0:e1f465d87307 | 1145 | |
| tvendov | 0:e1f465d87307 | 1146 | /** @brief test for operation of readdir(). |
| tvendov | 0:e1f465d87307 | 1147 | * |
| tvendov | 0:e1f465d87307 | 1148 | * Note, rewinddir(), telldir() and seekdir() dont appear to work reliably. |
| tvendov | 0:e1f465d87307 | 1149 | * opendir() not available on ARM/IAR toolchains. |
| tvendov | 0:e1f465d87307 | 1150 | * |
| tvendov | 0:e1f465d87307 | 1151 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1152 | */ |
| tvendov | 0:e1f465d87307 | 1153 | control_t fsfat_fopen_test_12(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1154 | { |
| tvendov | 0:e1f465d87307 | 1155 | char buf[FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1]; |
| tvendov | 0:e1f465d87307 | 1156 | char *pos = NULL; |
| tvendov | 0:e1f465d87307 | 1157 | int32_t count = 0; |
| tvendov | 0:e1f465d87307 | 1158 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1159 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 1160 | DIR *dir; |
| tvendov | 0:e1f465d87307 | 1161 | struct dirent *dp; |
| tvendov | 0:e1f465d87307 | 1162 | fsfat_kv_data_t *node = fsfat_fopen_test_12_kv_data; |
| tvendov | 0:e1f465d87307 | 1163 | |
| tvendov | 0:e1f465d87307 | 1164 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1165 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1166 | |
| tvendov | 0:e1f465d87307 | 1167 | #if ! defined(__ARMCC_VERSION) && defined(__GNUC__) |
| tvendov | 0:e1f465d87307 | 1168 | |
| tvendov | 0:e1f465d87307 | 1169 | /* start from a known state i.e. directory to be created in not present */ |
| tvendov | 0:e1f465d87307 | 1170 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1171 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1172 | node++; |
| tvendov | 0:e1f465d87307 | 1173 | } |
| tvendov | 0:e1f465d87307 | 1174 | |
| tvendov | 0:e1f465d87307 | 1175 | /* create a file */ |
| tvendov | 0:e1f465d87307 | 1176 | node = fsfat_fopen_test_12_kv_data; |
| tvendov | 0:e1f465d87307 | 1177 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1178 | ret = fsfat_filepath_make_dirs((char *) node->filename, false); |
| tvendov | 0:e1f465d87307 | 1179 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1180 | "%s:Error: failed to create dir (dirname=%s, ret=%d, errno=%d)\n", __func__, node->filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1181 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1182 | |
| tvendov | 0:e1f465d87307 | 1183 | node = fsfat_fopen_test_12_kv_data; |
| tvendov | 0:e1f465d87307 | 1184 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1185 | len = strlen(node->value); |
| tvendov | 0:e1f465d87307 | 1186 | ret = fsfat_test_create(node->filename, (char *) node->value, len); |
| tvendov | 0:e1f465d87307 | 1187 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1188 | "%s:Error: failed to create file (ret=%d).\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 1189 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1190 | node++; |
| tvendov | 0:e1f465d87307 | 1191 | } |
| tvendov | 0:e1f465d87307 | 1192 | |
| tvendov | 0:e1f465d87307 | 1193 | node = fsfat_fopen_test_12_kv_data; |
| tvendov | 0:e1f465d87307 | 1194 | memset(buf, 0, FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1); |
| tvendov | 0:e1f465d87307 | 1195 | memcpy(buf, node->filename, strlen(node->filename)); |
| tvendov | 0:e1f465d87307 | 1196 | pos = strrchr(buf, '/'); |
| tvendov | 0:e1f465d87307 | 1197 | *pos = '\0'; |
| tvendov | 0:e1f465d87307 | 1198 | dir = opendir(buf); |
| tvendov | 0:e1f465d87307 | 1199 | |
| tvendov | 0:e1f465d87307 | 1200 | while ((dp = readdir(dir)) != NULL) { |
| tvendov | 0:e1f465d87307 | 1201 | FSFAT_DBGLOG("%s: filename: \"%s\"\n", __func__, dp->d_name); |
| tvendov | 0:e1f465d87307 | 1202 | TEST_ASSERT_MESSAGE(dp != 0, "Error: readdir() failed\n"); |
| tvendov | 0:e1f465d87307 | 1203 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1204 | "%s:Error: unexpected object name (name=%s, expected=%s).\n", __func__, dp->d_name, |
| tvendov | 0:e1f465d87307 | 1205 | fsfat_fopen_test_12_kv_data[count].value); |
| tvendov | 0:e1f465d87307 | 1206 | TEST_ASSERT_MESSAGE(strncmp(dp->d_name, fsfat_fopen_test_12_kv_data[count].value, |
| tvendov | 0:e1f465d87307 | 1207 | strlen(fsfat_fopen_test_12_kv_data[count].value)) == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1208 | count++; |
| tvendov | 0:e1f465d87307 | 1209 | } |
| tvendov | 0:e1f465d87307 | 1210 | closedir(dir); |
| tvendov | 0:e1f465d87307 | 1211 | |
| tvendov | 0:e1f465d87307 | 1212 | /* cleanup */ |
| tvendov | 0:e1f465d87307 | 1213 | node = fsfat_fopen_test_12_kv_data; |
| tvendov | 0:e1f465d87307 | 1214 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1215 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1216 | node++; |
| tvendov | 0:e1f465d87307 | 1217 | } |
| tvendov | 0:e1f465d87307 | 1218 | #endif /* ! defined(__ARMCC_VERSION) && defined(__GNUC__) */ |
| tvendov | 0:e1f465d87307 | 1219 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1220 | } |
| tvendov | 0:e1f465d87307 | 1221 | |
| tvendov | 0:e1f465d87307 | 1222 | |
| tvendov | 0:e1f465d87307 | 1223 | /* file data for test_13 */ |
| tvendov | 0:e1f465d87307 | 1224 | static fsfat_kv_data_t fsfat_fopen_test_13_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 1225 | /* a file is included in the filepath even though its not created by the test, |
| tvendov | 0:e1f465d87307 | 1226 | * as the fsfat_filepath_make_dirs() works with it present. */ |
| tvendov | 0:e1f465d87307 | 1227 | { "/sd/test_13/dummy.txt", "testdir"}, |
| tvendov | 0:e1f465d87307 | 1228 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 1229 | }; |
| tvendov | 0:e1f465d87307 | 1230 | /** @brief test for operation of mkdir()/remove() |
| tvendov | 0:e1f465d87307 | 1231 | * |
| tvendov | 0:e1f465d87307 | 1232 | * This test checks that: |
| tvendov | 0:e1f465d87307 | 1233 | * - The mkdir() function successfully creates a directory that is not already present. |
| tvendov | 0:e1f465d87307 | 1234 | * - The mkdir() function returns EEXIST when trying to create a directory thats already present. |
| tvendov | 0:e1f465d87307 | 1235 | * - The remove() function successfully removes a directory that is present. |
| tvendov | 0:e1f465d87307 | 1236 | * |
| tvendov | 0:e1f465d87307 | 1237 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1238 | */ |
| tvendov | 0:e1f465d87307 | 1239 | control_t fsfat_fopen_test_13(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1240 | { |
| tvendov | 0:e1f465d87307 | 1241 | int32_t ret = 0; |
| tvendov | 0:e1f465d87307 | 1242 | |
| tvendov | 0:e1f465d87307 | 1243 | FSFAT_DBGLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1244 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1245 | |
| tvendov | 0:e1f465d87307 | 1246 | /* start from a known state i.e. directory to be created in not present */ |
| tvendov | 0:e1f465d87307 | 1247 | fsfat_filepath_remove_all((char *) fsfat_fopen_test_13_kv_data[0].filename); |
| tvendov | 0:e1f465d87307 | 1248 | |
| tvendov | 0:e1f465d87307 | 1249 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1250 | ret = fsfat_filepath_make_dirs((char *) fsfat_fopen_test_13_kv_data[0].filename, false); |
| tvendov | 0:e1f465d87307 | 1251 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1252 | "%s:Error: failed to create dir (dirname=%s, ret=%d, errno=%d)\n", __func__, fsfat_fopen_test_13_kv_data[0].filename, |
| tvendov | 0:e1f465d87307 | 1253 | (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1254 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1255 | |
| tvendov | 0:e1f465d87307 | 1256 | /* check that get a suitable error when try to create it again.*/ |
| tvendov | 0:e1f465d87307 | 1257 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1258 | ret = fsfat_filepath_make_dirs((char *) fsfat_fopen_test_13_kv_data[0].filename, false); |
| tvendov | 0:e1f465d87307 | 1259 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1260 | "%s:Error: permitted to create directory when already exists (dirname=%s, ret=%d, errno=%d)\n", __func__, |
| tvendov | 0:e1f465d87307 | 1261 | fsfat_fopen_test_13_kv_data[0].filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1262 | TEST_ASSERT_MESSAGE(ret != 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1263 | |
| tvendov | 0:e1f465d87307 | 1264 | /* check errno is as expected */ |
| tvendov | 0:e1f465d87307 | 1265 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1266 | "%s:Error: errno != EEXIST (dirname=%s, ret=%d, errno=%d)\n", __func__, fsfat_fopen_test_13_kv_data[0].filename, |
| tvendov | 0:e1f465d87307 | 1267 | (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1268 | TEST_ASSERT_MESSAGE(errno == EEXIST, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1269 | |
| tvendov | 0:e1f465d87307 | 1270 | ret = fsfat_filepath_remove_all((char *) fsfat_fopen_test_13_kv_data[0].filename); |
| tvendov | 0:e1f465d87307 | 1271 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1272 | "%s:Error: failed to remove directory (dirname=%s, ret=%d, errno=%d)\n", __func__, |
| tvendov | 0:e1f465d87307 | 1273 | fsfat_fopen_test_13_kv_data[0].filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1274 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1275 | |
| tvendov | 0:e1f465d87307 | 1276 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1277 | } |
| tvendov | 0:e1f465d87307 | 1278 | |
| tvendov | 0:e1f465d87307 | 1279 | /* file data for test_14 */ |
| tvendov | 0:e1f465d87307 | 1280 | static fsfat_kv_data_t fsfat_fopen_test_14_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 1281 | /* a file is included in the filepath even though its not created by the test, |
| tvendov | 0:e1f465d87307 | 1282 | * as the fsfat_filepath_make_dirs() works with it present. */ |
| tvendov | 0:e1f465d87307 | 1283 | { "/sd/test_14/testfile.txt", "testdata"}, |
| tvendov | 0:e1f465d87307 | 1284 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 1285 | }; |
| tvendov | 0:e1f465d87307 | 1286 | |
| tvendov | 0:e1f465d87307 | 1287 | /** @brief test for operation of stat() |
| tvendov | 0:e1f465d87307 | 1288 | * |
| tvendov | 0:e1f465d87307 | 1289 | * stat() is currently no supported by ARMCC and IAR toolchains libc. |
| tvendov | 0:e1f465d87307 | 1290 | * |
| tvendov | 0:e1f465d87307 | 1291 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1292 | */ |
| tvendov | 0:e1f465d87307 | 1293 | control_t fsfat_fopen_test_14(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1294 | { |
| tvendov | 0:e1f465d87307 | 1295 | #if ! defined(__ARMCC_VERSION) && defined(__GNUC__) |
| tvendov | 0:e1f465d87307 | 1296 | |
| tvendov | 0:e1f465d87307 | 1297 | char buf[FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1]; |
| tvendov | 0:e1f465d87307 | 1298 | char *pos = NULL; |
| tvendov | 0:e1f465d87307 | 1299 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1300 | size_t len = 0; |
| tvendov | 0:e1f465d87307 | 1301 | struct stat file_stat; |
| tvendov | 0:e1f465d87307 | 1302 | fsfat_kv_data_t *node = fsfat_fopen_test_14_kv_data; |
| tvendov | 0:e1f465d87307 | 1303 | |
| tvendov | 0:e1f465d87307 | 1304 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1305 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1306 | |
| tvendov | 0:e1f465d87307 | 1307 | TEST_ASSERT(strlen(node->filename) < FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1); |
| tvendov | 0:e1f465d87307 | 1308 | |
| tvendov | 0:e1f465d87307 | 1309 | /* start from a known state i.e. directory to be created in not present */ |
| tvendov | 0:e1f465d87307 | 1310 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1311 | |
| tvendov | 0:e1f465d87307 | 1312 | /* Create file in a directory. */ |
| tvendov | 0:e1f465d87307 | 1313 | errno = 0; |
| tvendov | 0:e1f465d87307 | 1314 | ret = fsfat_filepath_make_dirs((char *) node->filename, false); |
| tvendov | 0:e1f465d87307 | 1315 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1316 | "%s:Error: failed to create dir (dirname=%s, ret=%d, errno=%d)\n", __func__, node->filename, (int) ret, errno); |
| tvendov | 0:e1f465d87307 | 1317 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1318 | |
| tvendov | 0:e1f465d87307 | 1319 | len = strlen(node->value); |
| tvendov | 0:e1f465d87307 | 1320 | ret = fsfat_test_create(node->filename, (char *) node->value, len); |
| tvendov | 0:e1f465d87307 | 1321 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1322 | "%s:Error: failed to create file (ret=%d).\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 1323 | TEST_ASSERT_MESSAGE(ret >= 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1324 | |
| tvendov | 0:e1f465d87307 | 1325 | /* Test stat() on the file returns the correct attribute set */ |
| tvendov | 0:e1f465d87307 | 1326 | memset(&file_stat, 0, sizeof(file_stat)); |
| tvendov | 0:e1f465d87307 | 1327 | ret = stat(node->filename, &file_stat); |
| tvendov | 0:e1f465d87307 | 1328 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1329 | "%s:Error: stat() operation on file failed (filename=%s, ret=%d, errno=%d).\n", __func__, node->filename, (int) ret, |
| tvendov | 0:e1f465d87307 | 1330 | errno); |
| tvendov | 0:e1f465d87307 | 1331 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1332 | |
| tvendov | 0:e1f465d87307 | 1333 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1334 | "%s:Error: expected st_mode S_IFREG flag not set (filename=%s).\n", __func__, node->filename); |
| tvendov | 0:e1f465d87307 | 1335 | TEST_ASSERT_MESSAGE((file_stat.st_mode & S_IFREG) == S_IFREG, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1336 | |
| tvendov | 0:e1f465d87307 | 1337 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1338 | "%s:Error: unexpected st_mode S_IFDIR flag set (filename=%s).\n", __func__, node->filename); |
| tvendov | 0:e1f465d87307 | 1339 | TEST_ASSERT_MESSAGE((file_stat.st_mode & S_IFDIR) != S_IFDIR, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1340 | |
| tvendov | 0:e1f465d87307 | 1341 | /* Test stat() on the directory returns the correct attribute set */ |
| tvendov | 0:e1f465d87307 | 1342 | memset(&file_stat, 0, sizeof(file_stat)); |
| tvendov | 0:e1f465d87307 | 1343 | memset(buf, 0, FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1); |
| tvendov | 0:e1f465d87307 | 1344 | memcpy(buf, node->filename, strlen(node->filename)); |
| tvendov | 0:e1f465d87307 | 1345 | pos = strrchr(buf, '/'); |
| tvendov | 0:e1f465d87307 | 1346 | *pos = '\0'; |
| tvendov | 0:e1f465d87307 | 1347 | ret = stat(buf, &file_stat); |
| tvendov | 0:e1f465d87307 | 1348 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1349 | "%s:Error: stat() operation on directory failed (directory name=%s, ret=%d, errno=%d).\n", __func__, buf, (int) ret, |
| tvendov | 0:e1f465d87307 | 1350 | errno); |
| tvendov | 0:e1f465d87307 | 1351 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1352 | |
| tvendov | 0:e1f465d87307 | 1353 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1354 | "%s:Error: unexpected st_mode S_IFREG flag set (directory name=%s).\n", __func__, buf); |
| tvendov | 0:e1f465d87307 | 1355 | TEST_ASSERT_MESSAGE((file_stat.st_mode & S_IFREG) != S_IFREG, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1356 | |
| tvendov | 0:e1f465d87307 | 1357 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1358 | "%s:Error: expected st_mode S_IFDIR flag not set (directory name=%s).\n", __func__, buf); |
| tvendov | 0:e1f465d87307 | 1359 | TEST_ASSERT_MESSAGE((file_stat.st_mode & S_IFDIR) == S_IFDIR, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1360 | |
| tvendov | 0:e1f465d87307 | 1361 | /* clean up after successful test */ |
| tvendov | 0:e1f465d87307 | 1362 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1363 | |
| tvendov | 0:e1f465d87307 | 1364 | #endif /* ! defined(__ARMCC_VERSION) && defined(__GNUC__) */ |
| tvendov | 0:e1f465d87307 | 1365 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1366 | } |
| tvendov | 0:e1f465d87307 | 1367 | |
| tvendov | 0:e1f465d87307 | 1368 | /** @brief test for operation of SDFileSystem::format() |
| tvendov | 0:e1f465d87307 | 1369 | * |
| tvendov | 0:e1f465d87307 | 1370 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1371 | */ |
| tvendov | 0:e1f465d87307 | 1372 | control_t fsfat_fopen_test_15(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1373 | { |
| tvendov | 0:e1f465d87307 | 1374 | |
| tvendov | 0:e1f465d87307 | 1375 | FSFAT_FENTRYLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1376 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1377 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1378 | |
| tvendov | 0:e1f465d87307 | 1379 | /* the allocation_unit of 0 means chanFS will use the default for the card (varies according to capacity). */ |
| tvendov | 0:e1f465d87307 | 1380 | fs.unmount(); |
| tvendov | 0:e1f465d87307 | 1381 | ret = fs.format(&sd); |
| tvendov | 0:e1f465d87307 | 1382 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1383 | "%s:Error: failed to format sdcard (ret=%d)\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 1384 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1385 | fs.mount(&sd); |
| tvendov | 0:e1f465d87307 | 1386 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1387 | } |
| tvendov | 0:e1f465d87307 | 1388 | |
| tvendov | 0:e1f465d87307 | 1389 | |
| tvendov | 0:e1f465d87307 | 1390 | /* @brief test utility function to create a file of a given size. |
| tvendov | 0:e1f465d87307 | 1391 | * |
| tvendov | 0:e1f465d87307 | 1392 | * A reference data table is used of so that the data file can be later be |
| tvendov | 0:e1f465d87307 | 1393 | * checked with fsfat_test_check_data_file(). |
| tvendov | 0:e1f465d87307 | 1394 | * |
| tvendov | 0:e1f465d87307 | 1395 | * @param filename name of the file including path |
| tvendov | 0:e1f465d87307 | 1396 | * @param data data to store in file |
| tvendov | 0:e1f465d87307 | 1397 | * @param len number of bytes of data present in the data buffer. |
| tvendov | 0:e1f465d87307 | 1398 | */ |
| tvendov | 0:e1f465d87307 | 1399 | int32_t fsfat_test_create_data_file(const char *filename, size_t len) |
| tvendov | 0:e1f465d87307 | 1400 | { |
| tvendov | 0:e1f465d87307 | 1401 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1402 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 1403 | size_t write_len = 0; |
| tvendov | 0:e1f465d87307 | 1404 | size_t written_len = 0; |
| tvendov | 0:e1f465d87307 | 1405 | int32_t exp = 0; |
| tvendov | 0:e1f465d87307 | 1406 | const int32_t exp_max = 8; /* so as not to exceed FSFAT_TEST_BYTE_DATA_TABLE_SIZE/2 */ |
| tvendov | 0:e1f465d87307 | 1407 | |
| tvendov | 0:e1f465d87307 | 1408 | FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len); |
| tvendov | 0:e1f465d87307 | 1409 | TEST_ASSERT(len % FSFAT_TEST_BYTE_DATA_TABLE_SIZE == 0); |
| tvendov | 0:e1f465d87307 | 1410 | fp = fopen(filename, "a"); |
| tvendov | 0:e1f465d87307 | 1411 | if (fp == NULL) { |
| tvendov | 0:e1f465d87307 | 1412 | return ret; |
| tvendov | 0:e1f465d87307 | 1413 | } |
| tvendov | 0:e1f465d87307 | 1414 | |
| tvendov | 0:e1f465d87307 | 1415 | while (written_len < len) { |
| tvendov | 0:e1f465d87307 | 1416 | /* write fsfat_test_byte_data_table or part thereof, in 9 writes of sizes |
| tvendov | 0:e1f465d87307 | 1417 | * 1, 2, 4, 8, 16, 32, 64, 128, 1, totalling 256 bytes len permitting. */ |
| tvendov | 0:e1f465d87307 | 1418 | for (exp = 0; (exp <= exp_max) && (written_len < len); exp++) { |
| tvendov | 0:e1f465d87307 | 1419 | write_len = 0x1 << (exp % exp_max); |
| tvendov | 0:e1f465d87307 | 1420 | write_len = len - written_len > write_len ? write_len : len - written_len; |
| tvendov | 0:e1f465d87307 | 1421 | ret = fwrite((const void *) &fsfat_test_byte_data_table[written_len % FSFAT_TEST_BYTE_DATA_TABLE_SIZE], write_len, 1, |
| tvendov | 0:e1f465d87307 | 1422 | fp); |
| tvendov | 0:e1f465d87307 | 1423 | written_len += write_len; |
| tvendov | 0:e1f465d87307 | 1424 | if (ret != 1) { |
| tvendov | 0:e1f465d87307 | 1425 | FSFAT_DBGLOG("%s:Error: fwrite() failed (ret=%d)\n", __func__, (int) ret); |
| tvendov | 0:e1f465d87307 | 1426 | ret = -1; |
| tvendov | 0:e1f465d87307 | 1427 | goto out0; |
| tvendov | 0:e1f465d87307 | 1428 | } |
| tvendov | 0:e1f465d87307 | 1429 | } |
| tvendov | 0:e1f465d87307 | 1430 | } |
| tvendov | 0:e1f465d87307 | 1431 | if (written_len == len) { |
| tvendov | 0:e1f465d87307 | 1432 | ret = 0; |
| tvendov | 0:e1f465d87307 | 1433 | } else { |
| tvendov | 0:e1f465d87307 | 1434 | ret = -1; |
| tvendov | 0:e1f465d87307 | 1435 | } |
| tvendov | 0:e1f465d87307 | 1436 | out0: |
| tvendov | 0:e1f465d87307 | 1437 | fclose(fp); |
| tvendov | 0:e1f465d87307 | 1438 | return ret; |
| tvendov | 0:e1f465d87307 | 1439 | } |
| tvendov | 0:e1f465d87307 | 1440 | |
| tvendov | 0:e1f465d87307 | 1441 | |
| tvendov | 0:e1f465d87307 | 1442 | /* @brief test utility function to check the data in the specified file is correct. |
| tvendov | 0:e1f465d87307 | 1443 | * |
| tvendov | 0:e1f465d87307 | 1444 | * The data read from the file is check that it agrees with the data written by |
| tvendov | 0:e1f465d87307 | 1445 | * fsfat_test_create_data_file(). |
| tvendov | 0:e1f465d87307 | 1446 | * |
| tvendov | 0:e1f465d87307 | 1447 | * @param filename name of the file including path |
| tvendov | 0:e1f465d87307 | 1448 | * @param data data to store in file |
| tvendov | 0:e1f465d87307 | 1449 | * @param len number of bytes of data present in the data buffer. |
| tvendov | 0:e1f465d87307 | 1450 | */ |
| tvendov | 0:e1f465d87307 | 1451 | int32_t fsfat_test_check_data_file(const char *filename, size_t len) |
| tvendov | 0:e1f465d87307 | 1452 | { |
| tvendov | 0:e1f465d87307 | 1453 | int32_t ret = -1; |
| tvendov | 0:e1f465d87307 | 1454 | FILE *fp = NULL; |
| tvendov | 0:e1f465d87307 | 1455 | size_t read_len = 0; |
| tvendov | 0:e1f465d87307 | 1456 | uint8_t buf[FSFAT_TEST_BYTE_DATA_TABLE_SIZE]; |
| tvendov | 0:e1f465d87307 | 1457 | |
| tvendov | 0:e1f465d87307 | 1458 | FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len); |
| tvendov | 0:e1f465d87307 | 1459 | TEST_ASSERT(len % FSFAT_TEST_BYTE_DATA_TABLE_SIZE == 0); |
| tvendov | 0:e1f465d87307 | 1460 | fp = fopen(filename, "r"); |
| tvendov | 0:e1f465d87307 | 1461 | if (fp == NULL) { |
| tvendov | 0:e1f465d87307 | 1462 | return ret; |
| tvendov | 0:e1f465d87307 | 1463 | } |
| tvendov | 0:e1f465d87307 | 1464 | |
| tvendov | 0:e1f465d87307 | 1465 | while (read_len < len) { |
| tvendov | 0:e1f465d87307 | 1466 | ret = fread((void *) buf, FSFAT_TEST_BYTE_DATA_TABLE_SIZE, 1, fp); |
| tvendov | 0:e1f465d87307 | 1467 | read_len += FSFAT_TEST_BYTE_DATA_TABLE_SIZE; |
| tvendov | 0:e1f465d87307 | 1468 | if (ret == 0) { |
| tvendov | 0:e1f465d87307 | 1469 | /* end of read*/ |
| tvendov | 0:e1f465d87307 | 1470 | FSFAT_DBGLOG("%s:unable to read data\n", __func__); |
| tvendov | 0:e1f465d87307 | 1471 | break; |
| tvendov | 0:e1f465d87307 | 1472 | } |
| tvendov | 0:e1f465d87307 | 1473 | if (memcmp(buf, fsfat_test_byte_data_table, FSFAT_TEST_BYTE_DATA_TABLE_SIZE) != 0) { |
| tvendov | 0:e1f465d87307 | 1474 | FSFAT_DBGLOG("%s:Error: read data not as expected (0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x\n", |
| tvendov | 0:e1f465d87307 | 1475 | __func__, |
| tvendov | 0:e1f465d87307 | 1476 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], |
| tvendov | 0:e1f465d87307 | 1477 | buf[14], buf[15]); |
| tvendov | 0:e1f465d87307 | 1478 | ret = -1; |
| tvendov | 0:e1f465d87307 | 1479 | goto out0; |
| tvendov | 0:e1f465d87307 | 1480 | } |
| tvendov | 0:e1f465d87307 | 1481 | } |
| tvendov | 0:e1f465d87307 | 1482 | if (read_len == len) { |
| tvendov | 0:e1f465d87307 | 1483 | ret = 0; |
| tvendov | 0:e1f465d87307 | 1484 | } |
| tvendov | 0:e1f465d87307 | 1485 | out0: |
| tvendov | 0:e1f465d87307 | 1486 | fclose(fp); |
| tvendov | 0:e1f465d87307 | 1487 | return ret; |
| tvendov | 0:e1f465d87307 | 1488 | } |
| tvendov | 0:e1f465d87307 | 1489 | |
| tvendov | 0:e1f465d87307 | 1490 | /* file data for test_16 */ |
| tvendov | 0:e1f465d87307 | 1491 | static fsfat_kv_data_t fsfat_fopen_test_16_kv_data[] = { |
| tvendov | 0:e1f465d87307 | 1492 | { "/sd/tst16_0/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1493 | { "/sd/tst16_1/subdir0/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1494 | { "/sd/tst16_2/subdir0/subdir1/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1495 | { "/sd/tst16_3/subdir0/subdir1/subdir2/subdir3/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1496 | { "/sd/tst16_4/subdir0/subdir1/subdir2/subdir3/subdir4/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1497 | { "/sd/tst16_5/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1498 | { "/sd/tst16_6/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1499 | { "/sd/tst16_7/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1500 | { "/sd/tst16_8/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1501 | { "/sd/tst16_9/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/subdir9/testfil0.txt", "dummy_data"}, |
| tvendov | 0:e1f465d87307 | 1502 | { NULL, NULL}, |
| tvendov | 0:e1f465d87307 | 1503 | }; |
| tvendov | 0:e1f465d87307 | 1504 | |
| tvendov | 0:e1f465d87307 | 1505 | |
| tvendov | 0:e1f465d87307 | 1506 | /** @brief stress test to write data to fs |
| tvendov | 0:e1f465d87307 | 1507 | * |
| tvendov | 0:e1f465d87307 | 1508 | * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. |
| tvendov | 0:e1f465d87307 | 1509 | */ |
| tvendov | 0:e1f465d87307 | 1510 | control_t fsfat_fopen_test_16(const size_t call_count) |
| tvendov | 0:e1f465d87307 | 1511 | { |
| tvendov | 0:e1f465d87307 | 1512 | int32_t ret = 0; |
| tvendov | 0:e1f465d87307 | 1513 | fsfat_kv_data_t *node = fsfat_fopen_test_16_kv_data; |
| tvendov | 0:e1f465d87307 | 1514 | const int32_t num_blocks = 100; /* each file ~25kB */ |
| tvendov | 0:e1f465d87307 | 1515 | |
| tvendov | 0:e1f465d87307 | 1516 | FSFAT_DBGLOG("%s:entered\n", __func__); |
| tvendov | 0:e1f465d87307 | 1517 | (void) call_count; |
| tvendov | 0:e1f465d87307 | 1518 | |
| tvendov | 0:e1f465d87307 | 1519 | /* remove file and directory from a previous failed test run, if present */ |
| tvendov | 0:e1f465d87307 | 1520 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1521 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1522 | node++; |
| tvendov | 0:e1f465d87307 | 1523 | } |
| tvendov | 0:e1f465d87307 | 1524 | |
| tvendov | 0:e1f465d87307 | 1525 | /* create dirs */ |
| tvendov | 0:e1f465d87307 | 1526 | node = fsfat_fopen_test_16_kv_data; |
| tvendov | 0:e1f465d87307 | 1527 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1528 | ret = fsfat_filepath_make_dirs((char *) node->filename, true); |
| tvendov | 0:e1f465d87307 | 1529 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1530 | "%s:Error: failed to create dirs for filename (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 1531 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1532 | node++; |
| tvendov | 0:e1f465d87307 | 1533 | } |
| tvendov | 0:e1f465d87307 | 1534 | |
| tvendov | 0:e1f465d87307 | 1535 | /* create the data files */ |
| tvendov | 0:e1f465d87307 | 1536 | node = fsfat_fopen_test_16_kv_data; |
| tvendov | 0:e1f465d87307 | 1537 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1538 | ret = fsfat_test_create_data_file(node->filename, num_blocks * FSFAT_TEST_BYTE_DATA_TABLE_SIZE); |
| tvendov | 0:e1f465d87307 | 1539 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1540 | "%s:Error: failed to create data file (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 1541 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1542 | node++; |
| tvendov | 0:e1f465d87307 | 1543 | } |
| tvendov | 0:e1f465d87307 | 1544 | |
| tvendov | 0:e1f465d87307 | 1545 | /* read the data back and check its as expected */ |
| tvendov | 0:e1f465d87307 | 1546 | node = fsfat_fopen_test_16_kv_data; |
| tvendov | 0:e1f465d87307 | 1547 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1548 | ret = fsfat_test_check_data_file(node->filename, num_blocks * FSFAT_TEST_BYTE_DATA_TABLE_SIZE); |
| tvendov | 0:e1f465d87307 | 1549 | FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, |
| tvendov | 0:e1f465d87307 | 1550 | "%s:Error: failed to check data file (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); |
| tvendov | 0:e1f465d87307 | 1551 | TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); |
| tvendov | 0:e1f465d87307 | 1552 | node++; |
| tvendov | 0:e1f465d87307 | 1553 | } |
| tvendov | 0:e1f465d87307 | 1554 | |
| tvendov | 0:e1f465d87307 | 1555 | /* clean up */ |
| tvendov | 0:e1f465d87307 | 1556 | node = fsfat_fopen_test_16_kv_data; |
| tvendov | 0:e1f465d87307 | 1557 | while (node->filename != NULL) { |
| tvendov | 0:e1f465d87307 | 1558 | fsfat_filepath_remove_all((char *) node->filename); |
| tvendov | 0:e1f465d87307 | 1559 | node++; |
| tvendov | 0:e1f465d87307 | 1560 | } |
| tvendov | 0:e1f465d87307 | 1561 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1562 | } |
| tvendov | 0:e1f465d87307 | 1563 | |
| tvendov | 0:e1f465d87307 | 1564 | |
| tvendov | 0:e1f465d87307 | 1565 | #else |
| tvendov | 0:e1f465d87307 | 1566 | |
| tvendov | 0:e1f465d87307 | 1567 | #define FSFAT_FOPEN_TEST_00 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1568 | #define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1569 | #define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1570 | #define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1571 | #define FSFAT_FOPEN_TEST_04 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1572 | #define FSFAT_FOPEN_TEST_05 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1573 | #define FSFAT_FOPEN_TEST_06 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1574 | #define FSFAT_FOPEN_TEST_07 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1575 | #define FSFAT_FOPEN_TEST_08 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1576 | #define FSFAT_FOPEN_TEST_09 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1577 | #define FSFAT_FOPEN_TEST_10 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1578 | #define FSFAT_FOPEN_TEST_11 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1579 | #define FSFAT_FOPEN_TEST_12 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1580 | #define FSFAT_FOPEN_TEST_13 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1581 | #define FSFAT_FOPEN_TEST_14 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1582 | #define FSFAT_FOPEN_TEST_15 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1583 | #define FSFAT_FOPEN_TEST_16 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1584 | #define FSFAT_FOPEN_TEST_17 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1585 | #define FSFAT_FOPEN_TEST_18 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1586 | #define FSFAT_FOPEN_TEST_19 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1587 | #define FSFAT_FOPEN_TEST_20 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1588 | #define FSFAT_FOPEN_TEST_21 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1589 | #define FSFAT_FOPEN_TEST_22 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1590 | #define FSFAT_FOPEN_TEST_23 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1591 | #define FSFAT_FOPEN_TEST_24 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1592 | #define FSFAT_FOPEN_TEST_25 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1593 | #define FSFAT_FOPEN_TEST_26 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1594 | #define FSFAT_FOPEN_TEST_27 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1595 | #define FSFAT_FOPEN_TEST_28 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1596 | #define FSFAT_FOPEN_TEST_29 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1597 | #define FSFAT_FOPEN_TEST_30 fsfat_fopen_test_dummy |
| tvendov | 0:e1f465d87307 | 1598 | |
| tvendov | 0:e1f465d87307 | 1599 | /** @brief fsfat_fopen_test_dummy Dummy test case for testing when platform doesnt have an SDCard installed. |
| tvendov | 0:e1f465d87307 | 1600 | * |
| tvendov | 0:e1f465d87307 | 1601 | * @return success always |
| tvendov | 0:e1f465d87307 | 1602 | */ |
| tvendov | 0:e1f465d87307 | 1603 | static control_t fsfat_fopen_test_dummy() |
| tvendov | 0:e1f465d87307 | 1604 | { |
| tvendov | 0:e1f465d87307 | 1605 | printf("Null test\n"); |
| tvendov | 0:e1f465d87307 | 1606 | return CaseNext; |
| tvendov | 0:e1f465d87307 | 1607 | } |
| tvendov | 0:e1f465d87307 | 1608 | |
| tvendov | 0:e1f465d87307 | 1609 | #endif |
| tvendov | 0:e1f465d87307 | 1610 | |
| tvendov | 0:e1f465d87307 | 1611 | |
| tvendov | 0:e1f465d87307 | 1612 | /// @cond FSFAT_DOXYGEN_DISABLE |
| tvendov | 0:e1f465d87307 | 1613 | utest::v1::status_t greentea_setup(const size_t number_of_cases) |
| tvendov | 0:e1f465d87307 | 1614 | { |
| tvendov | 0:e1f465d87307 | 1615 | GREENTEA_SETUP(FSFAT_FOPEN_GREENTEA_TIMEOUT_S, "default_auto"); |
| tvendov | 0:e1f465d87307 | 1616 | return greentea_test_setup_handler(number_of_cases); |
| tvendov | 0:e1f465d87307 | 1617 | } |
| tvendov | 0:e1f465d87307 | 1618 | |
| tvendov | 0:e1f465d87307 | 1619 | Case cases[] = { |
| tvendov | 0:e1f465d87307 | 1620 | /* 1 2 3 4 5 6 7 */ |
| tvendov | 0:e1f465d87307 | 1621 | /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ |
| tvendov | 0:e1f465d87307 | 1622 | Case("FSFAT_FOPEN_TEST_00: format sd card to FAT FS.", FSFAT_FOPEN_TEST_00), |
| tvendov | 0:e1f465d87307 | 1623 | Case("FSFAT_FOPEN_TEST_01: fopen()/fwrite()/fclose() directories/file in multi-dir filepath.", FSFAT_FOPEN_TEST_01), |
| tvendov | 0:e1f465d87307 | 1624 | Case("FSFAT_FOPEN_TEST_02: fopen(r) pre-existing file try to write it.", FSFAT_FOPEN_TEST_02), |
| tvendov | 0:e1f465d87307 | 1625 | Case("FSFAT_FOPEN_TEST_03: fopen(w+) pre-existing file try to write it.", FSFAT_FOPEN_TEST_03), |
| tvendov | 0:e1f465d87307 | 1626 | Case("FSFAT_FOPEN_TEST_04: fopen() with a filename exceeding the maximum length.", FSFAT_FOPEN_TEST_04), |
| tvendov | 0:e1f465d87307 | 1627 | #ifdef FOPEN_EXTENDED_TESTING |
| tvendov | 0:e1f465d87307 | 1628 | Case("FSFAT_FOPEN_TEST_05: fopen() with bad filenames (extended).", FSFAT_FOPEN_TEST_05), |
| tvendov | 0:e1f465d87307 | 1629 | #endif |
| tvendov | 0:e1f465d87307 | 1630 | Case("FSFAT_FOPEN_TEST_06: fopen() with bad filenames (minimal).", FSFAT_FOPEN_TEST_06), |
| tvendov | 0:e1f465d87307 | 1631 | Case("FSFAT_FOPEN_TEST_07: fopen()/errno handling.", FSFAT_FOPEN_TEST_07), |
| tvendov | 0:e1f465d87307 | 1632 | Case("FSFAT_FOPEN_TEST_08: ferror()/clearerr()/errno handling.", FSFAT_FOPEN_TEST_08), |
| tvendov | 0:e1f465d87307 | 1633 | Case("FSFAT_FOPEN_TEST_09: ftell() handling.", FSFAT_FOPEN_TEST_09), |
| tvendov | 0:e1f465d87307 | 1634 | Case("FSFAT_FOPEN_TEST_10: remove() test.", FSFAT_FOPEN_TEST_10), |
| tvendov | 0:e1f465d87307 | 1635 | Case("FSFAT_FOPEN_TEST_11: rename().", FSFAT_FOPEN_TEST_11), |
| tvendov | 0:e1f465d87307 | 1636 | Case("FSFAT_FOPEN_TEST_12: opendir(), readdir(), closedir() test.", FSFAT_FOPEN_TEST_12), |
| tvendov | 0:e1f465d87307 | 1637 | Case("FSFAT_FOPEN_TEST_13: mkdir() test.", FSFAT_FOPEN_TEST_13), |
| tvendov | 0:e1f465d87307 | 1638 | Case("FSFAT_FOPEN_TEST_14: stat() test.", FSFAT_FOPEN_TEST_14), |
| tvendov | 0:e1f465d87307 | 1639 | Case("FSFAT_FOPEN_TEST_15: format() test.", FSFAT_FOPEN_TEST_15), |
| tvendov | 0:e1f465d87307 | 1640 | Case("FSFAT_FOPEN_TEST_16: write/check n x 25kB data files.", FSFAT_FOPEN_TEST_16), |
| tvendov | 0:e1f465d87307 | 1641 | }; |
| tvendov | 0:e1f465d87307 | 1642 | |
| tvendov | 0:e1f465d87307 | 1643 | |
| tvendov | 0:e1f465d87307 | 1644 | /* Declare your test specification with a custom setup handler */ |
| tvendov | 0:e1f465d87307 | 1645 | Specification specification(greentea_setup, cases); |
| tvendov | 0:e1f465d87307 | 1646 | |
| tvendov | 0:e1f465d87307 | 1647 | int main() |
| tvendov | 0:e1f465d87307 | 1648 | { |
| tvendov | 0:e1f465d87307 | 1649 | return !Harness::run(specification); |
| tvendov | 0:e1f465d87307 | 1650 | } |
| tvendov | 0:e1f465d87307 | 1651 | /// @endcond |
| tvendov | 0:e1f465d87307 | 1652 |