From 82fef276321bc98466ff5340c08241209783ec3c Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 29 Sep 2026 12:53:54 -0400 Subject: [PATCH 1/5] Fix #126, pass correct compile options to DB builds Passes the full set of compile options from CMake (obtained via the COMPILE_OPTIONS target property) to the DB object builds. This should alleviate any discrepancy between how the DB objects are compiled vs the library source file, including any machine-specific options. In doing so, this is now compiling all the objects with the C99 "pendantic" flags, which in turn caused other issues to appear regarding empty initializers and unused static variable declarations. This also includes fixes for those issues. --- cfecfs/missionlib/arch_build.cmake | 6 +++++ .../eds/76-cfe_sb_topicdb_global.lua | 24 +++++++++-------- .../eds/85-write_commandcode_headers.lua | 2 +- edslib/cmake/base_patternrules.mk | 2 +- edslib/cmake/edstool-buildenv.mk.in | 14 ++++++---- .../eds/45-seds_write_datatypedb_objects.lua | 27 +++++++++++-------- edslib/eds/52-seds_write_intfdb_objects.lua | 23 +++++++++------- edslib/fsw/src/edslib_intfdb_api.c | 23 ++++++++++------ tool/cmake/edstool-execute-all.mk | 6 ++--- tool/cmake/edstool-execute-target.cmake | 3 +++ 10 files changed, 81 insertions(+), 49 deletions(-) diff --git a/cfecfs/missionlib/arch_build.cmake b/cfecfs/missionlib/arch_build.cmake index 4547272..981d04a 100644 --- a/cfecfs/missionlib/arch_build.cmake +++ b/cfecfs/missionlib/arch_build.cmake @@ -19,6 +19,9 @@ add_custom_target(edstool-execute COMMAND "\$(MAKE)" BUILD_CONFIG="${BUILD_CONFIG_${TARGETSYSTEM}}" EDSTOOL_PROJECT_NAME=${MISSION_NAME} + CMAKE_C_FLAGS=\"$\" + CMAKE_INCLUDE_DIRECTORIES=\"$\" + CMAKE_COMPILE_DEFINITIONS=\"$\" O="${EDSTOOL_ARCH_SUBDIR}/obj" S="src" -f ${missionlib_MISSION_DIR}/cmake/edstool-execute-arch.mk @@ -34,6 +37,9 @@ if (ENABLE_UNIT_TESTS) COMMAND "\$(MAKE)" BUILD_CONFIG="${BUILD_CONFIG_${TARGETSYSTEM}}" EDSTOOL_PROJECT_NAME="ut" + CMAKE_C_FLAGS=\"$\" + CMAKE_INCLUDE_DIRECTORIES=\"$\" + CMAKE_COMPILE_DEFINITIONS=\"$\" O="${EDSTOOL_ARCH_SUBDIR}/obj" S="src" -f ${missionlib_MISSION_DIR}/cmake/edstool-execute-arch.mk diff --git a/cfecfs/missionlib/eds/76-cfe_sb_topicdb_global.lua b/cfecfs/missionlib/eds/76-cfe_sb_topicdb_global.lua index 3ce834c..69eb723 100644 --- a/cfecfs/missionlib/eds/76-cfe_sb_topicdb_global.lua +++ b/cfecfs/missionlib/eds/76-cfe_sb_topicdb_global.lua @@ -57,19 +57,21 @@ for tid = 1,SEDS.get_define("CFE_MISSION/MAX_TOPICID") do for j,cmd in ipairs(cmdlist) do if (cmd.subcommand_arg) then local derivlist = cmd.args[cmd.subcommand_arg].type.edslib_derivtable_list - chain.dispatch_symbol_name = string.format("EDS_DISPATCHTABLE_%s_%s", intf:get_flattened_name(), cmd.refnode.name) - chain.dispatch_table_size = #derivlist - dbout:write(string.format("static const CFE_MissionLib_DispatchTable_Entry_t %s[] =",chain.dispatch_symbol_name)) - dbout:start_group("{") - for _,deriv in ipairs(derivlist) do - dbout:append_previous(",") + if (derivlist) then + chain.dispatch_symbol_name = string.format("EDS_DISPATCHTABLE_%s_%s", intf:get_flattened_name(), cmd.refnode.name) + chain.dispatch_table_size = #derivlist + dbout:write(string.format("static const CFE_MissionLib_DispatchTable_Entry_t %s[] =",chain.dispatch_symbol_name)) dbout:start_group("{") - dbout:write(string.format(".DispatchOffset = offsetof(struct %s, %s)", - intf:get_ctype_basename("Commands"), deriv.name .. "_" .. cmd.refnode.name)) - dbout:end_group("}") + for _,deriv in ipairs(derivlist) do + dbout:append_previous(",") + dbout:start_group("{") + dbout:write(string.format(".DispatchOffset = offsetof(struct %s, %s)", + intf:get_ctype_basename("Commands"), deriv.name .. "_" .. cmd.refnode.name)) + dbout:end_group("}") + end + dbout:end_group("};") + dbout:add_whitespace(1) end - dbout:end_group("};") - dbout:add_whitespace(1) end end end diff --git a/cfecfs/missionlib/eds/85-write_commandcode_headers.lua b/cfecfs/missionlib/eds/85-write_commandcode_headers.lua index 7046be6..7fde6d1 100644 --- a/cfecfs/missionlib/eds/85-write_commandcode_headers.lua +++ b/cfecfs/missionlib/eds/85-write_commandcode_headers.lua @@ -41,7 +41,7 @@ for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do local constraint_values = {} local constraint_argtype = {} - for _,subcommand in ipairs(argtype.edslib_derivtable_list) do + for _,subcommand in ipairs(argtype.edslib_derivtable_list or {}) do -- Note that this list is not in value-order, the index relates to the lookup table, not the actual cmdcode value -- To get the command code value, need to drill down into the constraint set. This assumes a single value constraint. local cmdname = subcommand:get_flattened_name() diff --git a/edslib/cmake/base_patternrules.mk b/edslib/cmake/base_patternrules.mk index 2a73d70..47f5c08 100644 --- a/edslib/cmake/base_patternrules.mk +++ b/edslib/cmake/base_patternrules.mk @@ -11,7 +11,7 @@ EDSTOOL_ARCH ?= host # NOTE: using "abspath" here makes any error reports clickable in IDEs like VSCode $(O)/%_impl.o: $(S)/%_impl.c @echo EDS: Compiling $(<) for $(EDSTOOL_ARCH) - $(CC) $(CFLAGS) -Iinc -D_EDSLIB_BUILD_ -MMD -c -o $@ $(abspath $<) + $(CC) $(CFLAGS) $(CFLAGS_PIC) -Iinc -D_EDSLIB_BUILD_ -MMD -c -o $@ $(abspath $<) # diff --git a/edslib/cmake/edstool-buildenv.mk.in b/edslib/cmake/edstool-buildenv.mk.in index 55dc7e7..1d45d4e 100644 --- a/edslib/cmake/edstool-buildenv.mk.in +++ b/edslib/cmake/edstool-buildenv.mk.in @@ -14,11 +14,15 @@ export SHARED_LDFLAGS := ${CMAKE_SHARED_LINKER_FLAGS} export SHARED_SUFFIX := ${CMAKE_SHARED_LIBRARY_SUFFIX} export STATIC_LDFLAGS := ${CMAKE_STATIC_LINKER_FLAGS} export STATIC_SUFFIX := ${CMAKE_STATIC_LIBRARY_SUFFIX} +export CFLAGS_PIC := ${CMAKE_C_COMPILE_OPTIONS_PIC} -# Special treatment for CFLAGS - code compiled here -# will require access to the EdsLib API headers. This assumes -# a gnu-style compiler option (-I), but should with clang too. -CFLAGS ?= ${CMAKE_C_FLAGS} ${EDSLIB_C_FLAGS} -CFLAGS ?= -Wall -Werror -std=c99 -pedantic +# initialize the CFLAGS from the passed-in info +# NOTE: the vaiable refs here are make refs, NOT cmake refs +# these are passed in at compile time, they are not known +# at the time when this file is generated +CFLAGS = $(subst ;, ,$(CMAKE_C_FLAGS)) CFLAGS += -I$(EDS_REPO_SOURCE_DIR)/edslib/fsw/inc +CFLAGS += $(addprefix -I,$(subst ;, ,$(CMAKE_INCLUDE_DIRECTORIES))) +CFLAGS += $(addprefix -D,$(subst ;, ,$(CMAKE_COMPILE_DEFINITIONS))) export CFLAGS + diff --git a/edslib/eds/45-seds_write_datatypedb_objects.lua b/edslib/eds/45-seds_write_datatypedb_objects.lua index b8df523..df7c078 100644 --- a/edslib/eds/45-seds_write_datatypedb_objects.lua +++ b/edslib/eds/45-seds_write_datatypedb_objects.lua @@ -896,21 +896,18 @@ local function write_c_derivative_descriptor(output,node) vref.reftype = entitylist[entitymap[vref.refent]].reftype end - descriptor_fields.DerivativeList = string.format("%s_DERIVATIVE_LIST", basename) - output:write(string.format("static const EdsLib_DerivativeEntry_t %s[] =", descriptor_fields.DerivativeList)) - output:start_group("{") + local derivlist_c_initializer = {} local deriviter = SEDS.sorted_keys(derivset, function(a,b) return (a.edslib_refobj_typedb_initializer < b.edslib_refobj_typedb_initializer) end) for deriv in deriviter do local setlist = derivset[deriv] if (type(setlist) == "table") then - output:append_previous(",") deriv.edslib_basetype_derivtable_idx = #derivlist -- save in DOM for future scripts derivlist[1 + #derivlist] = deriv local _,first_val = next(setlist) - output:write(string.format("{ .IdentSeqIdx =%4d, .RefObj = %40s }", - first_val or 0,deriv.edslib_refobj_typedb_initializer)) + derivlist_c_initializer[1 + #derivlist_c_initializer] = + string.format("{ .IdentSeqIdx =%4d, .RefObj = %40s }", first_val or 0,deriv.edslib_refobj_typedb_initializer) for _,seqidx in pairs(setlist) do local seq = identseq[seqidx] @@ -920,11 +917,19 @@ local function write_c_derivative_descriptor(output,node) end end end - output:end_group("};") - output:add_whitespace(1) - node.edslib_derivtable_list = derivlist -- stash flattened list in DOM for future scripts - descriptor_fields.DerivativeListSize = #derivlist - + if (#derivlist_c_initializer > 0) then + descriptor_fields.DerivativeList = string.format("%s_DERIVATIVE_LIST", basename) + output:write(string.format("static const EdsLib_DerivativeEntry_t %s[] =", descriptor_fields.DerivativeList)) + output:start_group("{") + for _,c_initializer in ipairs(derivlist_c_initializer) do + output:append_previous(",") + output:write(c_initializer) + end + output:end_group("};") + output:add_whitespace(1) + node.edslib_derivtable_list = derivlist -- stash flattened list in DOM for future scripts + descriptor_fields.DerivativeListSize = #derivlist_c_initializer + end end if (#identseq > 1) then diff --git a/edslib/eds/52-seds_write_intfdb_objects.lua b/edslib/eds/52-seds_write_intfdb_objects.lua index d825f82..0c499b2 100644 --- a/edslib/eds/52-seds_write_intfdb_objects.lua +++ b/edslib/eds/52-seds_write_intfdb_objects.lua @@ -402,6 +402,7 @@ local component_output_handlers = local global_sym_prefix = SEDS.get_define("EDSTOOL_PROJECT_NAME") local global_file_prefix = global_sym_prefix and string.lower(global_sym_prefix) or "eds" global_sym_prefix = global_sym_prefix and string.upper(global_sym_prefix) or "EDS" +all_intf_db_objs = {} -- -------------------------------------- -- Generate the "intfdb_impl.c" file per datasheet @@ -423,16 +424,20 @@ for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do merge_fields(ds_fields, execute_output_handlers(output,ds:find_first("DECLARED_INTERFACE_SET"),write_declared_intfs)) merge_fields(ds_fields, execute_output_handlers(output,ds:find_first("COMPONENT_SET"),write_components)) - output:section_marker("Database Object") - output:write(string.format("const struct EdsLib_App_IntfDB %s_INTF_DB =", ds_flat_name)) - output:start_group("{") - for key in SEDS.sorted_keys(ds_fields) do - if (ds_fields[key] ~= nil) then - output:append_previous(",") - output:write(string.format(".%s = %s", key, ds_fields[key])) + if (type(ds_fields) == "table" and next(ds_fields) ~= nil) then + local obj_name = string.format("%s_INTF_DB", ds_flat_name) + all_intf_db_objs[ds_flat_name] = "&" .. obj_name + output:section_marker("Database Object") + output:write(string.format("const struct EdsLib_App_IntfDB %s =", obj_name)) + output:start_group("{") + for key in SEDS.sorted_keys(ds_fields) do + if (ds_fields[key] ~= nil) then + output:append_previous(",") + output:write(string.format(".%s = %s", key, ds_fields[key])) + end end + output:end_group("};") end - output:end_group("};") -- Close the output files SEDS.output_close(output) @@ -459,7 +464,7 @@ output:start_group("{") for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do local ds_name, ds_flat_name = get_toplevel_names(ds) output:append_previous(","); - output:write(string.format("[%s_INDEX_%s] = &%s_INTF_DB",global_sym_prefix,ds_name,ds_flat_name)) + output:write(string.format("[%s_INDEX_%s] = %s",global_sym_prefix,ds_name,all_intf_db_objs[ds_flat_name] or "NULL")) end output:end_group("};") diff --git a/edslib/fsw/src/edslib_intfdb_api.c b/edslib/fsw/src/edslib_intfdb_api.c index 02224d5..2e3ff31 100644 --- a/edslib/fsw/src/edslib_intfdb_api.c +++ b/edslib/fsw/src/edslib_intfdb_api.c @@ -107,14 +107,19 @@ void EdsLib_IntfDB_ExportInterfaceInfo(const EdsLib_IntfDB_InterfaceEntry_t *Int if (IntfInfoBuffer != NULL) { - /* Not copying the name for now, should be OK as the output is const */ - IntfInfoBuffer->InterfaceName = IntfEntry->Name; - IntfInfoBuffer->IntfTypeEdsId = EdsLib_Encode_StructId(&IntfEntry->IntfTypeRef); - ParentRefObj = *SelfRefObj; - ParentRefObj.SubIndex = IntfEntry->ParentIdx; - IntfInfoBuffer->ParentCompEdsId = EdsLib_Encode_StructId(&ParentRefObj); + memset(IntfInfoBuffer, 0, sizeof(*IntfInfoBuffer)); - IntfInfoBuffer->GenericTypeMapCount = IntfEntry->GenericTypeMapCount; + if (IntfEntry != NULL) + { + /* Not copying the name for now, should be OK as the output is const */ + IntfInfoBuffer->InterfaceName = IntfEntry->Name; + IntfInfoBuffer->IntfTypeEdsId = EdsLib_Encode_StructId(&IntfEntry->IntfTypeRef); + ParentRefObj = *SelfRefObj; + ParentRefObj.SubIndex = IntfEntry->ParentIdx; + IntfInfoBuffer->ParentCompEdsId = EdsLib_Encode_StructId(&ParentRefObj); + + IntfInfoBuffer->GenericTypeMapCount = IntfEntry->GenericTypeMapCount; + } } } @@ -495,10 +500,12 @@ int32_t EdsLib_IntfDB_GetComponentInterfaceInfo(const EdsLib_DatabaseObject_t *G } else { - EdsLib_IntfDB_ExportInterfaceInfo(IntfEntry, IntfInfoBuffer, &RefObj); Status = EDSLIB_SUCCESS; } + /* If the entry is invalid, this will wipe the output buffer */ + EdsLib_IntfDB_ExportInterfaceInfo(IntfEntry, IntfInfoBuffer, &RefObj); + return Status; } diff --git a/tool/cmake/edstool-execute-all.mk b/tool/cmake/edstool-execute-all.mk index 94e1507..6759b33 100644 --- a/tool/cmake/edstool-execute-all.mk +++ b/tool/cmake/edstool-execute-all.mk @@ -1,9 +1,9 @@ ##################################################### -# +# # CFE/CFS mission build makefile helper # This calls the EDS tooling to generate all artifacts # The process also includes building those artifacts for the host -# +# ##################################################### # This checks the sanity of the calling environment. If any of these fail @@ -26,7 +26,7 @@ LOCAL_STAMPFILE := $(O)/edstool-execute-${EDSTOOL_PROJECT_NAME}.stamp # Read all context info from files exported from CMake include $(EDSNAMESPACE) include $(EDSSOURCES) -include $(O)/edstool-buildenv.mk +include $(O)/edstool-buildenv.mk # Sanity check: all of these vars should have been part of the context info ifeq ($(EDSTOOL_OUTPUT_DIR),) diff --git a/tool/cmake/edstool-execute-target.cmake b/tool/cmake/edstool-execute-target.cmake index d224c7d..adac539 100644 --- a/tool/cmake/edstool-execute-target.cmake +++ b/tool/cmake/edstool-execute-target.cmake @@ -100,6 +100,9 @@ function(edstool_setup_toplevel TARGET_NAME EDSTOOL_PROJECT_NAME EDSTOOL_OUTPUT_ COMMAND "\$(MAKE)" EDSTOOL=$ EDSTOOL_PROJECT_NAME="${EDSTOOL_PROJECT_NAME}" + CMAKE_C_FLAGS=\"$\" + CMAKE_INCLUDE_DIRECTORIES=\"$\" + CMAKE_COMPILE_DEFINITIONS=\"$\" O=obj S=src -f ${EDS_REPO_SOURCE_DIR}/tool/cmake/edstool-execute-all.mk From 983be6688ee04b8a8f97dfc3eda4a68ece0299a7 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Mon, 5 Oct 2026 22:54:40 +0100 Subject: [PATCH 2/5] Part #120, reject unmatched derived command dispatch --- cfecfs/edsmsg/CMakeLists.txt | 1 + cfecfs/edsmsg/fsw/inc/edsmsg_dispatcher.h | 4 + cfecfs/edsmsg/fsw/src/edsmsg_dispatcher.c | 30 ++- cfecfs/edsmsg/fsw/unit-test/CMakeLists.txt | 15 ++ .../fsw/unit-test/edsmsg_dispatcher_test.c | 210 ++++++++++++++++++ 5 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 cfecfs/edsmsg/fsw/unit-test/CMakeLists.txt create mode 100644 cfecfs/edsmsg/fsw/unit-test/edsmsg_dispatcher_test.c diff --git a/cfecfs/edsmsg/CMakeLists.txt b/cfecfs/edsmsg/CMakeLists.txt index bd003f9..122c29d 100644 --- a/cfecfs/edsmsg/CMakeLists.txt +++ b/cfecfs/edsmsg/CMakeLists.txt @@ -29,4 +29,5 @@ target_link_libraries(edsmsg PRIVATE core_private) if (ENABLE_UNIT_TESTS) add_subdirectory(fsw/ut-stubs) + add_subdirectory(fsw/unit-test) endif() diff --git a/cfecfs/edsmsg/fsw/inc/edsmsg_dispatcher.h b/cfecfs/edsmsg/fsw/inc/edsmsg_dispatcher.h index c7c0303..9692e21 100644 --- a/cfecfs/edsmsg/fsw/inc/edsmsg_dispatcher.h +++ b/cfecfs/edsmsg/fsw/inc/edsmsg_dispatcher.h @@ -63,6 +63,10 @@ * * If the message payload is defined by the application's EDS, the correct * handler function in the dispatch table will be called. + * Types with registered derivatives must match one of those derivatives; + * a failed identification returns CFE_STATUS_VALIDATION_FAILURE without invoking + * a handler. Only types without derivatives use dispatch table position zero + * directly. Both paths validate the message size against the selected type. * * \note this function is generally not directly invoked from applications, it * should be invoked through a wrapper generated from the EDS tool. The wrapper diff --git a/cfecfs/edsmsg/fsw/src/edsmsg_dispatcher.c b/cfecfs/edsmsg/fsw/src/edsmsg_dispatcher.c index 9d8bbc7..bea9bcb 100644 --- a/cfecfs/edsmsg/fsw/src/edsmsg_dispatcher.c +++ b/cfecfs/edsmsg/fsw/src/edsmsg_dispatcher.c @@ -205,6 +205,7 @@ CFE_Status_t CFE_EDSMSG_Dispatch_CheckActualBufferType(const CFE_SB_Buffer_t *Bu { const EdsLib_DatabaseObject_t *GD; EdsLib_DataTypeDB_TypeInfo_t TypeInfo; + EdsLib_DataTypeDB_DerivedTypeInfo_t DerivedInfo; EdsLib_DataTypeDB_DerivativeObjectInfo_t DerivObjInfo; int32_t Status; CFE_MSG_Size_t MessageSize; @@ -212,21 +213,34 @@ CFE_Status_t CFE_EDSMSG_Dispatch_CheckActualBufferType(const CFE_SB_Buffer_t *Bu GD = CFE_Config_GetObjPointer(CFE_CONFIGID_MISSION_EDS_DB); - CFE_MSG_GetSize(&Buffer->Msg, &MessageSize); + ReturnCode = CFE_MSG_GetSize(&Buffer->Msg, &MessageSize); + if (ReturnCode != CFE_SUCCESS) + { + return ReturnCode; + } - /* Check if the argument type has derivatives. This is typical for CMD interfaces where there - * are many possible command codes, and in this case each command code will have its own - * entry in the dispatch table. If this fails, it does not fail the overall process, it just - * means that the argument is not derived. */ - Status = EdsLib_DataTypeDB_IdentifyBufferWithSize(GD, *EdsId, Buffer, MessageSize, &DerivObjInfo); - if (Status == EDSLIB_SUCCESS) + /* A failed identification is not evidence that a type is non-derived. + * Consult the database before allowing the sole-handler fallback. */ + Status = EdsLib_DataTypeDB_GetDerivedInfo(GD, *EdsId, &DerivedInfo); + if (Status != EDSLIB_SUCCESS) { + return CFE_SB_INTERNAL_ERR; + } + + if (DerivedInfo.NumDerivatives > 0) + { + Status = EdsLib_DataTypeDB_IdentifyBufferWithSize(GD, *EdsId, Buffer, MessageSize, &DerivObjInfo); + if (Status != EDSLIB_SUCCESS) + { + return CFE_STATUS_VALIDATION_FAILURE; + } + *EdsId = DerivObjInfo.EdsId; *DispatchTblPosition = DerivObjInfo.DerivativeTableIndex; } else { - /* Non derived, there is just one entry, it is always first */ + /* A genuinely non-derived type has exactly one handler. */ *DispatchTblPosition = 0; } diff --git a/cfecfs/edsmsg/fsw/unit-test/CMakeLists.txt b/cfecfs/edsmsg/fsw/unit-test/CMakeLists.txt new file mode 100644 index 0000000..32fb550 --- /dev/null +++ b/cfecfs/edsmsg/fsw/unit-test/CMakeLists.txt @@ -0,0 +1,15 @@ +# Exercise the real dispatcher against the existing cFE, EDS, and missionlib stubs. +add_executable(edsmsg-dispatcher-test + edsmsg_dispatcher_test.c + ../src/edsmsg_dispatcher.c +) +target_include_directories(edsmsg-dispatcher-test PRIVATE + $ +) +target_compile_options(edsmsg-dispatcher-test PRIVATE ${UT_COVERAGE_COMPILE_FLAGS}) +target_link_libraries(edsmsg-dispatcher-test + ${UT_COVERAGE_LINK_FLAGS} + ut_core_api_stubs ut_missionlib_stubs ut_edslib_stubs + cfe_missionlib_sb_dispatchdb_static cfe_edsdb_static ut_assert +) +add_test(edsmsg-dispatcher edsmsg-dispatcher-test) diff --git a/cfecfs/edsmsg/fsw/unit-test/edsmsg_dispatcher_test.c b/cfecfs/edsmsg/fsw/unit-test/edsmsg_dispatcher_test.c new file mode 100644 index 0000000..0946a02 --- /dev/null +++ b/cfecfs/edsmsg/fsw/unit-test/edsmsg_dispatcher_test.c @@ -0,0 +1,210 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 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. +*/ + +#include +#include "cfe_error.h" +#include "cfe_msg.h" +#include "edsmsg_dispatcher.h" +#include "edslib_datatypedb.h" +#include "edslib_intfdb.h" +#include "cfe_missionlib_api.h" +#include "cfe_missionlib_runtime.h" +#include "utassert.h" +#include "utstubs.h" +#include "uttest.h" + +#define TEST_COMPONENT EDSLIB_INTF_ID(1, 1) +#define TEST_BASE_TYPE EDSLIB_MAKE_ID(1, 1) +#define TEST_DERIVED_TYPE EDSLIB_MAKE_ID(1, 2) + +static CFE_SB_Buffer_t Buffer; +static CFE_MSG_Size_t MessageSize; +static EdsLib_DataTypeDB_DerivedTypeInfo_t DerivedInfo; +static EdsLib_DataTypeDB_DerivativeObjectInfo_t IdentifiedType; +static EdsLib_DataTypeDB_TypeInfo_t TypeInfo; +static EdsLib_Id_t LookedUpType; +static unsigned int HandlerCalls[2]; + +static CFE_Status_t Handler0(const CFE_SB_Buffer_t *Message) +{ + UtAssert_True(Message == &Buffer, "Original buffer passed to handler zero"); + ++HandlerCalls[0]; + return 10; +} + +static CFE_Status_t Handler1(const CFE_SB_Buffer_t *Message) +{ + UtAssert_True(Message == &Buffer, "Original buffer passed to handler one"); + ++HandlerCalls[1]; + return 11; +} + +static void GetInterface(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + EdsLib_IntfDB_InterfaceInfo_t *Info = + UT_Hook_GetArgValueByName(Context, "IntfInfoBuffer", EdsLib_IntfDB_InterfaceInfo_t *); + memset(Info, 0, sizeof(*Info)); + Info->ParentCompEdsId = TEST_COMPONENT; +} + +static void GetId(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + *UT_Hook_GetArgValueByName(Context, "IdBuffer", EdsLib_Id_t *) = TEST_BASE_TYPE; +} + +static void GetDerived(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + *UT_Hook_GetArgValueByName(Context, "DerivInfo", EdsLib_DataTypeDB_DerivedTypeInfo_t *) = DerivedInfo; +} + +static void Identify(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + *UT_Hook_GetArgValueByName(Context, "DerivObjInfo", EdsLib_DataTypeDB_DerivativeObjectInfo_t *) = IdentifiedType; +} + +static void GetType(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + LookedUpType = UT_Hook_GetArgValueByName(Context, "EdsId", EdsLib_Id_t); + *UT_Hook_GetArgValueByName(Context, "TypeInfo", EdsLib_DataTypeDB_TypeInfo_t *) = TypeInfo; +} + +static void Setup(void) +{ + UT_ResetState(0); + memset(&Buffer, 0, sizeof(Buffer)); + memset(&DerivedInfo, 0, sizeof(DerivedInfo)); + memset(&IdentifiedType, 0, sizeof(IdentifiedType)); + memset(&TypeInfo, 0, sizeof(TypeInfo)); + memset(HandlerCalls, 0, sizeof(HandlerCalls)); + MessageSize = sizeof(CFE_MSG_CommandHeader_t); + TypeInfo.Size.Bytes = MessageSize; + DerivedInfo.NumDerivatives = 2; + IdentifiedType.EdsId = TEST_DERIVED_TYPE; + IdentifiedType.DerivativeTableIndex = 1; + LookedUpType = EDSLIB_ID_INVALID; + UT_SetDefaultReturnValue(UT_KEY(CFE_MissionLib_PubSub_IsListenerComponent), 1); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MessageSize, sizeof(MessageSize), false); + UT_SetHandlerFunction(UT_KEY(EdsLib_IntfDB_GetComponentInterfaceInfo), GetInterface, NULL); + UT_SetHandlerFunction(UT_KEY(EdsLib_IntfDB_FindAllCommands), GetId, NULL); + UT_SetHandlerFunction(UT_KEY(EdsLib_IntfDB_FindAllArgumentTypes), GetId, NULL); + UT_SetHandlerFunction(UT_KEY(EdsLib_DataTypeDB_GetDerivedInfo), GetDerived, NULL); + UT_SetHandlerFunction(UT_KEY(EdsLib_DataTypeDB_IdentifyBufferWithSize), Identify, NULL); + UT_SetHandlerFunction(UT_KEY(EdsLib_DataTypeDB_GetTypeInfo), GetType, NULL); +} + +static CFE_Status_t Dispatch(void) +{ + CFE_Status_t (*const Handlers[])(const CFE_SB_Buffer_t *) = { Handler0, Handler1 }; + return CFE_EDSMSG_Dispatch(TEST_COMPONENT, TEST_COMPONENT, &Buffer, Handlers); +} + +static void AssertNoHandler(void) +{ + UtAssert_UINT32_EQ(HandlerCalls[0], 0); + UtAssert_UINT32_EQ(HandlerCalls[1], 0); +} + +static void TestMatchingDerivatives(void) +{ + IdentifiedType.DerivativeTableIndex = 0; + UtAssert_INT32_EQ(Dispatch(), 10); + UtAssert_UINT32_EQ(LookedUpType, TEST_DERIVED_TYPE); + UtAssert_UINT32_EQ(HandlerCalls[0], 1); + UtAssert_UINT32_EQ(HandlerCalls[1], 0); + Setup(); + UtAssert_INT32_EQ(Dispatch(), 11); + UtAssert_UINT32_EQ(LookedUpType, TEST_DERIVED_TYPE); + UtAssert_UINT32_EQ(HandlerCalls[0], 0); + UtAssert_UINT32_EQ(HandlerCalls[1], 1); +} + +static void TestUnmatchedDerivative(void) +{ + UT_SetDefaultReturnValue(UT_KEY(EdsLib_DataTypeDB_IdentifyBufferWithSize), EDSLIB_NO_MATCHING_VALUE); + UtAssert_INT32_EQ(Dispatch(), CFE_STATUS_VALIDATION_FAILURE); + AssertNoHandler(); + UtAssert_STUB_COUNT(EdsLib_DataTypeDB_GetTypeInfo, 0); +} + +static void TestIdentificationError(void) +{ + UT_SetDefaultReturnValue(UT_KEY(EdsLib_DataTypeDB_IdentifyBufferWithSize), EDSLIB_FAILURE); + UtAssert_INT32_EQ(Dispatch(), CFE_STATUS_VALIDATION_FAILURE); + AssertNoHandler(); +} + +static void TestNonDerivedType(void) +{ + DerivedInfo.NumDerivatives = 0; + UT_SetDefaultReturnValue(UT_KEY(EdsLib_DataTypeDB_IdentifyBufferWithSize), EDSLIB_NO_MATCHING_VALUE); + UtAssert_INT32_EQ(Dispatch(), 10); + UtAssert_UINT32_EQ(LookedUpType, TEST_BASE_TYPE); + UtAssert_STUB_COUNT(EdsLib_DataTypeDB_IdentifyBufferWithSize, 0); + UtAssert_UINT32_EQ(HandlerCalls[0], 1); + UtAssert_UINT32_EQ(HandlerCalls[1], 0); +} + +static void TestDerivedInfoError(void) +{ + UT_SetDefaultReturnValue(UT_KEY(EdsLib_DataTypeDB_GetDerivedInfo), EDSLIB_FAILURE); + UtAssert_INT32_EQ(Dispatch(), CFE_SB_INTERNAL_ERR); + AssertNoHandler(); + UtAssert_STUB_COUNT(EdsLib_DataTypeDB_IdentifyBufferWithSize, 0); +} + +static void TestTypeInfoError(void) +{ + UT_SetDefaultReturnValue(UT_KEY(EdsLib_DataTypeDB_GetTypeInfo), EDSLIB_FAILURE); + UtAssert_INT32_EQ(Dispatch(), CFE_SB_INTERNAL_ERR); + AssertNoHandler(); +} + +static void TestMessageSizeError(void) +{ + UT_SetDefaultReturnValue(UT_KEY(CFE_MSG_GetSize), CFE_STATUS_WRONG_MSG_LENGTH); + UtAssert_INT32_EQ(Dispatch(), CFE_STATUS_WRONG_MSG_LENGTH); + AssertNoHandler(); + UtAssert_STUB_COUNT(EdsLib_DataTypeDB_GetDerivedInfo, 0); + UtAssert_STUB_COUNT(EdsLib_DataTypeDB_IdentifyBufferWithSize, 0); +} + +static void TestWrongMessageLength(void) +{ + ++TypeInfo.Size.Bytes; + UtAssert_INT32_EQ(Dispatch(), CFE_STATUS_WRONG_MSG_LENGTH); + AssertNoHandler(); + Setup(); + DerivedInfo.NumDerivatives = 0; + --TypeInfo.Size.Bytes; + UtAssert_INT32_EQ(Dispatch(), CFE_STATUS_WRONG_MSG_LENGTH); + AssertNoHandler(); +} + +void UtTest_Setup(void) +{ + UtTest_Add(TestMatchingDerivatives, Setup, NULL, "Matching derivatives keep their handlers"); + UtTest_Add(TestUnmatchedDerivative, Setup, NULL, "Unknown derivative never invokes handler zero"); + UtTest_Add(TestIdentificationError, Setup, NULL, "Identification errors do not fall back"); + UtTest_Add(TestNonDerivedType, Setup, NULL, "Non-derived type retains handler zero"); + UtTest_Add(TestDerivedInfoError, Setup, NULL, "Database metadata errors are rejected"); + UtTest_Add(TestTypeInfoError, Setup, NULL, "Type information errors are rejected"); + UtTest_Add(TestMessageSizeError, Setup, NULL, "Unreadable message size is rejected"); + UtTest_Add(TestWrongMessageLength, Setup, NULL, "Derived and base size checks remain enforced"); +} From f061a247fb53a997d26bacaa0b8b8d6f6f4892cc Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 20 Oct 2026 09:05:11 -0400 Subject: [PATCH 3/5] Fix #134, use 64-bit expat API for location A recent expat update marks the original functions as deprecated so it throws an error when compiling with -Wall -Werror. This adds a preprocessor check and macro to use the updated function. --- tool/src/seds_xmlparser.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tool/src/seds_xmlparser.c b/tool/src/seds_xmlparser.c index e4adb53..62fe47c 100644 --- a/tool/src/seds_xmlparser.c +++ b/tool/src/seds_xmlparser.c @@ -57,6 +57,18 @@ */ #define XML_CHAR_C(x) x +/* + * 64-bit location functions + * After many years of an unchanging API, Expat 2.9.0 introduces 64-bit + * versions of the functions that deal with location. Since these are only + * available/existing in the latest versions, we need to check for it. + */ +#if (XML_MAJOR_VERSION > 2) || (XML_MAJOR_VERSION == 2 && XML_MINOR_VERSION >= 9) +#define XML_LOCATION_FUNCTION(f, p) XML_##f##64(p) +#else +#define XML_LOCATION_FUNCTION(f, p) XML_##f(p) +#endif + /* * Define the functions used for basic string ops on XML strings. * Allows override with custom / wide-char versions if needed. @@ -964,7 +976,7 @@ static int seds_xmlparser_get_property(lua_State *lua) } else { - lua_pushinteger(lua, XML_GetCurrentLineNumber(pself->xmlp)); + lua_pushinteger(lua, XML_LOCATION_FUNCTION(GetCurrentLineNumber, pself->xmlp)); } } else @@ -1114,9 +1126,9 @@ int seds_xmlparser_readfile(lua_State *lua) if (!XML_ParseBuffer(pself->xmlp, len, file_flag)) { lua_pushfstring(lua, - "%s:%d: XML Parsing Error: %s", + "%s:%I: XML Parsing Error: %s", lua_tostring(lua, 2), - XML_GetCurrentLineNumber(pself->xmlp), + (lua_Integer)XML_LOCATION_FUNCTION(GetCurrentLineNumber, pself->xmlp), XML_ErrorString(XML_GetErrorCode(pself->xmlp))); return lua_error(lua); } From fd12d2e69b863fd2022300ee66a9e382318006d9 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 27 Oct 2026 13:21:20 -0400 Subject: [PATCH 4/5] Fix #137, split bash pipelines into separate targets When building tables, instead of piping one command into another, create separate rules and an intermediate file. This catches a non-zero exit status on the "source" and will appropriately stop the make without creating an empty file. --- cfecfs/eds2cfetbl/scripts/eds2cfetbl_rules.mk | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cfecfs/eds2cfetbl/scripts/eds2cfetbl_rules.mk b/cfecfs/eds2cfetbl/scripts/eds2cfetbl_rules.mk index ab0580b..54e1c66 100644 --- a/cfecfs/eds2cfetbl/scripts/eds2cfetbl_rules.mk +++ b/cfecfs/eds2cfetbl/scripts/eds2cfetbl_rules.mk @@ -29,16 +29,24 @@ eds/%.source: # the key is to pipe it through the C preprocessor so it handles all #include and #ifdef properly, # then strip out all content from files other than the directly-supplied file. Importantly, this # will resolve any C macros used in that file, including CFE_TBL_FILEDEF, leaving only the real definition -eds/%.tbldef.c: eds/%.source $(TABLETOOL_SCRIPT_DIR)/extract_filedef.awk - $(CC) -E $(DEPENDENCY_FLAGS) $(CFLAGS) $(LOCAL_CFLAGS) "$(SRC)" |\ - $(AWK) -v SRC="$(SRC)" -f "$(TABLETOOL_SCRIPT_DIR)/extract_filedef.awk" > "$(@).tmp" +eds/%.tbldef.c.pp: eds/%.source + $(CC) -E $(DEPENDENCY_FLAGS) $(CFLAGS) $(LOCAL_CFLAGS) "$(SRC)" > "$(@).tmp" + mv "$(@).tmp" "$(@)" + +eds/%.tbldef.c: eds/%.tbldef.c.pp $(TABLETOOL_SCRIPT_DIR)/extract_filedef.awk + $(AWK) -v SRC="$(SRC)" -f "$(TABLETOOL_SCRIPT_DIR)/extract_filedef.awk" "$(<)" > "$(@).tmp" mv "$(@).tmp" "$(@)" # The "filedef.c" contains only the C FILEDEF macro/object, not the defintion of that object -# Because it is separating the filedef from the object definition, it also needs to remove "sizeof" refs eds/%.filedef.c: eds/%.tbldef.c $(TABLETOOL_SCRIPT_DIR)/separate_filedef.awk - $(AWK) -v WANT_FILEDEF=1 -f "$(TABLETOOL_SCRIPT_DIR)/separate_filedef.awk" "$(<)" |\ - $(M4) -P -E -D sizeof=0 > "$(@).tmp" + $(AWK) -v WANT_FILEDEF=1 -f "$(TABLETOOL_SCRIPT_DIR)/separate_filedef.awk" "$(<)" > "$(@).tmp" + mv "$(@).tmp" "$(@)" + +# Scrub the "sizeof" operator from the filedef.c file +# After splitting the filedef macro from the instatiation of the object, the sizeof() reference +# is likely to break. This is why it has to be scrubbed. EDS has its own size knowledge so its not needed. +eds/%.filedef.scrubbed.c: eds/%.filedef.c + $(M4) -P -E -D sizeof=0 "$(<)" > "$(@).tmp" mv "$(@).tmp" "$(@)" # The "objdef.c" contains only the C object definition/instantiation (not the FILEDEF macro/object) @@ -49,7 +57,7 @@ eds/%.objdef.c: eds/%.tbldef.c $(TABLETOOL_SCRIPT_DIR)/separate_filedef.awk filedef_extract.o: $(TABLETOOL_SCRIPT_DIR)/filedef_extract.c $(CC) $(DEPENDENCY_FLAGS) $(CFLAGS) $(LOCAL_CFLAGS) -c -o "$(@)" "$(<)" -eds/%.filedef.o: eds/%.filedef.c +eds/%.filedef.o: eds/%.filedef.scrubbed.c $(CC) $(DEPENDENCY_FLAGS) -include cfe_tbl_filedef.h $(CFLAGS) $(LOCAL_CFLAGS) -c -o "$(@)" "$(<)" # The "objname" file will contain strictly the C object name used in the table definition From a183570b01cf463a4dc44e290bba8e418dd1d035 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 24 Nov 2026 13:25:32 -0500 Subject: [PATCH 5/5] Part nasa/cFS#1205, add snapshot workflow Local wrapper to call the reusable snapshot workflow --- .github/workflows/snapshot-module.yml | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/snapshot-module.yml diff --git a/.github/workflows/snapshot-module.yml b/.github/workflows/snapshot-module.yml new file mode 100644 index 0000000..64d56b8 --- /dev/null +++ b/.github/workflows/snapshot-module.yml @@ -0,0 +1,35 @@ +name: Snapshot CFS module + +on: + workflow_dispatch: + inputs: + base-branch: + description: 'The base branch to merge into' + type: string + required: false + default: 'main' + ic-branch: + description: 'The temporary integration branch to create (ic)' + type: string + required: false + default: 'ic-snapshot-dev' + dev-branch: + description: 'The branch to pull in' + type: string + required: false + default: 'dev' + pr-label: + description: 'The label(s) to apply to the generated PR' + type: string + required: false + default: '' + +jobs: + snapshot-module: + name: Snapshot module + uses: nasa/cFS/.github/workflows/snapshot-module-reusable.yml@dev + with: + base-branch: ${{ inputs.base-branch }} + ic-branch: ${{ inputs.ic-branch }} + dev-branch: ${{ inputs.dev-branch }} + pr-label: ${{ inputs.pr-label }}