From 66d184b5ee486dd8e3ef8903979253c6116d536c Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 16:41:04 -0400 Subject: [PATCH] Partial #1052, Filesys test cases --- src/os/inc/osapi-filesys.h | 2 +- src/os/shared/src/osapi-filesys.c | 1 + .../file-sys-add-fixed-map-api-test.c | 42 +++---------------- .../shared/src/coveragetest-filesys.c | 8 ++-- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/os/inc/osapi-filesys.h b/src/os/inc/osapi-filesys.h index 6f7fb47cf..58ca0ffbf 100644 --- a/src/os/inc/osapi-filesys.h +++ b/src/os/inc/osapi-filesys.h @@ -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 * diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 8a209fe13..68eb5f438 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -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); diff --git a/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c index 01047aadf..e1f0f0599 100644 --- a/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c +++ b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c @@ -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]; @@ -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); diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 751a65f52..9e0fb6376 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -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); @@ -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;