Skip to content

Commit ceb9266

Browse files
committed
minor edits to fopen test.
1 parent 1cc6f7f commit ceb9266

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

features/storage/FEATURE_STORAGE/TESTS/fs-fat/fopen/fopen.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ int32_t fsfat_filepath_make_dirs(char* filepath)
275275
/* FIX ME: errno not set correctly when error occurs. This indicates a problem with the implementation. */
276276

277277
/** @brief
278-
* Basic open test which does the following:
279-
* - creates KV with default rw perms and writes some data to the value blob.
280-
* - closes the newly created KV.
281-
* - opens the KV with the default permissions (r-only)
282-
* - reads the KV data and checks its the same as the previously created data.
283-
* - closes the opened key
278+
* Basic fopen test which does the following:
279+
* - creates file and writes some data to the value blob.
280+
* - closes the newly created file.
281+
* - opens the file (r-only)
282+
* - reads the file data and checks its the same as the previously created data.
283+
* - closes the opened file
284284
*
285285
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
286286
*/
@@ -355,7 +355,6 @@ control_t fsfat_fopen_test_01(const size_t call_count)
355355
return CaseNext;
356356
}
357357

358-
359358
#ifdef NOT_DEFINED
360359

361360
static fsfat_kv_data_t fsfat_fopen_test_02_data[] = {
@@ -397,7 +396,7 @@ control_t fsfat_fopen_test_02(const size_t call_count)
397396
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, fsfat_fopen_utest_msg_g);
398397

399398
/* by default, owner of key opens with read-only permissions*/
400-
ret = drv->Open(fsfat_fopen_test_02_data[0].key_name, flags, hkey);
399+
ret = fopen(fsfat_fopen_test_02_data[0].key_name, "w+");
401400
FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (filename=\"%s\")(ret=%d)\n", __func__, fsfat_fopen_test_02_data[0].key_name, (int) ret);
402401
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, fsfat_fopen_utest_msg_g);
403402

@@ -416,6 +415,8 @@ control_t fsfat_fopen_test_02(const size_t call_count)
416415
}
417416

418417

418+
419+
419420
/**
420421
* @brief test to open() a pre-existing key and try to write it, which should succeed
421422
* because the key was opened read-write permissions explicitly

features/storage/FEATURE_STORAGE/fs/test/fsfat_debug.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
}while(0);
3030

3131
#define noFSFAT_DEBUG
32-
// todo: remove next line
33-
#define FSFAT_DEBUG
3432

3533
#ifdef FSFAT_DEBUG
3634

features/storage/FEATURE_STORAGE/fs/test/fsfat_test.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
#ifdef FSFAT_DEBUG
3333
uint32_t fsfat_optDebug_g = 1;
34-
// todo: re-instate uint32_t fsfat_optLogLevel_g = FSFAT_LOG_NONE; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FSFAT_LOG_DEBUG|FSFAT_LOG_FENTRY */
35-
uint32_t fsfat_optLogLevel_g = FSFAT_LOG_FENTRY; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FSFAT_LOG_DEBUG|FSFAT_LOG_FENTRY */
34+
uint32_t fsfat_optLogLevel_g = FSFAT_LOG_NONE; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FSFAT_LOG_DEBUG|FSFAT_LOG_FENTRY */
3635
#endif
3736

3837
/* ruler for measuring text strings */
@@ -363,39 +362,39 @@ int32_t fsfat_test_delete_all(void)
363362
return ret;
364363
}
365364

365+
//#endif // NOT_DEFINED
366366

367-
/* @brief test utility function to create a KV in the cfstore
368-
* @note this function expects cfstore to have been initialised with
369-
* a call to ARM_FSFAT_DRIVER::Initialize()
367+
368+
/* @brief test utility function to create a file
370369
*/
371-
int32_t fsfat_test_create(const char* key_name, const char* data, ARM_FSFAT_SIZE* len, ARM_FSFAT_KEYDESC* kdesc)
370+
int32_t fsfat_test_create(const char* filename, const char* data, size_t* len)
372371
{
373-
int32_t ret = ARM_DRIVER_ERROR;
374-
ARM_FSFAT_SIZE value_len = 0;
375-
ARM_FSFAT_DRIVER* drv = &fsfat_driver;
376-
ARM_FSFAT_HANDLE_INIT(hkey);
372+
int32_t ret = -1;
373+
size_t value_len = 0;
377374

378375
FSFAT_FENTRYLOG("%s:entered.\r\n", __func__);
379376
value_len = *len;
380-
kdesc->drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
381-
ret = drv->Create(key_name, value_len, kdesc, hkey);
377+
ret = fopen(filename, value_len, kdesc, hkey);
382378
if(ret < ARM_DRIVER_OK){
383379
return ret;
384380
}
385381
value_len = *len;
386-
ret = drv->Write(hkey, data, &value_len);
382+
ret = fwrite(hkey, data, &value_len);
387383
if(ret < ARM_DRIVER_OK){
388-
drv->Close(hkey);
384+
flose(hkey);
389385
return ret;
390386
}
391387
if(value_len != *len){
392-
drv->Close(hkey);
388+
fclose(hkey);
393389
return ARM_DRIVER_ERROR;
394390
}
395-
drv->Close(hkey);
391+
flose(hkey);
396392
return ret;
397393
}
398394

395+
396+
//#ifdef NOT_DEFINED
397+
399398
/* @brief test utility function to create KVs from the supplied table
400399
* @note this function expects cfstore to have been initialised with
401400
* a call to ARM_FSFAT_DRIVER::Initialize()

0 commit comments

Comments
 (0)