From 588fb633588724e9573cf0ac0c0aba461cf76ca7 Mon Sep 17 00:00:00 2001 From: kanjoe24 <165808281+kanjoe24@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:37:00 +0000 Subject: [PATCH 1/4] Upgrade gh #154 : Upgarding autogenerate script to generate weak stubs Changes done to make all stubs in skeleton/src as weak. Also done changes for the src file have correct headers. --- scripts/autogenerate_skeletons.sh | 24 ++++++++++++++++++++++++ scripts/autogenerate_tests.sh | 25 +++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/scripts/autogenerate_skeletons.sh b/scripts/autogenerate_skeletons.sh index 6aaacf6..fe163c2 100755 --- a/scripts/autogenerate_skeletons.sh +++ b/scripts/autogenerate_skeletons.sh @@ -108,6 +108,30 @@ function AGT_generate_skeletons() mv *.c src/ fi + # Process all .c files in the directory to be weak functions + for file in src/*.c; + do + # Skip if no .c files are found + [ -e "$file" ] || continue + + temp_file="${file}.tmp" + + # Process the file to add __attribute__((weak)) to function definitions + awk ' + { + # Match function definitions: return type, function name, and arguments + if ($0 ~ /^[a-zA-Z_][a-zA-Z0-9_]*[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\(/) { + print "__attribute__((weak)) " $0; + } else { + print $0; + } + }' "$file" > "$temp_file" + + # Replace the original file with the updated file + mv "$temp_file" "$file" + AGT_SUCCESS "$file updated with weak attribute" + done + AGT_SUCCESS "Skeletons are generated successfully" cd - &> /dev/null diff --git a/scripts/autogenerate_tests.sh b/scripts/autogenerate_tests.sh index c2c3f2f..ef3a8c0 100755 --- a/scripts/autogenerate_tests.sh +++ b/scripts/autogenerate_tests.sh @@ -122,6 +122,26 @@ function AGT_add_common_to_tests_file() AGT_add_headers_to_files "${1}.c" true } +# Function to add headers to the start of the skeleton src +function AGT_add_common_to_skeleton_src_file() +{ + # Change to the target directory, exit on failure + cd "${AGT_SKELETONS_SRC}" || { + return 1 + } + + COPYRGT_MESSAGE=`cat ${AGT_COPYRGT_TEMPLATE}` + + # Process all .c files in the directory + for filename in *.c; do + # Ensure the file exists (in case no .c files are found) + [ -e "$filename" ] || continue + + # Call the helper functions with the actual filename + eval "echo -e \"${COPYRGT_MESSAGE}\\n\"" | cat - "$filename" > temp && mv temp "$filename" + done +} + # Function to make a copy of the config template and update it for each test # @param [in] Keyname to be changed # @param [in] Value to be changed into @@ -348,8 +368,8 @@ function AGT_generate_l1_l2_tests() continue fi - # Get the list of functions and copy into another temp file - cat ${AGT_TEMP_FUNC_DEF_FILE} | cut -d"(" -f1 | cut -d" " -f2 > ${AGT_TEMP_FUNC_NAMES_FILE} + # Get the list of functions and copy into another temp file making sure the attribute is removed + cat ${AGT_TEMP_FUNC_DEF_FILE} | grep -oP '\w+\s\w+(?=\()' | awk '{print $2}' > ${AGT_TEMP_FUNC_NAMES_FILE} # Set up the L1 filename new_L1_filename="test_l1_`echo $filename| cut -d"." -f1`" @@ -418,3 +438,4 @@ AGT_delete_and_create_ut_src AGT_add_main_file AGT_generate_l1_l2_tests AGT_add_test_register_file +AGT_add_common_to_skeleton_src_file \ No newline at end of file From 6baa47048ebff41ca04637a952053c062006ec32 Mon Sep 17 00:00:00 2001 From: kanjoe24 <165808281+kanjoe24@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:37:33 +0000 Subject: [PATCH 2/4] Update gh #154 :Updating makefile to provide flexibility to users to build libs --- Makefile | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 643f3ed..c68e0ef 100755 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ TOP_DIR ?= $(UT_CORE_DIR) BIN_DIR ?= $(TOP_DIR)/build/bin LIB_DIR ?= $(TOP_DIR)/build/$(TARGET)/lib BUILD_DIR ?= $(TOP_DIR)/build/$(TARGET)/obj +LIBRARY_DIR = $(LIB_DIR) # Non-Moveable Directories FRAMEWORK_DIR = $(UT_CORE_DIR)/framework @@ -94,6 +95,12 @@ OBJS := $(filter %.o, $(sort $(OBJS))) # Filter and sort the object files and re # Dependency files DEPS := $(OBJS:.o=.d) +# Add the library type (static or shared) +LIBRARY_TYPE ?= shared # Default to shared, change to static to build a static library + +# Object files for the library +LIBRARY_OBJS = $(subst $(TOP_DIR),$(BUILD_DIR),$(LIBRARY_SRCS:.c=.o)) + # Final flags INC_FLAGS := $(addprefix -I,$(INC_DIRS)) VERSION := $(shell git describe --tags | head -n1) @@ -112,7 +119,7 @@ VPATH += $(UT_CORE_DIR) $(TOP_DIR) # Default target .PHONY: clean list arm linux framework test createdirs all printenv -all: framework $(OBJS) +all: framework $(OBJS) $(if $(LIBRARY_NAME),$(LIBRARY_DIR)/$(LIBRARY_NAME)$(LIBRARY_EXTENSION)) # Build framework # Recursive make is needed as src files are not available during the first iteration @@ -133,7 +140,7 @@ download_and_build: @${MAKE} -C $(UT_CONTROL) TARGET=${TARGET} # Build the test binary -test: $(OBJS) createdirs +test: $(OBJS) createdirs $(if $(LIBRARY_NAME),$(LIBRARY_DIR)/$(LIBRARY_NAME)$(LIBRARY_EXTENSION)) @${ECHOE} ${GREEN}Linking $@ $(BUILD_DIR)/$(TARGET_EXEC)${NC} @$(COMPILER) $(OBJS) -o $(BUILD_DIR)/$(TARGET_EXEC) $(XCFLAGS) $(XLDFLAGS) @cp $(BUILD_DIR)/$(TARGET_EXEC) $(BIN_DIR)/ @@ -171,6 +178,22 @@ checkvariantchange: fi \ fi +# Create the library (shared or static) +$(LIBRARY_DIR)/$(LIBRARY_NAME)$(LIBRARY_EXTENSION): $(LIBRARY_OBJS) createdirs + @if [ "${LIBRARY_TYPE}" = "shared" ]; then \ + ${ECHOE} ${GREEN}Building shared library $(LIBRARY_NAME)$(LIBRARY_EXTENSION)${NC}; \ + $(CC) $(LIBRARY_OBJS) $(LIBRARY_FLAGS) -o $@; \ + else \ + ${ECHOE} ${GREEN}Building static library $(LIBRARY_NAME)$(LIBRARY_EXTENSION)${NC}; \ + $(AR) rcs $@ $(LIBRARY_OBJS); \ + fi + +# Create object files for the library +$(LIBRARY_DIR)/%.o: $(SRC_DIR)/%.c + @${ECHOE} ${GREEN}Building [${YELLOW}$<${GREEN}] for library${NC} + @$(MKDIR_P) $(dir $@) + @$(CC) $(XCFLAGS) $(CFLAGS) -I$(LIBRARY_INC) -c $< -o $@ + arm: make TARGET=arm @@ -240,6 +263,14 @@ list: @${ECHOE} @${ECHOE} ${YELLOW}INC_FLAGS:${NC} $(INC_FLAGS) @${ECHOE} + @${ECHOE} ${YELLOW}LIBRARY_DIR:${NC} $(LIBRARY_DIR) + @${ECHOE} + @${ECHOE} ${YELLOW}LIBRARY_NAME:${NC} $(LIBRARY_NAME) + @${ECHOE} + @${ECHOE} ${YELLOW}LIBRARY_EXTENSION:${NC} $(LIBRARY_EXTENSION) + @${ECHOE} + @${ECHOE} ${YELLOW}LIBRARY_TYPE:${NC} $(LIBRARY_TYPE) + @${ECHOE} @${ECHOE} ${YELLOW}DEPS:${NC} $(DEPS) @${ECHOE} @${ECHOE} --------- ut_control ---------------- From 67ebffbaeb1d63ff078d81893fb3371b931d0d46 Mon Sep 17 00:00:00 2001 From: kanjoe24 <165808281+kanjoe24@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:16:19 +0000 Subject: [PATCH 3/4] Fix gh #154 : Fix review comments --- Makefile | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index c68e0ef..81e0efe 100755 --- a/Makefile +++ b/Makefile @@ -38,7 +38,6 @@ TOP_DIR ?= $(UT_CORE_DIR) BIN_DIR ?= $(TOP_DIR)/build/bin LIB_DIR ?= $(TOP_DIR)/build/$(TARGET)/lib BUILD_DIR ?= $(TOP_DIR)/build/$(TARGET)/obj -LIBRARY_DIR = $(LIB_DIR) # Non-Moveable Directories FRAMEWORK_DIR = $(UT_CORE_DIR)/framework @@ -76,6 +75,17 @@ else # GTEST case SRCS := $(shell find $(SRC_DIRS) -type f \( -name '*.cpp' -o -name '*.c' \) | grep -v "$(EXCLUDE_DIRS)") endif +# Check if BUILD_WEAK_STUBS_SRC is defined +ifdef BUILD_WEAK_STUBS_SRC + +# Define variables for the static library and its source files +WEAK_STUBS_LIB := $(LIB_DIR)/libweak_stubs_libs.a +WEAK_STUBS_SRC := $(shell find $(BUILD_WEAK_STUBS_SRC) -name *.c) +WEAK_STUBS_OBJ := $(patsubst $(TOP_DIR)/%, $(BUILD_DIR)/%, $(WEAK_STUBS_SRC:.c=.o)) # Apply the pattern substitution to create object file paths + +XLDFLAGS := -L$(LIB_DIR) -lweak_stubs_libs $(XLDFLAGS) +endif + VARIANT_FILE := .variant ifeq ($(TARGET),arm) @@ -95,12 +105,6 @@ OBJS := $(filter %.o, $(sort $(OBJS))) # Filter and sort the object files and re # Dependency files DEPS := $(OBJS:.o=.d) -# Add the library type (static or shared) -LIBRARY_TYPE ?= shared # Default to shared, change to static to build a static library - -# Object files for the library -LIBRARY_OBJS = $(subst $(TOP_DIR),$(BUILD_DIR),$(LIBRARY_SRCS:.c=.o)) - # Final flags INC_FLAGS := $(addprefix -I,$(INC_DIRS)) VERSION := $(shell git describe --tags | head -n1) @@ -119,7 +123,7 @@ VPATH += $(UT_CORE_DIR) $(TOP_DIR) # Default target .PHONY: clean list arm linux framework test createdirs all printenv -all: framework $(OBJS) $(if $(LIBRARY_NAME),$(LIBRARY_DIR)/$(LIBRARY_NAME)$(LIBRARY_EXTENSION)) +all: framework $(OBJS) $(if $(BUILD_WEAK_STUBS_SRC),$(WEAK_STUBS_LIB)) # Build framework # Recursive make is needed as src files are not available during the first iteration @@ -140,7 +144,7 @@ download_and_build: @${MAKE} -C $(UT_CONTROL) TARGET=${TARGET} # Build the test binary -test: $(OBJS) createdirs $(if $(LIBRARY_NAME),$(LIBRARY_DIR)/$(LIBRARY_NAME)$(LIBRARY_EXTENSION)) +test: $(OBJS) createdirs $(if $(BUILD_WEAK_STUBS_SRC),$(WEAK_STUBS_LIB)) @${ECHOE} ${GREEN}Linking $@ $(BUILD_DIR)/$(TARGET_EXEC)${NC} @$(COMPILER) $(OBJS) -o $(BUILD_DIR)/$(TARGET_EXEC) $(XCFLAGS) $(XLDFLAGS) @cp $(BUILD_DIR)/$(TARGET_EXEC) $(BIN_DIR)/ @@ -178,21 +182,15 @@ checkvariantchange: fi \ fi -# Create the library (shared or static) -$(LIBRARY_DIR)/$(LIBRARY_NAME)$(LIBRARY_EXTENSION): $(LIBRARY_OBJS) createdirs - @if [ "${LIBRARY_TYPE}" = "shared" ]; then \ - ${ECHOE} ${GREEN}Building shared library $(LIBRARY_NAME)$(LIBRARY_EXTENSION)${NC}; \ - $(CC) $(LIBRARY_OBJS) $(LIBRARY_FLAGS) -o $@; \ - else \ - ${ECHOE} ${GREEN}Building static library $(LIBRARY_NAME)$(LIBRARY_EXTENSION)${NC}; \ - $(AR) rcs $@ $(LIBRARY_OBJS); \ - fi +# Create the library weak_stubs_libs +$(WEAK_STUBS_LIB): $(WEAK_STUBS_OBJ) + @${ECHOE} ${GREEN}Building weak_stubs_libs...${NC} + @$(AR) rcs $@ $^ -# Create object files for the library -$(LIBRARY_DIR)/%.o: $(SRC_DIR)/%.c - @${ECHOE} ${GREEN}Building [${YELLOW}$<${GREEN}] for library${NC} +# Rule to compile .c files into .o files in the correct directory +$(BUILD_DIR)/skelton/src/%.o: $(BUILD_WEAK_STUBS_SRC)/%.c @$(MKDIR_P) $(dir $@) - @$(CC) $(XCFLAGS) $(CFLAGS) -I$(LIBRARY_INC) -c $< -o $@ + @$(COMPILER) $(XCFLAGS) -c $< -o $@ arm: make TARGET=arm @@ -263,13 +261,7 @@ list: @${ECHOE} @${ECHOE} ${YELLOW}INC_FLAGS:${NC} $(INC_FLAGS) @${ECHOE} - @${ECHOE} ${YELLOW}LIBRARY_DIR:${NC} $(LIBRARY_DIR) - @${ECHOE} - @${ECHOE} ${YELLOW}LIBRARY_NAME:${NC} $(LIBRARY_NAME) - @${ECHOE} - @${ECHOE} ${YELLOW}LIBRARY_EXTENSION:${NC} $(LIBRARY_EXTENSION) - @${ECHOE} - @${ECHOE} ${YELLOW}LIBRARY_TYPE:${NC} $(LIBRARY_TYPE) + @${ECHOE} ${YELLOW}BUILD_WEAK_STUBS_SRC:${NC} $(BUILD_WEAK_STUBS_SRC) @${ECHOE} @${ECHOE} ${YELLOW}DEPS:${NC} $(DEPS) @${ECHOE} From b4e281c445184f51794a120f0abbf8e75dd8eea1 Mon Sep 17 00:00:00 2001 From: kanjoe24 <165808281+kanjoe24@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:33:41 +0000 Subject: [PATCH 4/4] Move gh #154: Moved makefile related changes to separate PR. --- Makefile | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 81e0efe..643f3ed 100755 --- a/Makefile +++ b/Makefile @@ -75,17 +75,6 @@ else # GTEST case SRCS := $(shell find $(SRC_DIRS) -type f \( -name '*.cpp' -o -name '*.c' \) | grep -v "$(EXCLUDE_DIRS)") endif -# Check if BUILD_WEAK_STUBS_SRC is defined -ifdef BUILD_WEAK_STUBS_SRC - -# Define variables for the static library and its source files -WEAK_STUBS_LIB := $(LIB_DIR)/libweak_stubs_libs.a -WEAK_STUBS_SRC := $(shell find $(BUILD_WEAK_STUBS_SRC) -name *.c) -WEAK_STUBS_OBJ := $(patsubst $(TOP_DIR)/%, $(BUILD_DIR)/%, $(WEAK_STUBS_SRC:.c=.o)) # Apply the pattern substitution to create object file paths - -XLDFLAGS := -L$(LIB_DIR) -lweak_stubs_libs $(XLDFLAGS) -endif - VARIANT_FILE := .variant ifeq ($(TARGET),arm) @@ -123,7 +112,7 @@ VPATH += $(UT_CORE_DIR) $(TOP_DIR) # Default target .PHONY: clean list arm linux framework test createdirs all printenv -all: framework $(OBJS) $(if $(BUILD_WEAK_STUBS_SRC),$(WEAK_STUBS_LIB)) +all: framework $(OBJS) # Build framework # Recursive make is needed as src files are not available during the first iteration @@ -144,7 +133,7 @@ download_and_build: @${MAKE} -C $(UT_CONTROL) TARGET=${TARGET} # Build the test binary -test: $(OBJS) createdirs $(if $(BUILD_WEAK_STUBS_SRC),$(WEAK_STUBS_LIB)) +test: $(OBJS) createdirs @${ECHOE} ${GREEN}Linking $@ $(BUILD_DIR)/$(TARGET_EXEC)${NC} @$(COMPILER) $(OBJS) -o $(BUILD_DIR)/$(TARGET_EXEC) $(XCFLAGS) $(XLDFLAGS) @cp $(BUILD_DIR)/$(TARGET_EXEC) $(BIN_DIR)/ @@ -182,16 +171,6 @@ checkvariantchange: fi \ fi -# Create the library weak_stubs_libs -$(WEAK_STUBS_LIB): $(WEAK_STUBS_OBJ) - @${ECHOE} ${GREEN}Building weak_stubs_libs...${NC} - @$(AR) rcs $@ $^ - -# Rule to compile .c files into .o files in the correct directory -$(BUILD_DIR)/skelton/src/%.o: $(BUILD_WEAK_STUBS_SRC)/%.c - @$(MKDIR_P) $(dir $@) - @$(COMPILER) $(XCFLAGS) -c $< -o $@ - arm: make TARGET=arm @@ -261,8 +240,6 @@ list: @${ECHOE} @${ECHOE} ${YELLOW}INC_FLAGS:${NC} $(INC_FLAGS) @${ECHOE} - @${ECHOE} ${YELLOW}BUILD_WEAK_STUBS_SRC:${NC} $(BUILD_WEAK_STUBS_SRC) - @${ECHOE} @${ECHOE} ${YELLOW}DEPS:${NC} $(DEPS) @${ECHOE} @${ECHOE} --------- ut_control ----------------