Skip to content

Commit e59a952

Browse files
committed
add uitl folder, necessary for tests
1 parent d6beb4d commit e59a952

File tree

3 files changed

+293
-0
lines changed

3 files changed

+293
-0
lines changed

util/fsfat_debug.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2016 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** @file fsfat_debug.h
18+
*
19+
* component debug header file.
20+
*/
21+
22+
23+
#ifndef __FSFAT_DEBUG
24+
#define __FSFAT_DEBUG
25+
26+
#include <stdint.h>
27+
#include <assert.h>
28+
#include <stdio.h>
29+
30+
31+
/* Debug Support */
32+
33+
#define FSFAT_LOG_NONE 0
34+
#define FSFAT_LOG_ERR 1
35+
#define FSFAT_LOG_WARN 2
36+
#define FSFAT_LOG_NOTICE 3
37+
#define FSFAT_LOG_INFO 4
38+
#define FSFAT_LOG_DEBUG 5
39+
#define FSFAT_LOG_FENTRY 6
40+
41+
#define FSFAT_LOG(_fmt, ...) \
42+
do \
43+
{ \
44+
printf(_fmt, __VA_ARGS__); \
45+
}while(0);
46+
47+
#define noFSFAT_DEBUG
48+
#ifdef FSFAT_DEBUG
49+
50+
extern uint32_t fsfat_optDebug_g;
51+
extern uint32_t fsfat_optLogLevel_g;
52+
53+
/* uncomment for asserts to work */
54+
/* #undef NDEBUG */
55+
// todo: port to mbedOSV3++ #include <core-util/assert.h>
56+
57+
#define FSFAT_INLINE
58+
// todo: port to mbedOSV3++ #define FSFAT_ASSERT CORE_UTIL_ASSERT
59+
#define FSFAT_ASSERT(...)
60+
61+
#define FSFAT_DBGLOG(_fmt, ...) \
62+
do \
63+
{ \
64+
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_DEBUG)) \
65+
{ \
66+
printf(_fmt, __VA_ARGS__); \
67+
} \
68+
}while(0);
69+
70+
71+
#define FSFAT_ERRLOG(_fmt, ...) \
72+
do \
73+
{ \
74+
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_ERR)) \
75+
{ \
76+
printf(_fmt, __VA_ARGS__); \
77+
} \
78+
}while(0);
79+
80+
81+
#define FSFAT_FENTRYLOG(_fmt, ...) \
82+
do \
83+
{ \
84+
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_FENTRY)) \
85+
{ \
86+
printf(_fmt, __VA_ARGS__); \
87+
} \
88+
}while(0);
89+
90+
91+
92+
93+
94+
#else
95+
#define FSFAT_ASSERT(_x) do { } while(0)
96+
#define FSFAT_INLINE inline
97+
#define FSFAT_DBGLOG(_fmt, ...) do { } while(0)
98+
#define FSFAT_ERRLOG(_fmt, ...) do { } while(0)
99+
#define FSFAT_FENTRYLOG(_fmt, ...) do { } while(0)
100+
#endif /* FSFAT_DEBUG */
101+
102+
103+
#endif /*__FSFAT_DEBUG*/

util/fsfat_test.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* @file fsfat_test.c
2+
*
3+
* mbed Microcontroller Library
4+
* Copyright (c) 2006-2016 ARM Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* test support code implementation file.
19+
*/
20+
21+
#include "fsfat_debug.h"
22+
#include "fsfat_test.h"
23+
24+
#include <stdio.h>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <assert.h>
28+
#include <inttypes.h>
29+
#include <ctype.h>
30+
31+
32+
#ifdef FSFAT_DEBUG
33+
uint32_t fsfat_optDebug_g = 1;
34+
uint32_t fsfat_optLogLevel_g = FSFAT_LOG_FENTRY; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FSFAT_LOG_DEBUG|FSFAT_LOG_FENTRY; */
35+
#endif
36+
37+
/* ruler for measuring text strings */
38+
/* 1 1 1 1 1 1 1 1 1 1 2 2 2 */
39+
/* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */
40+
/* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
41+
42+
const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE] = {
43+
0x2d, 0xf3, 0x31, 0x4c, 0x11, 0x4f, 0xde, 0x0d, 0xbd, 0xbc, 0xa6, 0x78, 0x36, 0x5c, 0x1d, 0x28,
44+
0x5f, 0xa9, 0x10, 0x65, 0x54, 0x45, 0x21, 0x1a, 0x88, 0xfe, 0x76, 0x45, 0xb9, 0xac, 0x65, 0x9a,
45+
0x34, 0x9d, 0x73, 0x10, 0xb4, 0xa9, 0x2e, 0x90, 0x95, 0x68, 0xac, 0xfe, 0xc5, 0x2d, 0x15, 0x03,
46+
0x34, 0x70, 0xf1, 0x1d, 0x48, 0xa1, 0xa0, 0xed, 0x5c, 0x2f, 0xf5, 0x2b, 0xb9, 0x84, 0xbb, 0x45,
47+
0x32, 0xdd, 0xb1, 0x33, 0x95, 0x2a, 0xbc, 0x26, 0xf0, 0x89, 0xba, 0xf4, 0xbd, 0xf9, 0x5d, 0x2e,
48+
0x6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* @brief test utility function to delete the file identified by filename
63+
*/
64+
int32_t fsfat_test_delete(const char *filename)
65+
{
66+
FSFAT_FENTRYLOG("%s:entered.\r\n", __func__);
67+
return remove(filename);
68+
}
69+
70+
71+
/* @brief test utility function to create a file
72+
*
73+
* @param filename name of the file including path
74+
* @param data data to store in file
75+
* @param len number of bytes of data present in the data buffer.
76+
*/
77+
int32_t fsfat_test_create(const char *filename, const char *data, size_t len)
78+
{
79+
int32_t ret = -1;
80+
FILE *fp = NULL;
81+
82+
FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len);
83+
fp = fopen(filename, "w+");
84+
if (fp == NULL) {
85+
return ret;
86+
}
87+
ret = fwrite((const void *) data, len, 1, fp);
88+
if (ret < 0) {
89+
fclose(fp);
90+
return ret;
91+
}
92+
fclose(fp);
93+
return ret;
94+
}
95+
96+
97+
/* @brief support function for generating a kv_name
98+
* @param name buffer to hold kv name
99+
* @param len length of kv name to generate
100+
*
101+
*/
102+
int32_t fsfat_test_filename_gen(char *name, const size_t len)
103+
{
104+
size_t i;
105+
uint32_t pos = 0;
106+
107+
const char *buf = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@";
108+
const int buf_len = strlen(buf);
109+
FSFAT_FENTRYLOG("%s:entered\n", __func__);
110+
for (i = 0; i < len; i++) {
111+
pos = rand() % (buf_len);
112+
name[i] = buf[pos];
113+
}
114+
return 0;
115+
}
116+

util/fsfat_test.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/** @file fsfat_test.h
2+
*
3+
* mbed Microcontroller Library
4+
* Copyright (c) 2006-2016 ARM Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Header file for test support data structures and function API.
19+
*/
20+
#ifndef __FSFAT_TEST_H
21+
#define __FSFAT_TEST_H
22+
23+
#include <stdint.h>
24+
#include <stdlib.h>
25+
#include <stdbool.h>
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
/* Defines */
32+
//#define FSFAT_INIT_1_TABLE_HEAD { "a", ""}
33+
#define FSFAT_INIT_1_TABLE_MID_NODE { "/sd/01234567.txt", "abcdefghijklmnopqrstuvwxyz"}
34+
//#define FSFAT_INIT_1_TABLE_TAIL { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/backrght.txt", "present"}
35+
#define FSFAT_TEST_RW_TABLE_SENTINEL 0xffffffff
36+
#define FSFAT_TEST_BYTE_DATA_TABLE_SIZE 256
37+
#define FSFAT_UTEST_MSG_BUF_SIZE 256
38+
#define FSFAT_UTEST_DEFAULT_TIMEOUT_MS 10000
39+
#define FSFAT_MBED_HOSTTEST_TIMEOUT 60
40+
#define FSFAT_MAX_FILE_BASENAME 8
41+
#define FSFAT_MAX_FILE_EXTNAME 3
42+
#define FSFAT_BUF_MAX_LENGTH 64
43+
#define FSFAT_FILENAME_MAX_LENGTH 255
44+
45+
46+
/* support macro for make string for utest _MESSAGE macros, which dont support formatted output */
47+
#define FSFAT_TEST_UTEST_MESSAGE(_buf, _max_len, _fmt, ...) \
48+
do \
49+
{ \
50+
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
51+
}while(0);
52+
53+
54+
/*
55+
* Structures
56+
*/
57+
58+
/* kv data for test */
59+
typedef struct fsfat_kv_data_t {
60+
const char *filename;
61+
const char *value;
62+
} fsfat_kv_data_t;
63+
64+
65+
extern const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE];
66+
67+
int32_t fsfat_test_create(const char *filename, const char *data, size_t len);
68+
int32_t fsfat_test_delete(const char *key_name);
69+
int32_t fsfat_test_filename_gen(char *name, const size_t len);
70+
#ifdef __cplusplus
71+
}
72+
#endif
73+
74+
#endif /* __FSFAT_TEST_H */

0 commit comments

Comments
 (0)