diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 000000000..3a4f0e9cd --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,54 @@ +name: Static Analysis + +# Run this workflow every time a new commit pushed to your repository +on: + push: + branches: + - main + pull_request: + +jobs: + + static-analysis: + name: Run cppcheck + runs-on: ubuntu-18.04 + + strategy: + fail-fast: false + matrix: + cppcheck: [all, osal] + + steps: + + - name: Install cppcheck + run: sudo apt-get install cppcheck -y + + # Checks out a copy of the cfs bundle + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: true + + - name: Run bundle cppcheck + if: ${{matrix.cppcheck =='all'}} + run: cppcheck --force --inline-suppr --quiet . 2> ${{matrix.cppcheck}}_cppcheck_err.txt + + # Run strict static analysis for embedded portions of osal + - name: osal strict cppcheck + if: ${{matrix.cppcheck =='osal'}} + run: | + cppcheck --force --inline-suppr --std=c99 --language=c --enable=warning,performance,portability,style --suppress=variableScope --inconclusive ./src/bsp ./src/os 2> ./${{matrix.cppcheck}}_cppcheck_err.txt + + - name: Archive Static Analysis Artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{matrix.cppcheck}}-cppcheck-err + path: ./*cppcheck_err.txt + + - name: Check for errors + run: | + if [[ -s ${{matrix.cppcheck}}_cppcheck_err.txt ]]; + then + cat ${{matrix.cppcheck}}_cppcheck_err.txt + exit -1 + fi diff --git a/README.md b/README.md index 86cd9bdee..72d57a312 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,16 @@ The autogenerated OSAL user's guide can be viewed at + ### Development Build: 5.1.0-rc1+dev132 - Convert the OSAL Configuration Guide from docx and pdf to a markdown file. diff --git a/src/os/inc/osapi-bsp.h b/src/os/inc/osapi-bsp.h index 250fb30d2..ff8f95120 100644 --- a/src/os/inc/osapi-bsp.h +++ b/src/os/inc/osapi-bsp.h @@ -91,4 +91,6 @@ char *const *OS_BSP_GetArgV(void); ------------------------------------------------------------------*/ void OS_BSP_SetExitCode(int32 code); +/**@}*/ + #endif diff --git a/src/os/inc/osapi-idmap.h b/src/os/inc/osapi-idmap.h index 4458848dc..cd93b0f3e 100644 --- a/src/os/inc/osapi-idmap.h +++ b/src/os/inc/osapi-idmap.h @@ -51,15 +51,6 @@ #define OS_OBJECT_TYPE_USER 0x10 /**< @brief Object user type */ /**@}*/ -/** @defgroup OSAPICore OSAL Core Operation APIs - * - * These are for OSAL core operations for startup/initialization, running, and shutdown. - * Typically only used in bsps, unit tests, psps, etc. - * - * Not intended for user application use - * @{ - */ - /** @defgroup OSAPIObjUtil OSAL Object ID Utility APIs * @{ */ diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index b71137902..3b17e2e7d 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -30,7 +30,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 132 +#define OS_BUILD_NUMBER 149 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index 27debe318..69f89aa0b 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -762,6 +762,7 @@ void OS_WaitForStateChange(osal_objtype_t idtype, uint32 attempts) /* * After return, this task owns the table again */ + /* cppcheck-suppress redundantAssignment */ objtype->table_owner = saved_owner_id; } } diff --git a/src/tests/select-test/select-test.c b/src/tests/select-test/select-test.c index 80c8cc5bc..bcdef177a 100644 --- a/src/tests/select-test/select-test.c +++ b/src/tests/select-test/select-test.c @@ -108,7 +108,7 @@ void Setup_Server(void) UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); /* Set server port */ - actual = OS_SocketAddrSetPort(&s_addr, 9997); + actual = OS_SocketAddrSetPort(&s_addr, 9994); UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); /* Set server address */ @@ -142,7 +142,7 @@ void Setup_Client(void) UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); /* Set client port */ - actual = OS_SocketAddrSetPort(&c_addr, 9996); + actual = OS_SocketAddrSetPort(&c_addr, 9993); UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); /* Set client address */ @@ -193,7 +193,7 @@ void Setup_Server2(void) UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); /* Set server port */ - actual = OS_SocketAddrSetPort(&s2_addr, 9998); + actual = OS_SocketAddrSetPort(&s2_addr, 9995); UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); /* Set server address */ @@ -227,7 +227,7 @@ void Setup_Client2(void) UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); /* Set client port */ - actual = OS_SocketAddrSetPort(&c2_addr, 9995); + actual = OS_SocketAddrSetPort(&c2_addr, 9992); UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); /* Set client address */ @@ -281,8 +281,8 @@ void Teardown_Multi(void) { uint32 status; - status = OS_BinSemFlush(bin_sem_id); - UtAssert_True(status == OS_SUCCESS, "BinSem1 Teardown multi flush Rc=%d", (int)status); + status = OS_BinSemGive(bin_sem_id); + UtAssert_True(status == OS_SUCCESS, "BinSem1 Teardown multi give Rc=%d", (int)status); OS_close(c2_socket_id); Teardown_Single(); diff --git a/src/unit-tests/inc/ut_os_support.h b/src/unit-tests/inc/ut_os_support.h index 147fef09f..ebdf0a974 100644 --- a/src/unit-tests/inc/ut_os_support.h +++ b/src/unit-tests/inc/ut_os_support.h @@ -109,8 +109,6 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line) /*--------------------------------------------------------------------------------*/ -#define UT_OS_LOG(...) UtAssert_Message(UTASSERT_CASETYPE_INFO, __FILE__, __LINE__, __VA_ARGS__); - /* * An osal_id_t value which is not OS_OBJECT_ID_UNDEFINED and also * not aliasing any other valid value/type. 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 f54ca186e..5d45d0fc7 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.c @@ -161,7 +161,7 @@ void UT_os_apiinit_test() void UT_os_printf_test() { OS_printf_enable(); - UT_OS_LOG("OS_printf() - #1 Nominal [This is the expected stdout output after API call]\n"); + 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); @@ -184,7 +184,7 @@ void UT_os_printfenable_test() OS_printf_disable(); OS_printf_enable(); - UT_OS_LOG("OS_printf_enable() - #1 Nominal [This is the expected stdout output after API call]\n"); + 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); @@ -205,18 +205,18 @@ void UT_os_printfenable_test() void UT_os_printfdisable_test() { OS_printf_enable(); - UT_OS_LOG("OS_printf_disable() - #1 Nominal [This is the expected stdout output before API call]\n"); + 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"); OS_printf_disable(); - UT_OS_LOG("OS_printf_disable() - #1 Nominal [This is NOT the expected stdout output after API call]\n"); + 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); /* Reset test environment */ OS_printf_enable(); - UT_OS_LOG("OS_printf_disable() - #1 Nominal [This is the expected stdout output after test reset]\n"); + 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"); } @@ -286,11 +286,11 @@ void UT_os_getlocaltime_test() res = OS_GetLocalTime(&time_struct); if (res == OS_SUCCESS) { - UT_OS_LOG("\n"); + UtPrintf("\n"); for (i = 0; i < 5; i++) { - UT_OS_LOG("OS_GetLocalTime() - #3 Nominal "); - UT_OS_LOG("[Expecting output after API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, + UtPrintf("OS_GetLocalTime() - #3 Nominal "); + UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, (long)time_struct.microsecs); OS_TaskDelay(20); @@ -378,8 +378,8 @@ void UT_os_setlocaltime_test() { for (i = 0; i < 5; i++) { - UT_OS_LOG("OS_SetLocalTime() - #3 Nominal "); - UT_OS_LOG("[Expecting output before API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, + UtPrintf("OS_SetLocalTime() - #3 Nominal "); + UtPrintf("[Expecting output before API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, (long)time_struct.microsecs); OS_TaskDelay(20); @@ -394,7 +394,7 @@ void UT_os_setlocaltime_test() res = OS_SetLocalTime(&time_struct); if (res == OS_SUCCESS) { - UT_OS_LOG("OS_SetLocalTime() - #3 Nominal [New time set at %ld.%ld]\n", (long)time_struct.seconds, + UtPrintf("OS_SetLocalTime() - #3 Nominal [New time set at %ld.%ld]\n", (long)time_struct.seconds, (long)time_struct.microsecs); res = OS_GetLocalTime(&time_struct); @@ -402,8 +402,8 @@ void UT_os_setlocaltime_test() { for (i = 0; i < 5; i++) { - UT_OS_LOG("OS_SetLocalTime() - #3 Nominal "); - UT_OS_LOG("[Expecting output after API call to increase over time: %ld.%ld]\n", + UtPrintf("OS_SetLocalTime() - #3 Nominal "); + UtPrintf("[Expecting output after API call to increase over time: %ld.%ld]\n", (long)time_struct.seconds, (long)time_struct.microsecs); OS_TaskDelay(20); 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 bb3d5b9da..ff53e9f56 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -84,7 +84,7 @@ void generic_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting GenericTask: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); + UtPrintf("Starting GenericTask: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); while (1) { @@ -322,7 +322,7 @@ void UT_os_task_delete_test() **--------------------------------------------------------------------------------*/ void delete_handler_callback(void) { - UT_OS_LOG("Task delete callback...\n"); + UtPrintf("Task delete callback...\n"); } /*--------------------------------------------------------------------------------*/ @@ -337,7 +337,7 @@ void delete_handler_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting DeleteTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); + UtPrintf("Starting DeleteTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); g_task_result = OS_TaskInstallDeleteHandler(&delete_handler_callback); @@ -443,7 +443,7 @@ void exit_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting ExitTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); + UtPrintf("Starting ExitTest Task: %s, id: %lx\n", task_prop.name, OS_ObjectIdToInteger(task_id)); /* ** The parent task will check to see if this task is valid. @@ -675,7 +675,7 @@ void register_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("Starting RegisterTest Task: %s\n", task_prop.name); + UtPrintf("Starting RegisterTest Task: %s\n", task_prop.name); ; /* @@ -775,7 +775,7 @@ void getid_test_task(void) task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); - UT_OS_LOG("OS_TaskGetId() - #1 Nominal [This is the returned task Id=%lx]\n", OS_ObjectIdToInteger(task_id)); + UtPrintf("OS_TaskGetId() - #1 Nominal [This is the returned task Id=%lx]\n", OS_ObjectIdToInteger(task_id)); while (1) { @@ -814,7 +814,7 @@ void UT_os_task_get_id_test() { OS_TaskDelay(500); - UT_OS_LOG("OS_TaskGetId() - #1 Nominal [This is the expected task Id=%lx]\n", + 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 */ 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 dbb8479a2..7ed2072f7 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -804,9 +804,9 @@ void UT_os_readfile_test() OS_close(g_fDescs[0]); OS_remove(g_fNames[0]); - UT_OS_LOG("OS_read() success test -- Write to file:\n\t%s\n", g_writeBuff); + UtPrintf("OS_read() success test -- Write to file:\n\t%s\n", g_writeBuff); ; - UT_OS_LOG("OS_read() success test -- Read from file:\n\t%s\n", g_readBuff); + UtPrintf("OS_read() success test -- Read from file:\n\t%s\n", g_readBuff); ; UT_os_readfile_test_exit_tag: @@ -975,9 +975,9 @@ void UT_os_writefile_test() OS_close(g_fDescs[0]); OS_remove(g_fNames[0]); - UT_OS_LOG("OS_write() success test -- Write to file:\n\t%s\n", g_writeBuff); + UtPrintf("OS_write() success test -- Write to file:\n\t%s\n", g_writeBuff); ; - UT_OS_LOG("OS_write() success test -- Read from file:\n\t%s\n", g_readBuff); + UtPrintf("OS_write() success test -- Read from file:\n\t%s\n", g_readBuff); ; UT_os_writefile_test_exit_tag: diff --git a/src/unit-tests/osfile-test/ut_osfile_test.c b/src/unit-tests/osfile-test/ut_osfile_test.c index fc6d6cea3..925fdb612 100644 --- a/src/unit-tests/osfile-test/ut_osfile_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_test.c @@ -79,7 +79,7 @@ int32 UT_os_setup_fs() res = OS_mkfs(g_fsAddrPtr, g_devName, "RAM3", OSAL_SIZE_C(512), OSAL_BLOCKCOUNT_C(64)); if (res != OS_SUCCESS) { - UT_OS_LOG("OS_mkfs() returns %d\n", (int)res); + UtPrintf("OS_mkfs() returns %d\n", (int)res); ; goto UT_os_setup_fs_exit_tag; } @@ -87,7 +87,7 @@ int32 UT_os_setup_fs() res = OS_mount(g_devName, g_mntName); if (res != OS_SUCCESS) { - UT_OS_LOG("OS_mount() returns %d\n", (int)res); + UtPrintf("OS_mount() returns %d\n", (int)res); ; OS_rmfs(g_devName); goto UT_os_setup_fs_exit_tag; 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 400695917..1ce269883 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c @@ -105,7 +105,7 @@ void UT_os_networkgetid_test() /* NOTE: This API does not return error codes. * Any return value could be valid */ - UT_OS_LOG("OS_NetworkGetID() return value=%ld", (long)res); + UtPrintf("OS_NetworkGetID() return value=%ld", (long)res); UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_MIR); UT_os_networkgetid_test_exit_tag: 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 94e8060e5..304da7d6b 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c @@ -550,7 +550,7 @@ void UT_os_timerset_test() intervalTime = 5; g_toleranceVal = 0; - UT_OS_LOG("\nOS_TimerSet() - #3 Interval-too-short (clk_accuracy=%d)\n", (int)g_clkAccuracy); + 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) { @@ -588,7 +588,7 @@ void UT_os_timerset_test() startTime = 1000; intervalTime = 500000; g_toleranceVal = intervalTime / 20; /* 5% */ - UT_OS_LOG("\nOS_TimerSet() - #1 Nominal condition (clk_accuracy=%d)\n", (int)g_clkAccuracy); + 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) { diff --git a/ut_assert/inc/utassert.h b/ut_assert/inc/utassert.h index 87ebf9a14..08969e3bb 100644 --- a/ut_assert/inc/utassert.h +++ b/ut_assert/inc/utassert.h @@ -206,7 +206,7 @@ typedef struct } while (0) /** - * \brief Confirm an integer value is nonzero + * \brief Confirm an integer value is zero */ #define UtAssert_ZERO(actual) \ do \ @@ -272,13 +272,20 @@ bool UtAssertEx(bool Expression, UtAssert_CaseType_t CaseType, const char *File, void UtAssert_Abort(const char *Message); /** - * Output an informational message to the console/log file + * \brief Output an informational message to the console/log file * * Just like the standard printf except it will output to the given status channel (see utassert.h) * * This calls into the UT BSP function to actually write the message * to the current output device. This may be the console or a log file * or something else depending on what BSP is in use. + * + * \param MessageType Message case type + * \param File File name containing the message + * \param Line Line number containing the message + * \param Spec printf style format followed by args of message + * + * \sa Helper macros: UtPrintf(), UtDebug() */ void UtAssert_Message(uint8 MessageType, const char *File, uint32 Line, const char *Spec, ...) OS_PRINTF(4, 5); @@ -292,7 +299,7 @@ void UtAssert_Message(uint8 MessageType, const char *File, uint32 Line, const ch * * \param File File containing the test case * \param LineNum Line number containing the test case - * \param MessageType Should be set to either UT_MESSAGE_PASS or UT_MESSAGE_FAILURE. + * \param MessageType Message case type * \param SubsysName The subsystem under test (abbreviated name) * \param ShortDesc Short description of the test case * \param SegmentNum Sequence among the overall/global test Segments