diff --git a/fsw/modules/rtems_sysmon/rtems_sysmon.c b/fsw/modules/rtems_sysmon/rtems_sysmon.c index 8b9b355a..95fa9f56 100644 --- a/fsw/modules/rtems_sysmon/rtems_sysmon.c +++ b/fsw/modules/rtems_sysmon/rtems_sysmon.c @@ -23,7 +23,6 @@ /************************************************************************ * Includes ************************************************************************/ - #include "cfe_psp.h" #include "iodriver_impl.h" @@ -33,73 +32,12 @@ #include #include #include - -/******************************************************************** - * Local Defines - ********************************************************************/ -#ifdef OS_MAXIMUM_PROCESSORS - #define RTEMS_SYSMON_MAX_CPUS OS_MAXIMUM_PROCESSORS -#else - #define RTEMS_SYSMON_MAX_CPUS 1 -#endif - -#define RTEMS_SYSMON_AGGREGATE_SUBSYS 0 -#define RTEMS_SYSMON_CPULOAD_SUBSYS 1 -#define RTEMS_SYSMON_AGGR_CPULOAD_SUBCH 0 -#define RTEMS_SYSMON_SAMPLE_DELAY 1000 -#define RTEMS_SYSMON_TASK_PRIORITY 100 -#define RTEMS_SYSMON_STACK_SIZE 4096 -#define RTEMS_SYSMON_MAX_SCALE 100000 - -#ifdef DEBUG_BUILD -#define RTEMS_SYSMON_DEBUG(...) OS_printf(__VA_ARGS__) -#else -#define RTEMS_SYSMON_DEBUG(...) -#endif - -/******************************************************************** - * Local Type Definitions - ********************************************************************/ -typedef struct rtems_sysmon_cpuload_core -{ - CFE_PSP_IODriver_AdcCode_t avg_load; - Timestamp_Control last_run_time; - Timestamp_Control idle_last_uptime; - -} rtems_sysmon_cpuload_core_t; - -typedef struct rtems_sysmon_cpuload_state -{ - volatile bool is_running; - volatile bool should_run; - - rtems_id task_id; - rtems_name task_name; - - uint8_t num_cpus; - rtems_sysmon_cpuload_core_t per_core[RTEMS_SYSMON_MAX_CPUS]; - -} rtems_sysmon_cpuload_state_t; - -typedef struct rtems_sysmon_state -{ - uint32_t local_module_id; - rtems_sysmon_cpuload_state_t cpu_load; -} rtems_sysmon_state_t; +#include "rtems_sysmon.h" /******************************************************************** * Local Function Prototypes ********************************************************************/ static void rtems_sysmon_Init(uint32_t local_module_id); -static int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state); -static int32_t rtems_sysmon_Stop(rtems_sysmon_cpuload_state_t *state); - -int32_t rtems_sysmon_aggregate_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg); -int32_t rtems_sysmon_calc_aggregate_cpu(rtems_sysmon_cpuload_state_t *state, CFE_PSP_IODriver_AdcCode_t *Val); - -/* Function that starts up rtems_sysmon driver. */ -static int32_t rtems_sysmon_DevCmd(uint32_t CommandCode, uint16_t SubsystemId, uint16_t SubchannelId, - CFE_PSP_IODriver_Arg_t Arg); /******************************************************************** * Global Data @@ -112,7 +50,7 @@ CFE_PSP_IODriver_API_t rtems_sysmon_DevApi = {.DeviceCommand = rtems_sysmon_DevC CFE_PSP_MODULE_DECLARE_IODEVICEDRIVER(rtems_sysmon); -static rtems_sysmon_state_t rtems_sysmon_global; +rtems_sysmon_state_t rtems_sysmon_global; static const char *rtems_sysmon_subsystem_names[] = {"aggregate", "per-cpu", NULL}; static const char *rtems_sysmon_subchannel_names[] = {"cpu-load", NULL}; @@ -127,7 +65,7 @@ void rtems_sysmon_Init(uint32_t local_module_id) rtems_sysmon_global.local_module_id = local_module_id; } -static bool rtems_cpu_usage_vistor(Thread_Control *the_thread, void *arg) +bool rtems_cpu_usage_visitor(Thread_Control *the_thread, void *arg) { rtems_sysmon_cpuload_state_t *state = (rtems_sysmon_cpuload_state_t *)arg; rtems_sysmon_cpuload_core_t* core_p = &state->per_core[state->num_cpus]; @@ -213,7 +151,7 @@ static bool rtems_cpu_usage_vistor(Thread_Control *the_thread, void *arg) void rtems_sysmon_update_stat(rtems_sysmon_cpuload_state_t *state) { state->num_cpus = 0; - rtems_task_iterate( rtems_cpu_usage_vistor, state); + rtems_task_iterate( rtems_cpu_usage_visitor, state); } rtems_task rtems_sysmon_Task(rtems_task_argument arg) @@ -246,7 +184,7 @@ rtems_task rtems_sysmon_Task(rtems_task_argument arg) * Starts the cpu load watcher function * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state) +int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state) { int32_t StatusCode; rtems_status_code status; @@ -453,6 +391,12 @@ int32_t rtems_sysmon_cpu_load_dispatch(uint32_t CommandCode, uint16_t Subchannel { RdWr->Samples[ch] = state->per_core[ch].avg_load; } + + StatusCode = CFE_PSP_SUCCESS; + } + else + { + StatusCode = CFE_PSP_ERROR; } break; diff --git a/fsw/modules/rtems_sysmon/rtems_sysmon.h b/fsw/modules/rtems_sysmon/rtems_sysmon.h new file mode 100644 index 00000000..43b43437 --- /dev/null +++ b/fsw/modules/rtems_sysmon/rtems_sysmon.h @@ -0,0 +1,101 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2023 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * + * Internal header for rtems_sysmon.c + */ + +#ifndef RTEMS_SYSMON_H_ +#define RTEMS_SYSMON_H_ + +/******************************************************************** + * Local Defines + ********************************************************************/ +#ifdef OS_MAXIMUM_PROCESSORS + #define RTEMS_SYSMON_MAX_CPUS OS_MAXIMUM_PROCESSORS +#else + #define RTEMS_SYSMON_MAX_CPUS 1 +#endif + +#define RTEMS_SYSMON_AGGREGATE_SUBSYS 0 +#define RTEMS_SYSMON_CPULOAD_SUBSYS 1 +#define RTEMS_SYSMON_AGGR_CPULOAD_SUBCH 0 +#define RTEMS_SYSMON_SAMPLE_DELAY 1000 +#define RTEMS_SYSMON_TASK_PRIORITY 100 +#define RTEMS_SYSMON_STACK_SIZE 4096 +#define RTEMS_SYSMON_MAX_SCALE 100000 + +#ifdef DEBUG_BUILD +#define RTEMS_SYSMON_DEBUG(...) OS_printf(__VA_ARGS__) +#else +#define RTEMS_SYSMON_DEBUG(...) +#endif + + +/******************************************************************** + * Local Type Definitions + ********************************************************************/ +typedef struct rtems_sysmon_cpuload_core +{ + CFE_PSP_IODriver_AdcCode_t avg_load; + Timestamp_Control last_run_time; + Timestamp_Control idle_last_uptime; + +} rtems_sysmon_cpuload_core_t; + +typedef struct rtems_sysmon_cpuload_state +{ + volatile bool is_running; + volatile bool should_run; + + rtems_id task_id; + rtems_name task_name; + + uint8_t num_cpus; + rtems_sysmon_cpuload_core_t per_core[RTEMS_SYSMON_MAX_CPUS]; + +} rtems_sysmon_cpuload_state_t; + +typedef struct rtems_sysmon_state +{ + uint32_t local_module_id; + rtems_sysmon_cpuload_state_t cpu_load; +} rtems_sysmon_state_t; + + +/******************************************************************** + * Local Function Prototypes + ********************************************************************/ +rtems_task rtems_sysmon_Task(rtems_task_argument arg); +void rtems_sysmon_update_stat(rtems_sysmon_cpuload_state_t *state); +bool rtems_cpu_usage_visitor(Thread_Control *the_thread, void *arg); + +int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state); +int32_t rtems_sysmon_Stop(rtems_sysmon_cpuload_state_t *state); + +int32_t rtems_sysmon_aggregate_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg); +int32_t rtems_sysmon_calc_aggregate_cpu(rtems_sysmon_cpuload_state_t *state, CFE_PSP_IODriver_AdcCode_t *Val); + +/* Function that starts up rtems_sysmon driver. */ +int32_t rtems_sysmon_DevCmd(uint32_t CommandCode, uint16_t SubsystemId, uint16_t SubchannelId, + CFE_PSP_IODriver_Arg_t Arg); + + +#endif /* RTEMS_SYSMON_H_ */ diff --git a/unit-test-coverage/modules/CMakeLists.txt b/unit-test-coverage/modules/CMakeLists.txt index 44207b3b..447f4f6c 100644 --- a/unit-test-coverage/modules/CMakeLists.txt +++ b/unit-test-coverage/modules/CMakeLists.txt @@ -71,6 +71,7 @@ endfunction() # a list of modules for which there is a coverage test implemented add_subdirectory(timebase_vxworks) add_subdirectory(vxworks_sysmon) +add_subdirectory(rtems_sysmon) add_subdirectory(ram_notimpl) add_subdirectory(ram_direct) add_subdirectory(port_notimpl) diff --git a/unit-test-coverage/modules/rtems_sysmon/CMakeLists.txt b/unit-test-coverage/modules/rtems_sysmon/CMakeLists.txt index 91d5ab4e..0d4e5808 100644 --- a/unit-test-coverage/modules/rtems_sysmon/CMakeLists.txt +++ b/unit-test-coverage/modules/rtems_sysmon/CMakeLists.txt @@ -1,6 +1,6 @@ ###################################################################### # -# CMAKE build recipe for white-box coverage tests of VxWorks timebase module +# CMAKE build recipe for white-box coverage tests of rtems_sysmon # add_definitions(-D_CFE_PSP_MODULE_) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc") @@ -8,5 +8,6 @@ include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/iodriver/inc") include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/rtems_sysmon") add_psp_covtest(rtems_sysmon src/coveragetest-rtems_sysmon.c + src/coveragetest-rtems_sysmon_utils.c ${CFEPSP_SOURCE_DIR}/fsw/modules/rtems_sysmon/rtems_sysmon.c ) diff --git a/unit-test-coverage/modules/rtems_sysmon/coveragetest-rtems_sysmon.c b/unit-test-coverage/modules/rtems_sysmon/coveragetest-rtems_sysmon.c deleted file mode 100644 index 14875710..00000000 --- a/unit-test-coverage/modules/rtems_sysmon/coveragetest-rtems_sysmon.c +++ /dev/null @@ -1,758 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 United States Government as represented by the - * Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ************************************************************************/ - -/* - * - * Copyright (c) 2020, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - * - */ - -/** - * \file - * \ingroup modules - * - * Coverage test for VxWorks timebase module implementation - */ - -#include "utassert.h" -#include "utstubs.h" -#include "uttest.h" - -#include "cfe_psp.h" -#include "cfe_psp_config.h" -#include "cfe_psp_module.h" - -#include "PCS_arch_ppc_vxPpcLib.h" - -/* - * Reference to the API entry point for the module - */ -extern CFE_PSP_ModuleApi_t CFE_PSP_timebase_vxworks_API; - -const CFE_PSP_ModuleApi_t *TgtAPI = &CFE_PSP_timebase_vxworks_API; - -UT_PSP_TimeBase_VxWorks_TestConfig_t UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG; - -typedef struct -{ - uint32 u; - uint32 l; -} PSP_VxWorks_TimeBaseVal_t; - -void ModuleTest_ResetState(void) -{ - memset(&UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG, 0, sizeof(UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG)); -} - -int32 UTHOOK_vxTimeBaseGet(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - PSP_VxWorks_TimeBaseVal_t *val = UserObj; - uint32 * u = UT_Hook_GetArgValueByName(Context, "u", uint32 *); - uint32 * l = UT_Hook_GetArgValueByName(Context, "l", uint32 *); - - *u = val->u; - *l = val->l; - - return StubRetcode; -} - -void Test_Nominal(void) -{ - OS_time_t OsTime; - PSP_VxWorks_TimeBaseVal_t VxTime; - - memset(&OsTime, 0, sizeof(OsTime)); - - /* Nominal test with a simple 1:1 ratio */ - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 1; - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 1; - TgtAPI->Init(0); - UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 1000000000); - - /* Check operation of CFE_PSP_GetTime() */ - UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime); - VxTime.u = 0; - VxTime.l = 10000; - CFE_PSP_GetTime(&OsTime); - - UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(OsTime), 10000); -} - -void Test_Non_Reducible(void) -{ - OS_time_t OsTime; - PSP_VxWorks_TimeBaseVal_t VxTime; - int64 TestTime; - - memset(&OsTime, 0, sizeof(OsTime)); - - /* Use an oddball ratio of of some primes, will not be reducible */ - /* Ratio is 43*3 / 53*2 => 129/106 */ - /* This translates to about ~1.217ns per tick */ - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 43 * 3; - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 53 * 2; - TgtAPI->Init(0); - UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 821705426); - - /* - * Check operation of CFE_PSP_GetTime() - * - * This test requires that the conversion uses the actual ratio, - * otherwise a rounding error will be noticed. - * For example: - * Conversion using 1.217ns/tick yields 52269758 usec (wrong). - * Conversion using actual ratio yields 52268947 usec. - */ - - UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime); - VxTime.u = 10; - VxTime.l = 5000; - CFE_PSP_GetTime(&OsTime); - - TestTime = OS_TimeGetTotalMicroseconds(OsTime); - UtAssert_True(TestTime == 52268947, "CFE_PSP_GetTime() Microseconds (%lld) == 52268947", (long long)TestTime); -} - -void Test_Reducible_1(void) -{ - OS_time_t OsTime; - PSP_VxWorks_TimeBaseVal_t VxTime; - int64 TestTime; - - memset(&OsTime, 0, sizeof(OsTime)); - - /* Test with a ratio that is also 1:1, but can be reduced */ - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 1000; - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 1000; - TgtAPI->Init(0); - UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 1000000000); - - /* - * Check operation of CFE_PSP_GetTime() - * - * Externally calculated value should be 10376293541461622 usec. - * If overflow occurs then value will be wrong. - */ - UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime); - VxTime.u = 0x90000000; /* nearing 64-bit limit */ - VxTime.l = 0; - CFE_PSP_GetTime(&OsTime); - - TestTime = OS_TimeGetTotalMicroseconds(OsTime); - UtAssert_True(TestTime == 10376293541461622, "CFE_PSP_GetTime() Microseconds (%lld) == 10376293541461622", - (long long)TestTime); -} - -void Test_Reducible_2(void) -{ - OS_time_t OsTime; - PSP_VxWorks_TimeBaseVal_t VxTime; - int64 TestTime; - - memset(&OsTime, 0, sizeof(OsTime)); - - /* Test with a ratio that can be reduced */ - /* Final reduced ratio should be 12:5 with 100ns OS ticks */ - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 84000; - UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 350; - TgtAPI->Init(0); - UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 4166666); - - /* - * Check operation of CFE_PSP_GetTime() - * - * Externally calculated value should be 276701161105643274 usec. - * If overflow occurs then value will be wrong. - */ - UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime); - VxTime.u = 0x10000000; /* nearing 64-bit limit */ - VxTime.l = 0; - CFE_PSP_GetTime(&OsTime); - - TestTime = OS_TimeGetTotalMicroseconds(OsTime); - UtAssert_True(TestTime == 276701161105643274, "CFE_PSP_GetTime() Microseconds(%lld) == 276701161105643274", - (long long)TestTime); -} - -void Test_Rollover(void) -{ - /* This function always returns 0 */ - UtAssert_UINT32_EQ(CFE_PSP_GetTimerLow32Rollover(), 0); -} - -/****************************************************************************** -** -** Purpose: -** Provides a common interface to system timebase. This routine -** is in the BSP because it is sometimes implemented in hardware and -** sometimes taken care of by the RTOS. -** -** Arguments: -** -** Return: -** Timebase register value -*/ -void Test_Get_Timebase(void) -{ - PSP_VxWorks_TimeBaseVal_t VxTime; - uint32 tbu; - uint32 tbl; - - /* The value from vxTimeBaseGet() should be passed through unchanged */ - UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime); - VxTime.u = 0x00112233; - VxTime.l = 0x44556677; - - CFE_PSP_Get_Timebase(&tbu, &tbl); - - UtAssert_UINT32_EQ(tbu, VxTime.u); - UtAssert_UINT32_EQ(tbl, VxTime.l); -} - -/* - * Macro to add a test case to the list of tests to execute - */ -#define ADD_TEST(test) UtTest_Add(test, ModuleTest_ResetState, NULL, #test) - -/* - * Register the test cases to execute with the unit test tool - */ -void UtTest_Setup(void) -{ - ADD_TEST(Test_Nominal); - ADD_TEST(Test_Non_Reducible); - ADD_TEST(Test_Reducible_1); - ADD_TEST(Test_Reducible_2); - ADD_TEST(Test_Rollover); - ADD_TEST(Test_Get_Timebase); -} -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: - * Draco - * - * Copyright (c) 2023 United States Government as represented by the - * Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ************************************************************************/ -/* - * Based on RTEMS5 cpuusagereport.c - */ - -/************************************************************************ - * Includes - ************************************************************************/ - -#include "cfe_psp.h" - -#include "iodriver_impl.h" -#include "iodriver_analog_io.h" - -#include -#include -#include -#include - -/******************************************************************** - * Local Defines - ********************************************************************/ -#ifdef OS_MAXIMUM_PROCESSORS -#define RTEMS_SYSMON_MAX_CPUS OS_MAXIMUM_PROCESSORS -#else -#define RTEMS_SYSMON_MAX_CPUS 1 -#endif - -#define RTEMS_SYSMON_AGGREGATE_SUBSYS 0 -#define RTEMS_SYSMON_CPULOAD_SUBSYS 1 -#define RTEMS_SYSMON_AGGR_CPULOAD_SUBCH 0 -#define RTEMS_SYSMON_SAMPLE_DELAY 1000 -#define RTEMS_SYSMON_TASK_PRIORITY 100 -#define RTEMS_SYSMON_STACK_SIZE 4096 -#define RTEMS_SYSMON_MAX_SCALE 100000 - -#ifdef DEBUG_BUILD -#define RTEMS_SYSMON_DEBUG(...) OS_printf(__VA_ARGS__) -#else -#define RTEMS_SYSMON_DEBUG(...) -#endif - -/******************************************************************** - * Local Type Definitions - ********************************************************************/ -typedef struct rtems_sysmon_cpuload_core -{ - CFE_PSP_IODriver_AdcCode_t avg_load; - Timestamp_Control last_run_time; - Timestamp_Control idle_last_uptime; - -} rtems_sysmon_cpuload_core_t; - -typedef struct rtems_sysmon_cpuload_state -{ - volatile bool is_running; - volatile bool should_run; - - rtems_id task_id; - rtems_name task_name; - - uint8_t num_cpus; - rtems_sysmon_cpuload_core_t per_core[RTEMS_SYSMON_MAX_CPUS]; - -} rtems_sysmon_cpuload_state_t; - -typedef struct rtems_sysmon_state -{ - uint32_t local_module_id; - rtems_sysmon_cpuload_state_t cpu_load; -} rtems_sysmon_state_t; - -/******************************************************************** - * Local Function Prototypes - ********************************************************************/ -static void rtems_sysmon_Init(uint32_t local_module_id); -static int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state); -static int32_t rtems_sysmon_Stop(rtems_sysmon_cpuload_state_t *state); - -int32_t rtems_sysmon_aggregate_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg); -int32_t rtems_sysmon_calc_aggregate_cpu(rtems_sysmon_cpuload_state_t *state, CFE_PSP_IODriver_AdcCode_t *Val); - -/* Function that starts up rtems_sysmon driver. */ -static int32_t rtems_sysmon_DevCmd(uint32_t CommandCode, uint16_t SubsystemId, uint16_t SubchannelId, - CFE_PSP_IODriver_Arg_t Arg); - -/******************************************************************** - * Global Data - ********************************************************************/ -/* This object provides the uptime timestamp at the last CPU usage reset. */ -extern Timestamp_Control CPU_usage_Uptime_at_last_reset; - -/* rtems_sysmon device command that is called by iodriver to start up rtems_sysmon */ -CFE_PSP_IODriver_API_t rtems_sysmon_DevApi = {.DeviceCommand = rtems_sysmon_DevCmd}; - -CFE_PSP_MODULE_DECLARE_IODEVICEDRIVER(rtems_sysmon); - -static rtems_sysmon_state_t rtems_sysmon_global; - -static const char *rtems_sysmon_subsystem_names[] = {"aggregate", "per-cpu", NULL}; -static const char *rtems_sysmon_subchannel_names[] = {"cpu-load", NULL}; - -/*********************************************************************** - * Global Functions - ********************************************************************/ -void rtems_sysmon_Init(uint32_t local_module_id) -{ - memset(&rtems_sysmon_global, 0, sizeof(rtems_sysmon_global)); - - rtems_sysmon_global.local_module_id = local_module_id; -} - -static bool rtems_cpu_usage_vistor(Thread_Control *the_thread, void *arg) -{ - rtems_sysmon_cpuload_state_t *state = (rtems_sysmon_cpuload_state_t *)arg; - rtems_sysmon_cpuload_core_t * core_p = &state->per_core[state->num_cpus]; - - Timestamp_Control uptime_at_last_calc = core_p->last_run_time; - Timestamp_Control idle_uptime_at_last_calc = core_p->idle_last_uptime; - Timestamp_Control current_uptime; - Timestamp_Control idle_task_uptime; - Timestamp_Control idle_uptime_elapsed; - Timestamp_Control total_elapsed; - - char name[38]; - uint32_t ival; - uint32_t fval; - bool status = false; - - _Thread_Get_name(the_thread, name, sizeof(name)); - if (strncmp("IDLE", name, 4) == 0) - { -#if __RTEMS_MAJOR__ == 5 - _Thread_Get_CPU_time_used(the_thread, &idle_task_uptime); -#else /* RTEMS 6 */ - idle_task_uptime = _Thread_Get_CPU_time_used_after_last_reset(the_thread); -#endif - - _TOD_Get_uptime(¤t_uptime); - _Timestamp_Subtract(&idle_uptime_at_last_calc, &idle_task_uptime, &idle_uptime_elapsed); - _Timestamp_Subtract(&uptime_at_last_calc, ¤t_uptime, &total_elapsed); - _Timestamp_Divide(&idle_uptime_elapsed, &total_elapsed, &ival, - &fval); /* ival - points to the integer portion */ - /* fval - points to the thousandths of percentage */ - - core_p->last_run_time = current_uptime; - core_p->idle_last_uptime = idle_task_uptime; - - if (ival >= 100) - { - core_p->avg_load = 0xFFFFFF; /* max */ - } - else if (total_elapsed == 0) - { - core_p->avg_load = 0; - } - else - { - while (fval > 999) - { - fval /= 10; - } /* Keep 3 most significant digits. Should not occur. */ - core_p->avg_load = (RTEMS_SYSMON_MAX_SCALE - ((ival * 1000) + fval)); /* Get percentages as integer */ - - /* - ** Mimic ADC so that "analogio" API can be used with out modification. API assumes 24 bits. - ** First calculate out of 0x1000 and then duplicate it to expand to 24 bits. Doing this prevents - ** an overflow. avg_load has a "real" resolution of 12 bits. - */ - core_p->avg_load = (0x1000 * core_p->avg_load) / RTEMS_SYSMON_MAX_SCALE; - core_p->avg_load |= (core_p->avg_load << 12); - } - -#ifdef DEBUG_BUILD - rtems_cpu_usage_report(); - - uint32_t microsec = _Timestamp_Get_nanoseconds(&idle_uptime_elapsed) / TOD_NANOSECONDS_PER_MICROSECOND; - uint32_t sec = _Timestamp_Get_seconds(&idle_uptime_elapsed); - RTEMS_SYSMON_DEBUG("\nCFE_PSP(rtems_sysmon): IDLE cpu time elapsed = %7u.%06u, IDLE percentages =%4u.%03u\n", - sec, microsec, ival, fval); - - microsec = _Timestamp_Get_nanoseconds(&total_elapsed) / TOD_NANOSECONDS_PER_MICROSECOND; - sec = _Timestamp_Get_seconds(&total_elapsed); - RTEMS_SYSMON_DEBUG("CFE_PSP(rtems_sysmon): Total elapsed CPU time = %7u.%06u, CPU Load =%08X\n", sec, microsec, - core_p->avg_load); -#endif - - state->num_cpus++; - if (state->num_cpus >= RTEMS_SYSMON_MAX_CPUS) - { - /* stop checking when all idle tasks has been found */ - status = true; - } - } - - /* return true to exit iterating tasks */ - return status; -} - -void rtems_sysmon_update_stat(rtems_sysmon_cpuload_state_t *state) -{ - state->num_cpus = 0; - rtems_task_iterate(rtems_cpu_usage_vistor, state); -} - -rtems_task rtems_sysmon_Task(rtems_task_argument arg) -{ - rtems_sysmon_cpuload_state_t *state = (rtems_sysmon_cpuload_state_t *)arg; - int i; - - /* Initialize */ - rtems_cpu_usage_reset(); - - memset(state->per_core, 0, RTEMS_SYSMON_MAX_CPUS * sizeof(rtems_sysmon_cpuload_core_t)); - for (i = 0; i < RTEMS_SYSMON_MAX_CPUS; i++) - { - state->per_core[i].last_run_time = CPU_usage_Uptime_at_last_reset; - } - - while (state->should_run) - { - - OS_TaskDelay(RTEMS_SYSMON_SAMPLE_DELAY); - rtems_sysmon_update_stat(state); - } - - rtems_task_delete(RTEMS_SELF); -} - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * rtems_sysmon_Start() - * ------------------------------------------------------ - * Starts the cpu load watcher function - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static int32_t rtems_sysmon_Start(rtems_sysmon_cpuload_state_t *state) -{ - int32_t StatusCode; - rtems_status_code status; - - if (state->is_running) - { - /* already running, nothing to do */ - StatusCode = CFE_PSP_SUCCESS; - } - else - { - /* start clean */ - memset(state, 0, sizeof(*state)); - StatusCode = CFE_PSP_ERROR; - - state->should_run = true; - state->task_name = rtems_build_name('R', 'S', 'M', ' '); - status = rtems_task_create(state->task_name, RTEMS_SYSMON_TASK_PRIORITY, RTEMS_SYSMON_STACK_SIZE, - RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &state->task_id); - if (status != RTEMS_SUCCESSFUL) - { - perror("rtems_task_create()"); - state->should_run = false; - } - else - { - status = rtems_task_start(state->task_id, rtems_sysmon_Task, (rtems_task_argument)state); - if (status != RTEMS_SUCCESSFUL) - { - perror("rtems_task_start()"); - rtems_task_delete(state->task_id); - state->should_run = false; - } - else - { - OS_printf("CFE_PSP(RTEMS_SysMon): Started CPU utilization monitoring\n"); - - StatusCode = CFE_PSP_SUCCESS; - state->is_running = true; - } - } - } - return StatusCode; -} - -int32_t rtems_sysmon_Stop(rtems_sysmon_cpuload_state_t *state) -{ - if (state->is_running) - { - state->should_run = false; - state->is_running = false; - rtems_task_delete(state->task_id); - } - - return CFE_PSP_SUCCESS; -} - -int32_t rtems_sysmon_calc_aggregate_cpu(rtems_sysmon_cpuload_state_t *state, CFE_PSP_IODriver_AdcCode_t *Val) -{ - - uint8_t cpu; - uint32_t sum; - - sum = 0; - for (cpu = 0; cpu < RTEMS_SYSMON_MAX_CPUS; cpu++) - { - sum += state->per_core[cpu].avg_load; - } - - sum /= RTEMS_SYSMON_MAX_CPUS; - *Val = sum; - - RTEMS_SYSMON_DEBUG("CFE_PSP(rtems_sysmon): Aggregate CPU load=%08X\n", (unsigned int)sum); - - return CFE_PSP_SUCCESS; -} - -int32_t rtems_sysmon_aggregate_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg) -{ - int32_t StatusCode; - rtems_sysmon_cpuload_state_t *state; - - /* There is just one global cpuload object */ - state = &rtems_sysmon_global.cpu_load; - - StatusCode = CFE_PSP_ERROR_NOT_IMPLEMENTED; - switch (CommandCode) - { - case CFE_PSP_IODriver_NOOP: - case CFE_PSP_IODriver_ANALOG_IO_NOOP: - RTEMS_SYSMON_DEBUG("CFE_PSP(RTEMS_SysMon): Noop \n"); - break; - case CFE_PSP_IODriver_SET_RUNNING: - { - if (Arg.U32) - { - StatusCode = rtems_sysmon_Start(state); - } - else - { - StatusCode = rtems_sysmon_Stop(state); - } - break; - } - case CFE_PSP_IODriver_GET_RUNNING: - { - StatusCode = state->is_running; - break; - } - case CFE_PSP_IODriver_SET_CONFIGURATION: /**< const string argument (device-dependent content) */ - case CFE_PSP_IODriver_GET_CONFIGURATION: /**< void * argument (device-dependent content) */ - { - /* not implemented for now */ - break; - } - case CFE_PSP_IODriver_LOOKUP_SUBSYSTEM: /**< const char * argument, looks up name and returns positive - value for subsystem number, negative value for error */ - { - uint16_t i; - - for (i = 0; rtems_sysmon_subsystem_names[i] != NULL; ++i) - { - if (strcmp(Arg.ConstStr, rtems_sysmon_subsystem_names[i]) == 0) - { - StatusCode = i; - break; - } - } - - break; - } - case CFE_PSP_IODriver_LOOKUP_SUBCHANNEL: /**< const char * argument, looks up name and returns positive - value for channel number, negative value for error */ - { - uint16_t i; - - for (i = 0; rtems_sysmon_subchannel_names[i] != NULL; ++i) - { - if (strcmp(Arg.ConstStr, rtems_sysmon_subchannel_names[i]) == 0) - { - StatusCode = i; - break; - } - } - - break; - } - case CFE_PSP_IODriver_QUERY_DIRECTION: /**< CFE_PSP_IODriver_Direction_t argument */ - { - CFE_PSP_IODriver_Direction_t *DirPtr = (CFE_PSP_IODriver_Direction_t *)Arg.Vptr; - if (DirPtr != NULL) - { - *DirPtr = CFE_PSP_IODriver_Direction_INPUT_ONLY; - StatusCode = CFE_PSP_SUCCESS; - } - break; - } - case CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS: - { - CFE_PSP_IODriver_AnalogRdWr_t *RdWr = Arg.Vptr; - - if (RdWr->NumChannels == 1 && Subchannel == RTEMS_SYSMON_AGGR_CPULOAD_SUBCH) - { - StatusCode = rtems_sysmon_calc_aggregate_cpu(state, RdWr->Samples); - } - break; - } - default: - break; - } - - return StatusCode; -} - -int32_t rtems_sysmon_cpu_load_dispatch(uint32_t CommandCode, uint16_t Subchannel, CFE_PSP_IODriver_Arg_t Arg) -{ - int32_t StatusCode; - rtems_sysmon_cpuload_state_t *state; - - /* There is just one global cpuload object */ - state = &rtems_sysmon_global.cpu_load; - StatusCode = CFE_PSP_ERROR_NOT_IMPLEMENTED; - switch (CommandCode) - { - case CFE_PSP_IODriver_NOOP: - case CFE_PSP_IODriver_ANALOG_IO_NOOP: - { - /* NO-OP should return success - - * This is a required opcode as "generic" clients may use it to - * determine if a certain set of opcodes are supported or not - */ - StatusCode = CFE_PSP_SUCCESS; - break; - } - case CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS: - { - CFE_PSP_IODriver_AnalogRdWr_t *RdWr = Arg.Vptr; - uint32_t ch; - - if (Subchannel < RTEMS_SYSMON_MAX_CPUS && (Subchannel + RdWr->NumChannels) <= RTEMS_SYSMON_MAX_CPUS) - { - for (ch = Subchannel; ch < (Subchannel + RdWr->NumChannels); ++ch) - { - RdWr->Samples[ch] = state->per_core[ch].avg_load; - } - } - - break; - } - default: - break; - } - - return StatusCode; -} - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* rtems_sysmon_DevCmd() */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/** - * \brief Main entry point for API. - * - * This function is called through iodriver to invoke the rtems_sysmon module. - * - * \par Assumptions, External Events, and Notes: - * None - * - * \param[in] CommandCode The CFE_PSP_IODriver_xxx command. - * \param[in] SubsystemId The monitor subsystem identifier - * \param[in] SubchannelId The monitor subchannel identifier - * \param[in] Arg The arguments for the corresponding command. - * - * \returns Status code - * \retval #CFE_PSP_SUCCESS if successful - */ -int32_t rtems_sysmon_DevCmd(uint32_t CommandCode, uint16_t SubsystemId, uint16_t SubchannelId, - CFE_PSP_IODriver_Arg_t Arg) -{ - int32_t StatusCode; - - StatusCode = CFE_PSP_ERROR_NOT_IMPLEMENTED; - switch (SubsystemId) - { - case RTEMS_SYSMON_AGGREGATE_SUBSYS: - StatusCode = rtems_sysmon_aggregate_dispatch(CommandCode, SubchannelId, Arg); - break; - case RTEMS_SYSMON_CPULOAD_SUBSYS: - StatusCode = rtems_sysmon_cpu_load_dispatch(CommandCode, SubchannelId, Arg); - break; - default: - /* not implemented */ - break; - } - - return StatusCode; -} diff --git a/unit-test-coverage/modules/rtems_sysmon/inc/coveragetest-rtems_sysmon.h b/unit-test-coverage/modules/rtems_sysmon/inc/coveragetest-rtems_sysmon.h new file mode 100644 index 00000000..06696121 --- /dev/null +++ b/unit-test-coverage/modules/rtems_sysmon/inc/coveragetest-rtems_sysmon.h @@ -0,0 +1,60 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: + * Draco + * + * Copyright (c) 2023 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **********************************************************************/ + +/* + * + * Copyright (c) 2025, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + +/** + * \file + * \ingroup coveragetest-rtems_sysmon + * \author anh.d.van@nasa.gov + * + */ + +#ifndef COVERAGETEST_RTEMS_SYSMON_H +#define COVERAGETEST_RTEMS_SYSMON_H + +#include "utassert.h" +#include "uttest.h" +#include "utstubs.h" + +#include "iodriver_analog_io.h" +#include "iodriver_base.h" +#include "iodriver_impl.h" + +#include "../../../ut-stubs/override_inc/rtems.h" +#include "../../../ut-stubs/override_inc/rtems/score/threadimpl.h" +#include "rtems_sysmon.h" + +/* + * Macro to add a test case to the list of tests to execute + */ +#define ADD_TEST(test) UtTest_Add(test, ModuleTest_ResetState, NULL, #test) + + +#endif diff --git a/unit-test-coverage/modules/rtems_sysmon/inc/coveragetest-rtems_sysmon_utils.h b/unit-test-coverage/modules/rtems_sysmon/inc/coveragetest-rtems_sysmon_utils.h new file mode 100644 index 00000000..e14aa797 --- /dev/null +++ b/unit-test-coverage/modules/rtems_sysmon/inc/coveragetest-rtems_sysmon_utils.h @@ -0,0 +1,67 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: + * Draco + * + * Copyright (c) 2023 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **********************************************************************/ + +/* + * + * Copyright (c) 2025, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + +/** + * \file + * \ingroup coveragetest-rtems_sysmon + * \author anh.d.van@nasa.gov + * + */ + +#ifndef COVERAGETEST_RTEMS_SYSMON_UTILS_H +#define COVERAGETEST_RTEMS_SYSMON_UTILS_H + +#include "coveragetest-rtems_sysmon.h" +#include "PCS_tasks.h" + +extern CFE_PSP_ModuleApi_t CFE_PSP_rtems_sysmon_API; +extern rtems_sysmon_state_t rtems_sysmon_global; + +typedef struct +{ + char Name[38]; + size_t Size; +} UT_ThreadGetNameData_t; + +typedef struct +{ + uint32_t IntValue; + uint32_t FraValue; + int64_t TotalElapsed; + int64_t IdleUptimeElapsed; +} UT_TimeDivideData_t; + +void ModuleTest_ResetState(void); +void UT_TaskDelay_Hook(void *UserObj); +void UT_ThreadGetName_Hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); +void UT_TimestampDivide_Hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); + +#endif diff --git a/unit-test-coverage/modules/rtems_sysmon/src/coveragetest-rtems_sysmon.c b/unit-test-coverage/modules/rtems_sysmon/src/coveragetest-rtems_sysmon.c new file mode 100644 index 00000000..528f8224 --- /dev/null +++ b/unit-test-coverage/modules/rtems_sysmon/src/coveragetest-rtems_sysmon.c @@ -0,0 +1,397 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* + * + * Copyright (c) 2025, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + +/** + * \file + * \ingroup modules + * + * Coverage test for rtems_sysmon module implementation + */ + +#include "utassert.h" +#include "utstubs.h" +#include "uttest.h" + +#include "cfe_psp.h" +#include "cfe_psp_config.h" +#include "cfe_psp_module.h" + +#include "coveragetest-rtems_sysmon.h" +#include "coveragetest-rtems_sysmon_utils.h" + +/* + * Reference to the API entry point for the module + */ +const CFE_PSP_ModuleApi_t * TgtAPI = &CFE_PSP_rtems_sysmon_API; +PCS_Timestamp_Control PCS_CPU_usage_Uptime_at_last_reset; + + +void Test_Init_Nominal(void) +{ + int id = 2; + + TgtAPI->Init(id); /* Init rtems Sysmon */ + UtAssert_True(rtems_sysmon_global.local_module_id == id, "Nominal Case: Init RTEMS Sysmon"); +} + +void Test_Task_Nominal(void) +{ + int DelayCounter = 0; + + /* Nominal Case: rtems sysmon task */ + rtems_sysmon_global.cpu_load.should_run = true; + UT_SetHookFunction(UT_KEY(OS_TaskDelay), (UT_HookFunc_t)UT_TaskDelay_Hook, &DelayCounter); + rtems_sysmon_Task((rtems_task_argument) &rtems_sysmon_global.cpu_load); + + UtAssert_True(rtems_sysmon_global.cpu_load.should_run == false && DelayCounter == 1, "Nominal Case: RTEMS Sysmon Task"); +} + +void Test_Entry_Nominal(void) +{ + int32 StatusCode; + CFE_PSP_IODriver_API_t *EntryAPI = TgtAPI->ExtendedApi; + + /* Nominal Case: Aggregate Subsystem */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_NOOP, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Nominal Case: Aggregate Subsystem"); + + /* Nominal Case: Cpuload Subsystem */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_NOOP, 1, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: Cpuload Subsystem"); + + /* Nominal Case: No Subsystem */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_NOOP, 2, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Nominal Case: No Subsystem"); +} + +void Test_Aggregate_Nominal(void) +{ + int32 StatusCode; + int32 IsRunningStatus; + + CFE_PSP_IODriver_AdcCode_t Sample; + CFE_PSP_IODriver_AnalogRdWr_t RdWr = {.NumChannels = 1, .Samples = &Sample}; + + CFE_PSP_IODriver_Direction_t QueryDirArg; + CFE_PSP_IODriver_API_t * EntryAPI = TgtAPI->ExtendedApi; + + /* Nominal Case: Aggregate Dispatch Noop CMD (Not Impl) */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_NOOP, 0, 0, CFE_PSP_IODriver_U32ARG(0)); /* Entry Point */ + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Nominal Case: IO Driver NOOP"); + + /* Nominal Case: Aggregate Dispatch Noop CMD (Not Impl) */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_NOOP, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Nominal Case: ANALOG IO NOOP"); + + /* Nominal Case: Start RTEMS Sysmon */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + IsRunningStatus = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: Start RTEMS Sysmon"); + UtAssert_True(IsRunningStatus == true, "Nominal Case: RTEMS Sysmon running status set"); + + /* Nominal Case: RTEMS Sysmon already running */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + IsRunningStatus = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: RTEMS Sysmon Already Running"); + UtAssert_True(IsRunningStatus == true, "Nominal Case: RTEMS Sysmon running status already set"); + + /* Nominal Case: Stop RTEMS Sysmon */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + IsRunningStatus = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: Stop RTEMS Sysmon"); + UtAssert_True(IsRunningStatus == false, "Nominal Case: RTEMS Sysmon running status disabled"); + + /* Nominal Case: RTEMS Sysmon already stop */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + IsRunningStatus = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: RTEMS Sysmon already stopped"); + UtAssert_True(IsRunningStatus == false, "Nominal Case: RTEMS Sysmon running status already disabled"); + + /* Nominal Case: Set Configuration (Not Impl) */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_CONFIGURATION, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Nominal Case: Set Configuration"); + + /* Nominal Case: Get Configuration (Not Impl) */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_CONFIGURATION, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Nominal Case: Get Configuration"); + + /* Nominal Case: Look Up per-cpu Subsystem */ + StatusCode = + EntryAPI->DeviceCommand(CFE_PSP_IODriver_LOOKUP_SUBSYSTEM, 0, 0, CFE_PSP_IODriver_CONST_STR("per-cpu")); + UtAssert_True(StatusCode == 1, "Nominal Case: Look up per-cpu subsytem"); + + /* Nominal Case: Look Up aggregate Subsystem */ + StatusCode = + EntryAPI->DeviceCommand(CFE_PSP_IODriver_LOOKUP_SUBSYSTEM, 0, 0, CFE_PSP_IODriver_CONST_STR("aggregate")); + UtAssert_True(StatusCode == 0, "Nominal Case: Look up aggregate subsytem"); + + /* Nominal Case: Look Up cpu-load subchannel */ + StatusCode = + EntryAPI->DeviceCommand(CFE_PSP_IODriver_LOOKUP_SUBCHANNEL, 0, 0, CFE_PSP_IODriver_CONST_STR("cpu-load")); + UtAssert_True(StatusCode == 0, "Nominal Case: Look up cpu-load subchannel"); + + /* Nominal Case: Query Direction */ + QueryDirArg = CFE_PSP_IODriver_Direction_DISABLED; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_QUERY_DIRECTION, 0, 0, CFE_PSP_IODriver_VPARG(&QueryDirArg)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: RTEMS Sysmon Driver Query Direction Status Code"); + UtAssert_True(QueryDirArg == CFE_PSP_IODriver_Direction_INPUT_ONLY, + "Nominal Case: RTEMS Sysmon Direction (INPUT ONLY)"); + + /* Nominal Case: Analog IO Read Channel */ + Sample = -1; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS, 0, 0, CFE_PSP_IODriver_VPARG(&RdWr)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: RTEMS Sysmon Aggregate CPU Load Status Code"); + UtAssert_True(Sample == 0, "Nominal Case: RTEMS Sysmon Aggregate CPU"); +} + +void Test_Aggregate_Error(void) +{ + CFE_PSP_IODriver_API_t * EntryAPI = TgtAPI->ExtendedApi; + int32 StatusCode; + int32 IsRunningStatus; + CFE_PSP_IODriver_AdcCode_t Sample; + CFE_PSP_IODriver_AnalogRdWr_t RdWr = {.NumChannels = 1, .Samples = &Sample}; + + /* Error Case: Look Up Subsystem Not Found */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_LOOKUP_SUBSYSTEM, 0, 0, CFE_PSP_IODriver_CONST_STR("Empty")); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: Subsystem Not Found"); + + /* Error Case: Look Up Subchannel Not Found */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_LOOKUP_SUBCHANNEL, 0, 0, CFE_PSP_IODriver_CONST_STR("Empty")); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: Subchannel Not Found"); + + /* Error Case: NULL Query Direction */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_QUERY_DIRECTION, 0, 0, CFE_PSP_IODriver_VPARG(NULL)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: NULL Query Direction Status Code"); + + /* Error Case: Analog IO Read, Wrong Channel Number */ + Sample = -1; + RdWr.NumChannels = 0; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS, 0, 0, CFE_PSP_IODriver_VPARG(&RdWr)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: Analog IO Read, Wrong Channel Number"); + + /* Error Case: Analog IO Read, Wrong Channel Subchannel */ + Sample = -1; + RdWr.NumChannels = 1; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS, 0, 5, CFE_PSP_IODriver_VPARG(&RdWr)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: Analog IO Read, Wrong Subchannel"); + + /* Error Case: Command Code Not Found */ + StatusCode = EntryAPI->DeviceCommand(40, 0, 0, CFE_PSP_IODriver_U32ARG(0)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: Aggregated Substem, Bad Command Code"); + + /* Error Case: Unable To Create Child Process */ + UT_SetDeferredRetcode(UT_KEY(PCS_rtems_task_create), 1, OS_ERROR); + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + IsRunningStatus = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_ERROR, "Error Case: Creating Child Process, Status Code"); + UtAssert_True(IsRunningStatus == false, "Error Case: Creating Child Process, Running Status"); + + /* Error Case: Unable To Start Child Process */ + UT_SetDeferredRetcode(UT_KEY(PCS_rtems_task_create), 1, RTEMS_SUCCESSFUL); + UT_SetDeferredRetcode(UT_KEY(PCS_rtems_task_start), 1, OS_ERROR); + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_SET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + IsRunningStatus = EntryAPI->DeviceCommand(CFE_PSP_IODriver_GET_RUNNING, 0, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_ERROR, "Error Case: Creating Starting Child Process, Status Code"); + UtAssert_True(IsRunningStatus == false, "Error Case: Creating Starting Child Process, Running Status"); +} + +void Test_Dispatch_Cpuload_Nominal(void) +{ + CFE_PSP_IODriver_API_t * EntryAPI = TgtAPI->ExtendedApi; + CFE_PSP_IODriver_AdcCode_t Sample[2]; + CFE_PSP_IODriver_AnalogRdWr_t RdWr = {.NumChannels = 1, .Samples = Sample}; + int32 StatusCode; + + /* Nominal Case: Dispatch IO Driver NOOP */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_NOOP, 1, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: Dispatch IO Driver NOOP "); + + /* Nominal Case: Dispatch Analog IO NOOP */ + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_NOOP, 1, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS, "Nominal Case: Dispatch Analog IO NOOP"); + + /* Nominal Case: Dispatch Analog Read Channels */ + Sample[0] = -1; + Sample[1] = -1; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS, 1, 0, CFE_PSP_IODriver_VPARG(&RdWr)); + UtAssert_True(StatusCode == CFE_PSP_SUCCESS && Sample[0] == 0 && Sample[1] == -1, "Nominal Case: Dispatch cpuload"); +} + +void Test_Dispatch_Cpuload_Error(void) +{ + CFE_PSP_IODriver_API_t * EntryAPI = TgtAPI->ExtendedApi; + CFE_PSP_IODriver_AdcCode_t Sample[2]; + CFE_PSP_IODriver_AnalogRdWr_t RdWr = {.NumChannels = 1, .Samples = Sample}; + int StatusCode; + + /* Error Case: Dispatch Analog Read Channels, Subchannel >= Max Cpu */ + /* Default max cpu == 1 */ + Sample[0] = -1; + Sample[1] = -1; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS, 1, 2, CFE_PSP_IODriver_VPARG(&RdWr)); + UtAssert_True(Sample[0] == -1 && Sample[1] == -1 && StatusCode == CFE_PSP_ERROR, + "Error Case: Dispatch cpuload, subchannel >= max cpu"); + + /* Error Case: Dispatch Analog Read Channels, NumChannels > max cpu */ + RdWr.NumChannels = 2; + StatusCode = EntryAPI->DeviceCommand(CFE_PSP_IODriver_ANALOG_IO_READ_CHANNELS, 1, 0, CFE_PSP_IODriver_VPARG(&RdWr)); + UtAssert_True(StatusCode == CFE_PSP_ERROR && Sample[0] == -1 && Sample[1] == -1, + "Error Case: Dispatch cpuload, NumChannels > max cpu"); + + /* Error Case: Command Code Not Found */ + StatusCode = EntryAPI->DeviceCommand(10, 1, 0, CFE_PSP_IODriver_U32ARG(1)); + UtAssert_True(StatusCode == CFE_PSP_ERROR_NOT_IMPLEMENTED, "Error Case: Command Code Not Found"); +} + +void Test_Cpu_Visitor_Nominal(void) +{ + PCS_Thread_Control Thread; + UT_ThreadGetNameData_t UT_ThreadGetNameData; + rtems_sysmon_cpuload_state_t Arg; + UT_TimeDivideData_t UT_TimeDivideData; + int32 AverageLoadCalc; + + UT_SetHookFunction(UT_KEY(PCS_Thread_Get_name), (UT_HookFunc_t)UT_ThreadGetName_Hook, &UT_ThreadGetNameData); + UT_SetHookFunction(UT_KEY(PCS_Timestamp_Divide), (UT_HookFunc_t)UT_TimestampDivide_Hook, &UT_TimeDivideData); + + /* Nominal Test: Thread Not IDLE Task */ + memset(UT_ThreadGetNameData.Name, 0, sizeof(UT_ThreadGetNameData.Name)); + memset(&Arg, 0, sizeof(Arg)); + + strncpy(UT_ThreadGetNameData.Name, "Testing", 7); + UT_ThreadGetNameData.Size = 7; + + UtAssert_BOOL_FALSE(rtems_cpu_usage_visitor(&Thread, &Arg)); + UtAssert_True(Arg.per_core[0].avg_load == 0, "Nominal Case: Not Idle Task"); + + /* Nominal Case Idle Task */ + /* 100% CPU util. */ + memset(UT_ThreadGetNameData.Name, 0, sizeof(UT_ThreadGetNameData.Name)); + memset(&Arg, 0, sizeof(Arg)); + memset(&UT_TimeDivideData, 0, sizeof(UT_TimeDivideData)); + + strncpy(UT_ThreadGetNameData.Name, "IDLE", 4); + UT_ThreadGetNameData.Size = 4; + + UT_TimeDivideData.IntValue = 100; + UT_TimeDivideData.FraValue = 0; + + UtAssert_BOOL_TRUE(rtems_cpu_usage_visitor(&Thread, &Arg)); + UtAssert_True(Arg.per_core[0].avg_load == 0xFFFFFF, "Nominal Case: 100 percents cpu utilization"); + + /* Nominal Case Idle Task */ + /* 50 percent util */ + memset(UT_ThreadGetNameData.Name, 0, sizeof(UT_ThreadGetNameData.Name)); + memset(&Arg, 0, sizeof(Arg)); + memset(&UT_TimeDivideData, 0, sizeof(UT_TimeDivideData)); + + strncpy(UT_ThreadGetNameData.Name, "IDLE", 4); + UT_ThreadGetNameData.Size = 4; + + UT_TimeDivideData.IntValue = 50; + UT_TimeDivideData.FraValue = 0; + UT_TimeDivideData.TotalElapsed = 10; + UT_TimeDivideData.IdleUptimeElapsed = 5; + + UtAssert_BOOL_TRUE(rtems_cpu_usage_visitor(&Thread, &Arg)); + + AverageLoadCalc = 0x1000 * UT_TimeDivideData.IntValue / 100; + AverageLoadCalc |= (AverageLoadCalc << 12); + UtAssert_True(Arg.per_core[0].avg_load == AverageLoadCalc, "Nominal Case: 50 percents cpu utilization"); + + /* Nominal Case Idle Task */ + /* 49.999 percent util */ + memset(UT_ThreadGetNameData.Name, 0, sizeof(UT_ThreadGetNameData.Name)); + memset(&Arg, 0, sizeof(Arg)); + memset(&UT_TimeDivideData, 0, sizeof(UT_TimeDivideData)); + + strncpy(UT_ThreadGetNameData.Name, "IDLE", 4); + UT_ThreadGetNameData.Size = 4; + + UT_TimeDivideData.IntValue = 50; + UT_TimeDivideData.FraValue = 9990; + UT_TimeDivideData.TotalElapsed = 10; /* placeholder */ + UT_TimeDivideData.IdleUptimeElapsed = 5; /* placeholder*/ + + UtAssert_BOOL_TRUE(rtems_cpu_usage_visitor(&Thread, &Arg)); + + /* convert int and fra part of percentages into integer. + ** Then convert into an percentages and normalizes out of 0x1000 + */ + AverageLoadCalc = (UT_TimeDivideData.IntValue * 1000) + (UT_TimeDivideData.FraValue / 10); /* Combine fraction and int to one number */ + AverageLoadCalc = (0x1000 * (100000 - AverageLoadCalc)) / 100000; + AverageLoadCalc |= (AverageLoadCalc << 12); + UtAssert_True(Arg.per_core[0].avg_load == AverageLoadCalc, "Nominal Case: 49.001 percents cpu utilization"); + + /* Nominal Case Idle Task */ + /* 0 percent util */ + memset(UT_ThreadGetNameData.Name, 0, sizeof(UT_ThreadGetNameData.Name)); + memset(&Arg, 0, sizeof(Arg)); + memset(&UT_TimeDivideData, 0, sizeof(UT_TimeDivideData)); + + strncpy(UT_ThreadGetNameData.Name, "IDLE", 4); + UT_ThreadGetNameData.Size = 4; + + UT_TimeDivideData.IntValue = 0; + UT_TimeDivideData.FraValue = 0; + UT_TimeDivideData.TotalElapsed = 0; + UT_TimeDivideData.IdleUptimeElapsed = 0; + + UtAssert_BOOL_TRUE(rtems_cpu_usage_visitor(&Thread, &Arg)); + UtAssert_True(Arg.per_core[0].avg_load == 0, "Nominal Case: 0 percents cpu utilization"); + + /* Nominal Case: Max Cpu not reach */ + memset(UT_ThreadGetNameData.Name, 0, sizeof(UT_ThreadGetNameData.Name)); + memset(&Arg, 0, sizeof(Arg)); + memset(&UT_TimeDivideData, 0, sizeof(UT_TimeDivideData)); + + strncpy(UT_ThreadGetNameData.Name, "IDLE", 4); + Arg.num_cpus = -1; + UtAssert_BOOL_FALSE(rtems_cpu_usage_visitor(&Thread, &Arg)); + UtAssert_True(Arg.num_cpus == 0, "Nominal Case: CPU Number increment"); + +} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(Test_Init_Nominal); + ADD_TEST(Test_Entry_Nominal); + ADD_TEST(Test_Aggregate_Nominal); + ADD_TEST(Test_Aggregate_Error); + ADD_TEST(Test_Dispatch_Cpuload_Nominal); + ADD_TEST(Test_Dispatch_Cpuload_Error); + ADD_TEST(Test_Cpu_Visitor_Nominal); + ADD_TEST(Test_Task_Nominal); + +} diff --git a/unit-test-coverage/modules/rtems_sysmon/src/coveragetest-rtems_sysmon_utils.c b/unit-test-coverage/modules/rtems_sysmon/src/coveragetest-rtems_sysmon_utils.c new file mode 100644 index 00000000..b35ce20b --- /dev/null +++ b/unit-test-coverage/modules/rtems_sysmon/src/coveragetest-rtems_sysmon_utils.c @@ -0,0 +1,81 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* + * + * Copyright (c) 2025, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + +/** + * \file + * \ingroup modules + * + * utils for rtems_sysmon coverage test + */ + +#include "coveragetest-rtems_sysmon_utils.h" + +void ModuleTest_ResetState(void) +{ + memset(&rtems_sysmon_global, 0, sizeof(rtems_sysmon_global)); +} + +/* Hook */ +void UT_TaskDelay_Hook(void *UserObj) +{ + int *DelayCounter = UserObj; + rtems_sysmon_global.cpu_load.should_run = false; + + (*DelayCounter)++; +} + +void UT_ThreadGetName_Hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) +{ + int i; + + char * Name = UT_Hook_GetArgValueByName(Context, "buffer", char *); + UT_ThreadGetNameData_t * Data = (UT_ThreadGetNameData_t *) UserObj; + + for (i = 0; i < Data->Size; i++) + { + Name[i] = Data->Name[i]; + } +} + +void UT_TimestampDivide_Hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) +{ + + UT_TimeDivideData_t * TimeDivideData = (UT_TimeDivideData_t *) UserObj; + + uint32_t * IntValue = UT_Hook_GetArgValueByName(Context, "_ival_percentage", uint32_t *); + uint32_t * FraValue = UT_Hook_GetArgValueByName(Context, "_fval_percentage", uint32_t *); + int64_t * IdleUptimeElapsed = UT_Hook_GetArgValueByName(Context, "_lhs", int64_t *); + int64_t * TotalElapsed = UT_Hook_GetArgValueByName(Context, "_rhs", int64_t *); + + *IntValue = TimeDivideData->IntValue; + *FraValue = TimeDivideData->FraValue; + *IdleUptimeElapsed = TimeDivideData->IdleUptimeElapsed; + *TotalElapsed = TimeDivideData->TotalElapsed; +} \ No newline at end of file diff --git a/unit-test-coverage/ut-stubs/CMakeLists.txt b/unit-test-coverage/ut-stubs/CMakeLists.txt index ffa8208c..9ddb8309 100644 --- a/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -86,6 +86,12 @@ add_library(ut_psp_libc_stubs STATIC EXCLUDE_FROM_ALL src/PCS_unistd_stubs.c src/PCS_xbdBlkDev_stubs.c src/vxworks-mcpx750-stubs.c + src/PCS_timestampimpl_stubs.c + src/PCS_todimpl_stubs.c + src/PCS_threadimpl_stubs.c + src/PCS_tasks_stubs.c + src/PCS_object_stubs.c + src/PCS_cpuuse_stubs.c ) target_include_directories(ut_libc_stubs PUBLIC diff --git a/unit-test-coverage/ut-stubs/inc/PCS_cpuuse.h b/unit-test-coverage/ut-stubs/inc/PCS_cpuuse.h new file mode 100644 index 00000000..024cdd66 --- /dev/null +++ b/unit-test-coverage/ut-stubs/inc/PCS_cpuuse.h @@ -0,0 +1,25 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ +#ifndef PCS_CPUUSE_H +#define PCS_CPUUSE_H + +#include "PCS_rtems.h" + +void PCS_rtems_cpu_usage_reset( void ); + +#endif diff --git a/unit-test-coverage/ut-stubs/inc/PCS_object.h b/unit-test-coverage/ut-stubs/inc/PCS_object.h new file mode 100644 index 00000000..d7c8e6f0 --- /dev/null +++ b/unit-test-coverage/ut-stubs/inc/PCS_object.h @@ -0,0 +1,48 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/************************************************************************ + * Note that this file has been cloned-n-owned from its open-source github + * repository for Gateway as of September 2023. Therefore, it is subject to + * NASA Export Control restrictions, as stated below. + ************************************************************************/ + +/************************************************************************/ +/** \export_control EAR ECCN 9E515.a and/or 9E515.f (HALO) + * + * Export Administration Regulations (EAR) Notice + * + * This document contains information which falls under the purview of the + * Export Administration Regulations (EAR), 15 CFR §730-774 and is export + * controlled. It may be used only to fulfill responsibilities of the Parties + * of, or a Cooperating Agency of a NASA Gateway Program Partner (CSA, ESA, + * JAXA, MBRSC) and their contractors in furtherance of the Gateway MOUs + * with ESA, CSA, and Japan and IA with MBRSC. Any use, re-transfer, or + * disclosure to any party for any purpose other than the designated use of + * fulfilling the responsibilities of the Gateway MOUs and IA requires prior + * U.S. Government authorization. + *************************************************************************/ + +#ifndef PCS_OBJECT_H +#define PCS_OBJECT_H + +#include "PCS_rtems.h" + +uint32_t PCS_rtems_build_name(char A, char B, char C, char D); + +#endif diff --git a/unit-test-coverage/ut-stubs/inc/PCS_rtems.h b/unit-test-coverage/ut-stubs/inc/PCS_rtems.h index 5381e900..3a874de2 100644 --- a/unit-test-coverage/ut-stubs/inc/PCS_rtems.h +++ b/unit-test-coverage/ut-stubs/inc/PCS_rtems.h @@ -22,8 +22,27 @@ #include "PCS_basetypes.h" -typedef uint32_t PCS_rtems_task_priority; -typedef uint32_t PCS_rtems_id; +#define PCS_RTEMS_SELF 0 +#define PCS_RTEMS_DEFAULT_MODES 0x00000000 +#define PCS_RTEMS_DEFAULT_ATTRIBUTES 0x00000000 + +typedef uint32_t PCS_rtems_task_priority; +typedef uint32_t PCS_rtems_id; +typedef uint32_t PCS_rtems_name; +typedef uintptr_t PCS_CPU_Uint32ptr; +typedef int64_t PCS_Timestamp_Control; +typedef void PCS_rtems_task; +typedef uint32_t PCS_rtems_mode; +typedef uint32_t PCS_rtems_attribute; +typedef PCS_CPU_Uint32ptr PCS_rtems_task_argument; + +typedef struct { + /* Fake Thread control */ + char * Name; +} PCS_Thread_Control_S; + +typedef PCS_Thread_Control_S PCS_rtems_tcb; +typedef PCS_rtems_tcb PCS_Thread_Control; struct PCS_rtems_bsdnet_ifconfig { diff --git a/unit-test-coverage/ut-stubs/inc/PCS_tasks.h b/unit-test-coverage/ut-stubs/inc/PCS_tasks.h new file mode 100644 index 00000000..f6788c42 --- /dev/null +++ b/unit-test-coverage/ut-stubs/inc/PCS_tasks.h @@ -0,0 +1,36 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for tasks.h */ +#ifndef PCS_TASKS_H +#define PCS_TASKS_H + +#include "PCS_rtems.h" + +typedef bool( * PCS_rtems_task_visitor) (PCS_rtems_tcb *tcb, void *arg); +typedef PCS_rtems_task( * PCS_rtems_task_entry) (PCS_rtems_task_argument); + +void PCS_rtems_task_iterate (PCS_rtems_task_visitor visitor, void *arg); +PCS_rtems_status_code PCS_rtems_task_delete (PCS_rtems_id id); +PCS_rtems_status_code PCS_rtems_task_create (PCS_rtems_name name, PCS_rtems_task_priority initial_priority, size_t stack_size, + PCS_rtems_mode initial_modes, PCS_rtems_attribute attribute_set, PCS_rtems_id *id); +PCS_rtems_status_code PCS_rtems_task_start (PCS_rtems_id id, PCS_rtems_task_entry entry_point, PCS_rtems_task_argument argument); + + + +#endif \ No newline at end of file diff --git a/unit-test-coverage/ut-stubs/inc/PCS_threadimpl.h b/unit-test-coverage/ut-stubs/inc/PCS_threadimpl.h new file mode 100644 index 00000000..4599f69b --- /dev/null +++ b/unit-test-coverage/ut-stubs/inc/PCS_threadimpl.h @@ -0,0 +1,28 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for threadimpl.h */ +#ifndef PCS_THREADIMPL_H +#define PCS_THREADIMPL_H + +#include "PCS_rtems.h" + +size_t PCS_Thread_Get_name(const PCS_Thread_Control *the_thread, char *buffer, size_t buffer_size); +PCS_Timestamp_Control PCS_Thread_Get_CPU_time_used_after_last_reset(PCS_Thread_Control *the_thread); + +#endif \ No newline at end of file diff --git a/unit-test-coverage/ut-stubs/inc/PCS_timestampimpl.h b/unit-test-coverage/ut-stubs/inc/PCS_timestampimpl.h new file mode 100644 index 00000000..7931834b --- /dev/null +++ b/unit-test-coverage/ut-stubs/inc/PCS_timestampimpl.h @@ -0,0 +1,29 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for timestampimp.h */ +#ifndef PCS_TIMESTAMPIMP_H +#define PCS_TIMESTAMPIMP_H + +#include "PCS_rtems.h" + +void PCS_Timestamp_Subtract (const PCS_Timestamp_Control *_start, const PCS_Timestamp_Control *_end, PCS_Timestamp_Control *_result); +void PCS_Timestamp_Divide (const PCS_Timestamp_Control *_lhs, const PCS_Timestamp_Control *_rhs, uint32_t *_ival_percentage, uint32_t *_fval_percentage); + + +#endif \ No newline at end of file diff --git a/unit-test-coverage/ut-stubs/inc/PCS_todimpl.h b/unit-test-coverage/ut-stubs/inc/PCS_todimpl.h new file mode 100644 index 00000000..fd7a49f3 --- /dev/null +++ b/unit-test-coverage/ut-stubs/inc/PCS_todimpl.h @@ -0,0 +1,28 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for todimpl.h */ +#ifndef PCS_TODIMPL_H +#define PCS_TODIMPL_H + +#include "PCS_rtems.h" + +void PCS_TOD_Get_uptime (PCS_Timestamp_Control *time); + + +#endif \ No newline at end of file diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems.h b/unit-test-coverage/ut-stubs/override_inc/rtems.h index 97bb582c..154800c1 100644 --- a/unit-test-coverage/ut-stubs/override_inc/rtems.h +++ b/unit-test-coverage/ut-stubs/override_inc/rtems.h @@ -22,11 +22,29 @@ #include "PCS_rtems.h" -#define rtems_task_priority PCS_rtems_task_priority -#define rtems_id PCS_rtems_id +#include "rtems/score/todimpl.h" +#include "rtems/score/timestampimpl.h" +#include "rtems/rtems/object.h" -#define rtems_status_code PCS_rtems_status_code -#define RTEMS_SUCCESSFUL PCS_RTEMS_SUCCESSFUL +#define rtems_task_priority PCS_rtems_task_priority +#define rtems_id PCS_rtems_id +#define rtems_name PCS_rtems_name +#define CPU_Uint32ptr PCS_CPU_Uint32ptr +#define rtems_task PCS_rtems_task +#define rtems_task_argument PCS_rtems_task_argument +#define Timestamp_Control PCS_Timestamp_Control +#define Thread_Control PCS_Thread_Control +#define _Thread_Control PCS_Thread_Control_S +#define rtems_task_visitor PCS_rtems_task_visitor +#define rtems_mode PCS_rtems_mode +#define rtems_attribute PCS_rtems_attribute +#define rtems_task_entry PCS_rtems_task_entry + +#define rtems_status_code PCS_rtems_status_code +#define RTEMS_SUCCESSFUL PCS_RTEMS_SUCCESSFUL +#define RTEMS_SELF PCS_RTEMS_SELF +#define RTEMS_DEFAULT_MODES PCS_RTEMS_DEFAULT_MODES +#define RTEMS_DEFAULT_ATTRIBUTES PCS_RTEMS_DEFAULT_ATTRIBUTES #define rtems_bsdnet_ifconfig PCS_rtems_bsdnet_ifconfig #define rtems_bsdnet_config PCS_rtems_bsdnet_config diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems/cpuuse.h b/unit-test-coverage/ut-stubs/override_inc/rtems/cpuuse.h new file mode 100644 index 00000000..997c8cd5 --- /dev/null +++ b/unit-test-coverage/ut-stubs/override_inc/rtems/cpuuse.h @@ -0,0 +1,28 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for cpuuse.h */ +#ifndef OVERRIDE_CPUUSE_H +#define OVERRIDE_CPUUSE_H + +#include "PCS_cpuuse.h" + +#define rtems_cpu_usage_reset PCS_rtems_cpu_usage_reset +#define CPU_usage_Uptime_at_last_reset PCS_CPU_usage_Uptime_at_last_reset + +#endif diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems/rtems/object.h b/unit-test-coverage/ut-stubs/override_inc/rtems/rtems/object.h new file mode 100644 index 00000000..b79a370a --- /dev/null +++ b/unit-test-coverage/ut-stubs/override_inc/rtems/rtems/object.h @@ -0,0 +1,27 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for object.h */ +#ifndef OVERRIDE_OBJECT_H +#define OVERRIDE_OBJECT_H + +#include "PCS_object.h" + +#define rtems_build_name PCS_rtems_build_name + +#endif diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems/rtems/tasks.h b/unit-test-coverage/ut-stubs/override_inc/rtems/rtems/tasks.h new file mode 100644 index 00000000..058f9a41 --- /dev/null +++ b/unit-test-coverage/ut-stubs/override_inc/rtems/rtems/tasks.h @@ -0,0 +1,30 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for tasks.h */ +#ifndef OVERRIDE_TASKS_H +#define OVERRIDE_TASKS_H + +#include "PCS_tasks.h" + +#define rtems_task_iterate PCS_rtems_task_iterate +#define rtems_task_delete PCS_rtems_task_delete +#define rtems_task_create PCS_rtems_task_create +#define rtems_task_start PCS_rtems_task_start + +#endif diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems/score/threadimpl.h b/unit-test-coverage/ut-stubs/override_inc/rtems/score/threadimpl.h new file mode 100644 index 00000000..1e7f736c --- /dev/null +++ b/unit-test-coverage/ut-stubs/override_inc/rtems/score/threadimpl.h @@ -0,0 +1,28 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for threadimpl.h */ +#ifndef OVERRIDE_THREADIMPL_H +#define OVERRIDE_THREADIMPL_H + +#include "PCS_threadimpl.h" + +#define _Thread_Get_name PCS_Thread_Get_name +#define _Thread_Get_CPU_time_used_after_last_reset PCS_Thread_Get_CPU_time_used_after_last_reset + +#endif diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems/score/timestampimpl.h b/unit-test-coverage/ut-stubs/override_inc/rtems/score/timestampimpl.h new file mode 100644 index 00000000..6b28d44d --- /dev/null +++ b/unit-test-coverage/ut-stubs/override_inc/rtems/score/timestampimpl.h @@ -0,0 +1,28 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for timestampimpl.h */ +#ifndef OVERRIDE_TIMESTAMPIMPL_H +#define OVERRIDE_TIMESTAMPIMPL_H + +#include "PCS_timestampimpl.h" + +#define _Timestamp_Subtract PCS_Timestamp_Subtract +#define _Timestamp_Divide PCS_Timestamp_Divide + +#endif diff --git a/unit-test-coverage/ut-stubs/override_inc/rtems/score/todimpl.h b/unit-test-coverage/ut-stubs/override_inc/rtems/score/todimpl.h new file mode 100644 index 00000000..d835db28 --- /dev/null +++ b/unit-test-coverage/ut-stubs/override_inc/rtems/score/todimpl.h @@ -0,0 +1,27 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* PSP coverage stub replacement for todimpl.h */ +#ifndef OVERRIDE_TOOIMPL_H +#define OVERRIDE_TODIMPL_H + +#include "PCS_todimpl.h" + +#define _TOD_Get_uptime PCS_TOD_Get_uptime + +#endif diff --git a/unit-test-coverage/ut-stubs/src/PCS_cpuuse_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_cpuuse_stubs.c new file mode 100644 index 00000000..028c493c --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_cpuuse_stubs.c @@ -0,0 +1,40 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ +#define PCS_CPUUSE_H + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_cpuuse header + */ + +#include "PCS_cpuuse.h" +#include "utgenstub.h" + + + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_cpu_usage_reset() + * ---------------------------------------------------- + */ +void PCS_rtems_cpu_usage_reset(void) +{ + + UT_GenStub_Execute(PCS_rtems_cpu_usage_reset, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_object_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_object_stubs.c new file mode 100644 index 00000000..4e0caacf --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_object_stubs.c @@ -0,0 +1,45 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_object header + */ + +#include "PCS_object.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_build_name() + * ---------------------------------------------------- + */ +uint32_t PCS_rtems_build_name(char A, char B, char C, char D) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_build_name, uint32_t); + + UT_GenStub_AddParam(PCS_rtems_build_name, char, A); + UT_GenStub_AddParam(PCS_rtems_build_name, char, B); + UT_GenStub_AddParam(PCS_rtems_build_name, char, C); + UT_GenStub_AddParam(PCS_rtems_build_name, char, D); + + UT_GenStub_Execute(PCS_rtems_build_name, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_build_name, uint32_t); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_tasks_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_tasks_stubs.c new file mode 100644 index 00000000..5960b34d --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_tasks_stubs.c @@ -0,0 +1,97 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_tasks header + */ + +#include "PCS_tasks.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_task_create() + * ---------------------------------------------------- + */ +PCS_rtems_status_code PCS_rtems_task_create(PCS_rtems_name name, PCS_rtems_task_priority initial_priority, + size_t stack_size, PCS_rtems_mode initial_modes, + PCS_rtems_attribute attribute_set, PCS_rtems_id *id) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_task_create, PCS_rtems_status_code); + + UT_GenStub_AddParam(PCS_rtems_task_create, PCS_rtems_name, name); + UT_GenStub_AddParam(PCS_rtems_task_create, PCS_rtems_task_priority, initial_priority); + UT_GenStub_AddParam(PCS_rtems_task_create, size_t, stack_size); + UT_GenStub_AddParam(PCS_rtems_task_create, PCS_rtems_mode, initial_modes); + UT_GenStub_AddParam(PCS_rtems_task_create, PCS_rtems_attribute, attribute_set); + UT_GenStub_AddParam(PCS_rtems_task_create, PCS_rtems_id *, id); + + UT_GenStub_Execute(PCS_rtems_task_create, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_task_create, PCS_rtems_status_code); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_task_delete() + * ---------------------------------------------------- + */ +PCS_rtems_status_code PCS_rtems_task_delete(PCS_rtems_id id) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_task_delete, PCS_rtems_status_code); + + UT_GenStub_AddParam(PCS_rtems_task_delete, PCS_rtems_id, id); + + UT_GenStub_Execute(PCS_rtems_task_delete, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_task_delete, PCS_rtems_status_code); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_task_iterate() + * ---------------------------------------------------- + */ +void PCS_rtems_task_iterate(PCS_rtems_task_visitor visitor, void *arg) +{ + UT_GenStub_AddParam(PCS_rtems_task_iterate, PCS_rtems_task_visitor, visitor); + UT_GenStub_AddParam(PCS_rtems_task_iterate, void *, arg); + + UT_GenStub_Execute(PCS_rtems_task_iterate, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_task_start() + * ---------------------------------------------------- + */ +PCS_rtems_status_code PCS_rtems_task_start(PCS_rtems_id id, PCS_rtems_task_entry entry_point, + PCS_rtems_task_argument argument) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_task_start, PCS_rtems_status_code); + + UT_GenStub_AddParam(PCS_rtems_task_start, PCS_rtems_id, id); + UT_GenStub_AddParam(PCS_rtems_task_start, PCS_rtems_task_entry, entry_point); + UT_GenStub_AddParam(PCS_rtems_task_start, PCS_rtems_task_argument, argument); + + UT_GenStub_Execute(PCS_rtems_task_start, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_task_start, PCS_rtems_status_code); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_threadimpl_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_threadimpl_stubs.c new file mode 100644 index 00000000..a03b608d --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_threadimpl_stubs.c @@ -0,0 +1,60 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_threadimpl header + */ + +#include "PCS_threadimpl.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_Thread_Get_CPU_time_used_after_last_reset() + * ---------------------------------------------------- + */ +PCS_Timestamp_Control PCS_Thread_Get_CPU_time_used_after_last_reset(PCS_Thread_Control *the_thread) +{ + UT_GenStub_SetupReturnBuffer(PCS_Thread_Get_CPU_time_used_after_last_reset, PCS_Timestamp_Control); + + UT_GenStub_AddParam(PCS_Thread_Get_CPU_time_used_after_last_reset, PCS_Thread_Control *, the_thread); + + UT_GenStub_Execute(PCS_Thread_Get_CPU_time_used_after_last_reset, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_Thread_Get_CPU_time_used_after_last_reset, PCS_Timestamp_Control); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_Thread_Get_name() + * ---------------------------------------------------- + */ +size_t PCS_Thread_Get_name(const PCS_Thread_Control *the_thread, char *buffer, size_t buffer_size) +{ + UT_GenStub_SetupReturnBuffer(PCS_Thread_Get_name, size_t); + + UT_GenStub_AddParam(PCS_Thread_Get_name, const PCS_Thread_Control *, the_thread); + UT_GenStub_AddParam(PCS_Thread_Get_name, char *, buffer); + UT_GenStub_AddParam(PCS_Thread_Get_name, size_t, buffer_size); + + UT_GenStub_Execute(PCS_Thread_Get_name, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_Thread_Get_name, size_t); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_timestampimpl_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_timestampimpl_stubs.c new file mode 100644 index 00000000..80fee3f3 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_timestampimpl_stubs.c @@ -0,0 +1,57 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_timestampimpl header + */ + +#include "PCS_timestampimpl.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_Timestamp_Divide() + * ---------------------------------------------------- + */ +void PCS_Timestamp_Divide(const PCS_Timestamp_Control *_lhs, const PCS_Timestamp_Control *_rhs, + uint32_t *_ival_percentage, uint32_t *_fval_percentage) +{ + UT_GenStub_AddParam(PCS_Timestamp_Divide, const PCS_Timestamp_Control *, _lhs); + UT_GenStub_AddParam(PCS_Timestamp_Divide, const PCS_Timestamp_Control *, _rhs); + UT_GenStub_AddParam(PCS_Timestamp_Divide, uint32_t *, _ival_percentage); + UT_GenStub_AddParam(PCS_Timestamp_Divide, uint32_t *, _fval_percentage); + + UT_GenStub_Execute(PCS_Timestamp_Divide, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_Timestamp_Subtract() + * ---------------------------------------------------- + */ +void PCS_Timestamp_Subtract(const PCS_Timestamp_Control *_start, const PCS_Timestamp_Control *_end, + PCS_Timestamp_Control *_result) +{ + UT_GenStub_AddParam(PCS_Timestamp_Subtract, const PCS_Timestamp_Control *, _start); + UT_GenStub_AddParam(PCS_Timestamp_Subtract, const PCS_Timestamp_Control *, _end); + UT_GenStub_AddParam(PCS_Timestamp_Subtract, PCS_Timestamp_Control *, _result); + + UT_GenStub_Execute(PCS_Timestamp_Subtract, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_todimpl_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_todimpl_stubs.c new file mode 100644 index 00000000..ea14c463 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_todimpl_stubs.c @@ -0,0 +1,38 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_todimpl header + */ + +#include "PCS_todimpl.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_TOD_Get_uptime() + * ---------------------------------------------------- + */ +void PCS_TOD_Get_uptime(PCS_Timestamp_Control *time) +{ + UT_GenStub_AddParam(PCS_TOD_Get_uptime, PCS_Timestamp_Control *, time); + + UT_GenStub_Execute(PCS_TOD_Get_uptime, Basic, NULL); +}