Skip to content

Commit

Permalink
Merge pull request #159 from rdkcentral/feature/gh154-upgrade-autogen…
Browse files Browse the repository at this point in the history
…eration-script

gh #154 : Upgrading auto-generate script to generate weak stubs
  • Loading branch information
kanjoe24 authored Dec 18, 2024
2 parents 6d63143 + b4e281c commit 38990a0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
24 changes: 24 additions & 0 deletions scripts/autogenerate_skeletons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 23 additions & 2 deletions scripts/autogenerate_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`"
Expand Down Expand Up @@ -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

0 comments on commit 38990a0

Please sign in to comment.