ELEC351 SUBMISSION - Same as on the DLE

/media/uploads/Luka_Danilovic/elec_315_prototype_assembly.jpg

Committer:
Luka_Danilovic
Date:
Wed Jan 10 09:49:43 2018 +0000
Revision:
0:c66224a27cf8
ELEC351 SUBMISSION - SAme as on the DLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Luka_Danilovic 0:c66224a27cf8 1 /* @file fsfat_test.c
Luka_Danilovic 0:c66224a27cf8 2 *
Luka_Danilovic 0:c66224a27cf8 3 * mbed Microcontroller Library
Luka_Danilovic 0:c66224a27cf8 4 * Copyright (c) 2006-2016 ARM Limited
Luka_Danilovic 0:c66224a27cf8 5 *
Luka_Danilovic 0:c66224a27cf8 6 * Licensed under the Apache License, Version 2.0 (the "License");
Luka_Danilovic 0:c66224a27cf8 7 * you may not use this file except in compliance with the License.
Luka_Danilovic 0:c66224a27cf8 8 * You may obtain a copy of the License at
Luka_Danilovic 0:c66224a27cf8 9 *
Luka_Danilovic 0:c66224a27cf8 10 * http://www.apache.org/licenses/LICENSE-2.0
Luka_Danilovic 0:c66224a27cf8 11 *
Luka_Danilovic 0:c66224a27cf8 12 * Unless required by applicable law or agreed to in writing, software
Luka_Danilovic 0:c66224a27cf8 13 * distributed under the License is distributed on an "AS IS" BASIS,
Luka_Danilovic 0:c66224a27cf8 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Luka_Danilovic 0:c66224a27cf8 15 * See the License for the specific language governing permissions and
Luka_Danilovic 0:c66224a27cf8 16 * limitations under the License.
Luka_Danilovic 0:c66224a27cf8 17 *
Luka_Danilovic 0:c66224a27cf8 18 * test support code implementation file.
Luka_Danilovic 0:c66224a27cf8 19 */
Luka_Danilovic 0:c66224a27cf8 20
Luka_Danilovic 0:c66224a27cf8 21 #include "fsfat_debug.h"
Luka_Danilovic 0:c66224a27cf8 22 #include "fsfat_test.h"
Luka_Danilovic 0:c66224a27cf8 23
Luka_Danilovic 0:c66224a27cf8 24 #include <stdio.h>
Luka_Danilovic 0:c66224a27cf8 25 #include <stdlib.h>
Luka_Danilovic 0:c66224a27cf8 26 #include <string.h>
Luka_Danilovic 0:c66224a27cf8 27 #include <assert.h>
Luka_Danilovic 0:c66224a27cf8 28 #include <inttypes.h>
Luka_Danilovic 0:c66224a27cf8 29 #include <ctype.h>
Luka_Danilovic 0:c66224a27cf8 30
Luka_Danilovic 0:c66224a27cf8 31
Luka_Danilovic 0:c66224a27cf8 32 #ifdef FSFAT_DEBUG
Luka_Danilovic 0:c66224a27cf8 33 uint32_t fsfat_optDebug_g = 1;
Luka_Danilovic 0:c66224a27cf8 34 uint32_t fsfat_optLogLevel_g = FSFAT_LOG_NONE; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FSFAT_LOG_DEBUG|FSFAT_LOG_FENTRY; */
Luka_Danilovic 0:c66224a27cf8 35 #endif
Luka_Danilovic 0:c66224a27cf8 36
Luka_Danilovic 0:c66224a27cf8 37 /* ruler for measuring text strings */
Luka_Danilovic 0:c66224a27cf8 38 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 */
Luka_Danilovic 0:c66224a27cf8 39 /* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */
Luka_Danilovic 0:c66224a27cf8 40 /* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
Luka_Danilovic 0:c66224a27cf8 41
Luka_Danilovic 0:c66224a27cf8 42 const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE] = {
Luka_Danilovic 0:c66224a27cf8 43 0x2d, 0xf3, 0x31, 0x4c, 0x11, 0x4f, 0xde, 0x0d, 0xbd, 0xbc, 0xa6, 0x78, 0x36, 0x5c, 0x1d, 0x28,
Luka_Danilovic 0:c66224a27cf8 44 0x5f, 0xa9, 0x10, 0x65, 0x54, 0x45, 0x21, 0x1a, 0x88, 0xfe, 0x76, 0x45, 0xb9, 0xac, 0x65, 0x9a,
Luka_Danilovic 0:c66224a27cf8 45 0x34, 0x9d, 0x73, 0x10, 0xb4, 0xa9, 0x2e, 0x90, 0x95, 0x68, 0xac, 0xfe, 0xc5, 0x2d, 0x15, 0x03,
Luka_Danilovic 0:c66224a27cf8 46 0x34, 0x70, 0xf1, 0x1d, 0x48, 0xa1, 0xa0, 0xed, 0x5c, 0x2f, 0xf5, 0x2b, 0xb9, 0x84, 0xbb, 0x45,
Luka_Danilovic 0:c66224a27cf8 47 0x32, 0xdd, 0xb1, 0x33, 0x95, 0x2a, 0xbc, 0x26, 0xf0, 0x89, 0xba, 0xf4, 0xbd, 0xf9, 0x5d, 0x2e,
Luka_Danilovic 0:c66224a27cf8 48 0x6e, 0x11, 0xc6, 0xa7, 0x78, 0xfc, 0xc9, 0x0e, 0x6b, 0x38, 0xba, 0x14, 0x1b, 0xab, 0x4c, 0x20,
Luka_Danilovic 0:c66224a27cf8 49 0x91, 0xe4, 0xb0, 0xf1, 0x2b, 0x14, 0x07, 0x6b, 0xb5, 0xcd, 0xe3, 0x49, 0x75, 0xac, 0xe8, 0x98,
Luka_Danilovic 0:c66224a27cf8 50 0xf1, 0x58, 0x8f, 0xd9, 0xc4, 0x8f, 0x00, 0x17, 0xb5, 0x06, 0x6a, 0x33, 0xbd, 0xa7, 0x40, 0x5a,
Luka_Danilovic 0:c66224a27cf8 51 0xbf, 0x49, 0xf7, 0x27, 0x1b, 0x4c, 0x3e, 0x6f, 0xe3, 0x08, 0x1f, 0xfd, 0xa6, 0xd4, 0xc7, 0x5f,
Luka_Danilovic 0:c66224a27cf8 52 0xa4, 0xa6, 0x82, 0xad, 0x19, 0xd5, 0x5c, 0xd8, 0x3a, 0x49, 0x85, 0xc9, 0x21, 0x83, 0xf6, 0xc6,
Luka_Danilovic 0:c66224a27cf8 53 0x84, 0xf9, 0x76, 0x89, 0xf3, 0x2d, 0x17, 0x50, 0x97, 0x38, 0x48, 0x9a, 0xe1, 0x82, 0xcd, 0xac,
Luka_Danilovic 0:c66224a27cf8 54 0xa8, 0x1d, 0xd7, 0x96, 0x5e, 0xb3, 0x08, 0xa8, 0x3a, 0xc7, 0x2b, 0x05, 0xaf, 0xdc, 0x16, 0xdf,
Luka_Danilovic 0:c66224a27cf8 55 0x48, 0x0f, 0x2a, 0x7e, 0x3a, 0x82, 0xd7, 0x80, 0xd6, 0x49, 0x27, 0x5d, 0xe3, 0x07, 0x62, 0xb3,
Luka_Danilovic 0:c66224a27cf8 56 0xc3, 0x6c, 0xba, 0xb2, 0xaa, 0x9f, 0xd9, 0x03, 0x0d, 0x27, 0xa8, 0xe0, 0xd6, 0xee, 0x79, 0x4b,
Luka_Danilovic 0:c66224a27cf8 57 0xd6, 0x97, 0x99, 0xb7, 0x11, 0xd6, 0x0d, 0x34, 0xae, 0x99, 0x4a, 0x93, 0x95, 0xd0, 0x5a, 0x34,
Luka_Danilovic 0:c66224a27cf8 58 0x19, 0xa2, 0x69, 0x57, 0xcf, 0x7c, 0x3d, 0x98, 0x88, 0x5d, 0x04, 0xf2, 0xd7, 0xac, 0xa5, 0x63
Luka_Danilovic 0:c66224a27cf8 59 };
Luka_Danilovic 0:c66224a27cf8 60
Luka_Danilovic 0:c66224a27cf8 61
Luka_Danilovic 0:c66224a27cf8 62 /* @brief test utility function to delete the file identified by filename
Luka_Danilovic 0:c66224a27cf8 63 */
Luka_Danilovic 0:c66224a27cf8 64 int32_t fsfat_test_delete(const char* filename)
Luka_Danilovic 0:c66224a27cf8 65 {
Luka_Danilovic 0:c66224a27cf8 66 FSFAT_FENTRYLOG("%s:entered.\r\n", __func__);
Luka_Danilovic 0:c66224a27cf8 67 return remove(filename);
Luka_Danilovic 0:c66224a27cf8 68 }
Luka_Danilovic 0:c66224a27cf8 69
Luka_Danilovic 0:c66224a27cf8 70
Luka_Danilovic 0:c66224a27cf8 71 /* @brief test utility function to create a file
Luka_Danilovic 0:c66224a27cf8 72 *
Luka_Danilovic 0:c66224a27cf8 73 * @param filename name of the file including path
Luka_Danilovic 0:c66224a27cf8 74 * @param data data to store in file
Luka_Danilovic 0:c66224a27cf8 75 * @param len number of bytes of data present in the data buffer.
Luka_Danilovic 0:c66224a27cf8 76 */
Luka_Danilovic 0:c66224a27cf8 77 int32_t fsfat_test_create(const char* filename, const char* data, size_t len)
Luka_Danilovic 0:c66224a27cf8 78 {
Luka_Danilovic 0:c66224a27cf8 79 int32_t ret = -1;
Luka_Danilovic 0:c66224a27cf8 80 FILE *fp = NULL;
Luka_Danilovic 0:c66224a27cf8 81
Luka_Danilovic 0:c66224a27cf8 82 FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len);
Luka_Danilovic 0:c66224a27cf8 83 fp = fopen(filename, "w+");
Luka_Danilovic 0:c66224a27cf8 84 if(fp == NULL){
Luka_Danilovic 0:c66224a27cf8 85 return ret;
Luka_Danilovic 0:c66224a27cf8 86 }
Luka_Danilovic 0:c66224a27cf8 87 ret = fwrite((const void*) data, len, 1, fp);
Luka_Danilovic 0:c66224a27cf8 88 if(ret < 0){
Luka_Danilovic 0:c66224a27cf8 89 fclose(fp);
Luka_Danilovic 0:c66224a27cf8 90 return ret;
Luka_Danilovic 0:c66224a27cf8 91 }
Luka_Danilovic 0:c66224a27cf8 92 fclose(fp);
Luka_Danilovic 0:c66224a27cf8 93 return ret;
Luka_Danilovic 0:c66224a27cf8 94 }
Luka_Danilovic 0:c66224a27cf8 95
Luka_Danilovic 0:c66224a27cf8 96
Luka_Danilovic 0:c66224a27cf8 97 /* @brief support function for generating a kv_name
Luka_Danilovic 0:c66224a27cf8 98 * @param name buffer to hold kv name
Luka_Danilovic 0:c66224a27cf8 99 * @param len length of kv name to generate
Luka_Danilovic 0:c66224a27cf8 100 *
Luka_Danilovic 0:c66224a27cf8 101 */
Luka_Danilovic 0:c66224a27cf8 102 int32_t fsfat_test_filename_gen(char* name, const size_t len)
Luka_Danilovic 0:c66224a27cf8 103 {
Luka_Danilovic 0:c66224a27cf8 104 size_t i;
Luka_Danilovic 0:c66224a27cf8 105 uint32_t pos = 0;
Luka_Danilovic 0:c66224a27cf8 106
Luka_Danilovic 0:c66224a27cf8 107 const char* buf = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@";
Luka_Danilovic 0:c66224a27cf8 108 const int buf_len = strlen(buf);
Luka_Danilovic 0:c66224a27cf8 109 FSFAT_FENTRYLOG("%s:entered\n", __func__);
Luka_Danilovic 0:c66224a27cf8 110 for(i = 0; i < len; i++)
Luka_Danilovic 0:c66224a27cf8 111 {
Luka_Danilovic 0:c66224a27cf8 112 pos = rand() % (buf_len);
Luka_Danilovic 0:c66224a27cf8 113 name[i] = buf[pos];
Luka_Danilovic 0:c66224a27cf8 114 }
Luka_Danilovic 0:c66224a27cf8 115 return 0;
Luka_Danilovic 0:c66224a27cf8 116 }
Luka_Danilovic 0:c66224a27cf8 117