rdkcentral / ut-core

Unit Test - Core Framework
Apache License 2.0
4 stars 0 forks source link

Write a script to compare the functions in header files and testing suites #128

Closed kanjoe24 closed 1 week ago

kanjoe24 commented 3 weeks ago

Problem: Some of the functions in header files are not covered in testing suites

Goal: All functions in the header file must be covered by the testing suites

Ulrond commented 3 weeks ago
#!/bin/bash

# Color code for red text
RED='\033[0;31m'
NC='\033[0m' # No color (reset)

# Input parameters: directory with header files and object file
HEADER_DIR="$1"
OBJECT_FILE="$2"

# Check for missing parameters
if [[ -z "$HEADER_DIR" || -z "$OBJECT_FILE" ]]; then
    echo "Usage: $0 <header_directory> <object_file.o>"
    exit 1
fi

# Check if directory and object file exist
if [[ ! -d "$HEADER_DIR" || ! -f "$OBJECT_FILE" ]]; then
    echo "Error: Directory or object file does not exist."
    exit 1
fi

# Collect all function declarations from header files in the directory
# Adjusted grep pattern to exclude typedefs and function pointers
HEADER_FUNCTIONS=$(grep -hoP '^\s*(?!typedef)\w+\s+\w+\s*\(.*\)\s*;' "$HEADER_DIR"/*.h | \
                   sed -E 's/^\s*\w+\s+(\w+)\s*\(.*/\1/' | sort | uniq)

# Extract implemented functions from the object file
OBJECT_FUNCTIONS=$(objdump -t "$OBJECT_FILE" | grep ' F ' | awk '{print $6}' | sort | uniq)

# Compare and find functions in the headers but not in the object file
echo "Checking for unimplemented functions across all headers in $HEADER_DIR..."
MISSING_FUNCTIONS=$(comm -23 <(echo "$HEADER_FUNCTIONS") <(echo "$OBJECT_FUNCTIONS"))

# Output the results
if [[ -z "$MISSING_FUNCTIONS" ]]; then
    echo "All functions declared in the header files are implemented in the object file."
else
    echo -e "${RED}The following functions are declared in the header files but not implemented in the object file:${NC}"
    echo -e "${RED}$MISSING_FUNCTIONS${NC}"
fi
Ulrond commented 2 weeks ago

No requirement to integrate into the build, want to be able to run it as part of a review process.