Skip to content

Commit 61a816a

Browse files
committed
Fix fopen test build error due to #include <sys/stat.h>, which is not present.
1 parent 28a1f91 commit 61a816a

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

features/TESTS/filesystem/basic/basic.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ SDFileSystem sd(p11, p12, p13, p14, "sd");
139139

140140
#ifdef FSFAT_SDCARD_INSTALLED
141141

142-
#define FAT_FN_TEST_00 fsfat_test_00
143-
#define FAT_FN_TEST_01 fsfat_test_01
144-
#define FAT_FN_TEST_02 fsfat_test_02
142+
#define FSFAT_BASIC_TEST_00 fsfat_basic_test_00
143+
#define FSFAT_BASIC_TEST_01 fsfat_basic_test_01
144+
#define FSFAT_BASIC_TEST_02 fsfat_basic_test_02
145145

146146

147147
#define FSFAT_BASIC_MSG_BUF_SIZE 256
@@ -168,7 +168,7 @@ static char fsfat_basic_msg_g[FSFAT_BASIC_MSG_BUF_SIZE];
168168
*
169169
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
170170
*/
171-
static control_t fsfat_test_00() {
171+
static control_t fsfat_basic_test_00() {
172172

173173
uint8_t data_written[FSFAT_BASIC_DATA_SIZE] = { 0 };
174174
bool result = false;
@@ -219,7 +219,7 @@ extern int errno;
219219
*
220220
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
221221
*/
222-
static control_t fsfat_test_01() {
222+
static control_t fsfat_basic_test_01() {
223223
FILE *fp, *fp1;
224224
int i, j;
225225
int ret = 0;
@@ -234,6 +234,9 @@ static control_t fsfat_test_01() {
234234
for (i = 0; i < 256; i++) {
235235
putc (i, fp);
236236
}
237+
/* FIXME: freopen() should open the specified file closing the first stream. As can be seen from the
238+
* code below, the old file descriptor fp can still be used, and this should not happen.
239+
*/
237240
fp1 = freopen (sd_file_path, "r", fp);
238241
TEST_ASSERT_MESSAGE(fp1 == fp, "Error: cannot open file for reading");
239242

@@ -279,7 +282,7 @@ static control_t fsfat_test_01() {
279282
*
280283
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
281284
*/
282-
static control_t fsfat_test_02() {
285+
static control_t fsfat_basic_test_02() {
283286
static const char hello[] = "Hello, world.\n";
284287
static const char replace[] = "Hewwo, world.\n";
285288
static const size_t replace_from = 2, replace_to = 4;
@@ -397,19 +400,21 @@ static control_t fsfat_test_02() {
397400

398401
#else
399402

400-
#define FAT_FN_TEST_00 fsfat_test_dummy
401-
#define FAT_FN_TEST_01 fsfat_test_dummy
402-
#define FAT_FN_TEST_02 fsfat_test_dummy
403+
#define FSFAT_BASIC_TEST_00 fsfat_basic_test_dummy
404+
#define FSFAT_BASIC_TEST_01 fsfat_basic_test_dummy
405+
#define FSFAT_BASIC_TEST_02 fsfat_basic_test_dummy
403406

404-
/** @brief fsfat_test_dummy Dummy test case for testing when platform doesnt have an SDCard installed.
407+
/** @brief fsfat_basic_test_dummy Dummy test case for testing when platform doesnt have an SDCard installed.
405408
*
406409
* @return success always
407410
*/
408-
static control_t fsfat_test_dummy() {
411+
static control_t fsfat_basic_test_dummy()
412+
{
413+
printf("Null test\n");
409414
return CaseNext;
410415
}
411416

412-
#endif
417+
#endif /* FSFAT_SDCARD_INSTALLED */
413418

414419
utest::v1::status_t greentea_setup(const size_t number_of_cases)
415420
{
@@ -421,10 +426,10 @@ utest::v1::status_t greentea_setup(const size_t number_of_cases)
421426
Case cases[] = {
422427
/* 1 2 3 4 5 6 7 */
423428
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
424-
Case("FSFAT_test_00: fopen()/fgetc()/fprintf()/fclose() test.", FAT_FN_TEST_00),
425-
Case("FSFAT_test_01: fopen()/fseek()/fclose() test.", FAT_FN_TEST_01)
429+
Case("FSFAT_test_00: fopen()/fgetc()/fprintf()/fclose() test.", FSFAT_BASIC_TEST_00),
430+
Case("FSFAT_test_01: fopen()/fseek()/fclose() test.", FSFAT_BASIC_TEST_01)
426431
/* WARNING: Test case not working but currently not required for PAL support
427-
* Case("FSFAT_test_02: fopen()/fgets()/fputs()/ftell()/rewind()/remove() test.", FAT_FN_TEST_02) */
432+
* Case("FSFAT_test_02: fopen()/fgets()/fputs()/ftell()/rewind()/remove() test.", FSFAT_BASIC_TEST_02) */
428433
};
429434

430435

features/TESTS/filesystem/fopen/fopen.cpp

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <stdlib.h> /*rand()*/
3535
#include <inttypes.h>
3636
#include <errno.h>
37-
#include <sys/stat.h>
3837

3938
using namespace utest::v1;
4039

@@ -56,8 +55,6 @@ SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
5655
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
5756
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
5857
/* #define FSFAT_SDCARD_INSTALLED */
59-
/* todo: remove */
60-
#define FSFAT_SDCARD_INSTALLED
6158

6259
#elif defined(TARGET_K22F)
6360
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
@@ -128,6 +125,16 @@ SDFileSystem sd(p11, p12, p13, p14, "sd");
128125
#endif
129126
/// @endcond
130127

128+
#ifdef FSFAT_SDCARD_INSTALLED
129+
130+
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_01
131+
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_02
132+
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_03
133+
#define FSFAT_FOPEN_TEST_04 fsfat_fopen_test_04
134+
#define FSFAT_FOPEN_TEST_05 fsfat_fopen_test_05
135+
#define FSFAT_FOPEN_TEST_06 fsfat_fopen_test_06
136+
#define FSFAT_FOPEN_TEST_07 fsfat_fopen_test_07
137+
131138

132139
/* support functions */
133140

@@ -165,7 +172,7 @@ static fsfat_kv_data_t fsfat_fopen_test_01_kv_data[] = {
165172
*
166173
* @return On success, this returns the number of components in the filepath Returns number of compoee
167174
*/
168-
int32_t fsfat_filepath_split(char* filepath, char* parts[], uint32_t num)
175+
static int32_t fsfat_filepath_split(char* filepath, char* parts[], uint32_t num)
169176
{
170177
uint32_t i = 0;
171178
int32_t ret = -1;
@@ -231,7 +238,7 @@ int32_t fsfat_filepath_remove_all(char* filepath)
231238
*
232239
* @return On success, this returns 0, otherwise < 0 is returned;
233240
*/
234-
int32_t fsfat_filepath_make_dirs(char* filepath)
241+
static int32_t fsfat_filepath_make_dirs(char* filepath)
235242
{
236243
int32_t i = 0;
237244
int32_t num_parts = 0;
@@ -284,7 +291,7 @@ int32_t fsfat_filepath_make_dirs(char* filepath)
284291
*
285292
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
286293
*/
287-
control_t fsfat_fopen_test_01(const size_t call_count)
294+
static control_t fsfat_fopen_test_01(const size_t call_count)
288295
{
289296
char* read_buf;
290297
int32_t ret = 0;
@@ -799,6 +806,29 @@ control_t fsfat_fopen_test_07(const size_t call_count)
799806

800807
#endif // NOT_DEFINED
801808

809+
#else
810+
811+
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_dummy
812+
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_dummy
813+
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_dummy
814+
#define FSFAT_FOPEN_TEST_04 fsfat_fopen_test_dummy
815+
#define FSFAT_FOPEN_TEST_05 fsfat_fopen_test_dummy
816+
#define FSFAT_FOPEN_TEST_06 fsfat_fopen_test_dummy
817+
#define FSFAT_FOPEN_TEST_07 fsfat_fopen_test_dummy
818+
819+
/** @brief fsfat_fopen_test_dummy Dummy test case for testing when platform doesnt have an SDCard installed.
820+
*
821+
* @return success always
822+
*/
823+
static control_t fsfat_fopen_test_dummy()
824+
{
825+
printf("Null test\n");
826+
return CaseNext;
827+
}
828+
829+
#endif /* FSFAT_SDCARD_INSTALLED */
830+
831+
802832
/// @cond FSFAT_DOXYGEN_DISABLE
803833
utest::v1::status_t greentea_setup(const size_t number_of_cases)
804834
{
@@ -809,15 +839,15 @@ utest::v1::status_t greentea_setup(const size_t number_of_cases)
809839
Case cases[] = {
810840
/* 1 2 3 4 5 6 7 */
811841
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
812-
Case("FOPEN_test_01", fsfat_fopen_test_01)
842+
Case("FOPEN_test_01", FSFAT_FOPEN_TEST_01)
813843

814844
#ifdef NOT_DEFINED
815-
Case("FOPEN_test_02", fsfat_fopen_test_02),
816-
Case("FOPEN_test_03", fsfat_fopen_test_03),
817-
Case("FOPEN_test_04", fsfat_fopen_test_04),
818-
Case("FOPEN_test_05", fsfat_fopen_test_05),
819-
Case("FOPEN_test_06", fsfat_fopen_test_06),
820-
Case("FOPEN_test_07", fsfat_fopen_test_07),
845+
Case("FOPEN_test_02", FSFAT_FOPEN_TEST_02),
846+
Case("FOPEN_test_03", FSFAT_FOPEN_TEST_03),
847+
Case("FOPEN_test_04", FSFAT_FOPEN_TEST_04),
848+
Case("FOPEN_test_05", FSFAT_FOPEN_TEST_05),
849+
Case("FOPEN_test_06", FSFAT_FOPEN_TEST_06),
850+
Case("FOPEN_test_07", FSFAT_FOPEN_TEST_07),
821851
#endif // NOT_DEFINED
822852

823853
};

0 commit comments

Comments
 (0)