diff --git a/.github/workflows/codeql-osal-default.yml b/.github/workflows/codeql-osal-default.yml new file mode 100644 index 000000000..207c844f8 --- /dev/null +++ b/.github/workflows/codeql-osal-default.yml @@ -0,0 +1,57 @@ +name: "CodeQL Analysis OSAL Default Build" + +on: + push: + pull_request: + +env: + SIMULATION: native + ENABLE_UNIT_TESTS: true + OMIT_DEPRECATED: true + BUILDTYPE: release + PERMISSIVE_MODE: true + +jobs: + + #Checks for duplicate actions. Skips push actions if there is a matching or duplicate pull-request action. + check-for-duplicates: + runs-on: ubuntu-latest + # Map a step output to a job output + outputs: + should_skip: ${{ steps.skip_check.outputs.should_skip }} + steps: + - id: skip_check + uses: fkirc/skip-duplicate-actions@master + with: + concurrent_skipping: 'same_content' + skip_after_successful_duplicate: 'true' + do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]' + + + CodeQL-Build: + #Continue if check-for-duplicates found no duplicates. Always runs for pull-requests. + needs: check-for-duplicates + if: ${{ needs.check-for-duplicates.outputs.should_skip != 'true' }} + runs-on: ubuntu-18.04 + timeout-minutes: 15 + + steps: + - name: Checkout submodule + uses: actions/checkout@v2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: c + queries: +security-extended, security-and-quality + + - name: Set up for build + run: | + cp Makefile.sample Makefile + make prep + + - name: Build + run: make -j + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 \ No newline at end of file diff --git a/README.md b/README.md index 7ec3d55e2..8bb3377c3 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,20 @@ The autogenerated OSAL user's guide can be viewed at modifications to subsequent sections only where there was a difference between cmake and classic builds; i.e. the cmake build has no \"make config\" or \"make depend\". Updated title page to replace Code 582 banner with cFS. Added header. | J.Hickey S.Strege | \ No newline at end of file +| 4.2 | 01/31/16 | Moved osconfig.h description into section 2.2.h Consolidated the \"classic\" build and prerequisites setup into section 2.3. Added new section 2.4 on provisioning a build using cmake. Minor
modifications to subsequent sections only where there was a difference between cmake and classic builds; i.e. the cmake build has no \"make config\" or \"make depend\". Updated title page to replace Code 582 banner with cFS. Added header. | J.Hickey S.Strege | diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 9b9805085..a16d12c7f 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -34,7 +34,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 434 +#define OS_BUILD_NUMBER 452 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index 0e86a4cda..4eab9e44e 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -44,6 +44,23 @@ struct OS_common_record uint16 refcount; }; +typedef enum +{ + OS_TASK_BASE = 0, + OS_QUEUE_BASE = OS_TASK_BASE + OS_MAX_TASKS, + OS_BINSEM_BASE = OS_QUEUE_BASE + OS_MAX_QUEUES, + OS_COUNTSEM_BASE = OS_BINSEM_BASE + OS_MAX_BIN_SEMAPHORES, + OS_MUTEX_BASE = OS_COUNTSEM_BASE + OS_MAX_COUNT_SEMAPHORES, + OS_STREAM_BASE = OS_MUTEX_BASE + OS_MAX_MUTEXES, + OS_DIR_BASE = OS_STREAM_BASE + OS_MAX_NUM_OPEN_FILES, + OS_TIMEBASE_BASE = OS_DIR_BASE + OS_MAX_NUM_OPEN_DIRS, + OS_TIMECB_BASE = OS_TIMEBASE_BASE + OS_MAX_TIMEBASES, + OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS, + OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES, + OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS, + OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES +} OS_ObjectIndex_t; + /* * Type of locking that should occur when checking IDs. */ diff --git a/src/os/shared/src/osapi-dir.c b/src/os/shared/src/osapi-dir.c index 7566aa606..0a296306e 100644 --- a/src/os/shared/src/osapi-dir.c +++ b/src/os/shared/src/osapi-dir.c @@ -248,7 +248,7 @@ int32 OS_rmdir(const char *path) return_code = OS_TranslatePath(path, local_path); if (return_code == OS_SUCCESS) { - OS_DirRemove_Impl(local_path); + return_code = OS_DirRemove_Impl(local_path); } return return_code; diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index ab3a71883..cd05f5f0c 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -63,23 +63,6 @@ #define OS_LOCK_KEY_FIXED_VALUE 0x4D000000 #define OS_LOCK_KEY_INVALID ((osal_key_t) {0}) -typedef enum -{ - OS_TASK_BASE = 0, - OS_QUEUE_BASE = OS_TASK_BASE + OS_MAX_TASKS, - OS_BINSEM_BASE = OS_QUEUE_BASE + OS_MAX_QUEUES, - OS_COUNTSEM_BASE = OS_BINSEM_BASE + OS_MAX_BIN_SEMAPHORES, - OS_MUTEX_BASE = OS_COUNTSEM_BASE + OS_MAX_COUNT_SEMAPHORES, - OS_STREAM_BASE = OS_MUTEX_BASE + OS_MAX_MUTEXES, - OS_DIR_BASE = OS_STREAM_BASE + OS_MAX_NUM_OPEN_FILES, - OS_TIMEBASE_BASE = OS_DIR_BASE + OS_MAX_NUM_OPEN_DIRS, - OS_TIMECB_BASE = OS_TIMEBASE_BASE + OS_MAX_TIMEBASES, - OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS, - OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES, - OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS, - OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES -} OS_ObjectIndex_t; - /* * A structure containing the user-specified * details of a "foreach" iteration request diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 5b548ee52..3ca691f09 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -471,10 +471,10 @@ void TestMkRmDirFreeBytes(void) "Checking Free Blocks: status=%d blocks=%lu", (int)status, (unsigned long)statbuf.blocks_free); /* make the two directories */ - status = OS_mkdir(dir1, 0); + status = OS_mkdir(dir1, OS_READ_WRITE); UtAssert_True(status == OS_SUCCESS, "status after mkdir 1 = %d", (int)status); - status = OS_mkdir(dir2, 0); + status = OS_mkdir(dir2, OS_READ_WRITE); UtAssert_True(status == OS_SUCCESS, "status after mkdir 2 = %d", (int)status); /* now create two files in the two directories (1 file per directory) */ @@ -580,10 +580,10 @@ void TestOpenReadCloseDir(void) /* make the two directories */ - status = OS_mkdir(dir1, 0); + status = OS_mkdir(dir1, OS_READ_WRITE); UtAssert_True(status == OS_SUCCESS, "status after mkdir 1 = %d", (int)status); - status = OS_mkdir(dir2, 0); + status = OS_mkdir(dir2, OS_READ_WRITE); UtAssert_True(status == OS_SUCCESS, "status after mkdir 2 = %d", (int)status); /* now create two files in the two directories (1 file per directory) */ @@ -788,7 +788,7 @@ void TestRename(void) /* make the directory */ - status = OS_mkdir(dir1, 0); + status = OS_mkdir(dir1, OS_READ_WRITE); UtAssert_True(status == OS_SUCCESS, "status after mkdir 1 = %d", (int)status); /* now create a file in the directory */ @@ -866,7 +866,7 @@ void TestStat(void) strcpy(buffer1, "111111111111"); /* make the directory */ - status = OS_mkdir(dir1, 0); + status = OS_mkdir(dir1, OS_READ_WRITE); UtAssert_True(status == OS_SUCCESS, "status after mkdir 1 = %d", (int)status); /* now create a file */ diff --git a/src/unit-test-coverage/shared/src/coveragetest-dir.c b/src/unit-test-coverage/shared/src/coveragetest-dir.c index 94cf59ab7..d197136a0 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-dir.c +++ b/src/unit-test-coverage/shared/src/coveragetest-dir.c @@ -52,7 +52,7 @@ void Test_OS_mkdir(void) * int32 OS_mkdir (const char *path, uint32 access) */ int32 expected = OS_SUCCESS; - int32 actual = OS_mkdir("Dir", 0); + int32 actual = OS_mkdir("Dir", OS_READ_WRITE); UtAssert_True(actual == expected, "OS_mkdir() (%ld) == OS_SUCCESS", (long)actual); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index c15c9ea97..cc8670ab9 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -1088,6 +1088,76 @@ void Test_OS_ObjectIdIterator(void) UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2); } +void Test_OS_ObjectIDInteger(void) +{ + /* + * Test Case For: + * OS_ObjectIdToInteger, OS_ObjectIdFromInteger, OS_ObjectIdEqual, OS_ObjectIdDefined + */ + int32 actual; + OS_object_token_t token; + osal_id_t typesI[OS_MAX_TOTAL_RECORDS]; + osal_id_t typesJ[OS_MAX_TOTAL_RECORDS]; + uint32 intID; + int32 recordscount = 0; + osal_objtype_t idtype; + char str[OS_MAX_API_NAME]; + + for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) + { + actual = OS_SUCCESS; + while (actual == OS_SUCCESS && recordscount < OS_MAX_TOTAL_RECORDS) + { + snprintf(str, sizeof(str), "%d", (int)recordscount); + actual = OS_ObjectIdAllocateNew(idtype, str, &token); + + if (actual == OS_SUCCESS) + { + typesI[recordscount] = token.obj_id; + intID = OS_ObjectIdToInteger(typesI[recordscount]); + typesJ[recordscount] = OS_ObjectIdFromInteger(intID); + + recordscount++; + } + } + } + + UtAssert_True(recordscount < OS_MAX_TOTAL_RECORDS, "All Id types checked"); + + for (int i = 0; i < recordscount; i++) + { + UtAssert_True(OS_ObjectIdDefined(typesI[i]), "%lu Is defined", OS_ObjectIdToInteger(typesI[i])); + + for (int j = 0; j < recordscount; j++) + { + if (i == j) + { + UtAssert_True(OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu equals %lu", OS_ObjectIdToInteger(typesI[i]), + OS_ObjectIdToInteger(typesJ[j])); + } + else if (OS_ObjectIdEqual(typesI[i], typesJ[j])) + { + UtAssert_Failed("%lu does not equal %lu", OS_ObjectIdToInteger(typesI[i]), + OS_ObjectIdToInteger(typesJ[j])); + } + } + } +} + +void Test_OS_ObjectIDUndefined(void) +{ + osal_id_t id; + uint32 intID; + + UtAssert_True(!OS_ObjectIdDefined(OS_OBJECT_ID_UNDEFINED), "%lu Is undefined", + OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED)); + + intID = OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED); + id = OS_ObjectIdFromInteger(intID); + + UtAssert_True(!OS_ObjectIdDefined(id), "%lu Is undefined", OS_ObjectIdToInteger(id)); +} + /* Osapi_Test_Setup * * Purpose: @@ -1138,4 +1208,6 @@ void UtTest_Setup(void) ADD_TEST(OS_GetBaseForObjectType); ADD_TEST(OS_GetResourceName); ADD_TEST(OS_ObjectIdIterator); + ADD_TEST(OS_ObjectIDInteger); + ADD_TEST(OS_ObjectIDUndefined); } diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index 82efb42b3..8cadb7f1d 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -130,13 +130,13 @@ add_custom_target(generate_osal_coverage_stubs COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl --filter=/_Impl$/ --stub-suffix=impl-stubs - --hook-suffix=impl-hooks + --handler-suffix=impl-handlers ${CMAKE_CURRENT_SOURCE_DIR}/src ${OSAL_SHARED_IMPL_HEADERS} COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl --filter=/_Init$/ --stub-suffix=init-stubs - --hook-suffix=init-hooks + --handler-suffix=init-handlers ${CMAKE_CURRENT_SOURCE_DIR}/src ${OSAL_SHARED_IMPL_HEADERS} COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl @@ -158,15 +158,15 @@ add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL src/os-shared-console-impl-stubs.c src/os-shared-countsem-impl-stubs.c src/os-shared-dir-impl-stubs.c - src/os-shared-file-impl-hooks.c + src/os-shared-file-impl-handlers.c src/os-shared-file-impl-stubs.c - src/os-shared-filesys-impl-hooks.c + src/os-shared-filesys-impl-handlers.c src/os-shared-filesys-impl-stubs.c src/os-shared-heap-impl-stubs.c src/os-shared-idmap-impl-stubs.c src/os-shared-module-impl-stubs.c src/os-shared-mutex-impl-stubs.c - src/os-shared-network-impl-hooks.c + src/os-shared-network-impl-handlers.c src/os-shared-network-impl-stubs.c src/os-shared-printf-impl-stubs.c src/os-shared-queue-impl-stubs.c @@ -210,7 +210,7 @@ add_library(ut_osapi_shared_stubs STATIC EXCLUDE_FROM_ALL src/os-shared-file-stubs.c src/os-shared-filesys-stubs.c src/os-shared-globaldefs-stubs.c - src/os-shared-idmap-hooks.c + src/os-shared-idmap-handlers.c src/os-shared-idmap-stubs.c src/os-shared-module-stubs.c src/os-shared-sockets-stubs.c diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-handlers.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-hooks.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-handlers.c diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-handlers.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-hooks.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-handlers.c diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-handlers.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/os-shared-idmap-hooks.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-idmap-handlers.c diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-handlers.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-hooks.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-handlers.c diff --git a/src/unit-tests/inc/ut_os_support.h b/src/unit-tests/inc/ut_os_support.h index e285a1e74..1b3f59e0a 100644 --- a/src/unit-tests/inc/ut_os_support.h +++ b/src/unit-tests/inc/ut_os_support.h @@ -61,42 +61,59 @@ */ #define UT_OS_IO_BUFF_SIZE 128 -static inline bool UtOsalRetVal(int32 Fn, int32 Exp, UtAssert_CaseType_t casetype, const char *File, uint32 Line, - const char *FnTxt, const char *ExpTxt, const char *Msg) +static inline bool UtOsalRetVal(int32 Fn, int32 Exp, bool NotImplAllowed, UtAssert_CaseType_t casetype, + const char *File, uint32 Line, const char *FnTxt, const char *ExpTxt) { - return UtAssertEx(Fn == Exp, casetype, File, Line, "%s (%d) == %s (%d): %s", FnTxt, (int)Fn, ExpTxt, (int)Exp, Msg); + /* If "not implemented" is acceptable, override the casetype to be N/A */ + if (NotImplAllowed && (Fn == OS_ERR_NOT_IMPLEMENTED || Fn == OS_ERR_OPERATION_NOT_SUPPORTED)) + { + casetype = UTASSERT_CASETYPE_NA; + } + + return UtAssertEx(Fn == Exp, casetype, File, Line, "%s (%d) == %s (%d)", FnTxt, (int)Fn, ExpTxt, (int)Exp); +} + +static inline bool UtManualInspectionWithStatus(int32 Fn, const char *File, uint32 Line, const char *FnTxt) +{ + UtAssertEx(false, UTASSERT_CASETYPE_MIR, File, Line, "%s value=%d", FnTxt, (int)Fn); + return (Fn >= 0); } /* Only report errors */ -static inline bool UtOsalCheck(int32 Fn, int32 Exp, UtAssert_CaseType_t casetype, const char *File, uint32 Line, - const char *FnTxt, const char *ExpTxt) +static inline bool UtOsalCheck(int32 Fn, UtAssert_CaseType_t casetype, const char *File, uint32 Line, const char *FnTxt) { - return Fn == Exp - ? true - : UtAssertEx(Fn == Exp, casetype, File, Line, "%s (%d) == %s (%d)", FnTxt, (int)Fn, ExpTxt, (int)Exp); + /* Check non-negative to support APIs that return nonzero on success (e.g. read/write) */ + if (Fn >= 0) + { + return true; + } + + return UtAssertEx(false, casetype, File, Line, "%s (%d) >= %s", FnTxt, (int)Fn, "OS_SUCCESS"); } static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line) { if (Fn == OS_ERR_NOT_IMPLEMENTED) { - UtAssertEx(false, UTASSERT_CASETYPE_NA, File, Line, "API not implemented"); + UtAssertEx(false, UTASSERT_CASETYPE_NA, File, Line, "API not implemented (%d)", (int)Fn); return false; } return true; } +#define UT_RETVAL(Fn, Exp) UtOsalRetVal(Fn, Exp, false, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, #Exp) #define UT_NOMINAL(Fn) \ - UtOsalRetVal(Fn, OS_SUCCESS, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, "OS_SUCCESS", "Nominal") -#define UT_RETVAL(Fn, Exp, Msg) UtOsalRetVal(Fn, Exp, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, #Exp, Msg) -#define UT_SETUP(Fn) UtOsalCheck(Fn, OS_SUCCESS, UTASSERT_CASETYPE_TSF, __FILE__, __LINE__, #Fn, "OS_SUCCESS") -#define UT_TEARDOWN(Fn) UtOsalCheck(Fn, OS_SUCCESS, UTASSERT_CASETYPE_TTF, __FILE__, __LINE__, #Fn, "OS_SUCCESS") -#define UT_IMPL(Fn) UtOsalImplemented(Fn, __FILE__, __LINE__) + UtOsalRetVal(Fn, OS_SUCCESS, false, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, "OS_SUCCESS") +#define UT_NOMINAL_OR_NOTIMPL(Fn) \ + UtOsalRetVal(Fn, OS_SUCCESS, true, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, "OS_SUCCESS") -/*--------------------------------------------------------------------------------*/ +#define UT_MIR_STATUS(Fn) UtManualInspectionWithStatus(Fn, __FILE__, __LINE__, #Fn) +#define UT_MIR_VOID(Fn) Fn, UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", #Fn) -#define UT_OS_TEST_RESULT(descStr, caseType) UtAssertEx(false, caseType, __FILE__, __LINE__, "%s", descStr) +#define UT_SETUP(Fn) UtOsalCheck(Fn, UTASSERT_CASETYPE_TSF, __FILE__, __LINE__, #Fn) +#define UT_TEARDOWN(Fn) UtOsalCheck(Fn, UTASSERT_CASETYPE_TTF, __FILE__, __LINE__, #Fn) +#define UT_IMPL(Fn) UtOsalImplemented(Fn, __FILE__, __LINE__) /*--------------------------------------------------------------------------------*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_binsem_test.c b/src/unit-tests/oscore-test/ut_oscore_binsem_test.c index 14dafa6c6..defbf2f0e 100644 --- a/src/unit-tests/oscore-test/ut_oscore_binsem_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_binsem_test.c @@ -73,20 +73,15 @@ void UT_os_bin_sem_create_test() osal_id_t sem_ids[OS_MAX_BIN_SEMAPHORES + 1]; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemCreate(&sem_ids[0], "Good", 1, 0))) - return; - UT_TEARDOWN(OS_BinSemDelete(sem_ids[0])); - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemCreate(NULL, "BinSem1", 1, 0), OS_INVALID_POINTER, "null pointer arg 1"); + UT_RETVAL(OS_BinSemCreate(NULL, "BinSem1", 1, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemCreate(&sem_ids[0], NULL, 1, 0), OS_INVALID_POINTER, "null pointer arg 2"); + UT_RETVAL(OS_BinSemCreate(&sem_ids[0], NULL, 1, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ memset(long_sem_name, 'X', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name) - 1] = '\0'; - UT_RETVAL(OS_BinSemCreate(&sem_ids[0], long_sem_name, 1, 0), OS_ERR_NAME_TOO_LONG, "name too long"); + UT_RETVAL(OS_BinSemCreate(&sem_ids[0], long_sem_name, 1, 0), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ /* Setup */ @@ -103,8 +98,7 @@ void UT_os_bin_sem_create_test() if (i == OS_MAX_BIN_SEMAPHORES) /* setup was successful */ { - UT_RETVAL(OS_BinSemCreate(&sem_ids[OS_MAX_BIN_SEMAPHORES], "OneTooMany", 1, 0), OS_ERR_NO_FREE_IDS, - "no free ids"); + UT_RETVAL(OS_BinSemCreate(&sem_ids[OS_MAX_BIN_SEMAPHORES], "OneTooMany", 1, 0), OS_ERR_NO_FREE_IDS); } /* Reset test environment */ @@ -113,7 +107,7 @@ void UT_os_bin_sem_create_test() /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&sem_ids[0], "DUPLICATE", 1, 0))) { - UT_RETVAL(OS_BinSemCreate(&sem_ids[0], "DUPLICATE", 1, 0), OS_ERR_NAME_TAKEN, "duplicate name"); + UT_RETVAL(OS_BinSemCreate(&sem_ids[0], "DUPLICATE", 1, 0), OS_ERR_NAME_TAKEN); /* Reset test environment */ UT_TEARDOWN(OS_BinSemDelete(sem_ids[0])); @@ -139,11 +133,7 @@ void UT_os_bin_sem_delete_test() osal_id_t bin_sem_id; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemDelete(OS_OBJECT_ID_UNDEFINED))) - return; - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID, "invalid id arg"); + UT_RETVAL(OS_BinSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "DeleteTest", 1, 0))) @@ -166,11 +156,7 @@ void UT_os_bin_sem_flush_test() osal_id_t bin_sem_id; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemFlush(OS_OBJECT_ID_UNDEFINED))) - return; - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemFlush(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID, "invalid id arg"); + UT_RETVAL(OS_BinSemFlush(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "FlushTest", 1, 0))) @@ -194,11 +180,7 @@ void UT_os_bin_sem_give_test() osal_id_t bin_sem_id; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemGive(OS_OBJECT_ID_UNDEFINED))) - return; - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID, "invalid id arg"); + UT_RETVAL(OS_BinSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "GiveTest", 1, 0))) @@ -223,11 +205,7 @@ void UT_os_bin_sem_take_test() osal_id_t bin_sem_id; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemTake(OS_OBJECT_ID_UNDEFINED))) - return; - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID, "invalid id arg"); + UT_RETVAL(OS_BinSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "TakeTest", 1, 0))) @@ -251,16 +229,12 @@ void UT_os_bin_sem_timed_wait_test() osal_id_t bin_sem_id; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemTimedWait(OS_OBJECT_ID_UNDEFINED, 1000))) - return; - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemTimedWait(UT_OBJID_INCORRECT, 1000), OS_ERR_INVALID_ID, "invalid id arg"); + UT_RETVAL(OS_BinSemTimedWait(UT_OBJID_INCORRECT, 1000), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "TimedWait", 1, 0)) && UT_SETUP(OS_BinSemTake(bin_sem_id))) { - UT_RETVAL(OS_BinSemTimedWait(bin_sem_id, 1000), OS_SEM_TIMEOUT, "semtake timed out"); + UT_RETVAL(OS_BinSemTimedWait(bin_sem_id, 1000), OS_SEM_TIMEOUT); UT_TEARDOWN(OS_BinSemDelete(bin_sem_id)); } @@ -288,22 +262,18 @@ void UT_os_bin_sem_get_id_by_name_test() char long_sem_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemGetIdByName(NULL, "InvalidName"))) - return; + UT_RETVAL(OS_BinSemGetIdByName(NULL, "InvalidName"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemGetIdByName(NULL, "InvalidName"), OS_INVALID_POINTER, "invalid ptr arg 1"); - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemGetIdByName(&bin_sem_id, NULL), OS_INVALID_POINTER, "invalid ptr arg 2"); + UT_RETVAL(OS_BinSemGetIdByName(&bin_sem_id, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ memset(long_sem_name, 'Y', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name) - 1] = '\0'; - UT_RETVAL(OS_BinSemGetIdByName(&bin_sem_id, long_sem_name), OS_ERR_NAME_TOO_LONG, "name too long"); + UT_RETVAL(OS_BinSemGetIdByName(&bin_sem_id, long_sem_name), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemGetIdByName(&bin_sem_id, "NameNotFound"), OS_ERR_NAME_NOT_FOUND, "name not found"); + UT_RETVAL(OS_BinSemGetIdByName(&bin_sem_id, "NameNotFound"), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "GetIDByName", 1, 0))) @@ -328,16 +298,12 @@ void UT_os_bin_sem_get_info_test() OS_bin_sem_prop_t bin_sem_prop; /*-----------------------------------------------------*/ - if (!UT_IMPL(OS_BinSemGetInfo(OS_OBJECT_ID_UNDEFINED, &bin_sem_prop))) - return; - - /*-----------------------------------------------------*/ - UT_RETVAL(OS_BinSemGetInfo(UT_OBJID_INCORRECT, &bin_sem_prop), OS_ERR_INVALID_ID, "invalid id"); + UT_RETVAL(OS_BinSemGetInfo(UT_OBJID_INCORRECT, &bin_sem_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "GetInfo", 1, 0))) { - UT_RETVAL(OS_BinSemGetInfo(bin_sem_id, NULL), OS_INVALID_POINTER, "invalid ptr"); + UT_RETVAL(OS_BinSemGetInfo(bin_sem_id, NULL), OS_INVALID_POINTER); UT_TEARDOWN(OS_BinSemDelete(bin_sem_id)); } diff --git a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c index 855d5e9f5..b5cbc7eae 100644 --- a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c @@ -67,146 +67,84 @@ **--------------------------------------------------------------------------------*/ void UT_os_count_sem_create_test() { - int i; - int32 res = 0; - const char *testDesc; - osal_id_t count_sem_ids[OS_MAX_COUNT_SEMAPHORES + 1]; - char sem_name[UT_OS_NAME_BUFF_SIZE]; - char long_sem_name[UT_OS_NAME_BUFF_SIZE]; - uint32 test_setup_invalid = 0; + int i; + osal_id_t count_sem_ids[OS_MAX_COUNT_SEMAPHORES + 1]; + char sem_name[UT_OS_NAME_BUFF_SIZE]; + char long_sem_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg-1 */ - res = OS_CountSemCreate(&count_sem_ids[0], "Good", 1, 0); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_create_test_exit_tag; - } - - /* Clean up */ - OS_CountSemDelete(count_sem_ids[0]); - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg-1"; - - res = OS_CountSemCreate(NULL, "CountSem1", 1, 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemCreate(NULL, "CountSem1", 1, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Null-pointer-arg-2"; + /* #2 Null-pointer-arg-2 */ - res = OS_CountSemCreate(&count_sem_ids[0], NULL, 1, 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemCreate(&count_sem_ids[0], NULL, 1, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ memset(long_sem_name, 'X', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name) - 1] = '\0'; - res = OS_CountSemCreate(&count_sem_ids[0], long_sem_name, 1, 0); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemCreate(&count_sem_ids[0], long_sem_name, 1, 0), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Initial-count-too-high"; + /* #4 Initial-count-too-high */ /* * This test can only be done if the OS defines a specific "SEM_VALUE_MAX" * The OSAL should define this for itself, but it currently does not. * (This macro is not currently defined in RTEMS) */ -#if defined SEM_VALUE_MAX && SEM_VALUE_MAX < UINT32_MAX - res = OS_CountSemCreate(&count_sem_ids[0], "CountSem1", ((uint32)SEM_VALUE_MAX) + 1, 0); - if (res == OS_INVALID_SEM_VALUE) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); +#if defined(SEM_VALUE_MAX) && SEM_VALUE_MAX < UINT32_MAX + UT_RETVAL(OS_CountSemCreate(&count_sem_ids[0], "CountSem1", ((uint32)SEM_VALUE_MAX) + 1, 0), OS_INVALID_SEM_VALUE, + "#4 Initial-count-too-high"); #else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); + UtAssert_NA("#4 Initial-count-too-high"); #endif /*-----------------------------------------------------*/ - testDesc = "#5 No-free-IDs"; + /* #5 No-free-IDs */ /* Setup */ - for (i = 0; i < OS_MAX_COUNT_SEMAPHORES; i++) + for (i = 0; i <= OS_MAX_COUNT_SEMAPHORES; i++) { memset(sem_name, '\0', sizeof(sem_name)); UT_os_sprintf(sem_name, "COUNTSEM%d", i); - res = OS_CountSemCreate(&count_sem_ids[i], sem_name, 1, 0); - if (res != OS_SUCCESS) + + if (i == OS_MAX_COUNT_SEMAPHORES) + { + UT_RETVAL(OS_CountSemCreate(&count_sem_ids[i], "OneTooMany", 1, 0), OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_CountSemCreate(&count_sem_ids[i], sem_name, 1, 0))) { - testDesc = "#5 No-free-IDs - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - test_setup_invalid = 1; break; } } - if (test_setup_invalid == 0) - { - res = OS_CountSemCreate(&count_sem_ids[OS_MAX_COUNT_SEMAPHORES], "OneTooMany", 1, 0); - if (res == OS_ERR_NO_FREE_IDS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - /* Reset test environment */ OS_DeleteAllObjects(); /*-----------------------------------------------------*/ - testDesc = "#6 Duplicate-name"; + /* #6 Duplicate-name */ /* Setup */ - res = OS_CountSemCreate(&count_sem_ids[0], "DUPLICATE", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#6 Duplicate-name - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - } - else + if (UT_SETUP(OS_CountSemCreate(&count_sem_ids[0], "DUPLICATE", 1, 0))) { - res = OS_CountSemCreate(&count_sem_ids[1], "DUPLICATE", 1, 0); - if (res == OS_ERR_NAME_TAKEN) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemCreate(&count_sem_ids[1], "DUPLICATE", 1, 0), OS_ERR_NAME_TAKEN); /* Reset test environment */ - OS_CountSemDelete(count_sem_ids[0]); - OS_CountSemDelete(count_sem_ids[1]); + UT_TEARDOWN(OS_CountSemDelete(count_sem_ids[0])); } /*-----------------------------------------------------*/ - testDesc = "#7 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#8 Nominal"; + /* #8 Nominal */ - res = OS_CountSemCreate(&count_sem_ids[0], "Good", 1, 0); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_CountSemCreate(&count_sem_ids[0], "Good", 1, 0)); /* Reset test environment */ - res = OS_CountSemDelete(count_sem_ids[0]); - -UT_os_count_sem_create_test_exit_tag: - return; + UT_TEARDOWN(OS_CountSemDelete(count_sem_ids[0])); } /*--------------------------------------------------------------------------------* @@ -219,55 +157,21 @@ void UT_os_count_sem_create_test() **--------------------------------------------------------------------------------*/ void UT_os_count_sem_delete_test() { - int32 res = 0; - const char *testDesc; - osal_id_t count_sem_id; + osal_id_t count_sem_id; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_CountSemDelete(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_delete_test_exit_tag; - } + UT_RETVAL(OS_CountSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_CountSemDelete(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "DeleteTest", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "DeleteTest", 1, 0))) { - res = OS_CountSemDelete(count_sem_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_CountSemDelete(count_sem_id)); } - -UT_os_count_sem_delete_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -281,57 +185,23 @@ void UT_os_count_sem_delete_test() **--------------------------------------------------------------------------------*/ void UT_os_count_sem_give_test() { - int32 res = 0; - const char *testDesc; - osal_id_t count_sem_id; + osal_id_t count_sem_id; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_CountSemGive(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_give_test_exit_tag; - } + UT_RETVAL(OS_CountSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_CountSemGive(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "GiveTest", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "GiveTest", 1, 0))) { - res = OS_CountSemGive(count_sem_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_CountSemGive(count_sem_id)); - res = OS_CountSemDelete(count_sem_id); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } - -UT_os_count_sem_give_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -345,56 +215,22 @@ void UT_os_count_sem_give_test() **--------------------------------------------------------------------------------*/ void UT_os_count_sem_take_test() { - int32 res = 0; - const char *testDesc; - osal_id_t count_sem_id; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_CountSemTake(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_take_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_CountSemTake(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + osal_id_t count_sem_id; /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #1 Invalid-ID-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_CountSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "TakeTest", 1, 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "TakeTest", 1, 0))) { - testDesc = "#3 Nominal - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_CountSemTake(count_sem_id)); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } - else - { - res = OS_CountSemTake(count_sem_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_CountSemDelete(count_sem_id); - } - -UT_os_count_sem_take_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -408,86 +244,35 @@ void UT_os_count_sem_take_test() **--------------------------------------------------------------------------------*/ void UT_os_count_sem_timed_wait_test() { - int32 res = 0; - const char *testDesc; - osal_id_t count_sem_id; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_CountSemTimedWait(OS_OBJECT_ID_UNDEFINED, 1000); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_timed_wait_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_CountSemTimedWait(UT_OBJID_INCORRECT, 1000); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + osal_id_t count_sem_id; /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #1 Invalid-ID-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_CountSemTimedWait(UT_OBJID_INCORRECT, 1000), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Sem-take-timed-out"; + /* #3 Sem-take-timed-out */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "TimedWait", 1, 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "TimedWait", 1, 0))) { - testDesc = "#3 Sem-take-timed-out - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_CountSemTake(count_sem_id); - if (res != OS_SUCCESS) - { - testDesc = "#3 Sem-take-timed-out - Count Sem Take failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_CountSemTake(count_sem_id))) { - res = OS_CountSemTimedWait(count_sem_id, 1000); - if (res == OS_SEM_TIMEOUT) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemTimedWait(count_sem_id, 1000), OS_SEM_TIMEOUT); } - res = OS_CountSemDelete(count_sem_id); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "TimedWait", 1, 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "TimedWait", 1, 0))) { - testDesc = "#4 Nominal - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_CountSemTimedWait(count_sem_id, 1000)); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } - else - { - res = OS_CountSemTimedWait(count_sem_id, 1000); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - res = OS_CountSemDelete(count_sem_id); - } - -UT_os_count_sem_timed_wait_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -502,82 +287,41 @@ void UT_os_count_sem_timed_wait_test() **--------------------------------------------------------------------------------*/ void UT_os_count_sem_get_id_by_name_test() { - int32 res = 0; - const char *testDesc; - osal_id_t count_sem_id; - char long_sem_name[UT_OS_NAME_BUFF_SIZE]; + osal_id_t count_sem_id; + char long_sem_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-pointer-arg-1 */ - res = OS_CountSemGetIdByName(0, "InvalidName"); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_get_id_by_name_test_exit_tag; - } + UT_RETVAL(OS_CountSemGetIdByName(NULL, "Name"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg-1"; + /* #2 Invalid-pointer-arg-2 */ - res = OS_CountSemGetIdByName(NULL, "InvalidName"); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemGetIdByName(&count_sem_id, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-2"; - - res = OS_CountSemGetIdByName(&count_sem_id, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ memset(long_sem_name, 'Y', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name) - 1] = '\0'; - res = OS_CountSemGetIdByName(&count_sem_id, long_sem_name); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemGetIdByName(&count_sem_id, long_sem_name), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-not-found"; + /* #4 Name-not-found */ - res = OS_CountSemGetIdByName(&count_sem_id, "NameNotFound"); - if (res == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemGetIdByName(&count_sem_id, "NotFound"), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "GetIDByName", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#5 Nominal - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "GetIDByName", 1, 0))) { - res = OS_CountSemGetIdByName(&count_sem_id, "GetIDByName"); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_CountSemGetIdByName(&count_sem_id, "GetIDByName")); - res = OS_CountSemDelete(count_sem_id); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } - -UT_os_count_sem_get_id_by_name_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -590,74 +334,34 @@ void UT_os_count_sem_get_id_by_name_test() **--------------------------------------------------------------------------------*/ void UT_os_count_sem_get_info_test() { - int32 res = 0; - const char * testDesc; osal_id_t count_sem_id; OS_count_sem_prop_t count_sem_prop; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_CountSemGetInfo(OS_OBJECT_ID_UNDEFINED, &count_sem_prop); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_count_sem_get_info_test_exit_tag; - } + UT_RETVAL(OS_CountSemGetInfo(UT_OBJID_INCORRECT, &count_sem_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_CountSemGetInfo(UT_OBJID_INCORRECT, &count_sem_prop); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #2 Invalid-pointer-arg */ - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg"; - - /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "GetInfo", 1, 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "GetInfo", 1, 0))) { - testDesc = "#2 Invalid-pointer-arg - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_CountSemGetInfo(count_sem_id, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_CountSemGetInfo(count_sem_id, NULL), OS_INVALID_POINTER); - res = OS_CountSemDelete(count_sem_id); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_CountSemCreate(&count_sem_id, "GetInfo", 1, 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_CountSemCreate(&count_sem_id, "GetInfo", 1, 0))) { - testDesc = "#3 Nominal - Count Sem Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_CountSemGetInfo(count_sem_id, &count_sem_prop); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_CountSemGetInfo(count_sem_id, &count_sem_prop)); - res = OS_CountSemDelete(count_sem_id); + UT_TEARDOWN(OS_CountSemDelete(count_sem_id)); } - -UT_os_count_sem_get_info_test_exit_tag: - return; } /*================================================================================* diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.c b/src/unit-tests/oscore-test/ut_oscore_misc_test.c index 4a33644e9..9bea12c08 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.c @@ -88,8 +88,6 @@ *--------------------------------------------------------------------------------*/ void UT_os_apiinit_test() { - int32 res = 0; - const char * testDesc; osal_id_t qId; osal_blockcount_t qDepth = OSAL_BLOCKCOUNT_C(10); size_t qSize = OSAL_SIZE_C(4); @@ -98,52 +96,28 @@ void UT_os_apiinit_test() uint32 semInitValue = 1, semOptions = 0; /*-----------------------------------------------------*/ - testDesc = "#1 Init-not-call-first"; + /* #1 Init-not-call-first */ - if ((OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags) != OS_SUCCESS) && - (OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions) != OS_SUCCESS) && - (OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions) != OS_SUCCESS) && - (OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions) != OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_QueueDelete(qId); - OS_BinSemDelete(semIds[0]); - OS_CountSemDelete(semIds[1]); - OS_MutSemDelete(semIds[2]); + UT_RETVAL(OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags), OS_ERROR); + UT_RETVAL(OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions), OS_ERROR); + UT_RETVAL(OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions), OS_ERROR); + UT_RETVAL(OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions), OS_ERROR); /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ - res = OS_API_Init(); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - testDesc = "API not implemented"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_apiinit_test_exit_tag; - } - else if ((res == OS_SUCCESS) && (OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags) == OS_SUCCESS) && - (OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions) == OS_SUCCESS) && - (OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions) == OS_SUCCESS) && - (OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions) == OS_SUCCESS)) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } + UT_NOMINAL(OS_API_Init()); - /* Reset test environment */ - OS_QueueDelete(qId); - OS_BinSemDelete(semIds[0]); - OS_CountSemDelete(semIds[1]); - OS_MutSemDelete(semIds[2]); + UT_RETVAL(OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags), OS_SUCCESS); + UT_RETVAL(OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions), OS_SUCCESS); + UT_RETVAL(OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions), OS_SUCCESS); + UT_RETVAL(OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions), OS_SUCCESS); -UT_os_apiinit_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_QueueDelete(qId)); + UT_TEARDOWN(OS_BinSemDelete(semIds[0])); + UT_TEARDOWN(OS_CountSemDelete(semIds[1])); + UT_TEARDOWN(OS_MutSemDelete(semIds[2])); } /*--------------------------------------------------------------------------------* @@ -161,10 +135,7 @@ void UT_os_apiinit_test() void UT_os_printf_test() { OS_printf_enable(); - UtPrintf("OS_printf() - #1 Nominal [This is the expected stdout output after API call]\n"); - OS_printf("OS_printf() - #1 Nominal [ This is the expected stdout output after API call]\n"); - - UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); + UT_MIR_VOID(OS_printf("OS_printf() - #1 Nominal [This is the expected stdout output after API call]\n")); } /*--------------------------------------------------------------------------------* @@ -184,10 +155,7 @@ void UT_os_printfenable_test() OS_printf_disable(); OS_printf_enable(); - UtPrintf("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n"); - OS_printf("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n"); - - UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); + UT_MIR_VOID(OS_printf("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n")); } /*--------------------------------------------------------------------------------* @@ -205,19 +173,15 @@ void UT_os_printfenable_test() void UT_os_printfdisable_test() { OS_printf_enable(); - UtPrintf("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n"); - OS_printf("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n"); + UT_MIR_VOID(OS_printf("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n")); OS_printf_disable(); - UtPrintf("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n"); - OS_printf("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n"); - - UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); + UT_MIR_VOID( + OS_printf("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n")); /* Reset test environment */ OS_printf_enable(); - UtPrintf("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n"); - OS_printf("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n"); + UT_MIR_VOID(OS_printf("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n")); } /*--------------------------------------------------------------------------------* @@ -253,60 +217,35 @@ void UT_os_printfdisable_test() **--------------------------------------------------------------------------------*/ void UT_os_getlocaltime_test() { - OS_time_t time_struct; - const char *testDesc; - int32 res = 0, i = 0; + OS_time_t time_struct; + int32 i = 0; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_GetLocalTime(NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_GetLocalTime(NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_getlocaltime_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - res = OS_GetLocalTime(NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #1 Null-pointer-arg */ + UT_RETVAL(OS_GetLocalTime(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #3 Nominal */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - res = OS_GetLocalTime(&time_struct); - if (res == OS_SUCCESS) + for (i = 0; i < 5; i++) { - UtPrintf("\n"); - for (i = 0; i < 5; i++) - { - UtPrintf("OS_GetLocalTime() - #3 Nominal "); - UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", - (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); - - OS_TaskDelay(20); - OS_GetLocalTime(&time_struct); - } + UT_NOMINAL(OS_GetLocalTime(&time_struct)); + UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); - testDesc = "#3 Nominal - Manual inspection required"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_MIR); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + OS_TaskDelay(20); } -UT_os_getlocaltime_test_exit_tag: - return; + /* #3 Nominal - Manual inspection required */ + UT_MIR_STATUS(OS_GetLocalTime(&time_struct)); } /*--------------------------------------------------------------------------------* @@ -342,84 +281,56 @@ void UT_os_getlocaltime_test() **--------------------------------------------------------------------------------*/ void UT_os_setlocaltime_test() { - OS_time_t time_struct; - const char *testDesc; - int32 res = 0, i = 0; + OS_time_t time_struct; + int32 i = 0; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_SetLocalTime(NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_SetLocalTime(NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_setlocaltime_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - res = OS_GetLocalTime(NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_GetLocalTime(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 Nominal */ - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - res = OS_GetLocalTime(&time_struct); - if (res == OS_SUCCESS) + for (i = 0; i < 5; i++) { - for (i = 0; i < 5; i++) - { - UtPrintf("OS_SetLocalTime() - #3 Nominal "); - UtPrintf("[Expecting output before API call to increase over time: %ld.%ld]\n", - (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); + UT_NOMINAL(OS_GetLocalTime(&time_struct)); + UtPrintf("[Expecting output before API call to increase over time: %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); - OS_TaskDelay(20); - OS_GetLocalTime(&time_struct); - } + OS_TaskDelay(20); } time_struct = OS_TimeAssembleFromNanoseconds(20000, 123000); - res = OS_SetLocalTime(&time_struct); - if (res == OS_SUCCESS) + /* + * This case is MIR because on some systems this requires permission, + * failure is expected if user does not have the required permission + */ + if (UT_MIR_STATUS(OS_SetLocalTime(&time_struct))) { UtPrintf("OS_SetLocalTime() - #3 Nominal [New time set at %ld.%ld]\n", (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); - res = OS_GetLocalTime(&time_struct); - if (res == OS_SUCCESS) + for (i = 0; i < 5; i++) { - for (i = 0; i < 5; i++) - { - UtPrintf("OS_SetLocalTime() - #3 Nominal "); - UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", - (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); - - OS_TaskDelay(20); - OS_GetLocalTime(&time_struct); - } + UT_NOMINAL(OS_GetLocalTime(&time_struct)); + UtPrintf("[Expecting output before API call to increase over time: %ld.%ld]\n", + (long)OS_TimeGetTotalSeconds(time_struct), (long)OS_TimeGetMicrosecondsPart(time_struct)); + + OS_TaskDelay(20); } - testDesc = "#3 Nominal - Manual inspection required"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_MIR); - } - else - { - /* Most likely it is a permission issue - no way to fix - but OK to ignore this failure */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); + UT_MIR_STATUS(OS_GetLocalTime(&time_struct)); } - -UT_os_setlocaltime_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -448,52 +359,29 @@ void UT_os_setlocaltime_test() **--------------------------------------------------------------------------------*/ void UT_os_geterrorname_test(void) { - int32 res = 0; os_err_name_t errNames[4]; - const char * testDesc; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg */ - res = OS_GetErrorName(OS_SUCCESS, &errNames[0]); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_geterrorname_test_exit_tag; - } + UT_RETVAL(OS_GetErrorName(OS_ERROR, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #2 Undefined Error */ - res = OS_GetErrorName(OS_ERROR, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_GetErrorName(12345, &errNames[0]), OS_ERROR); /*-----------------------------------------------------*/ - testDesc = "#2 Undefined Error"; + /* #3 Nominal */ - if (OS_GetErrorName(12345, &errNames[0]) == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_GetErrorName(OS_ERR_NAME_TOO_LONG, &errNames[0])); + UtAssert_StrCmp(errNames[0], "OS_ERR_NAME_TOO_LONG", "%s == %s", errNames[0], "OS_ERR_NAME_TOO_LONG"); - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - if ((OS_GetErrorName(OS_ERR_NAME_TOO_LONG, &errNames[0]) == OS_SUCCESS) && - (strcmp(errNames[0], "OS_ERR_NAME_TOO_LONG") == 0) && - (OS_GetErrorName(OS_ERR_NAME_TAKEN, &errNames[1]) == OS_SUCCESS) && - (strcmp(errNames[1], "OS_ERR_NAME_TAKEN") == 0) && - (OS_GetErrorName(OS_ERR_NO_FREE_IDS, &errNames[2]) == OS_SUCCESS) && - (strcmp(errNames[2], "OS_ERR_NO_FREE_IDS") == 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_geterrorname_test_exit_tag: - return; + UT_NOMINAL(OS_GetErrorName(OS_ERR_NAME_TAKEN, &errNames[1])); + UtAssert_StrCmp(errNames[1], "OS_ERR_NAME_TAKEN", "%s == %s", errNames[1], "OS_ERR_NAME_TAKEN"); + + UT_NOMINAL(OS_GetErrorName(OS_ERR_NO_FREE_IDS, &errNames[2])); + UtAssert_StrCmp(errNames[2], "OS_ERR_NO_FREE_IDS", "%s == %s", errNames[2], "OS_ERR_NO_FREE_IDS"); } /*--------------------------------------------------------------------------------* @@ -528,45 +416,25 @@ void UT_os_geterrorname_test(void) **--------------------------------------------------------------------------------*/ void UT_os_heapgetinfo_test(void) { - int32 res = 0; OS_heap_prop_t heapProp; - const char * testDesc; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_HeapGetInfo(&heapProp); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_HeapGetInfo(&heapProp))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_heapgetinfo_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - res = OS_HeapGetInfo(NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #1 Null-pointer-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_HeapGetInfo(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - res = OS_HeapGetInfo(&heapProp); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #3 Nominal */ -UT_os_heapgetinfo_test_exit_tag: - return; + UT_NOMINAL(OS_HeapGetInfo(&heapProp)); } /*================================================================================* diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c index 4781db0f9..b42bfe2cf 100644 --- a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c @@ -67,128 +67,69 @@ **--------------------------------------------------------------------------------*/ void UT_os_mut_sem_create_test() { - int i; - int32 res = 0; - const char *testDesc; - osal_id_t mut_sem_id; - osal_id_t mut_sem_id2; - char sem_name[UT_OS_NAME_BUFF_SIZE]; - char long_sem_name[UT_OS_NAME_BUFF_SIZE]; - uint32 test_setup_invalid = 0; + int i; + osal_id_t mut_sem_id; + osal_id_t mut_sem_id2; + char sem_name[UT_OS_NAME_BUFF_SIZE]; + char long_sem_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg-1 */ - res = OS_MutSemCreate(&mut_sem_id, "Good", 0); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_create_test_exit_tag; - } - - /* Clean up */ - OS_MutSemDelete(mut_sem_id); - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg-1"; - - res = OS_MutSemCreate(NULL, "MutSem1", 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemCreate(NULL, "MutSem1", 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Null-pointer-arg-2"; + /* #2 Null-pointer-arg-2 */ - res = OS_MutSemCreate(&mut_sem_id, NULL, 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemCreate(&mut_sem_id, NULL, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ memset(long_sem_name, 'X', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name) - 1] = '\0'; - res = OS_MutSemCreate(&mut_sem_id, long_sem_name, 0); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemCreate(&mut_sem_id, long_sem_name, 0), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 No-free-IDs"; + /* #4 No-free-IDs */ /* Setup */ - for (i = 0; i < OS_MAX_MUTEXES; i++) + for (i = 0; i <= OS_MAX_MUTEXES; i++) { memset(sem_name, '\0', sizeof(sem_name)); UT_os_sprintf(sem_name, "MUTSEM%d", i); - res = OS_MutSemCreate(&mut_sem_id, sem_name, 0); - if (res != OS_SUCCESS) + if (i == OS_MAX_MUTEXES) + { + UT_RETVAL(OS_MutSemCreate(&mut_sem_id, "OneTooMany", 0), OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_MutSemCreate(&mut_sem_id, sem_name, 0))) { - testDesc = "#4 No-free-IDs - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - test_setup_invalid = 1; break; } } - if (test_setup_invalid == 0) - { - res = OS_MutSemCreate(&mut_sem_id, "OneTooMany", 0); - if (res == OS_ERR_NO_FREE_IDS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - /* Reset test environment */ OS_DeleteAllObjects(); /*-----------------------------------------------------*/ - testDesc = "#5 Duplicate-name"; + /* #5 Duplicate-name */ /* Setup */ - res = OS_MutSemCreate(&mut_sem_id2, "DUPLICATE", 0); - if (res != OS_SUCCESS) - { - testDesc = "#5 Duplicate-name - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id2, "DUPLICATE", 0))) { - res = OS_MutSemCreate(&mut_sem_id, "DUPLICATE", 0); - if (res == OS_ERR_NAME_TAKEN) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemCreate(&mut_sem_id, "DUPLICATE", 0), OS_ERR_NAME_TAKEN); /* Reset test environment */ - res = OS_MutSemDelete(mut_sem_id2); + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id2)); } /*-----------------------------------------------------*/ - testDesc = "#6 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#7 Nominal"; + /* #7 Nominal */ - res = OS_MutSemCreate(&mut_sem_id, "Good", 0); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_MutSemCreate(&mut_sem_id, "Good", 0)); /* Reset test environment */ - res = OS_MutSemDelete(mut_sem_id); - -UT_os_mut_sem_create_test_exit_tag: - return; + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id)); } /*--------------------------------------------------------------------------------* @@ -202,55 +143,20 @@ void UT_os_mut_sem_create_test() **--------------------------------------------------------------------------------*/ void UT_os_mut_sem_delete_test() { - int32 res = 0; - const char *testDesc; - osal_id_t mut_sem_id; + osal_id_t mut_sem_id; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_MutSemDelete(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_delete_test_exit_tag; - } + UT_RETVAL(OS_MutSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_MutSemDelete(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #3 Nominal */ - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "DeleteTest", 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id, "DeleteTest", 0))) { - res = OS_MutSemDelete(mut_sem_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_MutSemDelete(mut_sem_id)); } - -UT_os_mut_sem_delete_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -264,66 +170,25 @@ void UT_os_mut_sem_delete_test() **--------------------------------------------------------------------------------*/ void UT_os_mut_sem_give_test() { - int32 res = 0; - const char *testDesc; - osal_id_t mut_sem_id; + osal_id_t mut_sem_id; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_MutSemGive(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_give_test_exit_tag; - } + UT_RETVAL(OS_MutSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_MutSemGive(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 Nominal */ - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "GiveTest", 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id, "GiveTest", 0))) { - res = OS_MutSemTake(mut_sem_id); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_MutSemTake(mut_sem_id))) { - testDesc = "#3 Nominal - Mutex Take failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_MutSemGive(mut_sem_id)); } - else - { - res = OS_MutSemGive(mut_sem_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_MutSemDelete(mut_sem_id); - } + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id)); } - -UT_os_mut_sem_give_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -337,58 +202,23 @@ void UT_os_mut_sem_give_test() **--------------------------------------------------------------------------------*/ void UT_os_mut_sem_take_test() { - int32 res = 0; - const char *testDesc; - osal_id_t mut_sem_id; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_MutSemTake(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_take_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_MutSemTake(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + osal_id_t mut_sem_id; /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #1 Invalid-ID-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_MutSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "TakeTest", 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id, "TakeTest", 0))) { - res = OS_MutSemTake(mut_sem_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - OS_MutSemGive(mut_sem_id); - OS_MutSemDelete(mut_sem_id); - } + UT_NOMINAL(OS_MutSemTake(mut_sem_id)); -UT_os_mut_sem_take_test_exit_tag: - return; + UT_TEARDOWN(OS_MutSemGive(mut_sem_id)); + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id)); + } } /*--------------------------------------------------------------------------------* @@ -402,81 +232,39 @@ void UT_os_mut_sem_take_test() **--------------------------------------------------------------------------------*/ void UT_os_mut_sem_get_id_by_name_test() { - int32 res = 0; - const char *testDesc; - osal_id_t mut_sem_id; - char long_sem_name[UT_OS_NAME_BUFF_SIZE]; + osal_id_t mut_sem_id; + char long_sem_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-pointer-arg-1 */ - res = OS_MutSemGetIdByName(0, "InvalidName"); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_get_id_by_name_test_exit_tag; - } + UT_RETVAL(OS_MutSemGetIdByName(NULL, "Name"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg-1"; + /* #2 Invalid-pointer-arg-2 */ - res = OS_MutSemGetIdByName(NULL, "InvalidName"); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemGetIdByName(&mut_sem_id, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-2"; - - res = OS_MutSemGetIdByName(&mut_sem_id, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ memset(long_sem_name, 'Y', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name) - 1] = '\0'; - res = OS_MutSemGetIdByName(&mut_sem_id, long_sem_name); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemGetIdByName(&mut_sem_id, long_sem_name), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-not-found"; + /* #4 Name-not-found */ + + UT_RETVAL(OS_MutSemGetIdByName(&mut_sem_id, "NotFound"), OS_ERR_NAME_NOT_FOUND); - res = OS_MutSemGetIdByName(&mut_sem_id, "NameNotFound"); - if (res == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ - /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "GetIDByName", 0); - if (res != OS_SUCCESS) - { - testDesc = "#5 Nominal - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id, "GetIDByName", 0))) { - res = OS_MutSemGetIdByName(&mut_sem_id, "GetIDByName"); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - res = OS_MutSemDelete(mut_sem_id); + UT_NOMINAL(OS_MutSemGetIdByName(&mut_sem_id, "GetIDByName")); + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id)); } - -UT_os_mut_sem_get_id_by_name_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -489,73 +277,33 @@ void UT_os_mut_sem_get_id_by_name_test() **--------------------------------------------------------------------------------*/ void UT_os_mut_sem_get_info_test() { - int32 res = 0; - const char * testDesc; osal_id_t mut_sem_id; OS_mut_sem_prop_t mut_sem_prop; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_MutSemGetInfo(OS_OBJECT_ID_UNDEFINED, &mut_sem_prop); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_get_info_test_exit_tag; - } + UT_RETVAL(OS_MutSemGetInfo(UT_OBJID_INCORRECT, &mut_sem_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; + /* #2 Invalid-pointer-arg */ - res = OS_MutSemGetInfo(UT_OBJID_INCORRECT, &mut_sem_prop); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg"; - - res = OS_MutSemCreate(&mut_sem_id, "InvalidPtr", 0); - if (res != OS_SUCCESS) - { - testDesc = "#2 Invalid-pointer-arg - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id, "InvalidPtr", 0))) { - res = OS_MutSemGetInfo(mut_sem_id, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_MutSemGetInfo(mut_sem_id, NULL), OS_INVALID_POINTER); - OS_MutSemDelete(mut_sem_id); + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id)); } /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "GetInfo", 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Mutex Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_MutSemCreate(&mut_sem_id, "GetInfo", 0))) { - res = OS_MutSemGetInfo(mut_sem_id, &mut_sem_prop); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_MutSemGetInfo(mut_sem_id, &mut_sem_prop)); - res = OS_MutSemDelete(mut_sem_id); + UT_TEARDOWN(OS_MutSemDelete(mut_sem_id)); } - -UT_os_mut_sem_get_info_test_exit_tag: - return; } /*================================================================================* diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.c b/src/unit-tests/oscore-test/ut_oscore_queue_test.c index c991f3324..33edadafa 100644 --- a/src/unit-tests/oscore-test/ut_oscore_queue_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.c @@ -71,126 +71,70 @@ **--------------------------------------------------------------------------------*/ void UT_os_queue_create_test() { - int i = 0; - int32 res = 0; - const char *testDesc; - osal_id_t queue_id; - osal_id_t queue_id2; - char queue_name[UT_OS_NAME_BUFF_SIZE]; - char long_queue_name[UT_OS_NAME_BUFF_SIZE]; - uint32 test_setup_invalid = 0; + int i = 0; + osal_id_t queue_id; + osal_id_t queue_id2; + char queue_name[UT_OS_NAME_BUFF_SIZE]; + char long_queue_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg-1 */ - res = OS_QueueCreate(&queue_id, "Good", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_queue_create_test_exit_tag; - } - /* Clean up */ - OS_QueueDelete(queue_id); - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg-1"; - - res = OS_QueueCreate(NULL, "Queue1", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueCreate(NULL, "Queue1", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Null-pointer-arg-2"; + /* #2 Null-pointer-arg-2 */ - res = OS_QueueCreate(&queue_id, NULL, OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueCreate(&queue_id, NULL, OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ memset(long_queue_name, 'X', sizeof(long_queue_name)); long_queue_name[sizeof(long_queue_name) - 1] = '\0'; - res = OS_QueueCreate(&queue_id, long_queue_name, OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueCreate(&queue_id, long_queue_name, OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0), + OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 No-free-IDs"; + /* #4 No-free-IDs */ /* Setup */ - for (i = 0; i < OS_MAX_QUEUES; i++) + for (i = 0; i <= OS_MAX_QUEUES; i++) { memset(queue_name, '\0', sizeof(queue_name)); UT_os_sprintf(queue_name, "QUEUE%d", i); - res = OS_QueueCreate(&queue_id, queue_name, OSAL_BLOCKCOUNT_C(2), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (i == OS_MAX_QUEUES) + { + UT_RETVAL(OS_QueueCreate(&queue_id, "OneTooMany", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0), + OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_QueueCreate(&queue_id, queue_name, OSAL_BLOCKCOUNT_C(2), sizeof(uint32), 0))) { - testDesc = "#4 No-free-IDs - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - test_setup_invalid = 1; break; } } - if (test_setup_invalid == 0) - { - res = OS_QueueCreate(&queue_id, "OneTooMany", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_ERR_NO_FREE_IDS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - /* Reset test environment */ OS_DeleteAllObjects(); /*-----------------------------------------------------*/ - testDesc = "#5 Duplicate-name"; + /* #5 Duplicate-name */ - /* Setup */ - res = OS_QueueCreate(&queue_id2, "DUPLICATE", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id2, "DUPLICATE", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - UT_OS_TEST_RESULT("Queue Create failed", UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueueCreate(&queue_id, "DUPLICATE", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_ERR_NAME_TAKEN) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueCreate(&queue_id, "DUPLICATE", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0), OS_ERR_NAME_TAKEN); /* Reset test environment */ - res = OS_QueueDelete(queue_id2); + UT_TEARDOWN(OS_QueueDelete(queue_id2)); } /*-----------------------------------------------------*/ - testDesc = "#6 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #7 Nominal */ - /*-----------------------------------------------------*/ - testDesc = "#7 Nominal"; - - res = OS_QueueCreate(&queue_id, "Good", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_QueueCreate(&queue_id, "Good", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0)); /* Reset test environment */ - res = OS_QueueDelete(queue_id); - -UT_os_queue_create_test_exit_tag: - return; + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*--------------------------------------------------------------------------------* @@ -203,55 +147,20 @@ void UT_os_queue_create_test() **--------------------------------------------------------------------------------*/ void UT_os_queue_delete_test() { - int32 res = 0; - const char *testDesc; - osal_id_t queue_id; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_QueueDelete(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_queue_delete_test_exit_tag; - } + osal_id_t queue_id; /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; + /* #1 Invalid-ID-arg */ - res = OS_QueueDelete(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #3 Nominal */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - /* Setup */ - res = OS_QueueCreate(&queue_id, "DeleteTest", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id, "DeleteTest", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - testDesc = "#3 Nominal - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_QueueDelete(queue_id)); } - else - { - res = OS_QueueDelete(queue_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - -UT_os_queue_delete_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -267,244 +176,104 @@ void UT_os_queue_delete_test() **--------------------------------------------------------------------------------*/ void UT_os_queue_get_test() { - int32 res = 0; - const char *testDesc; - osal_id_t queue_id; - uint32 queue_data_out; - uint32 queue_data_in; - size_t size_copied; - size_t data_size; + osal_id_t queue_id; + uint32 queue_data_out; + uint32 queue_data_in; + size_t size_copied; + size_t data_size; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_QueueGet(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_queue_get_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_QueueGet(UT_OBJID_INCORRECT, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-1"; - - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#2 Invalid-pointer-arg-1 - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueueGet(queue_id, NULL, sizeof(uint32), &size_copied, OS_CHECK); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - res = OS_QueueDelete(queue_id); - } + UT_RETVAL(OS_QueueGet(UT_OBJID_INCORRECT, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK), + OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-pointer-arg-2"; + /* #2 Invalid-pointer-arg-1 */ + /* #3 Invalid-pointer-arg-2 */ /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - testDesc = "#3 Invalid-pointer-arg-2 - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), NULL, OS_CHECK); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGet(queue_id, NULL, sizeof(uint32), &size_copied, OS_CHECK), OS_INVALID_POINTER); + UT_RETVAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), NULL, OS_CHECK), OS_INVALID_POINTER); - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#4 Queue-empty"; + /* #4 Queue-empty */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueEmpty", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueEmpty", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - testDesc = "#4 Queue-empty - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, OS_CHECK); - if (res == OS_QUEUE_EMPTY) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), &data_size, OS_CHECK), OS_QUEUE_EMPTY); - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#5 Queue-timed-out"; + /* #5 Queue-timed-out */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueTimeout", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#5 Queue-timed-out - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueTimeout", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, 2); - if (res == OS_QUEUE_TIMEOUT) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), &data_size, 2), OS_QUEUE_TIMEOUT); - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#6 Invalid-queue-size"; + /* #6 Invalid-queue-size */ /* Setup */ - res = OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#6 Invalid-queue-size - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, OSAL_SIZE_C(2), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueuePut(queue_id, &queue_data_out, OSAL_SIZE_C(2), 0))) { - testDesc = "#6 Invalid-queue-size - Queue Put failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_RETVAL(OS_QueueGet(queue_id, &queue_data_in, OSAL_SIZE_C(3), &data_size, OS_CHECK), + OS_QUEUE_INVALID_SIZE); } - else - { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, OSAL_SIZE_C(3), &data_size, OS_CHECK); - if (res == OS_QUEUE_INVALID_SIZE) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#7 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#8 Nominal Pend"; + /* #8 Nominal Pend */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#8 Nominal Pend - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32), 0))) { - testDesc = "#8 Nominal Pend - Queue Put failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), &data_size, OS_PEND)); } - else - { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, OS_PEND); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#9 Nominal timeout"; + /* #9 Nominal timeout */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#9 Nominal timeout - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#9 Nominal timeout - Queue Put failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32), 0))) { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, 20); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), &data_size, 20)); } - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#10 Nominal check"; + /* #10 Nominal check */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#10 Nominal check - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32), 0))) { - testDesc = "#10 Nominal check - Queue Put failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), &data_size, OS_CHECK)); } - else - { - res = OS_QueueGet(queue_id, (void *)&queue_data_in, sizeof(uint32), &data_size, OS_CHECK); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } - -UT_os_queue_get_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -519,107 +288,55 @@ void UT_os_queue_get_test() **--------------------------------------------------------------------------------*/ void UT_os_queue_put_test() { - int32 res = 0; - const char *testDesc; - osal_id_t queue_id; - uint32 queue_data_out = 0; - int i; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_QueuePut(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_out, sizeof(uint32), 0); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_queue_put_test_exit_tag; - } + osal_id_t queue_id; + uint32 queue_data_out = 0; + int i; /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; + /* #1 Invalid-ID-arg */ - res = OS_QueuePut(UT_OBJID_INCORRECT, (void *)&queue_data_out, sizeof(uint32), 0); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueuePut(UT_OBJID_INCORRECT, (void *)&queue_data_out, sizeof(uint32), 0), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg"; + /* #2 Invalid-pointer-arg */ /* Setup */ - res = OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - testDesc = "#2 Invalid-pointer-arg - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueuePut(queue_id, NULL, sizeof(uint32), 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_QueueDelete(queue_id); + UT_RETVAL(OS_QueuePut(queue_id, NULL, sizeof(uint32), 0), OS_INVALID_POINTER); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; + /* #4 Queue-full */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Queue-full"; - - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#4 Queue-full - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueuePut", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { queue_data_out = 0x11223344; - for (i = 0; i < 100; i++) + for (i = 0; i <= 10; i++) { - res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); - if (res == OS_QUEUE_FULL) + if (i == 10) + { + UT_RETVAL(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32), 0), OS_QUEUE_FULL); + } + else if (!UT_SETUP(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32), 0))) + { break; + } } - if (res == OS_QUEUE_FULL) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#5 Nominal - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "QueueGet", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { queue_data_out = 0x11223344; - res = OS_QueuePut(queue_id, (void *)&queue_data_out, sizeof(uint32), 0); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_QueueDelete(queue_id); + UT_NOMINAL(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32), 0)); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } - -UT_os_queue_put_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -633,82 +350,40 @@ void UT_os_queue_put_test() **--------------------------------------------------------------------------------*/ void UT_os_queue_get_id_by_name_test() { - int32 res = 0; - const char *testDesc; - osal_id_t queue_id; - char long_queue_name[UT_OS_NAME_BUFF_SIZE]; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_QueueGetIdByName(0, "InvalidName"); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_queue_get_id_by_name_test_exit_tag; - } + osal_id_t queue_id; + char long_queue_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg-1"; + /* #1 Invalid-pointer-arg-1 */ - res = OS_QueueGetIdByName(NULL, "InvalidName"); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGetIdByName(NULL, "Name"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-2"; + /* #2 Invalid-pointer-arg-2 */ - res = OS_QueueGetIdByName(&queue_id, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGetIdByName(&queue_id, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ memset(long_queue_name, 'Y', sizeof(long_queue_name)); long_queue_name[sizeof(long_queue_name) - 1] = '\0'; - res = OS_QueueGetIdByName(&queue_id, long_queue_name); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGetIdByName(&queue_id, long_queue_name), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-not-found"; + /* #4 Name-not-found */ - res = OS_QueueGetIdByName(&queue_id, "NameNotFound"); - if (res == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_QueueGetIdByName(&queue_id, "NameNotFound"), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "GetIDByName", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) - { - testDesc = "#5 Nominal - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_QueueCreate(&queue_id, "GetIDByName", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - res = OS_QueueGetIdByName(&queue_id, "GetIDByName"); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_QueueGetIdByName(&queue_id, "GetIDByName")); - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } - -UT_os_queue_get_id_by_name_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -721,74 +396,32 @@ void UT_os_queue_get_id_by_name_test() **--------------------------------------------------------------------------------*/ void UT_os_queue_get_info_test() { - int32 res = 0; - const char * testDesc; osal_id_t queue_id; OS_queue_prop_t queue_prop; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_QueueGetInfo(OS_OBJECT_ID_UNDEFINED, &queue_prop); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_queue_get_info_test_exit_tag; - } + UT_RETVAL(OS_QueueGetInfo(UT_OBJID_INCORRECT, &queue_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_QueueGetInfo(UT_OBJID_INCORRECT, &queue_prop); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #2 Invalid-pointer-arg */ - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg"; - - /* Setup */ - res = OS_QueueCreate(&queue_id, "GetInfo", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id, "GetInfo", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - testDesc = "#2 Invalid-pointer-arg - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueueGetInfo(queue_id, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - res = OS_QueueDelete(queue_id); + UT_RETVAL(OS_QueueGetInfo(queue_id, NULL), OS_INVALID_POINTER); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - /* Setup */ - res = OS_QueueCreate(&queue_id, "GetInfo", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_QueueCreate(&queue_id, "GetInfo", OSAL_BLOCKCOUNT_C(10), sizeof(uint32), 0))) { - testDesc = "#3 Nominal - Queue Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_QueueGetInfo(queue_id, &queue_prop); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_QueueGetInfo(queue_id, &queue_prop)); - res = OS_QueueDelete(queue_id); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } - -UT_os_queue_get_info_test_exit_tag: - return; } /*================================================================================* diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.c b/src/unit-tests/oscore-test/ut_oscore_select_test.c index 3ebba4844..b127d4c01 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.c @@ -48,6 +48,8 @@ ** Global variables **--------------------------------------------------------------------------------*/ +static osal_id_t selecttest_fd; + /*--------------------------------------------------------------------------------* ** External function prototypes **--------------------------------------------------------------------------------*/ @@ -60,19 +62,18 @@ ** Local function definitions **--------------------------------------------------------------------------------*/ -char * fsAddrPtr = NULL; -static osal_id_t setup_file(void) +char *fsAddrPtr = NULL; +void UT_os_select_setup_file(void) { - osal_id_t id; UT_SETUP(OS_mkfs(fsAddrPtr, "/ramdev3", "RAM3", OSAL_SIZE_C(512), OSAL_BLOCKCOUNT_C(20))); UT_SETUP(OS_mount("/ramdev3", "/drive3")); - UT_SETUP(OS_OpenCreate(&id, "/drive3/select_test.txt", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE)); - return id; + UT_SETUP(OS_OpenCreate(&selecttest_fd, "/drive3/select_test.txt", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, + OS_READ_WRITE)); } -static void teardown_file(osal_id_t fd) +void UT_os_select_teardown_file(void) { - OS_close(fd); + OS_close(selecttest_fd); OS_remove("/drive3/select_test.txt"); OS_unmount("/drive3"); OS_rmfs("/ramdev3"); @@ -87,32 +88,36 @@ static void teardown_file(osal_id_t fd) **--------------------------------------------------------------------------------*/ void UT_os_select_fd_test(void) { - OS_FdSet FdSet; - osal_id_t fd = setup_file(); + OS_FdSet FdSet; - if (OS_SelectFdZero(&FdSet) == OS_ERR_NOT_IMPLEMENTED || OS_SelectFdAdd(&FdSet, fd) == OS_ERR_NOT_IMPLEMENTED || - OS_SelectFdClear(&FdSet, fd) == OS_ERR_NOT_IMPLEMENTED) + if (!UT_NOMINAL_OR_NOTIMPL(OS_SelectFdZero(&FdSet))) { - UtAssertEx(false, UTASSERT_CASETYPE_NA, __FILE__, __LINE__, "OS_SelectFd...() not implemented"); - goto UT_os_select_fd_test_exit_tag; + return; } - UtAssert_Simple(OS_SelectFdZero(NULL) == OS_INVALID_POINTER); - UtAssert_Simple(OS_SelectFdAdd(NULL, fd) == OS_INVALID_POINTER); - UtAssert_Simple(OS_SelectFdClear(NULL, fd) == OS_INVALID_POINTER); - UtAssert_Simple(OS_SelectFdIsSet(NULL, fd) == false); + if (!UT_NOMINAL_OR_NOTIMPL(OS_SelectFdAdd(&FdSet, selecttest_fd))) + { + return; + } - OS_SelectFdZero(&FdSet); - OS_SelectFdAdd(&FdSet, fd); - UtAssert_Simple(OS_SelectFdIsSet(&FdSet, fd)); + if (!UT_NOMINAL_OR_NOTIMPL(OS_SelectFdClear(&FdSet, selecttest_fd))) + { + return; + } - OS_SelectFdZero(&FdSet); - OS_SelectFdAdd(&FdSet, fd); - OS_SelectFdClear(&FdSet, fd); - UtAssert_Simple(!OS_SelectFdIsSet(&FdSet, fd)); + UT_RETVAL(OS_SelectFdZero(NULL), OS_INVALID_POINTER); + UT_RETVAL(OS_SelectFdAdd(NULL, selecttest_fd), OS_INVALID_POINTER); + UT_RETVAL(OS_SelectFdClear(NULL, selecttest_fd), OS_INVALID_POINTER); + UtAssert_Simple(!OS_SelectFdIsSet(NULL, selecttest_fd)); -UT_os_select_fd_test_exit_tag: - teardown_file(fd); + UT_NOMINAL(OS_SelectFdZero(&FdSet)); + UT_NOMINAL(OS_SelectFdAdd(&FdSet, selecttest_fd)); + UtAssert_Simple(OS_SelectFdIsSet(&FdSet, selecttest_fd)); + + UT_NOMINAL(OS_SelectFdZero(&FdSet)); + UT_NOMINAL(OS_SelectFdAdd(&FdSet, selecttest_fd)); + UT_NOMINAL(OS_SelectFdClear(&FdSet, selecttest_fd)); + UtAssert_Simple(!OS_SelectFdIsSet(&FdSet, selecttest_fd)); } /*--------------------------------------------------------------------------------* @@ -124,32 +129,24 @@ void UT_os_select_fd_test(void) **--------------------------------------------------------------------------------*/ void UT_os_select_single_test(void) { - uint32 StateFlags; - osal_id_t fd = setup_file(); - int32 rc; + uint32 StateFlags; - UT_RETVAL(OS_SelectSingle(fd, NULL, 0), OS_INVALID_POINTER, "NULL flags pointer"); + UT_RETVAL(OS_SelectSingle(selecttest_fd, NULL, 0), OS_INVALID_POINTER); StateFlags = OS_STREAM_STATE_WRITABLE; - rc = OS_SelectSingle(fd, &StateFlags, 0); - if (rc == OS_ERR_NOT_IMPLEMENTED || rc == OS_ERR_OPERATION_NOT_SUPPORTED) + if (!UT_NOMINAL_OR_NOTIMPL(OS_SelectSingle(selecttest_fd, &StateFlags, 0))) { - UtAssertEx(false, UTASSERT_CASETYPE_NA, __FILE__, __LINE__, "OS_SelectSingle() not supported"); - goto UT_os_select_single_test_exit_tag; + return; } - UT_RETVAL(rc, OS_SUCCESS, "OS_SelectSingle(fd, OS_STREAM_STATE_WRITABLE, 0)"); UtAssert_True((StateFlags & OS_STREAM_STATE_WRITABLE) != 0, "StateFlags (0x%x) & OS_STREAM_STATE_WRITABLE", (unsigned int)StateFlags); StateFlags = OS_STREAM_STATE_READABLE; - rc = OS_SelectSingle(fd, &StateFlags, 1); - UT_RETVAL(rc, OS_SUCCESS, "OS_SelectSingle(fd, OS_STREAM_STATE_READABLE, 0)"); + UT_NOMINAL(OS_SelectSingle(selecttest_fd, &StateFlags, 1)); + UtAssert_True((StateFlags & OS_STREAM_STATE_READABLE) != 0, "StateFlags (0x%x) & OS_STREAM_STATE_READABLE", (unsigned int)StateFlags); - -UT_os_select_single_test_exit_tag: - teardown_file(fd); } /*--------------------------------------------------------------------------------* @@ -161,30 +158,22 @@ void UT_os_select_single_test(void) **--------------------------------------------------------------------------------*/ void UT_os_select_multi_test(void) { - OS_FdSet ReadSet, WriteSet; - osal_id_t fd = setup_file(); - int32 rc; - - OS_SelectFdZero(&WriteSet); - OS_SelectFdAdd(&WriteSet, fd); - rc = OS_SelectMultiple(NULL, &WriteSet, 1); - if (rc == OS_ERR_NOT_IMPLEMENTED || rc == OS_ERR_OPERATION_NOT_SUPPORTED) + OS_FdSet ReadSet, WriteSet; + + UT_SETUP(OS_SelectFdZero(&WriteSet)); + UT_SETUP(OS_SelectFdAdd(&WriteSet, selecttest_fd)); + if (!UT_NOMINAL_OR_NOTIMPL(OS_SelectMultiple(NULL, &WriteSet, 1))) { - UtAssertEx(false, UTASSERT_CASETYPE_NA, __FILE__, __LINE__, "OS_SelectMultiple() not supported"); - goto UT_select_multi_test_exit_tag; + return; } - UT_RETVAL(rc, OS_SUCCESS, "OS_SelectMultiple(NULL, &WriteSet, 1)"); - UtAssert_True(OS_SelectFdIsSet(&WriteSet, fd), "OS_SelectFdIsSet(&WriteSet, fd)"); + UtAssert_True(OS_SelectFdIsSet(&WriteSet, selecttest_fd), "OS_SelectFdIsSet(&WriteSet, selecttest_fd)"); - OS_SelectFdZero(&ReadSet); - OS_SelectFdAdd(&ReadSet, fd); - rc = OS_SelectMultiple(&ReadSet, NULL, 1); - UT_RETVAL(rc, OS_SUCCESS, "OS_SelectMultiple(&ReadSet, NULL, 1)"); - UtAssert_True(OS_SelectFdIsSet(&ReadSet, fd), "!OS_SelectFdIsSet(&ReadSet, fd)"); + UT_SETUP(OS_SelectFdZero(&ReadSet)); + UT_SETUP(OS_SelectFdAdd(&ReadSet, selecttest_fd)); + UT_NOMINAL(OS_SelectMultiple(&ReadSet, NULL, 1)); -UT_select_multi_test_exit_tag: - teardown_file(fd); + UtAssert_True(OS_SelectFdIsSet(&ReadSet, selecttest_fd), "!OS_SelectFdIsSet(&ReadSet, selecttest_fd)"); } /*================================================================================* diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.h b/src/unit-tests/oscore-test/ut_oscore_select_test.h index 6f6c10258..0e1a0b93c 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.h @@ -54,6 +54,9 @@ ** Function prototypes **--------------------------------------------------------------------------------*/ +void UT_os_select_setup_file(void); +void UT_os_select_teardown_file(void); + void UT_os_select_fd_test(void); void UT_os_select_single_test(void); void UT_os_select_multi_test(void); diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 2e47c3178..c63e8d5d6 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -55,6 +55,7 @@ extern char g_long_task_name[UT_OS_NAME_BUFF_SIZE]; uint32 g_task_result = 0; osal_id_t g_task_sync_sem; osal_id_t g_task_ids[UT_OS_TASK_LIST_LEN]; +osal_id_t g_task_get_id_result; struct { uint32 words[UT_TASK_STACK_SIZE]; @@ -104,147 +105,95 @@ void generic_test_task(void) **--------------------------------------------------------------------------------*/ void UT_os_task_create_test() { - int32 i = 0, res = 0; - const char *testDesc; - char task_name[UT_OS_NAME_BUFF_SIZE]; + int32 i = 0; + char task_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg-1 */ - res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[0]), - sizeof(g_task_stacks[0]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_create_test_exit_tag; - } - - /* Delay to let child task run */ - OS_TaskDelay(200); - - /* Reset test environment */ - OS_TaskDelete(g_task_ids[0]); - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg-1"; - - res = OS_TaskCreate(NULL, g_task_names[1], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), - sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskCreate(NULL, g_task_names[1], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), + sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0), + OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Null-pointer-arg-2"; + /* #2 Null-pointer-arg-2 */ - res = OS_TaskCreate(&g_task_ids[2], NULL, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), - sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskCreate(&g_task_ids[2], NULL, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), + sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0), + OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Null-pointer-arg-3"; + /* #3 Null-pointer-arg-3 */ - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], NULL, OSAL_STACKPTR_C(&g_task_stacks[3]), - sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskCreate(&g_task_ids[3], g_task_names[3], NULL, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0), + OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long"; + /* #4 Name-too-long */ - res = OS_TaskCreate(&g_task_ids[4], g_long_task_name, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[4]), - sizeof(g_task_stacks[4]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskCreate(&g_task_ids[4], g_long_task_name, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[4]), + sizeof(g_task_stacks[4]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0), + OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#6 No-free-IDs"; + /* #6 No-free-IDs */ - /* Setup */ for (i = 0; i <= OS_MAX_TASKS; i++) { memset(task_name, '\0', sizeof(task_name)); UT_os_sprintf(task_name, "CREATE_TASK%d", (int)i); - res = OS_TaskCreate(&g_task_ids[i], task_name, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[i]), - sizeof(g_task_stacks[i]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) + if (i == OS_MAX_TASKS) + { + UT_RETVAL(OS_TaskCreate(&g_task_ids[i], task_name, generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[i]), + sizeof(g_task_stacks[i]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0), + OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_TaskCreate(&g_task_ids[i], task_name, generic_test_task, + OSAL_STACKPTR_C(&g_task_stacks[i]), sizeof(g_task_stacks[i]), + OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { break; } } - if ((res == OS_ERR_NO_FREE_IDS) && (i == OS_MAX_TASKS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /* Delay to let child tasks run */ OS_TaskDelay(500); /* Reset test environment */ for (i = 0; i < OS_MAX_TASKS; i++) { - res = OS_TaskDelete(g_task_ids[i]); /* Ignore errors, does not matter here */ + UT_TEARDOWN(OS_TaskDelete(g_task_ids[i])); } /*-----------------------------------------------------*/ - testDesc = "#7 Duplicate-name"; + /* #7 Duplicate-name */ - /* Setup */ - res = OS_TaskCreate(&g_task_ids[7], g_task_names[7], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[7]), - sizeof(g_task_stacks[7]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#7 Duplicate-name - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[7], g_task_names[7], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[7]), + sizeof(g_task_stacks[7]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { - res = OS_TaskCreate(&g_task_ids[8], g_task_names[7], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[8]), - sizeof(g_task_stacks[8]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_ERR_NAME_TAKEN) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskCreate(&g_task_ids[8], g_task_names[7], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[8]), + sizeof(g_task_stacks[8]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0), + OS_ERR_NAME_TAKEN); /* Delay to let child task run */ OS_TaskDelay(200); /* Reset test environment */ - res = OS_TaskDelete(g_task_ids[7]); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[7])); } /*-----------------------------------------------------*/ - testDesc = "#8 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#9 Nominal"; + /* #9 Nominal */ - res = OS_TaskCreate(&g_task_ids[9], g_task_names[9], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[9]), - sizeof(g_task_stacks[9]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_TaskCreate(&g_task_ids[9], g_task_names[9], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[9]), + sizeof(g_task_stacks[9]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0)); /* Delay to let child task run */ OS_TaskDelay(200); /* Reset test environment */ - res = OS_TaskDelete(g_task_ids[9]); - -UT_os_task_create_test_exit_tag: - return; + UT_TEARDOWN(OS_TaskDelete(g_task_ids[9])); } /*--------------------------------------------------------------------------------* @@ -257,58 +206,23 @@ void UT_os_task_create_test() **--------------------------------------------------------------------------------*/ void UT_os_task_delete_test() { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TaskDelete(UT_OBJID_INCORRECT); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_delete_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_TaskDelete(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #1 Invalid-ID-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_TaskDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), - sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { /* Delay to let child task run */ OS_TaskDelay(200); - res = OS_TaskDelete(g_task_ids[3]); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_TaskDelete(g_task_ids[3])); } - -UT_os_task_delete_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -353,74 +267,40 @@ void delete_handler_test_task(void) void UT_os_task_install_delete_handler_test(void) { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TaskInstallDeleteHandler(&delete_handler_callback); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_install_delete_handler_test_exit_tag; - } - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; + /* #1 Invalid-ID-arg */ /* ** This test works because it is being called from the main task ** which should not be an official OSAL task */ - res = OS_TaskInstallDeleteHandler(&delete_handler_callback); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskInstallDeleteHandler(&delete_handler_callback), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ - /* Setup */ - res = OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#2 Nominal - Bin-Sem-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0))) { OS_BinSemTake(g_task_sync_sem); - res = - OS_TaskCreate(&g_task_ids[2], g_task_names[2], delete_handler_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), - sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#2 Nominal - Task-Create-failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[2], g_task_names[2], delete_handler_test_task, + OSAL_STACKPTR_C(&g_task_stacks[2]), sizeof(g_task_stacks[2]), + OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { /* Wait for the task to finish the test */ - OS_BinSemTake(g_task_sync_sem); + UT_SETUP(OS_BinSemTake(g_task_sync_sem)); + /* Delay to let child task run */ OS_TaskDelay(500); - res = OS_TaskDelete(g_task_ids[2]); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[2])); - if (g_task_result == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UtAssert_True(g_task_result == OS_SUCCESS, "OS_TaskInstallDeleteHandler() (%d) == OS_SUCCESS", + (int)g_task_result); } - res = OS_BinSemDelete(g_task_sync_sem); + UT_TEARDOWN(OS_BinSemDelete(g_task_sync_sem)); } - -UT_os_task_install_delete_handler_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -456,35 +336,21 @@ void exit_test_task(void) void UT_os_task_exit_test(void) { - int32 res = 0; OS_task_prop_t task_prop; - const char * testDesc; /*-----------------------------------------------------*/ - testDesc = "#1 Nominal"; + /* #1 Nominal */ - /* Setup */ - res = OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#1 Nominal - Bin-Sem-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0))) { - OS_BinSemTake(g_task_sync_sem); + UT_SETUP(OS_BinSemTake(g_task_sync_sem)); - res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], exit_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), - sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#1 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[1], g_task_names[1], exit_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), + sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { /* Wait for the task to finish the test */ - OS_BinSemTake(g_task_sync_sem); + UT_SETUP(OS_BinSemTake(g_task_sync_sem)); + /* Delay to let the child task run */ OS_TaskDelay(500); @@ -492,19 +358,11 @@ void UT_os_task_exit_test(void) ** The only real way to tell if TaskExit ran is to check to see if the ** task ID is valid. It should not be valid */ - res = OS_TaskGetInfo(g_task_ids[1], &task_prop); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - OS_TaskDelete(g_task_ids[1]); /* Won't hurt if its already deleted */ + UT_RETVAL(OS_TaskGetInfo(g_task_ids[1], &task_prop), OS_ERR_INVALID_ID); } - OS_BinSemDelete(g_task_sync_sem); + UT_TEARDOWN(OS_BinSemDelete(g_task_sync_sem)); } - - return; } /*--------------------------------------------------------------------------------* @@ -516,35 +374,10 @@ void UT_os_task_exit_test(void) **--------------------------------------------------------------------------------*/ void UT_os_task_delay_test() { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TaskDelay(100); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_delay_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ - res = OS_TaskDelay(100); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_task_delay_test_exit_tag: - return; + UT_NOMINAL(OS_TaskDelay(100)); } /*--------------------------------------------------------------------------------* @@ -558,110 +391,37 @@ void UT_os_task_delay_test() **--------------------------------------------------------------------------------*/ void UT_os_task_set_priority_test() { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TaskCreate(&g_task_ids[0], g_task_names[0], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[0]), - sizeof(g_task_stacks[0]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#0 API not implemented - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_task_set_priority_test_exit_tag; - } - else - { - res = OS_TaskSetPriority(g_task_ids[0], OSAL_PRIORITY_C(UT_TASK_PRIORITY)); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_set_priority_test_exit_tag; - } - - /* Delay to let child task run */ - OS_TaskDelay(500); - - /* Clean up */ - res = OS_TaskDelete(g_task_ids[0]); - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_TaskSetPriority(UT_OBJID_INCORRECT, OSAL_PRIORITY_C(100)); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-priority"; - - res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), - sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#2 Invalid-priority - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - /* Delay to let child task run */ - OS_TaskDelay(500); - - /* Reset test environment */ - res = OS_TaskDelete(g_task_ids[2]); - } - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; + /* #1 Invalid-ID-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_TaskSetPriority(UT_OBJID_INCORRECT, OSAL_PRIORITY_C(100)), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - res = OS_TaskCreate(&g_task_ids[4], g_task_names[4], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[4]), - sizeof(g_task_stacks[4]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#4 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[4], g_task_names[4], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[4]), + sizeof(g_task_stacks[4]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { - res = OS_TaskSetPriority(g_task_ids[4], OSAL_PRIORITY_C(UT_TASK_PRIORITY - 10)); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_TaskSetPriority(g_task_ids[4], OSAL_PRIORITY_C(UT_TASK_PRIORITY - 10))); /* Delay to let child task run */ OS_TaskDelay(500); + UT_NOMINAL(OS_TaskSetPriority(g_task_ids[4], OSAL_PRIORITY_C(UT_TASK_PRIORITY))); + /* Reset test environment */ - OS_TaskSetPriority(g_task_ids[4], OSAL_PRIORITY_C(UT_TASK_PRIORITY)); - OS_TaskDelete(g_task_ids[4]); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[4])); } - -UT_os_task_set_priority_test_exit_tag: - return; } /*--------------------------------------------------------------------------------*/ void getid_test_task(void) { - osal_id_t task_id; OS_task_prop_t task_prop; - task_id = OS_TaskGetId(); - OS_TaskGetInfo(task_id, &task_prop); - - UtPrintf("OS_TaskGetId() - #1 Nominal [This is the returned task Id=%lx]\n", OS_ObjectIdToInteger(task_id)); + g_task_get_id_result = OS_TaskGetId(); + OS_TaskGetInfo(g_task_get_id_result, &task_prop); while (1) { @@ -677,35 +437,23 @@ void getid_test_task(void) **--------------------------------------------------------------------------------*/ void UT_os_task_get_id_test() { - int32 res = 0; - const char *testDesc; - /* * Note this function does not return a normal status code, * there is no provision to return/check for OS_ERR_NOT_IMPLEMENTED. */ /*-----------------------------------------------------*/ - testDesc = "#1 Nominal"; + /* #1 Nominal */ - /* Setup */ - res = OS_TaskCreate(&g_task_ids[1], g_task_names[1], getid_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), - sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#1 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[1], g_task_names[1], getid_test_task, OSAL_STACKPTR_C(&g_task_stacks[1]), + sizeof(g_task_stacks[1]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { OS_TaskDelay(500); - UtPrintf("OS_TaskGetId() - #1 Nominal [This is the expected task Id=%lx]\n", - OS_ObjectIdToInteger(g_task_ids[1])); - - res = OS_TaskDelete(g_task_ids[1]); /* Won't hurt if its already deleted */ + UtAssert_True(OS_ObjectIdEqual(g_task_get_id_result, g_task_ids[1]), "OS_TaskGetId() (%lu) == %lu", + OS_ObjectIdToInteger(g_task_get_id_result), OS_ObjectIdToInteger(g_task_ids[1])); - UT_OS_TEST_RESULT("#1 Nominal - Manual inspection required", UTASSERT_CASETYPE_MIR); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[1])); } } @@ -720,80 +468,41 @@ void UT_os_task_get_id_test() **--------------------------------------------------------------------------------*/ void UT_os_task_get_id_by_name_test() { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TaskGetIdByName(0, "InvalidName"); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_get_id_by_name_test_exit_tag; - } - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg-1"; + /* #1 Invalid-pointer-arg-1 */ - res = OS_TaskGetIdByName(NULL, "InvalidName"); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskGetIdByName(NULL, "Name"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-2"; + /* #2 Invalid-pointer-arg-2 */ - res = OS_TaskGetIdByName(&g_task_ids[2], NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskGetIdByName(&g_task_ids[2], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Name-too-long"; + /* #3 Name-too-long */ - res = OS_TaskGetIdByName(&g_task_ids[3], g_long_task_name); - if (res == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskGetIdByName(&g_task_ids[3], g_long_task_name), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-not-found"; + /* #4 Name-not-found */ - res = OS_TaskGetIdByName(&g_task_ids[4], "NameNotFound"); - if (res == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskGetIdByName(&g_task_ids[4], "NotFound"), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ /* Setup */ - res = OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[5]), - sizeof(g_task_stacks[5]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_TaskCreate(&g_task_ids[5], g_task_names[5], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[5]), + sizeof(g_task_stacks[5]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { - testDesc = "#5 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_TaskGetIdByName(&g_task_ids[6], g_task_names[5]); - if ((res == OS_SUCCESS) && OS_ObjectIdEqual(g_task_ids[5], g_task_ids[6])) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_TaskGetIdByName(&g_task_ids[6], g_task_names[5])); + + UtAssert_True(OS_ObjectIdEqual(g_task_ids[5], g_task_ids[6]), "OS_TaskGetIdByName() ID (%lu) == %lu", + OS_ObjectIdToInteger(g_task_ids[5]), OS_ObjectIdToInteger(g_task_ids[6])); OS_TaskDelay(500); /* Delay to let task run */ - res = OS_TaskDelete(g_task_ids[5]); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[5])); } - -UT_os_task_get_id_by_name_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -806,83 +515,43 @@ void UT_os_task_get_id_by_name_test() **--------------------------------------------------------------------------------*/ void UT_os_task_get_info_test() { - int32 res = 0; OS_task_prop_t task_prop; - const char * testDesc; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-ID-arg */ - res = OS_TaskGetInfo(UT_OBJID_INCORRECT, &task_prop); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_get_info_test_exit_tag; - } + UT_RETVAL(OS_TaskGetInfo(UT_OBJID_INCORRECT, &task_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_TaskGetInfo(UT_OBJID_INCORRECT, &task_prop); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg"; + /* #2 Invalid-pointer-arg */ /* Setup */ - res = OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), - sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#2 Invalid-pointer-arg - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TaskCreate(&g_task_ids[2], g_task_names[2], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), + sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { - res = OS_TaskGetInfo(g_task_ids[2], NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TaskGetInfo(g_task_ids[2], NULL), OS_INVALID_POINTER); /* Delay to let child task run */ OS_TaskDelay(500); /* Reset test environment */ - res = OS_TaskDelete(g_task_ids[2]); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[2])); } /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - /* Setup */ - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), - sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_TaskCreate(&g_task_ids[3], g_task_names[3], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), + sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) { - testDesc = "#3 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_TaskGetInfo(g_task_ids[3], &task_prop); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_TaskGetInfo(g_task_ids[3], &task_prop)); /* Delay to let child task run */ OS_TaskDelay(500); /* Reset test environment */ - res = OS_TaskDelete(g_task_ids[3]); + UT_TEARDOWN(OS_TaskDelete(g_task_ids[3])); } - -UT_os_task_get_info_test_exit_tag: - return; } /*================================================================================* diff --git a/src/unit-tests/oscore-test/ut_oscore_test.c b/src/unit-tests/oscore-test/ut_oscore_test.c index 9a48689b8..3556bd074 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -228,9 +228,9 @@ void UtTest_Setup(void) UtTest_Add(UT_os_queue_get_id_by_name_test, NULL, NULL, "OS_QueueGetIdByName"); UtTest_Add(UT_os_queue_get_info_test, NULL, NULL, "OS_QueueGetInfo"); - UtTest_Add(UT_os_select_fd_test, NULL, NULL, "OS_SelectFd"); - UtTest_Add(UT_os_select_single_test, NULL, NULL, "OS_SelectSingle"); - UtTest_Add(UT_os_select_multi_test, NULL, NULL, "OS_SelectMultiple"); + UtTest_Add(UT_os_select_fd_test, UT_os_select_setup_file, UT_os_select_teardown_file, "OS_SelectFd"); + UtTest_Add(UT_os_select_single_test, UT_os_select_setup_file, UT_os_select_teardown_file, "OS_SelectSingle"); + UtTest_Add(UT_os_select_multi_test, UT_os_select_setup_file, UT_os_select_teardown_file, "OS_SelectMultiple"); UtTest_Add(NULL, UT_os_init_task_misc, NULL, "UT_os_init_task_misc"); UtTest_Add(UT_os_task_create_test, UT_os_init_task_create_test, NULL, "OS_TaskCreate"); diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c index 40540e824..ea7661d4c 100644 --- a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c @@ -55,7 +55,7 @@ extern char *g_mntName; **--------------------------------------------------------------------------------*/ char g_dirName[UT_OS_PATH_BUFF_SIZE]; -char g_fileName[UT_OS_FILE_BUFF_SIZE]; +char g_fileName[UT_OS_PATH_BUFF_SIZE]; char g_subdirNames[UT_OS_FILE_MAX_DIRS][UT_OS_PATH_BUFF_SIZE]; const char *g_tgtSubdirs[UT_OS_FILE_MAX_DIRS] = {"subdir1", "subdir2"}; @@ -120,75 +120,39 @@ void UT_os_read_n_sort_dirs(osal_id_t); **--------------------------------------------------------------------------------*/ void UT_os_makedir_test() { - int32 status; - osal_id_t fileDesc; - const char *testDesc; + osal_id_t fileDesc; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg */ - if (OS_mkdir(NULL, 755) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_makedir_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_mkdir(NULL, 755) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; - - if (OS_mkdir(g_longPathName, 755) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mkdir(NULL, OS_READ_WRITE), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-path-arg"; + /* #2 Path-too-long-arg */ - if (OS_mkdir("tmpDir", 755) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mkdir(g_longPathName, OS_READ_WRITE), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 OS-call-failure"; + /* #3 Invalid-path-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_mkdir("tmpDir", OS_READ_WRITE), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ memset(g_dirName, '\0', sizeof(g_dirName)); UT_os_sprintf(g_dirName, "%s/mkdir_Nominal", g_mntName); - if (OS_mkdir(g_dirName, 755) != OS_SUCCESS) + if (UT_SETUP(OS_mkdir(g_dirName, OS_READ_WRITE))) { - testDesc = "#5 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_makedir_test_exit_tag; + memset(g_fileName, '\0', sizeof(g_fileName)); + UT_os_sprintf(g_fileName, "%s/mkdir_File.txt", g_dirName); + UT_NOMINAL(OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE)); + + /* Reset test environment */ + UT_TEARDOWN(OS_close(fileDesc)); + UT_TEARDOWN(OS_remove(g_fileName)); + UT_TEARDOWN(OS_rmdir(g_dirName)); } - - memset(g_fileName, '\0', sizeof(g_fileName)); - UT_os_sprintf(g_fileName, "%s/mkdir_File.txt", g_dirName); - status = OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (status >= 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_close(fileDesc); - OS_remove(g_fileName); - OS_rmdir(g_dirName); - -UT_os_makedir_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -238,70 +202,36 @@ void UT_os_makedir_test() **--------------------------------------------------------------------------------*/ void UT_os_opendir_test() { - osal_id_t dirh; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_DirectoryOpen(&dirh, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_opendir_test_exit_tag; - } + osal_id_t dirh; /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_DirectoryOpen(&dirh, NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_DirectoryOpen(&dirh, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ - if (OS_DirectoryOpen(&dirh, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_DirectoryOpen(&dirh, g_longPathName), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-path-arg"; + /* #3 Invalid-path-arg */ - if (OS_DirectoryOpen(&dirh, "/drive0/tmpDir") != OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_DirectoryOpen(&dirh, "/drive0/tmpDir"), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ memset(g_dirName, '\0', sizeof(g_dirName)); UT_os_sprintf(g_dirName, "%s/opendir_Nominal", g_mntName); - if (OS_mkdir(g_dirName, 755) != OS_SUCCESS) + if (UT_SETUP(OS_mkdir(g_dirName, OS_READ_WRITE))) { - testDesc = "#5 Nominal - Dir-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_opendir_test_exit_tag; - } + UT_NOMINAL(OS_DirectoryOpen(&dirh, g_dirName)); - if (OS_DirectoryOpen(&dirh, g_dirName) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_DirectoryClose(dirh); - OS_rmdir(g_dirName); - -UT_os_opendir_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_DirectoryClose(dirh)); + UT_TEARDOWN(OS_rmdir(g_dirName)); + } } /*--------------------------------------------------------------------------------* @@ -339,59 +269,25 @@ void UT_os_opendir_test() **--------------------------------------------------------------------------------*/ void UT_os_closedir_test() { - osal_id_t dirh; - os_dirent_t *dirEntry = NULL; - const char * testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_DirectoryClose(OS_OBJECT_ID_UNDEFINED) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_closedir_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + osal_id_t dirh; + os_dirent_t dirEntry; /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ memset(g_dirName, '\0', sizeof(g_dirName)); UT_os_sprintf(g_dirName, "%s/closeDir3", g_mntName); - if (OS_mkdir(g_dirName, 755) != OS_SUCCESS) - { - testDesc = "#2 Nominal - Dir-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_closedir_test_exit_tag; - } - - if (OS_DirectoryOpen(&dirh, g_dirName) != OS_SUCCESS) - { - testDesc = "#2 Nominal - Dir-open failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_closedir_test_exit_tag; - } - - if (OS_DirectoryClose(dirh) != OS_SUCCESS) + if (UT_SETUP(OS_mkdir(g_dirName, OS_READ_WRITE))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_closedir_test_exit_tag; + if (UT_SETUP(OS_DirectoryOpen(&dirh, g_dirName))) + { + UT_NOMINAL(OS_DirectoryClose(dirh)); + UT_RETVAL(OS_DirectoryRead(dirh, &dirEntry), OS_ERR_INVALID_ID); + } + + /* Reset test environment */ + UT_TEARDOWN(OS_rmdir(g_dirName)); } - - if (OS_DirectoryRead(dirh, dirEntry) != OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_rmdir(g_dirName); - -UT_os_closedir_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -439,89 +335,50 @@ void UT_os_closedir_test() **--------------------------------------------------------------------------------*/ void UT_os_readdir_test() { - osal_id_t dirh = OS_OBJECT_ID_UNDEFINED; - const char *testDesc; + osal_id_t dirh = OS_OBJECT_ID_UNDEFINED; strcpy(g_subdirNames[0], " "); strcpy(g_subdirNames[1], " "); /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_DirectoryRead(OS_OBJECT_ID_UNDEFINED, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_readdir_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_DirectoryRead(OS_OBJECT_ID_UNDEFINED, NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_DirectoryRead(OS_OBJECT_ID_UNDEFINED, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ memset(g_dirName, '\0', sizeof(g_dirName)); UT_os_sprintf(g_dirName, "%s/readdir_Nominal", g_mntName); - if (OS_mkdir(g_dirName, 755) != OS_SUCCESS) - { - testDesc = "#3 Nominal - Dir-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_readdir_test_exit_tag; - } - - memset(g_subdirNames[0], '\0', sizeof(g_subdirNames[0])); - UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]); - if (OS_mkdir(g_subdirNames[0], 755) != OS_SUCCESS) - { - testDesc = "#3 Nominal - Dir-create(subdir1) failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_readdir_test_exit_tag; - } - - memset(g_subdirNames[1], '\0', sizeof(g_subdirNames[1])); - UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]); - if (OS_mkdir(g_subdirNames[1], 755) != OS_SUCCESS) - { - testDesc = "#3 Nominal - Dir-create(subdir2) failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_readdir_test_exit_tag; - } - - if (OS_DirectoryOpen(&dirh, g_dirName) != OS_SUCCESS) + if (UT_SETUP(OS_mkdir(g_dirName, OS_READ_WRITE))) { - testDesc = "#3 Nominal - Dir-open failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_readdir_test_exit_tag; + memset(g_subdirNames[0], '\0', sizeof(g_subdirNames[0])); + UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]); + if (UT_SETUP(OS_mkdir(g_subdirNames[0], OS_READ_WRITE))) + { + memset(g_subdirNames[1], '\0', sizeof(g_subdirNames[1])); + UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]); + if (UT_SETUP(OS_mkdir(g_subdirNames[1], OS_READ_WRITE))) + { + if (UT_SETUP(OS_DirectoryOpen(&dirh, g_dirName))) + { + UT_os_read_n_sort_dirs(dirh); + + UtAssert_StrCmp(g_dirItems[2], g_tgtSubdirs[0], "%s == %s", g_dirItems[2], g_tgtSubdirs[0]); + UtAssert_StrCmp(g_dirItems[3], g_tgtSubdirs[1], "%s == %s", g_dirItems[3], g_tgtSubdirs[1]); + + /* Reset test environment */ + UT_TEARDOWN(OS_DirectoryClose(dirh)); + } + + UT_TEARDOWN(OS_rmdir(g_subdirNames[1])); + } + + UT_TEARDOWN(OS_rmdir(g_subdirNames[0])); + } + + UT_TEARDOWN(OS_rmdir(g_dirName)); } - - UT_os_read_n_sort_dirs(dirh); - - if ((strcmp(g_dirItems[2], g_tgtSubdirs[0]) == 0) && (strcmp(g_dirItems[3], g_tgtSubdirs[1]) == 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_readdir_test_exit_tag: - /* Reset test environment */ - OS_DirectoryClose(dirh); - OS_rmdir(g_subdirNames[0]); - OS_rmdir(g_subdirNames[1]); - OS_rmdir(g_dirName); - - return; } /*--------------------------------------------------------------------------------* @@ -566,94 +423,50 @@ void UT_os_readdir_test() **--------------------------------------------------------------------------------*/ void UT_os_rewinddir_test() { - osal_id_t dirh = OS_OBJECT_ID_UNDEFINED; - const char *testDesc; + osal_id_t dirh = OS_OBJECT_ID_UNDEFINED; strcpy(g_subdirNames[0], " "); strcpy(g_subdirNames[1], " "); /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; - - if (OS_DirectoryRewind(OS_OBJECT_ID_UNDEFINED) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_rewinddir_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ memset(g_dirName, '\0', sizeof(g_dirName)); UT_os_sprintf(g_dirName, "%s/rewinddir_Nominal", g_mntName); - if (OS_mkdir(g_dirName, 755) != OS_SUCCESS) - { - testDesc = "#2 Nominal - Dir-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_rewinddir_test_exit_tag; - } - - memset(g_subdirNames[0], '\0', sizeof(g_subdirNames[0])); - UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]); - if (OS_mkdir(g_subdirNames[0], 755) != OS_SUCCESS) - { - testDesc = "#2 Nominal - Dir-create(subdir1) failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_rewinddir_test_exit_tag; - } - - memset(g_subdirNames[1], '\0', sizeof(g_subdirNames[1])); - UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]); - if (OS_mkdir(g_subdirNames[1], 755) != OS_SUCCESS) + if (UT_SETUP(OS_mkdir(g_dirName, OS_READ_WRITE))) { - testDesc = "#2 Nominal - Dir-create(subdir2) failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_rewinddir_test_exit_tag; - } - - if (OS_DirectoryOpen(&dirh, g_dirName) != OS_SUCCESS) - { - testDesc = "#2 Nominal - Dir-open failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_rewinddir_test_exit_tag; + memset(g_subdirNames[0], '\0', sizeof(g_subdirNames[0])); + UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]); + if (UT_SETUP(OS_mkdir(g_subdirNames[0], OS_READ_WRITE))) + { + memset(g_subdirNames[1], '\0', sizeof(g_subdirNames[1])); + UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]); + if (UT_SETUP(OS_mkdir(g_subdirNames[1], OS_READ_WRITE))) + { + if (UT_SETUP(OS_DirectoryOpen(&dirh, g_dirName))) + { + UT_os_read_n_sort_dirs(dirh); + UtAssert_StrCmp(g_dirItems[2], g_tgtSubdirs[0], "%s == %s", g_dirItems[2], g_tgtSubdirs[0]); + UtAssert_StrCmp(g_dirItems[3], g_tgtSubdirs[1], "%s == %s", g_dirItems[3], g_tgtSubdirs[1]); + + UT_NOMINAL(OS_DirectoryRewind(dirh)); + + UT_os_read_n_sort_dirs(dirh); + UtAssert_StrCmp(g_dirItems[2], g_tgtSubdirs[0], "%s == %s", g_dirItems[2], g_tgtSubdirs[0]); + UtAssert_StrCmp(g_dirItems[3], g_tgtSubdirs[1], "%s == %s", g_dirItems[3], g_tgtSubdirs[1]); + + /* Reset test environment */ + UT_TEARDOWN(OS_DirectoryClose(dirh)); + } + + UT_TEARDOWN(OS_rmdir(g_subdirNames[1])); + } + + UT_TEARDOWN(OS_rmdir(g_subdirNames[0])); + } + + UT_TEARDOWN(OS_rmdir(g_dirName)); } - - UT_os_read_n_sort_dirs(dirh); - - if ((strcmp(g_dirItems[2], g_tgtSubdirs[0]) != 0) || (strcmp(g_dirItems[3], g_tgtSubdirs[1]) != 0)) - { - testDesc = "#2 Nominal - Dir-read failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - goto UT_os_rewinddir_test_exit_tag; - } - - OS_DirectoryRewind(dirh); - - UT_os_read_n_sort_dirs(dirh); - - if ((strcmp(g_dirItems[2], g_tgtSubdirs[0]) != 0) || (strcmp(g_dirItems[3], g_tgtSubdirs[1]) != 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - -UT_os_rewinddir_test_exit_tag: - /* Reset test environment */ - OS_DirectoryClose(dirh); - OS_rmdir(g_subdirNames[0]); - OS_rmdir(g_subdirNames[1]); - OS_rmdir(g_dirName); - - return; } /*--------------------------------------------------------------------------------* @@ -711,94 +524,53 @@ void UT_os_rewinddir_test() **--------------------------------------------------------------------------------*/ void UT_os_removedir_test() { - int32 status; - osal_id_t fileDesc; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_rmdir(NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_removedir_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_rmdir(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + osal_id_t fileDesc; /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #1 Null-pointer-arg */ - if (OS_rmdir(g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rmdir(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-path-arg"; + /* #2 Path-too-long-arg */ - if (OS_rmdir("tmpDir") == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rmdir(g_longPathName), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 OS-call-failure"; + /* #3 Invalid-path-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_rmdir("tmpDir"), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ memset(g_dirName, '\0', sizeof(g_dirName)); UT_os_sprintf(g_dirName, "%s/rmdir_Nominal", g_mntName); - if (OS_mkdir(g_dirName, 755) != OS_SUCCESS) - { - testDesc = "#5 Nominal - Dir-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_removedir_test_exit_tag; - } - - memset(g_fileName, '\0', sizeof(g_fileName)); - UT_os_sprintf(g_fileName, "%s/rmdir_File1.txt", g_dirName); - status = OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (status < 0) + if (UT_SETUP(OS_mkdir(g_dirName, OS_READ_WRITE))) { - testDesc = "#5 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + memset(g_fileName, '\0', sizeof(g_fileName)); + UT_os_sprintf(g_fileName, "%s/rmdir_File1.txt", g_dirName); + if (UT_SETUP(OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) + { + UT_RETVAL(OS_rmdir(g_dirName), OS_ERROR); + + /* Must close and remove all files before the directory can be removed */ + UT_TEARDOWN(OS_close(fileDesc)); + UT_TEARDOWN(OS_remove(g_fileName)); + + UT_NOMINAL(OS_rmdir(g_dirName)); + + memset(g_fileName, '\0', sizeof(g_fileName)); + UT_os_sprintf(g_fileName, "%s/rmdir_File2.txt", g_dirName); + UT_RETVAL(OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE), + OS_ERROR); + } } - - /* Must close and remove all files before the directory can be removed */ - OS_close(fileDesc); - OS_remove(g_fileName); - - if (OS_rmdir(g_dirName) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_removedir_test_exit_tag; - } - - memset(g_fileName, '\0', sizeof(g_fileName)); - UT_os_sprintf(g_fileName, "%s/rmdir_File2.txt", g_dirName); - status = OS_OpenCreate(&fileDesc, g_fileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (status < 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_removedir_test_exit_tag: - return; } -/*--------------------------------------------------------------------------------* +/*-------------------------------------------------------------------------------- * Internal helper function - **--------------------------------------------------------------------------------*/ + *--------------------------------------------------------------------------------*/ void UT_os_read_n_sort_dirs(osal_id_t dirh) { int i = 0; diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index 149184c96..0a0e51a4a 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -105,34 +105,7 @@ char g_writeBuff[UT_OS_IO_BUFF_SIZE]; *--------------------------------------------------------------------------------*/ void UT_os_initfs_test() { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "#1 Init-not-call-first - Test case not applicable on platform"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - - /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; - - /* Call to OS_FS_Init is inside OS_API_Init */ - res = OS_API_Init(); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - testDesc = "API not implemented"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - } - else if (res == OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - - return; + UT_NOMINAL(OS_API_Init()); } /*--------------------------------------------------------------------------------* @@ -196,117 +169,80 @@ void UT_os_initfs_test() **--------------------------------------------------------------------------------*/ void UT_os_createfile_test() { - const char *testDesc; - int32 res = 0, i = 0, j = 0; - osal_id_t fd; + int32 i = 0, j = 0; + osal_id_t fd; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg */ - if (OS_OpenCreate(NULL, NULL, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_createfile_test_exit_tag; - } + UT_RETVAL(OS_OpenCreate(NULL, "file", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE), + OS_INVALID_POINTER); + UT_RETVAL(OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #2 Invalid-path-arg */ - if (OS_OpenCreate(NULL, "file", OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - if (OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, g_invalidPath, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE), + OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; + /* #3 Path-too-long-arg */ - if (OS_OpenCreate(&fd, g_invalidPath, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == - OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, g_longPathName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE), + OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #4 Name-too-long-arg */ - if (OS_OpenCreate(&fd, g_longPathName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == - OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, g_longFileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE), + OS_FS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long-arg"; - - if (OS_OpenCreate(&fd, g_longFileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE) == - OS_FS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#5 Invalid-permission-arg"; + /* #5 Invalid-permission-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Create_InvPerm.txt", g_mntName); - res = OS_OpenCreate(&fd, g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, 123); - if (res == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[0]); + UT_RETVAL(OS_OpenCreate(&fd, g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, 123), OS_ERROR); /*-----------------------------------------------------*/ - testDesc = "#6 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#7 File-descriptors-full"; + /* #7 File-descriptors-full */ for (i = 0; i <= OS_MAX_NUM_OPEN_FILES; i++) { memset(g_fNames[i], '\0', sizeof(g_fNames[i])); UT_os_sprintf(g_fNames[i], "%s/tmpFile%d.txt", g_mntName, (int)i); - g_fStatus[i] = - OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - if (g_fStatus[i] < 0) + if (i == OS_MAX_NUM_OPEN_FILES) + { + UT_RETVAL( + OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY), + OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, + OS_WRITE_ONLY))) + { break; + } } - if ((i == OS_MAX_NUM_OPEN_FILES) && (g_fStatus[i] == OS_ERR_NO_FREE_IDS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /* Reset test environment */ - for (j = 0; j < i; j++) + for (j = 0; j < i && j < OS_MAX_NUM_OPEN_FILES; j++) { - OS_close(g_fDescs[j]); - OS_remove(g_fNames[j]); + UT_TEARDOWN(OS_close(g_fDescs[j])); + UT_TEARDOWN(OS_remove(g_fNames[j])); } /*-----------------------------------------------------*/ - testDesc = "#8 Nominal"; + /* #8 Nominal */ - g_fStatus[5] = OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - g_fStatus[6] = OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); + UT_NOMINAL(OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY)); + UT_NOMINAL(OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY)); - if ((OS_close(g_fDescs[5]) != OS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_SUCCESS) || - (OS_remove(g_fNames[5]) != OS_SUCCESS) || (OS_remove(g_fNames[6]) != OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + /* Reset test environment */ + UT_TEARDOWN(OS_close(g_fDescs[5])); + UT_TEARDOWN(OS_close(g_fDescs[6])); -UT_os_createfile_test_exit_tag: - return; + UT_TEARDOWN(OS_remove(g_fNames[5])); + UT_TEARDOWN(OS_remove(g_fNames[6])); } /*--------------------------------------------------------------------------------* @@ -370,154 +306,107 @@ void UT_os_createfile_test() **--------------------------------------------------------------------------------*/ void UT_os_openfile_test() { - const char *testDesc; - int32 res = 0, i = 0, j = 0, continueFlg = 0; - osal_id_t fd; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_NONE, OS_READ_WRITE) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_openfile_test_exit_tag; - } + int32 i = 0, j = 0; + osal_id_t fd; /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_NONE, OS_READ_WRITE) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #1 Null-pointer-arg */ - if (OS_OpenCreate(NULL, "file", OS_FILE_FLAG_NONE, OS_READ_WRITE) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, NULL, OS_FILE_FLAG_NONE, OS_READ_WRITE), OS_INVALID_POINTER); + UT_RETVAL(OS_OpenCreate(NULL, "file", OS_FILE_FLAG_NONE, OS_READ_WRITE), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; + /* #2 Invalid-path-arg */ - if (OS_OpenCreate(&fd, g_invalidPath, OS_FILE_FLAG_NONE, OS_READ_WRITE) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, g_invalidPath, OS_FILE_FLAG_NONE, OS_READ_WRITE), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #3 Path-too-long-arg */ - if (OS_OpenCreate(&fd, g_longPathName, OS_FILE_FLAG_NONE, OS_READ_WRITE) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, g_longPathName, OS_FILE_FLAG_NONE, OS_READ_WRITE), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long-arg"; + /* #4 Name-too-long-arg */ - if (OS_OpenCreate(&fd, g_longFileName, OS_FILE_FLAG_NONE, OS_READ_WRITE) == OS_FS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_OpenCreate(&fd, g_longFileName, OS_FILE_FLAG_NONE, OS_READ_WRITE), OS_FS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#5 Invalid-permission-arg"; + /* #5 Invalid-permission-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Open_InvPerm.txt", g_mntName); - res = OS_OpenCreate(&fd, g_fNames[0], OS_FILE_FLAG_NONE, 123); - if (res == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[0]); + UT_RETVAL(OS_OpenCreate(&fd, g_fNames[0], OS_FILE_FLAG_NONE, 123), OS_ERROR); /*-----------------------------------------------------*/ - testDesc = "#6 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #7 File-descriptors-full */ - /*-----------------------------------------------------*/ - testDesc = "#7 File-descriptors-full"; - - continueFlg = 1; + /* This first needs to create all the files */ for (i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) { memset(g_fNames[i], '\0', sizeof(g_fNames[i])); UT_os_sprintf(g_fNames[i], "%s/tmpFile%d.txt", g_mntName, (int)i); - g_fStatus[i] = - OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - if (g_fStatus[i] < OS_SUCCESS) + if (!UT_SETUP( + OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY))) { - testDesc = "#7 File-descriptors-full - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - continueFlg = 0; break; } - if (continueFlg && (OS_close(g_fDescs[i]) != OS_SUCCESS)) + if (!UT_SETUP(OS_close(g_fDescs[i]) != OS_SUCCESS)) { - testDesc = "#7 File-descriptors-full - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - continueFlg = 0; break; } } - if (continueFlg) + if (i < OS_MAX_NUM_OPEN_FILES) + { + /* setup failure, stop test now (already reported) */ + return; + } + + for (i = 0; i <= OS_MAX_NUM_OPEN_FILES; i++) { - for (i = 0; i <= OS_MAX_NUM_OPEN_FILES; i++) + if (i == OS_MAX_NUM_OPEN_FILES) { - g_fStatus[i] = OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_NONE, OS_WRITE_ONLY); - if (g_fStatus[i] < 0) - break; + UT_RETVAL(OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_NONE, OS_WRITE_ONLY), OS_ERR_NO_FREE_IDS); } - - if ((i == OS_MAX_NUM_OPEN_FILES) && (g_fStatus[i] < OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - for (j = 0; j < i; j++) + else if (!UT_SETUP(OS_OpenCreate(&g_fDescs[i], g_fNames[i], OS_FILE_FLAG_NONE, OS_WRITE_ONLY))) { - OS_close(g_fDescs[j]); - OS_remove(g_fNames[j]); + break; } } - /*-----------------------------------------------------*/ - testDesc = "#8 Nominal"; - - g_fStatus[5] = OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - g_fStatus[6] = OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - if ((g_fStatus[5] < OS_SUCCESS) || (g_fStatus[6] < OS_SUCCESS)) + /* Reset test environment */ + for (j = 0; j < i && j < OS_MAX_NUM_OPEN_FILES; j++) { - testDesc = "#8 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_openfile_test_exit_tag; + UT_TEARDOWN(OS_close(g_fDescs[j])); + UT_TEARDOWN(OS_remove(g_fNames[j])); } - if ((OS_close(g_fDescs[5]) != OS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_SUCCESS)) + /*-----------------------------------------------------*/ + /* #8 Nominal */ + + if (UT_SETUP(OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#8 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_openfile_test_exit_tag; - } + UT_SETUP(OS_close(g_fDescs[5])); + + if (UT_SETUP( + OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY))) + { + UT_SETUP(OS_close(g_fDescs[6])); - g_fStatus[5] = OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_NONE, OS_READ_WRITE); - g_fStatus[6] = OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_NONE, OS_WRITE_ONLY); + UT_NOMINAL( + OS_OpenCreate(&g_fDescs[5], g_fNames[5], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE)); + UT_NOMINAL( + OS_OpenCreate(&g_fDescs[6], g_fNames[6], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY)); - if ((OS_close(g_fDescs[5]) != OS_SUCCESS) || (OS_close(g_fDescs[6]) != OS_SUCCESS) || - (OS_remove(g_fNames[5]) != OS_SUCCESS) || (OS_remove(g_fNames[6]) != OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + UT_TEARDOWN(OS_close(g_fDescs[5])); + UT_TEARDOWN(OS_close(g_fDescs[6])); -UT_os_openfile_test_exit_tag: - return; + UT_TEARDOWN(OS_remove(g_fNames[6])); + } + + UT_TEARDOWN(OS_remove(g_fNames[5])); + } } /*--------------------------------------------------------------------------------* @@ -560,57 +449,29 @@ void UT_os_openfile_test() **--------------------------------------------------------------------------------*/ void UT_os_closefile_test() { - const char *testDesc; - char tmpBuff[UT_OS_IO_BUFF_SIZE]; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_close(UT_OBJID_INCORRECT) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_closefile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-file-desc-arg"; - - if (OS_close(UT_OBJID_INCORRECT) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + char tmpBuff[UT_OS_IO_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; + /* #1 Invalid-file-desc-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_close(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Close_Nominal.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#3 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_closefile_test_exit_tag; - } - - if ((OS_close(g_fDescs[0]) != OS_SUCCESS) || - (OS_write(g_fDescs[0], tmpBuff, sizeof(tmpBuff)) != OS_ERR_INVALID_ID) || - (OS_read(g_fDescs[0], tmpBuff, sizeof(tmpBuff)) != OS_ERR_INVALID_ID)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + UT_NOMINAL(OS_close(g_fDescs[0])); - /* Reset test environment */ - OS_remove(g_fNames[0]); + UT_RETVAL(OS_write(g_fDescs[0], tmpBuff, sizeof(tmpBuff)), OS_ERR_INVALID_ID); + UT_RETVAL(OS_read(g_fDescs[0], tmpBuff, sizeof(tmpBuff)), OS_ERR_INVALID_ID); -UT_os_closefile_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_remove(g_fNames[0])); + } } /*--------------------------------------------------------------------------------* @@ -668,122 +529,53 @@ void UT_os_closefile_test() **--------------------------------------------------------------------------------*/ void UT_os_readfile_test() { - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_read(UT_OBJID_INCORRECT, NULL, 0) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_readfile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + size_t expected_len; memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Read_NullPtr.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#1 Null-pointer-arg - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - if (OS_read(g_fDescs[0], NULL, sizeof(g_readBuff)) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /*-----------------------------------------------------*/ + /* #1 Null-pointer-arg */ + UT_RETVAL(OS_read(g_fDescs[0], NULL, sizeof(g_readBuff)), OS_INVALID_POINTER); /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); } /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-file-desc-arg"; - - if (OS_read(UT_OBJID_INCORRECT, g_readBuff, sizeof(g_readBuff)) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #2 Invalid-file-desc-arg */ + UT_RETVAL(OS_read(UT_OBJID_INCORRECT, g_readBuff, sizeof(g_readBuff)), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Read_Nominal.txt", g_mntName); - - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#4 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_readfile_test_exit_tag; - } - - memset(g_writeBuff, '\0', sizeof(g_writeBuff)); - strcpy(g_writeBuff, "A HORSE! A HORSE! MY KINGDOM FOR A HORSE!"); - if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#4 Nominal - File-write failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "A HORSE! A HORSE! MY KINGDOM FOR A HORSE!"); + expected_len = strlen(g_writeBuff); - goto UT_os_readfile_test_exit_tag; - } - - if (OS_close(g_fDescs[0]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_RETVAL(OS_write(g_fDescs[0], g_writeBuff, expected_len), expected_len); - /* Reset test environment */ - OS_remove(g_fNames[0]); + UT_SETUP(OS_close(g_fDescs[0])); - goto UT_os_readfile_test_exit_tag; - } + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_NONE, OS_READ_WRITE))) + { + memset(g_readBuff, '\0', sizeof(g_readBuff)); + UT_RETVAL(OS_read(g_fDescs[0], g_readBuff, sizeof(g_readBuff)), expected_len); + UtAssert_StrCmp(g_readBuff, g_writeBuff, "%s == %s", g_readBuff, g_writeBuff); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_NONE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#4 Nominal - File-open failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_TEARDOWN(OS_close(g_fDescs[0])); + } /* Reset test environment */ - OS_remove(g_fNames[0]); - - goto UT_os_readfile_test_exit_tag; + UT_TEARDOWN(OS_remove(g_fNames[0])); } - - memset(g_readBuff, '\0', sizeof(g_readBuff)); - if ((OS_read(g_fDescs[0], g_readBuff, strlen(g_writeBuff)) == strlen(g_writeBuff)) && - (strncmp(g_readBuff, g_writeBuff, strlen(g_writeBuff)) == 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); - - UtPrintf("OS_read() success test -- Write to file:\n\t%s\n", g_writeBuff); - ; - UtPrintf("OS_read() success test -- Read from file:\n\t%s\n", g_readBuff); - ; - -UT_os_readfile_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -840,121 +632,52 @@ void UT_os_readfile_test() **--------------------------------------------------------------------------------*/ void UT_os_writefile_test() { - const char *testDesc; + size_t expected_len; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_write(UT_OBJID_INCORRECT, NULL, 0) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_writefile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Write_NullPtr.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#1 Null-pointer-arg - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - if (OS_write(g_fDescs[0], NULL, sizeof(g_writeBuff)) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_write(g_fDescs[0], NULL, sizeof(g_writeBuff)), OS_INVALID_POINTER); /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); } /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-file-desc-arg"; - - if (OS_write(UT_OBJID_INCORRECT, g_writeBuff, sizeof(g_writeBuff)) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; + /* #2 Invalid-file-desc-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_write(UT_OBJID_INCORRECT, g_writeBuff, sizeof(g_writeBuff)), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Write_Nominal.txt", g_mntName); - - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < OS_SUCCESS) - { - testDesc = "#4 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_writefile_test_exit_tag; - } - - memset(g_writeBuff, '\0', sizeof(g_writeBuff)); - strcpy(g_writeBuff, "TO BE OR NOT TO BE, THAT IS A QUESTION."); - if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); - - goto UT_os_writefile_test_exit_tag; - } - - if (OS_close(g_fDescs[0]) != OS_SUCCESS) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY))) { - testDesc = "#4 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "TO BE OR NOT TO BE, THAT IS A QUESTION."); + expected_len = strlen(g_writeBuff); + UT_RETVAL(OS_write(g_fDescs[0], g_writeBuff, expected_len), expected_len); - /* Reset test environment */ - OS_remove(g_fNames[0]); - - goto UT_os_writefile_test_exit_tag; - } + UT_SETUP(OS_close(g_fDescs[0])); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_NONE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#4 Nominal - File-open failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - - /* Reset test environment */ - OS_remove(g_fNames[0]); + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_NONE, OS_READ_ONLY))) + { + memset(g_readBuff, '\0', sizeof(g_readBuff)); + UT_RETVAL(OS_read(g_fDescs[0], g_readBuff, sizeof(g_readBuff)), expected_len); + UtAssert_StrCmp(g_readBuff, g_writeBuff, "%s == %s", g_readBuff, g_writeBuff); - goto UT_os_writefile_test_exit_tag; + /* Reset test environment */ + UT_TEARDOWN(OS_close(g_fDescs[0])); + } + UT_TEARDOWN(OS_remove(g_fNames[0])); } - - memset(g_readBuff, '\0', sizeof(g_readBuff)); - if ((OS_read(g_fDescs[0], g_readBuff, strlen(g_writeBuff)) == strlen(g_writeBuff)) && - (strncmp(g_readBuff, g_writeBuff, strlen(g_writeBuff)) == 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); - - UtPrintf("OS_write() success test -- Write to file:\n\t%s\n", g_writeBuff); - ; - UtPrintf("OS_write() success test -- Read from file:\n\t%s\n", g_readBuff); - ; - -UT_os_writefile_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -1009,96 +732,51 @@ void UT_os_writefile_test() **--------------------------------------------------------------------------------*/ void UT_os_lseekfile_test() { - const char *testDesc; - size_t buffLen; - int32 pos1 = 0, pos2 = 0, pos3 = 0; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_lseek(UT_OBJID_INCORRECT, 0, OS_SEEK_CUR) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_lseekfile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-file-desc-arg"; + size_t buffLen; + int32 pos1 = 0, pos2 = 0, pos3 = 0; - if (OS_lseek(UT_OBJID_INCORRECT, 0, OS_SEEK_SET) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_lseek(UT_OBJID_INCORRECT, 0, OS_SEEK_SET), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-whence-arg"; + /* #2 Invalid-whence-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Seek_InvWhence.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#2 Invalid-whence-arg - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - if (OS_lseek(g_fDescs[0], 0, 123456) == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_lseek(g_fDescs[0], 0, 123456), OS_ERROR); - OS_close(g_fDescs[0]); + /* Reset test environment */ + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); } - /* Reset test environment */ - OS_remove(g_fNames[0]); - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Seek_Nominal.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#4 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_lseekfile_test_exit_tag; - } + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "THE BROWN FOX JUMPS OVER THE LAZY DOG."); + buffLen = strlen(g_writeBuff); - memset(g_writeBuff, '\0', sizeof(g_writeBuff)); - strcpy(g_writeBuff, "THE BROWN FOX JUMPS OVER THE LAZY DOG."); - buffLen = strlen(g_writeBuff); + UT_RETVAL(OS_write(g_fDescs[0], g_writeBuff, buffLen), buffLen); - if (OS_write(g_fDescs[0], g_writeBuff, buffLen) != buffLen) - { - testDesc = "#4 Nominal - File-write failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_lseekfile_test_exit_tag; - } + UT_RETVAL(pos1 = OS_lseek(g_fDescs[0], 10, OS_SEEK_SET), 10); + UT_RETVAL(pos2 = OS_lseek(g_fDescs[0], 7, OS_SEEK_CUR), 17); + UT_RETVAL(pos3 = OS_lseek(g_fDescs[0], -16, OS_SEEK_END), 22); - pos1 = OS_lseek(g_fDescs[0], 10, OS_SEEK_SET); - pos2 = OS_lseek(g_fDescs[0], 7, OS_SEEK_CUR); - pos3 = OS_lseek(g_fDescs[0], -16, OS_SEEK_END); - if ((pos1 < 0) || (g_writeBuff[pos1] != 'F') || (pos2 < 0) || (g_writeBuff[pos2] != 'P') || (pos3 < 0) || - (g_writeBuff[pos3] != 'E')) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); + UtAssert_INT32_EQ(g_writeBuff[pos1], 'F'); + UtAssert_INT32_EQ(g_writeBuff[pos2], 'P'); + UtAssert_INT32_EQ(g_writeBuff[pos3], 'E'); - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); - -UT_os_lseekfile_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); + } } /*--------------------------------------------------------------------------------* @@ -1111,19 +789,12 @@ void UT_os_lseekfile_test() **--------------------------------------------------------------------------------*/ void UT_os_chmodfile_test() { - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_chmod(NULL, 0644) == OS_ERR_NOT_IMPLEMENTED) + /* API not implemented */ + if (!UT_IMPL(OS_chmod(NULL, 0644))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_chmodfile_test_exit_tag; + return; } - -UT_os_chmodfile_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -1184,99 +855,55 @@ void UT_os_chmodfile_test() **--------------------------------------------------------------------------------*/ void UT_os_statfile_test() { - const char *testDesc; - os_fstat_t fstats1, fstats2; + os_fstat_t fstats1, fstats2; + size_t expected_len; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - if (OS_stat(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_stat(NULL, NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_statfile_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if ((OS_stat(NULL, &fstats1) == OS_INVALID_POINTER) && (OS_stat(g_fNames[0], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; - - if (OS_stat(g_invalidPath, &fstats1) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #1 Null-pointer-arg */ + UT_RETVAL(OS_stat(NULL, &fstats1), OS_INVALID_POINTER); + UT_RETVAL(OS_stat(g_fNames[0], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #2 Invalid-path-arg */ - if (OS_stat(g_longPathName, &fstats1) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_stat(g_invalidPath, &fstats1), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 OS-call-failure"; + /* #3 Path-too-long-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_stat(g_longPathName, &fstats1), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; + /* #5 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Stat_Nominal.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#5 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_statfile_test_exit_tag; - } + UT_NOMINAL(OS_stat(g_fNames[0], &fstats1)); + UtAssert_UINT32_EQ(fstats1.FileSize, 0); - if (OS_stat(g_fNames[0], &fstats1) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_statfile_test_exit_tag; - } + memset(g_writeBuff, '\0', sizeof(g_writeBuff)); + strcpy(g_writeBuff, "HOW NOW, BROWN COW?"); + expected_len = strlen(g_writeBuff); + UT_RETVAL(OS_write(g_fDescs[0], g_writeBuff, expected_len), expected_len); + UT_SETUP(OS_close(g_fDescs[0])); - memset(g_writeBuff, '\0', sizeof(g_writeBuff)); - strcpy(g_writeBuff, "HOW NOW, BROWN COW?"); - if (OS_write(g_fDescs[0], g_writeBuff, strlen(g_writeBuff)) != strlen(g_writeBuff)) - { - testDesc = "#5 Nominal - File-write failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_statfile_test_exit_tag; - } + UT_NOMINAL(OS_stat(g_fNames[0], &fstats2)); + UtAssert_UINT32_EQ(fstats1.FileSize, 0); - if (OS_close(g_fDescs[0]) != OS_SUCCESS) - { - testDesc = "#5 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_statfile_test_exit_tag; - } - - if (OS_stat(g_fNames[0], &fstats2) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_statfile_test_exit_tag; + /* Reset test environment */ + UT_TEARDOWN(OS_remove(g_fNames[0])); } - - if (memcmp(&fstats1, &fstats2, sizeof(fstats1)) != 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[0]); - -UT_os_statfile_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -1335,84 +962,42 @@ void UT_os_statfile_test() **--------------------------------------------------------------------------------*/ void UT_os_removefile_test() { - os_fstat_t fstats; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_remove(NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_removefile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_remove(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + os_fstat_t fstats; /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; + /* #1 Null-pointer-arg */ - if (OS_remove(g_invalidPath) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_remove(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #2 Invalid-path-arg */ - if (OS_remove(g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_remove(g_invalidPath), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long-arg"; + /* #3 Path-too-long-arg */ - if (OS_remove(g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_remove(g_longPathName), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#5 OS-call-failure"; + /* #4 Name-too-long-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_remove(g_longFileName), OS_FS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#6 Nominal"; + /* #6 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Remove_Nominal.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#6 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_removefile_test_exit_tag; - } + UT_SETUP(OS_close(g_fDescs[0])); - OS_close(g_fDescs[0]); - - if (OS_remove(g_fNames[0]) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_removefile_test_exit_tag; + UT_NOMINAL(OS_remove(g_fNames[0])); } - if (OS_stat(g_fNames[0], &fstats) == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_removefile_test_exit_tag: - return; + UT_RETVAL(OS_stat(g_fNames[0], &fstats), OS_ERROR); } /*--------------------------------------------------------------------------------* @@ -1471,93 +1056,53 @@ void UT_os_removefile_test() **--------------------------------------------------------------------------------*/ void UT_os_renamefile_test() { - os_fstat_t fstats; - const char *testDesc; + os_fstat_t fstats; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_rename(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_renamefile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[1], '\0', sizeof(g_fNames[1])); UT_os_sprintf(g_fNames[0], "%s/oldName.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/newName.txt", g_mntName); - if ((OS_rename(NULL, g_fNames[1]) == OS_INVALID_POINTER) && (OS_rename(g_fNames[0], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; - - if (OS_rename(g_invalidPath, g_invalidPath) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rename(NULL, g_fNames[1]), OS_INVALID_POINTER); + UT_RETVAL(OS_rename(g_fNames[0], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #2 Invalid-path-arg */ - if (OS_rename(g_longPathName, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rename(g_invalidPath, g_invalidPath), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long-arg"; + /* #3 Path-too-long-arg */ - if (OS_rename(g_longFileName, g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rename(g_longPathName, g_longPathName), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#5 OS-call-failure"; + /* #4 Name-too-long-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_rename(g_longFileName, g_longFileName), OS_FS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#6 Nominal"; + /* #6 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[0], '\0', sizeof(g_fNames[1])); UT_os_sprintf(g_fNames[0], "%s/Rename_Nom_Old.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/Rename_Nom_New.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#6 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_renamefile_test_exit_tag; - } - - if (OS_rename(g_fNames[0], g_fNames[1]) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_renamefile_test_exit_tag; - } - - if (OS_stat(g_fNames[0], &fstats) == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_SETUP(OS_close(g_fDescs[0])); + UT_NOMINAL(OS_rename(g_fNames[0], g_fNames[1])); - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[1]); + UT_RETVAL(OS_stat(g_fNames[0], &fstats), OS_ERROR); + UT_RETVAL(OS_stat(g_fNames[1], &fstats), OS_SUCCESS); -UT_os_renamefile_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_remove(g_fNames[1])); + } } /*--------------------------------------------------------------------------------* @@ -1620,107 +1165,61 @@ void UT_os_renamefile_test() **--------------------------------------------------------------------------------*/ void UT_os_copyfile_test() { - os_fstat_t fstats; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_cp(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_copyfile_test_exit_tag; - } + os_fstat_t fstats; /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[1], '\0', sizeof(g_fNames[1])); UT_os_sprintf(g_fNames[0], "%s/oldName.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/newName.txt", g_mntName); - if ((OS_cp(NULL, g_fNames[1]) == OS_INVALID_POINTER) && (OS_cp(g_fNames[0], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; - - if (OS_cp(g_invalidPath, g_invalidPath) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_cp(NULL, g_fNames[1]), OS_INVALID_POINTER); + UT_RETVAL(OS_cp(g_fNames[0], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #2 Invalid-path-arg */ - if (OS_cp(g_longPathName, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_cp(g_invalidPath, g_fNames[1]), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long-arg"; + /* #3 Path-too-long-arg */ - if (OS_cp(g_longFileName, g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_cp(g_longPathName, g_fNames[1]), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#5 OS-call-failure"; + /* #4 Name-too-long-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_cp(g_longFileName, g_fNames[1]), OS_FS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#6 Nominal"; + /* #6 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[1], '\0', sizeof(g_fNames[1])); UT_os_sprintf(g_fNames[0], "%s/Cp_Nom_Old.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/Cp_Nom_New.txt", g_mntName); - if (OS_stat(g_fNames[1], &fstats) != OS_ERROR) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#6 Nominal - File-stat failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_copyfile_test_exit_tag; - } + UT_SETUP(OS_close(g_fDescs[0])); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#6 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_copyfile_test_exit_tag; - } - - if (OS_close(g_fDescs[0]) != OS_SUCCESS) - { - testDesc = "#6 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_copyfile_test_exit_tag; - } + /* validate pass-thru codes on second arg (must be done with a valid 1st arg) */ - if (OS_cp(g_fNames[0], g_fNames[1]) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_copyfile_test_exit_tag; - } + UT_RETVAL(OS_cp(g_fNames[0], g_invalidPath), OS_FS_ERR_PATH_INVALID); + UT_RETVAL(OS_cp(g_fNames[0], g_longPathName), OS_FS_ERR_PATH_TOO_LONG); + UT_RETVAL(OS_cp(g_fNames[0], g_longFileName), OS_FS_ERR_NAME_TOO_LONG); - if (OS_stat(g_fNames[1], &fstats) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_cp(g_fNames[0], g_fNames[1])); - /* Reset test environment */ - OS_remove(g_fNames[0]); - OS_remove(g_fNames[1]); + UT_RETVAL(OS_stat(g_fNames[0], &fstats), OS_SUCCESS); + UT_RETVAL(OS_stat(g_fNames[1], &fstats), OS_SUCCESS); -UT_os_copyfile_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_remove(g_fNames[0])); + UT_TEARDOWN(OS_remove(g_fNames[1])); + } } /*--------------------------------------------------------------------------------* @@ -1786,107 +1285,60 @@ void UT_os_copyfile_test() **--------------------------------------------------------------------------------*/ void UT_os_movefile_test() { - os_fstat_t fstats; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_mv(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_movefile_test_exit_tag; - } + os_fstat_t fstats; /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[1], '\0', sizeof(g_fNames[1])); UT_os_sprintf(g_fNames[0], "%s/oldName.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/newName.txt", g_mntName); - if ((OS_mv(NULL, g_fNames[1]) == OS_INVALID_POINTER) && (OS_mv(g_fNames[0], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mv(NULL, g_fNames[1]), OS_INVALID_POINTER); + UT_RETVAL(OS_mv(g_fNames[0], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; + /* #2 Invalid-path-arg */ - if (OS_mv(g_invalidPath, g_invalidPath) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mv(g_invalidPath, g_fNames[1]), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#3 Path-too-long-arg"; + /* #3 Path-too-long-arg */ - if (OS_mv(g_longPathName, g_longPathName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mv(g_longPathName, g_fNames[1]), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-too-long-arg"; + /* #4 Name-too-long-arg */ - if (OS_mv(g_longFileName, g_longFileName) == OS_FS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mv(g_longFileName, g_fNames[1]), OS_FS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#5 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#6 Nominal"; + /* #6 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[0], '\0', sizeof(g_fNames[1])); UT_os_sprintf(g_fNames[0], "%s/Mv_Nom_Old.txt", g_mntName); UT_os_sprintf(g_fNames[1], "%s/Mv_Nom_New.txt", g_mntName); - if (OS_stat(g_fNames[1], &fstats) != OS_ERROR) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#6 Nominal - File-stat failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_movefile_test_exit_tag; - } + /* Close file before moving */ + UT_SETUP(OS_close(g_fDescs[0])); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#6 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_movefile_test_exit_tag; - } + /* validate pass-thru codes on second arg (must be done with a valid 1st arg) */ + UT_RETVAL(OS_mv(g_fNames[0], g_invalidPath), OS_FS_ERR_PATH_INVALID); + UT_RETVAL(OS_mv(g_fNames[0], g_longPathName), OS_FS_ERR_PATH_TOO_LONG); + UT_RETVAL(OS_mv(g_fNames[0], g_longFileName), OS_FS_ERR_NAME_TOO_LONG); - /* Close file before moving */ - if (OS_close(g_fDescs[0]) != OS_SUCCESS) - { - testDesc = "#6 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_movefile_test_exit_tag; - } + UT_NOMINAL(OS_mv(g_fNames[0], g_fNames[1])); - if (OS_mv(g_fNames[0], g_fNames[1]) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_movefile_test_exit_tag; - } - - if ((OS_stat(g_fNames[1], &fstats) == OS_SUCCESS) && (OS_stat(g_fNames[0], &fstats) != OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[1]); + UT_RETVAL(OS_stat(g_fNames[0], &fstats), OS_ERROR); + UT_RETVAL(OS_stat(g_fNames[1], &fstats), OS_SUCCESS); -UT_os_movefile_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_remove(g_fNames[1])); + } } /*--------------------------------------------------------------------------------* @@ -1942,97 +1394,39 @@ void UT_os_movefile_test() **--------------------------------------------------------------------------------*/ void UT_os_outputtofile_test() { - int res; - const char *cmd = NULL; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_ShellOutputToFile(NULL, OS_OBJECT_ID_UNDEFINED) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_outputtofile_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_ShellOutputToFile(NULL, OS_OBJECT_ID_UNDEFINED) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-file-desc-arg"; + /* #1 Null-pointer-arg */ - if (OS_ShellOutputToFile("ls", UT_OBJID_INCORRECT) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ShellOutputToFile(NULL, OS_OBJECT_ID_UNDEFINED), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; + /* #2 Invalid-file-desc-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_ShellOutputToFile("ls", UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Output_Nominal.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#4 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_outputtofile_test_exit_tag; - } - - cmd = "echo \"UT_os_outputtofile_test\""; - res = OS_ShellOutputToFile(cmd, g_fDescs[0]); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_outputtofile_test_exit_tag; - } - - if (res != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_outputtofile_test_exit_tag; - } - - if (OS_lseek(g_fDescs[0], 0, OS_SEEK_SET) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-lseek failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - memset(g_readBuff, '\0', sizeof(g_readBuff)); - if (OS_read(g_fDescs[0], g_readBuff, sizeof(g_readBuff)) <= 0) + /* #4 Nominal - File-create failed */ + if (UT_NOMINAL_OR_NOTIMPL(OS_ShellOutputToFile("echo \"UT_os_outputtofile_test\"", g_fDescs[0]))) { - testDesc = "#4 Nominal - File-read failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_RETVAL(OS_lseek(g_fDescs[0], 0, OS_SEEK_SET), 0); + memset(g_readBuff, '\0', sizeof(g_readBuff)); + if (UT_SETUP(OS_read(g_fDescs[0], g_readBuff, sizeof(g_readBuff)))) + { + UtAssert_True(strstr(g_readBuff, "UT_os_outputtofile_test") != NULL, + "Output file contains UT_os_outputtofile_test"); + } } - else if (strstr(g_readBuff, "UT_os_outputtofile_test") != NULL) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - } - -UT_os_outputtofile_test_exit_tag: - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); - - return; + /* Reset test environment */ + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); + } } /*--------------------------------------------------------------------------------* @@ -2086,96 +1480,41 @@ void UT_os_outputtofile_test() void UT_os_getfdinfo_test() { OS_file_prop_t fdProps; - const char * testDesc; const char * fileName = "GetInfo_Nom.txt"; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_FDGetInfo(OS_OBJECT_ID_UNDEFINED, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_getfdinfo_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/GetInfo_Null.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#1 Null-pointer-arg - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - if (OS_FDGetInfo(g_fDescs[0], NULL) != OS_INVALID_POINTER) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } + /* #1 Null-pointer-arg */ + UT_RETVAL(OS_FDGetInfo(g_fDescs[0], NULL), OS_INVALID_POINTER); - OS_close(g_fDescs[0]); + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); } - OS_remove(g_fNames[0]); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-file-desc-arg"; + /* #2 Invalid-file-desc-arg */ - if (OS_FDGetInfo(UT_OBJID_INCORRECT, &fdProps) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FDGetInfo(UT_OBJID_INCORRECT, &fdProps), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/%s", g_mntName, fileName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#4 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_getfdinfo_test_exit_tag; - } + UT_NOMINAL(OS_FDGetInfo(g_fDescs[0], &fdProps)); - memset(&fdProps, 0x00, sizeof(fdProps)); - if (OS_FDGetInfo(g_fDescs[0], &fdProps) != OS_SUCCESS || strcmp(fdProps.Path, g_fNames[0]) != 0) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_getfdinfo_test_exit_tag; - } + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_TEARDOWN(OS_remove(g_fNames[0])); - if (OS_close(g_fDescs[0]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_getfdinfo_test_exit_tag; + UT_RETVAL(OS_FDGetInfo(g_fDescs[0], &fdProps), OS_ERR_INVALID_ID); } - - memset(&fdProps, 0x00, sizeof(fdProps)); - if (OS_FDGetInfo(g_fDescs[0], &fdProps) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[0]); - -UT_os_getfdinfo_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -2212,82 +1551,33 @@ void UT_os_getfdinfo_test() **--------------------------------------------------------------------------------*/ void UT_os_checkfileopen_test() { - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_FileOpenCheck(NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_checkfileopen_test_exit_tag; - } - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_FileOpenCheck(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FileOpenCheck(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 File-not-opened"; + /* #2 File-not-opened */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/FChk_UnOpened.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) - { - testDesc = "#2 File-not-opened - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - if (OS_close(g_fDescs[0]) != OS_SUCCESS) - { - testDesc = "#2 File-not-opened - File-close failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else if (OS_FileOpenCheck(g_fNames[0]) != OS_ERROR) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - } - - /* Reset test environment */ - OS_remove(g_fNames[0]); + UT_RETVAL(OS_FileOpenCheck(g_fNames[0]), OS_ERROR); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/FileChk_Nominal.txt", g_mntName); - - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#3 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_checkfileopen_test_exit_tag; - } - - if (OS_FileOpenCheck(g_fNames[0]) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_FileOpenCheck(g_fNames[0])); - /* Reset test environment */ - OS_close(g_fDescs[0]); - OS_remove(g_fNames[0]); + UT_TEARDOWN(OS_close(g_fDescs[0])); + UT_RETVAL(OS_FileOpenCheck(g_fNames[0]), OS_ERROR); -UT_os_checkfileopen_test_exit_tag: - return; + UT_TEARDOWN(OS_remove(g_fNames[0])); + } } /*--------------------------------------------------------------------------------* @@ -2322,24 +1612,8 @@ void UT_os_checkfileopen_test() **--------------------------------------------------------------------------------*/ void UT_os_closeallfiles_test() { - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_CloseAllFiles() == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_closeallfiles_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); memset(g_fNames[1], '\0', sizeof(g_fNames[1])); @@ -2348,35 +1622,26 @@ void UT_os_closeallfiles_test() UT_os_sprintf(g_fNames[1], "%s/CloseAll_Nom_2.txt", g_mntName); UT_os_sprintf(g_fNames[2], "%s/CloseAll_Nom_3.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - g_fStatus[1] = OS_OpenCreate(&g_fDescs[1], g_fNames[1], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - g_fStatus[2] = OS_OpenCreate(&g_fDescs[2], g_fNames[2], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if ((g_fStatus[0] < 0) || (g_fStatus[1] < 0) || (g_fStatus[2] < 0)) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#2 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_closeallfiles_test_exit_tag; - } - - if (OS_CloseAllFiles() != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_closeallfiles_test_exit_tag; + if (UT_SETUP( + OS_OpenCreate(&g_fDescs[1], g_fNames[1], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) + { + if (UT_SETUP(OS_OpenCreate(&g_fDescs[2], g_fNames[2], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, + OS_READ_WRITE))) + { + UT_NOMINAL(OS_CloseAllFiles()); + + UT_RETVAL(OS_FileOpenCheck(g_fNames[0]), OS_ERROR); + UT_RETVAL(OS_FileOpenCheck(g_fNames[1]), OS_ERROR); + UT_RETVAL(OS_FileOpenCheck(g_fNames[2]), OS_ERROR); + + UT_TEARDOWN(OS_remove(g_fNames[2])); + } + UT_TEARDOWN(OS_remove(g_fNames[1])); + } + UT_TEARDOWN(OS_remove(g_fNames[0])); } - - if ((OS_FileOpenCheck(g_fNames[0]) == OS_ERROR) && (OS_FileOpenCheck(g_fNames[1]) == OS_ERROR) && - (OS_FileOpenCheck(g_fNames[2]) == OS_ERROR)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[0]); - OS_remove(g_fNames[1]); - OS_remove(g_fNames[2]); - -UT_os_closeallfiles_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -2423,67 +1688,28 @@ void UT_os_closeallfiles_test() **--------------------------------------------------------------------------------*/ void UT_os_closefilebyname_test() { - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_CloseFileByName(NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_closefilebyname_test_exit_tag; - } - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_CloseFileByName(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path-arg"; - - if (OS_CloseFileByName(g_invalidPath) == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #1 Null-pointer-arg */ + UT_RETVAL(OS_CloseFileByName(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; + /* #2 Invalid-path-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_CloseFileByName(g_invalidPath), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ memset(g_fNames[0], '\0', sizeof(g_fNames[0])); UT_os_sprintf(g_fNames[0], "%s/Close_Nominal.txt", g_mntName); - g_fStatus[0] = OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (g_fStatus[0] < 0) + if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE))) { - testDesc = "#4 Nominal - File-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_closefilebyname_test_exit_tag; - } + UT_NOMINAL(OS_CloseFileByName(g_fNames[0])); + UT_RETVAL(OS_FileOpenCheck(g_fNames[0]), OS_ERROR); - if (OS_CloseFileByName(g_fNames[0]) != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_closefilebyname_test_exit_tag; + /* Reset test environment */ + UT_TEARDOWN(OS_remove(g_fNames[0])); } - - if (OS_FileOpenCheck(g_fNames[0]) == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_remove(g_fNames[0]); - -UT_os_closefilebyname_test_exit_tag: - return; } /*================================================================================* diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c index dd28ae4ee..4f0dfcfaa 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -125,44 +125,33 @@ extern char g_mntNames[UT_OS_FILESYS_LIST_LEN][UT_OS_FILE_BUFF_SIZE]; **--------------------------------------------------------------------------------*/ void UT_os_initfs_test() { - const char *testDesc; - int32 res = 0, i = 0, j = 0; + int32 i = 0, j = 0; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_initfs(NULL, NULL, NULL, g_blkSize, g_blkCnt); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_initfs(NULL, NULL, NULL, g_blkSize, g_blkCnt))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_initfs_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if ((OS_initfs(g_fsAddrPtr, NULL, g_volNames[1], OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER) && - (OS_initfs(g_fsAddrPtr, g_devNames[1], NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_initfs(g_fsAddrPtr, NULL, g_volNames[1], OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_INVALID_POINTER); + UT_RETVAL(OS_initfs(g_fsAddrPtr, g_devNames[1], NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ - if ((OS_initfs(g_fsAddrPtr, g_fsLongName, g_volNames[2], g_blkSize, g_blkCnt) == OS_FS_ERR_PATH_TOO_LONG) && - (OS_initfs(g_fsAddrPtr, g_devNames[2], g_fsLongName, g_blkSize, g_blkCnt) == OS_FS_ERR_PATH_TOO_LONG)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_initfs(g_fsAddrPtr, g_fsLongName, g_volNames[2], g_blkSize, g_blkCnt), OS_FS_ERR_PATH_TOO_LONG); + UT_RETVAL(OS_initfs(g_fsAddrPtr, g_devNames[2], g_fsLongName, g_blkSize, g_blkCnt), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#4 Disk-full"; + /* #4 Disk-full */ for (i = 0; i <= OS_MAX_FILE_SYSTEMS; i++) { @@ -170,37 +159,30 @@ void UT_os_initfs_test() UT_os_sprintf(g_devNames[i], "/ramdev%d", (int)i); memset(g_volNames[i], '\0', sizeof(g_volNames[i])); UT_os_sprintf(g_volNames[i], "RAM%d", (int)i); - res = OS_initfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt); - if (res != OS_SUCCESS) + + /* Only need to check the last call to OS_initfs() */ + if (i == OS_MAX_FILE_SYSTEMS) + { + UT_RETVAL(OS_initfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt), + OS_FS_ERR_DEVICE_NOT_FREE); + } + else if (!UT_SETUP(OS_initfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt))) + { break; + } } - /* Only need to check the last call to OS_initfs() */ - if (res == OS_FS_ERR_DEVICE_NOT_FREE) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /* Reset test environment */ - for (j = 0; j < i; j++) - OS_rmfs(g_devNames[j]); - - /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; - - if (OS_initfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt) != OS_SUCCESS) + for (j = 0; j < OS_MAX_FILE_SYSTEMS; j++) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_initfs_test_exit_tag; + UT_TEARDOWN(OS_rmfs(g_devNames[j])); } - if (OS_rmfs(g_devNames[5]) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /*-----------------------------------------------------*/ + /* #5 Nominal */ -UT_os_initfs_test_exit_tag: - return; + UT_NOMINAL(OS_initfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt)); + UT_TEARDOWN(OS_rmfs(g_devNames[5])); } /*--------------------------------------------------------------------------------* @@ -258,44 +240,30 @@ void UT_os_initfs_test() **--------------------------------------------------------------------------------*/ void UT_os_makefs_test() { - const char *testDesc; - int32 res = 0, i = 0, j = 0; + int32 i = 0, j = 0; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_mkfs(g_fsAddrPtr, NULL, NULL, g_blkSize, g_blkCnt); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_mkfs(g_fsAddrPtr, NULL, NULL, g_blkSize, g_blkCnt))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_makefs_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if ((OS_mkfs(g_fsAddrPtr, NULL, g_volNames[1], OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER) && - (OS_mkfs(g_fsAddrPtr, g_devNames[1], NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #1 Null-pointer-arg */ - if ((OS_mkfs(g_fsAddrPtr, g_fsLongName, g_volNames[2], g_blkSize, g_blkCnt) == OS_FS_ERR_PATH_TOO_LONG) && - (OS_mkfs(g_fsAddrPtr, g_devNames[2], g_fsLongName, g_blkSize, g_blkCnt) == OS_FS_ERR_PATH_TOO_LONG)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mkfs(g_fsAddrPtr, NULL, g_volNames[1], OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_INVALID_POINTER); + UT_RETVAL(OS_mkfs(g_fsAddrPtr, g_devNames[1], NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; + /* #2 Path-too-long-arg */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + UT_RETVAL(OS_mkfs(g_fsAddrPtr, g_fsLongName, g_volNames[2], g_blkSize, g_blkCnt), OS_FS_ERR_PATH_TOO_LONG); + UT_RETVAL(OS_mkfs(g_fsAddrPtr, g_devNames[2], g_fsLongName, g_blkSize, g_blkCnt), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Disk-full"; + /* #4 Disk-full */ for (i = 0; i <= OS_MAX_FILE_SYSTEMS; i++) { @@ -303,37 +271,31 @@ void UT_os_makefs_test() UT_os_sprintf(g_devNames[i], "/ramdev%d", (int)i); memset(g_volNames[i], '\0', sizeof(g_volNames[i])); UT_os_sprintf(g_volNames[i], "RAM%d", (int)i); - res = OS_mkfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt); - if (res != OS_SUCCESS) + + /* Only need to check the last call to OS_mkfs() */ + if (i == OS_MAX_FILE_SYSTEMS) + { + UT_RETVAL(OS_mkfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt), + OS_FS_ERR_DEVICE_NOT_FREE); + } + else if (!UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[i], g_volNames[i], g_blkSize, g_blkCnt))) + { break; + } } - /* Only need to check the last call to OS_mkfs() */ - if (res == OS_FS_ERR_DEVICE_NOT_FREE) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - /* Reset test environment */ - for (j = 0; j < i; j++) - OS_rmfs(g_devNames[j]); - - /*-----------------------------------------------------*/ - testDesc = "#5 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt) != OS_SUCCESS) + for (j = 0; j < OS_MAX_FILE_SYSTEMS; j++) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - goto UT_os_makefs_test_exit_tag; + UT_TEARDOWN(OS_rmfs(g_devNames[j])); } - if (OS_rmfs(g_devNames[5]) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /*-----------------------------------------------------*/ + /* #5 Nominal */ + + UT_NOMINAL(OS_mkfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt)); -UT_os_makefs_test_exit_tag: - return; + UT_TEARDOWN(OS_rmfs(g_devNames[5])); } /*--------------------------------------------------------------------------------* @@ -375,56 +337,35 @@ void UT_os_makefs_test() **--------------------------------------------------------------------------------*/ void UT_os_removefs_test() { - int32 res = 0; - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_rmfs(NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_rmfs(NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_removefs_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_rmfs(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rmfs(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-device-arg"; + /* #2 Invalid-device-arg */ - if (OS_rmfs(g_devNames[2]) == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_rmfs(g_devNames[2]), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - if (OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#3 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_removefs_test_exit_tag; - } + UT_NOMINAL(OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt)); - if ((OS_rmfs(g_devNames[3]) == OS_SUCCESS) && - (OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt) == OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_TEARDOWN(OS_rmfs(g_devNames[3])); - /* Reset test environment */ - OS_rmfs(g_devNames[3]); + UT_NOMINAL(OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt)); -UT_os_removefs_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_rmfs(g_devNames[3])); } /*--------------------------------------------------------------------------------* @@ -471,57 +412,37 @@ void UT_os_removefs_test() **--------------------------------------------------------------------------------*/ void UT_os_mount_test() { - int32 res = 0; - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_mount(NULL, NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_mount(NULL, NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mount_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if ((OS_mount(NULL, g_mntNames[1]) == OS_INVALID_POINTER) && (OS_mount(g_devNames[1], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mount(NULL, g_mntNames[1]), OS_INVALID_POINTER); + UT_RETVAL(OS_mount(g_devNames[1], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-device-arg"; + /* #2 Invalid-device-arg */ - if (OS_mount("ramdev0", g_mntNames[2]) == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_mount("ramdev0", g_mntNames[2]), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - if (OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt) != OS_SUCCESS) + if (UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[3], g_volNames[3], g_blkSize, g_blkCnt))) { - testDesc = "#3 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_mount_test_exit_tag; - } - - if ((OS_mount(g_devNames[3], g_mntNames[3]) == OS_SUCCESS) && - (OS_mount(g_devNames[3], g_mntNames[3]) == OS_ERR_NAME_NOT_FOUND)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_mount(g_devNames[3], g_mntNames[3])); + UT_RETVAL(OS_mount(g_devNames[3], g_mntNames[3]), OS_ERR_NAME_NOT_FOUND); - /* Reset test environment */ - OS_unmount(g_mntNames[3]); - OS_rmfs(g_devNames[3]); - -UT_os_mount_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_unmount(g_mntNames[3])); + UT_TEARDOWN(OS_rmfs(g_devNames[3])); + } } /*--------------------------------------------------------------------------------* @@ -575,64 +496,41 @@ void UT_os_mount_test() **--------------------------------------------------------------------------------*/ void UT_os_unmount_test() { - int32 res = 0; - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_unmount(NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_unmount(NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_unmount_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_unmount(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_unmount(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ - if (OS_unmount(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_unmount(g_fsLongName), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-mount-point-arg"; + /* #3 Invalid-mount-point-arg */ - if (OS_unmount(g_mntNames[3]) == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_unmount(g_mntNames[3]), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) + if (UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt))) { - testDesc = "#3 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_unmount_test_exit_tag; - } - - if ((OS_mount(g_devNames[4], g_mntNames[4]) == OS_SUCCESS) && (OS_unmount(g_mntNames[4]) == OS_SUCCESS) && - (OS_unmount(g_mntNames[4]) == OS_ERR_NAME_NOT_FOUND)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_mount(g_devNames[4], g_mntNames[4])); + UT_NOMINAL(OS_unmount(g_mntNames[4])); + UT_RETVAL(OS_unmount(g_mntNames[4]), OS_ERR_NAME_NOT_FOUND); - /* Reset test environment */ - OS_rmfs(g_devNames[4]); - -UT_os_unmount_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_rmfs(g_devNames[4])); + } } /*--------------------------------------------------------------------------------* @@ -685,75 +583,50 @@ void UT_os_unmount_test() ** --------------------------------------------------------------------------------*/ void UT_os_getphysdrivename_test() { - int32 res = 0; - const char *testDesc; - char physDevName[UT_OS_PHYS_NAME_BUFF_SIZE]; + char physDevName[UT_OS_PHYS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_FS_GetPhysDriveName(NULL, NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_FS_GetPhysDriveName(NULL, NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_getphysicaldrivename_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if ((OS_FS_GetPhysDriveName(NULL, g_mntNames[1]) == OS_INVALID_POINTER) && - (OS_FS_GetPhysDriveName(physDevName, NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FS_GetPhysDriveName(NULL, g_mntNames[1]), OS_INVALID_POINTER); + UT_RETVAL(OS_FS_GetPhysDriveName(physDevName, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ - if (OS_FS_GetPhysDriveName(physDevName, g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FS_GetPhysDriveName(physDevName, g_fsLongName), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-mount-point-arg"; + /* #3 Invalid-mount-point-arg */ - if (OS_FS_GetPhysDriveName(physDevName, g_mntNames[3]) == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FS_GetPhysDriveName(physDevName, g_mntNames[3]), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_getphysicaldrivename_test_exit_tag; - } + /* #4 Nominal */ - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) + if (UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt))) { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_getphysicaldrivename_test_exit_tag; - } + if (UT_SETUP(OS_mount(g_devNames[4], g_mntNames[4]))) + { + memset(physDevName, '\0', sizeof(physDevName)); + UT_NOMINAL(OS_FS_GetPhysDriveName(physDevName, g_mntNames[4])); - memset(physDevName, '\0', sizeof(physDevName)); - if ((OS_FS_GetPhysDriveName(physDevName, g_mntNames[4]) == OS_SUCCESS) && - (strncmp(physDevName, g_physDriveName, strlen(g_physDriveName)) == 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* This just checks that the output string is not empty */ + UtAssert_True(physDevName[0] != 0, "physDevName (%s)", physDevName); - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); + UT_TEARDOWN(OS_unmount(g_mntNames[4])); + } -UT_os_getphysicaldrivename_test_exit_tag: - return; + UT_TEARDOWN(OS_rmfs(g_devNames[4])); + } } /*--------------------------------------------------------------------------------* @@ -781,37 +654,24 @@ void UT_os_getphysdrivename_test() void UT_os_getfsinfo_test(void) { os_fsinfo_t fsInfo; - int32 res = 0; - const char *testDesc; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - res = OS_GetFsInfo(&fsInfo); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_GetFsInfo(&fsInfo))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_getfsinfo_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_GetFsInfo(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_GetFsInfo(NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; + /* #2 Nominal */ - if (OS_GetFsInfo(&fsInfo) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_getfsinfo_test_exit_tag: - return; + UT_NOMINAL(OS_GetFsInfo(&fsInfo)); } /*--------------------------------------------------------------------------------* @@ -863,79 +723,45 @@ void UT_os_getfsinfo_test(void) ** --------------------------------------------------------------------------------*/ void UT_os_translatepath_test() { - int32 res = 0; - const char *testDesc; - char localPath[UT_OS_LOCAL_PATH_BUFF_SIZE]; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TranslatePath(NULL, NULL); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_translatepath_test_exit_tag; - } + char localPath[UT_OS_LOCAL_PATH_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if ((OS_TranslatePath(NULL, localPath) == OS_INVALID_POINTER) && - (OS_TranslatePath(g_mntNames[1], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TranslatePath(NULL, localPath), OS_INVALID_POINTER); + UT_RETVAL(OS_TranslatePath(g_mntNames[1], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ - if (OS_TranslatePath(g_fsLongName, localPath) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TranslatePath(g_fsLongName, localPath), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Invalid-virtual-path-arg"; + /* #3 Invalid-virtual-path-arg */ - if ((OS_TranslatePath("cf", localPath) == OS_FS_ERR_PATH_INVALID) && - (OS_TranslatePath("/foobar", localPath) == OS_FS_ERR_PATH_INVALID)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TranslatePath("cf", localPath), OS_FS_ERR_PATH_INVALID); + UT_RETVAL(OS_TranslatePath("/foobar", localPath), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) + if (UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt))) { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_translatepath_test_exit_tag; - } + if (UT_SETUP(OS_mount(g_devNames[4], g_mntNames[4]))) + { + memset(localPath, 0, sizeof(localPath)); - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); + UT_NOMINAL(OS_TranslatePath(g_mntNames[4], localPath)); - /* Reset test environment */ - OS_rmfs(g_devNames[4]); + /* This just checks that the output string is not empty */ + UtAssert_True(localPath[0] != 0, "localPath (%s)", localPath); - goto UT_os_translatepath_test_exit_tag; + /* Reset test environment */ + UT_TEARDOWN(OS_unmount(g_mntNames[4])); + } + /* Reset test environment */ + UT_TEARDOWN(OS_rmfs(g_devNames[4])); } - - if ((OS_TranslatePath(g_mntNames[4], localPath) == OS_SUCCESS) && - (strncmp(localPath, g_physDriveName, strlen(g_physDriveName)) == 0)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_translatepath_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -976,81 +802,48 @@ void UT_os_translatepath_test() ** --------------------------------------------------------------------------------*/ void UT_os_checkfs_test() { - const char *testDesc; - int res; - char driveName[UT_OS_PATH_BUFF_SIZE]; + char driveName[UT_OS_PATH_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - if (OS_chkfs(NULL, 0) == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_TranslatePath(NULL, NULL))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_checkfs_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if (OS_chkfs(NULL, 0) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_chkfs(NULL, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ memset(driveName, 'A', sizeof(driveName)); driveName[sizeof(driveName) - 1] = '\0'; - if (OS_chkfs(driveName, 0) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_chkfs(driveName, 0), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - if (OS_mkfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt) != OS_SUCCESS) + if (UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[5], g_volNames[5], g_blkSize, g_blkCnt))) { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_checkfs_test_exit_tag; - } + if (UT_SETUP(OS_mount(g_devNames[5], g_mntNames[5]))) + { + UT_NOMINAL_OR_NOTIMPL(OS_chkfs(g_mntNames[5], 0)); - if (OS_mount(g_devNames[5], g_mntNames[5]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_checkfs_test_exit_tag; - } + /* Reset test environment */ + UT_TEARDOWN(OS_unmount(g_mntNames[5])); + } - res = OS_chkfs(g_mntNames[5], 0); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - testDesc = "#4 Nominal - Not implemented in API"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - } - else if (res == OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* Reset test environment */ + UT_TEARDOWN(OS_rmfs(g_devNames[5])); } - - /* Reset test environment */ - OS_unmount(g_mntNames[5]); - OS_rmfs(g_devNames[5]); - -UT_os_checkfs_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -1099,75 +892,50 @@ void UT_os_checkfs_test() ** --------------------------------------------------------------------------------*/ void UT_os_fsstatvolume_test(void) { - const char * testDesc; OS_statvfs_t statbuf; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* API not implemented */ - if (OS_FileSysStatVolume("/cf", &statbuf) == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_FileSysStatVolume("/cf", &statbuf))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsstatvolume_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1a Null-pointer-arg"; + /* #1a Null-pointer-arg */ - if (OS_FileSysStatVolume(NULL, &statbuf) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FileSysStatVolume(NULL, &statbuf), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#1b Null-pointer-arg"; + /* #1b Null-pointer-arg */ - if (OS_FileSysStatVolume("/cf", NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FileSysStatVolume("/cf", NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; + /* #2 Path-too-long-arg */ - if (OS_FileSysStatVolume(g_fsLongName, &statbuf) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_FileSysStatVolume(g_fsLongName, &statbuf), OS_FS_ERR_PATH_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) + if (UT_SETUP(OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt))) { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsstatvolume_test_exit_tag; - } - - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsstatvolume_test_exit_tag; - } + if (UT_SETUP(OS_mount(g_devNames[4], g_mntNames[4]))) + { + UT_NOMINAL(OS_FileSysStatVolume(g_mntNames[4], &statbuf)); - if (OS_FileSysStatVolume(g_mntNames[4], &statbuf) >= 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* Reset test environment */ + UT_TEARDOWN(OS_unmount(g_mntNames[4])); + } - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_fsstatvolume_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_rmfs(g_devNames[4])); + } } /*================================================================================* diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.c b/src/unit-tests/osloader-test/ut_osloader_module_test.c index 9c5489097..f857e6078 100644 --- a/src/unit-tests/osloader-test/ut_osloader_module_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.c @@ -67,122 +67,82 @@ **--------------------------------------------------------------------------------*/ void UT_os_module_load_test() { - int i; - int32 res = 0; - const char *testDesc; - uint32 test_setup_invalid = 0; - osal_id_t module_id; - osal_id_t module_id2; - char module_name[UT_OS_NAME_BUFF_SIZE]; - char module_file_name[UT_OS_PATH_BUFF_SIZE]; + int i; + osal_id_t module_id; + osal_id_t module_id2; + char module_name[UT_OS_NAME_BUFF_SIZE]; + char module_file_name[UT_OS_PATH_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_module_load_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg-1"; + /* #1 Null-pointer-arg-1 */ - res = OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleLoad(0, "TestModule", UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS), + OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Null-pointer-arg-2"; + /* #2 Null-pointer-arg-2 */ - res = OS_ModuleLoad(&module_id, 0, UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleLoad(&module_id, 0, UT_OS_GENERIC_MODULE_NAME1, OS_MODULE_FLAG_LOCAL_SYMBOLS), + OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Null-pointer-arg-3"; + /* #3 Null-pointer-arg-3 */ - res = OS_ModuleLoad(&module_id, "TestModule", 0, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleLoad(&module_id, "TestModule", 0, OS_MODULE_FLAG_LOCAL_SYMBOLS), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#4 No-free-IDs"; + /* #4 No-free-IDs */ - /* Setup */ - for (i = 0; i < OS_MAX_MODULES; i++) + for (i = 0; i <= OS_MAX_MODULES; i++) { snprintf(module_name, sizeof(module_name), UT_OS_GENERIC_MODULE_NAME_TEMPLATE, i); snprintf(module_file_name, sizeof(module_file_name), UT_OS_GENERIC_MODULE_FILE_TEMPLATE, i); - res = OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res != OS_SUCCESS) + + if (i == OS_MAX_MODULES) + { + UT_RETVAL(OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS), + OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_ModuleLoad(&module_id, module_name, module_file_name, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { - testDesc = "#4 No-free-IDs - Module Load failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - test_setup_invalid = 1; break; } } - if (test_setup_invalid == 0) - { - res = OS_ModuleLoad(&module_id, "OneTooMany", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_ERR_NO_FREE_IDS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } /* Reset test environment */ OS_DeleteAllObjects(); /*-----------------------------------------------------*/ - testDesc = "#5 Duplicate-name"; + /* #5 Duplicate-name */ /* Setup */ - res = OS_ModuleLoad(&module_id2, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res != OS_SUCCESS) - { - testDesc = "#5 Duplicate-name - Module Load failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_ModuleLoad(&module_id2, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { - res = OS_ModuleLoad(&module_id, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_ERR_NAME_TAKEN) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleLoad(&module_id, "DUPLICATE", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS), + OS_ERR_NAME_TAKEN); /* Reset test environment */ - res = OS_ModuleUnload(module_id2); + UT_TEARDOWN(OS_ModuleUnload(module_id2)); } /*-----------------------------------------------------*/ - testDesc = "#6 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #6 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#7 Nominal"; + /* #7 Nominal */ - res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS)); /* Reset test environment */ - res = OS_ModuleUnload(module_id); - -UT_os_module_load_test_exit_tag: - return; + UT_TEARDOWN(OS_ModuleUnload(module_id)); } /*--------------------------------------------------------------------------------* @@ -195,55 +155,32 @@ void UT_os_module_load_test() **--------------------------------------------------------------------------------*/ void UT_os_module_unload_test() { - int32 res = 0; - const char *testDesc; - osal_id_t module_id; + osal_id_t module_id; /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_ModuleUnload(OS_OBJECT_ID_UNDEFINED); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_ModuleUnload(OS_OBJECT_ID_UNDEFINED))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_module_unload_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; + /* #1 Invalid-ID-arg */ - res = OS_ModuleUnload(UT_OBJID_INCORRECT); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleUnload(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #2 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Module Load failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { - res = OS_ModuleUnload(module_id); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_ModuleUnload(module_id)); } - -UT_os_module_unload_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -256,62 +193,37 @@ void UT_os_module_unload_test() **--------------------------------------------------------------------------------*/ void UT_os_module_info_test() { - int32 res = 0; - const char * testDesc; osal_id_t module_id; OS_module_prop_t module_info; /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, &module_info); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, &module_info))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_module_info_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg"; + /* #1 Invalid-pointer-arg */ - res = OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, NULL); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-ID-arg"; + /* #2 Invalid-ID-arg */ - res = OS_ModuleInfo(UT_OBJID_INCORRECT, &module_info); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleInfo(UT_OBJID_INCORRECT, &module_info), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ /* Setup */ - res = OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Module Load failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_ModuleLoad(&module_id, "Good", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { - res = OS_ModuleInfo(module_id, &module_info); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_ModuleInfo(module_id, &module_info)); - res = OS_ModuleUnload(module_id); + UT_TEARDOWN(OS_ModuleUnload(module_id)); } - -UT_os_module_info_test_exit_tag: - return; } /*================================================================================* diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c index b81ddb1ec..c28a80ffe 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -66,73 +66,44 @@ void UT_os_symbol_lookup_test() { - int32 res = 0; - const char *testDesc; - cpuaddr symbol_addr; - osal_id_t module_id; + cpuaddr symbol_addr; + osal_id_t module_id; /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_SymbolLookup(&symbol_addr, "main"); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_SymbolLookup(&symbol_addr, "main"))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_symbol_lookup_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg-1"; + /* #1 Invalid-pointer-arg-1 */ - res = OS_SymbolLookup(0, "main"); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_SymbolLookup(0, "Sym"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-2"; + /* #2 Invalid-pointer-arg-2 */ - res = OS_SymbolLookup(&symbol_addr, 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_SymbolLookup(&symbol_addr, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#3 Symbol-not-found"; + /* Setup for remainder of tests */ + if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS))) + { + /*-----------------------------------------------------*/ + /* #3 Symbol-not-found */ - res = OS_SymbolLookup(&symbol_addr, "ThisSymbolIsNotFound"); - if (res == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_SymbolLookup(&symbol_addr, "NotFound"), OS_ERROR); - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal, Global Symbols"; + /*-----------------------------------------------------*/ + /* #4 Nominal, Global Symbols */ - /* Setup */ - res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS); - if (res != OS_SUCCESS) - { - UT_OS_TEST_RESULT("#4 Nominal - Module Load failed", UTASSERT_CASETYPE_TSF); - } - else - { - res = OS_SymbolLookup(&symbol_addr, "module1"); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else if (res == OS_ERR_NOT_IMPLEMENTED) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_SymbolLookup(&symbol_addr, "module1")); /* Reset test environment */ - res = OS_ModuleUnload(module_id); + UT_TEARDOWN(OS_ModuleUnload(module_id)); } - -UT_os_symbol_lookup_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -146,71 +117,44 @@ void UT_os_symbol_lookup_test() void UT_os_module_symbol_lookup_test() { - int32 res = 0; - const char *testDesc; - cpuaddr symbol_addr; - osal_id_t module_id; + cpuaddr symbol_addr; + osal_id_t module_id; /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "main"); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "main"))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_module_symbol_lookup_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg-1"; + /* #1 Invalid-pointer-arg-1 */ - res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, 0, "main"); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, 0, "Sym"), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-pointer-arg-2"; + /* #2 Invalid-pointer-arg-2 */ - res = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ /* Setup for remainder of tests */ - res = OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { - UT_OS_TEST_RESULT("Module Load failed", UTASSERT_CASETYPE_TSF); - goto UT_os_module_symbol_lookup_test_exit_tag; - } + /*-----------------------------------------------------*/ + /* #3 Symbol-not-found */ - /*-----------------------------------------------------*/ - testDesc = "#3 Symbol-not-found"; + UT_RETVAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, "NotFound"), OS_ERROR); - res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "ThisSymbolIsNotFound"); - if (res == OS_ERROR) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal, Local Symbols"; + /*-----------------------------------------------------*/ + /* #4 Nominal, Local Symbols */ - res = OS_ModuleSymbolLookup(module_id, &symbol_addr, "module1"); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_NOMINAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, "module1")); - /* Reset test environment */ - res = OS_ModuleUnload(module_id); - -UT_os_module_symbol_lookup_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_ModuleUnload(module_id)); + } } /*--------------------------------------------------------------------------------* @@ -224,9 +168,6 @@ void UT_os_module_symbol_lookup_test() **--------------------------------------------------------------------------------*/ void UT_os_symbol_table_dump_test() { - int32 res = 0; - const char *testDesc; - /* * Note that even if the functionality is not implemented, * the API still validates the input pointers (not null) and @@ -234,40 +175,19 @@ void UT_os_symbol_table_dump_test() */ /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-pointer-arg"; + /* #1 Invalid-pointer-arg */ - res = OS_SymbolTableDump(0, 10000); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_SymbolTableDump(0, 10000), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-path"; + /* #2 Invalid-path */ - res = OS_SymbolTableDump("/this/path/is/invalid.dat", 10000); - if (res == OS_FS_ERR_PATH_INVALID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_SymbolTableDump("/this/path/is/invalid.dat", 10000), OS_FS_ERR_PATH_INVALID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - res = OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolFile.dat", 32000); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - /* allowed, not applicable on this system */ - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - } - else if (res == OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } + UT_NOMINAL_OR_NOTIMPL(OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolFile.dat", 32000)); } /*================================================================================* diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c index 1ce269883..c4944db2d 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c @@ -80,36 +80,23 @@ **--------------------------------------------------------------------------------*/ void UT_os_networkgetid_test() { - int32 res = 0; - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_NetworkGetID(); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_NetworkGetID())) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_networkgetid_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #1 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; - - res = OS_NetworkGetID(); + /* #2 Nominal */ /* NOTE: This API does not return error codes. * Any return value could be valid */ - UtPrintf("OS_NetworkGetID() return value=%ld", (long)res); - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_MIR); - -UT_os_networkgetid_test_exit_tag: - return; + UT_MIR_STATUS(OS_NetworkGetID()); } /*--------------------------------------------------------------------------------* @@ -150,54 +137,33 @@ void UT_os_networkgetid_test() **--------------------------------------------------------------------------------*/ void UT_os_networkgethostname_test() { - int32 res = 0; - const char *testDesc; - char buffer[UT_OS_IO_BUFF_SIZE]; + char buffer[UT_OS_IO_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "API Not implemented"; + /* API Not implemented */ - res = OS_NetworkGetHostName(buffer, sizeof(buffer)); - if (res == OS_ERR_NOT_IMPLEMENTED) + if (!UT_IMPL(OS_NetworkGetHostName(buffer, sizeof(buffer)))) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_networkgethostname_test_exit_tag; + return; } /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - res = OS_NetworkGetHostName(NULL, 0); - if (res == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_NetworkGetHostName(NULL, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Zero-name-length-arg"; + /* #2 Zero-name-length-arg */ - res = OS_NetworkGetHostName(buffer, 0); - if (res == OS_ERR_INVALID_SIZE) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_NetworkGetHostName(buffer, 0), OS_ERR_INVALID_SIZE); /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 OS-call-failure */ /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - res = OS_NetworkGetHostName(buffer, sizeof(buffer)); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #4 Nominal */ -UT_os_networkgethostname_test_exit_tag: - return; + UT_NOMINAL(OS_NetworkGetHostName(buffer, sizeof(buffer))); } /*================================================================================* diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c index 304da7d6b..f08cb4bfb 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c @@ -102,51 +102,23 @@ osal_id_t g_timerIds[UT_OS_TIMER_LIST_LEN]; *--------------------------------------------------------------------------------*/ void UT_os_timerinit_test() { - int32 res = 0; - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "#1 Init-not-call-first"; + /* #1 Init-not-call-first */ - res = OS_TimerCreate(&g_timerIds[0], "Timer #0", &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else - { - /* Reset test environment */ - OS_TimerDelete(g_timerIds[0]); + UT_RETVAL(OS_TimerCreate(&g_timerIds[0], "Timer #0", &g_clkAccuracy, &UT_os_timercallback), OS_ERROR); - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + if (!UT_SETUP(OS_API_Init())) + { + return; } /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; - - res = OS_API_Init(); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - testDesc = "API not implemented"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - } - else if (res == OS_SUCCESS) - { - res = OS_TimerCreate(&g_timerIds[0], "Timer #0", &g_clkAccuracy, &UT_os_timercallback); - if (res == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #2 Nominal */ - /* Reset test environment */ - OS_TimerDelete(g_timerIds[0]); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } + UT_NOMINAL(OS_TimerCreate(&g_timerIds[0], "Timer #0", &g_clkAccuracy, &UT_os_timercallback)); - return; + /* Reset test environment */ + UT_TEARDOWN(OS_TimerDelete(g_timerIds[0])); } /*--------------------------------------------------------------------------------* @@ -226,127 +198,78 @@ void UT_os_timerinit_test() **--------------------------------------------------------------------------------*/ void UT_os_timercreate_test() { - const char *testDesc; - int32 res = 0, i = 0, j = 0; - char tmpStr[UT_OS_NAME_BUFF_SIZE]; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TimerCreate(&g_timerIds[0], g_timerNames[0], &g_clkAccuracy, &UT_os_timercallback); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_timercreate_test_exit_tag; - } - - /* Reset test environment */ - OS_TimerDelete(g_timerIds[0]); + int32 i = 0, j = 0; + char tmpStr[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if ((OS_TimerCreate(NULL, g_timerNames[1], &g_clkAccuracy, &UT_os_timercallback) == OS_INVALID_POINTER) && - (OS_TimerCreate(&g_timerIds[1], NULL, &g_clkAccuracy, &UT_os_timercallback) == OS_INVALID_POINTER) && - (OS_TimerCreate(&g_timerIds[1], g_timerNames[1], NULL, &UT_os_timercallback) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerCreate(NULL, g_timerNames[1], &g_clkAccuracy, &UT_os_timercallback), OS_INVALID_POINTER); + UT_RETVAL(OS_TimerCreate(&g_timerIds[1], NULL, &g_clkAccuracy, &UT_os_timercallback), OS_INVALID_POINTER); + UT_RETVAL(OS_TimerCreate(&g_timerIds[1], g_timerNames[1], NULL, &UT_os_timercallback), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Name-too-long"; + /* #2 Name-too-long */ - if (OS_TimerCreate(&g_timerIds[2], g_longTimerName, &g_clkAccuracy, &UT_os_timercallback) == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerCreate(&g_timerIds[2], g_longTimerName, &g_clkAccuracy, &UT_os_timercallback), + OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Name equal to OS_MAX_API_NAME characters test"; + /* #3 Name equal to OS_MAX_API_NAME characters test */ /* Test Load library returning an error on a too long library name */ memset(&tmpStr[0], 'a', OS_MAX_API_NAME); tmpStr[OS_MAX_API_NAME] = '\0'; - if (OS_TimerCreate(&g_timerIds[2], tmpStr, &g_clkAccuracy, &UT_os_timercallback) == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerCreate(&g_timerIds[2], tmpStr, &g_clkAccuracy, &UT_os_timercallback), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#4 Name-taken"; + /* #4 Name-taken */ - if ((OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback) == OS_SUCCESS) && - (OS_TimerCreate(&g_timerIds[4], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback) == OS_ERR_NAME_TAKEN)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + if (UT_SETUP(OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback))) + { + UT_RETVAL(OS_TimerCreate(&g_timerIds[4], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback), + OS_ERR_NAME_TAKEN); - /* Reset test environment */ - OS_TimerDelete(g_timerIds[3]); + /* Reset test environment */ + UT_TEARDOWN(OS_TimerDelete(g_timerIds[3])); + } /*-----------------------------------------------------*/ - testDesc = "#5 No-free-IDs"; + /* #5 No-free-IDs */ for (i = 0; i <= OS_MAX_TIMEBASES; i++) { memset(tmpStr, '\0', sizeof(tmpStr)); UT_os_sprintf(tmpStr, "Timer #%d", (int)i); - res = OS_TimerCreate(&g_timerIds[i], tmpStr, &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) + if (i == OS_MAX_TIMEBASES) + { + UT_RETVAL(OS_TimerCreate(&g_timerIds[i], tmpStr, &g_clkAccuracy, &UT_os_timercallback), OS_ERR_NO_FREE_IDS); + } + else if (!UT_SETUP(OS_TimerCreate(&g_timerIds[i], tmpStr, &g_clkAccuracy, &UT_os_timercallback))) + { break; + } } - if (i < OS_MAX_TIMEBASES) - { - testDesc = "#4 No-free-IDs - Timer-created failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else if (res == OS_ERR_NO_FREE_IDS) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - } - else + /* Reset test environment */ + for (j = 0; j < OS_MAX_TIMEBASES; j++) { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_TEARDOWN(OS_TimerDelete(g_timerIds[j])); } - /* Reset test environment */ - for (j = 0; j < i; j++) - OS_TimerDelete(g_timerIds[j]); - /*-----------------------------------------------------*/ - testDesc = "#6 Invalid-arg"; + /* #6 Invalid-arg */ - if (OS_TimerCreate(&g_timerIds[5], g_timerNames[5], &g_clkAccuracy, NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerCreate(&g_timerIds[5], g_timerNames[5], &g_clkAccuracy, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#7 Timer-unavailable"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #7 Timer-unavailable */ /*-----------------------------------------------------*/ - testDesc = "#8 Nominal"; + /* #8 Nominal */ - res = OS_TimerCreate(&g_timerIds[7], g_timerNames[7], &g_clkAccuracy, &UT_os_timercallback); - if (res == OS_SUCCESS) - { - if ((OS_TimerGetIdByName(&g_timerIds[8], g_timerNames[7]) == OS_SUCCESS) && - OS_ObjectIdEqual(g_timerIds[7], g_timerIds[8]) && (OS_TimerDelete(g_timerIds[7]) == OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - -UT_os_timercreate_test_exit_tag: - return; + UT_NOMINAL(OS_TimerCreate(&g_timerIds[7], g_timerNames[7], &g_clkAccuracy, &UT_os_timercallback)); } /*--------------------------------------------------------------------------------* @@ -393,61 +316,26 @@ void UT_os_timercreate_test() **--------------------------------------------------------------------------------*/ void UT_os_timerdelete_test() { - int32 res = 0; - const char *testDesc; - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Invalid-id-arg */ - res = OS_TimerDelete(UT_OBJID_INCORRECT); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_timerdelete_test_exit_tag; - } + UT_RETVAL(OS_TimerDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-id-arg"; - - if (OS_TimerDelete(UT_OBJID_INCORRECT) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* #2 Internal-error */ /*-----------------------------------------------------*/ - testDesc = "#2 Internal-error"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #3 Nominal */ - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - res = OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback))) { - testDesc = "#3 Nominal - Timer-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_timerdelete_test_exit_tag; - } + UT_NOMINAL(OS_TimerDelete(g_timerIds[3])); + UT_RETVAL(OS_TimerGetIdByName(&g_timerIds[4], g_timerNames[3]), OS_ERR_NAME_NOT_FOUND); + UT_NOMINAL(OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback)); - if (OS_TimerDelete(g_timerIds[3]) == OS_SUCCESS) - { - if ((OS_TimerGetIdByName(&g_timerIds[4], g_timerNames[3]) == OS_ERR_NAME_NOT_FOUND) && - (OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback) == OS_SUCCESS)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + /* Reset test environment */ + UT_TEARDOWN(OS_TimerDelete(g_timerIds[3])); } - - /* Reset test environment */ - OS_TimerDelete(g_timerIds[3]); - -UT_os_timerdelete_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -503,44 +391,20 @@ void UT_os_timerdelete_test() **--------------------------------------------------------------------------------*/ void UT_os_timerset_test() { - int32 res = 0; - const char *testDesc; - uint32 startTime = 0, intervalTime = 0; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TimerSet(UT_OBJID_INCORRECT, startTime, intervalTime); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_timerset_test_exit_tag; - } + uint32 startTime = 0, intervalTime = 0; /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-id-arg"; + /* #1 Invalid-id-arg */ - res = OS_TimerSet(UT_OBJID_INCORRECT, 10000, 10000); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerSet(UT_OBJID_INCORRECT, 10000, 10000), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#2 Internal-error"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); + /* #2 Internal-error */ /*-----------------------------------------------------*/ - testDesc = "#3 Interval-too-short"; + /* #3 Interval-too-short */ - res = OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) - { - testDesc = "#3 Interval-too-short - Timer-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback))) { g_status = 0; g_timerId = g_timerIds[3]; @@ -551,35 +415,24 @@ void UT_os_timerset_test() g_toleranceVal = 0; UtPrintf("\nOS_TimerSet() - #3 Interval-too-short (clk_accuracy=%d)\n", (int)g_clkAccuracy); - res = OS_TimerSet(g_timerIds[3], startTime, intervalTime); - if (res == OS_SUCCESS) + if (UT_NOMINAL(OS_TimerSet(g_timerIds[3], startTime, intervalTime))) { - while (!g_status) + while (g_status == 0) + { OS_TaskDelay(1); - if (g_status < 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + } + + UtAssert_True(g_status < 0, "4# Nominal - callback status %d", (int)g_status); } + /* Reset test environment */ - OS_TimerDelete(g_timerIds[3]); + UT_TEARDOWN(OS_TimerDelete(g_timerIds[3])); } /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - res = OS_TimerCreate(&g_timerIds[4], g_timerNames[4], &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) - { - testDesc = "#4 Nominal - Timer-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_timerset_test_exit_tag; - } - else + if (UT_SETUP(OS_TimerCreate(&g_timerIds[4], g_timerNames[4], &g_clkAccuracy, &UT_os_timercallback))) { g_status = 0; g_timerId = g_timerIds[4]; @@ -588,27 +441,21 @@ void UT_os_timerset_test() startTime = 1000; intervalTime = 500000; g_toleranceVal = intervalTime / 20; /* 5% */ - UtPrintf("\nOS_TimerSet() - #1 Nominal condition (clk_accuracy=%d)\n", (int)g_clkAccuracy); - res = OS_TimerSet(g_timerIds[4], startTime, intervalTime); - if (res == OS_SUCCESS) + + UtPrintf("\nOS_TimerSet() - #4 Nominal condition (clk_accuracy=%d)\n", (int)g_clkAccuracy); + if (UT_NOMINAL(OS_TimerSet(g_timerIds[4], startTime, intervalTime))) { - while (!g_status) + while (g_status == 0) + { OS_TaskDelay(1); - if (g_status > 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + } + + UtAssert_True(g_status > 0, "4# Nominal - callback status %d", (int)g_status); } + /* Reset test environment */ - OS_TimerDelete(g_timerIds[4]); + UT_TEARDOWN(OS_TimerDelete(g_timerIds[4])); } - -UT_os_timerset_test_exit_tag: - return; } /*--------------------------------------------------------------------------------* @@ -655,66 +502,35 @@ void UT_os_timerset_test() **--------------------------------------------------------------------------------*/ void UT_os_timergetidbyname_test() { - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TimerGetIdByName(&g_timerIds[0], g_timerNames[0]); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_timergetidbyname_test_exit_tag; - } - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #1 Null-pointer-arg */ - if ((OS_TimerGetIdByName(NULL, g_timerNames[1]) == OS_INVALID_POINTER) && - (OS_TimerGetIdByName(&g_timerIds[1], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerGetIdByName(NULL, g_timerNames[1]), OS_INVALID_POINTER); + UT_RETVAL(OS_TimerGetIdByName(&g_timerIds[1], NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#2 Name-too-long"; + /* #2 Name-too-long */ - if (OS_TimerGetIdByName(&g_timerIds[2], g_longTimerName) == OS_ERR_NAME_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerGetIdByName(&g_timerIds[2], g_longTimerName), OS_ERR_NAME_TOO_LONG); /*-----------------------------------------------------*/ - testDesc = "#3 Name-not-found"; + /* #3 Name-not-found */ - if (OS_TimerGetIdByName(&g_timerIds[3], g_timerNames[3]) == OS_ERR_NAME_NOT_FOUND) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerGetIdByName(&g_timerIds[3], g_timerNames[3]), OS_ERR_NAME_NOT_FOUND); /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; + /* #4 Nominal */ - res = OS_TimerCreate(&g_timerIds[4], g_timerNames[4], &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) + if (UT_SETUP(OS_TimerCreate(&g_timerIds[4], g_timerNames[4], &g_clkAccuracy, &UT_os_timercallback))) { - testDesc = "#4 Nominal - Timer-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_timergetidbyname_test_exit_tag; - } + UT_NOMINAL(OS_TimerGetIdByName(&g_timerIds[5], g_timerNames[4])); - res = OS_TimerGetIdByName(&g_timerIds[5], g_timerNames[4]); - if ((res == OS_SUCCESS) && OS_ObjectIdEqual(g_timerIds[4], g_timerIds[5])) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UtAssert_True(OS_ObjectIdEqual(g_timerIds[4], g_timerIds[5]), "OS_TimerGetIdByName() ID (%lu) == %lu", + OS_ObjectIdToInteger(g_timerIds[4]), OS_ObjectIdToInteger(g_timerIds[5])); - /* Reset test environment */ - OS_TimerDelete(g_timerIds[4]); - -UT_os_timergetidbyname_test_exit_tag: - return; + /* Reset test environment */ + UT_TEARDOWN(OS_TimerDelete(g_timerIds[4])); + } } /*--------------------------------------------------------------------------------* @@ -756,79 +572,32 @@ void UT_os_timergetidbyname_test() **--------------------------------------------------------------------------------*/ void UT_os_timergetinfo_test() { - int32 res = 0; - const char * testDesc; OS_timer_prop_t timerProps; /*-----------------------------------------------------*/ - testDesc = "API not implemented"; + /* #1 Null-pointer-arg */ - res = OS_TimerGetInfo(UT_OBJID_INCORRECT, &timerProps); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_timergetinfo_test_exit_tag; - } + UT_RETVAL(OS_TimerGetInfo(UT_OBJID_INCORRECT, NULL), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; + /* #2 Invalid-id-arg */ - res = OS_TimerCreate(&g_timerIds[1], g_timerNames[1], &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) - { - testDesc = "#1 Null-pointer-arg - Timer-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - if (OS_TimerGetInfo(g_timerIds[1], NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_TimerDelete(g_timerIds[1]); - } - - /*-----------------------------------------------------*/ - testDesc = "#2 Invalid-id-arg"; - - if (OS_TimerGetInfo(UT_OBJID_INCORRECT, &timerProps) == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); + UT_RETVAL(OS_TimerGetInfo(UT_OBJID_INCORRECT, &timerProps), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; + /* #3 Nominal */ - res = OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Timer-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else + if (UT_SETUP(OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback))) { memset(&timerProps, 0x00, sizeof(timerProps)); - res = OS_TimerGetInfo(g_timerIds[3], &timerProps); - if (res == OS_SUCCESS) - { - if (strcmp(timerProps.name, g_timerNames[3]) == 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - else - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } + + UT_NOMINAL(OS_TimerGetInfo(g_timerIds[3], &timerProps)); + + UtAssert_StrCmp(timerProps.name, g_timerNames[3], "%s == %s", timerProps.name, g_timerNames[3]); /* Reset test environment */ - OS_TimerDelete(g_timerIds[3]); + UT_TEARDOWN(OS_TimerDelete(g_timerIds[3])); } - -UT_os_timergetinfo_test_exit_tag: - return; } /*================================================================================* diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index 0e8ea53c8..1fb0104fb 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -55,45 +55,45 @@ add_custom_target(generate_osapi_stubs add_library(ut_osapi_stubs STATIC utstub-helpers.c osapi-binsem-stubs.c - osapi-binsem-hooks.c + osapi-binsem-handlers.c osapi-clock-stubs.c - osapi-clock-hooks.c + osapi-clock-handlers.c osapi-common-stubs.c osapi-countsem-stubs.c - osapi-countsem-hooks.c + osapi-countsem-handlers.c osapi-dir-stubs.c - osapi-dir-hooks.c + osapi-dir-handlers.c osapi-error-stubs.c - osapi-error-hooks.c + osapi-error-handlers.c osapi-file-stubs.c - osapi-file-hooks.c + osapi-file-handlers.c osapi-filesys-stubs.c - osapi-filesys-hooks.c + osapi-filesys-handlers.c osapi-heap-stubs.c - osapi-heap-hooks.c + osapi-heap-handlers.c osapi-idmap-stubs.c - osapi-idmap-hooks.c + osapi-idmap-handlers.c osapi-module-stubs.c - osapi-module-hooks.c + osapi-module-handlers.c osapi-mutex-stubs.c - osapi-mutex-hooks.c + osapi-mutex-handlers.c osapi-network-stubs.c - osapi-network-hooks.c + osapi-network-handlers.c osapi-printf-stubs.c - osapi-printf-hooks.c + osapi-printf-handlers.c osapi-queue-stubs.c - osapi-queue-hooks.c + osapi-queue-handlers.c osapi-select-stubs.c osapi-sockets-stubs.c - osapi-sockets-hooks.c + osapi-sockets-handlers.c osapi-task-stubs.c - osapi-task-hooks.c + osapi-task-handlers.c osapi-timer-stubs.c - osapi-timer-hooks.c + osapi-timer-handlers.c osapi-timebase-stubs.c - osapi-timebase-hooks.c + osapi-timebase-handlers.c osapi-version-stubs.c - osapi-version-hooks.c + osapi-version-handlers.c ) # Some of the internal API definitions in stubs are based on diff --git a/src/ut-stubs/osapi-binsem-hooks.c b/src/ut-stubs/osapi-binsem-handlers.c similarity index 100% rename from src/ut-stubs/osapi-binsem-hooks.c rename to src/ut-stubs/osapi-binsem-handlers.c diff --git a/src/ut-stubs/osapi-clock-hooks.c b/src/ut-stubs/osapi-clock-handlers.c similarity index 100% rename from src/ut-stubs/osapi-clock-hooks.c rename to src/ut-stubs/osapi-clock-handlers.c diff --git a/src/ut-stubs/osapi-countsem-hooks.c b/src/ut-stubs/osapi-countsem-handlers.c similarity index 100% rename from src/ut-stubs/osapi-countsem-hooks.c rename to src/ut-stubs/osapi-countsem-handlers.c diff --git a/src/ut-stubs/osapi-dir-hooks.c b/src/ut-stubs/osapi-dir-handlers.c similarity index 100% rename from src/ut-stubs/osapi-dir-hooks.c rename to src/ut-stubs/osapi-dir-handlers.c diff --git a/src/ut-stubs/osapi-error-hooks.c b/src/ut-stubs/osapi-error-handlers.c similarity index 100% rename from src/ut-stubs/osapi-error-hooks.c rename to src/ut-stubs/osapi-error-handlers.c diff --git a/src/ut-stubs/osapi-file-hooks.c b/src/ut-stubs/osapi-file-handlers.c similarity index 100% rename from src/ut-stubs/osapi-file-hooks.c rename to src/ut-stubs/osapi-file-handlers.c diff --git a/src/ut-stubs/osapi-filesys-hooks.c b/src/ut-stubs/osapi-filesys-handlers.c similarity index 100% rename from src/ut-stubs/osapi-filesys-hooks.c rename to src/ut-stubs/osapi-filesys-handlers.c diff --git a/src/ut-stubs/osapi-heap-hooks.c b/src/ut-stubs/osapi-heap-handlers.c similarity index 100% rename from src/ut-stubs/osapi-heap-hooks.c rename to src/ut-stubs/osapi-heap-handlers.c diff --git a/src/ut-stubs/osapi-idmap-hooks.c b/src/ut-stubs/osapi-idmap-handlers.c similarity index 100% rename from src/ut-stubs/osapi-idmap-hooks.c rename to src/ut-stubs/osapi-idmap-handlers.c diff --git a/src/ut-stubs/osapi-module-hooks.c b/src/ut-stubs/osapi-module-handlers.c similarity index 100% rename from src/ut-stubs/osapi-module-hooks.c rename to src/ut-stubs/osapi-module-handlers.c diff --git a/src/ut-stubs/osapi-mutex-hooks.c b/src/ut-stubs/osapi-mutex-handlers.c similarity index 100% rename from src/ut-stubs/osapi-mutex-hooks.c rename to src/ut-stubs/osapi-mutex-handlers.c diff --git a/src/ut-stubs/osapi-network-hooks.c b/src/ut-stubs/osapi-network-handlers.c similarity index 100% rename from src/ut-stubs/osapi-network-hooks.c rename to src/ut-stubs/osapi-network-handlers.c diff --git a/src/ut-stubs/osapi-printf-hooks.c b/src/ut-stubs/osapi-printf-handlers.c similarity index 100% rename from src/ut-stubs/osapi-printf-hooks.c rename to src/ut-stubs/osapi-printf-handlers.c diff --git a/src/ut-stubs/osapi-queue-hooks.c b/src/ut-stubs/osapi-queue-handlers.c similarity index 100% rename from src/ut-stubs/osapi-queue-hooks.c rename to src/ut-stubs/osapi-queue-handlers.c diff --git a/src/ut-stubs/osapi-sockets-hooks.c b/src/ut-stubs/osapi-sockets-handlers.c similarity index 100% rename from src/ut-stubs/osapi-sockets-hooks.c rename to src/ut-stubs/osapi-sockets-handlers.c diff --git a/src/ut-stubs/osapi-task-hooks.c b/src/ut-stubs/osapi-task-handlers.c similarity index 100% rename from src/ut-stubs/osapi-task-hooks.c rename to src/ut-stubs/osapi-task-handlers.c diff --git a/src/ut-stubs/osapi-timebase-hooks.c b/src/ut-stubs/osapi-timebase-handlers.c similarity index 100% rename from src/ut-stubs/osapi-timebase-hooks.c rename to src/ut-stubs/osapi-timebase-handlers.c diff --git a/src/ut-stubs/osapi-timer-hooks.c b/src/ut-stubs/osapi-timer-handlers.c similarity index 100% rename from src/ut-stubs/osapi-timer-hooks.c rename to src/ut-stubs/osapi-timer-handlers.c diff --git a/src/ut-stubs/osapi-version-hooks.c b/src/ut-stubs/osapi-version-handlers.c similarity index 100% rename from src/ut-stubs/osapi-version-hooks.c rename to src/ut-stubs/osapi-version-handlers.c diff --git a/ut_assert/scripts/generate_stubs.pl b/ut_assert/scripts/generate_stubs.pl index 03e3574b1..fefa2623f 100755 --- a/ut_assert/scripts/generate_stubs.pl +++ b/ut_assert/scripts/generate_stubs.pl @@ -47,7 +47,7 @@ # # By default the stubs are written to a file with the same basename and a "-stubs" suffix. # -# This script will check corresponding hook file (via the hook-suffix option) for the presence +# This script will check corresponding handler file (via the handler-suffix option) for the presence # of a handler. A reference to the handler will only be generated in the stub if it exists. # This is a convenience option to avoid rendering references to handlers that do not exist, # while still allowing the set to grow over time. @@ -60,7 +60,7 @@ # (note the result will fail to link unless handler is actually implemented) # --filter: a perl regex expression to apply on function names (e.g. /_Impl$/) # --stub-suffix: a suffix to use for the generated file names ("stubs" by default) -# --hook-suffix: a suffix to use for the generated file names ("hooks" by default) +# --handler-suffix: a suffix to use for the generated file names ("handlers" by default) # use strict; @@ -78,7 +78,7 @@ my %options = ( "stub-suffix" => 'stubs', - "hook-suffix" => 'hooks' + "handler-suffix" => 'handlers' ); my @hdrlist = grep(/\S/, map { @@ -272,7 +272,7 @@ $refname .= '_'; } my $stubfile = $refname . $options{"stub-suffix"} . '.c'; - my $hookfile = $refname . $options{"hook-suffix"} . '.c'; + my $handlerfile = $refname . $options{"handler-suffix"} . '.c'; my $handler_func = {}; my $handler_prefix = "UT_DefaultHandler_"; @@ -282,13 +282,13 @@ $handler_func->{$funcname} = $handler_prefix.$funcname; } } elsif (!$options{"no-handler"}) { - if (open(HOOK, $hookfile)) { - while () { + if (open(HANDLER, $handlerfile)) { + while () { if (/void\s+$handler_prefix(\S+)\s*\(/) { $handler_func->{$1} = $handler_prefix.$1; } } - close(HOOK); + close(HANDLER); } } diff --git a/ut_assert/src/utbsp.c b/ut_assert/src/utbsp.c index d5f1b1d1b..fde612fe4 100644 --- a/ut_assert/src/utbsp.c +++ b/ut_assert/src/utbsp.c @@ -108,6 +108,7 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) { const char *Prefix; char Buffer[16]; + size_t MsgLen; uint32 TermModeBits = OS_BSP_CONSOLEMODE_NORMAL; uint32 MsgEnabled = BSP_UT_Global.CurrVerbosity >> MessageType; @@ -182,8 +183,12 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) } OS_BSP_ConsoleOutput_Impl(" ", 1); - OS_BSP_ConsoleOutput_Impl(OutputMessage, strlen(OutputMessage)); - OS_BSP_ConsoleOutput_Impl("\n", 1); + MsgLen = strlen(OutputMessage); + OS_BSP_ConsoleOutput_Impl(OutputMessage, MsgLen); + if (MsgLen == 0 || OutputMessage[MsgLen - 1] != '\n') + { + OS_BSP_ConsoleOutput_Impl("\n", 1); + } OS_BSP_Unlock_Impl(); }