Skip to content

Commit

Permalink
Partial nasa#1052, Filesys test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jphickey committed Jun 17, 2021
1 parent aea265e commit 66d184b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/os/inc/osapi-filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct
*
* OS_FileSysAddFixedMap(&fs_id, "/", "/root");
*
* @param[out] filesys_id A non-zero OSAL ID reflecting the file system
* @param[out] filesys_id A buffer to store the ID of the file system mapping @nonnull
* @param[in] phys_path The native system directory (an existing mount point) @nonnull
* @param[in] virt_path The virtual mount point of this filesystem @nonnull
*
Expand Down
1 change: 1 addition & 0 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const
/*
* Validate inputs
*/
OS_CHECK_POINTER(filesys_id);
OS_CHECK_STRING(phys_path, sizeof(filesys->system_mountpt), OS_FS_ERR_PATH_TOO_LONG);
OS_CHECK_PATHNAME(virt_path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

void TestFileSysAddFixedMapApi(void)
{
int32 expected;
int32 actual;
osal_id_t fs_id;
char translated_path[OS_MAX_LOCAL_PATH_LEN + 5];
char long_path[OS_MAX_PATH_LEN + 5];
Expand All @@ -51,42 +49,14 @@ void TestFileSysAddFixedMapApi(void)
* Just map /test to a dir of the same name, relative to current dir.
*/

expected = OS_FS_ERR_PATH_INVALID;
actual = OS_TranslatePath("/test/myfile.txt", translated_path);
UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_SUCCESS", (long)actual);

expected = OS_SUCCESS;
actual = OS_FileSysAddFixedMap(&fs_id, "./test", "/test");
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual);

expected = OS_SUCCESS;
actual = OS_TranslatePath("/test/myfile.txt", translated_path);
UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_SUCCESS", (long)actual);
UtAssert_INT32_EQ(OS_TranslatePath("/test/myfile.txt", translated_path), OS_FS_ERR_PATH_INVALID);
UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, "./test", "/test"), OS_SUCCESS);
UtAssert_INT32_EQ(OS_TranslatePath("/test/myfile.txt", translated_path), OS_SUCCESS);

/* Test for invalid inputs */
expected = OS_ERR_NAME_TAKEN;
actual = OS_FileSysAddFixedMap(NULL, "./test", "/test");
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual);

expected = OS_INVALID_POINTER;
actual = OS_FileSysAddFixedMap(&fs_id, NULL, "/test");
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual);

expected = OS_INVALID_POINTER;
actual = OS_FileSysAddFixedMap(&fs_id, "./test", NULL);
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual);

expected = OS_INVALID_POINTER;
actual = OS_FileSysAddFixedMap(NULL, NULL, NULL);
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual);

expected = OS_INVALID_POINTER;
actual = OS_FileSysAddFixedMap(&fs_id, NULL, NULL);
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual);

expected = OS_INVALID_POINTER;
actual = OS_FileSysAddFixedMap(NULL, "./test", NULL);
UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual);
UtAssert_INT32_EQ(OS_FileSysAddFixedMap(NULL, "./test", "/test"), OS_INVALID_POINTER);
UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, NULL, "/test"), OS_INVALID_POINTER);
UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, "./test", NULL), OS_INVALID_POINTER);

/* Test names too long (phys_path and virt_path have different limits) */
memset(long_path, 'x', sizeof(long_path) - 1);
Expand Down
8 changes: 4 additions & 4 deletions src/unit-test-coverage/shared/src/coveragetest-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void Test_OS_FileSysAddFixedMap(void)
osal_id_t id;

OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, NULL), OS_INVALID_POINTER);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", NULL), OS_INVALID_POINTER);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, "/virt"), OS_INVALID_POINTER);

UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_FS_ERR_PATH_TOO_LONG);
Expand Down Expand Up @@ -441,9 +442,8 @@ void Test_OS_TranslatePath(void)
LocalBuffer);

/* Check various error paths */
expected = OS_INVALID_POINTER;
actual = OS_TranslatePath(NULL, NULL);
UtAssert_True(actual == expected, "OS_TranslatePath(NULL,NULL) (%ld) == OS_INVALID_POINTER", (long)actual);
UtAssert_INT32_EQ(OS_TranslatePath("/cf/test", NULL), OS_INVALID_POINTER);
UtAssert_INT32_EQ(OS_TranslatePath(NULL, LocalBuffer), OS_INVALID_POINTER);

UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR);
expected = OS_FS_ERR_PATH_TOO_LONG;
Expand Down

0 comments on commit 66d184b

Please sign in to comment.